gana.sets.function#
Function Set
Functions
|
Display a Python object in all frontends. |
|
Make input into a parameter set (P) |
|
Make input into a theta set (T) |
Classes
|
Represents a relationship between Parameters, Variables, or Expressions. |
|
Type of function |
|
Provides relational operations between parameter, variable, parametric variable, or function sets (F). |
|
function cases |
|
Set of index elements (X). |
|
|
|
parameter cases |
|
|
|
Cartesian product of input iterables. |
- class F(one: int | float | list[int | float] | P | V | T | Self | None = None, two: int | float | list[int | float] | P | V | T | Self | None = None, one_type: Elem | None = None, two_type: Elem | None = None, mul: bool = False, add: bool = False, sub: bool = False, div: bool = False, parent: Self | None = None, pos: int | None = None, index: tuple[I] | list[tuple[I]] | None = None, case: FCase | None = None, consistent: bool = False, issumhow: tuple[V, I, int] | None = None)[source]#
Bases:
objectProvides relational operations between parameter, variable, parametric variable, or function sets (F).
This class is not intended to be declared by the user directly. It is constructed based on operations between parameter sets (P or list of numbers or number), variable sets (V), or function sets (F).
- Parameters:
one (int | float | list[int | float] | P | V | T | F, optional) – First element.
two (int | float | list[int | float] | P | V | T | F, optional) – Second element. Defaults to 0.
one_type (Elem, optional) – Type of one. Defaults to None.
two_type (Elem, optional) – Type of two. Defaults to None.
mul (bool, optional) – Multiplication operation. Defaults to False.
add (bool, optional) – Addition operation. Defaults to False.
sub (bool, optional) – Subtraction operation. Defaults to False.
div (bool, optional) – Division operation. Defaults to False.
consistent (bool, optional) – If the function is already consistent, saves computation. Defaults to False.
case (FCase, optional) – Special function case. Defaults to None.
parent (Self, optional) – Parent function. Defaults to None.
pos (int, optional) – Position of the function in the parent. Defaults to None.
index (tuple[I] | list[tuple[I]] | None, optional) – Index of the function. Defaults to None.
issumhow (tuple[V, I, int], optional) – If the function is a summation, provides variable, index, and position. Defaults to None.
process (bool, optional) – Whether to make matrices. Defaults to True.
- Variables:
mul (bool) – Multiplication flag
add (bool) – Addition flag
sub (bool) – Subtraction flag
div (bool) – Division flag
rel (str) – Relation symbol
name (str) – Name of the function, describing the operation
index (I) – Index of the function set
vars (list[V]) – List of variables in the function
rels (list[str]) – Relations in the function
isnegvar (bool) – If the function is \(-1 \cdot v\) (negation)
isconsistent (bool) – If the function is consistent
n (int) – Number id, set by the program
pname (str) – Name set by the program
elmo (dict[int, list[P | V | T | str]]) – Elements with relation (also a sesame street character)
- Raises:
ValueError – If none of mul, add, sub, or div is True
- property matrix: dict#
Matrix as dict
- Returns:
dict: Dictionary mapping of positions to values in A matrix
- categorize(category: str)[source]#
Categorizes the function
- Parameters:
category (str) – Category name
- make_consistent(one: V | P | T | Self, one_type: Elem | None, two: V | P | T | Self, two_type: Elem | None, add: bool, sub: bool, mul: bool, div: bool) tuple[V | P | T | Self, Elem, V | P | T | Self, Elem, bool, bool, bool | bool][source]#
Sets the function in a consistent form Also makes parameters from int, float, or list[int|float] if needed sets self.isconsistent to True
- handle_mismatch()[source]#
Determine mismatch between indices
Stretches the shorter index to match the longer one.
This comes up in writing ‘multiscale’ constraints, e.g.:
\[\mathbf{production}_{operation, hour} - \mathrm{Parameter}_{operation, time} \cdot \mathbf{capacity}_{operation, year} \leq \theta\]One of the indices needs to be divisible by the other if there is a mismatch
Sets
self.mis,self._one,self._two,self.one,self.two
- handle_index()[source]#
Handles (compounds if needed) the index Irrespective of the operation being done
The index of a function is index.one + index.two Not in the mathematical sense! i am just using the __add__ dunder for I to create a function index basically. This is of the form
\[f(\mathbf{x}, \mathbf{y})_{i,j} = \mathbf{x}_{i} + \mathbf{y}_{j}\]sets
self.index
- handle_rel(mul: bool, add: bool, sub: bool, div: bool, ignore: bool = False)[source]#
Handles the relation of the function sets self.args, self.mul, self.add, self.sub, self.div, self.rel
- make_args()[source]#
Makes the arguments for the function This is convenient for passing to the birther functions and while making calls to the function. Also sets self.args
- types(one: V | P | T | Self, one_type: Elem | None, two: V | P | T | Self, two_type: Elem | None) tuple[V | P | T | Self, V | P | T | Self][source]#
Sets whether there is an element of a particular type in one and two
- generate_matrices()[source]#
Generates matrices A - variable coefficients P - position of continuous variables in program Y - position of integer variables in program Z - position of parametric variables in program B - rhs parameters F - pvar (theta) parameters
The general form is:
\[\mathrm{A} \cdot \mathbf{V} = \mathrm{B} + \mathrm{F} \cdot \theta\]sets
self.A,self.P,self.Y,self.Z,self.B,self.F
- show(descriptive: bool = False)[source]#
Display the function
- Parameters:
descriptive (bool, optional) – Whether to show all birthed functions, defaults to False
- solution(n_sol: int = 0) float | int | list[float | int][source]#
Evaluate the value of the function.
- Parameters:
n_sol (int, optional) – The solution number to evaluate, defaults to 0
- Returns:
Evaluated function value(s)
- Return type:
float | int | list[float | int]
- eval(*values: float | int | list[float | int]) float | int | list[float | int][source]#
Evaluate the function for given parameter values.
- Parameters:
values (float | int | list[float | int]) – Values for variables in the order they feature in the function
- Returns:
Evaluated function value(s)
- Return type:
float | int | list[float | int]