How to do that highly depends on how your model looks like. What are the variables? What are the constraints?.
In the traveling salesman example that is shipped with CPLEX Optimization Studio you could print the optimal tour by replacing this code in script
if (opl.newSubtourSize == opl.n) {
opl.end();
cplex1.end();
break; // not found
}
by something like this:
if (opl.newSubtourSize == opl.n) {
// This simply prints the selected edges.
for (var e in opl.Edges) {
if (opl.x[e] > 0.5) {
writeln(e.i, " -> ", e.j);
}
}
// This prints the tour as a cycle
var c = 1; // current city
var lastc = -1; // city visited right before C
write(c);
while (true) {
var nextc = -1; // next city to visit
// Find the next city to visit. To this end we
// find the edge that leaves city C and does not
// end in city LASTC. We know that exactly one such
// edge exists, otherwise the solution would be infeasible.
for (var e in opl.Edges) {
if (opl.x[e] > 0.5) {
if (e.i == c && e.j != lastc) {
nextc = e.j;
break;
}
else if (e.j == c && e.i != lastc) {
nextc = e.i;
break;
}
}
}
// Write next city and update current and last city.
write(" -> ", nextc);
lastc = c;
c = nextc;
// Stop if we are back at the origin.
if (c == 1) {
break;
}
}
opl.end();
cplex1.end();
break; // not found
}
If you have a different formulation of the model then the code to print the optimal tour will of course look completely different.
#DecisionOptimization#MathematicalProgramming-General