ILOG CPLEX introduction Presenter Mengyen Li Outline Introduction

  • Slides: 40
Download presentation
ILOG CPLEX introduction Presenter: Meng-yen Li

ILOG CPLEX introduction Presenter: Meng-yen Li

Outline • • • Introduction Using the interactive interface Read problem from file LP

Outline • • • Introduction Using the interactive interface Read problem from file LP format Demo with FS problem

Introduction • ILOG CPLEX is an optimization package. • Usually shortened as “cplex” •

Introduction • ILOG CPLEX is an optimization package. • Usually shortened as “cplex” • Named after Simplex method and C language. • Originally developed by Robert E. Bixby. • Now IBM has the acquisition of ILOG CPLEX. • CPLEX was acquired by ILOG in 1997 • ILOG was acquired by IBM in 2009

Capability • • • CPLEX can solve… Very large linear programming problems(LP) Mixed integer

Capability • • • CPLEX can solve… Very large linear programming problems(LP) Mixed integer programming problems(MIP) Quadratic objective programming problems(QP) Quadratic constraint programming problems(QCP)

Reference • “ILOG CPLEX <Version> Getting Started” • Ref. - “ILOG CPLEX 11. 0

Reference • “ILOG CPLEX <Version> Getting Started” • Ref. - “ILOG CPLEX 11. 0 Getting Started”, 2007 • For CPLEX starter. • “ILOG CPLEX <Version> File Formats” • Ref. - “ILOG CPLEX 10. 0 File Formats”, 2006 • For knowing file format detail, especially LP format. • “ILOG CPLEX <Version> User’s Manual” • Ref. - “ILOG CPLEX 9. 0 User’s Manual”, 2003 • For manually using CPLEX Classes and Library in C++. • • • You can get these documents by Google. Current version is 12. 1. 0 Easy / Hard

How to use • CPLEX is currently installed on eda union 13 • Login

How to use • CPLEX is currently installed on eda union 13 • Login to edaunion. ee. ntu. edu. tw: 40063 • Just directly execute cplex – Type cplex • Unfortunately, the License is only for one user. • So if others are using or link dead when using, you may see error message from ILM(license manager)

Interactive Interface r 97160@eda. U 13: ~$ cplex IBM ILOG License Manager: "ntu-taiwan "

Interactive Interface r 97160@eda. U 13: ~$ cplex IBM ILOG License Manager: "ntu-taiwan " is accessing CPLEX 12 with option(s): "e m b q use=1 Maintenance. End=20121031 ". Welcome to CPLEX Interactive Optimizer 12. 1. 0 with Simplex, Mixed Integer & Barrier Optimizers 5724 -Y 48 (c) Copyright IBM Corp. 1988, 2009. All Rights Reserved. CPLEX is a registered trademark of IBM Corp. Type 'help' for a list of available commands. Type 'help' followed by a command name for more information on commands. CPLEX>

