Is there a Python library for handling complicated mathematical sets (constructed using mathematical set-builder notation)?

心不动则不痛 提交于 2019-12-04 20:38:00

This looks more like a constraint-solver problem to me:

import constraint as c

p = c.Problem()
p.addVariable(0, range(1,101))
p.addVariable(1, range(1,51))
p.addConstraint(lambda i: i >= 20, [0])
p.addConstraint(lambda j: j >= 21, [1])
p.addConstraint(c.MaxSumConstraint(50))

indices = ((s[0], s[1]) for s in p.getSolutionIter())  # convert to tuple generator

then if you do

for ij in indices:
    print ij

you get

(29, 21)
(28, 22)
(28, 21)
(27, 23)
(27, 22)
(27, 21)

...

(20, 25)
(20, 24)
(20, 23)
(20, 22)
(20, 21)

Although I am not certain if this specifically (the set-builder notation) is supported by scipy. I think scipy is your best bet regardless.

There is support for sparse arrays/sets in scipy so you can easily let it handle the allocation of those without actually allocating the space :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!