Model#

class gamspy.Model(container, name, problem, equations=[], sense=None, objective=None, matches=None, limited_variables=None)[source]#

Bases: object

Represents 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. all as a string represents all the equations specified before the creation of this model

problemProblem

‘LP’, ‘NLP’, ‘QCP’, ‘DNLP’, ‘MIP’, ‘RMIP’, ‘MINLP’, ‘RMINLP’, ‘MIQCP’, ‘RMIQCP’, ‘MCP’, ‘CNS’, ‘MPEC’, ‘RMPEC’, ‘EMP’, or ‘MPSGE’

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.

Parameters:
  • container (Container) –

  • name (str) –

  • problem (Problem | str) –

  • equations (list[Equation]) –

  • sense (Sense | str | None) –

  • objective (Variable | Expression | None) –

  • matches (dict | None) –

  • limited_variables (Iterable[Variable] | None) –

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.

getStatement()

Statement of the Model definition

interrupt()

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()[source]#

Sends interrupt signal to the running job.

Raises:
ValidationError

If the job is not initialized

Return type:

None

freeze(modifiables, freeze_options=None)[source]#

Freezes all symbols except modifiable symbols.

Parameters:
modifiablesList[Parameter | ImplicitParameter]
freeze_optionsdict, optional
Parameters:
  • modifiables (list[Parameter | ImplicitParameter]) –

  • freeze_options (dict | None) –

Return type:

None

unfreeze()[source]#

Unfreezes all symbols

Return type:

None

solve(solver=None, options=None, solver_options=None, model_instance_options=None, output=None, backend='local', client=None, create_log_file=False)[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

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”

Parameters:
  • solver (str | None) –

  • options (Options | None) –

  • solver_options (dict | None) –

  • model_instance_options (ModelInstanceOptions | dict | None) –

  • output (io.TextIOWrapper | None) –

  • backend (Literal['local', 'engine', 'neos']) –

  • client (EngineClient | NeosClient | None) –

  • create_log_file (bool) –

Return type:

pd.DataFrame | None

getStatement()[source]#

Statement of the Model definition

Returns:
str
Return type:

str

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#
EvalError = 5#
CapabilityError = 6#
LicenseError = 7#
UserInterrupt = 8#
SetupError = 9#
SolverError = 10#
InternalError = 11#
Skipped = 12#
SystemError = 13#