From 37b702eba92965e440aad105e1073fa6e32b5934 Mon Sep 17 00:00:00 2001 From: yangeorget Date: Fri, 8 Nov 2024 17:23:39 +0100 Subject: [PATCH] optimize propagators related functions --- nucs/propagators/propagators.py | 11 +++++++---- nucs/solvers/bound_consistency_algorithm.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/nucs/propagators/propagators.py b/nucs/propagators/propagators.py index 6740afc..75b8d5f 100644 --- a/nucs/propagators/propagators.py +++ b/nucs/propagators/propagators.py @@ -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 @@ -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) diff --git a/nucs/solvers/bound_consistency_algorithm.py b/nucs/solvers/bound_consistency_algorithm.py index b81469c..a9dbc9f 100644 --- a/nucs/solvers/bound_consistency_algorithm.py +++ b/nucs/solvers/bound_consistency_algorithm.py @@ -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: