Topic
  • 2 replies
  • Latest Post - ‏2013-06-25T14:37:11Z by AlexFleischer
StephenHall
StephenHall
25 Posts

Pinned topic problem with piecewise using condition on the tuple

‏2013-06-22T11:12:18Z |

Hi,

 

I noticed a wired behavior that I can't explain with piecewise when I apply a condition on the tuple.

In the code below I gave 2 ways of computing vS:

  1. I have a tuple CostProfile with all my data. I filter the set passed to piecewise directly in piecewise. The result is the same for all the scenarios.... and it is equal to the result of scenario 1
  2. I store in an array the prefilter tuple to feed them to pieceswise with costProfileTest. This solution works just fine.

// code 1:  this does not work as it goive the same value for all scenario  
float vSbad[c in Contracts][t in period][s in scenario] = omega * piecewise(bp in CostProfiles
            : bp.contractId==c.contractId && bp.periodIndex == t && bp.scenario==s)
                      {bp.price -> bp.power; lastPrice[c][t][s]} vB[c][t];
 
 
 // code 2: this works and give different value for all scenario                         
{costProfile} costProfileTest[c in Contracts][t in period][s in scenario]= {bp| bp in CostProfiles: bp.contractId==c.contractId && bp.periodIndex == t && bp.scenario==s};
 
 float vSgood[c in Contracts][t in period][s in scenario] = omega * piecewise(bp in costProfileTest[c][t][s])
                          {bp.price -> bp.power; lastPrice[c][t][s]} vB[c][t];

my question is : Am I doing something wrong or does piecewise doesn't fully support the condition on tuples?

 

thank you for your comments

  • StephenHall
    StephenHall
    25 Posts

    Re: problem with piecewise using condition on the tuple

    ‏2013-06-24T11:52:15Z  

    I post my model here for someone to try:

    the lines in question are between: 91 and 101

    you have the script to  display in the console the result at the end of the model

     

    Attachments

  • AlexFleischer
    AlexFleischer
    1864 Posts

    Re: problem with piecewise using condition on the tuple

    ‏2013-06-25T14:37:11Z  

    I post my model here for someone to try:

    the lines in question are between: 91 and 101

    you have the script to  display in the console the result at the end of the model

     

    Hi,

    I can suggest a workaround:

    if you write

     

    float vSbad2[c in Contracts][t in period][s in scenario] = piecewise(bp in CostProfiles
                : bp.contractId==c.contractId && bp.periodIndex == t && bp.scenario==s)
                          {bp.price -> bp.power; lastPrice[c][t][s]} vB[c][t];                      
                                             
    float vSbad3 [c in Contracts][t in period][s in scenario] = vSbad2[c][t][s]*omega;

     

    then you will have vSbad3==vSgood

     

    regards

     

    Alex