Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Having problem with dexpr float...

    Posted 10/28/10 04:56 AM

    Originally posted by: Ebisa


    I am a beginner using the OPL using cp optimizer.

    I wanted to have a float decission variable as follows..

    dvar float charge_leveli in time_steps in 0..max_storage;

    But I received error message that says "decision variable of type dvar float not supported by this algorithm ". Then I shifted to dexpr float as follows:

    dexpr float charge_leveli in time_steps = (i == 1)? (initial_charge_level : charge_leveli-1*0.95);

    This one also gave me error saying "circular dependency declaring charge_level".

    How can I use float value for charge_level while keeping the circular dependence?
    If some one can help pls..

    cheers
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Having problem with dexpr float...

    Posted 10/28/10 07:59 AM

    Originally posted by: ChrisBr


    Hi Ebisa,

    What do you want to do exactly?
    Looking at your example, it seems that all the values of the charge_level array are known (as you are able to compute them at initialization time), thus they are "constants" not "decision variables".

    OPL using CP allows only discrete decision variables; float decision variables are allowed in OPL when using CPLEX algorithm.

    Therefore the simplest way to initialize the charge_level constant array is to use the dynamic initialization into a script block:

    
    
    
    float charge_level[time_steps]; execute 
    { 
    
    for (var i in time_steps) 
    { charge_level[i] = ((i==1) ? initial_charge_level : (charge_level[i-1]*0.95)); 
    } 
    }
    


    Or more efficiently:

    
    execute 
    { charge_level[1] = initial_charge_level ; 
    
    for (var i=2; i<= time_steps.UB; i++) 
    { charge_level[i] = charge_level[i-1]*0.95; 
    } 
    }
    


    I hope this helps,

    Chris.
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Having problem with dexpr float...

    Posted 10/28/10 09:02 AM

    Originally posted by: Ebisa


    Many thanks ChrisBr,

    In my problem, I have a local demand and a local supply each with different patterns over a period of time. I also have a storage unit that can buffer between supply and demand. I am trying to schedule the charging and discharging pattern of the storage to minimize some parameters. The storage level is float (continuous) and is also subject to some constraints. Now my problem is with the storage_level decision variable. would you give me some ideas on how to go around this?

    here is the code of what i was trying to do:

    using CP;

    int noOfTimesteps = ...;
    range time_steps = 1 ..noOfTimesteps;
    int time_pts = ...; //time units per unit time step
    int c1 = ...;
    int c2 = ...;
    int c3 = ...;

    float max_storage = ...;
    float min_storage = ...;
    int rate_charging = ...; //constraints on maximum charging rate
    int rate_discharging = ...;
    float initial_charge_level = ...;

    float self_loss_rate = ...;
    float charge_eff = ...;
    float discharge_eff = ...;

    float demandtime_steps = ...;
    float local_supplytime_steps = ...;
    dvar int chargetime_steps in 0..rate_charging; //actual charging rate
    dvar int dischargetime_steps in 0..rate_discharging; //actual discharging rate
    dvar int track_charging i in time_steps in 0..1;
    dvar int track_discharging i in time_steps in 0..1;

    dexpr float net_demandi in time_steps= demand[i] + charge[i]*track_charging[i] - local_supply[i] - discharge[i]*track_discharging[i];
    dexpr float sum_net_demand = sum(i in time_steps) net_demand[i];
    dexpr float average_net_demand = sum_net_demand/noOfTimesteps;
    dexpr float offseti in time_steps= abs(net_demand[i] - average_net_demand);

    dexpr float sum_offset = sum(i in time_steps) offset[i];
    dexpr float average_offset = sum_offset/noOfTimesteps;
    dexpr float peak_offset = max (i in time_steps) offset[i];

    dexpr float charge_leveli in time_steps in 0..max_storage;
    execute {
    cp.param.FailLimit = 10000;
    }

    //objective
    minimize c1*peak_offset; /*+ c2*average_offset + c3*average_net_demand;*/

    //constraints
    constraints
    {

    charge_level[1] == initial_charge_level;
    forall(i in 2..noOfTimesteps)
    {
    charge_level[i] == charge_leveli-1 - self_loss_rate*time_pts + track_chargingi-1*chargei-1 *charge_eff*time_pts - ((track_dischargingi-1*dischargei-1) /discharge_eff )*time_pts;
    }

    forall(i in time_steps)
    {
    charge_level[i] <= max_storage;
    charge_level[i] >= min_storage;
    charge[i] <= rate_charging;
    discharge[i] <= rate_discharging;
    track_charging[i]*track_discharging[i] == 0;

    }
    charge_levelnoOfTimesteps- self_loss_rate*time_pts - track_dischargingnoOfTimesteps*dischargenoOfTimesteps*time_pts/discharge_eff >= min_storage;

    }
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Having problem with dexpr float...

    Posted 10/28/10 09:56 AM

    Originally posted by: SystemAdmin


    Hello Ebisa.

    As Chris pointed out, CP Optimizer does not support float decision variables, only float expressions. However OPL language does not support recurrent expressions. This is limitation of OPL, using C++/Java/.NET interface it is possible to create such expressions. However I don't recommend this neither because the resulting expressions will be very big.

    The best solution, by my opinion, is to use integers instead of floats (if it is possible). The idea is that you decide what precession do you need - for example 0.01. Then you multiply every float variable by 100 and make it an integer variable. Of course, rounding error may accumulate, so you may also multiply by 10 000 instead of 100. Just be careful in order not to get values bigger than 2^31 (in case of 32bit architecture). This way you can convert all float constants, float variables and float expressions to integers.

    Final remark. For posting code on the forum, please use { code } (without spaces) tags around your code. It prevents square brackets to be interpreted as links. When you post your message, there is a box with markups explanation on the right from the input box. It is easy to overlook.

    I hope it helps, Petr
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Having problem with dexpr float...

    Posted 10/28/10 11:19 AM

    Originally posted by: Ebisa


    Thanks Petr Vilim,

    that was helpful.
    #DecisionOptimization
    #OPLusingCPOptimizer