Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions pycona/ca_environment/active_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
42 changes: 38 additions & 4 deletions pycona/ca_environment/ca_env_core.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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="")