gana.sets.function#

Function Set

Functions

display(*objs[, include, exclude, metadata, ...])

Display a Python object in all frontends.

make_P(inp[, index])

Make input into a parameter set (P)

make_T(inp[, index])

Make input into a theta set (T)

Classes

C(function[, leq, parent, pos, nn, category])

Represents a relationship between Parameters, Variables, or Expressions.

Elem(*values)

Type of function

F([one, two, one_type, two_type, mul, add, ...])

Provides relational operations between parameter, variable, parametric variable, or function sets (F).

FCase(*values)

function cases

I(*members[, size, start, mutable, tag, ...])

Set of index elements (X).

Math([data, url, filename, metadata])

PCase(*values)

parameter cases

cached_property(func)

product(*iterables[, repeat])

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: object

Provides 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:
  • one (P | V | F) – First element

  • two (P | V | F) – Second element

  • 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

  • array (list[P | T | V]) – List of elements in the function

  • vars (list[V]) – List of variables in the function

  • struct (tuple[Elem, Elem]) – Structure of the function

  • rels (list[str]) – Relations in the function

  • elms (list[P | V]) – Elements 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

property struct: tuple[Elem, Elem]#

Structure of the function

property elements: list[T | P | V]#

Elements in the function

property index_flat: list[tuple[I, ...] | set[tuple[I, ...]]]#

Flattens the index of the function

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

Parameters:
  • one (V | P | T | F) – First element

  • one_type (Elem | None) – Type of one

  • two (V | P | T | F) – Second element

  • two_type (Elem | None) – Type of two

  • add (bool) – Addition operation

  • sub (bool) – Subtraction operation

  • mul (bool) – Multiplication operation

  • div (bool) – Division operation

Returns:

Consistent elements and their types along with relation flags

Return type:

tuple[V | P | T | F, Elem, V | P | T | F, Elem, bool, bool, bool | bool]

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

birth_functions()[source]#

Creates a vector of functions Accordingly sets n sets self._, self.n

update_variables()[source]#

Updates the variables in the function

give_name()[source]#

Gives a name to the function

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

Parameters:
  • one – First element

  • one_type – Type of V | P | T | F

  • two – Second element

  • two_type – Type of V | P | T | F

Returns:

Updated elements

Return type:

tuple[V | P | T | F, V | P | T | F]

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

latex() str[source]#

LaTeX Equation

show(descriptive: bool = False)[source]#

Display the function

Parameters:

descriptive (bool, optional) – Whether to show all birthed functions, defaults to False

property longname[source]#

Gives a longer more descriptive name for the function

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]