ppopt.upop package
Submodules
ppopt.upop.language_generation module
- ppopt.upop.language_generation.gen_array(data: list, name: str, vartype: str, options=('const',), lang='cpp') str
- ppopt.upop.language_generation.gen_cpp_array(data: list, name: str, vartype: str, options: list = ('const',)) str
Generates a static C++ array from the provided data in the following format
vartype name[size] = {data};
- Parameters:
data –
name –
vartype –
options –
- Returns:
- ppopt.upop.language_generation.gen_cpp_variable(data, name: str, vartype: str, options: list = ('const',)) str
- ppopt.upop.language_generation.gen_js_array(data: list, name: str, vartype: str, options: list = ('const',)) str
- ppopt.upop.language_generation.gen_js_variable(data, name: str, vartype: str | None = None, options: list = ('const',)) str
- ppopt.upop.language_generation.gen_python_array(data: list, name: str, vartype: str, options: list = ('const',)) str
- ppopt.upop.language_generation.gen_python_variable(data, name: str, vartype: str, options: list = ('const',)) str
- ppopt.upop.language_generation.gen_variable(data, name: str, vartype: str | None = None, options=('const',), lang='cpp') str
ppopt.upop.linear_code_gen module
- ppopt.upop.linear_code_gen.generate_code_cpp(solution: Solution, float_type: str = 'float') str
Generates C++17 code for point location and function evaluation on microcontrollers
WARNING: This breaks down at high dimensions
- Parameters:
solution – a solution to a MPLP or MPQP solution
float_type – the type of C++ float to export, e.g. ‘double’ or ‘float’
- Returns:
List of the strings of the C++17 datafiles that integrate with uPOP
- ppopt.upop.linear_code_gen.generate_code_js(solution: Solution) List[str]
Generates Javascript code for point location and function evaluation for Scripting Engines and IOT servers
This is direct enumeration, and it is
- Parameters:
solution – a solution to a MPLP or MPQP solution
- Returns:
List of the strings of the C++17 datafiles that integrate with uPOP
- ppopt.upop.linear_code_gen.generate_code_matlab(solution: Solution, path: str = '') None
This code gen does not bother with memory compression as it is running in the matlab environment and takes ~1 gb to run regardless.
- Parameters:
solution –
path – File export path, if not specified will save in current working directory
- Returns:
ppopt.upop.point_location module
- class ppopt.upop.point_location.PointLocation(solution: Solution)
Bases:
object- evaluate(theta: ndarray) ndarray | None
Evaluates the value of x(theta).
- Parameters:
theta – realization of uncertainty
- Returns:
the solution to the optimization problem or None
- is_inside(theta: ndarray) bool
Determines if the theta point in inside the feasible space.
- Parameters:
theta – A point in the theta space
- Returns:
True, if theta in region and False, if theta not in region
- locate(theta: ndarray) int
Finds the index of the critical region that theta is inside.
- Parameters:
theta – realization of uncertainty
- Returns:
the index of the critical region found
ppopt.upop.ucontroller module
- class ppopt.upop.ucontroller.BVH(parent, fundamental_list, region_list, depth, index)
Bases:
objectThis is the Bounding Volume Hierarchy (BVH) class that decomposes the space that allows point location acceleration
- ppopt.upop.ucontroller.classify_polytope(region: CriticalRegion, hyper_plane: ndarray) int
We are going to classify the polytopic critical region by solving 2 LPS
max ||<x,A>||-d for x in Critical region
min ||<x,A>||-d for x in Critical region
The result of the objective function will tell us the side of the hyper plane the point is on.
- Parameters:
region – Critical region
hyper_plane – A fundamental hyperplane
- Returns:
-1 if completely not in support, 0 if intersected, 1 if completely in support
- ppopt.upop.ucontroller.determine_hyperplane(regions: List[CriticalRegion], hyper_planes: ndarray)
Finds the ‘best’ splitting hyper plane for this task.
In this case best means minimizing the number of intersected regions while also maximizing the difference between supported and not supported regions.
- Parameters:
regions –
hyper_planes –
- Returns:
[]
- ppopt.upop.ucontroller.generate_code(solution: Solution) List[str]
Generates C++17 code for point location and function evaluation on microcontrollers. This forms a BVH to accelerate solution times. WARNING: This breaks down at high dimensions.
- Parameters:
solution – a solution to a MPLP or MPQP solution
- Returns:
List of the strings of the C++17 datafiles that integrate with uPOP
ppopt.upop.upop_utils module
- ppopt.upop.upop_utils.convert_mi_critical_region(cr: CriticalRegion) CriticalRegion
The purpose of this function, is that this generates a new explicit expression for critical regions of programs with mixed integer solutions that is compatible with the exported code libraries.
- Parameters:
cr – a CR with integer values
- Returns:
an augmented CR that has the binary values promoted into the evaluation matrices
- ppopt.upop.upop_utils.find_unique_hyperplanes(overall: ndarray) Tuple[List[int], List[int], List[int]]
Generates the list of indices of the fundamental hyperplanes of the solution, as well as the indices of the associated hyperplanes from the original solution and the parity of the constraint
This is linear w.r.t. number of hyper planes and is quite quick ~25 ns per constraint in the solution
It first creates approximate(near exact) integer representations for each constraint for each region in the solution
This approximation step is justified in that it will find equality between 2 constraints if the L2 norm of the difference is below 10E-12
Then the positive and negative versions of these constraints [ -x < -1, x < 1 are on different sides of the same hyperplane] are made into a format that can be hashed (tuples of ints)
With this is relatively strait forward to check for uniqueness with the set
The first loop scans through all the constraints and if the constraint contains a unique hyperplane
1) if it is a unique hyper plane store the index, add the integer representation to the set, then index the integer representation to the index
if it is not a unique hyperplane do nothing
The second loop scans through the constraints again and assigns them unique hyper plane indices and the parity( what side of the hyper plane that they are on).
- Parameters:
overall – The solution of a multiparametric programming problem :return: returns indices of fundamental
hyperplanes, indices of constraints back to fundamental hyperplane, parity of constraint
- ppopt.upop.upop_utils.find_unique_region_functions(solution: Solution) Tuple[List[int], List[int], List[int]]
- ppopt.upop.upop_utils.find_unique_region_hyperplanes(solution: Solution) Tuple[List[int], List[int], List[int]]
This is an overload of the find_unique_hyperplane function.
- Parameters:
solution –
- Returns:
- ppopt.upop.upop_utils.get_chebychev_centers(solution: Solution) List[ndarray]
Calculates and returns a list of all the theta chebychev centers for the critical regions in the solution.
- Parameters:
solution – An mp programming Solution
- Returns:
A list of all the chebychev centers of the regions in the solutions
- ppopt.upop.upop_utils.get_outer_boundaries(indices: List[int], parity: List[int])
Takes in the global constraint indices to the fundamental hyperplanes and their parity finds all planes with only one parity version aka only one verity of them appears in the original set.
This method is linear w.r.t. number of indices, by the use of sets and hash maps
Only works for solutions with non-overlapping critical regions!
- Parameters:
indices – list of indices that maps the solution constraints into the fundamental hyperplanes
parity – the side of the hyperplane that the constraint represents
- Returns:
- ppopt.upop.upop_utils.verify_outer_boundary(solution: Solution, hyper_indices: List[int], outer_indices: List[int], chebychev_centers: List[ndarray] | None = None) List[int]
This checks all the possible outer boundary indices for errors, failures to solve for the minimal set of fundamental hyperplanes in the solution.
- Parameters:
solution – An mp programming solution
hyper_indices – The list of all fundamental hyperplane indices
outer_indices – The list of identified exterior hyperplane indices
chebychev_centers – the list of chebychev centers in the theta space for every critical region {Optional}
- Returns:
List of verified outer boundary constraints
Module contents
PPOPT.UPOP INIT FILE - todo fill in.
Currently, UPOP does not support cases in overlapping critical regions or objectives with