8.3.2. MdoCons¶
- class mindoptpy.MdoCons(model, index: int)¶
Bases:
object
This object implements the data structure to hold an optimization constraint. An empty variaconstraintble object can be created by calling
mindoptpy.MdoModel.add_cons()
. Once created, users may modify the its left-hand-side value or right-hand-side value by callingmindoptpy.MdoCons.set_real_attr()
with a proper real-valued model attribute.Examples
from mindoptpy import * # Create an empty model. model = MdoModel() MDO_INFINITY = MdoModel.get_infinity() # Add variables. x1 = model.add_var(0, MDO_INFINITY, 1, None, "x1", False) x2 = model.add_var(0, MDO_INFINITY, 1, None, "x2", False) x3 = model.add_var(0, 3, 1, None, "x2", False) # Add constraints cons1 = model.add_cons(2 * x1 - x2 <= 3, "c1") cons2 = model.add_cons(3 * x1 + 2 * x2 <= 5, "c2") # Set/get constraint attributes cons1.set_real_attr("RHS", 3.5) cons1.get_real_attr("RHS") cons1.set_str_attr("RowName", 'cons1') cons1.get_str_attr("RowName") # Check constraint cons1.same_as(model.get_cons(0))
Methods
Function to retrieve the current index of the constraint in the optimization model.
Function to retrieve the value of an integer-valued row attribute.
Function to retrieve the value of a real-valued row attribute.
Function to retrieve the value of a string-valued row attribute.
Check whether two constraint objects refer to the same constraint.
Function to change the value of an integer-valued row attribute.
Function to change the value of a real-valued row attribute.
Function to change the value of a string-valued row attribute.
- get_index()¶
This function retrieves the current index of the constraint in the optimization model.
- Returns
The current index of the constraint.
- Return type
int
- get_int_attr(att: str)¶
This function retrieves the value of an integer-valued row attribute.
- Parameters
att (str) – An integer-valued row attribute to access.
- Returns
The current value of the integer-valued row attribute.
- Return type
int
- get_real_attr(att: str)¶
This function retrieves the value of a real-valued row attribute.
- Parameters
att (str) – A real-valued row attribute to access.
- Returns
The current value of the real-valued row attribute.
- Return type
float
- get_str_attr(att: str)¶
This function retrieves the value of a string-valued row attribute.
- Parameters
att (str) – A string-valued row attribute to access.
- Returns
The current value of the string-valued row attribute.
- Return type
str
- same_as(rhs)¶
Check whether two constraint objects refer to the same constraint.
- Parameters
rhs (MdoCons) – Another constraint object.
- Returns
A boolean flag indicates if two constraint objects refer to the same constraint.
- Return type
bint
- set_int_attr(att: str, val: int)¶
This function changes the value of an integer-valued row attribute.
- Parameters
att (str) – An integer-valued row attribute to access.
- Return val
A new value for the integer-valued row attribute.
- Return type
int
- set_real_attr(att: str, val: float)¶
This function changes the value of a real-valued row attribute.
- Parameters
att (str) – A real-valued row attribute to access.
- Return val
A new value for the real-valued row attribute.
- Return type
float
- set_str_attr(att: str, val: str)¶
This function changes the value of a string-valued row attribute.
- Parameters
att (str) – A string-valued row attribute to access.
- Return val
A new value for the string-valued row attribute.
- Return type
str