Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Circular dependency problem 2

    Posted Mon June 01, 2015 01:51 PM

    Originally posted by: StevinYao


    Hey guys,

    I am working on a problem which involves a constraint on a decision expression. Since the value of the expression at time t+1 depends on its value at time t, one error regarding "circular dependency" is prompted.

    The expression is as follows.

    where all the variables related to time index t or t-1 are denoted using parentheses, while constants are simply represented by letter.  Lower case variables are decision variables; upper case variables are expressed as decision expressions; and bold upper case are decision expression vector. 

    I have a bound constraint on B(t). To be clear, the vector C, D[t], D[t-1] are apportion plans, i.e., the summation of all the elements of C, D[t], D[t-1] equals to 1. y[t] is a indicator variable (boolean).

    No matter how I tried, I can't avoid the circular dependency error. 

    I searched the forum about this problem. There is a topic posted about circular dependency error, and the link for that post is https://www.ibm.com/developerworks/community/forums/html/topic?id=27bced2b-1dab-419a-a3fd-563287bcea12&ps=25.

    I tried to use the second option listed in the post. However, B(t) in my case, is a float number, and it is not supported by CP optimizer. 

    Is there anyway that I can express this decision expression?

     

    All the best,

    Stevin


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Circular dependency problem 2

    Posted Tue June 02, 2015 01:23 AM

    Originally posted by: StevinYao


    I just translate the original model into the version using CPLEX, so the decision variable could be float. Keep trying to fix this by tomorrow. 

    The efficiency of CPLEX solver is much faster than the CP. Happy about this...


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Circular dependency problem 2

    Posted Wed June 03, 2015 08:57 AM

    Originally posted by: GGR


    Hi Stevin

    Do not forget OPL is a constraint programming language, OPL does not allow to write such an expression because of the tableau of variable declaration dependency. As a small example, let  B being an array of variable

    dvar B[i in 1..3] B[i] = 3*B[i-1];
    

    is not allowed as B[i-1] may not be defined. You have to declare the condition between B[i] and B[i-1] in the constraint part of the model. That is:

    forall(i in 2..3)
      B[i] == 2*B[i-1];
    

    Hope that helps

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Circular dependency problem 2

    Posted Wed June 03, 2015 05:37 PM

    Originally posted by: StevinYao


    Hi GGR, 

    Thanks for your reply. I understand that opl can put a lot limitations on the declaration of variables as well as the constraints. 

    What I want to know here is whether there is a way to express the constraint I listed in the formula. 

    To be clear, the vector CD[t], D[t-1] are apportion plans, i.e., the summation of all the elements of CD[t], D[t-1] equals to 1. 

    Do you have any idea?

     

    Stevin


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Circular dependency problem 2

    Posted Thu June 04, 2015 09:32 AM

    Originally posted by: GGR


    Hi Stevin

    May Be I did not understand the problem.

     

    My point is you cannot define an expression element of an array of OPL in reference to this array. Second I f understand what you ask for you have the sum operator in OPL. That is:

    dvar B[1..3];
    /*...*/
    subject to {
        /*...*/
        sum (i in 1..3) B[i] == 1;
    }
    

    Is that answer you issue?

     

    Cheer

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Circular dependency problem 2

    Posted Thu June 04, 2015 11:15 AM

    Originally posted by: StevinYao


    Hi GGR, 

    Thanks for your reply. And sorry for the vagueness in my explanation.

    What I mean is I want to express a relationship between B[t], D[t] and B[t-1], D[t-1], no matter it is expressed as decision expressions(dexpr) or decision variables. I know that the expression can not be expressed in OPL directly. So a fake decision variable is introduced to help express the relationship by setting up appropriate constraints. So I am trying to attune this technique a little so that the complex relationship can be expressed.

    What I am seeking is a way to express the relationship  B[t], D[t] and B[t-1], D[t-1].  It is much like the following code:

    // using CPLEX;
    dvar float B[Time];//Time is a range, indexed from 1..Timehorizon
    dvar float D[1..bins][Time]; //bins is the number of bins to represent the apportion.
    
    subject to 
    {
        apportion_total_constraint:
        forall(t in Time){
            sum(b in 1..bins) D[b][t] ==1;
        }
        
        
        //Relationship:
        forall(t in 2..Timehorizon){
             //constraint(s) to express the relationship
        } 
    }
    

    I hope this will help you understand what I am trying to do.

     

     

    All the best,

    Stevin


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: Circular dependency problem 2

    Posted Fri June 05, 2015 05:14 AM

    Hi,

    let me suggest a workaround you could use.

    The idea is to generate some part of the model.

    For example:

    using CP;

    int n=3;
    range r=1..n;
    float y[0..n];

    execute
    {
    y[0]=1;
    for(var i in r) y[i]=y[i-1]*1.5;
    writeln(y[3]);
    }

     


    dvar int x;
    dexpr float z0=x;

    include "sub.mod";

     

    maximize z[3];
    subject to
    {
    x==1;

    }

    execute
    {
    writeln(z[3]);
    }

    and with a writeln into a file you would generate sub.mod according to n.

    For example, for n=3:

    dexpr float z1=z0*1.5;
    dexpr float z2=z1*1.5;
    dexpr float z3=z2*1.5;

    dexpr float z[i in 0..3]=(z0)*(i==0)+(z1)*(i==1)+(z2)*(i==2)+(z3)*(i==3);

    The descriptive syntax of OPL is simple enough to generate this code in a script

    Regards

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 8.  Re: Circular dependency problem 2

    Posted Fri June 05, 2015 03:47 PM

    Originally posted by: StevinYao


    Hi Alex,

    Thanks for your reply. I get what you want to express, but I still have problems. Can you help me to explain the following questions?

    1. What is the code in the "sub.mod"?

    2. In the code you provided, I can't see the relationship between the imported file "sub.mod" and the main file we are using. Does the included\

        file only introduce the variables defined in the "sub.mod" file? 

    3. Only variables are allowed in the script,  while the decision variables are banded, Is this right? If it is in this case, how can I use the script to

         define the decision variable/ expr/ constraint?

     

    Regards

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 9.  Re: Circular dependency problem 2

    Posted Mon June 08, 2015 09:20 AM

    Hi,

    1) sub.mod is generated according to the value of n

    For example for n=3

    dexpr float z1=z0*1.5;
    dexpr float z2=z1*1.5;
    dexpr float z3=z2*1.5;

    dexpr float z[i in 0..3]=(z0)*(i==0)+(z1)*(i==1)+(z2)*(i==2)+(z3)*(i==3);

    whereas for n=2

    dexpr float z1=z0*1.5;
    dexpr float z2=z1*1.5;

    dexpr float z[i in 0..2]=(z0)*(i==0)+(z1)*(i==1)+(z2)*(i==2);

    2) include includes the file as if this file was there in the mod file

    3) I used scripting only to show that you get the same result.

    You may remove

    float y[0..n];

    execute
    {
    y[0]=1;
    for(var i in r) y[i]=y[i-1]*1.5;
    writeln(y[3]);
    }

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer