Model#
- class gamspy.Model(container: Container, name: str | None = None, problem: Problem | str = Problem.LP, equations: list[Equation] = [], sense: Sense | str | None = None, objective: Variable | Expression | None = None, matches: dict | None = None, limited_variables: Iterable[Variable] | None = None)[source]#
Bases:
object
Represents a list of equations to be solved.
- Parameters:
- containerContainer
Container of the model.
- namestr, optional
Name of the model. Name is autogenerated by default.
- equationsstr | Iterable
List of Equation objects or str.
all
as a string represents all the equations specified before the creation of this model.- problemProblem or str, optional
‘LP’, ‘NLP’, ‘QCP’, ‘DNLP’, ‘MIP’, ‘RMIP’, ‘MINLP’, ‘RMINLP’, ‘MIQCP’, ‘RMIQCP’, ‘MCP’, ‘CNS’, ‘MPEC’, ‘RMPEC’, ‘EMP’, or ‘MPSGE’, by default Problem.LP.
- senseSense, optional
“MIN”, “MAX”, or “FEASIBILITY”.
- 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])
- Attributes:
infeasibility_tolerance
This option sets the tolerance for marking an equation infeasible in the equation listing.
Methods
Computes infeasabilities for all equations of the model
freeze
(modifiables[, freeze_options])Freezes all symbols except modifiable symbols.
Declaration of the Model in GAMS
Statement of the Model declaration
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
- compute_infeasibilities() dict[str, pd.DataFrame] [source]#
Computes infeasabilities for all equations of the model
- Returns:
- dict[str, pd.DataFrame]
Dictionary of infeasibilities where equation names are keys and infeasibilities are values
- property infeasibility_tolerance: float | None#
This option sets the tolerance for marking an equation infeasible in the equation listing. By default, 1.0e-13.
- Returns:
- float | None
- interrupt() None [source]#
Sends interrupt signal to the running job.
- Raises:
- ValidationError
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: ModelInstanceOptions | dict | None = None, output: io.TextIOWrapper | None = None, backend: Literal['local', 'engine', 'neos'] = 'local', client: EngineClient | 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
- clientEngineClient, NeosClient, optional
EngineClient to communicate with GAMS Engine or NEOS Client to communicate with NEOS Server
- create_log_filebool
Allows creating a log file
- Returns:
- DataFrame, optional
- Raises:
- ValidationError
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”
- getDeclaration() str [source]#
Declaration of the Model in GAMS
- Returns:
- str
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]) >>> my_model.getDeclaration() 'Model my_model / e /;'
- class gamspy.ModelStatus(value)[source]#
Bases:
Enum
An 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#
- class gamspy.SolveStatus(value)[source]#
Bases:
Enum
An enumeration for solve status types
- NormalCompletion = 1#
- IterationInterrupt = 2#
- ResourceInterrupt = 3#
- TerminatedBySolver = 4#
- EvaluationInterrupt = 5#
- CapabilityError = 6#
- LicenseError = 7#
- UserInterrupt = 8#
- SetupError = 9#
- SolverError = 10#
- InternalError = 11#
- Skipped = 12#
- SystemError = 13#