gamspy#
- Container
- Set
- Alias
- UNIVERSE
- Universe Alias
- Parameter
- Variable
- Equation
- Model
- GUSSScenarioDict
- Problem
- Sense
- Options
- FreezeOptions
- ConvertOptions
- Expression
- Domain
- Number
- Sum
- Product
- Smax
- Smin
- Sand
- Sor
- Ord
- Card
- Loop
- For
- If
- ElseIf
- Else
- EngineClient
- NeosClient
- math
- formulations
- utils
- SpecialValues
- exceptions
- gamspy.sparse(rhs: Expression | Operation | Condition | MathOp | Parameter | ImplicitParameter | ImplicitSet | Card | Ord | Number | int | float | bool | str) SparseAssignment[source]#
Marks the right-hand side of an assignment as a sparse assignment.
A sparse assignment (
$=in GAMS) assigns to a tuple of the left-hand side only if the right-hand side evaluates to a non-zero value. Tuples for which the right-hand side is zero are left untouched. Therefore,p[i] = sparse(rhs)is equivalent top[i].where[rhs] = rhsbut the right-hand side is evaluated only once. This can be significantly faster if the right-hand side is expensive to evaluate, e.g. aSum.Note that the right-hand side is always evaluated, so unlike a condition on the left-hand side, a sparse assignment does not protect against undefined arithmetic such as a division by zero.
- Parameters:
- rhsExpression | Operation | Condition | MathOp | Parameter | ImplicitParameter | ImplicitSet | Card | Ord | Number | int | float | bool | str
Right-hand side of the assignment.
- Returns:
- SparseAssignment
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=["i1", "i2", "i3"]) >>> d1 = gp.Parameter(m, "d1", domain=i, records=[("i1", 1), ("i2", 1), ("i3", 1)]) >>> d2 = gp.Parameter(m, "d2", domain=i, records=[("i2", -2)]) >>> d3 = gp.Parameter(m, "d3", domain=i) >>> d3[i] = d1[i] >>> d3[i] = gp.sparse(d2[i]) >>> d3.records.values.tolist() [['i1', 1.0], ['i2', -2.0], ['i3', 1.0]] >>> d3.getAssignment() 'd3(i) $= d2(i);'
- gamspy.set_options(options: dict[Literal['GAMS_SYSDIR', 'LICENSE_PATH', 'VALIDATION', 'DOMAIN_VALIDATION', 'SOLVER_VALIDATION', 'SOLVER_OPTION_VALIDATION', 'MAP_SPECIAL_VALUES', 'ASSUME_VARIABLE_SUFFIX', 'USE_PY_VAR_NAME', 'DROP_DOMAIN_VIOLATIONS', 'ALLOW_AMBIGUOUS_EQUATIONS', 'STRICT_POWER_OPERATOR'], Any]) None[source]#
Sets the given configuration options.
- Parameters:
- optionsdict[str, Any]
Option names mapped to their new values.
- Raises:
- ValidationError
In case the given options are not in dict type or in case an option name is not recognized.
Examples
>>> import gamspy as gp >>> gp.set_options({"DOMAIN_VALIDATION": 1})
- gamspy.get_option(name: str) Any[source]#
Returns the requested option.
- Parameters:
- namestr
Option name.
- Returns:
- Any
The value of the option.
- Raises:
- KeyError
In case the option is not set.
Examples
>>> import gamspy as gp >>> gp.set_options({"DOMAIN_VALIDATION": 0}) >>> gp.get_option("DOMAIN_VALIDATION") 0 >>> gp.set_options({"DOMAIN_VALIDATION": 1})
- gamspy.serialize(container: Container, path: str) None[source]#
Serializes the given Container into a zip file.
- Parameters:
- containerContainer
Container to be serialized.
- pathstr
Path to the zip file.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=range(3)) >>> gp.serialize(m, "serialization_path.zip")
- gamspy.deserialize(path: str) Container[source]#
Deserializes the given zip file into a Container.
- Parameters:
- pathstr
Path to the zip file.
- Returns:
- Container
Deserialized Container.
- Raises:
- ValidationError
In case the given path is not a zip file.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.Set(m, "i", records=["i1"]) >>> m.serialize("model.zip") >>> m2 = gp.deserialize("model.zip") >>> print(m2["i"].toList()) ['i1']