12.07.2015 Views

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Once the model is created, solving it and querying the solution is straightforward. Whatremains to be pointed out is the exception handling. In case of an error, <strong>ILOG</strong> <strong>CPLEX</strong> willthrow an exception of type IloException or one of its subclasses. Thus the entire<strong>ILOG</strong> <strong>CPLEX</strong> program is enclosed in try/catch statements. The InputDataReader canthrow exceptions of type java.io.IOException orInputDataReader.InputDataReaderException.Since none of these three possible exceptions is handled elsewhere, the main function endsby catching them and issuing appropriate error messages.The call to the method cplex.end frees the memory that <strong>ILOG</strong> <strong>CPLEX</strong> uses.The entire source code listing for the example is available as Diet.java in the standarddistribution at your<strong>CPLEX</strong>installation/examples/src.Modifying the ModelAn important feature of <strong>ILOG</strong> <strong>CPLEX</strong> is that you can modify a previously created model toconsider different scenarios. Furthermore, depending on the optimization model andalgorithm used, <strong>ILOG</strong> <strong>CPLEX</strong> will save as much information from a previous solution aspossible when optimizing a modified model.The most important modification method is IloModel.add, for adding modeling objects tothe active model. Conversely, you can use IloModel.remove to remove a modeling objectfrom a model, if you have previously added that object.When you add a modeling object such as a ranged constraint to a model, all the variablesused by that modeling object implicitly become part of the model as well. However, whenyou remove a modeling object, no variables are implicitly removed from the model. Instead,variables can only be explicitly removed from a model by calling IloMPModeler.delete.(The interface IloMPModeler derives from the class IloModel, among others. It isimplemented by the class IloCplex.) This call will cause the specified variables to bedeleted from the model, and thus from all modeling objects in the model that are using thesevariables. In other words, deleting variables from a model may implicitly modify othermodeling objects in that model.The API of specific modeling objects may provide modification methods. For example, youcan change variable bounds by using the methods IloNumVar.setLB andIloNumVar.setUB. Similarly, you can change the bounds of ranged constraints by usingIloRange.setLB and IloRange.setUB.Because not all the optimizers that implement the IloModeler interface support the abilityto modify a model, modification methods are implemented in IloMPModeler. Thesemethods are for manipulating the linear expressions in ranged constraints and objectivefunctions used with IloCplex. The methods IloMPModeler.setLinearCoef,94 <strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!