Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Solve model multiple times with different inputs

    Posted 08/04/16 03:04 PM

    Originally posted by: deadlock_


    What I'm trying to do is to solve a model once with a given input, and then a second time with another input. The two resulting objective values should be printed on the console. Here's what I have tried so far:

     

    dvar int x;

    int y[1..1];

    minimize x;
    subject to {
      x >= y[1];
    }

    main
    {

      thisOplModel.y[1] = 10;  
      thisOplModel.generate();
      cplex.solve();
      writeln(cplex.getObjValue());
      cplex.clearModel();
     
      var newModel = new IloOplModel(thisOplModel.modelDefinition, cplex);
      var newData = thisOplModel.dataElements;
      newData.y[1] = 11;
      newModel.addDataSource(newData);
      newModel.generate();
     
      cplex.solve();
      writeln(cplex.getObjValue());
    }

     

    However, I currently get the following error:

    Scripting runtime error: Data element "y" does not exist.

    The error seems to occur in the following line:

    newData.y[1] = 11;

    So it seems that addDataSource() does not work as intended.

    Any help is appreciated.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Solve model multiple times with different inputs

    Posted 08/06/16 10:21 AM

    Originally posted by: deadlock_


    I was able to solve it myself, more or less, by loading the data from a data file instead of hardcoding it into the module. This article:

    https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.1/ilog.odms.ide.help/refjsopl/html/IloOplDataElements.html

    contains a working example that does everything I wanted to do, with one exception: I wanted to change an array, but the article changes a scalar value.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Solve model multiple times with different inputs



  • 4.  Re: Solve model multiple times with different inputs

    Posted 08/22/16 08:31 AM

    Originally posted by: deadlock_


    Weird, I wasn't able to solve my problem with an array instead of a scalar when I tried it about two weeks ago, but now it works.

    Anyway, some of the things I did change was that, unlike in the code shown at the first post, I loaded the data from a separate data file and I replaced

    int y[1..1];

    by

    int y[1..1] = …

    I'm setting this topic to solved.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer