The GamsWorkspace is the base class of the gams.control API. More...
Public Member Functions | |
def | get_eps (self) |
Reset value to be stored in and read from GamsDatabase for Epsilon. | |
def | __init__ (self, working_directory=None, system_directory=None, debug=DebugLevel.KeepFilesOnError) |
constructor | |
def | gamslib (self, model) |
Retrieves model from GAMS Model Library. | |
def | testlib (self, model) |
Retrieves model from GAMS Test Library. | |
def | emplib (self, model) |
Retrieves model from Extended Math Programming Library. | |
def | datalib (self, model) |
Retrieves model from GAMS Data Utilities Library. | |
def | finlib (self, model) |
Retrieves model from Practical Financial Optimization Library. | |
def | noalib (self, model) |
Retrieves model from Nonlinear Optimization Applications Using the GAMS Technology Library. | |
def | psoptlib (self, model) |
Retrieves model from Power System Optimization Modelling Library. | |
def | apilib (self, model) |
Retrieves model from GAMS API Library. | |
def | add_database (self, database_name=None, source_database=None, in_model_name=None) |
Database creation. | |
def | add_database_from_gdx (self, gdx_file_name, database_name=None, in_model_name=None) |
Database creation from an existing GDX file. | |
def | add_job_from_string (self, gams_source, checkpoint=None, job_name=None) |
Create GamsJob from string model source. | |
def | add_job_from_file (self, file_name, checkpoint=None, job_name=None) |
Create GamsJob from model file. | |
def | add_job_from_gamslib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from GAMS Model Library. | |
def | add_job_from_testlib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from GAMS Test Library. | |
def | add_job_from_apilib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from GAMS API Library. | |
def | add_job_from_emplib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from GAMS Extended Math Programming Library. | |
def | add_job_from_datalib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from GAMS Data Utilities Library. | |
def | add_job_from_finlib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from Practical Financial Optimization Library. | |
def | add_job_from_noalib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from GAMS Non-linear Optimization Applications Library. | |
def | add_job_from_psoptlib (self, model, checkpoint=None, job_name=None) |
Create GamsJob from model from Power System Optimization Modelling Library. | |
def | add_options (self, gams_options_from=None, opt_file=None) |
Create GamsOptions. | |
def | add_checkpoint (self, checkpoint_name=None) |
Create GamsCheckpoint. | |
Public Attributes | |
scratch_file_prefix | |
A string used to prefix automatically generated files. | |
Static Public Attributes | |
GamsOptions | api_version = GamsOptions._api_ver |
GAMS API version. | |
int | api_major_rel_number = int(GamsOptions._api_ver.split(".")[0]) |
GAMS API Major Release Number. | |
int | api_minor_rel_number = int(GamsOptions._api_ver.split(".")[1]) |
GAMS API Minor Release Number. | |
int | api_gold_rel_number = int(GamsOptions._api_ver.split(".")[2]) |
GAMS API GOLD Release Number. | |
Protected Member Functions | |
def | _add_database_from_gmd (self, gmd_handle, database_name=None, in_model_name=None) |
Properties | |
property | my_eps = property(get_eps, set_eps) |
Get value to be stored in and read from GamsDatabase for Epsilon. | |
property | working_directory = property(get_working_directory) |
GAMS working directory, anchor for all file-based operations. | |
property | system_directory = property(get_system_directory) |
GAMS system directory. | |
property | version = property(get_version) |
GAMS Version used. | |
property | major_rel_number = property(get_major_rel_number) |
GAMS Major Release Number. | |
property | minor_rel_number = property(get_minor_rel_number) |
GAMS Minor Release Number. | |
property | 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:
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__()
def gams.control.workspace.GamsWorkspace.__init__ | ( | self, | |
working_directory = None , |
|||
system_directory = None , |
|||
debug = DebugLevel.KeepFilesOnError |
|||
) |
constructor
- Parameters
-
working_directory GAMS working directory, anchor for all file-based operations (determined automatically if omitted, in user's temporary folder) system_directory GAMS system directory (determined automatically if omitted) debug Debug Flag (default: DebugLevel.KeepFilesOnError)
Member Function Documentation
◆ _add_database_from_gmd()
|
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()
def gams.control.workspace.GamsWorkspace.add_checkpoint | ( | self, | |
checkpoint_name = None |
|||
) |
Create GamsCheckpoint.
- Parameters
-
checkpoint_name checkpoint_name Identifier of GamsCheckpoint or filename for existing checkpoint (determined automatically if omitted)
- Returns
- GamsCheckpoint instance
◆ add_database()
def gams.control.workspace.GamsWorkspace.add_database | ( | self, | |
database_name = None , |
|||
source_database = None , |
|||
in_model_name = None |
|||
) |
Database creation.
- Parameters
-
database_name Identifier of GamsDatabase (determined automatically if omitted) source_database Source GamsDatabase to initialize Database from (empty Database if omitted) in_model_name GAMS string constant that is used to access this database
- Returns
- Instance of type GamsDatabase
◆ add_database_from_gdx()
def 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_name GDX File to initialize Database from database_name Identifier of GamsDatabase (determined automatically if omitted) in_model_name GAMS string constant that is used to access this database
- Returns
- Instance of type GamsDatabase
◆ add_job_from_apilib()
def gams.control.workspace.GamsWorkspace.add_job_from_apilib | ( | self, | |
model, | |||
checkpoint = None , |
|||
job_name = None |
|||
) |
Create GamsJob from model from GAMS API Library.
- Parameters
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_datalib()
def 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
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_emplib()
def 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
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_file()
def gams.control.workspace.GamsWorkspace.add_job_from_file | ( | self, | |
file_name, | |||
checkpoint = None , |
|||
job_name = None |
|||
) |
Create GamsJob from model file.
- Parameters
-
file_name GAMS source file name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_finlib()
def 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
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_gamslib()
def gams.control.workspace.GamsWorkspace.add_job_from_gamslib | ( | self, | |
model, | |||
checkpoint = None , |
|||
job_name = None |
|||
) |
Create GamsJob from model from GAMS Model Library.
- Parameters
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_noalib()
def 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
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_psoptlib()
def 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
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_string()
def gams.control.workspace.GamsWorkspace.add_job_from_string | ( | self, | |
gams_source, | |||
checkpoint = None , |
|||
job_name = None |
|||
) |
Create GamsJob from string model source.
- Parameters
-
gams_source GAMS model as string checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_job_from_testlib()
def gams.control.workspace.GamsWorkspace.add_job_from_testlib | ( | self, | |
model, | |||
checkpoint = None , |
|||
job_name = None |
|||
) |
Create GamsJob from model from GAMS Test Library.
- Parameters
-
model model name checkpoint GamsCheckpoint to initialize GamsJob from job_name Job name (determined automatically if omitted)
- Returns
- GamsJob instance
◆ add_options()
def gams.control.workspace.GamsWorkspace.add_options | ( | self, | |
gams_options_from = None , |
|||
opt_file = None |
|||
) |
Create GamsOptions.
- Parameters
-
gams_options_from GamsOptions used to initialize the new object opt_file Parameter file used to initialize the new object
- Returns
- GamsOptions instance
◆ apilib()
def gams.control.workspace.GamsWorkspace.apilib | ( | self, | |
model | |||
) |
Retrieves model from GAMS API Library.
- Parameters
-
model Model name
◆ datalib()
def gams.control.workspace.GamsWorkspace.datalib | ( | self, | |
model | |||
) |
Retrieves model from GAMS Data Utilities Library.
- Parameters
-
model Model name
◆ emplib()
def gams.control.workspace.GamsWorkspace.emplib | ( | self, | |
model | |||
) |
Retrieves model from Extended Math Programming Library.
- Parameters
-
model Model name
◆ finlib()
def gams.control.workspace.GamsWorkspace.finlib | ( | self, | |
model | |||
) |
Retrieves model from Practical Financial Optimization Library.
- Parameters
-
model Model name
◆ gamslib()
def gams.control.workspace.GamsWorkspace.gamslib | ( | self, | |
model | |||
) |
Retrieves model from GAMS Model Library.
- Parameters
-
model Model name
◆ noalib()
def gams.control.workspace.GamsWorkspace.noalib | ( | self, | |
model | |||
) |
Retrieves model from Nonlinear Optimization Applications Using the GAMS Technology Library.
- Parameters
-
model Model name
◆ psoptlib()
def gams.control.workspace.GamsWorkspace.psoptlib | ( | self, | |
model | |||
) |
Retrieves model from Power System Optimization Modelling Library.
- Parameters
-
model Model name
◆ testlib()
def gams.control.workspace.GamsWorkspace.testlib | ( | self, | |
model | |||
) |
Retrieves model from GAMS Test Library.
- Parameters
-
model Model name