Decision Optimization

 View Only
Expand all | Collapse all

Error , CPLEX can't extract the expression

  • 1.  Error , CPLEX can't extract the expression

    Posted Fri June 24, 2022 03:30 PM
    HI, This is my code I can't find a solution for this error
    //INDEX
    {int} ptcharg ={1,2,3};
    {int} ptdecharg= {1,2};
    {int} typecamion= {1,2};

    //DATA
    float demand[ptdecharg]= [100,90];
    float supply[ptcharg]= [35,50,80];
    float distance[ptcharg][ptdecharg]= [[6.6,3.7],[5.3,6.7],[5.9,5.7]];
    float tcostp[typecamion]= [30,26];
    float tcostv[typecamion]= [20,15];
    float capacamion[typecamion]=[136,190];
    float vitesmoy[ptcharg]= [10,15,18];
    float vitesmoyvide[typecamion]= [45,40];
    float vitesmoycharg[typecamion]= [32,30];
    float vitesmoydecharg[typecamion]= [12,16];
    float tmt[typecamion]= [5,6];
    float tms[typecamion]= [5,6];
    //DECISION VARIBALES
    dvar int nbvoyagecharg[ptcharg][ptdecharg][typecamion];
    dvar int nbvoyagevide[ptcharg][ptdecharg][typecamion];
    //OBJ.F
    dexpr float transpcostc= sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagecharg[i][j][k]*distance[i][j]*tcostp[k];
    dexpr float transpcostv= sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagevide[i][j][k]*distance[i][j]*tcostv[k];
    dexpr float transpcosttotal=transpcostc+transpcostv;
    //MODEL
    minimize transpcosttotal;

    subject to{
    SUPPLYCONS:
    forall(j in ptcharg)
    sum(i in ptdecharg,k in typecamion) capacamion[k]*nbvoyagecharg[i][j][k]<=supply[j];

    DEMANDCONS:
    forall( i in ptdecharg)
    sum(j in ptcharg,k in typecamion) capacamion[k]*nbvoyagecharg[i][j][k]<= demand[i];

    continu:
    forall( j in ptcharg, k in typecamion)
    sum(i in ptdecharg) nbvoyagevide[i][j][k]==sum(i in ptdecharg)nbvoyagecharg[i][j][k];
    Time:
    (sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagecharg[i][j][k]*((distance[i][j]/vitesmoycharg[k])+(capacamion[k]/vitesmoy[j])+tms[k]))+ (sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagevide[i][j][k]*((distance[i][j]/vitesmoyvide[k])+(capacamion[k]/vitesmoydecharg[k])+tmt[k]))<=480*2;


    }

    I really need your help
    Many thanks


    ------------------------------
    Hajar Bnouachir
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Error , CPLEX can't extract the expression

    IBM Champion
    Posted Fri June 24, 2022 05:35 PM
    In line 29, the domains of i and j are reversed.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: Error , CPLEX can't extract the expression

    Posted Mon June 27, 2022 09:27 AM
    thank you very much, I reversed the indices and I managed to find an optimal solution, but I have negative numbers, since my decision variables are integer "the number of trips".
    le code 
    //INDEX

    {int} ptcharg ={1,2,3};
    {int} ptdecharg= {1,2};
    {int} typecamion= {1,2};

    //DATA
    int demand[ptdecharg]= [3240,3550];
    int supply[ptcharg]= [4077,4000,4050];
    float distance[ptdecharg][ptcharg] =[[6.6,5.3,5.9],[3.7,6.7,5.7]];
    int tcostp[typecamion]= [11480,25160];
    int tcostv[typecamion]= [11000,25000];
    float capacamion[typecamion]=[136,190];
    int nombrecamion[typecamion]=[9,3];
    float vitesmoy[ptcharg]= [30,36,28];
    float vitesmoyvide[typecamion]= [32,33];
    float vitesmoycharg[typecamion]= [22,20];
    float vitesmoydecharg[typecamion]= [12,16];
    int tmt[typecamion]= [5,6];
    int tms[typecamion]= [5,6];
    //DECISION VARIBALES
    dvar int nbvoyagecharg[ptdecharg][ptcharg][typecamion];
    dvar int nbvoyagevide[ptdecharg][ptcharg][typecamion];
    //OBJ.F

    dexpr float transpcostc= sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagecharg[i][j][k]*distance[i][j]*tcostp[k];
    dexpr float transpcostv= sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagevide[i][j][k]*distance[i][j]*tcostv[k];
    dexpr float transpcosttotal=transpcostc+transpcostv;
    //MODEL
    minimize transpcosttotal;

    subject to{



    //ct1
    forall(j in ptcharg)
    sum(i in ptdecharg,k in typecamion) capacamion[k]*nbvoyagecharg[i][j][k]<=supply[j];

    //ct2
    forall( i in ptdecharg)
    sum(j in ptcharg,k in typecamion) capacamion[k]*nbvoyagecharg[i][j][k]<= demand[i];

    //ct3
    forall( j in ptcharg, k in typecamion)
    sum(i in ptdecharg) nbvoyagevide[i][j][k]==sum(i in ptdecharg)nbvoyagecharg[i][j][k];
    //ct4
    (sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagecharg[i][j][k]*((distance[i][j]/vitesmoycharg[k])+(capacamion[k]/vitesmoy[j])+tms[k]))+ (sum(i in ptdecharg, j in ptcharg,k in typecamion) nbvoyagevide[i][j][k]*((distance[i][j]/vitesmoyvide[k])+(capacamion[k]/vitesmoydecharg[k])+tmt[k]))<=480*2;
    //ct5
    forall( k in typecamion)
    (sum(i in ptdecharg, j in ptcharg) nbvoyagecharg[i][j][k]*((distance[i][j]/vitesmoycharg[k])+(capacamion[k]/vitesmoy[j])+tms[k]))+ (sum(i in ptdecharg, j in ptcharg) nbvoyagevide[i][j][k]*((distance[i][j]/vitesmoyvide[k])+(capacamion[k]/vitesmoydecharg[k])+tmt[k]))<=480*nombrecamion[k];
    }


    ------------------------------
    Hajar Bnouachir
    ------------------------------



  • 4.  RE: Error , CPLEX can't extract the expression

    IBM Champion
    Posted Mon June 27, 2022 11:31 AM
    You might want to change "dvar int" to "dvar int+" (nonnegative integer), or alternatively to add an "in" clause, for instance "dvar int nbvoyagecharg[ptdecharg][ptcharg][typecamion] in 0..1000;" (substituting an appropriate upper bound for 1000).

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 5.  RE: Error , CPLEX can't extract the expression

    Posted Mon June 27, 2022 02:24 PM
    I am really sorry for the inconvenience, but when I put dvar int nbvoyagecharg[ptdecharg][ptcharg][typecamion]in 0..1000 or dvar int + the solutions becomes zero.


    ------------------------------
    Hajar Bnouachir
    ------------------------------



  • 6.  RE: Error , CPLEX can't extract the expression

    IBM Champion
    Posted Mon June 27, 2022 02:38 PM
    Then there is likely something wrong with your formulation. If you cannot figure out what, try running a small problem instance (one for which you know a good if not necessarily optimal solution). If that instance still results in a zero solution, substitute your known good solution into each constraint and see which constraints are violated. Those are like where the errors are.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 7.  RE: Error , CPLEX can't extract the expression

    Posted Mon June 27, 2022 03:44 PM
    Yes, exactly what I think, the problem in the formulation of constraints, I'm really sorry for the inconvenience, I will try to do the modeling again.
    Thank you very much.

    ------------------------------
    Hajar Bnouachir
    ------------------------------



  • 8.  RE: Error , CPLEX can't extract the expression

    Posted Tue June 28, 2022 09:36 AM
    Hajar, the issue might be that: you are minimizing the cost. But since I can’t see any constraint forcing to transport (because of demand satisfaction or stock replenishment or whatever dictates your use case) the minimum cost is obtained by not transporting anything.

    You need some balance constraint. You need to tell the model how the need to transport arises.

    Ciao / Best regards
    Stefano Gliozzi




  • 9.  RE: Error , CPLEX can't extract the expression

    Posted Tue June 28, 2022 02:32 PM
    HI, I added a constraint on the transportation objective but there is still no solution, I changed the model and I got solutions but not all the solutions are realizable normally I am looking for the number of trips of the trucks but the values in my solution are negative I can't correct them.
    new code:

    {int} n={1,2,3,4,5,6,7};// Point de chargement
    {int} p={1,2}; // types de camion

    //DATA
    int Q[n]=[3240,2256,2146,828,3740,3220,1542];
    int K[n]=[4077,5245,6402,3672,4822,4220,2755];
    float d[n]=[6.6,5.3,5.9,3.7,6.7,5.7,4.7]; //km
    int Cost[p]=[11480,25160]; // DH/h
    int Va[p]=[22,32]; // km/h
    float Vr[p]=[22,32]; // km/h
    int Cap[p]=[136,190]; // tonnes
    float Tch[p]=[6,4]; // min
    float Tdech[p]=[5,3];// min
    float T[p]=[41,40]; // min
    int disp[p]=[6,3];


    //DECISION VARIBALES
    dvar int+ Nih[n][p];
    //OBJ.F

    dexpr float Z= sum(i in n, h in p) Nih[i][h]*Cost[h]*((d[i]/Va[h])+(d[i]/Vr[h]));

    //MODEL
    minimize Z;

    subject to{

    //ct1 La demande de chaque origine
    forall(i in n)
    sum(h in p) Nih[i][h]*Cap[h]>= Q[i];
    //ct2 Quantite diponible
    forall(i in n)
    sum(h in p) Nih[i][h]*Cap[h]<= K[i];
    //ct3 disponibilite camion
    forall(h in p)
    sum(i in n)Nih[i][h]*(((d[i]/Va[h])*60)+((d[i]/Vr[h])*60)+Tch[h]+Tdech[h])<= T[h]*disp[h];

    }


    ------------------------------
    Hajar Bnouachir
    ------------------------------



  • 10.  RE: Error , CPLEX can't extract the expression

    Posted Mon July 25, 2022 10:07 AM

    minimize transpcosttotal;

    subject to{
    SUPPLYCONS:
    forall(j in ptcharg)
    sum(i in ptdecharg,k in typecamion) capacamion[k]*nbvoyagecharg[i][j][k]<=supply[j];

    DEMANDCONS:
    forall( i in ptdecharg)
    sum(j in ptcharg,k in typecamion) capacamion[k]*nbvoyagecharg[i][j][k]<= demand[i];

    Read more



    ------------------------------
    ben len
    ------------------------------