Parameter#

class gamspy.Parameter(container: Container, name: str | None = None, domain: list[Set | Alias | str] | Set | Alias | str | None = None, records: Any | None = None, domain_forwarding: bool = False, description: str = '', uels_on_axes: bool = False, is_miro_input: bool = False, is_miro_output: bool = False, is_miro_table: bool = False)[source]#

Bases: Parameter, Operable, Symbol

Represents a parameter symbol in GAMS. https://www.gams.com/latest/docs/UG_DataEntry.html#UG_DataEntry_Parameters

Parameters:
containerContainer

Container of the parameter.

namestr, optional

Name of the parameter. Name is autogenerated by default.

domainlist[Set | Alias | str] | Set | Alias | str, optional

Domain of the parameter.

recordsint | float | pd.DataFrame | np.ndarray | list, optional

Records of the parameter.

domain_forwardingbool, optional

Whether the parameter forwards the domain. See: https://gams.com/latest/docs/UG_SetDefinition.html#UG_SetDefinition_ImplicitSetDefinition

descriptionstr, optional

Description of the parameter.

uels_on_axesbool

Assume that symbol domain information is contained in the axes of the given records.

is_miro_inputbool

Whether the symbol is a GAMS MIRO input symbol. See: https://gams.com/miro/tutorial.html

is_miro_outputbool

Whether the symbol is a GAMS MIRO output symbol. See: https://gams.com/miro/tutorial.html

Attributes:
container

Container of the symbol

description

Description of the symbol

dimension

The dimension of symbol

domain

List of domains given either as string (* for universe set) or as reference to the Set/Alias object

domain_forwarding

A boolean indicating whether domain forwarding is enabled

domain_labels

The column headings for the records DataFrame

domain_names

String version of domain names

domain_type

State of the domain links

is_scalar

Returns True if the len(self.domain) = 0

modified

Flag that identifies if the symbol has been modified

name

Name of symbol

number_records

Number of records

records

Records of the Parameter

shape

Returns a tuple describing the array dimensions if records were converted with .toDense()

summary

Returns a dict of only the metadata

Methods

countEps([columns])

Counts total number of SpecialValues.EPS across columns

countNA([columns])

Counts total number of SpecialValues.NA across columns

countNegInf([columns])

Counts total number of SpecialValues.NegInf across columns

countPosInf([columns])

Counts total number of SpecialValues.PosInf across columns

countUndef([columns])

Counts total number of SpecialValues.Undef across columns

dropDefaults()

Main convenience method to remove zero values from the symbol's records.

dropEps()

Main convenience method to remove epsilon values from the symbol's records.

dropMissing()

Main convenience method to remove missing values from the symbol's records.

dropNA()

Main convenience method to remove NA (Not Available) values from the symbol's records.

dropUndef()

Main convenience method to remove undefined values from the symbol's records.

dropZeros()

Main convenience method to remove zero values from the symbol's records.

equals(other[, check_uels, check_meta_data, ...])

Used to compare the symbol to another symbol

findEps([column])

Find positions of SpecialValues.EPS in value column

findNA([column])

Find positions of SpecialValues.NA in value column

findNegInf([column])

Find positions of SpecialValues.NegInf in value column

findPosInf([column])

Find positions of SpecialValues.PosInf in value column

findSpecialValues(values[, column])

Find positions of specified values in records columns

findUndef([column])

Find positions of SpecialValues.Undef in value column

gamsRepr()

Representation of this Parameter in GAMS language.

generateRecords([density, func, seed])

Convenience method to set standard pandas.DataFrame formatted records given domain set information.

getDeclaration()

Declaration of the Parameter in GAMS

getMaxAbsValue([columns])

Get the maximum absolute value across chosen columns

getMaxValue([columns])

Get the maximum value across chosen columns

getMeanValue([columns])

Get the mean value across chosen columns

getMinValue([columns])

Get the minimum value across chosen columns

getSparsity()

Get the sparsity of the symbol w.r.t the cardinality

isValid([verbose, force])

Checks if the symbol is in a valid format

pivot([index, columns, fill_value])

Convenience function to pivot records into a new shape (only symbols with >1D can be pivoted)

