Loading...
Searching...
No Matches

The GamsWorkspace is the base class of the gams.control API. More...

Public Member Functions

 get_eps (self)
 Reset value to be stored in and read from GamsDatabase for Epsilon.
 
 __init__ (self, working_directory=None, system_directory=None, debug=DebugLevel.KeepFilesOnError)
 constructor
 
 gamslib (self, model)
 Retrieves model from GAMS Model Library.
 
 testlib (self, model)
 Retrieves model from GAMS Test Library.
 
 emplib (self, model)
 Retrieves model from Extended Math Programming Library.
 
 datalib (self, model)
 Retrieves model from GAMS Data Utilities Library.
 
 finlib (self, model)
 Retrieves model from Practical Financial Optimization Library.
 
 noalib (self, model)
 Retrieves model from Nonlinear Optimization Applications Using the GAMS Technology Library.
 
 psoptlib (self, model)
 Retrieves model from Power System Optimization Modelling Library.
 
 apilib (self, model)
 Retrieves model from GAMS API Library.
 
 add_database (self, database_name=None, source_database=None, in_model_name=None)
 Database creation.
 
 add_database_from_gdx (self, gdx_file_name, database_name=None, in_model_name=None)
 Database creation from an existing GDX file.
 
 add_job_from_string (self, gams_source, checkpoint=None, job_name=None)
 Create GamsJob from string model source.
 
 add_job_from_file (self, file_name, checkpoint=None, job_name=None)
 Create GamsJob from model file.
 
 add_job_from_gamslib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Model Library.
 
 add_job_from_testlib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Test Library.
 
 add_job_from_apilib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS API Library.
 
 add_job_from_emplib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Extended Math Programming Library.
 
 add_job_from_datalib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Data Utilities Library.
 
 add_job_from_finlib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from Practical Financial Optimization Library.
 
 add_job_from_noalib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Non-linear Optimization Applications Library.
 
 add_job_from_psoptlib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from Power System Optimization Modelling Library.
 
 add_options (self, gams_options_from=None, opt_file=None)
 Create GamsOptions.
 
 add_checkpoint (self, checkpoint_name=None)
 Create GamsCheckpoint.
 

Public Attributes

str scratch_file_prefix = "_gams_py_"
 A string used to prefix automatically generated files.
 

Static Public Attributes

 api_version = __version__
 GAMS API version.
 
 api_major_rel_number = int(__version__.split(".")[0])
 GAMS API Major Release Number.
 
 api_minor_rel_number = int(__version__.split(".")[1])
 GAMS API Minor Release Number.
 
 api_gold_rel_number = int(__version__.split(".")[2])
 GAMS API GOLD Release Number.
 

Protected Member Functions

 _add_database_from_gmd (self, gmd_handle, database_name=None, in_model_name=None)
 

Properties

 my_eps = property(get_eps, set_eps)
 Get value to be stored in and read from GamsDatabase for Epsilon.
 
 working_directory = property(get_working_directory)
 GAMS working directory, anchor for all file-based operations.
 
 system_directory = property(get_system_directory)
 GAMS system directory.
 
 version = property(get_version)
 GAMS Version used.
 
 major_rel_number = property(get_major_rel_number)
 GAMS Major Release Number.
 
 minor_rel_number = property(get_minor_rel_number)
 GAMS Minor Release Number.
 
 gold_rel_number = property(get_gold_rel_number)
 GAMS GOLD Release Number.
 

Detailed Description

The GamsWorkspace is the base class of the gams.control API.

Most objects of the control API (e.g. GamsDatabase and GamsJob) should be created by an "add" method of GamsWorkspace instead of using the constructors.

Unless a GAMS system directory is specified during construction of GamsWorkspace, GamsWorkspace determines the location of the GAMS installation automatically. This is a source of potential problems if more than one GAMS installation exist on the machine.

Furthermore, a working directory (the anchor into the file system) can be provided when constructing the GamsWorkspace instance. All file based operation inside a GAMS model should be relative to this location (e.g. $GDXIN and $include). There are options to add input search paths (e.g. IDir) and output path (e.g. PutDir) to specify other file system locations. If no working directory is supplied, GamsWorkspace creates a temporary folder and on instance destruction removes this temporary folder.

In a typical Python application a single instance of GamsWorkspace will suffice, since the class is thread-safe.

Working with different GAMS Versions on one Machine

When creating a new instance of GamsWorkspace, one way of defining the GAMS system directory is setting the system_directory parameter of the constructor accordingly. If it is not set, it is tried to be defined automatically (see Control for details). However, this can be tricky if there is more than one version of GAMS installed on a machine and especially if there are different applications running with different GAMS versions.

On Windows, the automatic identification relies on information left in the Windows registry by the GAMS installer. Hence the system directory of the last GAMS installation will be found in this automatic identification step. One way of resetting the information in the registry is running the executable "findthisgams.exe" from the directory that should be detected automatically. While this can be done from the outside of the application it is not much more convenient than the system_directory argument in the GamsWorkspace constructor.

If one has a very structured way of organizing the GAMS installations (e.g. following the GAMS default installation location) one can use GamsWorkspace.api_version to point to the best matching GAMS system directory:

sysdir = "C:\\GAMS\\" + GamsWorkspace.api_version[:2]
ws = GamsWorkspace(system_directory=sysdir)

This avoids the automatic identification of the GAMS system directory but might be the most convenient solution for systems running multiple applications using different versions of the GAMS Python API together with different versions of GAMS.

Constructor & Destructor Documentation

◆ __init__()

