edu.uci.eecs.doc.clepsydra.ipet
Class GLPKAdapter

java.lang.Object
  extended by edu.uci.eecs.doc.clepsydra.ipet.GLPKAdapter
All Implemented Interfaces:
ILPSolver

public class GLPKAdapter
extends Object
implements ILPSolver

Provides an implementation of the ILPSolver interface for the GNU Linear Programming Kit.

Author:
Trevor Harmon

Constructor Summary
GLPKAdapter()
           
 
Method Summary
 void addConstraint(double[] coefficients, int equalTo)
          Adds an equality equation (i.e., row) to the ILP equation matrix.
 void addInequalityConstraint(double[] coefficients, int lessThanOrEqualTo)
          Adds an inequality equation (i.e., row) to the ILP equation matrix.
 void createProblem(int columns)
          Initializes an ILP problem whose equation matrix will contain the specified number of columns (i.e., variables).
 void destroyProblem()
          Deallocates resources that had been allocated to solve the ILP problem.
 String getColumnName(int column)
          Returns the human-friendly name for the specified column in the ILP equation matrix, if one was set.
 int getSolution()
          Solves the ILP problem and returns the result.
 void saveModel(String filename)
          Saves a representation of the ILP problem to disk.
 void setColumnName(int column, String name)
          Provides a human-friendly name for the specified column in the ILP equation matrix.
 void setMaximizeFunction(double[] coefficients)
          Provides the ILP solver with an equation to maximize.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GLPKAdapter

public GLPKAdapter()
Method Detail

createProblem

public void createProblem(int columns)
Initializes an ILP problem whose equation matrix will contain the specified number of columns (i.e., variables). After this method is called, all of the coefficients (i.e., rows) passed into this interface must be of length columns.

Specified by:
createProblem in interface ILPSolver
Parameters:
columns - the number of columns in the ILP equation matrix

setColumnName

public void setColumnName(int column,
                          String name)
Provides a human-friendly name for the specified column in the ILP equation matrix.

Specified by:
setColumnName in interface ILPSolver
Parameters:
column - a column index (first column starts at 1, not 0)
name - a human-friendly name for this column

getColumnName

public String getColumnName(int column)
Returns the human-friendly name for the specified column in the ILP equation matrix, if one was set.

Specified by:
getColumnName in interface ILPSolver
Parameters:
column - a column index (first column is at index 1, not 0)
Returns:
the name of the column, or null if no name has been set

addConstraint

public void addConstraint(double[] coefficients,
                          int equalTo)
Adds an equality equation (i.e., row) to the ILP equation matrix. For example, if the ILP equation has 4 variables (x1, x2, x3, and x4), adding an equation of the form x2 + 5 x3 = 42 would be accomplished like this:
 double[] coefficients = {0, 1, 5, 0};
 ilpsolver.addConstraint(coefficients, 42);
 

Specified by:
addConstraint in interface ILPSolver
Parameters:
coefficients - the coefficients of the equation (including zero coefficients)
equalTo - the right-hand side (a constant) of the equation

addInequalityConstraint

public void addInequalityConstraint(double[] coefficients,
                                    int lessThanOrEqualTo)
Adds an inequality equation (i.e., row) to the ILP equation matrix. For example, if the ILP equation has 4 variables (x1, x2, x3, and x4), adding an equation of the form x2 + 5 x3 <= 42 would be accomplished like this:
 double[] coefficients = {0, 1, 5, 0};
 ilpsolver.addInequalityConstraint(coefficients, 42);
 

Specified by:
addInequalityConstraint in interface ILPSolver
Parameters:
coefficients - the coefficients of the equation (including zero coefficients)
lessThanOrEqualTo - the right-hand side (a constant) of the equation

setMaximizeFunction

public void setMaximizeFunction(double[] coefficients)
Provides the ILP solver with an equation to maximize.

Specified by:
setMaximizeFunction in interface ILPSolver
Parameters:
coefficients - the coefficients of the equation (including zero coefficients)

getSolution

public int getSolution()
Solves the ILP problem and returns the result.

Specified by:
getSolution in interface ILPSolver
Throws:
ILPException - if the solution is infeasible or some other error occurred

saveModel

public void saveModel(String filename)
               throws IOException
Saves a representation of the ILP problem to disk. The format is the "free" variant of the Mathematical Programming System (MPS) format.

Specified by:
saveModel in interface ILPSolver
Parameters:
filename - the name of a file in which to store the representation
Throws:
IOException - if the representation could not be saved to disk

destroyProblem

public void destroyProblem()
Deallocates resources that had been allocated to solve the ILP problem.

Specified by:
destroyProblem in interface ILPSolver