setRecords(records[, uels_on_axes])

Main convenience method to set standard pandas.DataFrame formatted records.

toDense()

Convert symbol to a dense numpy.array format

toDict([orient])

convenience method to return symbol records as a python dictionary, orient can take values natural or columns and will control the shape of the dict.

toList()

Convenience method to return symbol records as a python list

toSparseCoo()

Convert symbol to a sparse COOrdinate numpy.array format

toValue()

Convenience method to return symbol records as a python float.

whereMax([column])

Find the domain entry of records with a maximum value (return first instance only)

whereMaxAbs([column])

Find the domain entry of records with a maximum absolute value (return first instance only)

whereMin([column])

Find the domain entry of records with a minimum value (return first instance only)

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=['i1','i2'])
>>> a = gp.Parameter(m, "a", [i], records=[['i1',1],['i2',2]])
property description#

Description of the symbol

property modified#

Flag that identifies if the symbol has been modified

property records#

Records of the Parameter

Returns:
DataFrame

Examples

>>> import gamspy as gp
>>> import numpy as np
>>> m = gp.Container()
>>> i = gp.Set(m, name="i", records=["seattle", "san-diego"])
>>> d = gp.Parameter(m, name="d", domain=[i])
>>> d.setRecords(np.array([10, 25]))
>>> d.records.values.tolist()
[['seattle', 10.0], ['san-diego', 25.0]]
setRecords(records: Any, uels_on_axes: bool = False) None[source]#

Main convenience method to set standard pandas.DataFrame formatted records. If uels_on_axes=True setRecords will assume that all domain information is contained in the axes of the pandas object – data will be flattened (if necessary).

Parameters:
recordsAny
uels_on_axesbool, optional

Examples

>>> import gamspy as gp
>>> import numpy as np
>>> m = gp.Container()
>>> i = gp.Set(m, name="i")
>>> i.setRecords(["seattle", "san-diego"])
>>> i.records.values.tolist()
[['seattle', ''], ['san-diego', '']]
gamsRepr() str[source]#

Representation of this Parameter in GAMS language.

Returns:
str

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=['i1','i2'])
>>> d = gp.Parameter(m, "d", domain=i)
>>> d.gamsRepr()
'd(i)'
property container#

Container of the symbol

countEps(columns: str | List[str] | None = None) int#

Counts total number of SpecialValues.EPS across columns

Parameters:
columnsstr | List[str], optional

Columns to count special values in, by default None

Returns:
Total number of SpecialValues.EPS across columns
countNA(columns: str | List[str] | None = None) int#

Counts total number of SpecialValues.NA across columns

Parameters:
columnsstr | List[str], optional

Columns to count special values in, by default None

Returns:
Total number of SpecialValues.NA across columns
countNegInf(columns: str | List[str] | None = None) int#

Counts total number of SpecialValues.NegInf across columns

Parameters:
columnsstr | List[str], optional

Columns to count special values in, by default None

Returns:
Total number of SpecialValues.NegInf across columns
countPosInf(columns: str | List[str] | None = None) int#

Counts total number of SpecialValues.PosInf across columns

Parameters:
columnsstr | List[str], optional

Columns to count special values in, by default None

Returns:
Total number of SpecialValues.PosInf across columns
countUndef(columns: str | List[str] | None = None) int#

Counts total number of SpecialValues.Undef across columns

Parameters:
columnsstr | List[str], optional

Columns to count special values in, by default None

Returns:
Total number of SpecialValues.Undef across columns
property dimension#

The dimension of symbol

property domain#

List of domains given either as string (* for universe set) or as reference to the Set/Alias object

property domain_forwarding#

A boolean indicating whether domain forwarding is enabled

property domain_labels#

The column headings for the records DataFrame

property domain_names#

String version of domain names

property domain_type#

State of the domain links

dropDefaults() None[source]#

Main convenience method to remove zero values from the symbol’s records.

dropEps() None[source]#

Main convenience method to remove epsilon values from the symbol’s records.

dropMissing() None[source]#

Main convenience method to remove missing values from the symbol’s records.

dropNA() None[source]#

