Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

element is immutable because it is referenced by another element

  • 1.  element is immutable because it is referenced by another element

    Posted 01/20/11 06:34 AM

    Originally posted by: Cplex81


    hi,

    I am trying to run the following code but I get the error "generate 215" which is element immutable. it has sth to do with the STA paramter. although it is only called in the function findmin but I don't know why I still the get this error.
    "The collection "STA" is immutable because it is referenced by another element.

    
    tuple Station 
    { 
    
    int index; 
    
    int datarate; 
    
    float linkrate; 
    
    float norm_rate; 
    
    int isAssigned; 
    }; tuple Channel 
    { 
    
    int StaNb; 
    
    float StaLoad; Station staInfo; 
    }; 
    {Station
    } station = ...; Channel K[1..3];   
    
    float tempMin=2; Station tempSta; 
    //{Station} STA = station; execute 
    { function findmin(whatever) 
    { var tempMin=2; var result; 
    
    for (var i in whatever)
    { 
    
    if (i.norm_rate < tempMin )
    { i.isAssigned =1; tempMin =i.norm_rate; result= i; 
    } 
    } 
    
    return result; 
    } 
    }   
    {Station
    } STA = station; main 
    { var station = thisOplModel.STA; var tempSta = thisOplModel.tempSta; 
    //var STA = thisOplModel.STA; var i =0 ; var tempMin =  2; 
    
    while ( i<15)
    {   tempSta = findmin(station); writeln(
    "rate=",tempSta.norm_rate); 
    
    for ( var r in station) 
    { 
    
    if ( r.isAssigned == tempSta.isAssigned)
    { r.isAssigned=1; 
    } 
    } i++; 
    }     
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: element is immutable because it is referenced by another element

    Posted 01/24/11 08:10 AM
    Hi,

    i.isAssigned =1;
    


    and

    r.isAssigned=1;
    


    are in 2 for loops where you try to modify the set on which you iterate, which is forbidden and that is why you get an error.
    Those changes should be done outside of the loop.

    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer