Concert Technology Slides

57
1 Embedding CPLEX using ILOG Concert Technology Lloyd W. Clarke, Ph.D., CPLEX Product Manager

Transcript of Concert Technology Slides

Page 1: Concert Technology Slides

1

Embedding CPLEX using ILOG Concert TechnologyLloyd W. Clarke, Ph.D., CPLEX Product Manager

Page 2: Concert Technology Slides

2

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

Page 3: Concert Technology Slides

3

ILOGILOGCPLEXCPLEX ILOG SolverILOG Solver

ILOG Concert Technology

Hybrid

Concert Technology

ILOG Optimization Suite

ILOGOPL

Studio

ILOGOPL

StudioILOGILOG

SchedulerSchedulerILOGILOG

DispatcherDispatcherILOGILOG

ConfiguratorConfigurator

Page 4: Concert Technology Slides

4

What is ILOG CPLEX?

❑ ILOG CPLEX Suite Algorithms:❑ Simplex Optimizer❑ Barrier Optimizer (for LP and QP)❑ Mixed Integer Optimizer

❑ ILOG CPLEX Suite Interfaces❑ CPLEX Interactive Optimizer❑ CPLEX Component Libraries

❍ CPLEX Callable Library (a C API)❍ ILOG Concert Technology (a C++ API)❍ Coming soon (a Java API)

Concert Technology

Page 5: Concert Technology Slides

5

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❑ Low memory requirements❑ Reduced runtimes for instantiating models❑ Includes problem modifications

Page 6: Concert Technology Slides

6

Concert Technology

Concert Features for CPLEX

❑ Modeling objects and expressions❑ Constraints, variables, models❑ Row-wise modeling❑ Column-wise modeling❑ Piecewise Linear expressions

❑ Problem modifications❑ Change any part of a model, using modeling objects

❑ Control of CPLEX branch-and-cut with presolve❑ Variable selection❑ Node selection❑ User cuts❑ Heuristics

Page 7: Concert Technology Slides

7

Basic Structure

❑ Environment: ❑ ILOG Concert memory heap that handles

input/output, memory allocation, and other general services for all objects.

❑ Model: ❑ Data facility that holds the problem descriptions.

Multiple models can be used in one environment.

Concert Technology

Page 8: Concert Technology Slides

8

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 memoryreturn 0;

}

Concert Technology

Page 9: Concert Technology Slides

9

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

Page 10: Concert Technology Slides

10

Constant Data Types

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

❑ IloNumArray cParam (env, size);

Data & Decision Variables

Page 11: Concert Technology Slides

11

Variable Data Types

❑ Variables❑ IloNumVar❑ IloFloatVar❑ IloIntVar❑ IloBoolVar❑ IloXXXVarArray❑ Examples

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

Data & Decision Variables

Page 12: Concert Technology Slides

12

Variable ExamplesIloNumVar 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

Data & Decision Variables

Page 13: Concert Technology Slides

13

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❑ Controlling optimization

Page 14: Concert Technology Slides

14

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

Constraints & Objective

Page 15: Concert Technology Slides

15

Summations

❑ Compute sum of x[i]

IloNumVarArray x(env,sizeX,0,IloInfinity);

IloExpr sum = IloSum(x);

Constraints & Objective

Page 16: Concert Technology Slides

16

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);

Constraints & Objective

Page 17: Concert Technology Slides

17

Iterative Expression BuildingIloExpr TotalRevenue(env);

IloExpr TotalProdCost(env);

IloExpr TotalInvCost(env);

for (p = 0; p < nProd; p++)

for (t = 1; t < nTime; t++) {

TotalRevenue += revenue[p][t] * Sell[p][t];

TotalProdCost += prodCost[p] * Make[p][t];

TotalInvCost += invCost[p] * Inv[p][t];

}

Constraints & Objective

Page 18: Concert Technology Slides

18

Constraints

