snowdrop.src.numeric.optimization package¶
Submodules¶
snowdrop.src.numeric.optimization.optimize module¶
Generic optimization module.
@author: A.Goumilevski
- class snowdrop.src.numeric.optimization.optimize.Data(success: bool, x: float, fun: float, nfev: int = 0, message: str = '')[source]¶
Bases:
object
- fun: float¶
- message: str = ''¶
- nfev: int = 0¶
- success: bool¶
- x: float¶
- snowdrop.src.numeric.optimization.optimize.run(fpath=None, fout=None, Output=False, plot_variables=None, model_info=False)[source]¶
Call main driver program.
Runs model simulations.
- Parameters:
- param fpath:
Path to model file.
- type fpath:
str.
- param fout:
Path to output excel file.
- type fout:
str.
- param Output:
If True save results in excel file.
- type Output:
bool.
- param plot_variables:
Plot variables.
- type plot_variables:
list.
- param model_info:
If True creates a pdf/latex model file.
- type model_info:
bool.
- returns:
Optimization results.
snowdrop.src.numeric.optimization.test module¶
Created on Mon Apr 18 00:09:58 2022
@author: A.Goumilevski
snowdrop.src.numeric.optimization.util module¶
Generic optimization module. Developed to replicate GAMS PATH Solver. @author: A.Goumilevski
- class snowdrop.src.numeric.optimization.util.Data(success: bool, x: float, fun: float, nfev: int = 0)[source]¶
Bases:
object
- fun: float¶
- nfev: int = 0¶
- success: bool¶
- x: float¶
- snowdrop.src.numeric.optimization.util.expand(sets, indices, expr, objFunc=False, loop=False)[source]¶
Expands expression.
- Parameters:
- param sets:
Dictionary of categories.
- type sets:
dict.
- param indices:
List of indeces.
- type indices:
list.
- param expr:
Object.
- type expr:
list or dict.
- returns:
objFunc: True if expanding expression for objective function.
- type objFunc:
bool.
- returns:
Expanded expression.
- snowdrop.src.numeric.optimization.util.expand_list(sets, indices, arr, objFunc=False, loop=False)[source]¶
Iterates thru a list of indices and categories, substitutes an index of a variable name with a corresponding category, and builds a list of new variables.
- Parameters:
- param sets:
Dictionary of categories.
- type sets:
dict.
- param indices:
List of indeces.
- type indices:
list.
- param arr:
List of indeces.
- type arr:
list.
- param:
objFunc: True if expanding expression for objective function.
- type objFunc:
bool.
- param loop:
True if expanding expression for objective function.
- type loop:
bool.
- returns:
list object.
- snowdrop.src.numeric.optimization.util.expand_loop(categories, sub, expr)[source]¶
Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.
- Parameters:
- param categories:
Categories.
- type categories:
list.
- param sub:
Sub-string to replace.
- type sub:
str.
- param expr:
Text.
- type expr:
str.
- returns:
Text representation of sum operation.
- snowdrop.src.numeric.optimization.util.expand_map(sets, indices, m)[source]¶
Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.
- Parameters:
- param sets:
Dictionary of categories.
- type sets:
dict.
- param indices:
List of indeces.
- type indices:
list.
- param m:
Map.
- type m:
dict.
- returns:
Dictionary object.
- snowdrop.src.numeric.optimization.util.expand_minmax(b, sets, indices, txt)[source]¶
Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.
- Parameters:
- param b:
True if minimum and False if maximum.
- type b:
bool.
- param sets:
Dictionary of categories.
- type sets:
dict.
- param indices:
List of indeces.
- type indices:
list.
- param txt:
Text.
- type txt:
str.
- returns:
Text representation of min/max operation.
- snowdrop.src.numeric.optimization.util.expand_obj_func_sum(categories, sub, expr)[source]¶
Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.
- Parameters:
- param categories:
Categories.
- type categories:
list.
- param sub:
Sub-string to replace.
- type sub:
str.
- param expr:
Text.
- type expr:
str.
- returns:
Text representation of sum operation.
- snowdrop.src.numeric.optimization.util.expand_sum_or_prod(sets, indices, txt, symb)[source]¶
Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.
- Parameters:
- param sets:
Dictionary of categories.
- type sets:
dict.
- param indices:
List of indeces.
- type indices:
list.
- param txt:
Text.
- type txt:
str.
- param symb:
Symbol “+” or “*”.
- type txt:
str.
- returns:
Text representation of summation or product operation.
- snowdrop.src.numeric.optimization.util.fix(eqs, model_eqs)[source]¶
Get equations, label of equations and complemtarity conditions.
- Parameters:
- param eqs:
Equations.
- type eqs:
list.
- param model_eqs:
Model equations to solve.
- type model_eqs:
list.
- returns:
List of equations and complemtarity conditions.
- snowdrop.src.numeric.optimization.util.getConstraints(n, constraints, cal, eqLabels, jacobian)[source]¶
Build linear constraints.
- snowdrop.src.numeric.optimization.util.getIndex(e, ind)[source]¶
Find the first matching occurance of open bracket.
- Parameters:
- param e:
Expression.
- type e:
str.
- param ind:
Starting index.
- type ind:
int.
- returns:
Index of the matching open bracket.
- snowdrop.src.numeric.optimization.util.getLimits(var_names, constraints, cal)[source]¶
Find variables upper and lower limits.
- snowdrop.src.numeric.optimization.util.importModel(fpath)[source]¶
Parse a model file and create a model object.
- Parameters:
- param fpath:
Path to model file.
- type fpath:
str.
- snowdrop.src.numeric.optimization.util.loadLibrary()[source]¶
Simple example of loading and using the system C library from Python.