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: Any | 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:
Equation,SymbolRepresents 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.
- recordsAny, 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
default_recordsDefault records of an equation
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_forwardingA boolean indicating whether domain forwarding is enabled
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.
modifiedFlag that identifies if the symbol has been modified
nameName of symbol
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.
shapeReturns a tuple describing the array dimensions if records were converted with .toDense()
slackThe Slack of the equation.
slackloThe lower bound slack of the equation.
slackupThe upper bound slack of the equation.
stageThe Stage of the equation.
summarySummary of the symbol
synchronizeSynchronization state of the symbol.
typeThe type of the equation.
upThe Upper Bound of the equation.
Methods
Computes infeasibilities of the equation.
countEps([columns])Counts total number of SpecialValues.EPS across columns
countNA([columns])Counts total number of SpecialValues.NA across columns
countNegInf([columns])Counts total number of SpecialValues.NegInf across columns
countPosInf([columns])Counts total number of SpecialValues.PosInf across columns
countUndef([columns])Counts total number of SpecialValues.Undef across columns
Drop records that are set to GAMS default records (check .default_records property for values)
dropEps()Drop records from the symbol that are GAMS EPS (zero 0.0 records will be retained)
Drop records from the symbol that are NaN (includes both NA and Undef special values)
dropNA()Drop records from the symbol that are GAMS NA
Drop records from the symbol that are GAMS Undef
equals(other[, columns, check_uels, ...])Used to compare the symbol to another symbol
findEps([column])Find positions of SpecialValues.EPS in value column
findNA([column])Find positions of SpecialValues.NA in value column
findNegInf([column])Find positions of SpecialValues.NegInf in value column
findPosInf([column])Find positions of SpecialValues.PosInf in value column
findSpecialValues(values[, column])Find positions of specified values in records columns
findUndef([column])Find positions of SpecialValues.Undef in value column
gamsRepr()Returns the string representation of this Equation in the GAMS language.
generateRecords([density, func, seed])Convenience method to set standard pandas.DataFrame formatted records given domain set information.
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.
getMaxAbsValue([columns])Get the maximum absolute value across chosen columns
getMaxValue([columns])Get the maximum value across chosen columns
getMeanValue([columns])Get the mean value across chosen columns
getMinValue([columns])Get the minimum value across chosen columns
Get the sparsity of the symbol w.r.t the cardinality
isValid([verbose, force])Checks if the symbol is in a valid format
Generates a LaTeX representation of the equation definition.
pivot([index, columns, value, fill_value])Convenience function to pivot records into a new shape (only symbols with >1D can be pivoted)
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])Convenience method to return symbol records as a Python dictionary
toList([columns])Convenience method to return symbol records as a Python list
toSparseCoo([column])Convert column to a sparse COOrdinate numpy.array format
toValue([column])Convenience method to return symbol records as a Python float.
whereMax([column])Find the domain entry of records with a maximum value (return first instance only)
whereMaxAbs([column])Find the domain entry of records with a maximum absolute value (return first instance only)
whereMin([column])Find the domain entry of records with a minimum value (return first instance only)
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() pd.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#
Counts total number of SpecialValues.EPS across columns
- Parameters:
- columnsstr | list[str], optional
Columns to count special values in, by default None
- Returns:
- Total number of SpecialValues.EPS across columns
- countNA(columns: str | list[str] | None = None) int#
Counts total number of SpecialValues.NA across columns
- Parameters:
- columnsstr | list[str], optional
Columns to count special values in, by default None
- Returns:
- Total number of SpecialValues.NA across columns
- countNegInf(columns: str | list[str] | None = None) int#
Counts total number of SpecialValues.NegInf across columns
- Parameters:
- columnsstr | list[str], optional
Columns to count special values in, by default None
- Returns:
- Total number of SpecialValues.NegInf across columns
- countPosInf(columns: str | list[str] | None = None) int#
Counts total number of SpecialValues.PosInf across columns
- Parameters:
- columnsstr | list[str], optional
Columns to count special values in, by default None
- Returns:
- Total number of SpecialValues.PosInf across columns
- countUndef(columns: str | list[str] | None = None) int#
Counts total number of SpecialValues.Undef across columns
- Parameters:
- columnsstr | list[str], optional
Columns to count special values in, by default None
- Returns:
- Total number of SpecialValues.Undef across columns
- dropDefaults() None#
Drop records that are set to GAMS default records (check .default_records property for values)
- dropEps() None#
Drop records from the symbol that are GAMS EPS (zero 0.0 records will be retained)
- dropMissing() None#
Drop records from the symbol that are NaN (includes both NA and Undef special values)
- dropNA() None#
Drop records from the symbol that are GAMS NA
- dropUndef() None#
Drop records from the symbol that are GAMS Undef
- equals(other: Variable, columns: str = None, check_uels: bool = True, check_meta_data: bool = True, rtol: int | float | None = None, atol: int | float | None = None, verbose: bool = False) bool#
Used to compare the symbol to another symbol
- Parameters:
- otherVariable
_description_
- columnsstr, optional
allows the user to numerically compare only specified variable attributes, by default None; compare all
- check_uelsbool, optional
If True, check both used and unused UELs and confirm same order, otherwise only check used UELs in data and do not check UEL order. by default True
- check_meta_databool, optional
If True, check that symbol name and description are the same, otherwise skip. by default True
- rtolint | float, optional
relative tolerance, by default None
- atolint | float, optional
absolute tolerance, by default None
- verbosebool, optional
If True, will return an exception from the asserter describing the nature of the difference. by default False
- Returns:
- bool
True if symbols are equal, False otherwise
- findEps(column: str | None = None) pd.DataFrame#
Find positions of SpecialValues.EPS in value column
- Parameters:
- columnstr, optional
Column to find the special values in, by default None
- Returns:
- pd.DataFrame
Dataframe containing special values
- findNA(column: str | None = None) pd.DataFrame#
Find positions of SpecialValues.NA in value column
- Parameters:
- columnstr, optional
Column to find the special values in, by default None
- Returns:
- pd.DataFrame
Dataframe containing special values
- findNegInf(column: str | None = None) pd.DataFrame#
Find positions of SpecialValues.NegInf in value column
- Parameters:
- columnstr, optional
Column to find the special values in, by default None
- Returns:
- pd.DataFrame
Dataframe containing special values
- findPosInf(column: str | None = None) pd.DataFrame#
Find positions of SpecialValues.PosInf in value column
- Parameters:
- columnstr, optional
Column to find the special values in, by default None
- Returns:
- pd.DataFrame
Dataframe containing special values
- findSpecialValues(values: float | list[float], column: str | None = None) pd.DataFrame#
Find positions of specified values in records columns
- Parameters:
- valuesfloat | list[float]
Values to look for
- columnstr, optional
Column to find the special values in, by default None
- Returns:
- pd.DataFrame
Dataframe containing special values
- findUndef(column: str | None = None) pd.DataFrame#
Find positions of SpecialValues.Undef in value column
- Parameters:
- columnstr, optional
Column to find the special values in, by default None
- Returns:
- pd.DataFrame
Dataframe containing special values
- 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: Callable | None = None, seed: int | None = None) None#
Convenience method to set standard pandas.DataFrame formatted records given domain set information. Will generate records with the Cartesian product of all domain sets.
- Parameters:
- densityint | float | list, optional
Takes any value on the interval [0,1]. If density is <1 then randomly selected records will be removed. density will accept a list of length dimension – allows users to specify a density per symbol dimension, by default None
- funcCallable, optional
Functions to generate the records, by default None; numpy.random.uniform(0,1)
- seedint, optional
Random number state can be set with seed argument, by default None
- 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#
Get the maximum absolute value across chosen columns
- Parameters:
- columnsstr | list[str], optional
Columns to find maximum absolute values in, by default None
- Returns:
- float
Maximum absolute value
- getMaxValue(columns: str | list[str] | None = None) float#
Get the maximum value across chosen columns
- Parameters:
- columnsstr | list[str], optional
Columns to find maximum values in, by default None
- Returns:
- float
Maximum value
- getMeanValue(columns: str | list[str] | None = None) float#
Get the mean value across chosen columns
- Parameters:
- columnsstr | list[str], optional
Columns to find mean values in, by default None
- Returns:
- float
Mean value
- getMinValue(columns: str | list[str] | None = None) float#
Get the minimum value across chosen columns
- Parameters:
- columnsstr | list[str], optional
Columns to find minimum values in, by default None
- Returns:
- float
Minimum value
- getSparsity() float#
Get the sparsity of the symbol w.r.t the cardinality
- Returns:
- float
Sparsity of the symbol w.r.t the cardinality
- isValid(verbose: bool = False, force: bool = False) bool#
Checks if the symbol is in a valid format
- Parameters:
- verbosebool, optional
Throw exceptions if verbose=True, by default False
- forcebool, optional
Recheck a symbol if force=True, by default False
- Returns:
- bool
True if a symbol is in valid format, False otherwise (throws exceptions if verbose=True)
- 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#
Convenience function to pivot records into a new shape (only symbols with >1D can be pivoted)
- Parameters:
- indexstr | list, optional
If index is None then it is set to dimensions [0..dimension-1], by default None
- columnsstr | list, optional
If columns is None then it is set to the last dimension, by default None
- valuestr, optional
If value is None then the level values will be pivoted, by default None
- fill_valueint | float | str, optional
Missing values in the pivot will take the value provided by fill_value, by default None
- Returns:
- DataFrame
Pivoted records dataframe
- setRecords(records: Any, 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:
- recordsAny
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') np.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 | None = None, orient: str | None = None) dict#
Convenience method to return symbol records as a Python dictionary
- Parameters:
- columnsstr, optional
Controls which attributes to include in the dict, by default None
- orientstr, optional
Orient can take values natural or columns and will control the shape of the dict. Must use orient=”columns” if attempting to set symbol records with setRecords, by default None
- Returns:
- dict
Records as a Python dictionary
- toList(columns: str | None = None) list#
Convenience method to return symbol records as a Python list
- Parameters:
- columnsstr, optional
Controls which attributes to include in the list, by default None
- Returns:
- list
Records as a Python list
- toSparseCoo(column: str = 'level') coo_matrix | None#
Convert column to a sparse COOrdinate numpy.array format
- Parameters:
- columnstr, optional
The column to convert, by default “level”
- Returns:
- coo_matrix, optional
A column in coo_matrix format
- toValue(column: str | None = None) float#
Convenience method to return symbol records as a Python float. Only possible with scalar symbols
- Parameters:
- columnstr, optional
Attribute can be specified with column argument, by default None
- Returns:
- float
Value of the symbol
- whereMax(column: str | None = None) list[str]#
Find the domain entry of records with a maximum value (return first instance only)
- Parameters:
- columnstr, optional
Columns to find maximum values in, by default None
- Returns:
- list[str]
List of symbol names where maximum values exist
- whereMaxAbs(column: str | None = None) list[str]#
Find the domain entry of records with a maximum absolute value (return first instance only)
- Parameters:
- columnstr, optional
Columns to find maximum absolute values in, by default None
- Returns:
- list[str]
List of symbol names where maximum absolute values exist
- whereMin(column: str | None = None) list[str]#
Find the domain entry of records with a minimum value (return first instance only)
- Parameters:
- columnstr, optional
Columns to find minimum values in, by default None
- Returns:
- list[str]
List of symbol names where minimum values exist
- property container#
Container of the symbol
- property default_records#
Default records of an equation
- property description#
Description of the symbol
- property dimension#
The dimension of symbol
- property domain#
List of domains given either as string (* for universe set) or as reference to the Set/Alias object
- property domain_forwarding#
A boolean indicating whether domain forwarding is enabled
- property domain_labels#
The column headings for the records DataFrame
- property domain_names#
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 modified#
Flag that identifies if the symbol has been modified
- property name#
Name of symbol
- property number_records#
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: pd.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#
Returns a tuple describing the array dimensions if records were converted with .toDense()
- Returns:
- tuple
A tuple describing the records dimensions
- 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#
Summary of the symbol
- 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
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=["i1"]) >>> i.synchronize = False >>> i["i2"] = True >>> i.records.uni.tolist() ['i1'] >>> i.synchronize = True >>> i.records.uni.tolist() ['i1', 'i2']
- 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.