Solving the Model with IloCplex

After the model has been populated, we are ready to create the cplex object and extract the model to it by calling:

IloCplex cplex(mod); 

It is then ready to solve the model, but for demonstration purposes we first write the extracted model to file diet.lp. Doing so can help you debug your model, as the file contains exactly what CPLEX sees. If it does not match what you expected, it will probably help you locate the code that generated the wrong part.

The model is then solved by calling method solve(). Finally, the solution status and solution vector are output to the output channel cplex.out(). By default this channel is initialized to cout. All logging during optimization is also output to this channel. To turn off logging, you would set the out() stream of cplex to a null stream by calling cplex.setOut(env.getNullStream()).


Previous Page: Program Description  Return to Top Next Page: Complete Program