Download ILOG CPLEX 8.1 Getting Started
Transcript
THE ANATOMY OF A CONCERT TECHNOLOGY APPLICATION IloCplex cplex(env); again using the environment env as parameter. The CPLEX object can then be used to extract the model to be solved. This can be done by calling cplex.extract(model). However, we recommend a shortcut that performs the construction of the cplex object and the extraction of the model in one line: IloCplex cplex(model); This works because the modeling object model contains within it the reference to the environment named env. After this line, object cplex is ready to solve the optimization problem described by model. Solving the model is done by calling: cplex.solve(); This method returns an IloBool value, where IloTrue indicates that cplex successfully found a feasible (yet not necessarily optimal) solution, and IloFalse indicates that no solution was found. More precise information about the outcome of the last call to method solve() can be obtained by calling: cplex.getStatus(); The returned value tells you what CPLEX found out about the model: whether it found the optimal solution or only a feasible solution, whether it proved the model to be unbounded or infeasible, or whether nothing at all has been determined at this point. Even more detailed information about the termination of the solve call is available through method IloCplex::getCplexStatus(). Querying Results After successfully solving the optimization problem, you probably are interested in accessing the solution. The following methods can be used to query the solution value for a variable or a set of variables: IloNum IloCplex::getValue(IloNumVar var) const; void IloCplex::getValues(IloNumArray val, const IloNumVarArray var) const; For example: IloNum val1 = cplex.getValue(x1); stores the solution value for the modeling variable x1 in variable val1. Other methods are available for querying other solution information. For example, the objective function value of the solution can be accessed using: IloNum objval = cplex.getObjValue(); 70 ILOG CPLEX 8.1 — GETTING STARTED