Commit 2d4c12fb authored by Tjerk Vreeken's avatar Tjerk Vreeken Committed by Teresa Piovesan

SimulationProblem: Fix scaling of bounds with nominals

The bounds were not scaled at all with the nominals. With the equations
being scaled, this would lead to many infeasible problems.
parent b4ccb638
......@@ -351,8 +351,9 @@ class SimulationProblem:
# State bounds can be symbolic, written in terms of parameters. After all
# parameter values are known, we evaluate the numeric values of bounds.
symbolic_bounds = ca.vertcat(*[ca.horzcat(v.min, v.max) for v in itertools.chain(
self.__pymoca_model.states, self.__pymoca_model.alg_states, self.__pymoca_model.der_states)])
bound_vars = list(itertools.chain(
self.__pymoca_model.states, self.__pymoca_model.alg_states, self.__pymoca_model.der_states))
symbolic_bounds = ca.vertcat(*[ca.horzcat(v.min, v.max) for v in bound_vars])
bound_evaluator = ca.Function('bound_evaluator', self.__mx['parameters'], [symbolic_bounds])
# Evaluate bounds using values of parameters
......@@ -362,6 +363,13 @@ class SimulationProblem:
else:
[evaluated_bounds] = bound_evaluator.call([])
# Scale the bounds with the nominals
nominals = []
for var in bound_vars:
nominals.append(nominal_dict[var.symbol.name()])
evaluated_bounds = np.array(evaluated_bounds) / np.array(nominals)[:, None]
# Update with the bounds of delayed states
n_delay = len(self.__pymoca_model.delay_states)
delay_bounds = np.array([-np.inf, np.inf] * n_delay).reshape((n_delay, 2))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment