1

I am defining a constraint in a class and later I am calling that class. Now I want to define range for the constraint created. How to set upper bound for the constraint. Relevant part of the code only I have given below.

import ilog.concert.IloConstraint;
import ilog.concert.IloException;
import ilog.concert.IloIntVar;
import ilog.concert.IloLinearNumExpr;
import ilog.concert.IloNumVar;
import ilog.cplex.IloCplex;

import java.util.List;

public class ***** {

    public void model(IloCplex cplex, IloIntVar[] cccDecisionVariable, *****, int *****, List<*****> *****) throws IloException {
        IloLinearNumExpr constraintExpression = cplex.linearNumExpr();   
        constraintExpression.addTerm(cccc.getBbbb(),cccDecisionVariable[ccc.getCccId()];          

        IloConstraint constraint = cplex.addGe(constraintExpression,cccc.getAvailable());
        constraint.setName("gggg");             
    }

}
Matthias J. Sax
  • 59,682
  • 7
  • 117
  • 137
wales
  • 49
  • 5
  • What do you mean by an upper bound for the constraint? Do you mean adding another constraint to your model to provide an upper bound for the constraintExpression? If so, why not just add another constraint using cplex.addLe() or similar? – TimChippingtonDerrick Oct 29 '15 at 14:30
  • i was expecting to make a constraint like LB<=AX<=UB. Defining another constraint with Less than will also work. Thanks Tim – wales Oct 30 '15 at 05:29
  • LB<=AX<=UB is two separate constraints. You can write it down as one expression on paper, but in mathematical programming you must express it as two separate constraints. – Ozzah Dec 14 '15 at 04:35

1 Answers1

1

You might want to use IloRange instead of IloConstraint

IloRange constraint = cplex.addGe(constraintExpression,cccc.getAvailable());
constraint.setUB(12.5);
Hernan
  • 39
  • 3