1 ilog modeling examples

Upload: mohamed-drid

Post on 04-Jun-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 1 ILOG Modeling Examples

    1/32

    2011 IBM Corporation

    Modeling Optimization Problems with IBMILOG Cplex Optimization Studio

    IBM Advanced Analytics Summit April 2011

  • 8/14/2019 1 ILOG Modeling Examples

    2/32

    2011 IBM Corporation

    Agenda

    Optimization Development

    Sample Application

    CPLEX Studio

    Projects

    Run Configurations

    OPL Language

    Primitive Types

    Tuples

    Sets

    Arrays

    Application to Mathematical Programming

    Application to Detailed Scheduling Using Constraint Programming

  • 8/14/2019 1 ILOG Modeling Examples

    3/32

    2011 IBM Corporation

    Optimization Development

    Mathematical Model

    Development

    Optimization Expert

    Traditional Application

    Development

    Software Developer

    IBM ILOG CPLEX Studio reduces the time to

    market for optimization applications

  • 8/14/2019 1 ILOG Modeling Examples

    4/32

    2011 IBM Corporation

    Simple Application

    Mathematical Model

    Engine

    Database

    Spreadsheet

    Input Data

    Database

    Spreadsheet

    Output Data

    GUI

    Database FormsSpreadsheet

    User Interface

    Database

    SpreadsheetGUI

    Reporting

    IBM ILOG OPL

    IBM ILOG CPLEX

    RawD

    ata

    Reposito

    ry

    Solve

    IBM ILOG CP

    Optimizer

  • 8/14/2019 1 ILOG Modeling Examples

    5/32

    2011 IBM Corporation

    Key Features

    OPL: Optimization Programming LanguageA compact language to represent optimization problems

    Advanced types for data organization

    Supports solving mathematical programming models with CPLEX and applying

    constraint programming including scheduling with CP Optimizer

    Connects to relational databases and Excel spreadsheets ILOG Script for data processing and iterative solving

  • 8/14/2019 1 ILOG Modeling Examples

    6/32 2011 IBM Corporation

    Key Features

    Integrated Development Environment Graphical editor for OPL models and data files

    File and project organization

    Review data and solutions as tables

    Menus/buttons to debug optimization

    Online help for OPL syntaxAccess to engine features

    Infeasibility Analysis

    Solution Pools

    Engine Parameters

  • 8/14/2019 1 ILOG Modeling Examples

    7/32 2011 IBM Corporation

    Run Configuration

    Run Configuration

    Run Configuration

    OPL Project

    Anatomy of an OPL Project

    Data Structure Definitions

    Pre-Processing

    Decision Variables

    Objective FunctionConstraints

    Post-Processing

    Model File (.mod)

    Excel Connections

    Database Connections

    Data Structure

    Initializations

    Data File (.dat)

    CPLEX Settings

    CPO SettingsLanguage Settings

    Settings File (.ops)

  • 8/14/2019 1 ILOG Modeling Examples

    8/32 2011 IBM Corporation

    Anatomy of an OPL Project

    Model Files

    You can share multiple model files between different run configurations: Good for

    running the same model on many different data instances

    You can have multiple model files in the same run configuration: Good for separating

    data structure definitions from model definitions

    Data Files

    You can share multiple data files between different run configurations: Good for testingdifferent models on the same data instance

    You can have multiple data files in the same run configuration: Good for separating

    different data initializations

  • 8/14/2019 1 ILOG Modeling Examples

    9/32 2011 IBM Corporation

    The Optimization Programming Language(OPL)

  • 8/14/2019 1 ILOG Modeling Examples

    10/32

  • 8/14/2019 1 ILOG Modeling Examples

    11/32 2011 IBM Corporation

    OPL Language: Tuples

    OPL allows you to create structured data types, called tuplestuplepair

    {

    int v;

    string s;

    };

    You can define sets of tuplessetof(pair) S = { , , };

  • 8/14/2019 1 ILOG Modeling Examples

    12/32

    2011 IBM Corporation

    OPL Language: Arrays

    OPL allows you to define arrays of fundamental types

    int a[1..4] = [10, 20, 30, 40];

    and arrays indexed on sets of tuplestuple Edges

    {

    int orig;

    int dest;}

    {Edge} Edges = {, , };

    int a[Edges] = [10,20,30];

  • 8/14/2019 1 ILOG Modeling Examples

    13/32

    2011 IBM Corporation

    OPL Language: Decision variables and expressions

    Decision variable - dvar

    Can be defined as: int, float, boolean

    Indexed on ranges or sets

    dvar int nWorkers[1..nShifts];

    dvar float+production[p in products][timePeriods];

    dvar boolean assign[workers][tasks];

    Decision expression - dexpr

    For readability and to separate parts of the objective function

    dexpr float tasksWorked = sum(w inworkers, t in tasks)assign[w][t];

    minimize tasksWorked;

  • 8/14/2019 1 ILOG Modeling Examples

    14/32

    2011 IBM Corporation

    Conditional loops

    Standard Loopforall (i in 1..10) {

    Conditional (filtered) Loopforall (i in 1..10 : mydata[i]

  • 8/14/2019 1 ILOG Modeling Examples

    15/32

    2011 IBM Corporation

    Data driven relaxations

    Use data to conditionally state a collection of constraints

    Data declarationsint includeBundleConstraint = ...;

    Conditional constraintsif (includeBundleConstraint == 1) {

    forall (i in S1) {

    sum (j in S2) x[j]

  • 8/14/2019 1 ILOG Modeling Examples

    16/32

    2011 IBM Corporation

    Examples of logical and nonlinear expressions

    Semi-continuous order quantity:(x == 0) || (x >= 100);

    Logical indicators(x == 0) => (y == 0);

    Zeros == sum (i in Index) (x[i] == 0);

    Maximum deviation from a target valuedeviation ==

    max (i in Index) abs(x[i]-target);

    Benefits Model is easier to develop and maintain

    Can eliminate some big-M bounds

  • 8/14/2019 1 ILOG Modeling Examples

    17/32

    2011 IBM Corporation

    Examples and Demo

  • 8/14/2019 1 ILOG Modeling Examples

    18/32

    2011 IBM Corporation

    A Production Planning Example

    A manufacturer wants to sell a product

    The product can be made either

    Inside the factory

    Scarce resources are required to build the product

    There is a cost per unit to manufacture the product

    Outside the factory

    There is a cost per unit to purchase the product

    All demand must be satisfied

    The objective is to minimize cost

  • 8/14/2019 1 ILOG Modeling Examples

    19/32

    2011 IBM Corporation

    A Production Planning Example: Data Declarations

    Sets of products and resources

    setof(string) Products = ...;setof(string) Resources = ...;

    Number of units of each resource needed to produce one unit of each

    product

    float consumption[Products][Resources] = ...;

    Total number of available resourcesfloat capacity[Resources] = ...;

    Number of units in demand for each productfloat demand[Products] = ...;

    Cost per unit of inside and outside productionfloat insideCost[Products] = ...;

    float outsideCost[Products] = ...;

  • 8/14/2019 1 ILOG Modeling Examples

    20/32

    2011 IBM Corporation

    A Production Planning Example: Decision Variables

    Inside and outside production

    dvar float+ inside[Products];

    dvar float+ outside[Products];

  • 8/14/2019 1 ILOG Modeling Examples

    21/32

    2011 IBM Corporation

    A Production Planning Example: Objective Function

    Inside and outside production cost

    dexpr float InsideCost =

    sum(p in Products) insideCost[p] * inside[p];

    dexpr float OutsideCost =sum(p in Products) outsideCost[p]* outside[p];

    minimize InsideCost + OutsideCost;

  • 8/14/2019 1 ILOG Modeling Examples

    22/32

    2011 IBM Corporation

    A Production Planning Example: Constraints

    Capacity and demand constraints

    subject to

    {

    forall (r in Resources)

    ctCapacity:

    sum (p in Products)

    consumption[p][r]*inside[p] = demand[p];

    };

  • 8/14/2019 1 ILOG Modeling Examples

    23/32

    2011 IBM Corporation

    Products Could be Jewelry

    Products and Resources

    Products = { rings earrings };Resources = { gold diamonds };

    ConsumptionConsumption = [ [3, 1], [2, 2] ];

    Capacity (Available units of gold and diamonds)Capacity = [ 130, 180 ];

    Demand (Number of rings and earrings)

    Demand = [ 100, 150 ];

    Costs (per unit for rings and earrings)InsideCost = [ 250, 200 ];

    OutsideCost = [ 260, 270 ];

  • 8/14/2019 1 ILOG Modeling Examples

    24/32

    2011 IBM Corporation

    Products Could be Pasta

    Products and Resources

    Products = { kluski capellini fettucine };Resources = { flour eggs };

    ConsumptionConsumption = [ [0.5, 0.2], [0.4, 0.4], [0.3, 0.6] ];

    Capacity (Available units of flour and eggs)Capacity = [20, 40];

    Demand (Quantities of kluski, capellini, and fettucine )

    Demand = [100, 200, 300];

    Costs (per unit for of kluski, capellini, and fettucine )

    InsideCost = [0.6, 0.8, 0.3];

    OutsideCost = [0.8, 0.9, 0.4];

  • 8/14/2019 1 ILOG Modeling Examples

    25/32

    2011 IBM Corporation

    Demo of Production Planning Example

    Open OPL

    Import Project

    Show configuration

    Show model, data and settings files

    Show input data tables

    Solve

    Show output data tables

    Show Solutions, Engine log, Statistics and Profiler tabs

    Show Online help

  • 8/14/2019 1 ILOG Modeling Examples

    26/32

    2011 IBM Corporation

    Scheduling using CP Optimizer - Demo

    Building 5 houses with 3 workers and a cash budget.

    Tasks are masonry, roofing, painting .

    Some tasks must necessarily take place before others.

    The building of a house must start after its release date

    Each task requires one worker.

    30,000 is available at the beginning of the project and 30,000 is added every 60 days.

    Each task costs a given amount of cash per day which must be available at the start of

    the task.

    The objective is to minimize the overall completion date.

  • 8/14/2019 1 ILOG Modeling Examples

    27/32

    2011 IBM Corporation

    Demo of sched_cumul

    Import the sched_cumul project

    See model and data file

    Solve problem

    Display the results in the Console tab and the Solutions tab

  • 8/14/2019 1 ILOG Modeling Examples

    28/32

    2011 IBM Corporation

    Brief intro to the Scheduling API in OPL

    interval variable:

    An interval variable represents an interval of time during which an

    activity is carried out. Its position in time is an unknown of the scheduling problem.

    It is characterized by a start value, an end value and a size.

    cumulFunction:

    A cumulative function is used to model a quantity that varies over

    time. Its value depends on other decision variables of the problem.

    An activity usually increases the cumulFunction at the start of the usage of the

    cumulative resources, and decreases the function when the resource is released at its

    end time (pulse function).

  • 8/14/2019 1 ILOG Modeling Examples

    29/32

    2011 IBM Corporation

    Brief intro to the Scheduling API in OPL - cont

    pulse:

    Pulse is a cumulative function expression that is used when an

    activity increases the resource usage function at its start

    decreases usage when it releases the resource at its end time.

    precedence constraint:

    Precedence constraints are common scheduling constraints used

    to restrict the relative position of interval variables in a solution. Examples: startAtEnd, endAtStart, startAfterEnd, etc.

  • 8/14/2019 1 ILOG Modeling Examples

    30/32

    2011 IBM Corporation

    CP Example Scheduling

    using CP;

    intNbWorkers = ...;

    intNbHouses = ...;

    range Houses = 1..NbHouses;

    {string} TaskNames = ...;

    int Duration [t in TaskNames] = ...;

    tuple Precedence {

    stringbefore;

    string after;

    };

    {Precedence} Precedences = ...;

    int ReleaseDate[Houses] = ...;

  • 8/14/2019 1 ILOG Modeling Examples

    31/32

    2011 IBM Corporation

    CP Example - Scheduling

    dvar interval itvs[h in Houses][t in TaskNames] inReleaseDate[h]..maxint size Duration[t];

    cumulFunctionworkersUsage =

    sum(h in Houses, t in TaskNames)pulse(itvs[h][t],1);

    cumulFunction cash =

    sum (p in 0..5) step(60*p, 30000)

    - sum(h in Houses, t in TaskNames) stepAtStart(itvs[h][t],

    200*Duration[t]);

  • 8/14/2019 1 ILOG Modeling Examples

    32/32

    CP-Example Scheduling

    minimize max(h in Houses) endOf(itvs[h]["moving"]);subject to {

    forall(h in Houses)

    forall(p in Precedences)

    endBeforeStart(itvs[h][p.before], itvs[h][p.after]);

    workersUsage = 0;

    }