Skip to content

Commit

Permalink
remove useless helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipuch committed Nov 2, 2023
1 parent 6ae075e commit bfc7606
Showing 1 changed file with 0 additions and 49 deletions.
49 changes: 0 additions & 49 deletions bioptim/optimization/optimal_control_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,52 +2019,3 @@ def _scale_values(values, scaling_entities, penalty, scaling_data):
scaling = np.repeat(complete_scaling, number_of_repeat, axis=0)

return values / scaling


def concatenate_optimization_variables(
variable: list[np.ndarray] | np.ndarray,
continuous_phase: bool = True,
continuous_interval: bool = True,
merge_phases: bool = True,
) -> np.ndarray | list[dict[np.ndarray]]:
"""
# TODO: remove from here I don't this function to be here forever, duplicated of solution helper.
This function concatenates the decision variables of the phases of the system
into a single array, omitting the last element of each phase except for the last one.
Parameters
----------
variable : list or dict
list of decision variables of the phases of the system
continuous_phase: bool
If the arrival value of a node should be discarded [True] or kept [False]. The value of an integrated
continuous_interval: bool
If the arrival value of a node of each interval should be discarded [True] or kept [False].
Only useful in direct multiple shooting
merge_phases: bool
If the decision variables of each phase should be merged into a single array [True] or kept separated [False].
Returns
-------
z_concatenated : np.ndarray or dict
array of the decision variables of the phases of the system concatenated
"""
if len(variable[0].shape):
if isinstance(variable[0][0], np.ndarray):
z_final = []
for zi in variable:
z_final.append(concatenate_optimization_variables(zi, continuous_interval))

if merge_phases:
return concatenate_optimization_variables(z_final, continuous_phase)
else:
return z_final
else:
final_tuple = []
for i, y in enumerate(variable):
if i < (len(variable) - 1) and continuous_phase:
final_tuple.append(y[:, :-1] if len(y.shape) == 2 else y[:-1])
else:
final_tuple.append(y)

return np.hstack(final_tuple)

0 comments on commit bfc7606

Please sign in to comment.