Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Modify Objective function

    Posted 06/28/18 04:03 AM

    Originally posted by: Redhat11


    Hi,

    I am trying to change the objective function on several runs of solving the model

    I have this in my mainfunction but it does not modify the variable "testweight" in the objective function.

                    var model = thisOplModel;
                    var data = new IloOplDataSource("data.dat");
                    
                    //model.generate();
                    var elements = model.dataElements;
                    writeln(elements.testweight);
                    elements.testweight = 5000;
                    writeln(elements.testweight);
                    model.addDataSource(elements);
                    model.generate();
    

     

    this is how the objective function looks like

    minimize
            sum(d in day, p in product, s in source) (c[d][s] * x[d][s][p]) + testweight * sum (d in day, s in source) (y[d][s]);
    

     

    When printing out the variable in logs it shows that the variables value has changed, however, when solving the model it still uses the old value. Anyone knows how to solve my problem?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Modify Objective function



  • 3.  Re: Modify Objective function

    Posted 06/28/18 05:38 AM

    I think you can only modify array elements. Can you try changing 'testweight' to a one-element array and then set/modify/use the first element in that array?

    I have this mod

    int weightM[0..0] = [10];
    int weightD[0..0] = ...;
    int weightI = ...;
    dvar boolean x;
    dvar boolean y;
    dvar boolean z;
    maximize weightM[0] * x + weightD[0] * y + weightI * z;
    subject to {}

    main {
      var model = thisOplModel;
      var data = new IloOplDataSource("data.dat");
      model.addDataSource(data);
      var elems = model.dataElements;
      thisOplModel.weightM[0] = 20;
      elems.weightD[0] = 30;
      elems.weightI = 40;
      model.generate();
      cplex.solve();
      writeln("Objective: " + cplex.getObjValue());
    }

    and this dat

    weightD = [ 5 ];
    weightI = 7;

    Running that prints

    Objective: 57

    So modifications to arrays are fine, while modifications of flat values are (silently) ignored. I think this is even documented somwhere.


    #CPLEXOptimizers
    #DecisionOptimization