0

I need to use python-constraint for solving a stowage problem. I have 2 different types of containers (standard S and refrigereted R) and two possible destinations. Containers must be stowed as shown in the next grid that

N N N N
N N N N
X E E X
X X X X

The containers info is a list of tuples where (idx, standard|energized, destination), as an example:

containers = [(1,S,1), (2,R,2), ...] 

Where N is a normal location and E is an energized one, X is a not used position.

I've been trying to use python-constrain the distribution of containers in ship. First my variables

problem = constraint.Problem()
problem.addVariables(range(1,len(containers)+1), containers)

And then I need to code my problem to assign cointainers into position in the ship but unsuccessful so far since I don't how to code the grid and assign them to each container. The n-queens is not working for this problem.

Any suggestions.

Edit: Using the n-rooks or n-queens as an example where the variables are the cells in the grid seems to work fine

problem.addVariables(rows, columns)

but then, adding the constraints (such as an unaccesible last row) I get:

for i, f in enumerate(rows):
    if (0<=i<=n-1):
       problem.adddConstraint(rows[i], cols)

So I don't seem to understand the syntax in the addConstraint function.

sergiohzlz
  • 113
  • 2
  • 5
  • Would you add more details? Do you have any problems on code? You need to know how to write program? – Reza Akraminejad Dec 08 '21 at 18:10
  • Thanks. I have problems establishing the constraints. Meaning that using the example of the n-rooks or n-queens, my variables can be the cells in the grid, but when I try to establish the las row as unused I get an exception. – sergiohzlz Dec 08 '21 at 18:38
  • Why you don't work with list of lists which represents matrix? And you didn't write the error text. – Reza Akraminejad Dec 08 '21 at 19:48

0 Answers0