0

I want to solve an integer programming model with cplex python. I have this model:

enter image description here

a and h are matrixes with 0s and 1s. p is a set of numbers. here is a part of my cplex code for this model:

p=[i for i in range (len(h))]
x=mdl.binary_var_dict(p,name='x')

#objective
mdl.minimize(0)

#constraints
#1
mdl.add_constraints(mdl.sum(h[i][k]*x[i] for  i  in p)==4  for k in T)

#2    
mdl.add_constraints(mdl.sum(a[i][k]*x[i] for i in p)==4  for k in T)

mdl.print_information()
Solution = mdl.solve(log_output=False)
mdl.get_solve_status()
print(Solution)

When I run the program I get this error:

Error: Adding trivial infeasible linear constraint: 0 == 4, rank: 1
Error: Adding trivial infeasible linear constraint: 0 == 4, rank: 1
Error: Adding trivial infeasible linear constraint: 0 == 4, rank: 23
Error: Adding trivial infeasible linear constraint: 0 == 4, rank: 23

'h' is a 600*22 matrix and 'a' is reverse of h(if there's a 1 (or 0) in h, it is 0 (or 1) in a). A sample of h:


 [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0],
 [1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]

I don't understand where is the problem.

Sana.Nz
  • 81
  • 11

1 Answers1

1

The error messages tells you what happens: you added a constraint that is trivially infeasible, i.e., that can obviously not be satisfied. From the error message it seems you added some == 4 constraints with an empty left-hand side.

From your code it looks that this would happen if p is empty.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22
  • But none of the left side parameters and sets are empty. – Sana.Nz Mar 16 '20 at 16:24
  • 1
    Well, if `p` is empty then all left-hand sides are empty. Or maybe the referenced values in `a` or `h` are all 0? You will have to update your question with the full code (a minimal example) if you need further assistance. – Daniel Junglas Mar 16 '20 at 16:33
  • Ok. I Edited the post. – Sana.Nz Mar 17 '20 at 09:42
  • In your sample of `h` you can see that there are columns that are all-0. This will result in constraints that have all-0 coefficients on the left-hand side. So the left-hand side is 0 in these constraints. You can compute/print `min(max(h[i][k] for i in p) for k in T)`. If this is 0 then you have all-0 columns in `h`. The constraints constructed from this column will trigger the above warning. – Daniel Junglas Mar 17 '20 at 14:02
  • So this is not related to the problem that I don't get any feasible solutions? – Sana.Nz Mar 18 '20 at 13:22
  • This *is* the reason why you don't get any feasible solutions. You are adding constraints that can never be satisfied. docplex warns you about that problem. There is a problem either with your model or with your definition of matrices `a` and `h`. As long as you have all-0 or all-1 columns in your matrix, the model you are creating will be infeasible. So the question is: why do you have these columns in your matrix? Or could it be that you transposed the matrix by accident? Right now you create a constraint from each column. Maybe you want to create a constraint from each *row* instead? – Daniel Junglas Mar 18 '20 at 13:29
  • Ok, this really helped. Thanks. I just have one more question. Now I get 2 feasible solutions but I know that there are hundreds of feasible solutions. How can I get all the solutions?! – Sana.Nz Mar 18 '20 at 14:10
  • Please start a new question for this. It is unrelated to your original question. – Daniel Junglas Mar 18 '20 at 15:02