Commit 5f3e17df authored by Tjerk Vreeken's avatar Tjerk Vreeken

Disallow function_range for minimization goals

Minimization goals only use the function nominal for scaling. Requiring
the user to specify a function range is misleading.

Closes #1051
parent a2f00aff
......@@ -250,15 +250,16 @@ class StateGoal(Goal, metaclass=ABCMeta):
raise Exception('Please specify a state.')
# Extract state range from model
try:
self.function_range = optimization_problem.bounds()[self.state]
except KeyError:
raise Exception('State {} has no bounds or does not exist in the model.'.format(self.state))
if self.has_target_bounds:
try:
self.function_range = optimization_problem.bounds()[self.state]
except KeyError:
raise Exception('State {} has no bounds or does not exist in the model.'.format(self.state))
if self.function_range[0] is None:
raise Exception('Please provide a lower bound for state {}.'.format(self.state))
if self.function_range[1] is None:
raise Exception('Please provide an upper bound for state {}.'.format(self.state))
if self.function_range[0] is None:
raise Exception('Please provide a lower bound for state {}.'.format(self.state))
if self.function_range[1] is None:
raise Exception('Please provide an upper bound for state {}.'.format(self.state))
# Extract state nominal from model
self.function_nominal = optimization_problem.variable_nominal(self.state)
......@@ -812,14 +813,18 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass=ABCMeta):
for goal in itertools.chain(goals, path_goals):
m, M = ca.MX(goal.function_range[0]), ca.MX(goal.function_range[1])
if not m.is_regular() or not M.is_regular():
raise Exception("No function range specified for goal {}".format(goal))
if m >= M:
raise Exception("Invalid function range for goal {}.".format(goal))
if goal.function_nominal <= 0:
raise Exception("Nonpositive nominal value specified for goal {}".format(goal))
if goal.has_target_bounds:
if not m.is_regular() or not M.is_regular():
raise Exception("No function range specified for goal {}".format(goal))
if m >= M:
raise Exception("Invalid function range for goal {}.".format(goal))
else:
if goal.function_range != (np.nan, np.nan):
raise Exception("Specifying function range not allowed for goal {}".format(goal))
try:
priorities = {int(goal.priority) for goal in itertools.chain(goals, path_goals) if not goal.is_empty}
except ValueError:
......
......@@ -125,7 +125,6 @@ class TestGoalNoMinMax(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.integral("x", ensemble_member=ensemble_member)
function_range = (-1e1, 1e1)
function_nominal = 2e1
priority = 1
order = 1
......@@ -179,7 +178,6 @@ class TestGoalMinimizeU(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.state_at("u", 0.5, ensemble_member=ensemble_member)
function_range = (-1e2, 1e2)
priority = 1
order = 1
......@@ -250,7 +248,6 @@ class PathGoal3(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.state("u")
function_range = (-1e1, 1e1)
priority = 3
......@@ -259,7 +256,6 @@ class PathGoal4(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.state("constant_input")
function_range = (-1e1, 1e1)
priority = 4
......@@ -268,7 +264,6 @@ class PathGoal5(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.state("k")
function_range = (-1e1, 1e1)
priority = 5
......@@ -368,7 +363,6 @@ class TestGoalMinU(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.integral("u", ensemble_member=ensemble_member)
function_range = (-1e1, 1e1)
priority = 3
......@@ -386,7 +380,6 @@ class PathGoal1Critical(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.state("x")
function_range = (-1e1, 1e1)
priority = 1
target_min = 0.0
critical = True
......@@ -397,7 +390,6 @@ class TestGoalLowerUCritical(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.integral("u", ensemble_member=ensemble_member)
function_range = (-1e1, 1e1)
priority = 3
target_min = 1e-6
critical = True
......@@ -473,7 +465,6 @@ class PathGoalSmoothing(Goal):
def function(self, optimization_problem, ensemble_member):
return optimization_problem.der("u")
function_range = (-1e1, 1e1)
priority = 3
......
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