Module scop2 :: Class Linear
[hide private]
[frames] | no frames]

Class Linear

source code

object --+    
         |    
Constraint --+
             |
            Linear

Instance Methods [hide private]
 
__init__(self, name, weight=1, rhs=0, direction='<=')
Linear constraint constructor.
source code
 
__str__(self)
Returns the information of the linear constraint.
source code
 
addTerms(self, coeffs=[], vars=[], values=[])
Adds new terms into left-hand-side of linear constraint.
source code
 
feasible(self, allvars)
Return True if the constraint is defined correctly.
source code
 
setDirection(self, direction='<=')
Sets the direction (or sense) of linear constraint.
source code
 
setRhs(self, rhs=0)
Sets the right-hand-side of linear constraint.
source code

Inherited from Constraint: setWeight

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, weight=1, rhs=0, direction='<=')
(Constructor)

source code 

Linear constraint constructor.

  • Arguments:
    • name: Name of linear constraint.
    • weight (optional): Positive integer representing importance of constraint.
    • rhs: Right-hand-side constant of linear constraint.
    • direction: Rirection (or sense) of linear constraint; "<=" (default) or ">=" or "=."
  • Attributes:
    • name: Name of linear constraint.
    • weight (optional): Positive integer representing importance of constraint.
    • rhs: Right-hand-side constant of linear constraint.
    • direction: Direction (or sense) of linear constraint; "<=" (default) or ">=" or "=".
    • terms: List of terms in left-hand-side of constraint. Each term is a tuple of coeffcient,variable and its value.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Returns the information of the linear constraint. The constraint is expanded and is shown in a readable format.

Overrides: object.__str__

addTerms(self, coeffs=[], vars=[], values=[])

source code 

Adds new terms into left-hand-side of linear constraint.

  • Arguments:
    • coeffs: Coefficients for new terms; either a list of coefficients or a single coefficient. The three arguments must have the same size.
    • vars: Variables for new terms; either a list of variables or a single variable. The three arguments must have the same size.
    • values: Values for new terms; either a list of values or a single value. The three arguments must have the same size.
  • Example usage:
    >>> L.addTerms(1.0, y, "A")
    >>> L.addTerms([2, 3, 1], [y, y, z], ["C", "D", "C"])

    which adds the left-hand-side 2 X[y,"C"]+3 X[y,"D"]+1 X[z,"C"].

setDirection(self, direction='<=')

source code 

Sets the direction (or sense) of linear constraint.

  • Argument:
    • direction: direction (or sense) of linear constraint; "<=" (default) or ">=" or "=."
  • Example usage:
    >>> L.setDirection("=")

setRhs(self, rhs=0)

source code 

Sets the right-hand-side of linear constraint.

  • Argument:
    • rhs: Right-hand-side of linear constraint.
  • Example usage:
    >>> L.setRhs(10)