Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to update tuple field value in the main script?

    Posted 12/08/11 03:14 PM

    Originally posted by: SystemAdmin


    When I try to update a tuple set field value in the main script, I receive the following error message:

    The collection "relPowerhouses" is immutable because it is referenced by another element.
    I declare the tuple and the setof tuple on the model:

    tuple rvPowerhouse {
    key int powerhouse;
    float minPower;
    }
    {rvPowerhouse } relPowerhouses = ...;
    In the main script, I try to update de value of the field minpower of
    for(var pwh in thisOplModel.relPowerhouses )
    {
    pwh.minPower=pwh.minPower*1.01;
    }
    How can I update a tuple field of a tuple set without having this error message?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to update tuple field value in the main script?

    Posted 12/08/11 09:14 PM

    Originally posted by: SystemAdmin


    > for(var pwh in thisOplModel.relPowerhouses )
    > {
    > pwh.minPower=pwh.minPower*1.01;
    > }
    > The collection "relPowerhouses" is immutable because it is referenced
    > by another element.

    What you see is part of the expected behavior. In your loop you are iterating over the elements of relPowerhouses, and thus this object is locked and immutable within the loop, leading to the error when you try to individually change the field value of each element.

    You could instead use the following to achieve your objective:
    for(var index=0;index<thisOplModel.relPowerhouses.size;index++){
            var pwh = Opl.item(thisOplModel.relPowerhouses,index);
            pwh.minPower = pwh.minPower*1.01;
        }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to update tuple field value in the main script?

    Posted 12/10/11 11:14 AM

    Originally posted by: SystemAdmin


    Thank you, I now understand why I have this behavior.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer