gana.block.program#

Program

Functions

dataclass([cls, init, repr, eq, order, ...])

Add dunder methods based on the fields defined in the class.

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

Display a Python object in all frontends.

field(*[, default, default_factory, init, ...])

Return an object to identify dataclass fields.

gpread(filename[, env])

ROUTINE:

inf(function)

Minimize the function

nparray(object[, dtype, copy, order, subok, ...])

array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0,

npzeros(shape[, dtype, order, device, like])

zeros(shape, dtype=None, order='C', *, device=None, like=None)

parametric_plot(solution[, save_path, show, ...])

Makes a simple plot from a solution.

solve_mpqp(problem[, algorithm])

Takes a mpqp programming problem and solves it in a specified manner, In addition this solves MPLPs. The default

sup(function)

Maximize the function

timer(logger[, kind, with_return, level])

Logs execution time and optionally shows a full computation using function arguments and result.

Classes

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

Represents a relationship between Parameters, Variables, or Expressions.

DataFrame([data, index, columns, dtype, copy])

Two-dimensional, size-mutable, potentially heterogeneous tabular data.

Elem(*values)

Type of function

Func

GPModel

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

Set of index elements (X).

ICase(*values)

index cases

MPLP_Program(A, b, c, H, A_t, b_t, F[, c_c, ...])

The standard class for multiparametric linear programming

MPSolution

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

O(function)

Objective Function

P(*index[, _, mutable, tag, ltx, name])

Ordered set of parameters.

PCase(*values)

parameter cases

Path(*args, **kwargs)

PurePath subclass that can make system calls.

Prg([name, tol, canonical, tag])

A mathematical program.

Solution([name])

A State with its variables filled in

T(*index[, _, tag, mutable, ltx, name])

Ordered set of parametric variables (theta).

V(*index[, itg, nn, bnr, mutable, tag, ltx, ...])

Ordered set of variables (Var).

mpqp_algorithm(*values)

Enum that selects the mpqp algorithm to be used

class Prg(name: str = 'prog', tol: float = None, canonical: bool = True, tag: str = '')[source]#

Bases: object

A 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

Parameters:
  • variable_ex (V) – existing variable set to be mutated

  • variable_new (V) – incoming variable set to be added

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

Parameters:
  • parameter_ex (P) – existing parameter set to be mutated

  • parameter_new (P) – incoming parameter set to be added

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

mutate_theta(theta_ex: T, theta_new: T)[source]#

Mutates an existing theta set in the program

Parameters:
  • theta_ex (T) – existing theta set to be mutated

  • theta_new (T) – incoming theta set to be added

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

Parameters:
  • function_ex (F) – existing function set to be mutated

  • function_new (F) – new function set to replace the existing one

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

Parameters:
  • constraint_ex (C) – existing constraint set to be mutated

  • constraint_new (C) – new constraint set to replace the existing one

add_objective(objective: O)[source]#

Adds an objective set to the program

Parameters:

objective (O) – objective object

property nncons_sets: list[C]#

non-negativity constraint sets

property eqcons_sets: list[C]#

equality constraint sets

property leqcons_sets: list[C]#

less than or equal constraint sets

nncons(n: bool = False) list[int | C][source]#

non-negativity constraints

eqcons(n: bool = False) list[int | C][source]#

equality constraints

leqcons(n: bool = False) list[int | C][source]#

less than or equal constraints

cons(n: bool = False) list[int | C][source]#

constraints

nnvars(n: bool = False) list[int | V][source]#

non-negative variables

bnrvars(n: bool = False) list[int | V][source]#

binary variables

itgvars(n: bool = False) list[int | V][source]#

integer variables

nonbnritgvars(n: bool = False) list[int | V][source]#

non-binary and integer variables

cntbnrvars(n: bool = False) list[int | V][source]#

continuous and binary variables integer variables are excluded

cntvars(n: bool = False) list[int | V][source]#

continuous variables

renumber()[source]#

Renumbers the constraints, just to be sure

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.

mps(name: str = None)[source]#

MPS File

lp()[source]#

LP File

opt(using: str = 'gurobi')[source]#

Determine the optimal solution to the program

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

lb(function: V | F)[source]#

Finds the lower bound of a variable or function

ub(function: V | F)[source]#

Finds the upper bound of a variable or function

obj()[source]#

Objective Values

output(n_sol: int = 0, slack: bool = True, compare=False)[source]#

Print sol

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

show(descriptive: bool = False, nncons: bool = False, categorical: bool = False, category: str = None)[source]#

Pretty Print

draw(variable: V = None, n_sol: int = 0)[source]#

Plots the solution for a variable

ppopt() MPLP_Program[source]#

Convert the program to a ppopt.MPLP_Program

gurobi() Model[source]#

Gurobi Model