Skip to content

Commit

Permalink
Parse cplex <objectiveValues> tags; fixes #1766
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Jan 19, 2021
1 parent dcd3fd8 commit 49b20dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pyomo/core/kernel/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ def load_solution(self,
raise KeyError("Objective associated with symbol '%s' "
"is not found on this block"
% (label))
unseen_var_ids.remove(id(obj))
# Because of __default_objective__, an objective might
# appear twice in the objective dictionary.
unseen_var_ids.discard(id(obj))
for _attr_key, attr_value in six.iteritems(entry):
attr_key = _attr_key[0].lower() + _attr_key[1:]
if attr_key in valid_import_suffixes:
Expand Down
14 changes: 13 additions & 1 deletion pyomo/solvers/plugins/solvers/CPLEX.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,21 @@ def process_soln_file(self,results):
break
tINPUT.close()

elif tokens[0].startswith("objectiveValue"):
elif tokens[0].startswith("objectiveValue") and tokens[0] != 'objectiveValues':
# prior to 12.10.0, the objective value came back as an
# attribute on the <header> tag
objective_value = (tokens[0].split('=')[1].strip()).lstrip("\"").rstrip("\"")
soln.objective['__default_objective__']['Value'] = float(objective_value)

elif tokens[0] == "objective":
# beginning in 12.10.0, CPLEX supports multiple
# objectives in an <objectiveValue> tag
fields = {}
for field in tokens[1:]:
k,v = field.split('=')
fields[k] = v.strip('"')
soln.objective.setdefault(fields['name'], {})['Value'] = float(fields['value'])

elif tokens[0].startswith("solutionStatusValue"):
pieces = tokens[0].split("=")
solution_status = eval(pieces[1])
Expand Down

0 comments on commit 49b20dc

Please sign in to comment.