Example with manually input CPLEX> enter example Enter new problem ['end' on a separate

Example with manually input CPLEX> enter example Enter new problem ['end' on a separate line terminates]: maximize x 1 + 2 x 2 + 3 x 3 subject to -x 1 + x 2 + x 3 <= 20 x 1 - 3 x 2 + x 3 <= 30 bounds 0 <= x 1 <= 40 0 <= x 2 0 <= x 3 end

Example with manually input CPLEX> enter example Keyword enter with problem name example Enter

Example with manually input CPLEX> enter example Keyword enter with problem name example Enter new problem ['end' on a separate line terminates]: maximize x 1 + 2 x 2 + 3 x 3 subject to -x 1 + x 2 + x 3 <= 20 Problem x 1 - 3 x 2 + x 3 <= 30 Objective Function maximize Subject to constraints subject to bounds Variable bounds 0 <= x 1 <= 40 end to finish input problem 0 <= x 2 0 <= x 3 end

Solving the problem CPLEX> optimize Tried aggregator 1 time. No LP presolve or aggregator

Solving the problem CPLEX> optimize Tried aggregator 1 time. No LP presolve or aggregator reductions. Presolve time = 0. 00 sec. Iteration log. . . Iteration: 1 Dual infeasibility = Iteration: 2 Dual objective = 0. 000000 202. 500000 Dual simplex - Optimal: Objective = 2. 0250000000 e+02 Solution time = 0. 00 sec. Iterations = 2 (1)

View solution CPLEX> display solution variables x 1 -x 3 Variable Name Solution Value

View solution CPLEX> display solution variables x 1 -x 3 Variable Name Solution Value x 1 40. 000000 x 2 17. 500000 x 3 42. 500000

Read problem from file • Manually input is too tedious. • We can read

Read problem from file • Manually input is too tedious. • We can read the problem from file if it is stored in LP format file. • You can read in many ways: • read (then to be prompted to input file name) – example (then to be prompted to input file format) – lp • read example lp (same to above but without prompt) • read example. lp (specify extension also works)

LP format Keyword abbreviation default name enter read e r by manually input (input

LP format Keyword abbreviation default name enter read e r by manually input (input filename) maximize minimize max min (obj) subject to st (c 1 …. cn) bounds end

LP format: variable naming • The variable name cannot be longer than 255 characters

LP format: variable naming • The variable name cannot be longer than 255 characters • All alphanumeric characters (a-z, A-Z, 0 -9) and certain symbols: ! " # $ % & ( ) , . ; ? @ _ ‘ ’ { } ~ can be used. • Any combinations are allowed except the followings. • Cannot start with numbers or period(. ) • Cannot start with e/E with another number or e • (because e is reseverd for exponents and equal sense) • Some examples: – O x 123, x@#$ , #4 x. 3 e, Example – X e 2, eels, . 123, 3 x 4

LP format: constraint naming As previous table shows The default name for objective function

LP format: constraint naming As previous table shows The default name for objective function is obj. The default name for constraints is c 1 … cn. You can change by adding labels before the linear (in)eqaulities. • example: • • max mymax: x 1 + 2 x 2 + 3 x 3 st time: -x 1 + x 2 + x 3 <= 20 labor: x 1 - 3 x 2 + x 3 <= 30

LP format: input limit • Any line with more than 510 characters is truncated.

LP format: input limit • Any line with more than 510 characters is truncated. • You can enter linear (in)equalities on separate lines, but without cutting the variables. • example: – correct input time: -x 1 + x 2 + <return> x 3 <= 20 <return> labor: x 1 - 3 x 2 + x 3 <= 30 <return> – incorrect input time: -x 1 + x 2 + x <return> 3 <= 20 <return> labor: x 1 - 3 x 2 + x 3 <= 30 <return>

LP format: sense • • • X 1 – 3 x 2 + x

LP format: sense • • • X 1 – 3 x 2 + x 3 <= 30 Yellow part is called sense. Blue part is called Right Hand Side(RHS). CPLEX parse constraints by these key parts. So if you add ; after a line(like c/c++) will get this warning. – Warning, line 55: Characters after RHS value are ignored. Sense = Input format <= >= = Synonym <, <=, =<, l(less) >, =>, >=, g(greater) =, e(equal) Note < is interpreted as <= by cplex > is interpreted as => by cplex

LP format: bounds • Variable bounds can enter as – ln <= xn <=

LP format: bounds • Variable bounds can enter as – ln <= xn <= un • You can also separately enter the bounds – ln <= xn – xn =< un • Default setting – lower bound: 0 – upper bound: +∞ • For infinity, set the bounds as +infinity(+inf) / -infinity(-inf) • also you can use free to indicate no bounds – x 7 free – same as –inf <= x 7 <= +inf

LP format: Integer • Add section general/binary to list which variable is integer/0 -1

LP format: Integer • Add section general/binary to list which variable is integer/0 -1 integer. • General/Generals/Gen is all acceptable. • Binary/Binaries/Bin is all acceptable.

LP format: Mixed Integer Maximize obj: x 1 + 2 x 2 + 3

LP format: Mixed Integer Maximize obj: x 1 + 2 x 2 + 3 x 3 + x 4 Subject To c 1: - x 1 + x 2 + x 3 + 10 x 4 <= 20 c 2: x 1 - 3 x 2 + x 3 <= 30 c 3: x 2 - 3. 5 x 4 = 0 Bounds 0 <= x 1 <= 40 2 <= x 4 <= 3 General x 4 Binary x 2 End

Demo • Using CPLEX to solve FS problem • Problem Input: X 0 X

Demo • Using CPLEX to solve FS problem • Problem Input: X 0 X 1 F 0 0 1 0 0 2 0 1 3 0 1 0 1 0 1 1 1 2 1 0 3 1 0 fsp 1. lp(infeasible) fsp 2. lp(has solution)

Formulation X • FS constraint: • f(ma) f(mb) (ma[bit]) (mb[bit]) ma a[0 a[1 a[2

Formulation X • FS constraint: • f(ma) f(mb) (ma[bit]) (mb[bit]) ma a[0 a[1 a[2 a[3 ] ] • (ma[bit]) (mb[bit]) | (ma[bit]) (mb[bit]) | 1 mb b[0 b[1 b[2 b[3 ] ] ( (ma[bit]) (mb[bit]) 1) ( (mb [bit]) (m a[bit]) 1) • At first I didn’t know how to write a Linear Constraint for this, so I wrote a Quadratic Constraint instead. • | (ma[bit]) (mb[bit]) | 1 ( (ma[bit]) (mb[bit]) )2 1 F 1 0 1 1 0 0

Convert constraints in MIQCP min dummy Use dummy variable for there’s no objective function

Convert constraints in MIQCP min dummy Use dummy variable for there’s no objective function x grc group/row/column z grrc group/pairs of row/column problem x x 0 x 1 encode f 0 0 x 001 x 100 1 1 1 0 x 011 x 100 0 2 2 0 x 021 x 100 1 3 3 0 x 031 x 100 1 4 0 1 x 000 x 001 x 110 0 5 1 1 x 010 x 011 x 110 1 6 2 1 x 020 x 021 x 110 0 7 3 1 x 030 x 031 x 110 0 Use to comment a line This problem is infeasible. And if this bit changes to 0 It will become feasible

Convert constraints in MIQCP st full symmetry property pair 01 FSpair 01: [ x

Convert constraints in MIQCP st full symmetry property pair 01 FSpair 01: [ x 000 * x 000 + x 000 * x 001 + x 000 * x 100 - x 000 * x 011 - x 000 * x 100 + x 001 * x 001 + x 001 * x 100 - x 001 * x 011 - x 001 * x 100 + x 100 * x 001 + x 100 * x 100 - x 100 * x 011 - x 100 * x 100 - x 010 * x 001 - x 010 * x 100 + x 010 * x 011 + x 010 * x 100 - x 011 * x 001 - x 011 * x 100 + x 011 * x 011 + x 011 * x 100 - x 100 * x 001 - x 100 * x 100 + x 100 * x 011 + x 100 * x 100 ] >= 1 this is the infeasible one’s FS QC(quadratic constraint) for example, other QC are omitted Quadratic terms must put inside of square brackets []

Convert constraints in MIQCP x 0 encode x 0 pair 01 ENCODEx 0 bit

Convert constraints in MIQCP x 0 encode x 0 pair 01 ENCODEx 0 bit 0 pair 01 LB: x 000 + x 010 - 2 z 0010 >= -1 ENCODEx 0 bit 0 pair 01 UB: x 000 + x 010 - 2 z 0010 <= 0 ENCODEx 0 bit 1 pair 01 LB: x 001 + x 011 - 2 z 0011 >= -1 ENCODEx 0 bit 1 pair 01 UB: x 001 + x 011 - 2 z 0011 <= 0 ENCODEx 0 pair 01: 2 z 0010 + 2 z 0011 - x 000 - x 010 - x 001 - x 011 >= 1 (… from pair 01 to pair 23) x 1 encode x 1 pair 01 ENCODEx 1 bit 0 pair 01 LB: x 100 + x 110 - 2 z 1010 >= -1 ENCODEx 1 bit 0 pair 01 UB: x 100 + x 110 - 2 z 1010 <= 0 Cplex interpret > 0 as >= 0 ENCODEx 1 pair 23: 2 z 1010 - x 100 - x 110 >= 1 here need change to >=1

Convert constraints in MIQCP bin dummy x 0 x 001 x 010 x 011

Convert constraints in MIQCP bin dummy x 0 x 001 x 010 x 011 x 020 x 021 x 030 x 031 x 1 x 100 x 110 z 0 z 0011 z 0020 z 0021 z 0030 z 0031 z 0120 z 0121 z 0130 z 0131 z 0230 z 0231 z 1 z 1010 end Remember to add end at last line

Use the interactive interface CPLEX> read fsp 1. lp Problem 'fsp 1. lp' read.

Use the interactive interface CPLEX> read fsp 1. lp Problem 'fsp 1. lp' read. Read time = 0. 00 sec. CPLEX> display problem stats Problem name: fsp 1. lp Variables : 24 [Binary: 24] Objective nonzeros : 1 Linear constraints : 33 [Less: 13, Greater: 20] Nonzeros : 117 RHS nonzeros : 20 Quadratic constraints: 16 [Greater: 16] Linear terms : 0 Quadratic terms : 256 RHS nonzeros : 16

Use the interactive interface Command needed not to type in full if CPLEX> opt

Use the interactive interface Command needed not to type in full if CPLEX> opt the shortened one is not ambiguous. (…message too long so omitted here) For example, read can also just type r. MIP - Integer infeasible. Current MIP best bound is infinite. Solution time = 0. 12 sec. Iterations = 350 Nodes = 68 (Change the problem and rewrite constraints, store in fsp 2. lp) CPLEX> r fsp 2. lp CPLEX> opt (…message too long so omitted here) Solution pool: 1 solution saved. MIP - Integer optimal solution: Objective = 0. 00000 e+00 Solution time = 0. 01 sec. Iterations = 37 Nodes = 0

Use the interactive interface CPLEX> display sol var * Shortened for command display solution

Use the interactive interface CPLEX> display sol var * Shortened for command display solution variables * Incumbent solution * is a wildcard character which means Variable Name Solution Value any matching characters x 100 1. 000000 that is, display all variables x 020 1. 000000 x 031 1. 000000 x 010 1. 000000 x 011 1. 000000 (…other auxiliary z variables are omitted here) z 1010 1. 000000 All other variables matching '*' are 0.

Solution for FS • CPLEX showed a solution to the problem – x 100

Solution for FS • CPLEX showed a solution to the problem – x 100 x 020 x 031 x 010 x 011 are 1, others are 0 • We got the solution! X 0 X 1 Y 0 0 1 1 1 0 1 1 1 0 0 0 0 1 0 0

Formulation • But now I know how to formulate in Linear Constraint. • |x

Formulation • But now I know how to formulate in Linear Constraint. • |x y| 1 ( (x-y) + M*b 1 ) ( (y-x) + M*(1 -b) 1 ) ( (x-y) + M*b 1 ) ( (y-x) - M*b 1 -M ) • x, y +Integer, b Binary, M is a large enough +integer. • Because |x-y| Max(x, y) (∵ x, y +Integer) • Let M = #bit + 1

FS in Linear Constraint full symmetry property #bit =3, M=4 FSpair 02 p: x

FS in Linear Constraint full symmetry property #bit =3, M=4 FSpair 02 p: x 000 + x 001 + x 100 - x 021 - x 100 + 4 fs 02 >= 1 FSpair 02 n: x 020 + x 021 + x 100 - x 001 - x 100 - 4 fs 02 >= -3 FSpair 03 p: x 000 + x 001 + x 100 - x 031 - x 100 + 4 fs 03 >= 1 FSpair 03 n: x 030 + x 031 + x 100 - x 001 - x 100 - 4 fs 03 >= -3 FSpair 05 p: x 000 + x 001 + x 100 - x 011 - x 110 + 4 fs 05 >= 1 FSpair 05 n: x 010 + x 011 + x 110 - x 001 - x 100 - 4 fs 05 >= -3

FS in Linear Constraint CPLEX> r fsp 3. lp Problem 'fsp 3. lp' read.

FS in Linear Constraint CPLEX> r fsp 3. lp Problem 'fsp 3. lp' read. Read time = 0. 00 sec. CPLEX> dis pro sta Problem name: fsp 3. lp Variables : 39 [Binary: 39] Objective nonzeros : 1 Linear constraints : 63 [Less: 13, Greater: 50] Nonzeros : 275 RHS nonzeros : 50 Variables : Min LB: 0. 000000 Max UB: 1. 000000 Objective nonzeros : Min : 1. 000000 Max : 1. 000000 Linear constraints : Nonzeros : Min : 1. 000000 Max : 4. 000000 RHS nonzeros : Min : 1. 000000 Max : 3. 000000

FS in Linear Constraint CPLEX> opt Tried aggregator 1 time. (…) Root node processing

FS in Linear Constraint CPLEX> opt Tried aggregator 1 time. (…) Root node processing (before b&c): Real time = 0. 01 Parallel b&c, 8 threads: Real time = 0. 00 Sync time (average) = 0. 00 Wait time (average) = 0. 00 ------Total (root+branch&cut) = 0. 01 sec. Solution pool: 1 solution saved. MIP - Integer optimal solution: Objective = 0. 00000 e+00 Solution time = 0. 01 sec. Iterations = 60 Nodes = 0

FS in Linear Constraint CPLEX> dis sol var * Incumbent solution Variable Name Solution

FS in Linear Constraint CPLEX> dis sol var * Incumbent solution Variable Name Solution Value x 000 1. 000000 x 001 1. 000000 x 021 1. 000000 x 030 1. 000000 x 110 1. 000000 (…) All other variables matching '*' are 0.

Solution for FS • CPLEX showed another solution to the problem – x 000

Solution for FS • CPLEX showed another solution to the problem – x 000 x 001 x 021 x 030 x 110 are 1, others are 0. – It’s in fact a complement encoding compare to QCP’s. X 0 X 1 Y 0 0 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 0 0 1 1 0 0 1 0 solution from QCP formulation solution from LP formulation

FS: maxmize multivalue f • Problem Input: X F 0 0 0 2 1

FS: maxmize multivalue f • Problem Input: X F 0 0 0 2 1 1 2 2 3 3 4 0 5 2 6 2 7 0 fsp 5. lp(both function FS feasible) fsp 6. lp(both function FS feasible)

Problem Encoding • X variables: x[minterm][bit] • example : x 71 means 7 -th

Problem Encoding • X variables: x[minterm][bit] • example : x 71 means 7 -th minterm’s “ 1 -th” bit • All start from 0! • Y variables: b[minterm][bit]

Formulation For each pair of two minterm row of X. If Y-multivalue same, skip.

Formulation For each pair of two minterm row of X. If Y-multivalue same, skip. Add LP constraint of b-encoding not same summation not same Min m 0+m 1+… b 00 + b 10 - 2 z >= -1 b 00 + b 10 - 2 z <= 0 2 z - b 00 - b 10 >= 1 =. . . sum 2 - sum 3 +Mfs +(1 -. . . ) + m 0>=1 sum 3 - sum 2 +M(1 -fs)+(1 -. . . ) + m 0>=1

Thank you.

Thank you.