edu.harvard.econcs.jopt.solver.mip
Class MIP

java.lang.Object
  extended by edu.harvard.econcs.jopt.solver.mip.MIP
All Implemented Interfaces:
IMIP, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
MIPWrapper

public class MIP
extends java.lang.Object
implements IMIP, java.io.Serializable, java.lang.Cloneable

Basic implementation of a mip.

Since:
April 12, 2004
Version:
$Revision: 1.22 $ on $Date: 2008/09/09 19:15:56 $
See Also:
Serialized Form

Field Summary
static int MAX_VALUE
          Never give mip a number bigger than this, FOR ANY reason This should never be greater than 1E9 per https://support.ilog.com/public/products/faq.cfm?Product=CPLEX&FAQ=75&CFID=96044&CFTOKEN=40609383&jsessionid=92301560341115251663761
 
Constructor Summary
MIP()
           
 
Method Summary
 int add(Constraint constraint)
          Adds a new constraint
 int add(Constraint constraint, int constraintId)
          Adds a new constraint
 java.lang.String add(Variable var)
          Adds a variable to the MIP formulation.
 void addObjectiveTerm(Term term)
          Adds a Term to the objective function.
 void addObjectiveTerm(Variable var, double coefficient)
          Creates and then adds a Term to the objective function.
 void clearProposedValues()
          Clears proposed value for this variable
 void clearSolveParams()
           
 boolean getBooleanSolveParam(SolveParam param)
           
 boolean getBooleanSolveParam(SolveParam param, boolean defaultValue)
           
 boolean getBooleanSolveParam(SolveParam param, java.lang.Boolean defaultValue)
           
 Constraint getConstraint(int constraintId)
           
 java.util.Iterator getConstraints()
           
 double getDoubleSolveParam(SolveParam param)
           
 double getDoubleSolveParam(SolveParam param, double defaultValue)
           
 double getDoubleSolveParam(SolveParam param, java.lang.Double defaultValue)
           
 int getIntSolveParam(SolveParam param)
           
 int getIntSolveParam(SolveParam param, int defaultValue)
           
 int getIntSolveParam(SolveParam param, java.lang.Integer defaultValue)
           
 int getNumConstraints()
           
 int getNumVars()
           
 java.util.Iterator getObjectiveTerms()
           
 boolean getProposedBooleanValue(Variable var)
          returns the currently proposed value for Boolean variable var
 double getProposedDoubleValue(Variable var)
          returns the currently proposed value for Double variable var
 int getProposedIntValue(Variable var)
          returns the currently proposed value for Integer variable var
 java.lang.Object getSolveParam(SolveParam param)
          These functions control how JOpt operates, and how the backend solver operates.
 java.util.Set getSpecifiedSolveParams()
           
 java.lang.String getStringSolveParam(SolveParam param)
           
 java.lang.String getStringSolveParam(SolveParam param, java.lang.String defaultValue)
           
 Variable getVar(java.lang.String name)
           
 java.util.Map getVars()
           
 java.util.Set getVarsWithProposedValues()
          useful for copying proposed var/vals to a new MIP
 boolean isObjectiveMax()
           
 boolean isObjectiveMin()
           
 boolean isSolveParamSpecified(SolveParam param)
           
 void proposeValue(Variable var, boolean value)
          Sets proposed value for this variable
 void proposeValue(Variable var, double value)
          Sets proposed value for this variable
 void proposeValue(Variable var, int value)
          Sets proposed value for this variable
 void remove(int constraintId)
          removes a constraint from the formulation.
 void remove(Variable var)
          Removes a variable from the MIP formulation.
 void removeObjectiveTerm(Term term)
          removes a Term from the objective function.
 void removeProposedValue(Variable var)
          Removes proposed value for this variable
 void resetDefaultSolveParams()
          Resets CPLEX/JOpt parameters to: Wall clock, 10 minute timelimit, strict IIS calculation, no-output problem file, and zero missing proposed variables.
 void setObjectiveMax(boolean isMax)
          Set the objective to be MAX (true) or MIN (false)
 void setSolveParam(SolveParam param, boolean value)
           
 void setSolveParam(SolveParam param, double value)
           
 void setSolveParam(SolveParam param, int value)
           
 void setSolveParam(SolveParam param, java.lang.String value)
           
 java.lang.String toString()
           
 IMIP typedClone()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final int MAX_VALUE
