Sie sind auf Seite 1von 57

Embedding CPLEX using ILOG Concert Technology

Lloyd W. Clarke, Ph.D., CPLEX Product Manager

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimizing Queries Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization

Concert Technology

ILOG Optimization Suite

ILOG OPL Studio

ILOG Scheduler

ILOG ILOG Dispatcher Configurator

ILOG CPLEX

Hybrid

ILOG Solver

ILOG Concert Technology

Concert Technology

What is ILOG CPLEX?


ILOG CPLEX Suite Algorithms:

Simplex Optimizer Barrier Optimizer (for LP and QP) Mixed Integer Optimizer CPLEX Interactive Optimizer CPLEX Component Libraries
CPLEX Callable Library (a C API) ILOG Concert Technology (a C++ API) Coming soon (a Java API)

ILOG CPLEX Suite Interfaces


Concert Technology

Features and Benefits


Common modeling layer for LP, IP, QP, and

CP, with model/algorithm separation


Facilitates easy comparisons of algorithmic technologies Makes all ILOG C++ optimization libraries easier to use

Supported and complete C++ interface for

CPLEX

5

Low memory requirements Reduced runtimes for instantiating models Includes problem modifications

Concert Technology

Concert Features for CPLEX


Modeling objects and expressions

Constraints, variables, models Row-wise modeling Column-wise modeling Piecewise Linear expressions Change any part of a model, using modeling objects Variable selection Node selection User cuts Heuristics

Problem modifications

Control of CPLEX branch-and-cut with presolve



6

Concert Technology

Basic Structure
Environment:

ILOG Concert memory heap that handles input/output, memory allocation, and other general services for all objects. Data facility that holds the problem descriptions. Multiple models can be used in one environment.

Model:

Concert Technology

Concert Technology Program Structure