❑ constant <= expression <= constant❑ Method 1

IloRange c(env,2,IloSum(x),4);

model.add(c);

❑ Method 2model.add(2 <= IloSum(x) <= 4);

Constraints & Objective

Page 19: Concert Technology Slides

19

Objective Functions

❑ Method 1model.add(z == IloScalProd( c, x));

model.add(IloMinimize(env, z));

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

Constraints & Objective

Page 20: Concert Technology Slides

20

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

Page 21: Concert Technology Slides

21

Optimizing

IloCplex cplex(model); //extraction

if ( !cplex.solve() ) {

env.error() << "Failed" << endl;

throw(-1);

}

Optimization & Solution Query

Page 22: Concert Technology Slides

22

Querying the Solution

❑ Query functions❑ .getCplexStatus()❑ .getObjValue()❑ .getValue(IloExpr)❑ .getValue(IloNumVar)❑ .getReducedCost(IloNumVar)❑ .getSlack(IloRange)❑ .getDual(IloRange)

❑ Second form❑ .getValues(IloNumArray, IloNumVarArray), ...

Optimization & Solution Query

Page 23: Concert Technology Slides

23

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

Page 24: Concert Technology Slides

24

Facility Location

❑ Determine set of facilities to open to satisfy customer demand minimizing transportation and construction cost

❑ Set of Facilities: j in {1…N}❑ Set of Customers: i in {1…M}❑ 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

Complete Example

Page 25: Concert Technology Slides

25

Facility Location Model

xj - 1 if plant j is open, 0 otherwise

yij - fraction of demand i shipped fromplant j, yij ≥ 0

Min z = ΣiΣj cijyij + Σjfjxjs.t.

Σj yij = 1 ∀ iΣi bi yij ≤ ujxj ∀ j

Complete Example

Page 26: Concert Technology Slides

26

Facility Location Model

xj - 1 if plant j is open, 0 otherwise

IloNumVarArray

open(env, nbLocations, 0, 1, ILOINT);

Complete Example

Page 27: Concert Technology Slides

27

Facility Location Model

yij - fraction of demand i shipped fromplant 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);

Complete Example

Page 28: Concert Technology Slides

28

Facility Location Model

Min z = Σjfjxj + ΣiΣj cijyij

IloExpr obj = IloScalProd(fixedCost, open);

for(i = 0; i < nbClients; i++)

obj += IloScalProd(cost[i], supply[i]);

model.add(IloMinimize(env, obj));

Complete Example

Page 29: Concert Technology Slides

29

Facility Location Model

Σj yij = 1 ∀ i

for(i = 0; i < nbClients; i++)

model.add(IloSum(supply[i]) == 1);

Complete Example

Page 30: Concert Technology Slides

30

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();

}

Complete Example

Page 31: Concert Technology Slides

31

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

Page 32: Concert Technology Slides

32

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.

Column-wise Modeling

Page 33: Concert Technology Slides

33

Example of Column CreationIloNumColumn col1(env);

IloNumColumn col2 = rng1(3.1415);

col1 += obj(1.0);

col1 += rng(-12.0);

col2 += rng2(13.7) + rng3(14.7);

col2 += col1;

Column-wise Modeling

Page 34: Concert Technology Slides

34

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

Column-wise Modeling

Page 35: Concert Technology Slides

35

Column ExampleIloNumVarArray 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();

}

Column-wise Modeling

Page 36: Concert Technology Slides

36

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

Page 37: Concert Technology Slides

37

Piecewise Function

0

0.5

1

1.5

2

2.5

3

3.5

4

1 2 3 4 5 6 7 8

Piecewise Linear Modeling

Page 38: Concert Technology Slides

38

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

❑ FunctionIloPiecewiseLinear(x,

IloNumArray(env, 3, 4, 5, 7),

IloNumArray(env, 4, -.5, 1, -1, 2),

4,2)

