scpsolver.problems
Class LinearProgram

java.lang.Object
  extended by scpsolver.problems.MathematicalProgram
      extended by scpsolver.problems.LinearProgram
All Implemented Interfaces:
ConstrainedProblem, Problem

public class LinearProgram
extends MathematicalProgram
implements ConstrainedProblem

Basic description for a linear program. In an ordinary production usage, this class usually gets instanced first. Then all constraints and boundaries are added and finally, a solver is instanced to solve the linear program.

Author:
planatsc

Field Summary
 
Fields inherited from class scpsolver.problems.MathematicalProgram
c, constraints, isboolean, isinteger, lowerbound, minproblem, upperbound
 
Constructor Summary
LinearProgram()
          Creates a basic maximization problem with no target function and no constraints.
LinearProgram(double[] pc)
          Creates a basic maximization problem with the given target function and no constraints.
LinearProgram(LinearProgram lp)
          Creates a shallow copy of a given linear program.
LinearProgram(SparseVector c)
          Creates a basic maximization problem with the given target function and no constraints.
 
Method Summary
 boolean addConstraint(LinearConstraint c)
          Adds a linear constraint to the model.
 boolean addConstraints(java.util.ArrayList<LinearConstraint> c)
          Adds a list of linear constraint to the model.
 java.lang.StringBuffer convertToCPLEX()
          Converts a given linear program into the CPLEX file format.
 double evaluate(double[] x)
          Evaluates the target function at position x.
 java.util.ArrayList<Constraint> getConstraints()
          Returns the current constraint list.
 java.util.HashMap<java.lang.String,java.lang.Integer> getIndexmap()
           
 java.lang.String getName()
          Returns a short String description of the class.
 boolean isFeasable(double[] x)
          Checks if all constraints are fulfilled for the vector x.
static void main(java.lang.String[] args)
           
 void setBinary(int i)
          Marks a variable as boolean.
 void setConstraints(java.util.ArrayList<Constraint> constraints)
          Sets the whole list of constraints at once.
 void setIndexmap(java.util.HashMap<java.lang.String,java.lang.Integer> indexmap)
           
 
Methods inherited from class scpsolver.problems.MathematicalProgram
getC, getDimension, getIsboolean, getIsinteger, getLowerbound, getUpperbound, hasBounds, isMinProblem, isMIP, makeDoubleArray, setC, setContinous, setInteger, setIsinteger, setLowerbound, setMinProblem, setUpperbound
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface scpsolver.problems.Problem
getDimension, isMinProblem, setMinProblem
 

Constructor Detail

LinearProgram

public LinearProgram()
Creates a basic maximization problem with no target function and no constraints.


LinearProgram

public LinearProgram(double[] pc)
Creates a basic maximization problem with the given target function and no constraints.

Parameters:
pc - the vector of the target function

LinearProgram

public LinearProgram(SparseVector c)
Creates a basic maximization problem with the given target function and no constraints.

Parameters:
c - the vector of the target function in its sparse representation

LinearProgram

public LinearProgram(LinearProgram lp)
Creates a shallow copy of a given linear program.

Parameters:
lp - the program to be copied
Method Detail

setBinary

public void setBinary(int i)
Marks a variable as boolean. Note: A variable is not directly marked as boolean but as an integer with 0 <= x_i <= 1.

Parameters:
i - The index of the variable.

setConstraints

public void setConstraints(java.util.ArrayList<Constraint> constraints)
Sets the whole list of constraints at once. Note that the existing constraints are immediately overwritten without any further checking or copying and are simply lost. Therefore, the user might want to check, if there are any previous constraints, before he sets the complete list. Generally, it's recommended to use the addConstraint method for adding constraints to a problem model. On the other hand, this method can be used to delete constraints from a model, but the user has to ensure that a valid ArrayList<Constraint> is passed. This method will accept the null value, but this will lead to invalid states.

Parameters:
constraints - the new constraint list

addConstraint

public boolean addConstraint(LinearConstraint c)
Adds a linear constraint to the model. If no deletion operation is needed, this method is to be preferred before using setConstraints.

Parameters:
c - the linear constraint to be added
Returns:
true, if the constraint was succesfully added, otherwise false

addConstraints

public boolean addConstraints(java.util.ArrayList<LinearConstraint> c)
Adds a list of linear constraint to the model. If no deletion operation is needed, this method is to be preferred before using setConstraints.

Parameters:
c - the linear constraint to be added
Returns:
true, if the constraint was succesfully added, otherwise false

isFeasable

public boolean isFeasable(double[] x)
Checks if all constraints are fulfilled for the vector x.

Specified by:
isFeasable in interface ConstrainedProblem
Parameters:
the - vector which is to be checked
Returns:
true, if the vector x fulfills all constraints, otherwise false

getConstraints

public java.util.ArrayList<Constraint> getConstraints()
Returns the current constraint list.

Specified by:
getConstraints in interface ConstrainedProblem
Returns:
the list of the current constraints

evaluate

public double evaluate(double[] x)
Evaluates the target function at position x.

Specified by:
evaluate in interface Problem
Parameters:
x - the position, where the target function is to be evaluated
Returns:
the value of the target function at said position

getName

public java.lang.String getName()
Returns a short String description of the class.

Specified by:
getName in interface Problem
Returns:
Returns the String "Linear Program"

convertToCPLEX

public java.lang.StringBuffer convertToCPLEX()
Converts a given linear program into the CPLEX file format.

Returns:
A StringBuffer containing the linear problem specifications in the CPLEX format

getIndexmap

public java.util.HashMap<java.lang.String,java.lang.Integer> getIndexmap()

setIndexmap

public void setIndexmap(java.util.HashMap<java.lang.String,java.lang.Integer> indexmap)

main

public static void main(java.lang.String[] args)