int main(int argc, char **argv) { IloEnv env; try { IloModel model(env); // ... // gather data, create model, // solve model, query solution, change model // ... } catch (IloException& e) { cerr << e << endl; } env.end(); // free all memory return 0; }

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimizing Queries Complete example Column-wise modeling Piecewise linear modeling Problem modifications
9

Controlling optimization

Data & Decision Variables

Constant Data Types


IloNum; IloInt; IloBool; IloNumArray; IloFloatArray; IloIntArray; IloBoolArray;

IloNumArray cParam (env, size);

10

Data & Decision Variables

Variable Data Types


Variables

IloNumVar IloFloatVar IloIntVar IloBoolVar IloXXXVarArray Examples


IloNumVar x(env, lb, ub, type, name); IloNumVarArray xArray(env, size, lb, ub, type);

11

Data & Decision Variables

Variable Examples
IloNumVar x(env, 0, IloInfinity, ILOFLOAT); IloIntVar y(env, 10, 25,"varY"); IloBoolVar z(env); IloFloatVarArray A1(env, 20, 0, 9999); IloNumVarArray A2(env, 10, 1, x, ILOFLOAT); IloNumVarArray A3(env, 3); A3[0] = x

12

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective Optimizing Queries Complete example Column-wise modeling Piecewise linear modeling Problem modifications
13

Controlling optimization

Constraints & Objective

Expressions
Addition, subtraction, multiplication and

division between different objects are allowed


When numerical variables are combined with

operators to express a sum, a product, etc., the composed object is an instance of the class IloExpr

14

Constraints & Objective

Summations
Compute sum of x[i]

IloNumVarArray x(env,sizeX,0,IloInfinity); IloExpr sum = IloSum(x);

15

Constraints & Objective

Scalar Products
compute sum of c[i]*x[i] IloNumVarArray x(env,sizeX,0,IloInfinity); IloNumArray c(env,sizeX); for (IloInt i=0; i<sizeX; i++) c[i]=i; IloExpr sum = IloScalProd(c,x);

16

Constraints & Objective

Iterative Expression Building


IloExpr TotalRevenue(env); IloExpr TotalProdCost(env); IloExpr TotalInvCost(env); for (p = 0; p < nProd; p++) for (t = 1; t < nTime; t++) { TotalRevenue TotalInvCost } += revenue[p][t] * Sell[p][t]; += invCost[p] * Inv[p][t]; TotalProdCost += prodCost[p] * Make[p][t];

17

Constraints & Objective

Constraints
constant <= expression <= constant Method 1 IloRange c(env,2,IloSum(x),4); model.add(c); Method 2 model.add(2 <= IloSum(x) <= 4);

18

Constraints & Objective

Objective Functions
Method 1
model.add(z == IloScalProd( c, x)); model.add(IloMinimize(env, z));

Method 2
model.add(IloMinimize(env,IloScalProd(c,x)));

19

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization
20

Optimization & Solution Query

Optimizing
IloCplex cplex(model); if ( !cplex.solve() ) { env.error() << "Failed" << endl; throw(-1); } //extraction

21

Optimization & Solution Query

Querying the Solution


Query functions

.getCplexStatus() .getObjValue() .getValue(IloExpr) .getValue(IloNumVar) .getReducedCost(IloNumVar) .getSlack(IloRange) .getDual(IloRange) .getValues(IloNumArray, IloNumVarArray), ...

Second form

22

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization
23

Complete Example

Facility Location
Determine set of facilities to open to satisfy

customer demand minimizing transportation and construction cost


Set of Facilities: j in {1N} Set of Customers: i in {1M} b(i) - total demand of customer i c(i,j) - cost of shipping total demand of

customer I from plant j


f(j) - cost of open plant j u(j) - capacity of plant j
24

Complete Example

Facility Location Model


xj - 1 if plant j is open, 0 otherwise yij - fraction of demand i shipped from plant j, yij 0

Min z = ij cijyij + jfjxj s.t. j yij = 1 i j i bi yij ujxj

25

Complete Example

Facility Location Model


xj - 1 if plant j is open, 0 otherwise IloNumVarArray open(env, nbLocations, 0, 1, ILOINT);

26

Complete Example

Facility Location Model


yij - fraction of demand i shipped from plant j, yij 0
typedef IloArray<IloNumVarArray> NumVarMatrix; NumVarMatrix supply(env, nbClients); for(i = 0; i < nbClients; i++) supply[i] = IloNumVarArray(env, nbLocations, 0, IloInfinity, ILOFLOAT);

27

Complete Example

Facility Location Model


Min z = jfjxj + ij cijyij
IloExpr obj = IloScalProd(fixedCost, open); for(i = 0; i < nbClients; i++) obj += IloScalProd(cost[i], supply[i]); model.add(IloMinimize(env, obj));

28

Complete Example

Facility Location Model


j yij = 1 i

for(i = 0; i < nbClients; i++) model.add(IloSum(supply[i]) == 1);

29

Complete Example

Facility Location Model


i bi yij ujxj j

for(j = 0; j < nbLocations; j++) { IloExpr v(env); for(i = 0; i < nbClients; i++) v += demand[i]*supply[i][j]; model.add(v <= capacity[j] * open[j]); v.end(); }

30

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization
31

Column-wise Modeling

Creating Columns
An instance of IloNumColumn enables you to

store informations on the column you want to create.


An IloNumColumn instance can be filled by operator (), with an IloNum argument, of IloRange and IloObjective.

32

Column-wise Modeling

Example of Column Creation


IloNumColumn col1(env); IloNumColumn col2 = rng1(3.1415); col1 += obj(1.0); col1 += rng(-12.0); col2 += rng2(13.7) + rng3(14.7); col2 += col1;

33

Column-wise Modeling

Creating an Instance by Columns


Declare objective function w/ null expression Declare range array with lb, ub and null

expression
Add objective and constraints to model Define columns Associate columns with variables

34

Column-wise Modeling

Column Example
IloNumVarArray Buy(env); IloRangeArray range (env, nutrMin, nutrMax); IloObjective cost = IloMinimize(env); mod.add(range); mod.add(obj); for (j = 0; j < n; j++) { IloNumColumn col = cost(foodCost[j]); for (i = 0; i < m; i++) col += range[i](nutrPer[i][j]); Buy.add(IloNumVar(col,foodMin[j],foodMax[j])); col.end(); }
35

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling Optimization
36

Piecewise Linear Modeling

Piecewise Function
4 3.5 3 2.5 2 1.5 1 0.5 0 1 2 3 4 5 6 7 8

37

Piecewise Linear Modeling

Piecewise Function in Concert Tech


Information Needed

variable: x breakpoints: 4, 5, 7 slopes: -0.5, 1, -1, 2 coordinates of a point: 4, 2

Function
IloPiecewiseLinear(x, IloNumArray(env, 3, 4, 5, 7), IloNumArray(env, 4, -.5, 1, -1, 2), 4,2)
38

Piecewise Linear Modeling

Piecewise Function
6 5 4 3 2 1 0 0 2 3 4 5 6 7 8

39

Piecewise Linear Modeling

Piecewise Function in Concert Tech


Information Needed

variable: x breakpoints: 3, 3, 5, 5 slopes, steps: 0, 2, .5, 1, -1 coordinates of a point: 2, 1

Function
IloPiecewiseLinear(x, IloNumArray(env, 4, 3, 3, 5, 5), IloNumArray(env, 5, 0, 2, .5, 1, -1), 2, 1)
40

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization
41

Problem Modifications

Modification Functions
Variables

Ranges

.setLb() .setUb() .setBounds() IloConversion(); .setSense() .setCoef() .setExpr()

.setLb() .setUb() .setBounds() .setCoef() .setExpr() .remove()

Objective

Model

42

Problem Modifications

Modification Example
for (;;) { cutSolver.solve(); for (i = 0; i < nWdth; i++) price[i] = -cutSolver.getDual(Fill[i]); ReducedCost.setCoef(Use, price); patSolver.solve(); if (patSolver.getValue(ReducedCost) > -RC_EPS) break; patSolver.getValues(newPatt, Use); Cut.add(IloNumVar(RollsUsed(1)+Fill(newPatt)) ); } cutOpt.add(IloConversion(env, Cut, ILOINT));
43

cutSolver.solve();

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization
44

Controlling Optimization

Controlling Optimization
LPs - generally easy

Try each algorithm (dual, barrier, primal) Algorithm selection Node selection Variable selection Branch selection Feasibility Cuts

MIPs - tuning required at times


45

Controlling Optimization

Algorithm Selection
setRootAlgorithm(), SetNodeAlgorithm()

46

AutoAlg* - CPLEX chooses algorithm Primal - primal simplex algorithm Dual - dual simples algorithm Barrier - barrier algorithm NetworkPrimal - network simplex on embedded network followed by primal simplex NetworkDual - network simplex on embedded network followed by primal simplex DualBarrier - dual simplex followed by barrier

Controlling Optimization

Algorithm Selection
SolveCallback()

User written routine called at each node Examine model and recent solution Determine what algorithm to use and ask CPLEX to solve Determine solution and pass to CPLEX without CPLEX solving

47

Controlling Optimization

Node Selection
.setParam(NodeSel, i)

DFS - depth-first search BestBound* - best-bound search BestEst - best-estimate search BestEstAlt - alternative best-estimate search User written routine called prior to node selection examine all remaining nodes and related information determine next node to solve

NodeCallback()

48

Controlling Optimization

Variable Selection
.setParam(VarSel, i)

MinInfeas - variable with minimum infeasibility DefaultVarSel* - variable automatically selected MaxInfeas - variable with maximum infeasibility Pseudo - branch based on pseudo costs Strong - strong branching PseudoReduced - branch based on pseudo reduced cost

49

Controlling Optimization

Variable Selection
.setPriorities(IloNumArray, IloNumVarArray)

sets priority order for all variables in the array during branch, variables with higher priority are given preference user written routine called at each node inquire about impending CPLEX branch prune the node create new branch (1 or 2) uses any number of variables

BranchCallback()

50

Controlling Optimization

Branch Direction
.setParam(BrDir, I)

BranchGlobal* - automatically determined BranchDown - down branch selected first BranchUp - up branch selected first sets the preferred direction for each variable in the array

.setDirections(IloNumArray, IloNumVarArray)

51

Controlling Optimization

Feasibility
.setParam(MIPEmphasis, I)

MIPEmphasisOptimality* MIPEmphasisFeasibility user written routine called at each node inquire current node solution change variable bounds resolve node pass new incumbent to CPLEX

HeuristicCallback()

52

Controlling Optimization

General Cuts
General cut strategies

53

Clique Cuts Cover Cuts Disjunctive Cuts Flow Cover Cuts Flow Path Cuts Gomory Fractional Cuts Generalized Upper Bound (GUB) Cuts Implied Bound Cuts Mixed Integer Rounding (MIR) Cuts

Controlling Optimization

Problem Specific Cuts


CutCallback()

user written routine called at each node user can add any number of new range constraints

54

Modeling with Concert Technology


Introduction to Concert Technology Data and decision variables Constraints and objective function Optimization and solution query Complete example Column-wise modeling Piecewise linear modeling Problem modifications Controlling optimization
55

Remaining Seminars

Next seminars in the series:

Embedding CPLEX Using ILOG OPL Studio


Thursday Aug 2 4:00pm Central European Time (10:00am EST)

56

For Additional Information

For Further Information


Visit http://optimization.ilog.com Email: Jim Claussen jclaussen@ilog.com

57

Das könnte Ihnen auch gefallen