gana.block.program#
Program
Functions
|
Add dunder methods based on the fields defined in the class. |
|
Display a Python object in all frontends. |
|
Return an object to identify dataclass fields. |
|
ROUTINE: |
|
Minimize the function |
|
array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0, |
|
zeros(shape, dtype=None, order='C', *, device=None, like=None) |
|
Makes a simple plot from a solution. |
|
Takes a mpqp programming problem and solves it in a specified manner, In addition this solves MPLPs. The default |
|
Maximize the function |
|
Logs execution time and optionally shows a full computation using function arguments and result. |
Classes
|
Represents a relationship between Parameters, Variables, or Expressions. |
|
Two-dimensional, size-mutable, potentially heterogeneous tabular data. |
|
Type of function |
|
|
|
|
|
Set of index elements (X). |
|
index cases |
|
The standard class for multiparametric linear programming |
|
|
|
|
|
Objective Function |
|
Ordered set of parameters. |
|
parameter cases |
|
PurePath subclass that can make system calls. |
|
A mathematical program. |
|
A State with its variables filled in |
|
Ordered set of parametric variables (theta). |
|
Ordered set of variables (Var). |
|
Enum that selects the mpqp algorithm to be used |
- class Prg(name: str = 'prog', tol: float = None, canonical: bool = True, tag: str = '')[source]#
Bases:
objectA mathematical program.
Can be a linear (LP), integer (IP), or mixed-integer (MIP).
- Parameters:
name (str, optional) – Name of the program. Defaults to ‘prog’.
tol (float, optional) – Tolerance. Defaults to None.
canonical (bool, optional) – Whether to use canonical form. Defaults to True.
tag (str, optional) – Tag for the program. Defaults to ‘’.
- Variables:
names (list[str]) – Names of declared sets
sets (Sets) – Object to hold set objects
names_idx (list[str]) – Names of the index elements
indices (list[X]) – Index sets
variables (list[Var]) – Variable sets
thetas (list[PVar]) – Parametric variable sets
functions (list[Func]) – Function sets
constraints (list[Cons]) – Constraint sets
objectives (list[Obj]) – Objective sets
- Raises:
ValueError – If overwriting a set
- name: str = 'prog'#
- tol: float = None#
- canonical: bool = True#
- tag: str = ''#
- property solution: Solution | Solution#
Returns the latest solution of the program
- Returns:
Solution object
- Return type:
Solution | MPSolution
- property formulation: Model | MPLP_Program#
Returns the latest formulation of the program
- Returns:
Formulation object
- Return type:
GPModel | MPLP_Program
- add_index(name: str, index: I)[source]#
Adds new index to program
- Parameters:
name (str) – name of index
index (I) – index set to be added
- add_indices(index: I, members: list[str] = None)[source]#
Adds indices from an index set to the program
- Parameters:
index (I) – Index set who elements are to be added to the program.
members (list[str], optional) – List of members to be added to the index set.
- add_variable(name: str, variable: V)[source]#
Adds new variable set to program
- Parameters:
name (str) – name of variable set
variable (V) – variable set to be added
- mutate_variable(variable_ex: V, variable_new: V)[source]#
Mutates an existing variable set in the program
- add_parameter(name: str, parameter: P)[source]#
Adds new parameter set to program
- Parameters:
name (str) – name of parameter set
parameter (P) – parameter set to be added
- mutate_parameter(parameter_ex: P, parameter_new: P)[source]#
Mutates an existing parameter set in the program
- add_theta(name: str, theta: T)[source]#
Adds new theta set to program
- Parameters:
name (str) – name of theta set
theta (T) – theta set to be added
- update_theta(constraint: C)[source]#
Updates the theta set and thetas in a constraint
- Parameters:
constraint (C) – constraint with thetas to be updated
- add_function(name: str, function: F)[source]#
Add a function set to the program
- Parameters:
name (str) – name of function
function (F) – function object
- replace_function(function_ex: F, function_new: F)[source]#
Replaces an existing function set in the program
- add_constraint(name: str, constraint: C)[source]#
Adds a constraint set to the program
- Parameters:
name (str) – name of constraint
constraint (C) – constraint object
- replace_constraint(constraint_ex: C, constraint_new: C)[source]#
Replaces an existing constraint set in the program
- add_objective(objective: O)[source]#
Adds an objective set to the program
- Parameters:
objective (O) – objective object
- cntbnrvars(n: bool = False) list[int | V][source]#
continuous and binary variables integer variables are excluded
- property B: list[float]#
RHS Parameter vector
- property A: list[list[float]]#
Matrix of Variable coefficients
- property F: list[list[float]]#
Matrix of Parameteric Variable coefficients
- property C: list[float]#
Transpose of the Vector of Objective Coefficients \(C^{T}\)
- property P: list[list[int]]#
Ordinals of continuous variables \(v \in \mathcal{V}\)
Example
The following constraints:
\[ \begin{align}\begin{aligned}5 \cdot \mathbf{v}_2 - 3 \cdot \mathbf{v}_3 + 15.2 \leq 0\\\mathbf{v}_0 = 1\\-4 \cdot \mathbf{v}_3 + \frac{\mathbf{v}_1}{13} = 0\end{aligned}\end{align} \]Correspond to:
\[\begin{split}P = \begin{bmatrix} 2 & 3 \\ 0 & \\ 3 & 1 \end{bmatrix}\end{split}\]
- property Z: list[list[int]]#
Ordinals of parametric variables \(\theta \in \Theta\)
Example
The following constraints:
\[ \begin{align}\begin{aligned}\mathbf{v}_1 - 2 \cdot \theta_1 + 21 \leq 0\\\mathbf{v}_0 - 7.23 \cdot \theta_0 = 0\\\theta_1 - 2 \cdot \mathbf{v}_0 - 31.56\end{aligned}\end{align} \]Corresponds to:
\[\begin{split}Z = \begin{bmatrix} 1 \\ 0 \\ 1 \end{bmatrix}\end{split}\]
- property G: list[list[float]]#
Coefficient matrix of inequality (leq) constraints
Example
The following constraints:
\[ \begin{align}\begin{aligned}5 \cdot \mathbf{v}_2 - 3 \cdot \mathbf{v}_3 = 0\\-4 \cdot \mathbf{v}_3 + \frac{\mathbf{v}_1}{13} + 0.55 \leq 0\\3.73 \cdot \mathbf{v}_0 - 2 \cdot \theta_1 + 21 \leq 0\end{aligned}\end{align} \]
- property H: list[list[float]]#
Coefficient matrix of equality constraints
h = 0
- property NN: list[list[float]]#
Matrix of Variable coefficients for non negative cons
- property A_with_NN: list[list[float]]#
Matrix of Variable coefficients with non-negative constraints
- property B_with_NN: list[float]#
RHS Parameter vector with non-negative constraints
- property CrA: list[list[float]]#
Critical Region A matrix
- property CrB: list[float]#
Critical Region RHS vector
- make_A_df(longname: bool = False) DataFrame[source]#
Create a DataFrame from the A matrix.
- Parameters:
longname (bool) – Whether to use long names for variables. Defaults to False.
- Returns:
Columns are the variables, rows are the constraints.
- Return type:
DataFrame
- make_B_df(longname: bool = False) DataFrame[source]#
Create a DataFrame from the B vector.
- Parameters:
longname (bool) – Whether to use long names for variables. Defaults to False.
- Returns:
Single column DataFrame with the RHS values.
- Return type:
DataFrame
- make_C_df(longname: bool = False) DataFrame[source]#
Create a DataFrame from the C matrix.
- Parameters:
longname (bool) – Whether to use long names for variables. Defaults to False.
- Returns:
Single row DataFrame with the objective coefficients.
- Return type:
DataFrame
- make_df(longname: bool = False) DataFrame[source]#
Create a DataFrame from the model.
- Parameters:
longname (bool) – Whether to use long names for variables. Defaults to False.
- Returns:
A DataFrame with the A matrix, B vector, and C vector.
- Return type:
DataFrame
- make_CrA_df(longname: bool = False) DataFrame[source]#
Creates a DataFrame from the Critical Region A matrix.
- make_CrB_df(longname: bool = False) DataFrame[source]#
Creates a DataFrame from the Critical Region RHS vector.
- make_F_df(longname: bool = False) DataFrame[source]#
Creates a DataFrame from the Theta coefficients matrix.
- import_solution(name: str)[source]#
Imports a solution from an external file Handles JSON and pickle
- Parameters:
name (str) – file name, with extenstion
- solve(using: Literal['combinatorial', 'combinatorial_parallel', 'combinatorial_parallel_exp', 'graph', 'graph_exp', 'graph_parallel', 'graph_parallel_exp', 'combinatorial_graph', 'geometric', 'geometric_parallel', 'geometric_parallel_exp'] = 'combinatorial', tol_mat: float = 1e-09, round_off: int = 4)[source]#
Solve the multiparametric program
- eval(*theta_vals: float, n_sol: int = 0, roundoff: int = 4) list[float][source]#
Evaluates the variable value as a function of parametric variables
- Parameters:
theta_vals (float) – values of the parametric variables
n_sol (int, optional) – solution number, defaults to 0
roundoff (int, optional) – round off the evaluated value, defaults to 4
- Returns:
list of values
- Return type:
list[float]
- Raises:
ValueError – if number of theta values provided does not match number of thetas in the problem
- latex(descriptive: bool = False, categorical: bool = False, category: str = None, as_document: bool = False) str[source]#
Return a LaTeX/Markdown-compatible representation of the mathematical program. - In Markdown mode: uses Markdown headers (##, ###) - In document mode: uses LaTeX section commands