Presentation is loading. Please wait.

Presentation is loading. Please wait.

ILOG CPLEX introduction Presenter: Meng-yen Li. Outline Introduction Using the interactive interface Read problem from file LP format Demo with FS problem.

Similar presentations


Presentation on theme: "ILOG CPLEX introduction Presenter: Meng-yen Li. Outline Introduction Using the interactive interface Read problem from file LP format Demo with FS problem."— Presentation transcript:

1 ILOG CPLEX introduction Presenter: Meng-yen Li

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

3 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

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

5 Reference “ILOG CPLEX Getting Started” Ref. - “ILOG CPLEX 11.0 Getting Started”, 2007 For CPLEX starter. “ILOG CPLEX File Formats” Ref. - “ILOG CPLEX 10.0 File Formats”, 2006 For knowing file format detail, especially LP format. “ILOG CPLEX 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

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

7 Interactive Interface r97160@edaU13:~$ cplex IBM ILOG License Manager: "ntu-taiwan " is accessing CPLEX 12 with option(s): "e m b q use=1 MaintenanceEnd=20121031 ". Welcome to CPLEX Interactive Optimizer 12.1.0 with Simplex, Mixed Integer & Barrier Optimizers 5724-Y48 (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>

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

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

10 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 = 0.000000 Iteration: 2 Dual objective = 202.500000 Dual simplex - Optimal: Objective = 2.0250000000e+02 Solution time = 0.00 sec. Iterations = 2 (1)

11 View solution CPLEX> display solution variables x1-x3 Variable Name Solution Value x1 40.000000 x2 17.500000 x3 42.500000

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

13 LP format Keywordabbreviationdefault name enter read erer by manually input (input filename) maximize minimize max min (obj) subject tost(c1 …. cn) bounds end

14 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 x123, x@#$, #4x.3e, Example – X e2, eels,.123, 3x4

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

16 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: -x1 + x2 + x3 labor: x1 - 3x2 + x3 – incorrect input time: -x1 + x2 + x 3 labor: x1 - 3x2 + x3

17 LP format: sense X1 – 3x2 + x3 <= 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

18 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 – x7 free – same as –inf <= x7 <= +inf

19 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.

20 LP format:Mixed Integer 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 2 <= x4 <= 3 General x4 Binary x2 End

21 Demo Using CPLEX to solve FS problem Problem Input: X0X0 X1X1 F 001 100 201 301 010 111 210 310 X0X0 X1X1 F 000 100 201 301 010 111 210 310 fsp1.lp(infeasible) fsp2.lp(has solution)

22 Formulation FS constraint: f(m a )  f(m b )   (m a [bit])  (m b [bit])  (m a [bit])  (m b [bit])  |  (m a [bit])   (m b [bit]) |  1  (  (m a [bit])   (m b [bit])  1)  (  (m b [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. |  (m a [bit])   (m b [bit]) |  1  (  (m a [bit])   (m b [bit]) ) 2  1 X F 1 mama a[0]a[1]a[2]a[3] 0 1 mbmb b[0]b[1]b[2]b[3] 1 0 0

23 Convert constraints in MIQCP min dummy \x grc group/row/column \z grrc group/pairs of row/column \problem \x x0x1 encode f \0 0 0 x000 x001 x100 1 \1 1 0 x010 x011 x100 0 \2 2 0 x020 x021 x100 1 \3 3 0 x030 x031 x100 1 \4 0 1 x000 x001 x110 0 \5 1 1 x010 x011 x110 1 \6 2 1 x020 x021 x110 0 \7 3 1 x030 x031 x110 0 Use dummy variable for there’s no objective function Use \ to comment a line This problem is infeasible. And if this bit changes to 0 It will become feasible

24 Convert constraints in MIQCP st \full symmetry property \pair01 FSpair01: [ x000 * x000 + x000 * x001 + x000 * x100 - x000 * x010 - x000 * x011 - x000 * x100 + x001 * x000 + x001 * x001 + x001 * x100 - x001 * x010 - x001 * x011 - x001 * x100 + x100 * x000 + x100 * x001 + x100 * x100 - x100 * x010 - x100 * x011 - x100 * x100 - x010 * x000 - x010 * x001 - x010 * x100 + x010 * x010 + x010 * x011 + x010 * x100 - x011 * x000 - x011 * x001 - x011 * x100 + x011 * x010 + x011 * x011 + x011 * x100 - x100 * x000 - x100 * x001 - x100 * x100 + x100 * x010 + x100 * x011 + x100 * x100 ] >= 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 []

25 Convert constraints in MIQCP \x0 encode \x0 pair 01 ENCODEx0bit0pair01LB: x000 + x010 - 2 z0010 >= -1 ENCODEx0bit0pair01UB: x000 + x010 - 2 z0010 <= 0 ENCODEx0bit1pair01LB: x001 + x011 - 2 z0011 >= -1 ENCODEx0bit1pair01UB: x001 + x011 - 2 z0011 <= 0 ENCODEx0pair01: 2 z0010 + 2 z0011 - x000 - x010 - x001 - x011 >= 1 \(… from pair01 to pair23) \x1 encode \x1 pair 01 ENCODEx1bit0pair01LB: x100 + x110 - 2 z1010 >= -1 ENCODEx1bit0pair01UB: x100 + x110 - 2 z1010 <= 0 ENCODEx1pair23: 2 z1010 - x100 - x110 >= 1 Cplex interpret > 0 as >= 0 here need change to >=1

26 Convert constraints in MIQCP bin dummy \x0 x000 x001 x010 x011 x020 x021 x030 x031 \x1 x100 x110 \z0 z0010 z0011 z0020 z0021 z0030 z0031 z0120 z0121 z0130 z0131 z0230 z0231 \z1 z1010 end Remember to add end at last line

27 Use the interactive interface CPLEX> read fsp1.lp Problem 'fsp1.lp' read. Read time = 0.00 sec. CPLEX> display problem stats Problem name: fsp1.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

28 Use the interactive interface CPLEX> opt (…message too long so omitted here) 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 fsp2.lp) CPLEX> r fsp2.lp CPLEX> opt (…message too long so omitted here) Solution pool: 1 solution saved. MIP - Integer optimal solution: Objective = 0.0000000000e+00 Solution time = 0.01 sec. Iterations = 37 Nodes = 0 Command needed not to type in full if the shortened one is not ambiguous. For example, read can also just type r.

29 Use the interactive interface CPLEX> display sol var * Incumbent solution Variable Name Solution Value x100 1.000000 x020 1.000000 x031 1.000000 x010 1.000000 x011 1.000000 (…other auxiliary z variables are omitted here) z1010 1.000000 All other variables matching '*' are 0. Shortened for command display solution variables * * is a wildcard character which means any matching characters that is, display all variables

30 Solution for FS CPLEX showed a solution to the problem – x100 x020 x031 x010 x011 are 1, others are 0 We got the solution! X0X0 X1X1 Y 00 1 0 11 1 0 101 1 011 1 000 0 110 1 100 0 010 0

31 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

32 FS in Linear Constraint \full symmetry property \#bit =3, M=4 FSpair02p: x000 + x001 + x100 - x020 - x021 - x100 + 4 fs02 >= 1 FSpair02n: x020 + x021 + x100 - x000 - x001 - x100 - 4 fs02 >= -3 FSpair03p: x000 + x001 + x100 - x030 - x031 - x100 + 4 fs03 >= 1 FSpair03n: x030 + x031 + x100 - x000 - x001 - x100 - 4 fs03 >= -3 FSpair05p: x000 + x001 + x100 - x010 - x011 - x110 + 4 fs05 >= 1 FSpair05n: x010 + x011 + x110 - x000 - x001 - x100 - 4 fs05 >= -3

33 FS in Linear Constraint CPLEX> r fsp3.lp Problem 'fsp3.lp' read. Read time = 0.00 sec. CPLEX> dis pro sta Problem name: fsp3.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

34 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.0000000000e+00 Solution time = 0.01 sec. Iterations = 60 Nodes = 0

35 FS in Linear Constraint CPLEX> dis sol var * Incumbent solution Variable Name Solution Value x000 1.000000 x001 1.000000 x021 1.000000 x030 1.000000 x110 1.000000 (…) All other variables matching '*' are 0.

36 Solution for FS CPLEX showed another solution to the problem – x000 x001 x021 x030 x110 are 1, others are 0. – It’s in fact a complement encoding compare to QCP’s. X0X0 X1X1 Y 00 1 0 11 1 0 101 1 011 1 000 0 110 1 100 0 010 0 X0X0 X1X1 Y 11 0 0 00 0 0 010 1 100 1 111 0 001 1 011 0 101 0 solution from QCP formulation solution from LP formulation

37 FS: maxmize multivalue f Problem Input: XF 00 11 22 33 40 52 62 70 fsp5.lp(both function FS feasible) XF 02 11 22 33 40 52 62 70 fsp6.lp(both function FS feasible)

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

39 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 m0+m1+… \b00 + b10 - 2z >= -1 \b00 + b10 - 2z <= 0 \2z - b00 - b10 >= 1 =... \sum2 - sum3 +Mfs +(1-...) + m0>=1 \sum3 - sum2 +M(1-fs)+(1-...) + m0>=1

40 Thank you.


Download ppt "ILOG CPLEX introduction Presenter: Meng-yen Li. Outline Introduction Using the interactive interface Read problem from file LP format Demo with FS problem."

Similar presentations


Ads by Google