+ All Categories
Home > Documents > cplexintro

cplexintro

Date post: 14-Oct-2014
Category:
Upload: kregina
View: 152 times
Download: 0 times
Share this document with a friend
Popular Tags:
41
1 Introduction to ILOG CPLEX Copyright © 2004 ILOG, Inc.
Transcript
Page 1: cplexintro

1

Introduction to ILOG CPLEX

Copyright © 2004 ILOG, Inc.

Page 2: cplexintro

2

Overview

• ILOG Optimization Suite

• Mathematical programming Problems

• CPLEX Algorithms

• Building CPLEX applications

• Parallel CPLEX

• Conclusion

Page 3: cplexintro

3

ILOG Optimization Suite

C API VB6 API

ILOGILOGCPLEXCPLEX ILOG SolverILOG Solver

ILOG Concert Technology (C++, Java, .NET)

ILOGOPL

Studio

ILOGOPL

StudioILOGILOG

SchedulerSchedulerILOGILOG

DispatcherDispatcherILOGILOG

ConfiguratorConfigurator

AMPL

A Common API for CPLEX and Solver

Page 4: cplexintro

4

Mathematical Programming

Problem Types

• Linear Programs• Mixed Integer Linear Programs• Quadratic Programs• Mixed Integer Quadratic Programs• Quadratic Constrained Programs• Mixed Integer Quadratic Constrained

Programs

Page 5: cplexintro

5

Linear Programming

Minimize cTxSubject to Ax = b

l ≤ x ≤ u

Objective Function

Constraints

Decision Variables

Lower Bounds

Upper Bounds

Page 6: cplexintro

6

Linear Programming

Minimize cTxSubject to Ax = b

l ≤ x ≤ u

(LP)

Maximizex1 + 2 x2 + 3 x3

Subject To- x1 + x2 + x3 ≤ 20x1 - 3 x2 + x3 ≤ 30

0 ≤ x1 ≤ 40x2, x3 ≥ 0

Page 7: cplexintro

7

Maximize x1 + 2 x2 + 3 x3 + x4Subject To

- x1 + x2 + x3 + 10 x4 ≤ 20x1 - 3 x2 + x3 ≤ 30

x2 - 3.5 x4 = 0

0 ≤ x1 ≤ 40 x2, x3 ≥ 02 ≤ x4 ≤ 3x4 integer

(MIP)

Mixed Integer Programming

Minimize cTxSubject to Ax = b

l ≤ x ≤ uSome x are integer

Page 8: cplexintro

8

Quadratic Programming

Minimize cTx + ½ xTQxSubject to Ax = b

l ≤ x ≤ u

(QP)

Maximizex1 + 2 x2 + 3 x3

- 0.5 ( 33*x1*x1 + 22*x2*x2 +

11*x3*x3 - 12*x1*x2 - 23*x2*x3 )Subject To

- x1 + x2 + x3 ≤ 20x1 - 3 x2 + x3 ≤ 30

0 ≤ x1 ≤ 40x2, x3 ≥ 0

Quadratic Function

Page 9: cplexintro

9

Mixed Integer Quadratic Programming

Minimize cTx + ½ xTQxSubject to Ax = b

l ≤ x ≤ u(MIQP)

Maximizex1 + 2 x2 + 3 x3

- 0.5 ( 33*x1*x1 + 22*x2*x2 + 11*x3*x3 - 12*x1*x2 - 23*x2*x3 )

Subject To- x1 + x2 + x3 ≤ 20

x1 - 3 x2 + x3 ≤ 30

0 ≤ x1 ≤ 40 x1 integerx2, x3 ≥ 0

Some x are integer

Quadratic Function

Page 10: cplexintro

10

Quadratic Constrained Programs

Minimize cTx + ½ xTQxSubject to Ax = b

½ xTQkx + akx ≤ bkl ≤ x ≤ u

(QCP)

Maximizex1 + 2 x2 + 3 x3

- 0.5 ( 33*x1*x1 + 22*x2*x2 + 11*x3*x3 - 12*x1*x2 - 23*x2*x3 )

Subject To- x1 + x2 + x3 ≤ 20

x1 - 3 x2 + x3 ≤ 30x1*x1 + x2*x2 + x3*x3 ≤ 1

0 ≤ x1 ≤ 40x2, x3 ≥ 0

Quadratic Constraint

Page 11: cplexintro

11

Mixed Integer Quadratic Constrained Programs

Minimize cTx + ½ xTQxSubject to Ax = b