Never give mip a number bigger than this, FOR ANY reason This should never be greater than 1E9 per https://support.ilog.com/public/products/faq.cfm?Product=CPLEX&FAQ=75&CFID=96044&CFTOKEN=40609383&jsessionid=92301560341115251663761

See Also:
Constant Field Values
Constructor Detail

MIP

public MIP()
Method Detail

getVars

public java.util.Map getVars()
Specified by:
getVars in interface IMIP
Returns:
a Map from Strings to Variables.

getVar

public Variable getVar(java.lang.String name)
Specified by:
getVar in interface IMIP
Returns:
the Variable corresponding to the String name.

add

public java.lang.String add(Variable var)
Description copied from interface: IMIP
Adds a variable to the MIP formulation. Depending on the implementation you may find that this variable doesn't show up in the solver. (For instance if there is no reference to the variable in any constraint

Specified by:
add in interface IMIP
Returns:
the string representation of the variable

getNumVars

public int getNumVars()
Specified by:
getNumVars in interface IMIP
Returns:
the number of variables in the MIP formulation.

proposeValue

public void proposeValue(Variable var,
                         double value)
Sets proposed value for this variable

Specified by:
proposeValue in interface IMIP

proposeValue

public void proposeValue(Variable var,
                         int value)
Sets proposed value for this variable

Specified by:
proposeValue in interface IMIP

proposeValue

public void proposeValue(Variable var,
                         boolean value)
Sets proposed value for this variable

Specified by:
proposeValue in interface IMIP

removeProposedValue

public void removeProposedValue(Variable var)
Removes proposed value for this variable

Specified by:
removeProposedValue in interface IMIP

clearProposedValues

public void clearProposedValues()
Clears proposed value for this variable

Specified by:
clearProposedValues in interface IMIP

getVarsWithProposedValues

public java.util.Set getVarsWithProposedValues()
useful for copying proposed var/vals to a new MIP

Specified by:
getVarsWithProposedValues in interface IMIP

getProposedIntValue

public int getProposedIntValue(Variable var)
Description copied from interface: IMIP
returns the currently proposed value for Integer variable var

Specified by:
getProposedIntValue in interface IMIP

getProposedDoubleValue

public double getProposedDoubleValue(Variable var)
Description copied from interface: IMIP
returns the currently proposed value for Double variable var

Specified by:
getProposedDoubleValue in interface IMIP

getProposedBooleanValue

public boolean getProposedBooleanValue(Variable var)
Description copied from interface: IMIP
returns the currently proposed value for Boolean variable var

Specified by:
getProposedBooleanValue in interface IMIP

getConstraints

public java.util.Iterator getConstraints()
Specified by:
getConstraints in interface IMIP
Returns:
An iterator over the constraints

add

public int add(Constraint constraint)
Description copied from interface: IMIP
Adds a new constraint

Specified by:
add in interface IMIP
Parameters:
constraint - the constraint to add
Returns:
constraintId should be a UNIQUE number; useful for getting the dual of this constraint

add

public int add(Constraint constraint,
               int constraintId)
Description copied from interface: IMIP
Adds a new constraint

Specified by:
add in interface IMIP
Parameters:
constraint - the constraint to add
constraintId - should be a UNIQUE number; useful for getting the dual of this constraint
Returns:

getNumConstraints

public int getNumConstraints()
Specified by:
getNumConstraints in interface IMIP
Returns:
the number of constraints in the system

getObjectiveTerms

public java.util.Iterator getObjectiveTerms()
Specified by:
getObjectiveTerms in interface IMIP
Returns:
an iterator on the objective Term objects

addObjectiveTerm

public void addObjectiveTerm(Term term)
Description copied from interface: IMIP
Adds a Term to the objective function.

Specified by:
addObjectiveTerm in interface IMIP

addObjectiveTerm

public void addObjectiveTerm(Variable var,
                             double coefficient)
Description copied from interface: IMIP
Creates and then adds a Term to the objective function.

Specified by:
addObjectiveTerm in interface IMIP

isObjectiveMax

public boolean isObjectiveMax()
Specified by:
isObjectiveMax in interface IMIP
Returns:
true if objective is a max

isObjectiveMin

