Commit 25856836 authored by Teresa Piovesan's avatar Teresa Piovesan Committed by Tjerk Vreeken

Fix seed derivatives

The value of the derivatives of the initial time step and of the extra
variables is included the seed.

Closes issue #1066
parent 0a119b4c
......@@ -1686,6 +1686,15 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass=ABC
x0[offset + k] = seed[self.extra_variables[k].name()]
except KeyError:
pass
offset += len(self.extra_variables)
for k in range(len(self.dae_variables['derivatives'])):
try:
der_name = self.dae_variables['derivatives'][k].name()
variable = "initial_" + der_name
x0[offset + k] = seed[variable]
except KeyError:
pass
# Return number of state variables
return count, discrete, lbx, ubx, x0, indices
......@@ -1750,6 +1759,13 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass=ABC
for k in range(len(self.extra_variables)):
variable = self.extra_variables[k].name()
results[variable] = X[offset + k].ravel()
offset += len(self.extra_variables)
# Extract derivatives
for k in range(len(self.dae_variables['derivatives'])):
der_name = self.dae_variables['derivatives'][k].name()
variable = "initial_" + der_name
results[variable] = X[offset + k].ravel()
# Done
return results
......
......@@ -366,6 +366,8 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass=ABCMeta):
# Only include seed timeseries which are consistent
# with the specified time stamps.
seed[key] = Timeseries(times, result)
elif len(result) == 1:
seed[key] = result
# Seed epsilons
for epsilon in self.__subproblem_epsilons:
......
......@@ -30,10 +30,14 @@ class HomotopyMixin(OptimizationProblem):
# Do not override any previously seeded values, such as goal programming results.
for key, result in self.__results[ensemble_member].items():
times = self.times(key)
if key not in seed and len(result) == len(times):
if key in seed:
continue
elif len(result) == len(times):
# Only include seed timeseries which are consistent
# with the specified time stamps.
seed[key] = Timeseries(times, result)
elif len(result) == 1:
seed[key] = result
return seed
def parameters(self, ensemble_member):
......
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