½ xTQkx + akx ≤ bkl ≤ x ≤ u

(MIQCP)

Maximizex1 + 2 x2 + 3 x3

- 0.5 ( 33*x1*x1 + 22*x2*x2 + 11*x3*x3 - 12*x1*x2 - 23*x2*x3 )

Subject To- x1 + x2 + x3 ≤ 20

x1 - 3 x2 + x3 ≤ 30x1*x1 + x2*x2 + x3*x3 ≤ 1

0 ≤ x1 ≤ 40 x1 integerx2, x3 ≥ 0

Some x are integer

Quadratic Constraint

Page 12: cplexintro

12

What’s inside ILOG CPLEX?

• ILOG CPLEX Suite contains:• Simplex Optimizers (Primal, Dual, Network) for LP

and QP• Barrier Optimizer for LP, QP, and QCP• Mixed Integer Optimizer for MIP, MIQP and MIQCP• CPLEX Interactive Optimizer• CPLEX Component Libraries

• CPLEX Callable Library (C API and VB6 API)• ILOG Concert Technology (C++, Java, Microsoft .NET APIs)

Page 13: cplexintro

13

CPLEX algorithms

Page 14: cplexintro

14

Linear Programming Algorithms

• Primal simplex• Dual simplex• Network simplex• Primal/dual log barrier

• Includes crossover to simplex solutions

All use automatic CPLEX presolve algorithms

Page 15: cplexintro

15

Quadratic Programming Algorithms

Note: Minimizing (maximizing) a quadratic function requires convexity (concavity)

• Primal dual log barrier• Primal Simplex• Dual Simplex

Page 16: cplexintro

16

Quadratic Constraint Programming Algorithms

• Primal dual log barrier• Based on second-order cone programming

Note: Inequalities require convex regions

Page 17: cplexintro

17

Choosing LP Algorithm

Trends

• Which is Best Algorithm?• Primal versus Dual: 2.3X• Primal versus Barrier: 4.2X• Primal versus Best: 7.5X

• Eliminate the need to choose• Use all algorithms at one time• Concurrent optimization• Requires multiple CPUs

Page 18: cplexintro

18

Concurrent Optimization

• CPU Utilization• # threads = 1: dual• # threads = 2: best of (dual, barrier)• # threads = 3: best of (dual, primal, barrier)• # threads >= 4: best of (dual, primal, parallel

barrier)

• User can customize• Requires a Parallel CPLEX license

Page 19: cplexintro

19

Mixed Integer Programming

Branch-and-Bound Fundamentals

Choose an integer variable: V in [0 ..40]with a non integer current value: 3.7

A new integer feasiblesolution has been foundyesyesdo all integer variables

have integer values?

no

Create two new problems to solve

V ≤ 3V in [0..3]

V ≥ 4V in [4..40]Or

Solve a linear program relaxation

Is it a better solution?

yesyes

Have new incumbent: Fathom

no

Page 20: cplexintro

20

Branch and Bound Tree

Root

Integer

v ≤ 3 v ≥ 4

x ≤2 x ≥ 3

y ≤0 y ≥ 1

z ≤0 z ≥ 1

Integer

Infeas

z ≤0 z ≥ 1

GAP

Lower Bound

Upper Bound

Page 21: cplexintro

21

Branch and Bound Tree

Root

Integer

v ≤ 3 v ≥ 4

x ≤2 x ∆ 3

y ≤0 y ≥ 1

z ≤0 z ≥ 1

Integer

Infeas

z ≤0 z ≥ 1

In the CPLEX MIP Algorithm:

• You pick a variable selection strategy to decide which variable to branch on, and what value to try next

• You pick a node strategy to select which node to work on next

• Often, the default built-in strategies work quite well!

• You can also write your own strategies based upon your own problem knowledge

Page 22: cplexintro

22

CPLEX Presolve Algorithms

Minimize cTxSubject to Ax = b

l ≤ x ≤ uPresolve

Minimize c'Tx' Subject to A'x' = b'

l' ≤ x' ≤ u'

Solve

Solution x'Basis

Dual ValuesUnpresolve

Solution xBasis

Dual Values

Page 23: cplexintro

23

Building a CPLEX application

Page 24: cplexintro

24

ILOG Optimization Suite

ILOGILOGCPLEXCPLEX

ILOGOPL

Studio

ILOGOPL

Studio

CPLEX Callable LibraryCPLEX Callable LibraryILOG Concert TechnologyILOG Concert Technology

CPLEX Callable LibraryILOG Concert Technology

