Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  binary variable with if-else logic // fleet size problem

    Posted 04/04/18 01:08 PM

    Originally posted by: kalleman


    Hi there,

    i have a short question. currently i am working on a linear programming, already implemented by myself in OPL (CPLEX 12.6.2)

    The LP is about a fleet sizing problem. Therefore its aim is to minimize a number of vehicles needed, which have to satisfy different amounts of daily orders by customers.

    So far so good. The model works.

     

    I got the basic model from a paper i found in the inet. And the author of this paper suggests direct tours in order to calculate the daily distances, which the transporters have to cover:

     

    forall (t in TimePeriods) csExpDis: 2 * sum (i in Customers) Distance [i] == ExpDistance [t];

     

    So the model adds up the distance of each customer every day, whether or not a customer needs to be supplied on a day. I would like to optimize that constraint, so that only the distances of that customers will be considered who need to be supplied on a day.

    My idea was to include a binary variable, which is equal 1 in the case that a customer has to be supplied:

     

    forall (t in TimePeriods) csExpDis: 2 * sum (i in Customers) Distance [i] * binaryVariable == ExpDistance [t];

     

    So lets say i have a distance array (4 customers) and we consider 2 days as the number of time periods:

    Distance= [1,2,3,4];

     

    quantity = [[10  0]

                      [0   2]

                      [0   0]

                      [12 1]];

    the binary variable checks if the quantity of customer i on a day t is >0. in the case the quantity is >0, it follows that the binary variable is equal 1 (else 0).

    day 1 -> ExpDistance = 1 + 4 = 5

    day 2 -> ExpDistance = 2 + 4 = 6

     

    But this is where it gets stuck. I dont know how to implement it correctly. 

    Can you help me? Maybe there is another better approach?

     

    Many thanks in advance!

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: binary variable with if-else logic // fleet size problem



  • 3.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/06/18 03:34 AM

    Originally posted by: kalleman


    Hi Alex,

    many thanks for your answer. I read the articles, which you have stated.

    So i should use logical constraints?

     

    I tried it with this, but it didnt work in the right way:

     

    forall (i in Customers, t in TimePeriods) testCS: (Quantity [i] [t] >=0.01) => Binary[i] [t] == 1;
        
    forall (t in TimePeriods) csExpDis: 2 * sum (i in Customers) Distance [i] * Binary[i] [t] == ExpDistance [t];

     

    I think the problem is indicated in the first contraint (underlined), the LP doesn't check each consumer-quantity-combination on a given day.

    Do you have an idea? 

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: binary variable with if-else logic // fleet size problem



  • 5.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/06/18 04:21 AM

    Originally posted by: kalleman


    Mod

     

    //Data
     int NumberOfCustomers = ...; //i
     int NumberOfTimePeriods = ...; //t //in days?
     int NumberOfVehicleTypes = ...; //j
     range Customers = 1..NumberOfCustomers; //Vdistance
     range TimePeriods = 1..NumberOfTimePeriods; //VtimePeriods
     range VehicleTypes = 1..NumberOfVehicleTypes; //VvehicleTypes
     
     float Quantity [Customers] [TimePeriods] = ...; //quantity to be delivered to customer i in period t
     float MaxDistance [VehicleTypes] = ...; //maximum distance that can be travelled in a period by a vehicle of type j
     float Capacity [VehicleTypes] = ...; //maximum capacity of a vehicle of type j
     float FixCostOwnCar [VehicleTypes] = ...; //fixed cost associated with owning a vehicle of type j for T periods
     float VariableCostOwnCar [VehicleTypes] = ...; //variable cost (per unit of distance travelled) of an owned car of type j
     //float DistanceMatrix [Customers] [TimePeriods] = ...; 
     float Distance [Customers] = ...; 
     
     //decisionVars
     dvar int+ OwnCar [VehicleTypes]; //number of own cars
     dvar int+ OwnCarInUse [VehicleTypes] [TimePeriods]; //number of owned cars of type j that are used for delivery in period t
     dvar float+ DistanceTravelledOwnCar [VehicleTypes] [TimePeriods]; //distance travelled by owned car in period t (by type j)
     dvar float+ ExpDistance [TimePeriods]; //expected distance travelled in period t 
     
     dvar int  Binary[Customers] [TimePeriods] in 0..1;
     
     //Objective Function
     minimize 
      (sum (j in VehicleTypes) (FixCostOwnCar [j] * OwnCar [j]) + sum (j in VehicleTypes, t in TimePeriods) (VariableCostOwnCar [j] * DistanceTravelledOwnCar [j] [t]));
     
     
     //constraints
     subject to {
     
      forall (j in VehicleTypes, t in TimePeriods) csNumberOwnedCars: OwnCarInUse [j] [t] <= OwnCar [j];
       
      forall (t in TimePeriods) csTotalSupply: sum (j in VehicleTypes) ((OwnCarInUse [j] [t]) * MaxDistance [j]) >= ExpDistance [t] ;
       
      forall (t in TimePeriods) csSufficientCap: sum (j in VehicleTypes) (OwnCarInUse [j] [t]  * Capacity [j]) >= sum (i in Customers) Quantity [i] [t];
       
      forall (i in Customers, t in TimePeriods) testCS: (Quantity [i] [t] >=0.01) => Binary[i] [t] == 1;
       
      forall (t in TimePeriods) csExpDis: 2 * sum (i in Customers) Distance [i] * Binary[i] [t] == ExpDistance [t];
     }

     

    dat

     

    NumberOfCustomers = 3;
    NumberOfTimePeriods = 3;
    NumberOfVehicleTypes = 1;
     
     
    MaxDistance = [500];
    Capacity = [5000];
    FixCostOwnCar = [60000];
    VariableCostOwnCar = [0.8];
     
     
    Distance = [3, 6, 2];
    Quantity = [[0,10,10]
                      [10, 10, 0]
                      [0, 0,0]];
     

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/06/18 06:10 AM

    Hi,

    don t you think

    forall (i in Customers, t in TimePeriods) testCS: (Quantity [i] [t] >=0.01) == Binary[i] [t] ;

    could be better ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/06/18 07:05 AM

    Originally posted by: kalleman


    Hi Alex,

     

    i have changed the line

    dvar int Binary[Customers] [TimePeriods] in 0..1;

    to

    dvar boolean Binary[Customers] [TimePeriods];

     

    and now your proposal works. Many thanks! Problem is, that it works just for small amounts of customers.

    I tried an analysis with 25000 customers and i got out of memory and status 1001 errors.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/06/18 07:26 AM

    And how many time periods ?

    Maybe time to improve your model.

    Are you a student or a business user ?

    regards

    .


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/06/18 07:34 AM

    Originally posted by: kalleman


    313 time periods. 

     

    i am a student. i want to use that lp for my master thesis and for that matter i would like to consider customers up to 50000.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: binary variable with if-else logic // fleet size problem

    Posted 04/07/18 09:55 AM

    Originally posted by: kalleman


    Hi Alex,

    i have simplified my model:

     

    //Data
     int NumberOfCustomers = ...; //i
     int NumberOfTimePeriods = ...; //t //in days
     range Customers = 1..NumberOfCustomers; //Vdistance
     range TimePeriods = 1..NumberOfTimePeriods; //VtimePeriods
     
     float Quantity [Customers] [TimePeriods] = ...; //quantity to be delivered to customer i in period t
     float MaxDistance = ...; //maximum distance that can be travelled in a period by a vehicle 
     float Capacity = ...; //maximum capacity of a vehicle of type j
     float FixCostOwnCar = ...; //fixed cost associated with owning a vehicle for T periods
     float VariableCostOwnCar = ...; //variable cost (per unit of distance travelled) of an owned car 
     float Distance [Customers] = ...; 
     
     
     //decisionVars
     dvar int+ OwnCar; //number of own cars
     dvar int+ OwnCarInUse [TimePeriods]; //number of owned cars  that are used for delivery in period t
     dvar float+ ExpDistance [TimePeriods]; //expected distance travelled in period t  
     
     dvar boolean Binary[Customers] [TimePeriods];
     
     //Objective Function
     minimize 
      (FixCostOwnCar * OwnCar) + sum (t in TimePeriods) (VariableCostOwnCar * ExpDistance [t]);
     
     
     //constraints
     subject to {
     
      forall (t in TimePeriods) csNumberOwnedCars: OwnCarInUse [t] <= OwnCar;
       
      forall (t in TimePeriods) csTotalSupply:  (OwnCarInUse [t] * MaxDistance) >= ExpDistance [t] ;
       
      forall (t in TimePeriods) csSufficientCap: (OwnCarInUse [t]  * Capacity) >= sum (i in Customers) Quantity [i] [t];   
       
      forall (i in Customers, t in TimePeriods) testCS: (Quantity [i] [t] >=0.01) == Binary[i] [t];
       
      forall (t in TimePeriods) csExpDis: sum (i in Customers) Distance [i] * Binary[i] [t] == ExpDistance [t];
     }
     

    But the error out of memory still occurs. Do you think i can improve the constraints with the binary variable?

     

       forall (i in Customers, t in TimePeriods) testCS: (Quantity [i] [t] >=0.01) == Binary[i] [t];
       
       forall (t in TimePeriods) csExpDis: sum (i in Customers) Distance [i] * Binary[i] [t] == ExpDistance [t];

     

    And is it possible to deactivate the printing of the solutions of a decision var in the solutions window? The model prints each binary variable in the solutions window...that are a lot and i dont need them


    #DecisionOptimization
    #OPLusingCPLEXOptimizer