Decision Optimization

 View Only
Expand all | Collapse all

CPLEX OPL Capabilities

  • 1.  CPLEX OPL Capabilities

    Posted Fri June 24, 2022 10:00 AM


  • 2.  RE: CPLEX OPL Capabilities

    Posted Fri June 24, 2022 11:51 AM

    Hi Jack,

     

    Try this for question 3.

     

    .mod

    int BigM=99999999;

    tuple TFreightTypes {

      key string Destination;

      key string VehicleType;

      int TotalWeight;

      key string Company;

      int Cost;

    };

      

    tuple TOrders {

      key int OrderNumber;

      float Weight;

      string ClientId;

      string Destination;

      string MaterialCategory;

      int CategoryPriority;

    };

     

    {TFreightTypes}    FreightTypes = ...;

    {TOrders}    Orders = ...;

     

    {int} Set_CategoryPriority={o.CategoryPriority| o in Orders};

     

     

    dvar boolean Assignment[Orders][FreightTypes];

    dvar boolean x_dvb_OrderFreightType[Set_CategoryPriority][FreightTypes];

    dvar int+ x_dvi_SlackOrderFreightType[Set_CategoryPriority];

    //choose freight with total minimum cost

    dexpr float objective =

      sum(o in Orders, f in FreightTypes)

         Assignment[o][f] * f.Cost;

     

    //try to put all orders with CategoryPriority=1 on one truck

    dexpr float objective1 =

    BigM*sum(o in Set_CategoryPriority)x_dvi_SlackOrderFreightType[o];

     

    minimize 0.95*objective+0.05*objective1;

     

     

    subject to{

     

      //c1: all order must be fulfilled

     

    forall(o in Orders)

    sum(f in FreightTypes) Assignment[o][f]==1;      

     

    //Remove this constraint

    //I just added it to test the grouping high priority

    forall(f in FreightTypes: f.VehicleType in {"Type1","Type2"})

    sum(o in Orders) Assignment[o][f]<=1;

     

    //Remove this constraint

    //I just added it to test the grouping high priority

    forall(f in FreightTypes: f.VehicleType =="Type3")

    sum(o in Orders) Assignment[o][f]<=2;

     

    //Important constraints

    //The constraint new_cts_1 tries to put all orders with the same priority on one freight

    //This is achieved by minimizing objective1 with is based on the integer variable x_dvi_SlackOrderFreightType

    forall(o in Set_CategoryPriority)

    new_cts_1:sum(f in FreightTypes)x_dvb_OrderFreightType[o][f]==1+x_dvi_SlackOrderFreightType[o];

     

    //Link the new decision variables x_dvb_OrderFreightType and Assignment

    forall(o in Orders,f in FreightTypes)

    x_dvb_OrderFreightType[o.CategoryPriority][f]>=Assignment[o][f];

    // 

    forall(categ in Set_CategoryPriority,f in FreightTypes)

      x_dvb_OrderFreightType[categ][f]<=sum(o in Orders:

      categ==o.CategoryPriority) Assignment[o][f];

     

    }

     

    execute

    {

      for(var o in Orders)

      for(var f in FreightTypes)

      if(Assignment[o][f]==1)

    writeln("<","<",o.OrderNumber," ",

    o.Weight," ",

    o.ClientId," ",

    o.Destination," ",

    o.MaterialCategory," ",

    o.CategoryPriority,">",

    "<",f.Company," ",f.Cost," ",f.Destination, " ",f.VehicleType,">",">")

    }

     

    .dat

    FreightTypes = {

        <"LONDON","Type1",20000,"SP TRANSPORTS",20000>,

        <"LONDON","Type2",20000,"SP TRANSPORTS",20000>,

        <"DURHAM","Type3",10000,"SP TRANSPORTS",20000>,

     

    };

    Orders = {

        <1,5000,"Client1","LONDON","A",0>,

        <2,1000,"Client2","DURHAM","B",1>,

        <3,2000,"Client3","LONDON","C",1>,     

     

    };

     

     


     

    Description: Description: email-signature-image_0014_H_COC-CTR_Surprint_1_-TO-3__BIL_ENG.png

    Nourredine Hail, PhD in Applied Mathematics
    Senior Operations Research & Data Scientist

    Data Analytics Governance team
    Canadian Tire Corporation
    2111 Steeles Avenue East, Brampton, ON, L6T4L5
    Phone: 905.792.5983  
    nourredine.hail@cantire.com

    "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young."  Henry Ford