Insert a previous result in gurobi
OngoingHello, i would like to know if it is possible to insert a suboptimal result from a heuristic method and then use gurobi to keep the search.

Hi Rafael,
Yes, you can pass warmstart solutions to Gurobi. One way to do this is by setting the Start variable attributes to the corresponding warmstart values. You can also specify a .mst or .sol solution file to use as a warm start via the InputFile parameter, or, e.g., GRBread() in C or Model.read() in Python.
Thanks,
Eli
0 
Thanks Eli.
0 
Hello again, I am struggling to insert .mst or .sol file in my model, on .lp file it came with the same name i used in my decision variables model like x, y. But writing in the same model files .mst and .sol the letter change to B and I, and gurobi tell it is uknown variable and no start values was specified in MIP Start. It confused me what i am doing wrong, just to make it clear, my variables are twothree dimension and I am using model.read(".mst") and model.read(".sol").
Regards.
0 
Hi Rafael,
Do you have a short code snippet that replicates this behavior, and the output produced by the code? Thanks!
Eli
0 
Brief of .lp
99.99900054931641 x0_0 + 77.75599670410156 x0_1 + 33.40299987792969 x0_2
+ 28.50699996948242 x0_3 + 4.197000026702881 x0_4
+ 41.56999969482422 x0_5 + 37.63199996948242 x0_6
+ 39.43899917602539 x0_7 + 39.60200119018555 x0_8
+ 33.18299865722656 x0_9 + 40.5 x0_10 + 18.0669994354248 x0_11
+ 36.7130012512207 x0_12 + 40.68199920654297 x0_13
+ 43.41600036621094 x0_14 + 38.5260009765625 x0_15
+ 38.4370002746582 x0_16 + 15.76900005340576 x0_17
+ 41.3849983215332 x0_18 + 36.79700088500977 x0_19
+ 46.36999893188477 x0_20 + 37.05300140380859 x0_21
+ 47.89400100708008 x0_22 + 48.5890007019043 x0_23
+ 34.68299865722656 x0_24 + 38.25600051879883 x0_25
+ 36.69100189208984 x0_26 + 45.44300079345703 x0_27
+ 45.94200134277344 x0_28 + 42.49499893188477 x0_29
+ 50.68399810791016 x0_30 + 45.10300064086914 x0_31
+ 37.85300064086914 x0_32 + 45.16600036621094 x0_33
+ 28.22200012207031 x0_34 + 27.98100090026855 x0_35Brief of .mst
B0(12) 0
B1(11) 0
B2(10) 0
B3(9) 0
B4(8) 0
B5(7) 0
B6(7) 0
B7(7) 0
B8(7) 0
B9(7) 0Regards.
0 
Output of the code:
Unknown variable 'I36994(10)' in MIP start  ignored
Unknown variable 'I36995(10)' in MIP start  ignored
Unknown variable 'I36996(10)' in MIP start  ignored
Unknown variable 'I36997(2)' in MIP start  ignored
Unknown variable 'I36998(2)' in MIP start  ignored
Unknown variable 'I36999(2)' in MIP start  ignored
Unknown variable 'I37000(2)' in MIP start  ignored
Optimize a model with 18955 rows, 37001 columns and 113938 nonzeros
Variable types: 0 continuous, 37001 integer (18496 binary)
Coefficient statistics:
Matrix range [1e+00, 9e+03]
Objective range [1e07, 2e+02]
Bounds range [1e+00, 1e+00]
RHS range [1e+00, 2e+05]No start values specified in MIP start
code:
declaring x...
x = new GRBVar* [N];
for(int i= 0; i< N; i++){
x[i] = model.addVars(N, GRB_BINARY);
model.update();
for (int j= 0; j< N; j++){
ostringstream vname;
vname << "x" << i<<" "<< j;
x[i][j].set(GRB_DoubleAttr_Obj,0);
x[i][j].set(GRB_StringAttr_VarName, vname.str());
}
}after objective function and all subjects:
if there is .sol file:
model.read(".sol");
model.update();
model.optimize();model.write(".lp");
model.write(".sol");
model.write(".mst");0 
Hi Rafael,
Based on this line:
vname << "x" << i<<" "<< j;
it looks like you have a space in your variable names. Can you try removing the space from your variable names? E.g.,
vname << "x[" << i << "," << j << "]";
For the purposes of model file reading/writing, it doesn't make sense to have spaces in variable names. For example, we could have a variable named "x" and another variable named "2 x". In the LP file, if we see "2 x", does this refer to the second variable, or does it mean two times the first variable?
Also, you may want to give names to all of your variables (like x[i]), and use filenames that aren't just an extension (e.g., "model.lp" instead of ".lp").
Does this help? Thanks!
Eli
1 
Thanks very much Eli, it really worked. I was just representing the .lp file, actually it has a name. But everything worked.
Best Regards.
0 
Hi Eli,
Wondering if you know how to turn off printing the ignored variables in Python? I have a lot of variables that are ignored each time I pass the initial solution but I don't want them printed on the screen.
Unknown variable 'x[1,2,1]' in MIP start  ignored
Thanks,
Khosro
0 
There isn't a specific option to disable those messages. The closest thing is the LogToConsole parameter, though setting this parameter to 0 completely disables console logging.
Why does your solution file contain variables that aren't part of the model?
0 
Thank you for your response. I have a large problem that the set of indexes slightly changes each time I want to solve it again. So I wanted to use the previous solution as a warm start for the next problem. That's the reason I have a lot of variables that are not included in the previous solution. I read the ".mst" file from the previous solution.
0
Please sign in to leave a comment.
Comments
11 comments