OPL Studio GUIOPL Studio GUIOPL Component LibrariesOPL Component Libraries

CPLEX Component libraries

Page 25: cplexintro

25

Component Libraries Features

• Problem Creation Routines and Methods• Optimization Result Routines and Methods• Utility Routines and Methods• Problem Modification Routines and Methods• Problem Query Routines and Methods• File Reading and Writing Routines and Methods• Parameter Setting Routines and Methods

Page 26: cplexintro

26

Simple LP Application

Raw Data(Database,

Spreadsheet,GUI)

Minimize cTxSubject to Ax = b

l ≤ x ≤ u

CPLEX

Output(Database,

Spreadsheet,GUI)

Transform (c, A, b

, l, u)

(x, c Tx)

Page 27: cplexintro

27

LP Application with Modifications

Raw Data(Database,

Spreadsheet,GUI)

Minimize cTxSubject to Ax = b

l ≤ x ≤ u

CPLEX

Output(Database,

Spreadsheet,GUI)

Transform (c, A, b

, l, u)

(x, c Tx)

Modify

Page 28: cplexintro

28

What are Hot Starts?

Basis

Minimize cTxSubject to Ax = b

l ≤ x ≤ u

Minimize c'TxSubject to A'x = b'

l' ≤ x ≤ u'

Solve

Use

Modify

Solve One ProblemObtain Solution

Modify The ProblemSolution Not Optimal

Solve the Modified ProblemUsing the Prior Solution to Start

Page 29: cplexintro

29

It’s all about how you model…..

• CPLEX Callable Library uses matrices to represent a problem

• Users map their model to a linear ordering

• ILOG Concert Technology uses objects and methods to represent a problem

• Users write out the mathematical representation in C++, Java, VB .NET, C# (or any .NET language)

• C++ features operator overloading for ease of expression

• A modeling language in C++, Java and .NET

• ILOG OPL Component Libraries allow OPL models to be embedded inside an application

• Provided inside ILOG OPLStudio (Requires an ILOG OPL Studio license)

Page 30: cplexintro

30

A Simple MIP Example

Maximize

obj: x1 + 2 x2 + 3 x3 + x4

Subject To

c1: - x1 + x2 + x3 + 10 x4 ≤ 20

c2: x1 - 3 x2 + x3 ≤ 30

c3: x2 - 3.5 x4 = 0

Bounds

0 ≤ x1 ≤ 40 x2, x3 ≥ 0

2 ≤ x4 ≤ 3

Integers

x4

End

-1 1 1 101 -3 1 00 1 0 -3.5

Matrix representation

Page 31: cplexintro

31

Simple MIP with C

strcpy (probname, "example");*numcols_p = 4;*numrows_p = 3;*objsen_p = CPX_MAX; /* The problem is maximization */

/* The code is formatted to make a visual correspondencebetween the mathematical linear program and the specific dataitems. */

obj[0] = 1.0; obj[1] = 2.0; obj[2] = 3.0; obj[3] = 1.0;

matbeg[0] = 0; matbeg[1] = 2; matbeg[2] = 5; matbeg[3] = 7;matcnt[0] = 2; matcnt[1] = 3; matcnt[2] = 2; matcnt[3] = 2;

matind[0] = 0; matind[2] = 0; matind[5] = 0; matind[7] = 0;matval[0] = -1.0; matval[2] = 1.0; matval[5] = 1.0; matval[7] = 10.0;

matind[1] = 1; matind[3] = 1; matind[6] = 1;matval[1] = 1.0; matval[3] = -3.0; matval[6] = 1.0;

matind[4] = 2; matind[8] = 2;matval[4] = 1.0; matval[8] = -3.5;

lb[0] = 0.0; lb[1] = 0.0; lb[2] = 0.0; lb[3] = 2.0;ub[0] = 40.0; ub[1] = CPX_INFBOUND; ub[2] = CPX_INFBOUND; ub[3] = 3.0;

ctype[0] = 'C'; ctype[1] = 'C'; ctype[2] = 'C'; ctype[3] = 'I';

/* The right-hand-side values don't fit nicely on a line above. So putthem here. */

sense[0] = 'L';rhs[0] = 20.0;

sense[1] = 'L';rhs[1] = 30.0;

sense[2] = 'E';rhs[2] = 0.0;

Page 32: cplexintro

32

Data Structures for C Callable Library

1.0E200.0

1.0 1.0

1.0E20

1.0

