diff --git a/pycona/ca_environment/active_ca.py b/pycona/ca_environment/active_ca.py index 637267d..6d412e6 100644 --- a/pycona/ca_environment/active_ca.py +++ b/pycona/ca_environment/active_ca.py @@ -212,39 +212,3 @@ def ask_generalization_query(self, c, C): self.metrics.asked_query() return answer - - def remove_from_bias(self, C): - """ - Remove given constraints from the bias (candidates) - - :param C: list of constraints to be removed from B - """ - if isinstance(C, Expression): - C = [C] - assert isinstance(C, list), "remove_from_bias accepts as input a list of constraints or a constraint" - - if self.verbose >= 3: - print(f"removing the following constraints from bias: {C}") - - self.instance.bias = list(set(self.instance.bias) - set(C)) - - def add_to_cl(self, C): - """ - Add the given constraints to the list of learned constraints - - :param C: Constraints to add to CL - """ - if isinstance(C, Expression): - C = [C] - assert isinstance(C, list), "add_to_cl accepts as input a list of constraints or a constraint" - - if self.verbose >= 3: - print(f"adding the following constraints to C_L: {C}") - - # Add constraint(s) c to the learned network and remove them from the bias - self.instance.cl.extend(C) - self.instance.bias = list(set(self.instance.bias) - set(C)) - - self.metrics.cl += 1 - if self.verbose == 1: - print("L", end="") diff --git a/pycona/ca_environment/ca_env_core.py b/pycona/ca_environment/ca_env_core.py index 971c705..92caa7b 100644 --- a/pycona/ca_environment/ca_env_core.py +++ b/pycona/ca_environment/ca_env_core.py @@ -1,7 +1,5 @@ -from abc import ABC, abstractmethod - -from .. import Metrics -from ..problem_instance import ProblemInstance +from abc import ABC +from cpmpy.expressions.core import Expression class CAEnv(ABC): @@ -61,3 +59,39 @@ def converged(self): def converged(self, converged): """ Set the convergence value """ self._converged = converged + + def remove_from_bias(self, C): + """ + Remove given constraints from the bias (candidates) + + :param C: list of constraints to be removed from B + """ + if isinstance(C, Expression): + C = [C] + assert isinstance(C, list), "remove_from_bias accepts as input a list of constraints or a constraint" + + if self.verbose >= 3: + print(f"removing the following constraints from bias: {C}") + + self.instance.bias = list(set(self.instance.bias) - set(C)) + + def add_to_cl(self, C): + """ + Add the given constraints to the list of learned constraints + + :param C: Constraints to add to CL + """ + if isinstance(C, Expression): + C = [C] + assert isinstance(C, list), "add_to_cl accepts as input a list of constraints or a constraint" + + if self.verbose >= 3: + print(f"adding the following constraints to C_L: {C}") + + # Add constraint(s) c to the learned network and remove them from the bias + self.instance.cl.extend(C) + self.instance.bias = list(set(self.instance.bias) - set(C)) + + self.metrics.cl += 1 + if self.verbose == 1: + print("L", end="")