Decision Optimization

Decision Optimization

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


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

experiment series

  • 1.  experiment series

    Posted 06/13/18 08:26 AM

    Originally posted by: Janisch


    Hi guys,

    I would like to do an experiment series. That is, before each pass, a particular parameter should change automatically. Example: One should calculate with x = 5, next with x = 4, etc.

    The whole experiment series should make all desired changes of the parameters in a "big" run and save all results in an Excel file.

    Can my project be realized with the help of OPL Studio?

    Regards 😊


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: experiment series

    Posted 06/13/18 09:15 AM

    Yes, I think you can do this using OPLScript. In a loop you have to update the data, regenerate the model, solve it and then export the results to Excel. The last step may be easiest to do with a SheetWrite statement in the .dat file.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: experiment series

    Posted 06/14/18 03:39 AM

    Hi

    in

    https://www.linkedin.com/pulse/how-opl-alex-fleischer/

    you may have a look at

    Change some data and solve again without regenerate
    Change some data and solve again with regenerate

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: experiment series

    Posted 06/14/18 08:48 AM

    Originally posted by: Janisch


    Thank you for your answers :)

    - Which instruction should I use if I want to have summed the target function value of all runs?

    - My model works with an Excel sheet. From this file a few data are exported. Now every time the error appears, that I have not defined my variables although I have defined them in the model file. How can this problem be solved?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: experiment series

    Posted 06/17/18 06:10 AM

    Originally posted by: Janisch


    Here is my mainMod:

     

    {string} Variante={"Verbrenner","Elektro","Gas"};
    int a[Variante];
    main {
    var source = new IloOplModelSource("Reihe Mixed-Model-Sequencing.mod");
    var cplex = new IloCplex();
    var def = new IloOplModelDefinition(source);
             
             
    for(var k=0;k<=4;k++)
    {
    var opl = new IloOplModel(def,cplex);
                
    var data2= new IloOplDataElements();
    data2.d=thisOplModel.a;
    data2.d["Verbrenner"]=4-k;
    data2.d["Elektro"]=k;
    data2.d["Gas"]=0;
    opl.addDataSource(data2);
    opl.generate();

    if (cplex.solve()) {  
    opl.postProcess();
    writeln("Overload = " + cplex.getObjValue());
    } else {
    writeln("No solution");
    }
    opl.end();
    }         
    }


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: experiment series

    Posted 06/17/18 07:59 AM

    Can you please post the full error message?

    Also, I don't see where in your code you provide data for Taktzeit, AnzahlStation, Arbeitsplaetze, l, Ueberlappung. It seems you have to include a .dat file that provides that data?


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: experiment series

    Posted 06/17/18 08:16 AM

    Originally posted by: Janisch


    The data should be imported from an Excel sheet. The excel file I have attached in my penultimate post.

    data-file:

    SheetConnection sheet("Daten.xlsx");

    Taktzeit from SheetRead(sheet,"'Input kleines Modell'!B11");                //cycle time
    AnzahlStation from SheetRead(sheet,"'Input kleines Modell'!B12");            //number of stations
    Fertigungstakt from SheetRead(sheet,"'Input kleines Modell'!B13");            //number of production cycles (=sum of products)
    Arbeitsplaetze from SheetRead(sheet,"'Input kleines Modell'!B18");            //numer of workstations (=always 2)
    d from SheetRead(sheet,"'Input kleines Modell'!B15:D15");                    //quantity of the product (burner, electric, gas) to be supplied
    l from SheetRead(sheet,"'Input kleines Modell'!B16:G16");                    //length of the station in seconds
    Ueberlappung from SheetRead(sheet,"'Input kleines Modell'!B17:G17");        //drift region in seconds

    nb2 from SheetRead(sheet,"'Input kleines Modell'!B26:S27");                 //Hilfsarray um Bearbeitungszeiten importieren zu koennen


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: experiment series

    Posted 06/17/18 09:33 AM

    In order to import data from that Excel file you have to create a regular .dat file with the content of what you just posted (SheetConnection etc.) and also add this .dat file to your model in the scripting block. Like so (see also the reference documentation for IloOplDataSource):

    var xldat = IloOplDataSource("datfile_that_references_excel.dat");
    opl.addDataSource(xldat);

    I am not sure whether the order matters in which you add xldata and data2. Maybe try both if you run into problems.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: experiment series

    Posted 06/18/18 11:40 AM

    Originally posted by: Janisch


    unfortunately, the error continues to appear (element Taktzeit is not defined)... I don´t know what it is.

     

    mainmixed.mod

    {string} Variante={"Verbrenner","Elektro","Gas"};
    int a[Variante];


    main {
    var source = new IloOplModelSource("Reihe_Sequencing.mod");
    var cplex = new IloCplex();
    var def = new IloOplModelDefinition(source);
    var data = IloOplDataSource("Input_data.dat");
    opl.addDataSource(data);         
             
    for(var k=0;k<=4;k++)
    {
    var opl = new IloOplModel(def,cplex);
                
    var data2= new IloOplDataElements();
    data2.d=thisOplModel.a;
    data2.d["Verbrenner"]=4-k;
    data2.d["Elektro"]=k;
    data2.d["Gas"]=0;
    opl.addDataSource(data2);
    opl.generate();

    if (cplex.solve()) {  
    opl.postProcess();
    writeln("Overload = " + cplex.getObjValue());
    } else {
    writeln("No solution");
    }
    opl.end();
    }       
    }

     

    Input_data.dat

    SheetConnection sheet("Daten.xlsx");

    Taktzeit from SheetRead(sheet,"'Input kleines Modell'!B11");                //cycle time
    AnzahlStation from SheetRead(sheet,"'Input kleines Modell'!B12");            //number of stations
    Fertigungstakt from SheetRead(sheet,"'Input kleines Modell'!B13");            //number of production cycles (=sum of products)
    Arbeitsplaetze from SheetRead(sheet,"'Input kleines Modell'!B18");            //numer of workstations (=always 2)
    l from SheetRead(sheet,"'Input kleines Modell'!B16:G16");                    //length of the station in seconds
    Ueberlappung from SheetRead(sheet,"'Input kleines Modell'!B17:G17");        //drift region in seconds

    nb2 from SheetRead(sheet,"'Input kleines Modell'!B26:S27");

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: experiment series

    Posted 06/18/18 01:31 PM

    The problem is that you do 'opl.addDataSource(data)' and then 'var opl = new IloOplModel(...)'. The latter creates a new model object that then knows nothing about the data you added to the previous object. Try calling addDataSource() on the new object (i.e. after calling 'new').


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: experiment series

    Posted 06/18/18 01:45 PM

    Originally posted by: Janisch


    Still the same error...

     

    main.mod

    main {
    var source = new IloOplModelSource("Reihe_Sequencing.mod");
    var cplex = new IloCplex();
    var def = new IloOplModelDefinition(source);
    var data = IloOplDataSource("Input_data.dat");
             
             
    for(var k=0;k<=4;k++)
    {
    var opl = new IloOplModel(def,cplex);
    opl.addDataSource(data);            
    var data2= new IloOplDataElements();
    data2.d=thisOplModel.a;
    data2.d["Verbrenner"]=4-k;
    data2.d["Elektro"]=k;
    data2.d["Gas"]=0;
    opl.addDataSource(data2);
    opl.generate();

    if (cplex.solve()) {  
    opl.postProcess();
    writeln("Overload = " + cplex.getObjValue());
    } else {
    writeln("No solution");
    }
    opl.end();


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: experiment series

    Posted 06/19/18 01:55 AM

    Are you sure it is still the same error? I get error "Fertigungstakt already defined" here. This is because Fertigungstakt is set in the .mod and in the .dat file.


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: experiment series

    Posted 06/19/18 03:12 AM

    Originally posted by: Janisch


    Do I have to delete my variables / parameter definitions from the mod.file?

    I thought it will first call the mod.file and then connect to excel sheet using the dat.file and load the data into the model.

    What does your main.file/mod file/dat file look like?

    Which files should I load in the execution configuration?


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: experiment series

    Posted 06/19/18 04:17 AM

    Here are my files. The "Reihe_Sequencing.mod" should be exactly what you posted before.

    Note that in the .dat file I replaced the references to Excel by the actual data. That should not matter though. If you things work correctly then you can go back to the file that actually references Excel. The only thing that is different to the .dat you posted is that I removed "Fertigungstakt" from the .dat since that is already defined in the .mod as

    int Fertigungstakt=sum(i in Variante)d[i];

    Hence it cannot be re-defined in the .dat file.


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: experiment series

    Posted 06/19/18 10:40 AM

    Originally posted by: Janisch


    Unfortunately, it still does not work for me.

    The Error: "Taktzeit is not defined" still occurs. I have no idea what it is. I did not change anything and I followed the same procedure as you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: experiment series

    Posted 06/20/18 03:26 AM

    Does your Reihe_Sequencing.mod file still contain a line 'int Taktzeit = ...'?

    I suggest to take the reverse approach: Start with an empty .mod and .dat and make sure that works. Then start adding things line by line and after each step check that things still work.


    #CPLEXOptimizers
    #DecisionOptimization


  • 17.  Re: experiment series

    Posted 06/20/18 04:12 AM

    Originally posted by: Janisch


    Could solve the problem!

    The dat.file have not be loaded into the execution configuration. Thank you for your help :)


    #CPLEXOptimizers
    #DecisionOptimization