Main convenience method to remove NA (Not Available) values from the symbol’s records.

dropUndef() None[source]#

Main convenience method to remove undefined values from the symbol’s records.

dropZeros() None[source]#

Main convenience method to remove zero values from the symbol’s records.

equals(other: Parameter, check_uels: bool = True, check_meta_data: bool = True, rtol: int | float | None = None, atol: int | float | None = None, verbose: bool = False) bool#

Used to compare the symbol to another symbol

Parameters:
otherParameter

Other Symbol to compare with

check_uelsbool, optional

If True, check both used and unused UELs and confirm same order, otherwise only check used UELs in data and do not check UEL order. by default True

check_meta_databool, optional

If True, check that symbol name and description are the same, otherwise skip. by default True

rtolint | float, optional

relative tolerance, by default None

atolint | float, optional

absolute tolerance, by default None

verbosebool, optional

If True, will return an exception from the asserter describing the nature of the difference. by default False

Returns:
bool

True if symbols are equal, False otherwise

findEps(column: str | None = None) DataFrame#

Find positions of SpecialValues.EPS in value column

Parameters:
columnstr, optional

Column to find the special values in, by default None

Returns:
pd.DataFrame

Dataframe containing special values

findNA(column: str | None = None) DataFrame#

Find positions of SpecialValues.NA in value column

Parameters:
columnstr, optional

Column to find the special values in, by default None

Returns:
pd.DataFrame

Dataframe containing special values

findNegInf(column: str | None = None) DataFrame#

Find positions of SpecialValues.NegInf in value column

Parameters:
columnstr, optional

Column to find the special values in, by default None

Returns:
pd.DataFrame

Dataframe containing special values

findPosInf(column: str | None = None) DataFrame#

Find positions of SpecialValues.PosInf in value column

Parameters:
columnstr, optional

Column to find the special values in, by default None

Returns:
pd.DataFrame

Dataframe containing special values

findSpecialValues(values: float | List[float], column: str | None = None) DataFrame#

Find positions of specified values in records columns

Parameters:
valuesfloat | List[float]

Values to look for

columnstr, optional

Column to find the special values in, by default None

Returns:
pd.DataFrame

Dataframe containing special values

findUndef(column: str | None = None) DataFrame#

Find positions of SpecialValues.Undef in value column

Parameters:
columnstr, optional

Column to find the special values in, by default None

Returns:
pd.DataFrame

Dataframe containing special values

generateRecords(density: int | float | list | None = None, func: Callable | None = None, seed: int | None = None) None#

Convenience method to set standard pandas.DataFrame formatted records given domain set information. Will generate records with the Cartesian product of all domain sets.

Parameters:
densityint | float | list, optional

Takes any value on the interval [0,1]. If density is <1 then randomly selected records will be removed. density will accept a list of length dimension – allows users to specify a density per symbol dimension, by default None

funcCallable, optional

Functions to generate the records, by default None; numpy.random.uniform(0,1)

seedint, optional

Random number state can be set with seed argument, by default None

getDeclaration() str[source]#

Declaration of the Parameter in GAMS

Returns:
str

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=['i1','i2'])
>>> a = gp.Parameter(m, "a", [i], records=[['i1',1],['i2',2]])
>>> a.getDeclaration()
'Parameter a(i);'
getMaxAbsValue(columns: str | List[str] | None = None) float#

Get the maximum absolute value across chosen columns

Parameters:
columnsstr | List[str], optional

Columns to find maximum absolute values in, by default None

Returns:
float

Maximum absolute value

getMaxValue(columns: str | List[str] | None = None) float#

Get the maximum value across chosen columns

Parameters:
columnsstr | List[str], optional

Columns to find maximum values in, by default None

Returns:
float

Maximum value

getMeanValue(columns: str | List[str] | None = None) float#

Get the mean value across chosen columns

Parameters:
columnsstr | List[str], optional

Columns to find mean values in, by default None

Returns:
float

Mean value

getMinValue(columns: str | List[str] | None = None) float#

Get the minimum value across chosen columns

Parameters:
columnsstr | List[str], optional

Columns to find minimum values in, by default None

