Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  using tuple elements on objective function

    Posted 06/22/18 01:47 PM

    Originally posted by: labrecheMustapha


    Hi,

    i am working on VRP, and i am using cplex.

    i need to know how to use a tuple element in objective function, some thing like this : 

     

    tuple Structures {
    int i; //index of structure
    string h;
    int failure_probability_value_category; 
    float failure_probability_threshold; 
    string consequence_category; 
    float consequence_area;
    int consequence_economic;
    string risk_category;
    }

    dvar boolean y[Cities,Vehicles,Inspection_technic];

    dexpr float TotalFailureCost= sum (i in Cities:i!=1,k in Vehicles,l in Inspection_technic) y[i,k,l] * (art.consequence_economic);// here i want to use the "consequence_economic" for each city "i" 

     

    Note that the element i in tuple and decision variable are same .

     

    Thanks.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: using tuple elements on objective function

    Posted 06/22/18 04:04 PM

    How are your instances of 'Structures' stored? Are they in a set? Are they in an array? How is the collection indexed?

    Unless you have them stored in something that is indexed by i you can just sum over all elements in the container and filter anything that has the i field different from the current city. This will take some time during generation but in the model handed to the engine there will only be single variable in the sum (the one with .i==current city).


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: using tuple elements on objective function

    Posted 06/25/18 05:22 AM

    Originally posted by: labrecheMustapha


    hi, 

    this is my .dat and .mod 

    .mod : 

     

    /*********************************************
      Ensembles
    **********************************************/
    //Villes
    //les villes de 1 à n et les structures de 2 à n avec noeud 1 comme dépôt
    int n=...;
    range Cities= 1..n;
     
    //Véhicules
    int m=...;
    range Vehicles= 1..m;
     
    //Techniques d'inspections
    {string} Inspection_technic =...;
     
    //Etats de santé
    {string} State_health =...;
     
     
     
     
    /*********************************************
      Données
    **********************************************/
    //Correspondances techniques d'inspection et vehicules 
    int o[Inspection_technic,Vehicles]=...;
     
    //Besoin de chaque structures en techniques
    int p[Inspection_technic,Cities]=...;
     
    //Etat de santé de la structure
    int z[Cities,State_health]=...;
     
    //Coordonnées des villes
    tuple location {
    float x;
    float y;
    }
    location cityLocation [Cities] ;
     
    //enumération des arcs entre toutes les villes (réseau complet)
    tuple edge {
    int i;
    int j;
    string t;
    }
    setof (edge)Edges = {<i,j,t> | i,j in Cities, t in Inspection_technic : i!=j} ;
     
    tuple Structures {
    int i;
    string h;
    int failure_probability_value_category; 
    float failure_probability_threshold; 
    string consequence_category; 
    float consequence_area;
    int consequence_economic;
    string risk_category;
    }
     
    tuple Arts {
    int i;
    int consequence_economic;
    }
     
    {Structures} structure = ...;
    {Arts} art ={<s.i, s.consequence_economic>| s in structure};
     
    {Structures} StructuresArray[i in art] = { s | s in structure : s.i==i.i && s.consequence_economic==i.consequence_economic};
    //Sous tours
    tuple Subtour { 
    int size; 
    int subtour[Cities]; 
    }
    {Subtour} subtours = ...;
     
    //Coûts 
    float c[Edges];
    float c_distance=...;
     
    //Coefficients : 
    float c_inspection[Inspection_technic]=...; //allocation matériels
    float k_inspection[Inspection_technic,Cities]=...;//coeeficient relatif au proportions et dimensions des structures  
     
    //Géneration aléatoire des coordonnées et calcul de la distance
    execute {
    function getDistance (city1,city2) {
    return Opl.sqrt(Opl.pow(city1.x-city2.x,2)+Opl.pow(city1.y-city2.y,2));
    }
     
    for (var i in Cities) {
    cityLocation[i].x=Opl.rand(100);
    cityLocation[i].y=Opl.rand(100);
    }
    //Depôt
    cityLocation[1].x=0; 
    cityLocation[1].y=0;
    for (var e in Edges){
    //Calcul de la distance
    c[e]=getDistance(cityLocation[e.i],cityLocation[e.j])
    }  
    }
     
    /*********************************************
    Variables de décision
    **********************************************/
     
    dvar boolean x[Edges,Vehicles];
    dvar boolean y[Cities,Vehicles,Inspection_technic];
    dvar int u[1..n] in 1..n;
     
    /*********************************************
    Objectif
    **********************************************/
    dexpr float TotalDistance= sum(e in Edges,k in Vehicles) c[e]* x[e,k]*c_distance;
    dexpr float TotalInspectionCost= sum (i in Cities:i!=1,k in Vehicles,l in Inspection_technic) y[i,k,l]*c_inspection[l]*k_inspection[l,i];

    /**/

    dexpr float TotalFailureCost= sum (i in Cities:i!=1,k in Vehicles,l in Inspection_technic) y[i,k,l] * StructuresArray[i];//**********************************//

    /**/

     

    minimize TotalDistance+TotalInspectionCost;
     
    /*********************************************
        Contraintes
    **********************************************/
    subject to {
    //Chaque ville "i" est visitée une seule fois par le véhicule "k" chargé par la technique "l" dont il a la compatibilité
    forall (i in Cities:i!=1,l in Inspection_technic)
           sum (k in Vehicles) y[i,k,l] == p[l,i] ;
           
        forall (k in Vehicles,i in Cities:i!=1,l in Inspection_technic)
           y[i,k,l] <= o[l,k];
           
    //L'ensemble des "m" véhicules quittent le dépôt 
    sum (k in Vehicles,l in Inspection_technic) y[1,k,l] == m;
     
    //Contraintes de conservation des flux (rentrer et sortir)
    forall (i in Cities:i!=1,k in Vehicles,l in Inspection_technic)
       y[i,k,l]-sum (j in Cities:<i,j,l> in Edges) x[<i,j,l>,k]==0;  
    forall (j in Cities:j!=1,k in Vehicles,l in Inspection_technic)
       y[j,k,l]-sum (i in Cities:<i,j,l> in Edges) x[<i,j,l>,k]==0;
       
    //Contrainte du nombre minimum de visite par véhicule    
        forall (k in Vehicles,l in Inspection_technic)
      sum (i in Cities:i!=1) y[i,k,l]>= 0;
     
    //Chaque structures à un seul état de santé à prendre dans une solution 
    // forall (i in Cities:i!=1)
    //   sum (h in State_health) z[i,h] == 1;
     
     
    // Subtour elimination constraints.
    u[1]==1;
    forall(i in 2..n) 2<=u[i]<=n;
    forall(k in Vehicles,e in Edges:e.i!=1 && e.j!=1) (u[e.j]-u[e.i])+1<=(n-1)*(1-x[e,k]);
          }

     

    .dat : 

    n= 13;
    m= 4;
    Inspection_technic = {"Visuelle" , "Technique", "Approfondie", "Reparation"};
    State_health = {"Classe 0", "Classe 1" , "Classe 2", "Classe 2E", "Classe 3", "Classe 3U"};
    subtours = {};
    c_distance=0.01;
    p=[/*
                    1  2  3  4  5  6  7  8  9  10 11 12 13*/
    /*Visuelle*/   [0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0],
    /*Technique*/  [0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0],
    /*Approfondie*/[0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
    /*Reparation*/ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
    ];
     
     
    c_inspection=[100, 300, 500, 2000];
    k_inspection=[[0, 1, 1.164, 1.1885, 1.772, 1.482, 1.469, 1.149, 1.454, 1, 1.310, 1.283, 1.823],
      [0, 1, 1.164, 1.1885, 1.772, 1.482, 1.469, 1.149, 1.454, 1, 1.310, 1.283, 1.823],
      [0, 1, 1.164, 1.1885, 1.772, 1.482, 1.469, 1.149, 1.454, 1, 1.310, 1.283, 1.823],
      [0, 1, 1.164, 1.1885, 1.772, 1.482, 1.469, 1.149, 1.454, 1, 1.310, 1.283, 1.823]];
     
     
    structure = {
    <1,"Classe 0",1,0.1,"A",0,0,"Faible">
    <2,"Classe 1",1,0.1,"A",10,10000,"Faible">
    <7,"Classe 2",2,0.2,"A",10,10000,"Faible">
    <3,"Classe 3",3,0.3,"A",10,10000,"Faible">
    <6,"Classe 3",3,0.3,"B",100,100000,"Faible">
    <12,"Classe 3U",4,0.5,"B",100,100000,"Moyen">
    <11,"Classe 1",1,0.1,"C",300,1000000,"Moyen">
    <8,"Classe 2",2,0.2,"C",300,1000000,"Moyen">
    <9,"Classe 3",3,0.3,"C",300,1000000,"Moyen">
    <4,"Classe 1",1,0.1,"D",1000,10000000,"Moyen">
    <10,"Classe 2",2,0.2,"D",1000,10000000,"Moyen">
    <5,"Classe 2E",3,0.3,"D",1000,10000000,"Moyennement élevé">
    <13,"Classe 3U",4,0.5,"D",1000,10000000,"Moyennement élevé">
    };
     
     
     
    z=[/*
     0  1  2  2E 3  3U*/
    [1, 0, 0, 0, 0, 0],/*1*/
    [0, 1, 0, 0, 0, 0],/*2*/
    [0, 0, 0, 0, 1, 0],/*3*/
    [0, 1, 0, 0, 0, 0],/*4*/
    [0, 0, 0, 1, 0, 0],/*5*/
    [0, 0, 0, 0, 1, 0],/*6*/
    [0, 0, 1, 0, 0, 0],/*7*/
    [0, 0, 1, 0, 0, 0],/*8*/
    [0, 0, 0, 0, 1, 0],/*9*/
    [0, 0, 1, 0, 0, 0],/*10*/
    [0, 1, 0, 0, 0, 0],/*11*/
    [0, 0, 0, 0, 0, 1],/*12*/
    [0, 0, 0, 0, 0, 1]/*13*/
    ];
     
    o=[
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
    [1, 0, 0, 0]
    ];

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: using tuple elements on objective function

    Posted 06/29/18 02:06 AM

    It is not clear which field from the tuple you want in your objective. If I understood correctly then you are looking for something like this

    dexpr float TotalFailureCost= sum (i in Cities:i!=1,k in Vehicles,l in Inspection_technic) y[i,k,l] * (sum (s in structure : s.i == i) s.the_field_you_want)

    The term in red will give you the sum of the_field_you_want in all structures that have s.i==i. If you have exactly one such structure then this is exactly what you were asking for? Maybe you need to add more conditions to 's.i == i' to further filter the structures you want to see there.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: using tuple elements on objective function

    Posted 06/29/18 07:27 AM

    Originally posted by: labrecheMustapha


    Thank u @DanielJunglas 548c249b-bb6b-42f6-99b8-f0376c80829e, it works!


    #CPLEXOptimizers
    #DecisionOptimization