ILOG CPLEX l CPLEX is a product developed

  • Slides: 25
Download presentation
ILOG CPLEX l CPLEX is a product developed by ILOG to solve Ø Ø

ILOG CPLEX l CPLEX is a product developed by ILOG to solve Ø Ø Ø LPs MIPs QPs MIQPs Network Flow problems l CPLEX technologies Ø CPLEX callable library (for C) Ø CPLEX interactive optimizer Ø Concert Technology (for C++) l Compatible platforms Ø Windows Ø Unix. 1

CPLEX interactive optimizer l An interactive program to Ø Load models in PC. Ø

CPLEX interactive optimizer l An interactive program to Ø Load models in PC. Ø Applying algorithms. l Supports features like Ø Ø Choosing different algorithms for problems. Change the specifications in the problem. Sensitivity analysis. Re-optimizing the problem. 2

Tutorial for CPLEX interactive optimizer in Unix To connect the iseunix machine you can

Tutorial for CPLEX interactive optimizer in Unix To connect the iseunix machine you can use SSH Secure Shell, which you can download a trial version from http: //ftp. ssh. com/pub/ssh/SSHSecure. Shell. Client-3. 2. 9. exe 3

1. Use SSH (Secure shell) to connect to iseunix machine. When you hit the

1. Use SSH (Secure shell) to connect to iseunix machine. When you hit the connect button it will ask the password, which is: tempaccess 6417, it is good until November 22. 2. Create a folder under your name and run your programs under this directory. You can do that by opening the file transfer window, by clicking the yellow folder with blue dots on it. 3. Type cplex and press enter. 4

5

5

CPLEX interactive optimizer (help) l Type help on the command prompt to see the

CPLEX interactive optimizer (help) l Type help on the command prompt to see the options. CPLEX> help add baropt change display enter help mipopt netopt optimize primopt quit read set tranopt write xecute add constraints to the problem solve using barrier algorithm change the problem display problem, solution, or parameter settings enter a new problem provide information on CPLEX commands solve a mixed integer program solve the problem using network method solve the problem (default is dual-simplex) solve using the primal method leave CPLEX read problem or basis information from a file set parameters solve using the dual method write problem or solution info. to a file execute a command from the OS 6

Entering a problem from the keyboard CPLEX> enter Enter name for problem: example Enter

Entering a problem from the keyboard CPLEX> enter Enter name for problem: example Enter new problem ['end' on a separate line terminates]: max 4 x+6 y subject to x+y<5 End CPLEX> optimize Tried aggregator 1 time. LP Presolve eliminated 1 rows and 2 columns. All rows and columns eliminated. Presolve time = 0. 00 sec. Dual simplex - Optimal: Objective = 3. 00000 e+01 Solution time = 0. 00 sec. Iterations = 0 (0) 7

CPLEX> display Display Options: iis display infeasibility diagnostics (IIS constraints) problem display problem characteristics

CPLEX> display Display Options: iis display infeasibility diagnostics (IIS constraints) problem display problem characteristics sensitivity display sensitivity analysis settings display parameter settings solution display existing solution Display what: solution Display Solution Options: basis display a range of basic constraints or variables bestbound display the current MIP best bound dual display a set of solution dual values kappa display the condition number of the basis matrix objective display solution objective value qcslacks display a set of solution quadratic constraint slack values quality display quality of solution reduced display a set of solution reduced costs slacks display a set of solution slack values variables display a set of solution variable values Display which part of the solution: var Display values of which variable(s): Variable Name Solution Value y 5. 000000 All other variables in the range 1 -2 are zero. 8

Reading from the input file l Example input file: max 4 x+6 y subject

Reading from the input file l Example input file: max 4 x+6 y subject to x+y<5 End l Save it as example. lp under your directory, let us say your directory is called “ 6417 example” 9

CPLEX> read 6417 example/example. lp Problem '6417 example/example. lp' read. Read time = 0.

CPLEX> read 6417 example/example. lp Problem '6417 example/example. lp' read. Read time = 0. 00 sec. CPLEX> optimize Tried aggregator 1 time. LP Presolve eliminated 1 rows and 2 columns. All rows and columns eliminated. Presolve time = 0. 00 sec. Dual simplex - Optimal: Objective = 3. 00000 e+01 Solution time = 0. 00 sec. Iterations = 0 (0) CPLEX> display solution variables – (shows all optimal variable values) 10

l CPLEX> display problem all Maximize obj: 4 x + 6 y Subject To

l CPLEX> display problem all Maximize obj: 4 x + 6 y Subject To c 1: x + y <= 5 Bounds All variables are >= 0. CPLEX> add Enter new constraints and bounds ['end' terminates]: x+y<8 end Problem addition successful. 11

Binary or integer variables l Before end we need to write Binaries x y

Binary or integer variables l Before end we need to write Binaries x y int z t End 12

Choosing an optimizer l For optimizing, the default solver is dual-simplex. l Other optimizers

Choosing an optimizer l For optimizing, the default solver is dual-simplex. l Other optimizers can be chosen by these commands, Ø primopt primal simplex optimizer Ø tranopt dual simplex optimizer Ø netopt network optimizer (for problems with special structure of a network flow problem) Ø baropt barrier optimizer (uses interior point algorithm to solve large scale problem) 13

Tips l For large problems, Ø write a small program in C/C++ which can

