Class MPConstraint

java.lang.Object
com.google.ortools.linearsolver.MPConstraint

public class MPConstraint extends Object
The class for constraints of a Mathematical Programming (MP) model.

A constraint is represented as a linear equation or inequality.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    MPConstraint(long cPtr, boolean cMemoryOwn)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Advanced usage: returns the basis status of the constraint.

    It is only available for continuous problems).

    Note that if a constraint "linear_expression in [lb, ub]" is transformed
    into "linear_expression + slack = 0" with slack in [-ub, -lb], then this
    status is the same as the status of the slack variable with AT_UPPER_BOUND
    and AT_LOWER_BOUND swapped.

    void
     
    double
    Advanced usage: returns the dual value of the constraint in the current
    solution (only available for continuous problems).
    protected void
     
    double
    Gets the coefficient of a given variable on the constraint (which is 0 if
    the variable does not appear in the constraint).
    protected static long
     
    int
    Returns the index of the constraint in the MPSolver::constraints_.
    boolean
    Advanced usage: returns true if the constraint is "lazy" (see below).
    double
    lb()
    Returns the lower bound.
    Returns the name of the constraint.
    void
    setBounds(double lb, double ub)
    Sets both the lower and upper bounds.
    void
    setCoefficient(MPVariable var, double coeff)
    Sets the coefficient of the variable on the constraint.

    If the variable does not belong to the solver, the function just returns,
    or crashes in non-opt mode.
    void
    setIsLazy(boolean laziness)
    Advanced usage: sets the constraint "laziness".

    This is only supported for SCIP and has no effect on other
    solvers.


    When laziness is true, the constraint is only considered by the Linear
    Programming solver if its current solution violates the constraint.
    void
    setLb(double lb)
    Sets the lower bound.
    void
    setUb(double ub)
    Sets the upper bound.
    protected static long
     
    double
    ub()
    Returns the upper bound.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • swigCMemOwn

      protected transient boolean swigCMemOwn
  • Constructor Details

    • MPConstraint

      protected MPConstraint(long cPtr, boolean cMemoryOwn)
  • Method Details

    • getCPtr

      protected static long getCPtr(MPConstraint obj)
    • swigRelease

      protected static long swigRelease(MPConstraint obj)
    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • delete

      public void delete()
    • name

      public String name()
      Returns the name of the constraint.
    • setCoefficient

      public void setCoefficient(MPVariable var, double coeff)
      Sets the coefficient of the variable on the constraint.

      If the variable does not belong to the solver, the function just returns,
      or crashes in non-opt mode.
    • getCoefficient

      public double getCoefficient(MPVariable var)
      Gets the coefficient of a given variable on the constraint (which is 0 if
      the variable does not appear in the constraint).
    • lb

      public double lb()
      Returns the lower bound.
    • ub

      public double ub()
      Returns the upper bound.
    • setLb

      public void setLb(double lb)
      Sets the lower bound.
    • setUb

      public void setUb(double ub)
      Sets the upper bound.
    • setBounds

      public void setBounds(double lb, double ub)
      Sets both the lower and upper bounds.
    • isLazy

      public boolean isLazy()
      Advanced usage: returns true if the constraint is "lazy" (see below).
    • setIsLazy

      public void setIsLazy(boolean laziness)
      Advanced usage: sets the constraint "laziness".

      This is only supported for SCIP and has no effect on other
      solvers.


      When laziness is true, the constraint is only considered by the Linear
      Programming solver if its current solution violates the constraint. In this
      case, the constraint is definitively added to the problem. This may be
      useful in some MIP problems, and may have a dramatic impact on performance.

      For more info see: http://tinyurl.com/lazy-constraints.
    • index

      public int index()
      Returns the index of the constraint in the MPSolver::constraints_.
    • dualValue

      public double dualValue()
      Advanced usage: returns the dual value of the constraint in the current
      solution (only available for continuous problems).
    • basisStatus

      public MPSolver.BasisStatus basisStatus()
      Advanced usage: returns the basis status of the constraint.

      It is only available for continuous problems).

      Note that if a constraint "linear_expression in [lb, ub]" is transformed
      into "linear_expression + slack = 0" with slack in [-ub, -lb], then this
      status is the same as the status of the slack variable with AT_UPPER_BOUND
      and AT_LOWER_BOUND swapped.