milp primer

Upload: shankaranarayanan-gopal

Post on 02-Jun-2018

234 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/11/2019 MILP Primer

    1/36

    A Primer on Mixed

    Integer LinearProgramming

    Using Matlab, AMPL and CPLEX atStanford University

    Steven Waslander, May 2nd, 2005

  • 8/11/2019 MILP Primer

    2/36

    Outline

    Optimization Program Types

    Linear Programming Methods

    Integer Programming Methods AMPL-CPLEX

    Example 1Production of Goods

    MATLAB-AMPL-CPLEX Example 2Rover Task Assignment

  • 8/11/2019 MILP Primer

    3/36

    General Optimization Program

    Standard form:

    where,

    Too general to solve, must specify propertiesofX, f,gand hmore precisely.

  • 8/11/2019 MILP Primer

    4/36

    Complexity Analysis

    (P)Deterministic Polynomial time algorithm

    (NP)Non-deterministic Polynomial time

    algorithm, Feasibility can be determined in polynomial time

    (NP-complete)NPand at least as hard asany known NPproblem

    (NP-hard)not provably NPand at least ashard as any NPproblem,

    Optimization over an NP-completefeasibility

    problem

  • 8/11/2019 MILP Primer

    5/36

    Optimization Problem Types

    Real Variables

    Linear Program (LP)

    (P) Easy, fast to solve, convex

    Non-Linear Program (NLP) (P) Convex problems easy to solve

    Non-convex problems harder, not guaranteed to find global

    optimum

  • 8/11/2019 MILP Primer

    6/36

    Optimization Problem Types

    Integer/Mixed Variables

    Integer Programs (IP) : (NP-hard) computational complexity

    Mixed Integer Linear Program (MILP)

    Our problem of interest, also generally (NP-hard)

    However, many problems can be solved surprisinglyquickly!

    MINLP, MILQP etc. New tools included in CPLEX 9.0!

  • 8/11/2019 MILP Primer

    7/36

    Solution Methods for

    Linear Programs

    cT

    x1

    x2

    Simplex Method

    Optimum must be at the intersection of constraints

    (for problems satisfying Slater condition)

    Intersections are easy to find, change inequalities

    to equalities

  • 8/11/2019 MILP Primer

    8/36

    Solution Method for

    Linear Programs

    Interior Point Methods

    Apply Barrier Function to each constraint and sum

    Primal-Dual Formulation

    Newton Step

    Benefits

    Scales Better than Simplex

    Certificate of Optimality

    -cT

    x1

    x2

  • 8/11/2019 MILP Primer

    9/36

    EnumerationTree Search, Dynamic

    Programming etc.

    Guaranteed to find a feasible solution (only

    consider integers, can check feasibility (P) )

    But, exponential growth in computation time

    Solution Methods for

    Integer Programs

    x1=0

    X2=0 X2=2X2=1

    x1=1 x1=2

    X2=0 X2=2X2=1X2=0 X2=2X2=1

  • 8/11/2019 MILP Primer

    10/36

    Solution Methods for

    Integer Programs

    How about solving LP Relaxation followed by

    rounding?

    -cT

    x1

    x2

    LP Solution

    Integer Solution

  • 8/11/2019 MILP Primer

    11/36

    Integer Programs

    LP solution provides lower bound on IP

    But, rounding can be arbitrarily far away from

    integer solution

    -cT

    x1

    x2

  • 8/11/2019 MILP Primer

    12/36

    Combined approach to Integer

    Programming

    -cT

    x1

    x2

    -cT

    x1

    x2

    Why not combine both approaches!

    Solve LP Relaxation to get fractional solutions

    Create two sub-branches by adding constraints

    x11

    x12

  • 8/11/2019 MILP Primer

    13/36

    Known as Branch and Bound

    Branch as above

    LP give lower bound, feasible solutions give

    upper bound

    Solution Methods for

    Integer Programs

    LP

    J* = J0

    LP + x14

    J* = J2

    LP + x13

    J* = J1

    x1= 3.4, x2= 2.3

    LP + x13 + x22

    J* = J3

    LP + x13 + x23

    J* = J4

    LP + x14 + x24

    J* = J6

    LP + x13 + x24

    J* = J5

    x1= 3.7, x2= 4x1= 3, x2= 2.6

  • 8/11/2019 MILP Primer

    14/36

    Branch and Bound Method

    for Integer Programs

    Branch and Bound Algorithm

    1. Solve LP relaxation for lower bound on cost for current

    branch

    If solution exceeds upper bound, branch is terminated If solution is integer, replace upper bound on cost

    2.Create two branched problems by adding constraints to

    original problem

    Select integer variable with fractional LP solution

    Add integer constraints to the original LP

    3. Repeat until no branches remain, return optimal solution.

  • 8/11/2019 MILP Primer

    15/36

    Integer Programs

    -cT

    x1

    x2

    Order mattersAll solutions cause branching to stop

    Each feasible solution is an upper bound on

    optimal cost, allowing elimination of nodes

    Branch x2Branch x1

    then x2

    Branch x1

  • 8/11/2019 MILP Primer

    16/36

    Additional Refinements

    Cutting Planes

    Idea stems from adding additional constraints

    to LP to improve tightness of relaxation

    Combine constraints to eliminate non-integer

    solutions

    x1

    x2

    Added Cut

    All feasible integer

    solutions remain

    feasible Current LP solution

    is not feasible

  • 8/11/2019 MILP Primer

    17/36

  • 8/11/2019 MILP Primer

    18/36

    Solving MILPs with

    CPLEX-AMPL-MATLAB

    CPLEX is the best MILP optimization engine

    out there.

    AMPL is a standard programming interface

    for many optimization engines.

    MATLAB can be used to generate AMPL files

    for CPLEX to solve.

  • 8/11/2019 MILP Primer

    19/36

    Introduction to AMPL

    Each optimization program has 2-3 files

    optprog.mod: the model file

    Defines a class of problems (variables, costs,

    constraints)

    optprog.dat: the data file

    Defines an instance of the class of problems

    optprog.run: optional script file

    Defines what variables should be saved/displayed,

    passes options to the solver and issues the solve

    command

  • 8/11/2019 MILP Primer

    20/36

    Running AMPL-CPLEX on

    Stanford Machines

    Get Samson

    Available at ess.stanford.edu

    Log into epic.stanford.edu

    or any other Solaris machine

    Copy your AMPL files to your afs directory SecureFX (from ess.stanford.edu) sftp to

    transfer.stanford.edu

    Move into the directory that holds your AMPLfiles cd ./private/MILP

  • 8/11/2019 MILP Primer

    21/36

    Running AMPL-CPLEX on

    Stanford Machines

    Start AMPL by typing ampl at the prompt

    Load the model file ampl: model optprog.mod; (note semi-colon)

    Load the data file ampl: data optprog.dat;

    Issue solve and display commands ampl: solve;

    ampl: display variable_of_interest; OR, run the run file with all of the above in it

    ampl: quit;

    Epic26:~> ampl example.run

  • 8/11/2019 MILP Primer

    22/36

    Example MILP Problem

    Decision on when to produce a good and how muchto produce in order to meet a demand forecast andminimize costs

    Costs Fixed cost of production in any producing period

    Production cost proportional to amount of goods produced

    Cost of keeping inventory

    Constraints Must meet fixed demand vector over T periods

    No initial stock

    Maximum number of goods, M, can be produced per period

  • 8/11/2019 MILP Primer

    23/36

    Example MILP Problem

  • 8/11/2019 MILP Primer

    24/36

    AMPL:

    Example Model File - Part 1#------------------------------------------------

    #example.mod

    #------------------------------------------------

    # PARAMETERS

    param T > 0; # Number of periods

    param M > 0; # Maximum production per period

    param fixedcost {2..T+1} >= 0; # Fixed cost of production in period t

    param prodcost {2..T+1} >= 0; # Production cost of production in period t

    param storcost {2..T+1} >= 0; # Storage cost of production in period t

    param demand {2..T+1} >= 0; # Demand in period t

    # VARIABLES

    var made {2..T+1} >= 0; # Units Produced in period t

    var stock {1..T+1} >= 0; # Units Stored at end of t

    var decide {2..T+1} binary; # Decision to produce in period t

  • 8/11/2019 MILP Primer

    25/36

  • 8/11/2019 MILP Primer

    26/36

    AMPL:

    Example Data File

    #------------------------------------------------

    #example.dat

    #------------------------------------------------

    param T:= 6;

    param demand := 2 6 3 7 4 4 5 6 6 3 7 8;

    param prodcost := 2 3 3 4 4 3 5 4 6 4 7 5;

    param storcost := 2 1 3 1 4 1 5 1 6 1 7 1;

    param fixedcost := 2 12 3 15 4 30 5 23 6 19 7 45;

    param M := 10;

  • 8/11/2019 MILP Primer

    27/36

    AMPL:

    Example Run File

    #------------------------------------------------

    #example.run

    #------------------------------------------------

    model example.mod;

    data example.dat;

    solve;

    display made;

  • 8/11/2019 MILP Primer

    28/36

    AMPL:

    Example Results

    epic26:~/private/example_MILP> ampl example.run

    ILOG AMPL 8.100, licensed to "stanford-palo alto, ca".

    AMPL Version 20021031 (SunOS 5.7)

    ILOG CPLEX 8.100, licensed to "stanford-palo alto, ca", options: e m b q

    CPLEX 8.1.0: optimal integer solution; objective 21215 MIP simplex iterations

    0 branch-and-bound nodes

    made [*] :=

    2 7

    3 10

    4 0

    5 7

    6 10

    7 0

    ;

  • 8/11/2019 MILP Primer

    29/36

    AMPL:

    Example Results

    Cumulative Production vs. Demand

    0

    5

    10

    15

    20

    25

    30

    35

    40

    1 2 3 4 5 6

    Period

    Goods

    Demand

    Goods Produced

  • 8/11/2019 MILP Primer

    30/36

    Using MATLAB to Generate

    and Run AMPL files

    Can auto-generate data file in Matlab

    fprintf(fid,['param 'param_name ' := %12.0f;\n'],p);

    Use ! command to execute system command, and >to dump output to a file

    ! ampl example.run > CPLEXrun.txt

    Add printf to run file to store variables for Matlab

    In .run: printf: variable > variable.dat;

    In Matlab: load variable.dat;

  • 8/11/2019 MILP Primer

    31/36

    Further Example Task

    Assignment

    System Goal only:

    Minimum completion

    time

    All tasks must beassigned

    Timing Constraints

    between tasks

    (loitering allowed) Obstacles must be

    avoided

  • 8/11/2019 MILP Primer

    32/36

    Task Assignment Difficulties

    NP-Hard problem

    Instead of assigning 6

    tasks, must select from all

    possible permutations Even 2 aircraft, 6 tasks

    yields 4320 permutations

    Timing Constraints Shortest path through tasks

    not necessarily optimal

  • 8/11/2019 MILP Primer

    33/36

    Task Assignment:

    Model File# AMPL model file for UAV coordination given permutations

    #

    # timing constraints exist

    # adjust TOE by loitering at waypoints

    param Nvehs integer >=1; # number of vehicles, also number of permutations per vehicle constraints

    param Nwps integer >=1; # number of waypoints, also number of waypoint constraints

    param Nperms integer >=1; # number of total permutations, also number of binary variables

    param M := 10000; # large number

    param Tcons integer; # number of timing constraints

    set WP ordered := 1..Nwps;

    set UAV ordered := 1..Nvehs;

    set BVARS ordered := 1..Nperms ;

    set TCONS ordered := 1..Tcons;

    #parameters for permMat*z = 1

    param permMat{WP,BVARS} binary;

    # parameters for minimizing max time

    param minMaxTimeCons{UAV,BVARS};

    # parameters for timing constraint

    param timeConstraintWpts{TCONS,1..2} integer;

    param timeStore{WP,BVARS};

    param Tdelay{TCONS};

    # parameters for calculating loitering time

    param firstSlot{UAV} integer; # position in the BVARS where permutations for idxUAV begin

    param lastSlot{UAV} integer; # position in the BVARS where permutations for idxUAV end

    param ord3D{WP,WP,BVARS} binary; # ord3D{idxWP,idxPreWP,p}

    # if idxPreWP is visited before idxWP or at the same time as idxWP in permutation p

    param loiteringCapability{WP,UAV} binary; # =0 if it cannot wait at that WP.

    # cost weightings

    param costStore{BVARS}; #cost weighting on binary variables, i.e. cost for each permutation

    param minMaxTimeCostwt; #cost weighting on variable that minimizes max time for individual missions

    # decision variables

    var MissionTime >=0;

    var z{BVARS} binary;

    var tLoiter{WP,UAV} >=0; #idxUAV loiters for "tLoiter[idxWP,idxUAV]" on its way to idxWP

    # intermediate variables

    var tLoiterVec{WP} >=0;

    var TOA{WP} >=0;var tLoiterBefore{WP} >=0; #the sum of loitering time before reaching idxWP

    #Objective function

    minimize cost: ##

  • 8/11/2019 MILP Primer

    34/36

    Rover Task Assignment:

    Model File

    # from Task_Assignment.mod

    param Nvehs integer >=1;

    param Nwps integer >=1;

    set UAV ordered := 1..Nvehs;

    set WP ordered := 1..Nwps;

    var tLoiter{WP,UAV} >=0;

    subject to loiteringTime {idxWP in WP}:

    tLoiterVec[idxWP] = sum{idxUAV in UAV} tLoiter[idxWP,idxUAV];

    Set definitions in AMPL

    Great for adding collections of constraints

  • 8/11/2019 MILP Primer

    35/36

    Task Assignment: Results

  • 8/11/2019 MILP Primer

    36/36

    Further Resources

    AMPL textbook

    AMPL: A modeling language for mathematicalprogramming, Robert Fourer, David M. Gay, Brian

    W. Kernighan CPLEX user manuals

    On Stanford network at /usr/pubsw/doc/Sweet/ilog

    MS&E 212 class website Further examples and references

    Class Website This presentation

    M tl b lib i f AMPL