Originally posted by: SystemAdmin
Hi everybody, I'm writing a C# program to solve a CPLEX model and I'd like to postprocess feasible solutions, i.e., to show in the log solutions as soon as they are found. I'm also using the solution pool to generate a set of optimal solutions, but I don't think this is an issue (using Solve() instead of Populate() leads to the same result). This is what I'm currently doing:
//... OplSettings oplSettings = oplFactory.CreateOplSettings(oplErrorHandler); OplRunSettings oplRunSettings = oplSettings.getRunSettings(); oplRunSettings.setProcessFeasibleSolutions(
true);
//...
// Solve the model
if (cplex.Populate())
{
int nSolutionsFound = cplex.SolnPoolNsolns; Console.Out.Write(
"Found " + nSolutionsFound +
" solutions");
for (
int i = 0; i < nSolutionsFound; i++)
{
// Postprocess solutions oplModel.SetPoolSolution(i); Console.Out.WriteLine(
"Solution found with objective value: " + cplex.ObjValue); oplModel.PostProcess();
}
}
The problem is that, even if I called setProcessFeasibleSolutions(true), solutions aren't printed as soon as they are found but only when Populate() returns. The assignment is however successful, because after calling the method isProcessFeasibleSolutions() returns true.
Setting the option in the IDE via the checkbox in "Language > Run" in the .ops settings file works just fine. I can guess the problem is in the cplex object TextWriter used as output that can't be used simultaneously by the CPLEX engine and the postprocessing (OPL Scripting?) engine. Since the "Engine log" (where the cplex nodes, cuts, etc. are shown) and the "Scripting log" (where the solutions would be postprocessed when found) can't "interfere", while the "Engine log" is still printing the "Scripting log" can't print anything. If my speculation is true, I could solve this by setting two different TextWriters as outputs for cplex (one for the "Engine log" and the other for the "Scripting log"), but I don't know how since the only related method I found was cplex.SetOut().
Any ideas?
Regards,
Stefano
#DecisionOptimization#OPLusingCPLEXOptimizer