Skip to content

Commit

Permalink
Merge pull request #14 from ami-iit/parametric
Browse files Browse the repository at this point in the history
Allow using parametric models in the turnkey planners
  • Loading branch information
S-Dafarra authored Apr 4, 2024
2 parents 7cba549 + b633486 commit 845ab09
Show file tree
Hide file tree
Showing 9 changed files with 1,338 additions and 156 deletions.
18 changes: 13 additions & 5 deletions src/hippopt/base/opti_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def _generate_opti_object(
if isinstance(value, float):
value = value * np.ones((1, 1))

if value.shape[0] * value.shape[1] == 0:
raise ValueError("Field " + name + " has a zero dimension.")

if storage_type is Variable.StorageTypeValue:
self._logger.debug("Creating variable " + name)
opti_object = self._solver.variable(*value.shape)
Expand Down Expand Up @@ -181,12 +184,17 @@ def _generate_objects_from_instance(
composite_value = output.__getattribute__(field.name)

is_list = isinstance(composite_value, list)
list_of_optimization_objects = is_list and all(
isinstance(elem, OptimizationObject) or isinstance(elem, list)
for elem in composite_value
list_of_optimization_objects = (
is_list
and len(composite_value) > 0
and all(
isinstance(elem, OptimizationObject) or isinstance(elem, list)
for elem in composite_value
)
)
list_of_float = is_list and all(
isinstance(elem, float) for elem in composite_value
list_of_float = is_list and (
len(composite_value) == 0
or all(isinstance(elem, float) for elem in composite_value)
)
if list_of_float:
composite_value = np.array(composite_value)
Expand Down
Loading

0 comments on commit 845ab09

Please sign in to comment.