introduction to opl cplex
play

Introduction to OPL CPLEX Writing OPL Torkel A. Haufmann January - PowerPoint PPT Presentation

Introduction to OPL CPLEX Torkel A. Haufmann What is it? Linear Op- timization Introduction to OPL CPLEX Writing OPL Torkel A. Haufmann January 25, 2017 Introduction to OPL What is it? CPLEX Torkel A. Haufmann What is it? Linear


  1. Introduction to OPL CPLEX Torkel A. Haufmann What is it? Linear Op- timization Introduction to OPL CPLEX Writing OPL Torkel A. Haufmann January 25, 2017

  2. Introduction to OPL What is it? CPLEX Torkel A. Haufmann What is it? Linear Op- timization • System for solving optimization problems Writing OPL • OPL: Optimization Programming Language • CPLEX: “Simplex in C” • Various competing systems • Xpress-MP • GuRoBi • ... • OPL CPLEX can be very useful in this course!

  3. Introduction to OPL Anatomy of an optimization CPLEX Torkel A. problem Haufmann What is it? Linear Op- timization Very informally, an optimization problem consists of two Writing things: OPL 1 A set of possible solutions to some problem. 2 A measure of “goodness” for any solution.

  4. Introduction to OPL Anatomy of an optimization CPLEX Torkel A. problem Haufmann What is it? Linear Op- timization Very informally, an optimization problem consists of two Writing things: OPL 1 A set of possible solutions to some problem. 2 A measure of “goodness” for any solution. We are concerned with problems where both parts are described in linear terms. Hence, for us an optimization problem in n variables consists of: 1 A set in R n defined by linear inequalities. 2 A linear function R n → R .

  5. Introduction to OPL Describing an optimization CPLEX Torkel A. problem Haufmann What is it? Linear Op- timization OPL is a domain-specific language , created for describing Writing optimization problems. OPL What must we define? 1 Constants used in the problem. 2 Variables used in the problem. 3 The linear objective function. 4 The linear inequalities defining the feasible region.

  6. Introduction to OPL Representing a problem CPLEX Torkel A. Haufmann What is it? OPL separates the model and its instance . Linear Op- timization Model: .mod extension, describes the structure of a Writing problem. OPL Instance: .dat extension, describes the data in a problem. Any linear program (in general form) has the same structure. Only the data changes! In the OPL IDE, a model and data file are associated in a run configuration .

  7. Introduction to OPL Defining constants and variables CPLEX Torkel A. Haufmann What is it? Linear Op- OPL has two main kinds of data: constants and decision timization variables . Writing OPL Constants: • float • float+ • int • int+ • string

  8. Introduction to OPL Defining constants and variables CPLEX Torkel A. Haufmann What is it? Linear Op- timization OPL has two main kinds of data: constants and decision Writing variables . OPL Decision variables: • dvar float • dvar float+ • dvar int • dvar int+

  9. Introduction to OPL Defining constants and variables CPLEX Torkel A. Haufmann What is it? Linear Op- timization Often, we want to represent our data as arrays. Writing OPL int n = 4; range vars = 1..n; float b[vars] = [1, 2, 3, 4];

  10. Introduction to OPL Defining constants and variables CPLEX Torkel A. Haufmann What is it? Contrast: Linear Op- timization dvar float+ x1; Writing OPL dvar float+ x2; dvar float+ x3; dvar float+ x4; range cols = 1..n; dvar float+ x[cols];

  11. Introduction to OPL Defining constants and variables CPLEX Torkel A. Haufmann What is it? Linear Op- timization There is also a ... syntax for reading from the data file. Writing OPL int n = ...; int cols = 1..n; dvar float+ x[cols]; We will get back to this later.

  12. Introduction to OPL Defining the objective function CPLEX Torkel A. Haufmann For example, let’s maximize What is it? Linear Op- timization 6 x 1 + 8 x 2 + 5 x 3 + 9 x 4 . Writing OPL

  13. Introduction to OPL Defining the objective function CPLEX Torkel A. Haufmann For example, let’s maximize What is it? Linear Op- timization 6 x 1 + 8 x 2 + 5 x 3 + 9 x 4 . Writing OPL Without range (bad): dvar float+ x1; dvar float+ x2; dvar float+ x3; dvar float+ x4; maximize 6*x1 + 8*x2 + 5*x3 + 9*x4;

  14. Introduction to OPL Defining the objective function CPLEX Torkel A. Haufmann For example, let’s maximize What is it? Linear Op- 6 x 1 + 8 x 2 + 5 x 3 + 9 x 4 . timization Writing OPL With range: range cols = 1..n; float c[cols] = [6, 8, 5, 9]; dvar float+ x[cols]; maximize sum(i in cols) c[i] * x[i]; Easier to write and read, and more general! Note: x is assumed to be nonnegative here.

  15. Introduction to OPL Defining the feasible region CPLEX Torkel A. Assume these constraints: Haufmann 2 x 1 + x 2 + x 3 + 3 x 4 ≤ 5 , What is it? x 1 + 3 x 2 + x 3 + 2 x 4 ≤ 3 , Linear Op- timization x 1 , x 2 , x 3 , x 4 ≥ 0 . Writing OPL

  16. Introduction to OPL Defining the feasible region CPLEX Torkel A. Assume these constraints: Haufmann 2 x 1 + x 2 + x 3 + 3 x 4 ≤ 5 , What is it? x 1 + 3 x 2 + x 3 + 2 x 4 ≤ 3 , Linear Op- timization x 1 , x 2 , x 3 , x 4 ≥ 0 . Writing OPL In OPL (But the data should be moved to a .dat file): float A[ rows ] [ c o l s ] = [ [ 2 , 1 , 1 , 3] , [1 , 3 , 1 , 2 ] ] ; float b [ rows ] = [ 5 , 3 ] ; // ( Define o b j e c t i v e and x as before ) subject to { forall ( j in rows ) { sum ( i in c o l s ) ( A[ j ] [ i ] ∗ x [ i ] ) < = b [ j ] ; } }

  17. Introduction to OPL Summary CPLEX Torkel A. Haufmann What is it? A problem instance properly modeled in OPL consists of: Linear Op- timization • A model file containing: Writing OPL 1 Constant definitions ( float b[ran] = ...; ) 2 Decision variable definitions ( dvar float+ x; ) 3 An objective definition ( maximize (...) ) 4 Constraints ( subject to { (...) } ) • A data file containing those values defined with = ...; in the model file. • Optionally, other configuration options controlling the optimization (likely irrelevant for this course).

Recommend


More recommend