Concert Technology Slides

Post on 10-Oct-2014

81 views 3 download

Transcript of Concert Technology Slides

1

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

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

3

ILOGILOGCPLEXCPLEX ILOG SolverILOG Solver

ILOG Concert Technology

Hybrid

Concert Technology

ILOG Optimization Suite

ILOGOPL

Studio

ILOGOPL

StudioILOGILOG

SchedulerSchedulerILOGILOG

DispatcherDispatcherILOGILOG

ConfiguratorConfigurator

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

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

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

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

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

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

10

Constant Data Types

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

❑ IloNumArray cParam (env, size);

Data & Decision Variables

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

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

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

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

15

Summations

❑ Compute sum of x[i]

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

IloExpr sum = IloSum(x);

Constraints & Objective

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

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

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

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

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

21

Optimizing

IloCplex cplex(model); //extraction

if ( !cplex.solve() ) {

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

throw(-1);

}

Optimization & Solution Query

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

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

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

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

26

Facility Location Model

xj - 1 if plant j is open, 0 otherwise

IloNumVarArray

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

Complete Example

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

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

29

Facility Location Model

Σj yij = 1 ∀ i

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

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

Complete Example

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

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

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

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

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

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

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

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

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

39

Piecewise Function

0

1

2

3

4

5

6

0 2 3 4 5 6 7 8

Piecewise Linear Modeling

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

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

42

Modification Functions

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

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

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

❑ Model❑ .remove()

Problem Modifications

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

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

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

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

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

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

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

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

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

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

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

54

Problem Specific Cuts

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

Controlling Optimization

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

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

57

For Further Information

❑ Visit http://optimization.ilog.com

❑ Email: Jim Claussen jclaussen@ilog.com

For Additional Information