Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  getting constraint coefficients

    Posted 04/22/08 12:43 PM

    Originally posted by: SystemAdmin


    [gyvahn said:]

    I'm writing a code in c++ to get and change the coefficients from a given problem.

    I've come across IloExpr::LinearIterator and how to use getCoef() in the user manual; except the example doesn't work.

    When I try the example

    IloExpr e = 2*x + 3*y + cos(x);
    IloExpr::LinearIterator it(e);      <
    this line doesn&#039;t work so the code stops here.<br />
    it.ok(); // returns IloTrue 
    it.getCoef(); // returns 2 from the term (2*x)

    Any suggestions?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: getting constraint coefficients

    Posted 04/22/08 09:30 PM

    Originally posted by: SystemAdmin


    [Sylvain said:]

    The expression you define is nonlinear (cos) so you cannot you a linear iterator on it.
    Try without cos(x).
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: getting constraint coefficients

    Posted 04/23/08 02:11 AM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    the IloExpr::LinearIterator should work with all expressions, althought it will only iterate on the linear part.

    In your example, you should use IloCos instead of cos.

    Then the way to get the iterator is using the getLinearIterator method.

    Working code is :


    int issue(IloEnv env) {
    IloCplex cplex(env);

      IloNumVar x(env), y(env);
      IloExpr e = 2*x + 3*y + IloCos(x);
      IloExpr::LinearIterator it = e.getLinearIterator();   

      it.ok(); // returns IloTrue
      cout << it.getCoef() << endl; // returns 2 from the term (2*x)
      cout << it.getVar() << endl;<br />
    cplex.end();
    return 0;
    }
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: getting constraint coefficients

    Posted 04/23/08 04:27 AM

    Originally posted by: SystemAdmin


    [gyvahn said:]

    thank you! but how do I iterate over "it"? I would like to access all the coefficients one by one.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: getting constraint coefficients

    Posted 05/23/08 06:32 PM

    Originally posted by: SystemAdmin


    [oussedik said:]

    Hi,

    To iterate ove it you need to use,

    while (it.ok()) {
    cout << it.getCoef() << endl;<br />....

    Sofiane
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: getting constraint coefficients

    Posted 05/26/08 02:07 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    You also need

    it.next();

    to go to the next one.

    Alain

    #CPLEXOptimizers
    #DecisionOptimization