utils
Utility functions for caching, printing, and output formatting.
This module provides utilities for OpenSCvx.
calculate_cost_from_boundaries(x: np.ndarray, initial_type: np.ndarray, final_type: np.ndarray) -> float
¶
Calculate cost from boundary condition objectives.
This function computes the total cost contribution from state boundary conditions marked as "Minimize" or "Maximize" at initial and final times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
State trajectory array of shape (N, n_states) |
required |
initial_type
|
ndarray
|
Array of boundary condition types for initial states |
required |
final_type
|
ndarray
|
Array of boundary condition types for final states |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total cost from minimize/maximize boundary conditions |
Example
State with final time to minimize¶
x = np.array([[0.0, 5.0], [10.0, 20.0]]) # 2 nodes, 2 states initial_type = np.array(["Fix", "Free"]) final_type = np.array(["Minimize", "Free"]) cost = calculate_cost_from_boundaries(x, initial_type, final_type) cost # Returns x[-1, 0] = 10.0
Source code in openscvx/utils/utils.py
gen_vertices(center, radii)
¶
Obtains the vertices of the gate.
Source code in openscvx/utils/utils.py
generate_orthogonal_unit_vectors(vectors=None)
¶
Generates 3 orthogonal unit vectors to model the axis of the ellipsoid via QR decomposition
vectors (np.ndarray): Optional, axes of the ellipsoid to be orthonormalized. If none specified generates randomly.
Returns: np.ndarray: A 3x3 matrix where each column is a unit vector.