On 15/05/2015 13:35, Mark Lawrence wrote:
On 15/05/2015 04:58, Xiang Zhang wrote:
Dear all,

I am writing a code using Python now.

I want to know how to find out values of all feasible x under
constraints.

x = [x_1, x_2, x_3,..., x_10]


constraints:
x_i = 0,1,2,3 or 4,          where i=1,2,....10
x_1 + x_2 + x_3 +...+x_10 <= 15

How to find out all the feasible solutions x (domain of x) using
python, like [0,0,0,0,0,0,0,0,0,0], [1,1,1,1,1,1,1,1,1,1] etc ? What
should be the code?

Any hint or help would be highly appreciated!

Sincerely,

Xiang Zhang


There are several constraint libraries on pypi if you don't want to roll
your own.  See for example
https://pypi.python.org/pypi/python-constraint/1.2


Forgot to mention this http://numberjack.ucc.ie/

Maybe of general interest see also http://www.csplib.org/ http://www.hakank.org/constraint_programming_blog/



--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to