Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Modifying tuple/array data in IBM ILOG Script

    Posted 02/01/11 09:13 PM

    Originally posted by: amedury


    I am trying to code a program which involves repeatedly solving an optimization problem after modifying some pieces of the data. In particular, I have a multidimensional array (3) of the form:

    int actns<i,j> in linksthttp://t in 1..40http://n in 1..100 = 0;

    As per the help manual, I can modify arrays if they have been externally initialized. However, a 3+ dimensional array cannot be initialized externally.

    I have tried to create a tuple to overcome this limitation in the following manner:
    tuple action {
    key link segment;
    key int t;
    key int n;
    int act;
    };

    {action} actn = ...;

    But when I try to modify the tuple in the scripting in main(), it gives an error that "the collection is immutable because it referenced by another element." I use the following script:

    var actnsm = produce.actns; (actns is the array that initialized internally using multidimensional tuple)
    var actnsi = produce.actn; (actn is the tuple of interest)

    <omitting the rest of the script>

    for(var x in actnsi){
    x.act= actnsmhttp://x.segmenthttp://x.thttp://x.n;
    data.actnshttp://x.segmenthttp://x.thttp://x.n=actnsmhttp://x.segmenthttp://x.thttp://x.n;
    }
    data.actn=actnsi;

    I am also told that the syntax for tuples changes in the scripting process, so I would appreciate if you could help me with this issue. The big picture idea is that I would like to modify the multidimensional array/tuple and resolve the optimization.

    Thanks!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 02/02/11 07:37 AM

    Originally posted by: amedury


    Sorry about the random links (wasn't expecting them to come up). Hopefully this will work out:
    for(var x in actnsi){
    x.act= actnsm"";
    data.actns"="actnsm"";
    }
    data.actn=actnsi;
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 02/04/11 01:47 AM

    Originally posted by: SystemAdmin


    Hi,

    Can you clarify what you mean by a 3D array cannot be initialized externally?
    Here is an example of how a 3D array could be initialized in a .dat file:
    
    actns = [ [[111,112],[121,122],[131,132],[141,142]], [[211,212],[221,222],[231,232],[241,242]], [[311,312],[321,322],[331,332],[341,342]] ];
    

    with the array declared as
    
    tuple Link 
    { 
    
    int i; 
    
    int j; 
    } 
    {Link
    } links = 
    {<1,1>, <1,2>, <1,3>
    }; 
    
    int actns[links][1..4][1..2]=...;
    


    Then in your main script, you can update your array as follows:
    
    main 
    { thisOplModel.generate(); var masterDef = thisOplModel.modelDefinition; var masterCplex = cplex; var dataElts = thisOplModel.dataElements; 
    
    if (cplex.solve()) 
    { writeln(
    "obj1 = ",cplex.getObjValue()); 
    //update array actns 
    
    for (var x in thisOplModel.actnsi) dataElts.actns[x.segment][x.t][x.n]=thisOplModel.actnsm[x.segment][x.t][x.n]+5; var opl2 = 
    
    new IloOplModel(masterDef,masterCplex); opl2.addDataSource(dataElts); opl2.generate(); masterCplex.solve(); writeln(
    "obj2 = ",masterCplex.getObjValue()); 
    } 
    }
    


    If this doesn't answer your question, can you post a reduced sample that illustrates the issue you're facing?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 11/12/13 12:19 PM

    Originally posted by: ikucukkoc


    Dear SystemAdmin

     

    I am using CPLEX and I need to preprocess data before the optimisation.

    In simplified version, I have a tuple "TaskTimes" as below and l need to modify the last column of every row by multiplying with a constant value, say 5.

     

    Sample.mod file

    tuple task { 
      int h; 
      string j; 
      int i; //
      string x; 
      float pt; 
    }

    {task} TaskTimes = ...;

     

    Sample.dat file:

    TaskTimes = {

    <1 A 1 L 3>,
    <1 A 2 R 3>,
    <1 A 3 E 0>,
    <1 A 4 L 2>,
    <1 A 5 E 2>,
    };

     

    Consequently; I should obtain following tuple:

     

    TaskTimes = {

    <1 A 1 L 15>,
    <1 A 2 R 15>,
    <1 A 3 E 0>,
    <1 A 4 L 10>,
    <1 A 5 E 10>,
    };

     

    Your prompt help and support is highly acknowledged.

    Many thanks.

    Best Regards

    Ibrahim


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 04/16/12 10:27 AM

    Originally posted by: SystemAdmin


    Hi,
    I am facing a similar issue.
    I have

    tuple TripleIndex{
    int t;
    int u;
    int g;
    }
    {TripleIndex} Index = {<t,u,g> | t in T, u in U, g in 1..G[t][u]};
    float T Index = ...;

    I need to calculate some data before I process my MILP.
    Here's what I want to do :

    for(var i in thisOplModel.Index){
    for (var a = i.g; a < Ghttp://i.thttp://i.u;a++) {
    Turbinehttp://thisOplModel.TripleIndex(i.t,i.u,a);
    }
    }
    }

    I need to access the tuple indexed T.
    So I have to build the coresponding tuple index.
    How can I "create" a tuple in OPL script ?

    Thanks !
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 04/16/12 10:30 AM

    Originally posted by: SystemAdmin


    for (var a = i.g ; a < G http:// i.t http:// i.u ; a++ ) {
    Turbine http:// thisOplModel . TripleIndex ( i.t , i.u , a ) ;
    }
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 04/16/12 11:35 AM

    Originally posted by: SystemAdmin


    Hi,

    In your code extract, "TripleIndex" is a tuple type definition, not a set so you can't use it to access elements of the sets Index.
    You need to work with the set itself: Index.
    So if "Turbine" is an array indexed by the set "Index", you would access the cell indexed by <i.t,i.u,a> with the following syntax:
    Turbine[Index.find(i.t,i.u,a)] = /*the value you want to set*/;
    


    The method find for tuple set is documented here: IDE and OPL > Optimization Programming Language (OPL) > IBM ILOG Script Reference Manual > OPL Classes > IloTupleSet

    I am unclear what T represents in your code sample but the way you've declared it doesn't work as you are mixing float and tuple set.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 04/17/12 04:10 AM

    Originally posted by: SystemAdmin


    Hi, thanks a lot for your fast answer !
    And yes you're right, it's actually a mistake...

    It is float Turbine = ... ;
    I just wanted to simplify the code, but I've done it too fast...

    Thanks again
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 11/12/13 12:19 PM

    Originally posted by: ikucukkoc


    Dear SystemAdmin

    I am using CPLEX and I need to preprocess data before the optimisation.

    In simplified version, I have a tuple "TaskTimes" as below and l need to modify the last column of every row by multiplying with a constant value, say 5.

    Sample.mod file

    tuple task { 
      int h; 
      string j; 
      int i; //
      string x; 
      float pt; 
    }

    {task} TaskTimes = ...;

     

    Sample.dat file:

    TaskTimes = {

    <1 A 1 L 3>,
    <1 A 2 R 3>,
    <1 A 3 E 0>,
    <1 A 4 L 2>,
    <1 A 5 E 2>,
    };

     

    Consequently; I should obtain following tuple:

     

    TaskTimes = {

    <1 A 1 L 15>,
    <1 A 2 R 15>,
    <1 A 3 E 0>,
    <1 A 4 L 10>,
    <1 A 5 E 10>,
    };

     

    Your prompt help and support is highly acknowledged.

    Many thanks.

    Best Regards

    Ibrahim


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Modifying tuple/array data in IBM ILOG Script

    Posted 11/12/13 02:52 PM

    Hi,

     

    could

    {task} TaskTimes2 = {<e.h,e.j,e.i,e.x,5*e.pt> | e in TaskTimes};
    execute
    {
     
      TaskTimes2;
     
     
    }

     

    help ?

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer