Skip to content

Commit

Permalink
optimize propagators related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yangeorget committed Nov 8, 2024
1 parent 66716ec commit 37b702e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions nucs/propagators/propagators.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def pop_propagator(triggered_propagators: NDArray, previous_prop_idx: int) -> in
:param previous_prop_idx: the index of the previous propagator which has been selected
:return: an index
"""
for prop_idx, triggered_prop in enumerate(triggered_propagators):
if triggered_prop and prop_idx != previous_prop_idx:
for prop_idx in range(len(triggered_propagators)):
if triggered_propagators[prop_idx] and prop_idx != previous_prop_idx:
triggered_propagators[prop_idx] = False
return prop_idx
return -1
Expand All @@ -147,5 +147,8 @@ def add_propagators(
dom_idx: int,
bound: int,
) -> None:
np.logical_or(triggered_propagators, shr_domains_propagators[dom_idx, bound], triggered_propagators)
np.logical_and(triggered_propagators, not_entailed_propagators, triggered_propagators)
for prop_idx in range(len(triggered_propagators)):
if shr_domains_propagators[dom_idx, bound, prop_idx] and not_entailed_propagators[prop_idx]:
triggered_propagators[prop_idx] = True
# np.logical_or(triggered_propagators, shr_domains_propagators[dom_idx, bound], triggered_propagators)
# np.logical_and(triggered_propagators, not_entailed_propagators, triggered_propagators)
2 changes: 1 addition & 1 deletion nucs/solvers/bound_consistency_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def bound_consistency_algorithm(
shr_domains_changes = False
for var_idx in range(prop_var_nb):
shr_domain_idx = prop_indices[var_idx]
prop_offset = prop_offsets[var_idx, 0]
prop_offset = prop_offsets[var_idx, 0] # because of vertical shape
for bound in [MIN, MAX]:
shr_domain_bound = prop_domains[var_idx, bound] - prop_offset
if shr_domains_stack[0, shr_domain_idx, bound] != shr_domain_bound:
Expand Down

0 comments on commit 37b702e

Please sign in to comment.