Piecewise Linear Modeling

Page 39: Concert Technology Slides

39

Piecewise Function

0

1

2

3

4

5

6

0 2 3 4 5 6 7 8

Piecewise Linear Modeling

Page 40: Concert Technology Slides

40

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

❑ FunctionIloPiecewiseLinear(x,

IloNumArray(env, 4, 3, 3, 5, 5),

IloNumArray(env, 5, 0, 2, .5, 1, -1),

2, 1)

Piecewise Linear Modeling

Page 41: Concert Technology Slides

41

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

Page 42: Concert Technology Slides

42

Modification Functions

❑ Variables❑ .setLb()❑ .setUb()❑ .setBounds()❑ IloConversion();

❑ Objective❑ .setSense()❑ .setCoef()❑ .setExpr()

❑ Ranges❑ .setLb()❑ .setUb()❑ .setBounds()❑ .setCoef()❑ .setExpr()

❑ Model❑ .remove()

Problem Modifications

Page 43: Concert Technology Slides

43

Modification Examplefor (;;) {

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));

cutSolver.solve();

Problem Modifications

Page 44: Concert Technology Slides

44

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

Page 45: Concert Technology Slides

45

Controlling Optimization

❑ LPs - generally easy❑ Try each algorithm (dual, barrier, primal)

❑ MIPs - tuning required at times❑ Algorithm selection❑ Node selection❑ Variable selection❑ Branch selection❑ Feasibility❑ Cuts

Controlling Optimization

Page 46: Concert Technology Slides

46

Algorithm Selection

❑ setRootAlgorithm(), SetNodeAlgorithm()❑ 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

Page 47: Concert Technology Slides

47

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

Controlling Optimization

Page 48: Concert Technology Slides

48

Node Selection

❑ .setParam(NodeSel, i)❑ DFS - depth-first search❑ BestBound* - best-bound search❑ BestEst - best-estimate search❑ BestEstAlt - alternative best-estimate search

❑ NodeCallback()❑ User written routine called prior to node selection❑ examine all remaining nodes and related

information❑ determine next node to solve

Controlling Optimization

Page 49: Concert Technology Slides

49

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

Controlling Optimization

Page 50: Concert Technology Slides

50

Variable Selection

❑ .setPriorities(IloNumArray, IloNumVarArray)❑ sets priority order for all variables in the array❑ during branch, variables with higher priority are

given preference❑ BranchCallback()

❑ 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

Controlling Optimization

Page 51: Concert Technology Slides

51

Branch Direction

❑ .setParam(BrDir, I)❑ BranchGlobal* - automatically determined❑ BranchDown - down branch selected first❑ BranchUp - up branch selected first

❑ .setDirections(IloNumArray, IloNumVarArray)❑ sets the preferred direction for each variable in the

array

Controlling Optimization

Page 52: Concert Technology Slides

52

Feasibility

❑ .setParam(MIPEmphasis, I)❑ MIPEmphasisOptimality*❑ MIPEmphasisFeasibility

❑ HeuristicCallback()❑ user written routine called at each node❑ inquire current node solution❑ change variable bounds❑ resolve node❑ pass new incumbent to CPLEX

Controlling Optimization

Page 53: Concert Technology Slides

53

General Cuts

❑ General cut strategies❑ 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

Page 54: Concert Technology Slides

54

Problem Specific Cuts

❑ CutCallback()❑ user written routine called at each node❑ user can add any number of new range constraints

Controlling Optimization

Page 55: Concert Technology Slides

55

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

Page 56: Concert Technology Slides

56

Next seminars in the series:

Embedding CPLEX Using ILOG OPL Studio Thursday Aug 2 4:00pm Central European Time (10:00am EST)

Remaining Seminars

Page 57: Concert Technology Slides

57

For Further Information

❑ Visit http://optimization.ilog.com

❑ Email: Jim Claussen [email protected]

For Additional Information