Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  generate a random array of string

    Posted 02/08/16 04:48 PM

    Originally posted by: Rym


    Hello

     

    i'm beginner in IBM OPl, i like t o generate randomly  in .mod file an array of strings in <s,m,l,xl>.

     

    I want to have 

     

    int n;

    range r= 1..n;

    int vm[r];

    execute

    {

    for ( var i in vm)

    {

    vm[i]= ....   ;  .//generate an array with randomly strings with vm[i] in s,m,l,xl

    }

    };

    Example of output:

    if i write writeln("vmi=",vmi) i will have : vmi=[s,m,xl,s,l,s,m ]

    thanks

     

     

     

     

     

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: generate a random array of string

    Posted 02/09/16 03:09 AM

    Hi,

    we can start from the example I gave you at

    https://www.ibm.com/developerworks/community/forums/html/topic?id=e0a84b10-59a1-4689-92df-5ad62ce1194d&ps=25

    and write

    int vm = 20;

        range Rvm = 1..vm;

         

        int DKmin=1;

        int DKmax = 4;

        int disk[i in Rvm]=DKmin+rand(DKmax-DKmin+1);

        string s[DKmin..DKmax]=["s","m","l","xl" ];
        
        string vmi[i in Rvm]=s[disk[i]];
        
        execute
        {
        writeln(vmi);    
        }
        
     

    which gives

     

     ["s" "s" "s" "s" "m" "xl" "l" "xl" "l" "s" "xl" "s" "xl" "s" "s" "l" "m" "l" "s" "xl"]

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: generate a random array of string

    Posted 02/09/16 07:41 AM

    Originally posted by: Rym


    Thanks Alex 

     

    It's working . I'm in love with IBM OPL 

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: generate a random array of string

    Posted 02/09/16 07:46 AM


  • 5.  Re: generate a random array of string

    Posted 03/08/16 07:46 AM

    See

    Optimization (aka prescriptive analytics) : Should we write the model in a modeling language or a general programming language ?

    https://www.linkedin.com/pulse/optimization-aka-prescriptive-analytics-should-we-write-fleischer?trk=hp-feed-article-title-publish

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: generate a random array of string

    Posted 03/17/16 06:45 AM

    Originally posted by: Rym


    Hi

     

    I have a a problem when a repeat the statement in loop for: it make me the same result for every step of the loop for .And my pupose is to change the result in every step of the loop for.

     

    My model :

     

    int cpui[s in V]=1rand(4-1+1);
     

    execute

    {
    writeln(cpui);
    }

    main

     

    {

     

    for(var j=1;j<nv;j=j+(min+(Opl.rand(mix))))
    {

    var masterOpl = new IloOplModel(masterDef, masterCplex);
       var masterData = thisOplModel.dataElements; 
       masterData.v=j;
       masterOpl.addDataSource(masterData);
       writeln("solving with ",j,"  vms");

    for (var i=1; i<=NbI;i++)
    {  

     

    masterOpl.generate();

     

    *****

    }

    }

    }

     

    the result is

     

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

     

    My problem is to change the different values by row

     

    example

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

    [2 2 2 1 2 6 3 6 1 8 1 1 4 2 2 1 4 8 2 2 1 4 8 8]

    [ 1 4 2 2 1 4 1 2 6 3 1 4 8  8 2  2  6 3 6 1 8 1 1 ]

    *

    *

    thanks

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: generate a random array of string



  • 8.  Re: generate a random array of string

    Posted 03/20/16 03:19 PM

    Originally posted by: Rym


    Thanks Alex

     

    But my problem  isn't sloving. The generated sequence is the same at each itteration and i would have( different )distinct sequence at each one.

     

    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

    [2 2 2 1 2 6 3 6 1 8 1 1 4 2 2 1 4 8 2 2 1 4 8 8]

    [ 1 4 2 2 1 4 1 2 6 3 1 4 8  8 2  2  6 3 6 1 8 1 1 ]

    and not

     
    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

     

     
    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

     

     
    [2 2 2 1 4 8 6 7 5 1 8 2 8 1 2 6 3 6 1 8 6 7 6 8]

     

     

    Thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: generate a random array of string



  • 10.  Re: generate a random array of string

    Posted 04/04/16 12:15 PM

    Originally posted by: Rym


    Hi 

     

    It's working but for executing the sentence , i should set  the value of the range a to a static parameter that i think isn't normal think


    int v = ...;
    range V = 1..v;
    int VM[V] = ...;
    int a[1..300];

    main
    {
      var masterDef = thisOplModel.modelDefinition;
      var masterCplex = cplex;
        var masterOpl = new IloOplModel(masterDef, masterCplex); 
      var masterData = thisOplModel.dataElements;
     
     
      for(var h=1;h<=10;h++)
      {

      var masterOpl = new IloOplModel(masterDef, masterCplex); 
      masterData.v=h;
      masterData.VM=thisOplModel.a;
      for(var q=1;q<=h;q++)
    {
      masterData.VM[q]=1+(Opl.rand() % (4 - 1 + 1));
    }  
      masterOpl.addDataSource(masterData);
      masterOpl.generate(); 
       }

    }

     

     

    thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: generate a random array of string