Decision Optimization

 View Only
  • 1.  change data by flow controlHi

    Posted Sat August 08, 2020 07:45 AM
    Hi,

    I wanna to generate release time randomly and make the trains' departure time equals to it. I write it as follows and I got something wrong with assignment statement.

    execute {
    cplex.tilim = 120;
    for (var k in orders)
      { writeln("\n origin release time is"+k.release_time);   
          k.release_time = Opl.rand(7);    // This is wrong.
         }    
    }

    my data file is :
                                                         // volume due_time release_time
    orders = {<1, {"Beijing"},{"Hamburg"},   24,       26,               0>,
                   <2, {"Yinchuan"},{"Hamburg"}, 26,     20,               0>,
                   <3, {"Shanghai"},{"Hamburg"}, 18,     28,               0> };

    Is it because I already define the value of release time in data file?  How can I change it ?  I need to change the release time of every order in each iteration.

    ------------------------------
    Dario Pisinger
    ------------------------------

    #DecisionOptimization


  • 2.  RE: change data by flow controlHi

    Posted Sun August 09, 2020 11:30 AM
    Hi

    see

    https://github.com/AlexFleischerParis/opltipsandtricks/blob/master/changetuplesetinaloop.mod


    In

    https://www.linkedin.com/pulse/tips-tricks-opl-cplex-alex-fleischer


    regards



    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 3.  RE: change data by flow controlHi

    Posted Thu August 13, 2020 12:55 PM
    Hi Alex,

    Sorry for my misunderstanding. I need to run my model multiply times and change some data in each running, so is it more suitable to use main block? Also thanks for your reply.

    I read some code you sharing online and I still have a question how to avoid original data covered by new data? I mean I want to keep original data and generate new data based by adding original data and random number.

    for example:
    tuple Service {
    int a;
    float dept_time;}

    {Service} services = ...;

    origin data: dept_time for each service is 1 2 3 4 5;   
    first running:               random number is 1 1 2 3 1;     so the dept_time is 1+1; 2+1; 3+2; 4+3; 5+1
    second running:         random number is 2 3 1 2 1;     so the dept_time is 1+2; 2+3; 3+1; 4+2; 5+1
    ...
    we use the original dept_time in each running



    I'd like to share my code.

    main {
    thisOplModel.generate();
    var m = thisOplModel;
    var cplex = new IloCplex();
    var def = m.modelDefinition;
         for (var time=1; time<=3;time++)
             { var opl2 = new IloOplModel(def,cplex);
               var data2 = m.dataElements; // if I change this sentence to "var data2 = new IloOplDataSource("original_data_file.dat"); ",cplex failed to recongnize services
              for( var e=1; e<=5; e++)
                   { service = Opl.item(data2.services,e-1);
                     service.dept_time += rand();  // chenge the dept_time of each service but original data also changed
                   }
               opl2.addDataSource(data2);
               opl2.generate();  
               cplex.solve();
               ...
               cplex.clearModel();
              }
    }

    ------------------------------
    Dario Pisinger
    ------------------------------



  • 4.  RE: change data by flow controlHi

    Posted Fri August 14, 2020 12:31 AM
    You may want to take a look at the cutstock OPL example that ships with CPLEX. In this example new data is added to the model in each iteration.

    ------------------------------
    Daniel Junglas
    ------------------------------