The GamsWorkspace is the base class of the gams namespace. More...

Inherits object.

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.Off)
 constructor More...
 
def gamslib (self, model)
 Retrieves model from GAMS Model Library. More...
 
def testlib (self, model)
 Retrieves model from GAMS Test Library. More...
 
def emplib (self, model)
 Retrieves model from Extended Math Programming Library. More...
 
def datalib (self, model)
 Retrieves model from GAMS Data Utilities Library. More...
 
def finlib (self, model)
 Retrieves model from Practical Financial Optimization Library. More...
 
def noalib (self, model)
 Retrieves model from Nonlinear Optimization Applications Using the GAMS Technology Library. More...
 
def apilib (self, model)
 Retrieves model from GAMS API Library. More...
 
def add_database (self, database_name=None, source_database=None, in_model_name=None)
 Database creation. More...
 
def add_database_from_gdx (self, gdx_file_name, database_name=None, in_model_name=None)
 Database creation from an existing GDX file. More...
 
def add_job_from_string (self, gams_source, checkpoint=None, job_name=None)
 Create GamsJob from string model source. More...
 
def add_job_from_file (self, file_name, checkpoint=None, job_name=None)
 Create GamsJob from model file. More...
 
def add_job_from_gamslib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Model Library. More...
 
def add_job_from_testlib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Test Library. More...
 
def add_job_from_apilib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS API Library. More...
 
def add_job_from_emplib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Extended Math Programming Library. More...
 
def add_job_from_datalib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Data Utilities Library. More...
 
def add_job_from_finlib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from Practical Financial Optimization Library. More...
 
def add_job_from_noalib (self, model, checkpoint=None, job_name=None)
 Create GamsJob from model from GAMS Non-linear Optimization Applications Library. More...
 
def add_options (self, gams_options_from=None, opt_file=None)
 Create GamsOptions. More...
 
def add_checkpoint (self, checkpoint_name=None)
 Create GamsCheckpoint. More...
 

Public Attributes

 scratch_file_prefix
 A string used to prefix automatically generated files.
 

Static Public Attributes

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

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 namespace.

Most objects of the gams namespace (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 Getting started for details). However, this can be tricky if there is more than on 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 construct from the GAMS assembly information enough information to point to the best matching GAMS system directory:

version = GamsWorkspace.api_version
is_64bit = sys.maxsize > 2**32
if is_64bit:
sysdir = "c:\\GAMS\\win64\\" + version[0:4]
else:
sysdir = "c:\\GAMS\\win32\\" + version[0:4]
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__()

def gams.workspace.GamsWorkspace.__init__ (   self,
  working_directory = None,
  system_directory = None,
  debug = DebugLevel.Off 
)

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

Member Function Documentation

◆ add_checkpoint()

def gams.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()

def gams.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()

def gams.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()

def gams.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()

def gams.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()

def gams.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()

def gams.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()

def gams.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()

def gams.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()

def gams.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_string()

def gams.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()

def gams.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()

def gams.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()

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

Retrieves model from GAMS API Library.

Parameters
modelModel name

◆ datalib()

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

Retrieves model from GAMS Data Utilities Library.

Parameters
modelModel name

◆ emplib()

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

Retrieves model from Extended Math Programming Library.

Parameters
modelModel name

◆ finlib()

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

Retrieves model from Practical Financial Optimization Library.

Parameters
modelModel name

◆ gamslib()

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

Retrieves model from GAMS Model Library.

Parameters
modelModel name

◆ noalib()

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

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

Parameters
modelModel name

◆ testlib()

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

Retrieves model from GAMS Test Library.

Parameters
modelModel name