Universe Alias#
- class gamspy.UniverseAlias(container: Container | None = None, name: str = 'universe')[source]#
Bases:
UniverseAlias
Represents a UniverseAlias symbol in GAMS.
- Parameters:
- containerContainer
- namestr
- Attributes:
alias_with
Returns aliased object
container
Container of the symbol
description
Always ‘Aliased with *’ for universe alias
dimension
Always 1 for universe alias
domain
Always [“*”] for universe alias
domain_labels
Always [“uni”] for universe alias
domain_names
Always [“*”] for universe alias
domain_type
Always none for universe alias
is_singleton
Whether a symbol is a singleton set
modified
Flag that identifies if the symbol has been modified
name
Name of symbol
number_records
Number of symbol records (i.e., returns len(records) if not NAN)
records
The main symbol records
summary
Returns 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
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)
- 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#
Number of symbol records (i.e., returns len(records) if not NAN)
- Returns:
- int
Number of symbol records
- property records: DataFrame | None#
The main symbol records
- Returns:
- DataFrame | None
Records dataframe if there are records, otherwise None.
- property summary: dict#
Returns a dict of only the metadata
- Returns:
- dict
Outputs a dict of only the metadata