Skip to content

Commit

Permalink
fix(bc): ensure constraint filters accurately restrict results based …
Browse files Browse the repository at this point in the history
…on area and cluster names
  • Loading branch information
hdinia committed Mar 28, 2024
1 parent 86efc5f commit def92ca
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,36 +178,32 @@ def match_filters(self, constraint: "ConstraintOutput") -> bool:
if self.time_step is not None and self.time_step != constraint.time_step:
return False

# Filter on terms
terms = constraint.terms or []

if self.area_name:
matching_terms = []

for term in terms:
if term.data:
if isinstance(term.data, LinkTerm):
# Check if either area in the link matches the specified area_name
# Check if either area in the link term matches the specified area_name.
if self.area_name.upper() in (term.data.area1.upper(), term.data.area2.upper()):
matching_terms.append(term)
elif isinstance(term.data, ClusterTerm):
# Check if the cluster's area matches the specified area_name
# Check if the area matches the specified area_name for a cluster term.
if self.area_name.upper() == term.data.area.upper():
matching_terms.append(term)

# If no terms match, the constraint should not pass
if not matching_terms:
return False

if self.cluster_name:
all_clusters = []
matching_terms = []
for term in terms:
if term.data is None:
continue
if isinstance(term.data, ClusterTerm):
all_clusters.append(term.data.cluster)
upper_cluster_name = self.cluster_name.upper()
if all_clusters and not any(upper_cluster_name in cluster.upper() for cluster in all_clusters):
if term.data and isinstance(term.data, ClusterTerm):
if self.cluster_name.upper() == term.data.cluster.upper():
matching_terms.append(term)
if not matching_terms:
return False

if self.link_id:
Expand Down Expand Up @@ -448,14 +444,12 @@ def terms_to_coeffs(terms: Sequence[ConstraintTerm]) -> Dict[str, List[float]]:
:return: A dictionary of term IDs mapped to a list of their coefficients.
"""
coeffs = {}

if terms is not None:
for term in terms:
if term.id and term.weight is not None:
coeffs[term.id] = [term.weight]
if term.offset is not None:
coeffs[term.id].append(term.offset)

return coeffs

def get_binding_constraint(
Expand Down

0 comments on commit def92ca

Please sign in to comment.