Universe Alias#
- class gamspy.UniverseAlias(container: Container | None = None, name: str = 'universe')[source]#
Bases:
UniverseAliasRepresents a UniverseAlias symbol in GAMS.
- Parameters:
- containerContainer
- namestr
- Attributes:
alias_withReturns aliased object
containerContainer of the symbol
descriptionAlways ‘Aliased with *’ for universe alias
dimensionAlways 1 for universe alias
domainAlways [“*”] for universe alias
domain_labelsAlways [“uni”] for universe alias
domain_namesAlways [“*”] for universe alias
domain_typeAlways none for universe alias
is_singletonWhether a symbol is a singleton set
modifiedFlag that identifies if the symbol has been modified
nameName of symbol
number_recordsNumber of symbol records (i.e., returns len(records) if not NAN)
recordsRecords of the UniverseAlias
summaryReturns a dict of only the metadata
Methods
equals(other, check_meta_data, verbose)Used to compare the symbol to another symbol.
gamsRepr()Representation of the UniverseAlias in GAMS language.
Declaration of the UniverseAlias in GAMS
Get the sparsity of the symbol w.r.t the cardinality
getUELs([ignore_unused])Gets UELs from the Container.
isValid([verbose, force])Checks if the symbol is in a valid format
Representation of the UniverseAlias in LaTeX.
pivot(*args, **kwargs)Pivot the records DataFrame of a symbol that has a dimension more than 1.
toList()Convenience method to return symbol records as a python list
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> universe = gp.UniverseAlias(m) >>> universe.records Empty DataFrame Columns: [uni] Index: [] >>> i = gp.Set(m, "i", records=['i1', 'i2']) >>> universe.records uni 0 i1 1 i2
- equals(other: Set' | 'Alias, check_meta_data: bool = True, verbose: bool = False)[source]#
Used to compare the symbol to another symbol. If check_meta_data=True then check that symbol name and description are the same, otherwise skip. If verbose=True will return an exception from the asserter describing the nature of the difference.
- Parameters:
- otherSet or Alias
The other symbol (Set or Alias) to compare with the current alias.
- check_meta_databool, optional
If True, compare the metadata of the two symbols, by default True.
- verbosebool, optional
If True, raise an exception with an explanation of where the symbols differ if they do differ, by default False.
- Returns:
- bool
True if the two symbols are equal in the specified aspects; False if they are not equal and verbose is False.
Examples
>>> m = gt.Container() >>> i = gt.Set(m, "i", records=["seattle", "san-diego"]) >>> j = gt.Set(m, "j", records=["new-york", "chicago", "topeka"]) >>> ij = gt.UniverseAlias(m, "ij") >>> print(ij.equals(i)) False
- gamsRepr() str[source]#
Representation of the UniverseAlias in GAMS language.
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.UniverseAlias(m, name="universe") >>> i.gamsRepr() 'universe'
- getDeclaration() str[source]#
Declaration of the UniverseAlias in GAMS
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.UniverseAlias(m, name="universe") >>> i.getDeclaration() 'Alias(universe,*);'
- getSparsity() float[source]#
Get the sparsity of the symbol w.r.t the cardinality
- Returns:
- float
Always 0
- getUELs(ignore_unused: bool = False) list[str] | None[source]#
Gets UELs from the Container. Returns only UELs in the data if ignore_unused=True, otherwise return all UELs.
- Parameters:
- ignore_unusedbool, optional
Whether to get all UELs or only used ones, by default False
- Returns:
- list | None
A list of UELs if the symbol is valid, otherwise None.
- 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)
- latexRepr() str[source]#
Representation of the UniverseAlias in LaTeX.
- Returns:
- str
Examples
>>> import gamspy as gp >>> m = gp.Container() >>> i = gp.UniverseAlias(m, name="universe") >>> i.latexRepr() 'universe'
- pivot(*args, **kwargs) None[source]#
Pivot the records DataFrame of a symbol that has a dimension more than 1. Always raises a dimensionality exception.
- toList() list[str] | None[source]#
Convenience method to return symbol records as a python list
- Returns:
- list[str] | None
A list of symbol records
Examples
>>> m = gt.Container() >>> i = gt.Set(m, "i", records=["seattle", "san-diego"]) >>> j = gt.Set(m, "j", records=["new-york", "chicago", "topeka"]) >>> ij = gt.UniverseAlias(m, "ij") >>> print(ij.toList()) ['seattle', 'san-diego', 'new-york', 'chicago', 'topeka']
- property alias_with: str#
Returns aliased object
- Returns:
- str
Always “*”
- property container#
Container of the symbol
- property description: str#
Always ‘Aliased with *’ for universe alias
- Returns:
- str
Always ‘Aliased with *’
- property dimension: int#
Always 1 for universe alias
- Returns:
- int
Always 1
- property domain: list[str]#
Always [“*”] for universe alias
- Returns:
- list[str]
Always [“*”]
- property domain_labels: list[str]#
Always [“uni”] for universe alias
- Returns:
- list[str]
Always [“uni”]
- property domain_names: list[str]#
Always [“*”] for universe alias
- Returns:
- list[str]
Always [“*”]
- property domain_type: str#
Always none for universe alias
- Returns:
- str
Always ‘none’
- property is_singleton: bool#
Whether a symbol is a singleton set
- Returns:
- bool
Always False
- property modified#
Flag that identifies if the symbol has been modified
- property name#
Name of symbol
- property number_records: int | float#
Number of symbol records (i.e., returns len(records) if not NAN)
- Returns:
- int
Number of symbol records
- property records: pd.DataFrame#
Records of the UniverseAlias
- Returns:
- list[str]
Examples
>>> import gamspy as gp >>> import numpy as np >>> m = gp.Container() >>> i = gp.Set(m, name="i", records=["seattle", "san-diego"]) >>> uni = gp.UniverseAlias(m) >>> uni.records uni 0 seattle 1 san-diego
- property summary: dict#
Returns a dict of only the metadata
- Returns:
- dict
Outputs a dict of only the metadata