Equation#
- class gamspy.Equation(container: Container | None = None, name: str | None = None, type: str | EquationType = 'regular', domain: DomainType | None = None, definition: Variable | Operation | Expression | None = None, records: VarEquRecordsType | None = None, domain_forwarding: bool | list[bool] = False, description: str = '', uels_on_axes: bool = False, is_miro_output: bool = False, definition_domain: list | None = None)[source]#
Bases:
VarEquSymbolRepresents an Equation symbol in GAMS.
Equations represent the constraints or relationships in a model. They can be defined using equality (==) or inequality (<=, >=) operators. See https://gamspy.readthedocs.io/en/latest/user/basics/equation.html
- Parameters:
- containerContainer
The Container object that this equation belongs to.
- namestr, optional
Name of the equation. If not provided, a unique name is generated automatically.
- typestr, optional
Type of the equation. Options: “regular”, “nonbinding”, “external”, “boolean”. Default is “regular”.
- domainSequence[Set | Alias | str] | Set | Alias | str, optional
The domain of the equation. Can be a list of Sets/Aliases, a single Set/Alias, or strings representing set names. Use “*” for the universe set. Default is [] (scalar).
- definitionVariable | Operation | Expression, optional
The mathematical definition of the equation. Can be set later via assignment.
- recordsSequence | np.ndarray | int | float | pd.DataFrame | pd.Series | dict, optional
Initial records to populate the equation.
- domain_forwardingbool | list[bool], optional
If True, adding records to this equation will implicitly add new elements to the domain sets (if they are dynamic). Default is False.
- descriptionstr, optional
A human-readable description of the equation.
- uels_on_axesbool, optional
If True, implies that the Unique Element Labels (UELs) for the domain are contained in the axes (index/columns) of the provided records object.
- is_miro_outputbool, optional
If True, flags this equation as an output symbol for GAMS MIRO. Default is False.
- Attributes:
containerContainer of the symbol
descriptionDescription of the symbol
dimensionThe dimension of symbol
domainList of domains given either as string (* for universe set) or as reference to the Set/Alias object
domain_labelsThe column headings for the records DataFrame
domain_namesString version of domain names
domain_typeState of the domain links
infeasThe Infeasibility of the equation.
is_scalarReturns True if the len(self.domain) = 0
lThe Level of the equation (its current value).
loThe Lower Bound of the equation.
mThe Marginal (dual) value of the equation.
number_recordsNumber of records
rangeThe Range of the equation.
recordsReturns the records (data) of the Equation as a DataFrame.
scaleThe Scale factor of the equation.
- shape
slackThe Slack of the equation.
slackloThe lower bound slack of the equation.
slackupThe upper bound slack of the equation.
stageThe Stage of the equation.
- summary
synchronizeSynchronization state of the symbol.
typeThe type of the equation.
upThe Upper Bound of the equation.
Methods
Computes infeasibilities of the equation.
Drops records from the symbol that are equal to their default values.
dropEps()Drops records from the symbol that contain EPS (Epsilon) values.
Drops records from the symbol that contain missing (NaN) values.
dropNA()Drops records from the symbol that contain NA (Not Available) values.
Drops records from the symbol that contain UNDEF (Undefined) values.
equals(other[, columns, check_meta_data, ...])Compares this symbol with another symbol to evaluate structural and numerical equality across specified attributes.
gamsRepr()Returns the string representation of this Equation in the GAMS language.
generateRecords([density, func, seed])Automatically generates records for the symbol based on a specified density and optional attribute-specific generation functions.
Returns the GAMS declaration statement for this Equation.
Returns the GAMS definition statement (algebra) for this Equation.
getEquationListing([n, filters, ...])Returns the equation listing (log output) from the last solve.
Calculates the sparsity of the symbol's records.
Generates a LaTeX representation of the equation definition.
pivot([index, columns, value, fill_value])Pivots the specified attribute of the symbol records into a two-dimensional pandas DataFrame.
setRecords(records[, uels_on_axes])Sets the records (data) of the Equation.
toDense([column])Convert column to a dense numpy.array format
toDict([columns, orient])Converts the records of a non-scalar symbol to a Python dictionary.
toList([columns])Converts the specified attributes of the symbol records to a Python list.
toSparseCoo([column])Converts a specified attribute column of the symbol's records to a SciPy sparse COOrdinate format (coo_matrix).
toValue([column])Returns the numerical value of a specified attribute for a scalar symbol.
countEps
countNA
countNegInf
countPosInf
countUndef
findEps
findNA
findNegInf
findPosInf
findSpecialValues
findUndef
getMaxAbsValue
getMaxValue
getMeanValue
getMinValue
whereMax
whereMaxAbs
whereMin
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=['i1','i2']) >>> a = gp.Parameter(m, "a", [i], records=[['i1',1],['i2',2]]) >>> v = gp.Variable(m, "v", domain=[i]) >>> e = gp.Equation(m, "e", domain=[i]) >>> e[i] = a[i] <= v[i]
- computeInfeasibilities() DataFrame | None[source]#
Computes infeasibilities of the equation.
Checks if the level value .l violates the bounds .lo and .up and returns a DataFrame containing the violations.
- Returns:
- pd.DataFrame | None
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> e = gp.Equation(m, "e") >>> e.l[...] = -10 >>> e.lo[...] = 5 >>> e.computeInfeasibilities().values.tolist() [[-10.0, 0.0, 5.0, inf, 1.0, 15.0]]
- countEps(columns: str | list[str] | None = None) int#
- countNA(columns: str | list[str] | None = None) int#
- countNegInf(columns: str | list[str] | None = None) int#
- countPosInf(columns: str | list[str] | None = None) int#
- countUndef(columns: str | list[str] | None = None) int#
- dropDefaults() None#
Drops records from the symbol that are equal to their default values.
This method removes records where all attributes (level, marginal, lower, upper, scale) match the default records for the symbol type.
- dropEps() None#
Drops records from the symbol that contain EPS (Epsilon) values.
This method removes any record where at least one of its attributes (level, marginal, lower, upper, scale) is a SpecialValues.EPS value.
- dropMissing() None#
Drops records from the symbol that contain missing (NaN) values.
This method removes any record where at least one of its attributes (level, marginal, lower, upper, scale) is missing (pandas NaN).
- dropNA() None#
Drops records from the symbol that contain NA (Not Available) values.
This method removes any record where at least one of its attributes (level, marginal, lower, upper, scale) is a SpecialValues.NA value.
- dropUndef() None#
Drops records from the symbol that contain UNDEF (Undefined) values.
This method removes any record where at least one of its attributes (level, marginal, lower, upper, scale) is a SpecialValues.UNDEF value.
- equals(other: Variable | Equation, columns: str | list[str] | None = None, check_meta_data: bool = True, rtol: int | float | None = None, atol: int | float | None = None) bool#
Compares this symbol with another symbol to evaluate structural and numerical equality across specified attributes.
This method verifies dimensions, domain types, and data structure. It then performs an outer merge to match domains and checks the specified attribute columns for strict special value equivalence (EPS, NA, UNDEF) and numeric closeness (using relative and absolute tolerances).
- Parameters:
- otherVariable | Equation
The other Variable or Equation object to compare against.
- columnsstr | list[str] | None, optional
The specific attribute column(s) to evaluate (e.g., [“level”, “marginal”]). If None, defaults to all symbol attributes (_attributes).
- check_meta_databool, optional
If True, verifies that the symbol names and descriptions match exactly. Defaults to True.
- rtolint | float | None, optional
Relative tolerance used for numeric evaluation via np.isclose. Defaults to 0.0.
- atolint | float | None, optional
Absolute tolerance used for numeric evaluation via np.isclose. Defaults to 0.0.
- Returns:
- bool
True if the symbols are structurally identical and the evaluated attributes are equivalent within the specified tolerances; False otherwise.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> v1 = gp.Variable(m, name="v1", type="positive", domain=[i]) >>> v2 = gp.Variable(m, name="v2", type="positive", domain=[i]) >>> v1.equals(v2, check_meta_data=False) True
- findEps(column: str | None = None) pd.DataFrame | None#
- findNA(column: str | None = None) pd.DataFrame | None#
- findNegInf(column: str | None = None) pd.DataFrame | None#
- findPosInf(column: str | None = None) pd.DataFrame | None#
- findSpecialValues(values: float | list[float], column: str | None = None) pd.DataFrame | None#
- findUndef(column: str | None = None) pd.DataFrame | None#
- gamsRepr() str[source]#
Returns the string representation of this Equation in the GAMS language.
(e.g., ‘e(i)’).
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=['i1','i2']) >>> e = gp.Equation(m, "e", domain=[i]) >>> e.gamsRepr() 'e(i)'
- generateRecords(density: int | float | list | None = None, func: dict[str, Callable] | None = None, seed: int | None = None) None#
Automatically generates records for the symbol based on a specified density and optional attribute-specific generation functions.
By default, the “level” attribute is populated with uniformly distributed floats between 0.0 and 1.0, while all other attributes (e.g., marginal, lower, upper) are initialized to the symbol’s default record limits.
- Parameters:
- densityint | float | list | None, optional
The target density for the generated records on the interval [0, 1]. * A single numeric value applies to the overall cartesian product. * A list applies specific densities to each domain independently. * Defaults to 1.0.
- funcdict[str, Callable] | None, optional
A dictionary mapping attribute strings (e.g., “level”, “marginal”) to custom callables. If provided, each callable is invoked as func(seed=seed, size=(num_records,)). Attributes not specified in the dictionary fallback to the symbol’s defaults.
- seedint | None, optional
A random seed for reproducibility during domain sampling and value generation.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> v = gp.Variable(m, name="v", type="positive", domain=[i]) >>> v.generateRecords(seed=42) >>> e = gp.Equation(m, name="e", domain=i) >>> e.generateRecords(seed=42)
- getDeclaration() str[source]#
Returns the GAMS declaration statement for this Equation.
(e.g., ‘Equation e(i);’).
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=['i1','i2']) >>> a = gp.Parameter(m, "a", [i], records=[['i1',1],['i2',2]]) >>> v = gp.Variable(m, "v", domain=[i]) >>> e = gp.Equation(m, "e", domain=[i]) >>> e.getDeclaration() 'Equation e(i) / /;'
- getDefinition() str[source]#
Returns the GAMS definition statement (algebra) for this Equation.
(e.g., ‘e(i) .. x(i) =l= 5;’).
- Returns:
- str
- Raises:
- ValidationError
If the equation algebra has not been defined.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=['i1','i2']) >>> a = gp.Parameter(m, "a", [i], records=[['i1',1],['i2',2]]) >>> v = gp.Variable(m, "v", domain=[i]) >>> e = gp.Equation(m, "e", domain=[i]) >>> e[i] = a[i] <= v[i] >>> e.getDefinition() 'e(i) .. a(i) =l= v(i);'
- getEquationListing(n: int | None = None, filters: list[list[str]] | None = None, infeasibility_threshold: float | None = None) str[source]#
Returns the equation listing (log output) from the last solve.
This requires the model to have been solved with the equation_listing_limit option enabled.
- Parameters:
- nint, optional
Maximum number of equations to return.
- filterslist[list[str]], optional
Filters to select specific elements for the listing. The list size must match the equation’s dimension.
- infeasibility_threshold: float, optional
If set, only returns equations with infeasibility values greater than this threshold.
- Returns:
- str
The text listing of the generated equations.
- Raises:
- ValidationError
If the model was not solved with equation_listing_limit.
- ValidationError
In case the length of the filters is different than the dimension of the equation.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, records=["item1", "item2"]) >>> v = gp.Variable(m, domain=i) >>> z = gp.Variable(m) >>> e = gp.Equation(m, domain=i) >>> e[i] = v[i] * z >= 5 >>> model = gp.Model(m, "test", equations=[e], problem="NLP", sense="MIN", objective=z) >>> summary = model.solve(options=gp.Options(equation_listing_limit=10)) >>> print(e.getEquationListing()) e(item1).. (0)*v(item1) + (0)*z =G= 5 ; (LHS = 0, INFES = 5 ****) e(item2).. (0)*v(item2) + (0)*z =G= 5 ; (LHS = 0, INFES = 5 ****)
- getMaxAbsValue(columns: str | list[str] | None = None) float#
- getMaxValue(columns: str | list[str] | None = None) float#
- getMeanValue(columns: str | list[str] | None = None) float#
- getMinValue(columns: str | list[str] | None = None) float#
- getSparsity() float#
Calculates the sparsity of the symbol’s records.
Sparsity is defined as 1 - (number_of_records / maximum_possible_records), where the maximum possible records is the product of the number of records in each of the symbol’s domain sets. A sparsity of 1.0 means the symbol has no records (completely empty), while 0.0 means the symbol is fully dense.
- Returns:
- float
The sparsity of the symbol (between 0.0 and 1.0). Returns float(“nan”) if the symbol is a scalar, has a relaxed domain (e.g., [“*”]), or if any of its domain sets have no records.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> j = gp.Set(m, name="j", records=["X", "Y", "Z"]) >>> p = gp.Parameter(m, name="p", domain=[i, j], records=[("A", "X", 10)]) >>> p.getSparsity() 0.8333333333333334
- latexRepr() str[source]#
Generates a LaTeX representation of the equation definition.
- Returns:
- str
LaTeX string defining the equation.
- Raises:
- ValidationError
If the equation has not been defined (assigned).
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=['i1']) >>> v = gp.Variable(m, "v", domain=[i]) >>> e = gp.Equation(m, "e", domain=[i]) >>> e[i] = v[i] <= 10 >>> print(e.latexRepr()) $ v_{i} \leq 10\hfill \forall i $
- pivot(index: str | list | None = None, columns: str | list | None = None, value: str | None = None, fill_value: int | float | str | None = None) pd.DataFrame#
Pivots the specified attribute of the symbol records into a two-dimensional pandas DataFrame. This isolates a specific attribute column (e.g., “level” or “marginal”) and pivots the data across the specified index and column domains.
- Parameters:
- indexstr | list | None, optional
Column(s) to use for the new frame’s index. If None, defaults to all domain labels except the last dimension.
- columnsstr | list | None, optional
Column(s) to use for the new frame’s columns. If None, defaults to the last dimension of the domain labels.
- valuestr | None, optional
The specific symbol attribute to pivot (e.g., “level”, “marginal”, “lower”, “upper”, “scale”). If None, defaults to “level”.
- fill_valueint | float | str | None, optional
Value used to fill missing data created by the pivot operation. Defaults to 0.0.
- Returns:
- pd.DataFrame
The pivoted DataFrame representing the specified attribute.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> j = gp.Set(m, name="j", records=["X", "Y"]) >>> v = gp.Variable(m, name="v", domain=[i, j]) >>> # Assuming variable has been solved/populated >>> df_level = v.pivot(value="level")
- setRecords(records: VarEquRecordsType | None, uels_on_axes: bool = False) None[source]#
Sets the records (data) of the Equation.
This allows manually setting the level, marginal, bounds, and scale for an equation.
- Parameters:
- recordsSequence | np.ndarray | int | float | pd.DataFrame | pd.Series | dict
The data to load (e.g., list, numpy array, DataFrame).
- uels_on_axesbool, optional
If True, assumes domain elements are in the axes of the DataFrame. Default is False.
Examples
>>> from gamspy import Container, Variable, Equation >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq.setRecords(5) >>> eq.toValue() np.float64(5.0)
- toDense(column: str = 'level') ndarray | None#
Convert column to a dense numpy.array format
- Parameters:
- columnstr, optional
The column to convert, by default “level”
- Returns:
- np.ndarray, optional
A column to a dense numpy.array format
- toDict(columns: str | list[str] | None = None, orient: str | None = None) dict#
Converts the records of a non-scalar symbol to a Python dictionary.
- Parameters:
- columnsstr | list[str] | None, optional
The attribute column(s) to extract (e.g., “level”, “marginal”). If None, defaults to “level”.
- orientstr | None, optional
The format of the dictionary. Options are: - “natural” (default): Maps domain elements to values. If multiple columns are requested,
the value becomes a dictionary mapping attributes to their values.
“columns”: Returns a dictionary of columns, mimicking a pandas DataFrame structure.
- Returns:
- dict
A dictionary containing the requested symbol attributes. Returns an empty dict if there are no records.
- Raises:
- TypeError
If the symbol is a scalar, or if an invalid column name is provided.
Examples
>>> import gamspy as gp >>> import numpy as np >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> v = gp.Variable(m, name="v", domain=[i]) >>> v.setRecords(np.array([10.0, 20.0])) >>> v.toDict(columns="level") {'A': 10.0, 'B': 20.0}
- toList(columns: str | None = None) list#
Converts the specified attributes of the symbol records to a Python list.
- Parameters:
- columnsstr | list[str] | None, optional
The attribute column(s) to include (e.g., “level”, “marginal”, “lower”, “upper”, “scale”). If None, defaults to “level”.
- Returns:
- list
A list containing the requested attribute values. For scalar symbols, it returns a list of tuples containing the attributes. For multi-dimensional symbols, it returns a list of tuples where domain indices are followed by the requested attributes. Returns an empty list if there are no records.
Examples
>>> import gamspy as gp >>> import numpy as np >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> v = gp.Variable(m, name="v", domain=[i]) >>> v.setRecords(np.array([1.0, 2.0])) >>> v.toList(columns="level") [('A', 1.0), ('B', 2.0)]
- toSparseCoo(column: str = 'level') coo_matrix | None#
Converts a specified attribute column of the symbol’s records to a SciPy sparse COOrdinate format (coo_matrix).
This method is only available for symbols with 2 or fewer dimensions. For scalar symbols (0D), it returns a 1x1 matrix. For 1D symbols, it returns a 1xN matrix. For 2D symbols, it returns an MxN matrix.
- Parameters:
- columnstr, optional
The attribute column to convert (e.g., “level”, “marginal”, “lower”, “upper”, “scale”). Defaults to “level”.
- Returns:
- coo_matrix | None
A SciPy sparse COO matrix containing the specified attribute values. Returns None if there are no records.
- Raises:
- TypeError
If the column argument is not a string, or if it is not a valid attribute for the symbol.
- ValidationError
If the symbol has a dimension greater than 2.
Examples
>>> import gamspy as gp >>> import numpy as np >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["A", "B"]) >>> j = gp.Set(m, name="j", records=["X", "Y"]) >>> v = gp.Variable(m, name="v", domain=[i, j]) >>> v.setRecords(np.array([[1.5, 0], [0, 2.5]])) >>> sparse_mat = v.toSparseCoo(column="level") # doctest +SKIP
- toValue(column: str | None = None) float#
Returns the numerical value of a specified attribute for a scalar symbol.
- Parameters:
- columnstr | None, optional
The attribute to extract (e.g., “level”, “marginal”, “lower”, “upper”, “scale”). If None, defaults to “level”.
- Returns:
- float
The floating-point value of the requested attribute.
- Raises:
- TypeError
If the symbol is not a scalar (dimension > 0) or if an invalid column name is provided.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> v = gp.Variable(m, name="v") >>> v.l[...] = 15.5 >>> v.toValue(column="level") np.float64(15.5)
- whereMax(column: str | None = None) list[str]#
- whereMaxAbs(column: str | None = None) list[str]#
- whereMin(column: str | None = None) list[str]#
- property description: str#
Description of the symbol
- property dimension: int#
The dimension of symbol
- property domain: NormalizedDomainType#
List of domains given either as string (* for universe set) or as reference to the Set/Alias object
- property domain_labels: list[str]#
The column headings for the records DataFrame
- property domain_names: list[str]#
String version of domain names
- property domain_type#
State of the domain links
- property infeas#
The Infeasibility of the equation.
Returns the amount by which the equation violates its bounds.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.infeas >>> repr.toValue() np.float64(0.0)
- property is_scalar: bool#
Returns True if the len(self.domain) = 0
- Returns:
- bool
True if the len(self.domain) = 0
- property l#
The Level of the equation (its current value).
This corresponds to the .l suffix in GAMS. After a solve, this represents the value of the equation.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.l >>> repr.toValue() np.float64(10.0)
- property lo#
The Lower Bound of the equation.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.lo >>> repr.toValue() np.float64(-inf)
- property m#
The Marginal (dual) value of the equation.
This corresponds to the .m suffix in GAMS. It represents the shadow price or dual variable associated with the constraint.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.m >>> repr.toValue() np.float64(5.0)
- property number_records: int#
Number of records
- property range#
The Range of the equation.
This corresponds to the .range suffix in GAMS. It is used to define the sensitivity range for range constraints.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.range >>> repr.toValue() np.float64(inf)
- property records: DataFrame | None#
Returns the records (data) of the Equation as a DataFrame.
- Returns:
- DataFrame | None
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> eq.toValue() np.float64(10.0)
- property scale#
The Scale factor of the equation.
This corresponds to the .scale suffix in GAMS, used for scaling the equation to improve numerical stability during solving.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.scale >>> repr.toValue() np.float64(1.0)
- property shape: tuple#
!! processed by numpydoc !!
- property slack#
The Slack of the equation.
This corresponds to the .slack suffix. It represents the distance from the equation’s bound (e.g., RHS - LHS for <= equations).
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.slack >>> repr.toValue() np.float64(0.0)
- property slacklo#
The lower bound slack of the equation.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.slacklo >>> repr.toValue() np.float64(inf)
- property slackup#
The upper bound slack of the equation.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.slackup >>> repr.toValue() np.float64(0.0)
- property stage#
The Stage of the equation.
This corresponds to the .stage suffix in GAMS, often used in stochastic programming or model translation contexts.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.stage >>> repr.toValue() np.float64(1.0)
- property summary#
!! processed by numpydoc !!
- property synchronize: bool#
Synchronization state of the symbol. If True, the symbol data will be communicated with GAMS. Otherwise, GAMS state will not be updated.
- Returns:
- bool
- property type#
The type of the equation.
Common types include:
‘regular’ (or ‘eq’, ‘geq’, ‘leq’): Standard =e=, =g=, =l= constraints.
‘nonbinding’ (‘=n=’): No relationship implied.
‘external’ (‘=x=’): External equation.
‘boolean’ (‘=b=’): Boolean equation.
- Returns:
- str
The type of equation
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> e = gp.Equation(m, "e", type="regular") >>> e.type 'eq'
- property up#
The Upper Bound of the equation.
- Returns:
- ImplicitParameter
Examples
>>> from gamspy import Container, Parameter, Variable, Equation, Model >>> m = Container() >>> x1 = Variable(m, "x1", type="Positive") >>> x2 = Variable(m, "x2", type="Positive") >>> z = Variable(m, "z") >>> eq = Equation(m, "eq") >>> eq[...] = 2*x1 + 3*x2 <= 10 >>> solved_model = Model(m, "my_model", equations=[eq], objective=10*x1 + 6*x2, sense="MAX").solve() >>> repr = Parameter(m, "repr") >>> repr[...] = eq.up >>> repr.toValue() np.float64(10.0)
- class gamspy.EquationType(*values)[source]#
Bases:
EnumEnumeration of available equation types.
- BOOLEAN = 'boolean'#
Boolean equations.
- EXTERNAL = 'external'#
Equation is defined by external programs.
- NONBINDING = 'nonbinding'#
No relationship implied between left-hand side and right-hand side. This equation type is ideally suited for use in MCP models and in variational inequalities.
- REGULAR = 'regular'#
Regular equations with =, >= and <= sign.