Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Decision Variable Not Allowed Error

    Posted 08/11/13 03:49 PM

    Originally posted by: Puppy26


    Dear all,

    I'm a new user of CPLEX for my thesis work. I'm constantly getting an error as Decision Variable (expression) not allowed.

    I'm getting some error as "Decision variable (expression) "Open" not allowed". If I remove the open parameter from the code, again I'm getting error as "CTSupply" not allowed.

    For your reference, I have the code of the project. 

     

     

    float Fixed = ...;
    float Revenue = ...;
    float ECDemanded = ...;
    float TSCFixed = ...;
    float DSCFixed = ...;
    float DSCost = ...;
    float ISTerminal = ...;
    float ISDepot = ...;
    {string} Terminals = ...;
    {string} Depots = ...;
    int NbShippers = ...;
    int NbConsignees = ...;
    range Shippers = 0..NbShippers-1;
    range Consignees = 0..NbConsignees-1;
    float Capacity[Depots] = ...;
    float ConsigneesCost[Depots][Consignees] = ...;
    float ShippersCost[Shippers][Depots] = ...;
    float ConstoTerminCost[Terminals][Consignees] = ...;
    float TermfloatoDepotCost[Depots][Terminals] = ...;
    float DepottoTerminCost[Terminals][Depots] = ...;
    float DepottoDepotCost [Depots][Depots] = ...;
    float STCcost [Shippers][Consignees] = ...;
      dvar boolean CTSupply;
      dvar boolean DSSupply;
      dvar boolean CDSupply;
      dvar boolean STSupply;
      dvar boolean TDSupply;
      dvar boolean DTSupply;
      dvar boolean DDSupply;
    dvar boolean Open[Depots];
    float RG = Revenue * ECDemanded;
    float TC =  sum( d in Depots ) 
        Fixed * Open[d] + sum (c in Consignees, t in Terminals) 
    ConstoTerminCost [t][c] * CTSupply + 
     sum (d in Depots, c in Consignees) ConsigneesCost [d][c] * CDSupply + 
     sum (s in Shippers, c in Consignees) STCcost [s][c] * (0.15 * ECDemanded) + 
     sum (s in Shippers, d in Depots) ShippersCost [s][d] * DSSupply + 
     sum (d in Depots, t in Terminals) TermfloatoDepotCost [d][t] * TDSupply +
     sum (t in Terminals, d in Depots) DepottoTerminCost [t][d] * DTSupply + 
     sum (t in Terminals) TSCFixed * (ISTerminal + CTSupply + DTSupply - TDSupply) + 
     sum (d in Depots) DSCFixed * (ISDepot + CDSupply + TDSupply - DSSupply - DTSupply - DDSupply) + 
     sum( d in Depots) DepottoDepotCost[d][d] * DDSupply;
        
    float Max = RG - TC ;
     
    subject to
    {
       forall (d in Depots)
         ctEachDepotHasOneConsignee:
           sum (c in Consignees)
             CDSupply ==1;
             
       forall (s in Shippers)
          ctEachShipperHasOneDepot:
            sum (d in Depots)
              DSSupply ==1;
              
       forall (d in Depots)
         ctUseOpenDepots:
           sum (d in Depots) DDSupply + sum (d in Depots) CDSupply  <= Open [d] * Capacity [d];       
    }        
     
     Please do help me. 

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Decision Variable Not Allowed Error

    Posted 08/12/13 02:09 AM

    You are trying to assign an expression that involves decision variables to a constant value of type 'float'. This cannot work since expressions involving decision variables are not constant (their value is determined during optimization).

    You can try to use 'dexpr TC' instead of 'float TC' (and then also change 'float Max' to 'dexpr Max').


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Decision Variable Not Allowed Error

    Posted 08/12/13 01:00 PM

    Originally posted by: Puppy26


    Hi Daniel,

    Thanks for your response.

    If I try to change the float to dexpr TC, I'm getting an error as "Syntax error, unexpected =,  expecting (identifier) or '['.

    Please advice me how to rectify this issue now.

    for your reference, I have attached the code and screenshot of an error.

    /*********************************************
     * OPL 12.5 Model
     * Author: Prabhu426
     * Creation Date: Aug 11, 2013 at 9:39:23 PM
     *********************************************/
     
    float Fixed = ...;
    float Revenue = ...;
    float ECDemanded = ...;
    float TSCFixed = ...;
    float DSCFixed = ...;
    float DSCost = ...;
    float ISTerminal = ...;
    float ISDepot = ...;
    {string} Terminals = ...;
    {string} Depots = ...;
    int NbShippers = ...;
    int NbConsignees = ...;
    range Shippers = 0..NbShippers-1;
    range Consignees = 0..NbConsignees-1;
    float Capacity[Depots] = ...;
    float ConsigneesCost[Depots][Consignees] = ...;
    float ShippersCost[Shippers][Depots] = ...;
    float ConstoTerminCost[Terminals][Consignees] = ...;
    float TermintoDepotCost[Depots][Terminals] = ...;
    float DepottoTerminCost[Terminals][Depots] = ...;
    float DepottoDepotCost [Depots][Depots] = ...;
    float STCcost [Shippers][Consignees] = ...;
      dvar boolean CTSupply;
      dvar boolean DSSupply;
      dvar boolean CDSupply;
      dvar boolean STSupply;
      dvar boolean TDSupply;
      dvar boolean DTSupply;
      dvar boolean DDSupply;
    dvar boolean Open[Depots];
     
    dexpr RG = Revenue * ECDemanded;
     
    dexpr TC  = sum( d in Depots ) 
        Fixed * Open[d] + sum (t in Terminals, c in Consignees) ConstoTerminCost [t][c] * CTSupply + 
     sum (d in Depots, c in Consignees) ConsigneesCost [d][c] * CDSupply [d][c] + 
     sum (s in Shippers, c in Consignees) STCcost [s][c] * (0.15 * ECDemanded) + 
     sum (s in Shippers, d in Depots) ShippersCost [s][d] * DSSupply + 
     sum (d in Depots, t in Terminals) TermintoDepotCost [d][t] * TDSupply +
     sum (t in Terminals, d in Depots) DepottoTerminCost [t][d] * DTSupply + 
     sum (t in Terminals) TSCFixed * (ISTerminal + CTSupply + DTSupply - TDSupply) + 
     sum (d in Depots) DSCFixed * (ISDepot + CDSupply + TDSupply - DSSupply - DTSupply - DDSupply) + 
     sum( d in Depots) DepottoDepotCost[d][d] * DDSupply;
        
    maximize RG-TC ;
     
    subject to
    {
       forall (d in Depots)
         ctEachDepotHasOneConsignee:
           sum (c in Consignees)
             CDSupply ==1;
             
       forall (s in Shippers)
          ctEachShipperHasOneDepot:
            sum (d in Depots)
              DSSupply ==1;
              
       forall (d in Depots)
         ctUseOpenDepots:
           sum (d in Depots) DDSupply + sum (d in Depots) CDSupply  <= Open [d] * Capacity [d];
            
    }
     

    Many thanks!

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Decision Variable Not Allowed Error

    Posted 08/12/13 04:46 PM

    Originally posted by: Puppy26


    Hi Daniel,

    I have cleared that error now. I have added dexpr float which cleared the problem.

    The model is error free but when I run the model, i'm getting an error as Index out of bounds for "Terminals".

    For your reference, I have included my sample data and error screen shot here.

     
    Fixed = 50;
     Revenue = 100;
     ECDemanded = 200;
     TSCFixed = 50;
     DSCFixed = 50;
     ISTerminal = 50;
     ISDepot = 50;
     Terminals = {Hamburg};
     Depots = {Erlangen, Russelsheim};
     NbShippers = 3;
     NbConsignees = 3;
     Capacity = [10,50];
     ConsigneesCost = [
       [20, 10, 30],
       [15, 20, 25]];
     ShippersCost =[
        [10, 15],
        [15, 20]
        [10, 20]];
        
     ConstoTerminCost = [[30, 10, 5]
      [40, 20, 10]
      [10, 10, 20]];

     

     TermintoDepotCost = [
      [10]
      [20]];
     
     DepottoTerminCost = 
      [10, 15];

     

     DepottoDepotCost = [10];

     

     STCcost = [
        [10, 15, 20]
        [20, 30, 40]
        [15, 20, 30]];

     

    Could you please let me know what's the problem here..

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Decision Variable Not Allowed Error

    Posted 08/13/13 03:03 AM

    Originally posted by: trebron


    You have just one Terminal

     Terminals = {Hamburg};

    but you are iterating

      float ConstoTerminCost[Terminals][Consignees] = ...;

    over 3 terminals ...

       ConstoTerminCost = [[30, 10, 5]
      [40, 20, 10]
      [10, 10, 20]];

    Best regards

        Norbert


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Decision Variable Not Allowed Error

    Posted 08/13/13 03:15 AM

    Originally posted by: Puppy26


    Hi,

    Thanks for your response.

    Initially I gave the data for

    float ConstoTerminCost[Terminals][Consignees] = ...;

    as

     ConstoTerminCost = [[10]

                                              [15]

                                              [10]];

    But I got the same error thats I tried with 3*3 matrix but still the error is same. Could you please advise me how I should give the input now for this case!!

    Many thanks!

    Regards,

    Prabhu

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Decision Variable Not Allowed Error

    Posted 08/13/13 03:27 AM

    Originally posted by: trebron


    Prabhu,

    you should give

    ConstoTerminCost = [[10, 15, 10]];

    a try.

     

    Regards

        Norbert


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Decision Variable Not Allowed Error

    Posted 08/13/13 05:09 AM

    Originally posted by: Puppy26


    Hi Norbert,

    Well, I tried in the way you mentioned but got the same error.

    Bit confused about how to proceed further! any help please.

     

    Regards,

    Prabhu


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Decision Variable Not Allowed Error

    Posted 08/13/13 05:32 AM

    Originally posted by: trebron


    Prabhu,

    hard to believe that you will get the same error - at least I get a different one.  You should properly check all the dimensions of your model elements, e.g.

    you try to access

    (*) CDSupply [d][c], whereas it is declared "dvar boolean CDSupply;" (no array !!)

    (*)  DepottoTerminCost =   [10, 15]; whereas it is declared as a 2-dim-array

    and so on.

    You should  correct all these dimensioning errors (check DepottoDepotCost as well).

    Regards

       Norbert


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Decision Variable Not Allowed Error

    Posted 08/13/13 11:44 AM

    Originally posted by: Puppy26


    Nobert,

    Thanks a lot for your kind advise... I have re-arranged all the data and it works perfectly well.

    Thanks to Daniel too for your kind help.

    Regards,

    Prabhu


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Decision Variable Not Allowed Error

    Posted 08/15/13 04:51 PM

    Originally posted by: Puppy26


    Hi all,

    Just got struck now in the model while including time period. 

    In my case, say for example, I have 3 importers and 3 exporters, 3 depots and 1 port terminals.

    As per the model, an importer can serve only one depot and one depot can only serve one exporter. In addition, if the depot is closed once, it can't be opened in the next time period. That is the depot can either be opened completely in the operation period or it should be closed after certain time period.

    My plan was to construct the model for the time period of 0..5 (for example).

    For Depot1, it is opened throughout the time period 1 to 5 so there is a movement between consignee, depot and shippers all the time.

    For Depot2, it is only opened from time period 1 to 3 so there is a movement between Consignees, Depot and shipper till time period 3 after that depot is closed and hence there is no movements them..

    For Depot3, it is opened only in time period 1 and 2 and closed for the remaining period. The same movement formulation applies here too.

    I know we can do it using FOR and IF statement but I tried with some methods but getting some syntax error.

    Could some one help me please.

    For your reference, I have attached the code here.  Please let me know if it's not clear.

    Many thanks!

    Regards,

    Prabhu


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Decision Variable Not Allowed Error

    Posted 08/21/13 05:45 AM

    Originally posted by: TobiasAchterberg


    I guess you should repost this in the OPL forum here: https://www.ibm.com/developerworks/community/forums/html/forum?id=11111111-0000-0000-0000-000000002053


    #CPLEXOptimizers
    #DecisionOptimization