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 02/05/14 10:50 PM

    Originally posted by: kendong


    hi,


    I am trying to run the following code but I get the error "inboundtrain","outboundtrian" which are element immutable. the set cannot be iterated in more than 2 loops??

    thanks.


    int PlanMonth = ...;
    int PlanDay = ...;

    //Inbound Trians Information
    tuple nInboundTrians
    {
      string TrianID;
      float ArrivalMonth;
      float ArrivalDay;
      float ArrivalHour;
      float ArrivalMinute;
      float InspectionTime;
      float RailcarNum;
      float HumpTime;
      float ArrivalTime;
    }
    {nInboundTrians} inboundtrain = ...;

    //Blocks Information
    tuple nBlocks
    {
      string BlockID;
      string InboundTrainID;
      int RailcarNum;
      string OutboundTrainID;
      float DwellTime;
      float ArrivalTime;
    }
    {nBlocks} block = ...;

    //Outbound Trians Information
    tuple nOutboundTrians
    {
      string TrianID;
      float DepartureMonth;
      float DepartureDay;
      float DepartureHour;
      float DepartureMinute;
      float InspectionTime;
      float AssembleTime;
      float DepartureTime;
      string BlockID1;
      string BlockID2;
      string BlockID3;
      string BlockID4;
      string BlockID5;
      string BlockID6;
    }
    {nOutboundTrians} outboundtrain = ...;

    execute INITIALIZE {
       
      //Calculate the arrival time and deparutre time
      for(i in inboundtrain)
       i.ArrivalTime = ((i.ArrivalMonth - PlanMonth) * 30 + (i.ArrivalDay - PlanDay)) * 1440
            + i.ArrivalHour * 60 + i.ArrivalMinute;
             
      for(j in outboundtrain)
       j.DepartureTime = ((j.DepartureMonth - PlanMonth) * 30 + (j.DepartureDay - PlanDay)) * 1440
            + j.DepartureHour * 60 + j.DepartureMinute;
       
         
      //set arrival time of each block
      for(u in block)
       for(i in inboundtrain)
        if(u.InboundTrainID == i.TrianID)
         u.ArrivalTime = i.ArrivalTime;
      }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


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

    Posted 02/06/14 02:39 AM

    Hi

    you get an error because you try to modify i in

    for(i in inboundtrain)
       i.ArrivalTime = ((i.ArrivalMonth - PlanMonth) * 30 + (i.ArrivalDay - PlanDay)) * 1440
            + i.ArrivalHour * 60 + i.ArrivalMinute;

    and i as the index is immutable.

    What you could write instead:

    for(var k=0;k<=inboundtrain.size;k++)

    Opl.item(inboundtrain,k).ArrivalTime= ((Opl.item(inboundtrain,k).ArrivalMonth - PlanMonth) * 30 + (Opl.item(inboundtrain,k).ArrivalDay - PlanDay)) * 1440
            + Opl.item(inboundtrain,k).ArrivalHour * 60 + Opl.item(inboundtrain,k).ArrivalMinute;

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


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

    Posted 02/06/14 09:24 AM

    Originally posted by: kendong


    It works, thank you so much!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer