One of the multiple solutions does not satisfy the constraints.
AnsweredHi. I am using a MIP solver with multiple solutions. The setting is with "PoolSearchMode=2" and "method=1", and model is "mip".
The first two solutions are both optimal, with the same cost. However, the second one violates one of the constraints.
My constraints are as follows: for each idx_smpl
model.addConstrs( x[idx_smpl,idx-shift_length] + y[idx_smpl,idx] + z[idx_smpl,idx-shift_length] - 2 <= 0 for idx in range(shift_length,k))model.addConstrs( x[idx_smpl,idx-shift_length] - y[idx_smpl,idx] - z[idx_smpl,idx-shift_length] <= 0 for idx in range(shift_length,k))model.addConstrs(-x[idx_smpl,idx-shift_length] + y[idx_smpl,idx] - z[idx_smpl,idx-shift_length] <= 0 for idx in range(shift_length,k))model.addConstrs(-x[idx_smpl,idx-shift_length] - y[idx_smpl,idx] + z[idx_smpl,idx-shift_length] <= 0 for idx in range(shift_length,k))
-
Could you please share the problematic model as an MPS or LP file together with the exact settings you use to reproduce this issue? Since uploading files in the Community is not possible, please use any of the possibilities described in Posting to the Community Forum.
Best regards,
Jaromił0 -
Thank you, Jaromit. Sure.
The goal is to find the g vector such that the summation of z vectors overall data samples is minimized.
The x is known, and y is the convolution of x and g (computed by using helper w).
The variables I defined in Gurobi are g,z,w,y, and only g is binary. We consider 50 data samples here.The constraints are
(Edge cases are considered)
0 -
Thank you for sharing the model formulation.
Could you please share an MPS or an LP file of the model? You can generate such file via the write method. This way, we can be sure that we are working on the same model as you.
Since uploading files in the Community is not possible, please use any of the possibilities described in Posting to the Community Forum.
0 -
Sorry for the misunderstanding. Here is the extracted MPS and LP file.
https://uofi.box.com/s/qlww5ht4tlirresi03b8crl3sy9nztuw
The one do not match is with idx = 90 and the first data sample. x[0,86] = 1, y[0,90] = 0, and z[0,86] = 0.
It violates x[0,86] - y[0,86] - z[0,90] <= -1. (constraint 3)
0 -
Thank you for the files.
In your MPS and LP files, there is no variable called \(\texttt{x}\). There are only \(\texttt{g,w,y,z}\) variables.
Also I cannot find any constraint with a \(-1\) as right-hand side and \(3\) variables on the left-hand side.
Best regards,
Jaromił0 -
Thank you Jaromit.
Yes. I didn't define x as Gurobi variable because it is a constant vector. Maybe I should define x as a variable instead?
Sorry for the typo, it is x[0,86] - y[0,86] - z[0,90] <= 0. Since I didn't define x as variable, it might show as
- y[0,86] - z[0,90] <= -1?
I am not sure.0 -
With the model you sent, I am not able to reproduce the issue you have. Could you please generate the LP/MPS file you have in mind together with a solution that violates one of the constraints? Please also provide the exact commands/parameters you used to generate the solution.
Best regards,
Jaromił0 -
Sorry for the late reply.
I pack the code, LP/MPS files, and also the outputs I saw into the following folder.
https://uofi.box.com/s/r9ua2ttrz7k07ipnlj0x8f6liaav5flm
Using the following command to run the code:
python optHD.py -setOfData 101 -num_smpl 2 -shift_length 4 -block_idx 2 -memory_length 10 -multi_solution 1
It will print out the first 10 solutions, denoted by gList, and the second one with the same optimal cost violates the constraint in my mind (x-y-z<=0). This constraint is related to the one in LP file:
R182: - z[0,86] - y[0,90] <= -1
where z[0,86] = 0 and y[0,90] = 0.
I made a comment under the solutions and variables that violate the constrain of x - y - z <= 0 (scroll down the outputs.txt to the end)
Again, thank you for your help.
Sincerely,
Yeqi0 -
Hi Yeqi,
I think that there is a bug in your code comparing solutions. When I write out all solutions) found by Gurobi to files called \(\texttt{solutionX.sol}\ via
model.setParam("SolutionNumber", sNum)
model.write("solution%d.sol"%(sNum))There is no solution with \(\texttt{z[0,86]=0}\) and \(\texttt{y[0,90]=0}\). Since the code is quite advanced, it is best that you double check the comparison part.
Best regards,
Jaromił0 -
Thank you, Jaromit,
I just used these two commands to save all 10 solutions, but they are identical. The second solution should be
g = [0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0]
(I am checking my comparison part.)
Sincerely,
Yeqi0 -
Hi Jaromił,
I got it! During the comparison, I force the variable into an integer int(v.xn) and it turns 0.99 to 0. So the constraints are indeed satisfied. Thank you for the help.
May I ask an additional question here? I still cannot save the correct multiple solutions (the saved solutions are identical) by running the following:
for sNum in range(model.SolCount):
model.setParam("SolutionNumber", sNum)
file_name = 'solution'+str(sNum)+'.sol'
model.write(file_name)Sincerely,
Yeqi0 -
Hi Yeqi,
Great to hear that you are doing progress!
May I ask an additional question here? I still cannot save the correct multiple solutions (the saved solutions are identical) by running the following:
This is my mistake. It is not possible to write different solution via the write method. You can use the following snippet to write the 10 different solutions to files
model.setParam("SolutionNumber", sNum)
file = open("solution%d.sol"%(sNum),"w")
for v in model.getVars():
file.write("%s %f\n"%(v.VarName,v.Xn))
file.close()It is very simple but enough for comparing solutions.
Best regards,
Jaromił0 -
Thank you so much, Jaromił! It works well.
It is a great journey with Gurobi and you. Wish you all the best. :)
Sincerely,
Yeqi0
Please sign in to leave a comment.
Comments
13 comments