Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  TSP with vehicle selection

    Posted 05/21/20 12:39 PM
    Hi everyone,
    I am new to OPL and CPLEX and am trying to formulate an objective function where I minimize the distances and costs by letting the model decide which type of vehicle should be used (with 1 driver on 1 day). I have been able to make separate models for each of the vehicles (using tsp) but when trying to combine them I get stuck on the distance being depend on the vehicle. I was wondering whether this is possible to program and how I should  create a matrix of distance differing per vehicle. I have been browsing through the internet and trying several things in OPL for a while now and was hoping that someone could help me out. If have 

    int n=...; // number of customers to be visited
    n= 9

    range N=1..n;

    string name[N]=...; 

    int v=...; // n0 of possible vehicle used.
    v= 2.

    range V=1..v;

    string type[V]=...;

    int d[V][N][N] = ...;

    dvar boolean x[V][N][N];// travelled from i to j using vehicle V

     dvar int+ u[N];

     minimize sum(i,j in N: v in V) d[v][i][j]*x[v][i][j];

    subject to {

       forall (i in N: v in V)

         sum (j in N) x[v][i][j] == 1;

         

         forall (j in N: v in V)

           sum (i in N) x[v][i][j] == 1;

           

          forall (i,j in N :i != j && j != 1 && v in V)

           u[i] + 1 <= u[j] + 10 * (1-x[v][i][j]);

             

             forall ( i in N: v in V)

               x[v][i][i] == 0;

               

               forall (j in N: v in V)

                 x[v][j][j] == 0;

               

               u[1] == 1;

             }           

             
    I would like to thank you for taking the time to read this.





    ------------------------------
    Fiona T
    ------------------------------

    #DecisionOptimization


  • 2.  RE: TSP with vehicle selection

    Posted 05/25/20 01:12 AM
    Could you be more specific about what your problem is?

    Your objective function looks correct to me. So does the distance matrix (or is the question how to create the distance matrix in the .dat file?).

    What looks wrong are things lie this:
    forall (i in N: v in V)
    This should produce an error that "v is not defined". As far as I can tell, you want to loop over all i and all v. This is done using
    forall (i in N, v in V)
    In your case another option is to wrap the whole constraint section into a big "forall (v in V)", like so:
    forall (v in V) {
       // What follows is the TSP model for one particular vehicle, namely vehicle v

      forall (i in N) sum (j in N) x[v][i][j] == 1;

      forall (j in N) sum (i in N) x[v][i][j] == 1;

      forall (i,j in N :i != j && j != 1u[i] + 1 <= u[j] + 10 * (1-x[v][i][j]);

      forall ( i in N) x[v][i][i] == 0;

      forall (j in N)  x[v][j][j] == 0;

    }

    I am not sure about constraint u[1] == 1. Should this be stated for each vehicle?

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 3.  RE: TSP with vehicle selection

    Posted 05/25/20 03:50 AM
    Thank you so much for your reply! 

    I was indeed mostly struggling with the creation of the distance matrix in the .dat file. I was wondering how to correctly indicate which distance is linked to which vehicle so far I have (unsuccessfully) tried several options such as:
    d=[
    [vehicle 1 dist1 dist 2 dist 3 etc.],
    [vehicle 2 dist1 dist 2 dist 3 etc.],
    or 
    d[1]=[
    [dist1 dist 2 dist 3 etc.],
    or
    d=[
    [1][dist1 dist 2 dist 3 etc.],
    [2]vehicle 2 dist1 dist 2 dist 3 etc.],

    Regarding the u[1]==1, It should be stated for each vehicle as it is the first observation in my dataset and therefore does not include parameters such as the length at the customer but also the distance towards the first point. 

    I would also like to thank you for the big loop, I had no idea that this was an possibility and it removes an error in a different model I am using!! 






    ------------------------------
    Fiona T
    ------------------------------



  • 4.  RE: TSP with vehicle selection

    Posted 05/25/20 05:04 AM
    The layout of d in your .dat file should be like this:

    d = [ [ [ v0n00, v0n01, v0n02, ... ],
            [ v0n10, v0n11, v0n12, ... ]
             ...
           ],
           [ [v1n00, v1n01, v1n02, ... ],
             [v1n10, v1n11, v1n12, ... ],
             ...
           ]
         ];

    Here vknij means the distance between i and j for vehicle k.

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 5.  RE: TSP with vehicle selection

    Posted 05/25/20 07:08 AM
    Thank you so much! it works now!

    ------------------------------
    Fiona T
    ------------------------------