Model#
- class gamspy.Model(container: Container, name: str, problem: str, equations: list[Equation] = [], sense: Literal['MIN', 'MAX', 'FEASIBILITY'] | None = None, objective: Variable | Expression | None = None, matches: dict | None = None, limited_variables: Iterable[Variable] | None = None)[source]#
Bases:
objectRepresents a list of equations to be solved.
- Parameters:
- containerContainer
The container that the model belongs to
- namestr
Name of the model
- equationsstr | Iterable
List of Equation objects or str.
allas a string represents all the equations specified before the creation of this model- problemstr
Problem type (e.g. LP, NLP etc.)
- sense“MIN”, “MAX”, or “FEASIBILITY”, optional
Minimize or maximize
- objectiveVariable | Expression, optional
Objective variable to minimize or maximize or objective itself
- limited_variablesIterable, optional
Allows limiting the domain of variables used in a model.
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> v = gp.Variable(m, "v") >>> e = gp.Equation(m, "e", definition= v == 5) >>> my_model = gp.Model(m, "my_model", "LP", [e])
Methods
freeze(modifiables[, freeze_options])Freezes all symbols except modifiable symbols.
Statement of the Model definition
Sends interrupt signal to the running job.
solve([solver, options, solver_options, ...])Generates the gams string, writes it to a file and runs it
unfreeze()Unfreezes all symbols
- interrupt() None[source]#
Sends interrupt signal to the running job.
- Raises:
- GamspyException
If the job is not initialized
- freeze(modifiables: list[Parameter | ImplicitParameter], freeze_options: dict | None = None) None[source]#
Freezes all symbols except modifiable symbols.
- Parameters:
- modifiablesList[Parameter | ImplicitParameter]
- freeze_optionsdict, optional
- solve(solver: str | None = None, options: Options | None = None, solver_options: dict | None = None, model_instance_options: dict | None = None, output: io.TextIOWrapper | None = None, backend: Literal['local', 'engine', 'neos'] = 'local', engine_config: EngineConfig | None = None, neos_client: NeosClient | None = None, create_log_file: bool = False) pd.DataFrame | None[source]#
Generates the gams string, writes it to a file and runs it
- Parameters:
- solverstr, optional
Solver name
- optionsOptions, optional
GAMS options
- solver_optionsdict, optional
Solver options
- model_instance_optionsoptional
Model instance options
- outputTextIOWrapper, optional
Output redirection target
- backendstr, optional
Backend to run on
- engine_configEngineConfig, optional
GAMS Engine configuration
- neos_clientNeosClient, optional
NEOS Client to communicate with NEOS Server
- create_log_filebool
Allows creating a log file
- Raises:
- GamspyException
In case engine_config is not provided for engine backend or neos_client is not provided for neos backend.
- ValueError
In case problem is not in possible problem types
- ValueError
In case sense is different than “MIN” or “MAX”
- class gamspy.ModelStatus(value)[source]#
Bases:
EnumAn enumeration for model status types
- OptimalGlobal = 1#
- OptimalLocal = 2#
- Unbounded = 3#
- InfeasibleGlobal = 4#
- InfeasibleLocal = 5#
- InfeasibleIntermed = 6#
- Feasible = 7#
- Integer = 8#
- NonIntegerIntermed = 9#
- IntegerInfeasible = 10#
- LicenseError = 11#
- ErrorUnknown = 12#
- ErrorNoSolution = 13#
- NoSolutionReturned = 14#
- SolvedUnique = 15#
- Solved = 16#
- SolvedSingular = 17#
- UnboundedNoSolution = 18#
- InfeasibleNoSolution = 19#