advanced features of ampl

Upload: fawaz-m-kha

Post on 05-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Advanced Features of AMPL

    1/13

    Advanced AMPL Features

    Cormac Lucas

  • 8/2/2019 Advanced Features of AMPL

    2/13

    Table of Contents

    1. Advanced Features of AMPL..........................................................1

  • 8/2/2019 Advanced Features of AMPL

    3/13

    Notes

    1

    1. Advanced Features of AMPL

    In this workshop we illustrate some advanced features of AMPL.

    Quite often we include redundant columns and rows in the model removing them by

    explicitly declaring upper bounds of zero. In this section we illustrate the use of the

    logical expressions to implicitly handle these conditions.

    The following model, taking from Williams is used to illustrate these features.

    WORKSHOP Multi-Time Period Problem

    An engineering factory makes seven products (PROD 1 to PROD 7) on the

    following machines: four grinders, two vertical drills, three horizontal drills, one

    borer, and one planer. Each product yields a certain contribution to profit (defined

    as /unit) together with the unit production times (hours) required on each process

    are given below. A dash indicates that a product does not require a process.

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    4/13

    Notes

    2

    PROD

    1

    PROD

    2

    PROD

    3

    PROD

    4

    PROD

    5

    PROD

    6

    PROD

    7

    Contribution

    to profit

    10 6 8 4 11 9 3

    Grinding 0.5 0.7 - - 0.3 0.2 0.5

    Vertical

    drilling

    0.1 0.2 - 0.3 - 0.6 -

    Horizontal

    drilling

    0.2 - 0.8 - - - 0.6

    Boring 0.05 0.03 - 0.07 0.1 - 0.08

    Planing - - 0.01 - 0.05 - 0.05

    In the present month (January) and the five subsequent months certain machines will be

    down for maintenance. These machines will be:

    January 1 grinder

    February 2 horizontal drills

    March 1 borer

    April 1 vertical drill

    May 1 grinder and 1 vertical drill

    June 1 planer and 1 horizontal drill

    There are marketing limitations on each product in each month. These are:

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    5/13

  • 8/2/2019 Advanced Features of AMPL

    6/13

    Notes

    4

    The corresponding mathematical model is as follows

    Indices

    i=1..5 denotes the machine types

    j=1..6 denotes the time periods

    k=1..7 denotes the products

    Data

    Pkunit profit contribution for product p

    Uk,i hours needed on machine i for a unit of product k

    D j k, monthly demand for each product

    Ni available number of machine type i

    Wi,j number of machine type i in maintenance time j

    M maximum storage of each product for all time periods

    S storage cost of holding one product in inventory for 1 month

    Gkdesired closing stock of product k

    A hours available each month

    Variables

    xj,kamount of product k produced time j

    yj,kamount of product k sold time j

    zj,kamount product k held in inventory at the end of time period j

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    7/13

    Notes

    5

    maximize = == =

    6

    1

    7

    1

    6

    1

    7

    1 k j

    jk

    k j

    kjk SzyP

    Subject to

    Machine hours each month

    ( ) jiWNAxU ijik

    jkkj ,7

    1

    =

    Production balance

    x y z z j kj k j k j k j k, , , , , + = 1

    and the following bounds

    z M k jj k, , < 6

    z G kk k6,

    =

    y D j kj k j k, , ,

    and non negativity of the variables

    x y z j kj k j k j k, , ,, , , 0

    The resulting AMPL model and data file are

    set product;

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    8/13

    Notes

    6

    set months circular;

    set machine;

    param contrib{i in product};

    param time {k in machine,i in product};

    param number{k in machine};

    param down{j in months,k in machine};

    param demand{j in months,i in product};

    param storecst := 0.5;

    param maxstore := 100;

    param closestck := 50;

    param maxhours := 6*4*2*8;

    var sale{i in product, j in months : demand[j,i]>0 } >=0, =0;

    var store{i in product, j in months} >=0,0} (contrib[i] * sale[i,j]) -

    sum{i in product, j in months} (storecst*store[i,j]);

    subject to

    cap{j in months, k in machine} : sum{i in product} time[k,i]*prod[i,j] 0} : store[i,j] = store[i,prev(j)]

    +prod[i,j]-sale[i,j];

    bal12{i in product, j in months: j"jan" and demand[j,i]=0} : store[i,j] = store[i,prev(j)]

    +prod[i,j];bal2{i in product, j in months: j="jan"} : store[i,j] = prod[i,j]-sale[i,j];

    str2{i in product, j in months: j="jun"} : store[i,j] = closestck;

    data;

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    9/13

    Notes

    7

    set product := 1 2 3 4 5 6 7;

    set months := jan feb mar apr may jun;

    set machine := grind vert hori bore plan;

    param contrib := 1 10

    2 6

    3 8

    4 4

    5 11

    6 9

    7 3;

    param time : 1 2 3 4 5 6 7 :=

    grind 0.5 0.7 0 0 0.3 0.2 0.5

    vert 0.1 0.2 0 0.3 0 0.6 0

    hori 0.2 0 0.08 0 0 0 0.6

    bore 0.05 0.03 0 0.07 0.1 0 0.08

    plan 0 0 0.01 0 0.05 0 0.05;

    param number := grind 4

    vert 2

    hori 3

    bore 1

    plan 1;

    param down : grind vert hori bore plan :=

    jan 1 0 0 0 0

    feb 0 2 0 0 0

    mar 0 0 0 1 0

    apr 0 1 0 0 0

    may 1 1 0 0 0

    jun 0 0 1 0 1;

    param demand : 1 2 3 4 5 6 7 :=

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    10/13

    Notes

    8

    jan 500 1000 300 300 800 200 100

    feb 600 500 200 0 400 300 150

    mar 300 600 0 0 500 400 100

    apr 200 300 400 500 200 0 100

    may 0 100 500 100 1000 300 0

    jun 500 500 100 300 1100 500 60;

    However, we can be more efficient in the declaration of the variable as in

    var store{i in product, j in months} >= (if (j="jun") then closestck else 0) ,

    0) then sale[i,j] else 0);

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    11/13

    Notes

    9

    Running AMPL in command line

    The ampl model file can be created in an editor such as notepad and saved with a

    name mymodel.mod. Similarly, the data file can also be edited in notepad and

    stored in a file called mydata.dat. Then by opening an MSDos window theproblem can be solved in the following manner.

    Microsoft Windows 2000 [Version 5.00.2195]

    (C) Copyright 1985-2000 Microsoft Corp

    C:\Program Files\AMPL\Models>ampl

    License expires on (y)2005:(m)06:(d)08.

    OptiRisk Systems license manager: valid AMPL license found

    ampl: model prodplan.mod;

    ampl: data prodplan.dat;

    ampl: solve;MINOS 5.5: optimal solution found.

    49 iterations, objective 81756.42857

    ampl: display store;

    store [*,*]

    : jan feb mar apr may jun :=

    1 100 0 0 0 0 50

    2 0 0 0 0 0 50

    3 0 0 0 0 100 50

    4 0 0 0 0 0 50

    5 0 100 0 0 100 50

    6 100 0 0 0 0 50

    7 0 100 0 0 100 50;

    ampl: display prod;

    prod [*,*]

    : jan feb mar apr may jun :=

    1 600 0 0 200 0 550

    2 788.571 0 0 300 100 550

    3 300 200 0 400 600 0

    4 300 0 0 500 100 350

    5 800 500 0 200 1100 06 300 0 400 0 300 550

    7 0 250 0 100 100 0;

    ampl: display sale;

    sale [*,*]

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    12/13

    Notes

    10

    : jan feb mar apr may jun :=

    1 500 100 0 200 . 500

    2 788.571 0 0 300 100 500

    3 300 200 . 400 500 50

    4 300 . . 500 100 300

    5 800 400 100 200 1000 50

    6 200 100 400 . 300 5007 0 150 100 100 . 50;

    Useful Commands

    ampl: show;

    parameters:

    closestck demand maxhours number time

    contrib down maxstore storecst

    sets: machine months product

    variables: prod sale store

    constraints: bal11 bal12 bal2 cap str2

    objective: contr

    ampl: show bal2;

    s.t. bal2{i in product, j in months: j == 'jan'} : store[i,j] == prod[i,j] -

    sale[i,j];

    ampl: expand bal2;

    s.t. bal2[1,'jan']:

    sale[1,'jan'] - prod[1,'jan'] + store[1,'jan'] = 0;

    s.t. bal2[2,'jan']:

    sale[2,'jan'] - prod[2,'jan'] + store[2,'jan'] = 0;

    s.t. bal2[3,'jan']:

    sale[3,'jan'] - prod[3,'jan'] + store[3,'jan'] = 0;

    s.t. bal2[4,'jan']:

    sale[4,'jan'] - prod[4,'jan'] + store[4,'jan'] = 0;

    s.t. bal2[5,'jan']:

    sale[5,'jan'] - prod[5,'jan'] + store[5,'jan'] = 0;

    Questions/Notes

  • 8/2/2019 Advanced Features of AMPL

    13/13

    Notes

    11

    s.t. bal2[6,'jan']:

    sale[6,'jan'] - prod[6,'jan'] + store[6,'jan'] = 0;

    s.t. bal2[7,'jan']:

    sale[7,'jan'] - prod[7,'jan'] + store[7,'jan'] = 0;

    ampl: display store >prodplan.log;

    ampl: display prod >>prodplan.log;

    ampl: exit;

    Estimating the Model Statistics

    We wish to estimate model statistics such as the number of rows, columns, bounds

    and non zeros of the problem.

    By expressing them as parameter expressions we see how easy it is to represent

    large problems in concise statements. For the above model we compute thestatistics as follows

    Variable Group Number Lower Upper

    sale[product,month]

    prod[product,month]

    store[product,month]

    Row Group Number Variable grp Number Tnonz

    cap[month,machine]

    bal[product,month]

    Now recompute the same information taking into account that there is no sales

    variable when demand is zero.

    Questions/Notes