matbeg 2 5 7matcnt 3 2 3matind 1 0 1 2 0 1 0 2matval -1.0 -3.0 1.0 1.0 10.0 -3.5obj 1.0 2.0 3.0 4.0lb 0.0 0.0 2.0ub 40.0 3.0ctype C C C

sense L L E -1 1 1 101 -3 1 00 1 0 -3.5

Non zero elements

0

Irhs 20.0 30.0 0.0

Page 33: cplexintro

33

Same MIP with Concert Technology (C++)

IloEnv env;IloModel mip(env);

// Declaring the variables; x4 is integerIloNumVar x1(env, 0.0, 40.0, "x1");IloNumVar x2(env, 0.0, IloInfinity, "x2");IloNumVar x3(env, 0.0, IloInfinity, "x3");IloNumVar x4(env, 2, 3, ILOINT, "x4");

// Adding the constraints :mip.add(-x1 + x2 + x3 + 10*x4 <= 20);mip.add( x1 - 3*x2 + x3 <= 30);mip.add( x2 - 3.5*x4 == 0);

// Setting the objectivemip.add(IloMaximize(env, x1 + 2*x2 + 3*x3 + x4));

Page 34: cplexintro

34

Solving the MIP

IloCplex cplex(mip);cplex.solve();

env.out() << "Solution status = " << cplex.getStatus() << endl;

env.out() << "Solution value = " << cplex.getObjValue() << endl;

env.out() << cplex.getValue(x1) << endl;env.out() << cplex.getValue(x2) << endl;env.out() << cplex.getValue(x3) << endl;env.out() << cplex.getValue(x4) << endl;

Page 35: cplexintro

35

Simple Arrays

/* Read in an array of numbers */IloNumArray mydata(env);ifstream file("mydata.dat");file >> mydata;IloInt n = mydata.getSize();

/* Create an array x of variables */IloNumVarArray x(env, n, 0.0, IloInfinity);

/* Add a constraint */model.add (IloScalProd(mydata, x) <= 15);

[5, 4, 9, 8, 7,6, 4, 3, 10, 2]

Page 36: cplexintro

36

Complex Arrays

var float make[Prod,Time];// ...forall(t in Time)

sum(p in Prod) (1/rate[p])*make[p,t] <= avail[t];

OPL

typedef IloArray<IloNumVarArray> IloNumVarArray2;// ...IloNumVarArray2 Make(env);

for (p = 0; p < nProd; p++)Make.add(IloNumVarArray(env, nTime, 0.0,IloInfinity));

// ...for (t = 0; t < nTime; t++) {

IloExpr availExpr(env); for (p = 0; p < nProd; p++)

availExpr += (1/rate[p]) * Make[p][t]; mod.add(availExpr <= avail[t]);

}

Concert(C++)

Page 37: cplexintro

37

CPLEX Parameters

• CPLEX offers a variety of parameters to control various algorithmic and display choices.

• All parameters have a default value which is sufficient in most of the cases.

• Parameters are accessible via all theinterfaces

Page 38: cplexintro

38

CPLEX Parameters

• CPLEX parameters can be subdivided in several categories according to their aims. There are:

• General parameters (example : set clocktype)• Starting and preprocessing parameters• Simplex parameters• Barrier parameters• Network parameters• MIP parameters

• CPLEX parameters are too numerous for a complete enumeration here (see the CPLEX 9.0 Reference Manual).

Page 39: cplexintro

39

CPLEX Parameters Settings Hints

• Default works well to prove optimality or to find good feasible solutions for most models

• Try it first• CPLEX has an emphasis setting.

• Using it to specify a goal may help for some models• Several features are off by default

• Turning them on or changing parameter settings can help solving hard models

• CPLEX provides advanced routines for exploiting user knowledge

• They can be helpful for hard models, e.g. their use for extending Gomory cuts for handling side constraints

Page 40: cplexintro

40

Parallel CPLEX

• Provides scalability on symmetric multi-processor (SMP) shared memory systems

• For extremely high-performance applications• Very large LPs or QPs• Very hard MIPs

• Speed-ups vary by problem type and instance• Barrier: sub-linear, but better than simplex• MIP: variable, may be super-linear!

Page 41: cplexintro

41

Conclusion

• CPLEX Algorithms• Simplex Optimizers (Primal, Dual, Network) (LP / QP)• Barrier Optimizer (LP / QP/ QCP)• Mixed Integer Optimizer (MILP / MIQP/ MIQCP)

• CPLEX Component Libraries• CPLEX Callable Library (C API)• ILOG Concert Technology (C++/Java/.NET API)

• Parallel CPLEX as an option


Recommended