Returns:
float

Minimum value

getSparsity() float#

Get the sparsity of the symbol w.r.t the cardinality

Returns:
float

Sparsity of the symbol w.r.t the cardinality

isValid(verbose: bool = False, force: bool = False) bool#

Checks if the symbol is in a valid format

Parameters:
verbosebool, optional

Throw exceptions if verbose=True, by default False

forcebool, optional

Recheck a symbol if force=True, by default False

Returns:
bool

True if a symbol is in valid format, False otherwise (throws exceptions if verbose=True)

property is_scalar: bool#

Returns True if the len(self.domain) = 0

Returns:
bool

True if the len(self.domain) = 0

property name#

Name of symbol

property number_records#

Number of records

pivot(index: str | list | None = None, columns: str | list | None = None, fill_value: int | float | str | None = None) DataFrame#

Convenience function to pivot records into a new shape (only symbols with >1D can be pivoted)

Parameters:
indexstr | list, optional

If index is None then it is set to dimensions [0..dimension-1], by default None

columnsstr | list, optional

If columns is None then it is set to the last dimension, by default None

fill_valueint | float | str, optional

Missing values in the pivot will take the value provided by fill_value, by default None

Returns:
DataFrame

Pivoted records dataframe

property shape: tuple#

Returns a tuple describing the array dimensions if records were converted with .toDense()

Returns:
tuple

A tuple describing the records dimensions

property summary: dict#

Returns a dict of only the metadata

Returns:
dict

Outputs a dict of only the metadata

toDense() ndarray | None[source]#

Convert symbol to a dense numpy.array format

Returns:
ndarray | None

A numpy array with symbol records, None if no records were assigned

Examples

>>> m = gt.Container()
>>> j = gt.Set(m, "j", records=["new-york", "chicago", "topeka"])
>>> s = gt.Parameter(m, "s", [j], records=np.array([3,4,5]))
>>> print(s.toDense())
[3. 4. 5.]
toDict(orient: str | None = None) dict | None[source]#

convenience method to return symbol records as a python dictionary, orient can take values natural or columns and will control the shape of the dict. Must use orient=”columns” if attempting to set symbol records with setRecords

Parameters:
orientstr, optional

Takes ‘natural’ or ‘columns’, by default None which sets it to ‘natural’.

Returns:
dict | None

A dictionary with symbol records, None if no records were assigned

Examples

>>> m = gt.Container()
>>> j = gt.Set(m, "j", records=["new-york", "chicago", "topeka"])
>>> s = gt.Parameter(m, "s", [j], records=np.array([3,4,5]))
>>> print(s.toDict(orient="natural"))
{'new-york': 3.0, 'chicago': 4.0, 'topeka': 5.0}
>>> print(s.toDict(orient="columns"))
{'j': {0: 'new-york', 1: 'chicago', 2: 'topeka'}, 'value': {0: 3.0, 1: 4.0, 2: 5.0}}
toList() list | None[source]#

Convenience method to return symbol records as a python list

Returns:
list | None

A list of symbol records, None if no records were assigned

toSparseCoo() coo_matrix | None[source]#

Convert symbol to a sparse COOrdinate numpy.array format

Returns:
coo_matrix | None
toValue() float | None[source]#

Convenience method to return symbol records as a python float. Only possible with scalar symbols.

Returns:
float | None

Scalar’s record, None if no record was assigned

whereMax(column: str | None = None) List[str]#

Find the domain entry of records with a maximum value (return first instance only)

Parameters:
columnstr, optional

Columns to find maximum values in, by default None

Returns:
List[str]

List of symbol names where maximum values exist

whereMaxAbs(column: str | None = None) List[str]#

Find the domain entry of records with a maximum absolute value (return first instance only)

Parameters:
columnstr, optional

Columns to find maximum absolute values in, by default None

Returns:
List[str]

List of symbol names where maximum absolute values exist

whereMin(column: str | None = None) List[str]#

Find the domain entry of records with a minimum value (return first instance only)

Parameters:
columnstr, optional

Columns to find minimum values in, by default None

Returns:
List[str]

List of symbol names where minimum values exist