Tips l For large problems, Ø write a small program in C/C++ which can read the data from the data files and write the model to a text file in the above-mentioned format. Ø save the file with “. lp” extension. Ø read the model from the file and solve. l View a comprehensive introductory manual at www. ise. ufl. eduilog about cplex and concert technologies 14

ILOG Concert 10 l A C++ library of classes and functions for Ø Defining

ILOG Concert 10 l A C++ library of classes and functions for Ø Defining models. Ø Applying algorithms. l Supports algorithm for both constraint programming and math programming (LP, MIP, QP, etc. ). l Can be integrated with rest of the application in the program. 15

An example Linear Programming formulation: 16

An example Linear Programming formulation: 16

Basic steps l Creating an environment. l Building a model. l Extracting a model

Basic steps l Creating an environment. l Building a model. l Extracting a model for an algorithm. l Solving the problem. l Accessing results. l Ending the program. 17

Creating an environment and a model #include <ilcplex/ilocplex. h> ILOSTLBEGIN // ILOG standard template

Creating an environment and a model #include <ilcplex/ilocplex. h> ILOSTLBEGIN // ILOG standard template library void main() { // creating an environment Ilo. Env env 1; // name of the environment is env 1 // creating a model Ilo. Model mymodel(env 1); //name of the model is mymodel in env 1. We will fill out this part… } Note: The line ILOSTLBEGIN is a macro that is needed for portability. Microsoft Visual C++ code varies, depending on whether you use the STL or not. It allows you to switch between both types of code without the need to otherwise change your source code. 18

Variable declaration Ilo. Num. Var. Array x(env 1, 2, 0, Ilo. Infinity, ILOFLOAT); //

Variable declaration Ilo. Num. Var. Array x(env 1, 2, 0, Ilo. Infinity, ILOFLOAT); // float variable array, has two elements x 1 and x 2 typedef Ilo. Array<Ilo. Num. Var. Array> Num. Var. Matrix; \ define two dimensional variable array called Num. Var. Matrix x(env 1, 10); \ define x as a two dimensional variable array for(int i=0; i<10; i++) x[i]= Ilo. Num. Var. Array(env 1, 10); //x is a matrix x[i][j]… 10*10 19

Parameters To store data using CONCERT, we can use the pre-defined arrays, Ilo. Num.

Parameters To store data using CONCERT, we can use the pre-defined arrays, Ilo. Num. Array array_name(environment, size_array) A 2 -dimensional array is an array of arrays. So, it can be defined as typedef Ilo. Array<Ilo. Num. Array> Num. Array 2 dim; Ilo. Num. Array Demand(env 1, 10); Ilo. Num. Array Supply(env 1, 10); Num. Array 2 dim cost(env 1, 10); for(int i=0; i<10; i++) cost[i]= Ilo. Num. Array(env 1, 10); 20

reading input file ifstream file(“transport. txt"); if (!file) cerr << "Error" << endl; for

reading input file ifstream file(“transport. txt"); if (!file) cerr << "Error" << endl; for (int k=0; k<10; k++){ for (int j=0; j<10; j++){ file >> cost[k][j]; } } file. close(); 133455555566. . . . 21

Expressions Ilo. Expr objective(env 1); for(Ilo. Int i = 0; i < 10; i++)

Expressions Ilo. Expr objective(env 1); for(Ilo. Int i = 0; i < 10; i++) for(Ilo. Int j= 0; j < 10; j++) objective += cost[i][j]*x[i][j]; mymodel. add(Ilo. Minimize(env 1, objective)); for(Ilo. Int j=0; j<10; j++) { Ilo. Expr r(env 1); for (Ilo. Int i=0; i<10; i++) { r+=x[i][j]; } mymodel. add(r>demand[j]); } 22

Expressions contd. for(Ilo. Int i=0; i<10; i++) { Ilo. Expr r(env 1); for (Ilo.

Expressions contd. for(Ilo. Int i=0; i<10; i++) { Ilo. Expr r(env 1); for (Ilo. Int j=0; j<10; j++) { r+=x[i][j]; } mymodel. add(r<supply[i]); } 23

Solving and output // handing over the model to the algorithm Ilo. Cplex mycplex(mymodel);

Solving and output // handing over the model to the algorithm Ilo. Cplex mycplex(mymodel); // solving the problem mycplex. solve(); mycplex. out() << "Solution Status is " << mycplex. get. Status() << endl; // the results cout << " The objective value is " << mycplex. get. Obj. Value() << endl; cout << " x[0][0]= " << mycplex. get. Value(x[0][0])<<endl; cout << " x[1][4]= " << mycplex. get. Value(x[1][4]) <<endl; // releasing the memory env 1. end(); 24

Running example. cpp in unix l go to the directory of the example. cpp

Running example. cpp in unix l go to the directory of the example. cpp l g++ -c -O -f. PIC -fexceptions -DNDEBUG -DIL_STD -I/usr/local/cplex 90/include -I/usr/local/concert 20/include. /example. cpp –o example. o l It will create output file called example. o l g++ -O -f. PIC -fexceptions -DNDEBUG -DIL_STD -I/usr/local/cplex 90/include -I/usr/local/concert 20/include example. o -o example -L/usr/local/cplex 90/lib/i 86_linux 2_glibc 2. 3_gcc 3. 2/static_pic -lilocplex -lcplex -L/usr/local/concert 20/lib/i 86_linux 2_glibc 2. 3_gcc 3. 2/static_pic -lconcert -lm –lpthread l Convert it to executable example l To run it type. /example 25