gams.control.workspace.GamsWorkspace.__init__ ( self,
working_directory = None,
system_directory = None,
debug = DebugLevel.KeepFilesOnError )

constructor

Parameters
working_directoryGAMS working directory, anchor for all file-based operations (determined automatically if omitted, in user's temporary folder)
system_directoryGAMS system directory (determined automatically if omitted)
debugDebug Flag (default: DebugLevel.KeepFilesOnError)

Member Function Documentation

◆ _add_database_from_gmd()

gams.control.workspace.GamsWorkspace._add_database_from_gmd ( self,
gmd_handle,
database_name = None,
in_model_name = None )
protected
   @brief Database creation from an existing GMD handle. This will alter setting for special values and debug settings using the functions: gmdSetDebug and gmdSetSpecialValues. Meant for internal use only
   @param gmd_handle The already created and initialised GMD handle
   @param database_name Identifier of GamsDatabase (determined automatically if omitted)
   @param in_model_name GAMS string constant that is used to access this database
   @return Instance of type GamsDatabase

◆ add_checkpoint()

gams.control.workspace.GamsWorkspace.add_checkpoint ( self,
checkpoint_name = None )

Create GamsCheckpoint.

Parameters
checkpoint_namecheckpoint_name Identifier of GamsCheckpoint or filename for existing checkpoint (determined automatically if omitted)
Returns
GamsCheckpoint instance

◆ add_database()

gams.control.workspace.GamsWorkspace.add_database ( self,
database_name = None,
source_database = None,
in_model_name = None )

Database creation.

Parameters
database_nameIdentifier of GamsDatabase (determined automatically if omitted)
source_databaseSource GamsDatabase to initialize Database from (empty Database if omitted)
in_model_nameGAMS string constant that is used to access this database
Returns
Instance of type GamsDatabase

◆ add_database_from_gdx()

gams.control.workspace.GamsWorkspace.add_database_from_gdx ( self,
gdx_file_name,
database_name = None,
in_model_name = None )

Database creation from an existing GDX file.

Parameters
gdx_file_nameGDX File to initialize Database from
database_nameIdentifier of GamsDatabase (determined automatically if omitted)
in_model_nameGAMS string constant that is used to access this database
Returns
Instance of type GamsDatabase

◆ add_job_from_apilib()

gams.control.workspace.GamsWorkspace.add_job_from_apilib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from GAMS API Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_datalib()

gams.control.workspace.GamsWorkspace.add_job_from_datalib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from GAMS Data Utilities Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_emplib()

gams.control.workspace.GamsWorkspace.add_job_from_emplib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from GAMS Extended Math Programming Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_file()

gams.control.workspace.GamsWorkspace.add_job_from_file ( self,
file_name,
checkpoint = None,
job_name = None )

Create GamsJob from model file.

Parameters
file_nameGAMS source file name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_finlib()

gams.control.workspace.GamsWorkspace.add_job_from_finlib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from Practical Financial Optimization Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_gamslib()

gams.control.workspace.GamsWorkspace.add_job_from_gamslib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from GAMS Model Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_noalib()

gams.control.workspace.GamsWorkspace.add_job_from_noalib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from GAMS Non-linear Optimization Applications Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_psoptlib()

gams.control.workspace.GamsWorkspace.add_job_from_psoptlib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from Power System Optimization Modelling Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_string()

gams.control.workspace.GamsWorkspace.add_job_from_string ( self,
gams_source,
checkpoint = None,
job_name = None )

Create GamsJob from string model source.

Parameters
gams_sourceGAMS model as string
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_job_from_testlib()

gams.control.workspace.GamsWorkspace.add_job_from_testlib ( self,
model,
checkpoint = None,
job_name = None )

Create GamsJob from model from GAMS Test Library.

Parameters
modelmodel name
checkpointGamsCheckpoint to initialize GamsJob from
job_nameJob name (determined automatically if omitted)
Returns
GamsJob instance

◆ add_options()

gams.control.workspace.GamsWorkspace.add_options ( self,
gams_options_from = None,
opt_file = None )

Create GamsOptions.

Parameters
gams_options_fromGamsOptions used to initialize the new object
opt_fileParameter file used to initialize the new object
Returns
GamsOptions instance

◆ apilib()

gams.control.workspace.GamsWorkspace.apilib ( self,
model )

Retrieves model from GAMS API Library.

Parameters
modelModel name

◆ datalib()

gams.control.workspace.GamsWorkspace.datalib ( self,
model )

Retrieves model from GAMS Data Utilities Library.

Parameters
modelModel name

◆ emplib()

gams.control.workspace.GamsWorkspace.emplib ( self,
model )

Retrieves model from Extended Math Programming Library.

Parameters
modelModel name

◆ finlib()

gams.control.workspace.GamsWorkspace.finlib ( self,
model )

Retrieves model from Practical Financial Optimization Library.

Parameters
modelModel name

◆ gamslib()

gams.control.workspace.GamsWorkspace.gamslib ( self,
model )

Retrieves model from GAMS Model Library.

Parameters
modelModel name

◆ noalib()

gams.control.workspace.GamsWorkspace.noalib ( self,
model )

Retrieves model from Nonlinear Optimization Applications Using the GAMS Technology Library.

Parameters
modelModel name

◆ psoptlib()

gams.control.workspace.GamsWorkspace.psoptlib ( self,
model )

Retrieves model from Power System Optimization Modelling Library.

Parameters
modelModel name

◆ testlib()

gams.control.workspace.GamsWorkspace.testlib ( self,
model )

Retrieves model from GAMS Test Library.

Parameters
modelModel name