Topic
  • 3 replies
  • Latest Post - ‏2013-02-21T14:42:06Z by SystemAdmin
SystemAdmin
SystemAdmin
7929 Posts

Pinned topic sutracting number from IloNumExpr java cplex

‏2013-02-21T14:01:32Z |
Hello! What I want to do is to subtract an IloNumExpr from a number. I want to put to an expression the following thing:
\{
for i
for j
for k
n-(n-k-1)*y[i][j]
\}
n is an integer and y is a decision variable

Cplex does not let me subtract a number in the addTerm method of the expression.
Updated on 2013-02-21T14:42:06Z at 2013-02-21T14:42:06Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: sutracting number from IloNumExpr java cplex

    ‏2013-02-21T14:16:45Z  
    You need to use the setConstant() member function to change the constant part of an expression.
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: sutracting number from IloNumExpr java cplex

    ‏2013-02-21T14:28:51Z  
    You need to use the setConstant() member function to change the constant part of an expression.
    Thanks, Daniel. But then how will I subtract the expression from this constant part. I will say \{setConstant(n) \} and how will I say the \{ -(n-k+1)y[i][j] \}?
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: sutracting number from IloNumExpr java cplex

    ‏2013-02-21T14:42:06Z  
    Thanks, Daniel. But then how will I subtract the expression from this constant part. I will say \{setConstant(n) \} and how will I say the \{ -(n-k+1)y[i][j] \}?
    I suggest you take a good look at the IloCplexModeler class reference documentation. That is the superclass of IloCplex that provides the modeling API.
    There you can find for example member function
    IloNumExpr sum(double v, IloNumExpr e1);
    

    that produces the sum of a constant and an expression.
    Updated on 2014-03-24T22:39:33Z at 2014-03-24T22:39:33Z by iron-man