Skip to content

Commit

Permalink
filter duplicates from list of nonlinear vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbybp committed Dec 13, 2023
1 parent ecaf053 commit 9236f4f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pyomo/contrib/incidence_analysis/incidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ def _get_incident_via_ampl_repn(expr, linear_only, visitor=None):
repn = visitor.walk_expression((expr, None, 0, 1.0))

nonlinear_var_ids = [] if repn.nonlinear is None else repn.nonlinear[1]
nonlinear_vars = [var_map[v_id] for v_id in nonlinear_var_ids]
nonlinear_vid_set = set(nonlinear_var_ids)
nonlinear_var_id_set = set()
unique_nonlinear_var_ids = []
for v_id in nonlinear_var_ids:
if v_id not in nonlinear_var_id_set:
nonlinear_var_id_set.add(v_id)
unique_nonlinear_var_ids.append(v_id)

nonlinear_vars = [var_map[v_id] for v_id in unique_nonlinear_var_ids]
linear_only_vars = [
var_map[v_id]
for v_id, coef in repn.linear.items()
if coef != 0.0 and v_id not in nonlinear_vid_set
if coef != 0.0 and v_id not in nonlinear_var_id_set
]
if linear_only:
return linear_only_vars
Expand Down

0 comments on commit 9236f4f

Please sign in to comment.