public boolean isObjectiveMin()
Specified by:
isObjectiveMin in interface IMIP
Returns:
true if objective is a min

setObjectiveMax

public void setObjectiveMax(boolean isMax)
Description copied from interface: IMIP
Set the objective to be MAX (true) or MIN (false)

Specified by:
setObjectiveMax in interface IMIP

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

remove

public void remove(int constraintId)
Description copied from interface: IMIP
removes a constraint from the formulation.

Specified by:
remove in interface IMIP

remove

public void remove(Variable var)
Description copied from interface: IMIP
Removes a variable from the MIP formulation. Depending on the implementation this may not actually communicate with the solver, if this variable is unused by the solver.

Specified by:
remove in interface IMIP

removeObjectiveTerm

public void removeObjectiveTerm(Term term)
Description copied from interface: IMIP
removes a Term from the objective function.

Specified by:
removeObjectiveTerm in interface IMIP

typedClone

public IMIP typedClone()
Specified by:
typedClone in interface IMIP

getConstraint

public Constraint getConstraint(int constraintId)
Specified by:
getConstraint in interface IMIP
Parameters:
constraintId - the id passed in during constraint creation
Returns:
the Constraint object

getSolveParam

public java.lang.Object getSolveParam(SolveParam param)
Description copied from interface: IMIP
These functions control how JOpt operates, and how the backend solver operates. You can control a number of parameters. Not all of these will be supported by your chosen backend solver, unfortunently. But we try to map these settings into relevant solver settings. See each setting to see if they are applicable to CPLEX, LPSOLVE, or ALLSOLVERS

Specified by:
getSolveParam in interface IMIP

getIntSolveParam

public int getIntSolveParam(SolveParam param,
                            java.lang.Integer defaultValue)
Specified by:
getIntSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getIntSolveParam

public int getIntSolveParam(SolveParam param,
                            int defaultValue)
Specified by:
getIntSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getIntSolveParam

public int getIntSolveParam(SolveParam param)
Specified by:
getIntSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getDoubleSolveParam

public double getDoubleSolveParam(SolveParam param,
                                  java.lang.Double defaultValue)
Specified by:
getDoubleSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getDoubleSolveParam

public double getDoubleSolveParam(SolveParam param,
                                  double defaultValue)
Specified by:
getDoubleSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getDoubleSolveParam

public double getDoubleSolveParam(SolveParam param)
Specified by:
getDoubleSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getBooleanSolveParam

public boolean getBooleanSolveParam(SolveParam param,
                                    java.lang.Boolean defaultValue)
Specified by:
getBooleanSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getBooleanSolveParam

public boolean getBooleanSolveParam(SolveParam param,
                                    boolean defaultValue)
Specified by:
getBooleanSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getBooleanSolveParam

public boolean getBooleanSolveParam(SolveParam param)
Specified by:
getBooleanSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getStringSolveParam

public java.lang.String getStringSolveParam(SolveParam param,
                                            java.lang.String defaultValue)
Specified by:
getStringSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getStringSolveParam

public java.lang.String getStringSolveParam(SolveParam param)
Specified by:
getStringSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

setSolveParam

public void setSolveParam(SolveParam param,
                          int value)
Specified by:
setSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

setSolveParam

public void setSolveParam(SolveParam param,
                          double value)
Specified by:
setSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

setSolveParam

public void setSolveParam(SolveParam param,
                          boolean value)
Specified by:
setSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

setSolveParam

public void setSolveParam(SolveParam param,
                          java.lang.String value)
Specified by:
setSolveParam in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

getSpecifiedSolveParams

public java.util.Set getSpecifiedSolveParams()
Specified by:
getSpecifiedSolveParams in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

clearSolveParams

public void clearSolveParams()
Specified by:
clearSolveParams in interface IMIP
See Also:
IMIP.getSolveParam(SolveParam)

resetDefaultSolveParams

public void resetDefaultSolveParams()
Resets CPLEX/JOpt parameters to: Wall clock, 10 minute timelimit, strict IIS calculation, no-output problem file, and zero missing proposed variables.

Specified by:
resetDefaultSolveParams in interface IMIP

isSolveParamSpecified

public boolean isSolveParamSpecified(SolveParam param)
Specified by:
isSolveParamSpecified in interface IMIP