Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

CPLEX cannot extract expression

  • 1.  CPLEX cannot extract expression

    Posted 10/31/11 02:12 AM

    Originally posted by: kutikz


    hi..
    please help me to solve this problem. im a beginner user for CPLEX, and i wanna use CPLEX to solve MIP problem but i found so many errors which said that "CPLEX cannot extract expression"

    for example:
    CPLEX(default) cannot extract expression: c16: forall(t in 1..10) sum(i in 1..12) w(i)(t) <= inventP(t+(-1)).

    for

    c16=forall(t in period) sum(i in customer)w[i][t]<=inventPt-1;
    where
    period=1..10;
    customer=1..12;
    dvar int Pperiod;
    dvar int wcustomerperiod;
    thanks in advance
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: CPLEX cannot extract expression

    Posted 10/31/11 05:55 AM

    Originally posted by: SystemAdmin


    Hi,

    I'm not sure, as the code is not properly formatted and I coud not find the declaration for
    inventP[]
    

    but my guess is that for t=1 you access inventP[0], which is not defined.

    Hope this wil be of any help.

    Regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: CPLEX cannot extract expression

    Posted 10/31/11 07:37 AM

    Originally posted by: kutikz


    sorry, what i meant was inventPperiod

    if i assume that inventP[0]=0, should i change the range of the period?or how should i manage this problem?

    many thanks
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: CPLEX cannot extract expression

    Posted 10/31/11 09:39 AM

    Originally posted by: SystemAdmin


    What you should do is define a range 0..10 and index inventP[] over this range.
    What is inventP[]? A data element or a decision variable. Dependent on this
    answer you will have to initialize/fix the value of inventP[0] to zero.

    Regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: CPLEX cannot extract expression

    Posted 10/31/11 10:20 AM

    Originally posted by: kutikz


    inventP[] is a decision variable, but for period 0 or inventP[0] the value will be set to 0.
    im not sure about how to set it.
    and, is it possible if i make two different ranges for the period ? because in other constraints im only using period 1 until 14

    thanks
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: CPLEX cannot extract expression

    Posted 10/31/11 10:32 AM

    Originally posted by: SystemAdmin


    You can define as many ranges as you like
    range Periods0 = 0..10;
    range Periods1 = 1..10;
    range Periods2 = 1..14;
     
    dvar int x[Periods0];
    dvar int y[Periods1];
    dvar int z[Periods2];
    

    (and so so ...) What you cannot do is define one set over two ranges ;-) ...

    The easiest way to fix inventP[0] to 0 is to add a constraint
    inventP[0] == 0;
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: CPLEX cannot extract expression

    Posted 10/31/11 10:36 AM

    Originally posted by: kutikz


    thank you :D
    this is really helpful
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: CPLEX cannot extract expression

    Posted 10/31/11 11:22 AM

    Originally posted by: kutikz


    i have tried the code as u suggested but im still finding errors, may u help me to trace the causes?
    i attached my model, please take a look at them. really need ur help

    thank you
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: CPLEX cannot extract expression

    Posted 10/31/11 11:38 AM

    Originally posted by: kutikz


    need some help more because i still find error in my model
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: CPLEX cannot extract expression

    Posted 10/31/11 12:06 PM
    Hi

    you made an error with the index.

    In the objective

    sum(i in customer, t in period1)(((2*dist[0][i])/dem[i][t])*w[i][t])
    


    t is in period1 ie 0 .. T-1 whereas dem is defined on period ie 1 .. T

    Instead of

    sum(i in customer, t in period1)
    


    maybe you should write

    sum(i in customer, t in period)
    


    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: CPLEX cannot extract expression

    Posted 11/02/16 04:41 PM

    Originally posted by: telangana


    Hi Alex,

     I am attaching my mod as well as dat file of my model


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: CPLEX cannot extract expression

    Posted 11/03/16 04:38 AM

    Hi,

    sometimes it s better to create a new thread rather than use an old thread in the forum.

    Can you attach your xls file too ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: CPLEX cannot extract expression

    Posted 11/03/16 07:37 PM

    Originally posted by: telangana


    Hi,

    Iam attaching my xls file .Please find the attachment


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  Re: CPLEX cannot extract expression

    Posted 11/04/16 04:10 AM

    Hi,

    simply an out of bound.

    minimize  sum(t in 1..5) (p*X[t]+k*H[t]+l*F[t]+r*W[t]+e*I[t]);
      //constraints
      subject to
      {
      forall(t in weeks:(t-1) in weeks )
       conso1:
        W[t]== W[t+(-1)]+H[t]-F[t];
        
        forall(t in weeks:(t-1) in weeks)
         conso2:
        I[t]==I[t-1]+X[t]-demand[t];
         
         W0==5;
         I0==20;
        
          
      }
     

    will work fine.

     

    I changed 

    forall(t in weeks)

    into

    forall(t in weeks:(t-1) in weeks)

    regards

     

    PS:

    Do not hesitate to retweet

    https://twitter.com/AlexFleischer1/status/773415864959991808

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 15.  Re: CPLEX cannot extract expression

    Posted 11/04/16 03:29 PM

    Originally posted by: telangana


    Hi,

    Thank you for helping me its working and one more problem is i am facing problem in attaching access file .

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 16.  Re: CPLEX cannot extract expression

    Posted 11/04/16 03:55 PM

    Hi,

    are you a researcher ?

    {string} cargos={"A","B"};
    {string} compartment={"1","2"};
    tuple cargotype{
    float available_weight;
    float volume_per_ton;
    float profit_per_ton;
    }
    tuple compatype {
    float weightcapacity;
    float spacecapacity;
    }
    cargotype cargodata [i in cargos]=<1,2.0,3.0>;
    compatype compadata [i in compartment]=<1.0,2.0>;

    //variables
    dvar float+ x[cargos][compartment];
    dvar float+ y;

    dexpr float profit = sum (i in cargos,j in compartment)cargodata[i].profit_per_ton*x [i][j];


    dexpr float SpaceUsedPerComp[j in compartment] = sum (i in cargos) cargodata[i].volume_per_ton * x[i][j];
    dexpr float weightusedpercomp[j in compartment]= sum(i in cargos)x[i][j];

    maximize profit;
    subject to
    {
    SpaceUsedPerComp["1"]==0;
    weightusedpercomp["1"]==0;
    }

    works fine.

    What is the error you get ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 17.  Re: CPLEX cannot extract expression

    Posted 11/04/16 08:05 PM

    Originally posted by: telangana


    Hi,

    Yes I am a research assistant in my university.

    dexpr float SpaceUsedPerComp[j in compartment] = sum (i in cargos) cargodata[i].volume_per_ton * x[i][j];

    at this line i am getting error and it is  variable indexer size is not allowed for generic array.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 18.  Re: CPLEX cannot extract expression

    Posted 11/05/16 10:32 AM

    Hi,

    ok, can you try to comment that so that it works and

    then do oplrun -de in order to export .dat and

    then share that .dat here ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer