Nov-29-2018, 10:53 AM
The documentation for problem.addVariable always shows items in list as numerics, never strings, although I don't see any constraints on doing so:
I found the example of building a crossword which uses constraints: http://www.cromulentrambling.com/2017/01...ython.html
Please note that the author builds problem thusly:
Output:addVariable(self, variable, domain)
Add a variable to the problem
Example:
>>> problem = Problem()
>>> problem.addVariable("a", [1, 2])
>>> problem.getSolution() in ({'a': 1}, {'a': 2})
True
Parameters:
variable - Object representing a problem variable
(type=hashable object)
domain - Set of items defining the possible values that the given variable may assume
(type=list, tuple, or instance of Domain)
addVariables(self, variables, domain)
Add one or more variables to the problem
Example:
>>> problem = Problem()
>>> problem.addVariables(["a", "b"], [1, 2, 3])
>>> solutions = problem.getSolutions()
>>> len(solutions)
9
>>> {'a': 3, 'b': 1} in solutions
True
Parameters:
variables - Any object containing a sequence of objects represeting problem variables
(type=sequence of hashable objects)
domain - Set of items defining the possible values that the given variables may assume
(type=list, tuple, or instance of Domain)
If that were an issue, I would expect it to be documented, but don't see it.I found the example of building a crossword which uses constraints: http://www.cromulentrambling.com/2017/01...ython.html
Please note that the author builds problem thusly:
problem.addVariables(list(range(s*s)), [0,1])again with a list of numerics for domain.