ilog.concert
Interface IloLinearIntExpr


public interface IloLinearIntExpr
extends IloIntExpr

This is the interface for scalar product expressions for integer variables. Objects of type IloLinearIntExpr represent integer linear expressions of the form

sum_{i=1..n} a_i * x_i + c

where x_i are variables of type IloIntVar and c and a_i are integer values. Note that the variable types must be known at compile time for use with IloLinearIntExpr. The java type of the variables must be IloIntVar and cannot be IloNumVar with variable type IloNumVarType.Int.

IloLinearIntExpr objects are created with the methods:

Once created, integer linear expressions can be fully edited: All the information stored in an IloLinearIntExpr object can be queried. The constant term is accessed through the method getConstant(). The values and variables of the terms a_i * x_i are accessed using iterator objects of type IloLinearIntExpr.Iterator that can be created using the method linearIterator().

See Also:
IloModeler.linearIntExpr(), IloModeler.scalProd(int[], IloIntVar[])

Inner Class Summary
static interface IloLinearIntExpr.Iterator
          Iterator for the linear terms of an IloLinearIntExpr expression object.
 
Method Summary
 void add(IloLinearIntExpr sc)
          Adds all the terms found in the scalar product passed as argument to the invoking object.
 void addTerm(IloIntVar var, int coef)
          Adds the new term coef * var to a scalar product.
 void addTerm(int coef, IloIntVar var)
          Adds the new term coef * var to a scalar product.
 void addTerms(IloIntVar[] var, int[] coef)
          Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.
 void addTerms(IloIntVar[] var, int[] coef, int start, int num)
          Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.
 void addTerms(int[] coef, IloIntVar[] var)
          Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.
 void addTerms(int[] coef, IloIntVar[] var, int start, int num)
          Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.
 void clear()
          Removes all terms from the invoking linear expression leaving a 0 expression behind.
 int getConstant()
          Queries the constant term from the invoking IloLinearIntExpr.
 IloLinearIntExpr.Iterator linearIterator()
          Returns an iterator for the variables in the invoking IloLinearIntExpr expression.
 void remove(IloIntVar var)
          Removes a variable from the invoking IloLinearIntExpr expression.
 void remove(IloIntVar[] var)
          Removes a set of variables from the invoking IloLinearIntExpr expression.
 void remove(IloIntVar[] var, int start, int num)
          Removes a set of variables from the invoking IloLinearIntExpr expression.
 void setConstant(int val)
          Sets the constant term from the invoking IloLinearIntExpr to val.
 

Method Detail

addTerm

public void addTerm(int coef,
                    IloIntVar var)
             throws IloException
Adds the new term coef * var to a scalar product.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain a term with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
coef - The coefficient of the added term.
var - The variable of the added term.

addTerm

public void addTerm(IloIntVar var,
                    int coef)
             throws IloException
Adds the new term coef * var to a scalar product.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain a term with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
var - The variable of the added term.
coef - The coefficient of the added term.

addTerms

public void addTerms(int[] coef,
                     IloIntVar[] var,
                     int start,
                     int num)
              throws IloException
Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain a term with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
coef - The coefficients of the added terms.
var - The variables of the added terms.
start - The first element in coef, var to be added.
num - The number of added terms.

addTerms

public void addTerms(IloIntVar[] var,
                     int[] coef,
                     int start,
                     int num)
              throws IloException
Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain terms with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
var - The variables of the added terms.
coef - The coefficients of the added terms.
start - The first element in coef, var to be added.
num - The number of added terms.

addTerms

public void addTerms(int[] coef,
                     IloIntVar[] var)
              throws IloException
Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain terms with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
coef - The coefficients of added terms.
var - The variables of added terms.

addTerms

public void addTerms(IloIntVar[] var,
                     int[] coef)
              throws IloException
Adds the new terms sum_i(coef[i] * var[i]) to a scalar product.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain terms with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
var - The variables of added terms.
coef - The coefficients of added terms.

add

public void add(IloLinearIntExpr sc)
         throws IloException
Adds all the terms found in the scalar product passed as argument to the invoking object.

No checks are performed to verify that the invoking IloLinearIntExpr object does not contain terms with the same variable var. This method can create duplicate terms ... + a_i * x + ... + a_k * x + ... that could be joined to a single term ... + (a_i + a_k) * x + ....
Duplicates do not generate errors but require more memory and more runtime when iterating through the terms of an IloLinearIntExpr.

Parameters:
sc - The scalar product expression, the terms of which are added to the invoking object.

clear

public void clear()
           throws IloException
Removes all terms from the invoking linear expression leaving a 0 expression behind.

getConstant

public int getConstant()
                throws IloException
Queries the constant term from the invoking IloLinearIntExpr.
Returns:
The constant term.

setConstant

public void setConstant(int val)
                 throws IloException
Sets the constant term from the invoking IloLinearIntExpr to val.
Parameters:
val - The new constant term.

remove

public void remove(IloIntVar var)
            throws IloException
Removes a variable from the invoking IloLinearIntExpr expression. All terms in the invoking linear expression with the specified variable are removed from the invoking IloLinearIntExpr object. If variable var occurs more than once in the invoking IloLinearIntExpr, all occurrences are removed. The IloLinearIntExpr.Iterator can be used to remove individual terms regardless of duplicates.
Parameters:
var - The variable to be removed.

remove

public void remove(IloIntVar[] var,
                   int start,
                   int num)
            throws IloException
Removes a set of variables from the invoking IloLinearIntExpr expression. All terms in the invoking linear expression having any variable in var[start], ..., var[start+num-1] are removed. If variable var occurs more than once in the invoking IloLinearIntExpr, all occurrences are removed. The IloLinearIntExpr.Iterator can be used to remove individual terms regardless of duplicates.
Parameters:
var - The array containing the variables to be removed.
start - The index of the first variable in var to be removed.
num - The number of variables in var to be removed.

remove

public void remove(IloIntVar[] var)
            throws IloException
Removes a set of variables from the invoking IloLinearIntExpr expression. All terms in the invoking linear expression having any variable in var[0], ..., var[num-1], where num is the length of array var, are removed from the invoking IloLinearIntExpr object. If variable var occurs more than once in the invoking IloLinearIntExpr, all occurrences are removed. The IloLinearIntExpr.Iterator can be used to remove individual terms regardless of duplicates.
Parameters:
var - The array of variables to be removed.

linearIterator

public IloLinearIntExpr.Iterator linearIterator()
Returns an iterator for the variables in the invoking IloLinearIntExpr expression. An iterator allows the caller to enumerate all the terms of an IloLinearIntExpr and to perform simple operations such as querying or modifying a term. An iterator also allows the caller to remove elements from the underlying IloLinearIntExpr during the iteration with well-defined semantics.