Class ModelBuilder

java.lang.Object
com.google.ortools.modelbuilder.ModelBuilder

public final class ModelBuilder extends Object
Main modeling class.

Proposes a factory to create all modeling objects understood by the SAT solver.

  • Constructor Details

    • ModelBuilder

      public ModelBuilder()
      Main constructor
  • Method Details

    • getClone

      public ModelBuilder getClone()
      Returns a cloned model
    • newVar

      public Variable newVar(double lb, double ub, boolean isIntegral, String name)
      Creates a variable with domain [lb, ub].
    • newNumVar

      public Variable newNumVar(double lb, double ub, String name)
      Creates a continuous variable with domain [lb, ub].
    • newIntVar

      public Variable newIntVar(double lb, double ub, String name)
      Creates an integer variable with domain [lb, ub].
    • newBoolVar

      public Variable newBoolVar(String name)
      Creates a Boolean variable with the given name.
    • newConstant

      public Variable newConstant(double value)
      Creates a constant variable.
    • varFromIndex

      public Variable varFromIndex(int index)
      Rebuilds a variable from its index.
    • addLinearConstraint

      public LinearConstraint addLinearConstraint(LinearArgument expr, double lb, double ub)
      Adds lb <= expr <= ub.
    • addEquality

      public LinearConstraint addEquality(LinearArgument expr, double value)
      Adds expr == value.
    • addEquality

      public LinearConstraint addEquality(LinearArgument left, LinearArgument right)
      Adds left == right.
    • addLessOrEqual

      public LinearConstraint addLessOrEqual(LinearArgument expr, double value)
      Adds expr <= value.
    • addLessOrEqual

      public LinearConstraint addLessOrEqual(LinearArgument left, LinearArgument right)
      Adds left <= right.
    • addGreaterOrEqual

      public LinearConstraint addGreaterOrEqual(LinearArgument expr, double value)
      Adds expr >= value.
    • addGreaterOrEqual

      public LinearConstraint addGreaterOrEqual(LinearArgument left, LinearArgument right)
      Adds left >= right.
    • constraintFromIndex

      public LinearConstraint constraintFromIndex(int index)
      Rebuilds a linear constraint from its index.
    • addEnforcedLinearConstraint

      public EnforcedLinearConstraint addEnforcedLinearConstraint(LinearArgument expr, double lb, double ub, Variable iVar, boolean iValue)
      Adds ivar == iValue => lb <= expr <= ub.
    • addEnforcedEquality

      public EnforcedLinearConstraint addEnforcedEquality(LinearArgument expr, double value, Variable iVar, boolean iValue)
      Adds ivar == iValue => expr == value.
    • addEnforcedEquality

      public EnforcedLinearConstraint addEnforcedEquality(LinearArgument left, LinearArgument right, Variable iVar, boolean iValue)
      Adds ivar == iValue => left == right.
    • addEnforcedLessOrEqual

      public EnforcedLinearConstraint addEnforcedLessOrEqual(LinearArgument expr, double value, Variable iVar, boolean iValue)
      Adds ivar == iValue => expr <= value.
    • addEnforcedLessOrEqual

      public EnforcedLinearConstraint addEnforcedLessOrEqual(LinearArgument left, LinearArgument right, Variable iVar, boolean iValue)
      Adds ivar == iValue => left <= right.
    • addEnforcedGreaterOrEqual

      public EnforcedLinearConstraint addEnforcedGreaterOrEqual(LinearArgument expr, double value, Variable iVar, boolean iValue)
      Adds ivar == iValue => expr >= value.
    • addEnforcedGreaterOrEqual

      public EnforcedLinearConstraint addEnforcedGreaterOrEqual(LinearArgument left, LinearArgument right, Variable iVar, boolean iValue)
      Adds ivar == iValue => left >= right.
    • enforcedConstraintFromIndex

      public EnforcedLinearConstraint enforcedConstraintFromIndex(int index)
      Rebuilds a linear constraint from its index.
    • minimize

      public void minimize(LinearArgument obj)
      Minimize expression
    • maximize

      public void maximize(LinearArgument obj)
      Minimize expression
    • optimize

      public void optimize(LinearArgument obj, boolean maximize)
      Sets the objective expression.
    • numVariables

      public int numVariables()
      Returns the number of variables in the model.
    • numConstraints

      public int numConstraints()
      Returns the number of constraints in the model.
    • getName

      public String getName()
      Returns the name of the model.
    • setName

      public void setName(String name)
      Sets the name of the model.
    • exportToFile

      public boolean exportToFile(String file)
      Write the model as a protocol buffer to 'file'.
      Parameters:
      file - file to write the model to. If the filename ends with 'txt', the model will be written as a text file, otherwise, the binary format will be used.
      Returns:
      true if the model was correctly written.
    • importFromFile

      public boolean importFromFile(String file)
      import the model from protocol buffer 'file'.
      Parameters:
      file - file to read the model from.
      Returns:
      true if the model was correctly loaded.
    • exportToMpsString

      public String exportToMpsString(boolean obfuscate)
    • exportToLpString

      public String exportToLpString(boolean obfuscate)
    • writeToMpsFile

      public boolean writeToMpsFile(String filename, boolean obfuscate)
    • importFromMpsString

      public boolean importFromMpsString(String mpsString)
    • importFromMpsFile

      public boolean importFromMpsFile(String mpsFile)
    • importFromLpString

      public boolean importFromLpString(String lpString)
    • importFromLpFile

      public boolean importFromLpFile(String lpFile)
    • getHelper

      public ModelBuilderHelper getHelper()
      Returns the model builder helper.