Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Application pwlFunction / Proper data allocation

  • 1.  Application pwlFunction / Proper data allocation

    Posted Thu September 28, 2017 12:30 PM

    Originally posted by: gustavgans123


    Hi,

    I've got the following problem / lack of understanding..:

     

    I have a set of Nodes (NW)  and I have certain wind speeds at each of those nodes. Through a piecewise linear function, these wind speeds correspond to a certain power output.

    The pwlFunction works fine (tested), but I can't manage to allocate the wind speeds to the nodes correctly.

    The aim is, to calculate the production at each node through the pwlFunction depending on the wind speed (defined in .dat) at that node.

     

    I hope my description is understandable. I tried several things but it never worked out. Attached the code of one try (Problem Section is marked Yellow).

    I also tried something like:

    {int} Windspd [i in NW] = ...;

    and then indexed referring to this set, but got errors like "array size not allowed for generic array"

     

    Any help is appreciated, thanks a lot,

    Gustav


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Application pwlFunction / Proper data allocation

    Posted Thu September 28, 2017 02:07 PM

    Hi,

    could

    https://www.ibm.com/developerworks/community/forums/html/threadTopic?id=dd4fa84b-4bcb-4be4-8887-0b55e8c8f7f2&ps=25

    help ?

    And from this example, you may also derive an array of pwl:

    float firstSlope=0.5;
         float lastSlope=2.0;
         
         tuple breakpoint // y=f(x)
         {
          key float x;
          float y;
         }
         
         sorted { breakpoint } breakpoints={<0,0>,<1,1>,<2,4>};
         
         float slopesBeforeBreakpoint[b in breakpoints]=
         (b.x==first(breakpoints).x)
         ?firstSlope
         :(b.y-prev(breakpoints,b).y)/(b.x-prev(breakpoints,b).x);
         
         pwlFunction f[i in 1..10]=piecewise(b in breakpoints)
         { slopesBeforeBreakpoint[b]->b.x; lastSlope } (first(breakpoints).x, first(breakpoints).y+i);
         
         
         execute
         {
         writeln(f[2](5));     
         }
         
        assert forall(i in 1..10,b in breakpoints) f[i](b.x)==b.y+i;

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Application pwlFunction / Proper data allocation

    Posted Fri September 29, 2017 04:17 AM

    Originally posted by: gustavgans123


    Hi Alex,

    thank you very much for your reply! I already saw that other topic on pwl functions with breakpoints - I think it is not quite what I need atm, as I am fine specifying the pwl with slopes. My standalone pwl is exactly what I want:

    range Wind = 0..30;

    pwlFunction fpow = piecewise{0->3.66; 459.32->12; 0->25;-3830.7288->26;0} (3.66,0);

    float powerc[i in Wind] = fpow(i);

    execute

    {

    for(var i in Wind) writeln(i," ==> ",powerc[i]);

    } ;

     Before using the pwl I had a working code, that calculated the production at one node (NW) based on the wind speed at that node (NW). The respective section of code:

    .mod: //NEW --- cost due to lost production

           float Wndsd[i in NW] = ...; // Wind speed at windpark i

           float elecpr = ...; // electricity price

           float powerc = ...;

           float produc[i in NW] = powerc * Wndsd[i];

           float loPro[i in NW] = produc[i] * elecpr; //lost production per hour in wind park i

           float lostProMa[i in NW][m in M] = loPro[i] * Tmt[m][s];

     

    //penalty for not completed or started tasks

           float Cpen[i in NW][m in M][s in S] = (Ctmt[i][m][s]+loPro[i]) * (Tmt[m][s]+Tshift[s]*2);

    //////////

    .dat

    Wndsd= [8,0]; // Wind speed at Nodes (NW 1..2)

    elecpr= 0.02; //(electricity price)

    powerc= 459.32; // to be replaced by pwl

     

    This first try worked, but I now want to replace "produc" by the above pwl funct. in order to represent the production more accurately.

    I get confused with the arrays / indexes - i need something like:

    i in NW -> Nodes

    Windspeed[i in NW] -> Wind speed at node i in NW

    produc[w in Windspeed] -> pwl(i) supposed to be the production at node i in NW as a pwl function of the windspeed at that node (but not a allowed to index over windspeed[]...)

     

     

    Sorry, I really hope it is understandable. Thanks a lot for any help!!

    Gustav

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Application pwlFunction / Proper data allocation

    Posted Fri September 29, 2017 04:34 AM

    Originally posted by: gustavgans123


    I also tried something like:

    .mod:

    {int} Windspeed[i in NW] = ...;

     

    pwlFunctionfpow = piecewise{0->3.66; 459.32->12; 0->25;-3830.7288->26;0} (3.66,0);

    float produc[i in NW][w in Windspeed[i]] = fpow(i);

     

    .dat:

    Windspeed= [{4},{8}];

    -> gives error:" Die Größe des Variablenindexers ist für einen generischen Array nicht zulässig. " (size of variable index not allowed for generic array)

    or I tried:

    float produc[w in Windspeed] = fpow(i);

    -> gives error: "type {int}[NW] can't be used with "in"

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Application pwlFunction / Proper data allocation

    Posted Fri September 29, 2017 04:44 AM

    Hi,

    .mod

    range NW=1..2;
    range M=1..2;
        range Wind = 0..30;
        
     

        pwlFunction fpow = piecewise{0->3.66; 459.32->12; 0->25;-3830.7288->26;0} (3.66,0);

        float powerc[i in Wind] = fpow(i);

        execute

        {

        for(var i in Wind) writeln(i," ==> ",powerc[i]);

        } ;
     float Wndsd[NW] = ...; // Wind speed at windpark i

           float elecpr = ...; // electricity price

           

           float produc[i in NW] = powerc[i] * Wndsd[i];

          

     

    execute
    {
    writeln(produc);
    }

     

    .dat

    Wndsd= [8,0]; // Wind speed at Nodes (NW 1..2)

    elecpr= 0.02; //(electricity price)

    works fine

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Application pwlFunction / Proper data allocation

    Posted Fri September 29, 2017 04:59 AM

    Originally posted by: gustavgans123


    Thanks a lot once more!

    The code works perfectly, but still does not exactly what I need.

    Output for produc is [0 0] , because it takes "1" and "2" as inputs of the pwl (i in NW).

     

    This is exactly my problem. It is suppose to take Wndsd = [8,0] as inputs of the pwl to express that windspeed at node 1 is 8 and at node 2 its 0. Which should result in a output of produc of  [~1991 0] for node 1 and 2 respectively.

    Do you know what i mean?

    Thank you very much!!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Application pwlFunction / Proper data allocation

    Posted Fri September 29, 2017 05:39 AM

    Ok then why don't you simply write

    float produc[i in NW] = fpow(Wndsd[i]) ;

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Application pwlFunction / Proper data allocation

    Posted Fri September 29, 2017 05:44 AM

    Originally posted by: gustavgans123


    ....sometimes it can be so easy.

    Thanks so much! This is what I needed!

    Spent so much time thinking too complicated and stupid - not getting the idea to simply try what you just wrote.

     

    Thanks for your time and help - saved me again.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer