Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  problem with the variable demand

    Posted 04/11/17 06:22 AM

    Originally posted by: Guerlain


    Hello
    I'm working on VRP
    During the optimization, I had a problem:
    The program divides the demand into two and gives half to each of the two vehicles
    For example, if I have a request for 20 products, delivery of 10 by vehicle 1 and 10 by vehicle 2
    I need to fix this
    thank you for helping me

     

    ​The model is in the following

     

     

    /*********************************************
     * OPL 12.5.1.0 Model
     * Author: user
     * Creation Date: 19 févr. 2017 at 13:54:04
     *********************************************/
    // problem size
    //number of customers
    int n=...;
    range cities = 1..n;
    //periods
    int t=...;
    range Periods = 0..t;
    //total number of vehicles
    int m=...;
    range Vehicles = 1..m;
    //capacity of vehicle
    int Cap_Veh[Vehicles][1..t]=...;
    //Cout de stock
    float Cout_Inv[cities]=...;
    // Inventory data
    int Born_Inf[2..n]=...;
    int Born_Sup[2..n]=...;
    int stock_Cons[2..n][Periods]=...;
    int Demand_in[2..n]=...;
    int stock_in[cities]=...;
    int produ[Periods]=...;
    tuple edge {
      int i;
      int j;
      }
    setof(edge) edges = {<i,j> | i,j in cities : i!=j};
    //cost incurred on arc from node i to j
    float c[edges]=...;
    //Deision variable
    //if the city i is served
    dvar boolean y[cities][Vehicles][Periods];
    // Stock Level
    dvar int stock[cities][Periods];
    //demand at node i
    dvar int Demand[2..n][Vehicles][Periods];
    dvar int Transf[2..n][Vehicles][Periods];
    //0 if there is no arc from node i to node j, and 1 otherwise
    dvar boolean x[edges][Vehicles][1..t];
    //the flow in the vehicle after it visits customer i
    dvar float+ u[2..n][Vehicles][1..t];
    // Expressions
     
     dexpr float TotalInventory= sum (i in cities, t in 1..t) Cout_Inv[i] * stock[i][t];
     dexpr float TotalDistance= sum (e in edges,k in Vehicles,t in 1..t) c[e]* x[e][k][t];
     
     minimize TotalDistance+TotalInventory;
     
     subject to {
      
    // CVRP
     
    sum(k in Vehicles,t in Periods)y[1][k][t]<= m;
     
    forall(j in 2..n, k in Vehicles,t in 1..t)
    sum(i in cities: j!=i)  x[<i,j>][k][t]==y[j][k][t];
    forall(i in 2..n, k in Vehicles,t in 1..t)
    sum(j in cities: j!=i)  x[<i,j>][k][t]==y[i][k][t];
    forall(i,j in 2..n: j!=i, k in Vehicles, t in 1..t)
    u[i][k][t]- u[j][k][t]+(sum(k in Vehicles)Cap_Veh[k][t]* x[<i,j>][k][t])<= sum(k in Vehicles)Cap_Veh[k][t] - Transf[j][k][t];
     
    forall(i in 2..n, k in Vehicles, t in 1..t)
    stock_Cons[i][t] <= u[i][k][t] <= Cap_Veh[k][t];
    // Vehicle Constraints
    forall(i in 2..n, k in Vehicles, t in 1..t)  
    Transf[i][k][t] <=  Cap_Veh[k][t]*y[i][k][t]; // If we eliminat this constraint we will have a SD-IRP
    forall(i in 2..n, k in Vehicles, t in 1..t)  
    sum(i in 2..n)Transf[i][k][t] <= sum(i in 2..n)Demand[i][k][t];
    forall(i in 2..n, k in Vehicles, t in 1..t)  
    sum(i in 2..n)Demand[i][k][t] <= sum(k in Vehicles)Cap_Veh[k][t];
    forall(i in cities, k in Vehicles, t in 1..t)
    Cap_Veh[k][t]*y[i][k][t]<=stock[1][t];
    // Inventory constraints
    forall(i in cities, k in Vehicles, t in Periods)
    sum(i in 2..n)Transf[i][k][t] <= stock[1][t];
    forall(i in 2..n, t in Periods, k in Vehicles)
    (y[i][k][t]==1) => (Transf[i][k][t]==Demand[i][k][t]); // A revoir
    forall(i in 2..n, t in Periods, k in Vehicles)
    (y[i][k][t]==0) => (Transf[i][k][t]==0);
    forall (t in 1..t, k in Vehicles)
    stock[1][t]==stock[1][t-1]+produ[t]-sum(i in 2..n)Demand[i][k][t];
    forall(i in 2..n, t in 1..t, k in Vehicles)
    stock[i][t]==stock[i][t-1]-stock_Cons[i][t-1]+Demand[i][k][t]; // Ajouter
    forall(i in cities)
    stock[i][0]==stock_in[i];
    forall(i in 2..n, k in Vehicles)
    Demand[i][k][0]==Demand_in[i];
    forall(i in 2..n, t in 1..t)
    Born_Inf[i]+stock_Cons[i][t]<=stock[i][t]<=Born_Sup[i]; // Ajouter
    forall(i in 2..n, t in 1..t, k in Vehicles)
    Demand[i][k][t]==Born_Sup[i]-stock[i][t]; // Order-up-to level constraints
    forall(i in 2..n, t in 1..t, k in Vehicles)
    Demand[i][k][t]>=Born_Sup[i]*y[i][k][t]-stock[i][t]; // Order-up-to level constraints
    forall(i in 2..n,t in Periods, k in Vehicles)
    Demand[i][k][t]<=Born_Sup[i]*y[i][k][t]; // Order-up-to level constraints
    // Nonnegativity and integrality constraints
    forall(i in 2..n, t in Periods, k in Vehicles)
    Demand[i][k][t]>=0;
    forall(i in cities, t in 1..t)
    stock[i][t]>=0;
    forall(t in Periods, k in Vehicles)
    y[1][k][t]==0;
    }

     

    /*********************************************
     * OPL 12.5.1.0 Data
     * Author: user
     * Creation Date: 19 févr. 2017 at 13:54:04
     *********************************************/
    n=6;
    m=2;
    t=3;
     
    SheetConnection my_sheet ("testvrp.xlsx");
    c from SheetRead (my_sheet,"Dis");
    Cap_Veh=[[300,300,300][300,300,300]];

    Demand_in= [0,0,0,0,0];
    stock_in= [500,15,20,25,30,50];
    produ= [0,100,100,100];
    Born_Inf=[0,0,0,0,0];
    Born_Sup=[45,60,75,90,150];
    stock_Cons=[[0,15,15,15][0,20,20,20][0,25,25,25][0,30,30,30][0,50,50,50]];
    Cout_Inv=[0.03,0.03,0.04,0.01,0.02,0.01];

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: problem with the variable demand

    Posted 04/12/17 12:52 AM

    Without looking at your very long model in detail, I think you need to have a boolean variable serves[r][v] for each request r and vehicle v that is 1 if request r is served by v and 0 otherwise. Assuming that A[r][v] is the amount of request r served by vehicle v and S[r] is the size of request r you then add constraint A[r][v] >= S[r] * serves[r][v]. This makes sure a request can never be split across multiple vehicles.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: problem with the variable demand

    Posted 04/12/17 05:37 PM

    Originally posted by: Guerlain


    Hi

    I correct the demand but the problem is I have no divided quantity now but the same quantity is served by the two vehicles

    demand = 20 ; V1 is affected by 20 and the same for V 2


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: problem with the variable demand

    Posted 04/25/17 04:31 AM

    Looks like you have to add another constraint that forces A[r][v] to 0 in case r is not served by v.


    #CPLEXOptimizers
    #DecisionOptimization