How to use a solution from a heuristic algorithm as the initial solution of Gurobi
回答済みRecently, I know that , if Guribi has a good initial solution, the speed of solving will be accelerated and the result may be better. Therefore, I want to use Genetic algorithm to obtain a better solution, which will be as a initial solution of Gurobi to solve my model. But, I can not find some code examples in C# version to deliver a solution to be a initial solution of Gurobi. In Python, 'model.cbSetSolution' can accomplish it. If you solved the similar problem, please give me some help, such as the code examples. Best wishes to you.
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Yuan,
You can pass an initial solution to Gurobi by setting the Start variable attributes. An example of this can be seen in the C# facility location example from the Gurobi examples library.
Thanks,
Eli
0 -
Think you very much, best wishes to you.
0 -
Dear Eli,
I've been trying to set an initial solution using the example you suggested to Yuan. It does work fine with Gurobi 9.0.1, but it doesn't with Gurobi 8.1.1. I checked the example file provided in both versions, and they coincide for, at least, the part that's relevant to setting an initial solution. Should I follow a different procedure in Gurobi 8.1.1?
Best,
//Stefano
0 -
Hi Stefano,
Do you mean the \( \texttt{facility_cs.cs} \) example doesn't work with Gurobi 8.1.1, or setting the Start attributes doesn't work for your particular model when using Gurobi 8.1.1? In the case of the latter, are you passing the exact same solution to the exact same model when using Gurobi 9.0.1 and 8.1.1? It would be nice to see the log files for both runs.
Eli
0 -
Hi Eli,
What I mean is that setting the "Start" attributes doesn't work in my code when using Gurobi 8.1.1, but it does work when compiled with Gurobi 9.0.1. The code that sets the starting solution is:
for (int j = 0; j < bp_data->n_COL_incumbent; j++) {
error = GRBsetdblattrelement(lp_MASTER_GRB, "Start", bp_data->COL_INDEX_incumbent[j], 1.0);
}
I don't have a log using Gurobi 9.0.1 version, but I can produce one. With 8.1.1, commenting the lines of code I reported makes no difference at all.
//Stefano
0 -
Hi Stefano,
It's possible that Gurobi quickly finds a solution better than the warm-start solution, so the warm start doesn't have any real effect on the solution process. Either way, there should be an indication in the log that Gurobi at least tried to use the warm start.
Note that if the Start attributes are not defined for every variable, Gurobi will try to construct a solution to the problem using the "partial" warm start. Sometimes, Gurobi is unable to construct a complete feasible solution in a reasonable amount of time, so the partial warm start is discarded.
Thanks,
Eli
0
投稿コメントは受け付けていません。
コメント
7件のコメント