net.sf.javailp
Class Linear

java.lang.Object
  extended by net.sf.javailp.Linear
All Implemented Interfaces:
Iterable<Term>

public class Linear
extends Object
implements Iterable<Term>

The class Linear is a linear expression consisting of variables and their coefficients.


Constructor Summary
Linear()
          Constructs an empty linear expression.
Linear(Iterable<Term> terms)
          Constructs a linear expression from the terms.
Linear(List<Number> coefficients, List<Object> variables)
          Constructs a linear expression with the predefined variables and their coefficients.
 
Method Summary
 void add(Number coefficient, Object variable)
          Adds an element to the linear expression.
 void add(Term... terms)
          Adds terms.
 void clear()
          Removes all elements.
 Number evaluate(Map<Object,Number> result)
          Evaluates the value of the linear expression.
 Term get(int i)
          Returns the i-th Term.
 List<Number> getCoefficients()
          Returns the coefficients.
 List<Object> getVariables()
          Returns the variables.
 Iterator<Term> iterator()
           
 int size()
          Returns the size (number of variables) of the linear expression.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Linear

public Linear()
Constructs an empty linear expression.


Linear

public Linear(List<Number> coefficients,
              List<Object> variables)
Constructs a linear expression with the predefined variables and their coefficients.

Parameters:
coefficients - the coefficients
variables - the variables

Linear

public Linear(Iterable<Term> terms)
Constructs a linear expression from the terms.

Parameters:
terms - the terms to be added
Method Detail

getCoefficients

public List<Number> getCoefficients()
Returns the coefficients.

Returns:
the coefficients

getVariables

public List<Object> getVariables()
Returns the variables.

Returns:
the variables

add

public void add(Number coefficient,
                Object variable)
Adds an element to the linear expression.

Parameters:
coefficient - the coefficient
variable - the variable

add

public void add(Term... terms)
Adds terms.

Parameters:
terms - the terms to be added

size

public int size()
Returns the size (number of variables) of the linear expression.

Returns:
the size

clear

public void clear()
Removes all elements.


toString

public String toString()
Overrides:
toString in class Object

evaluate

public Number evaluate(Map<Object,Number> result)
Evaluates the value of the linear expression.

Parameters:
result - the result
Returns:
the value

iterator

public Iterator<Term> iterator()
Specified by:
iterator in interface Iterable<Term>

get

public Term get(int i)
Returns the i-th Term.

Parameters:
i - the index
Returns:
the term