Topic
  • 4 replies
  • Latest Post - ‏2016-04-19T15:38:29Z by AlexFleischer
trebron
trebron
10 Posts

Pinned topic Getter/Setter for objective coefficients

‏2014-05-14T08:16:18Z |

Dear all,

 

OPL offers the possibility to set the objective-coeeficients by OPL-Script

 for( i in model.idx){
//     model.getObjective().setCoef(model.x[i],5);
     myCplex.setObjCoef(model.x[i],20);
  }

 

Is there as well a getter-method for the coefficient, like, e.g.

    model.getObjective().getCoef(model.x[i]);
     myCplex.getObjCoef(model.x[i]);

 

Cheers,

   Norbert

  • AlexFleischer
    AlexFleischer
    2572 Posts

    Re: Getter/Setter for objective coefficients

    ‏2014-05-20T09:44:47Z  

    Hi,

    I do not have any nice way in mind but two workaround:

    1)

    Use IloLinearNumExprIterator linearIterator() after an external java call

    2)

    Do a white solve in order to know the coef as in

    dvar float+ Gas;
    dvar float+ Chloride;


    maximize
      40 * Gas + 50 * Chloride;
    subject to {
      ctMaxTotal:     
        Gas + Chloride <= 50;
      ctMaxTotal2:    
        3 * Gas + 4 * Chloride <= 180;
      ctMaxChloride:  
        Chloride <= 40;
    }

    main
    {
     thisOplModel.Gas.UB=1;
     thisOplModel.Chloride.UB=0;
     thisOplModel.Gas.LB=1;
     thisOplModel.Chloride.LB=0;
     thisOplModel.generate();
     cplex.solve();
     writeln(cplex.getObjValue());
     
    }  
     

    which gives 40

     

    regards

  • trebron
    trebron
    10 Posts

    Re: Getter/Setter for objective coefficients

    ‏2014-05-20T09:56:14Z  

    Hi,

    I do not have any nice way in mind but two workaround:

    1)

    Use IloLinearNumExprIterator linearIterator() after an external java call

    2)

    Do a white solve in order to know the coef as in

    dvar float+ Gas;
    dvar float+ Chloride;


    maximize
      40 * Gas + 50 * Chloride;
    subject to {
      ctMaxTotal:     
        Gas + Chloride <= 50;
      ctMaxTotal2:    
        3 * Gas + 4 * Chloride <= 180;
      ctMaxChloride:  
        Chloride <= 40;
    }

    main
    {
     thisOplModel.Gas.UB=1;
     thisOplModel.Chloride.UB=0;
     thisOplModel.Gas.LB=1;
     thisOplModel.Chloride.LB=0;
     thisOplModel.generate();
     cplex.solve();
     writeln(cplex.getObjValue());
     
    }  
     

    which gives 40

     

    regards

    Dear Alex,

    many thanks for your reply.

    To me it is surprising that there are setter-Methodsbut no getter-Methods. Changing the coeff can do more harm than just having a look at it ...  Can you put it on the "wish-list"?

    Concerning your workarounds:

    (1)  Seems to fail as well, as the hasNext() method always returns null in that setting, i.e. you can not iterate over the variables.

    (2) Seems to me like 'overkill' in order to obtain the objective coeeficients. That works well for your small example. For more compex problems it is out of scope to wait several hours for the problem to be solved in order to access the objective coefficients.

     

    Best regards

        Norbert

  • AlexFleischer
    AlexFleischer
    2572 Posts

    Re: Getter/Setter for objective coefficients

    ‏2014-05-20T11:31:13Z  
    • trebron
    • ‏2014-05-20T09:56:14Z

    Dear Alex,

    many thanks for your reply.

    To me it is surprising that there are setter-Methodsbut no getter-Methods. Changing the coeff can do more harm than just having a look at it ...  Can you put it on the "wish-list"?

    Concerning your workarounds:

    (1)  Seems to fail as well, as the hasNext() method always returns null in that setting, i.e. you can not iterate over the variables.

    (2) Seems to me like 'overkill' in order to obtain the objective coeeficients. That works well for your small example. For more compex problems it is out of scope to wait several hours for the problem to be solved in order to access the objective coefficients.

     

    Best regards

        Norbert

    Hi,

    do not hesitate to log a wish at

    http://www.ibm.com/developerworks/rfe/execute?use_case=changeRequestLanding

    regards

  • AlexFleischer
    AlexFleischer
    2572 Posts

    Re: Getter/Setter for objective coefficients

    ‏2016-04-19T15:38:29Z  

    Now, the wish is logged at

    https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=53791

    anyone can vote ...

    And now we have

    getObjCoef
    {number} getObjCoef(dvar)
    Returns the coefficient of a decision variable in the objective expression

    and

    getCoef
    {number} getCoef(ct, dvar)
    returns the coefficient of the variable in the constraint; returns 0 if not mentioned

    regards

    Updated on 2016-04-20T10:49:50Z at 2016-04-20T10:49:50Z by AlexFleischer