Decision Optimization

 View Only
  • 1.  How to add two IloLinearNumExpr terms in Java

    Posted Tue May 18, 2021 01:36 AM
    Edited by System Test Fri January 20, 2023 04:10 PM
    Hi,

    I would like to progressively build up certain constraints in Java API. I aim to add certain values into IloNumExpr per each origin-destination pair.

    HashMap<OriginDestionation,IloNumExpr> tracker = new HashMap<OriginDestionation,IloNumExpr>();

    Suppose I create

    IloNumExpr expr= ...; 
    OriginDestionation instance= ...; 

    and add to my map as follows 

    tracker.put(instance, expr);

    Now, I would like to add another IloNumExpr term by using the "instance" key in another part of my code. I have tried to do the following but received an error. 

    IloNumExpr tempExpr = tracker.get(instance);
    tempExpr.addTerm(x, y); //x and y are double and IloIntVar, respectively. 
    tracker.put(instance, tempExpr);


    Error message is "The method addTerm(double, IloIntVar) is undefined for the type IloNumExpr"
    ------------------------------
    Ser Giovio
    ------------------------------
    #DecisionOptimization


  • 2.  RE: How to add two IloLinearNumExpr terms in Java

    Posted Tue May 18, 2021 03:37 AM
    I guess you should create and store IloLinearNumExpr objects which are created from cplex.linearNumExpr() ?

    ------------------------------
    Vincent Beraudier
    ------------------------------



  • 3.  RE: How to add two IloLinearNumExpr terms in Java

    Posted Tue May 18, 2021 04:05 AM
    Thanks! I did actually figure it out myself after posting the question, but could not find a way to delete the post. Aren't we allowed to delete our posts which have not been answered? πŸ€”

    ------------------------------
    Ser Giovio
    ------------------------------