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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ notebooks/.ipynb_checkpoints/Prediction-based CA system-checkpoint.ipynb
dist/pycona-0.2.4-py3-none-any.whl
dist/pycona-0.2.4.tar.gz
notebooks/.ipynb_checkpoints/Comparing different algorithms and methods-checkpoint.ipynb
testing.py
1 change: 0 additions & 1 deletion pycona/active_algorithms/genacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.total_queries} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generation_time(gen_end - gen_start)
Expand Down
7 changes: 6 additions & 1 deletion pycona/active_algorithms/growacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..answering_queries import Oracle, UserOracle
from .. import Metrics
from ..ca_environment import ProbaActiveCAEnv

from ..utils import get_con_subset

class GrowAcq(AlgorithmCAInteractive):
"""
Expand Down Expand Up @@ -67,6 +67,11 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
print(f"\nGrowAcq: calling inner_algorithm for {len(Y)}/{n_vars} variables")
self.env.instance = self.inner_algorithm.learn(self.env.instance, oracle, verbose=verbose, X=Y, metrics=self.env.metrics)

# Add implied constraints from bias to cl
implied_constraints = get_con_subset(self.env.instance.bias, Y)
self.env.instance.cl.extend(implied_constraints)
self.env.instance.bias = [c for c in self.env.instance.bias if c not in set(implied_constraints)] # remove implied constraints from bias

if verbose >= 3:
print("C_L: ", len(self.env.instance.cl))
print("B: ", len(self.env.instance.bias))
Expand Down
1 change: 0 additions & 1 deletion pycona/active_algorithms/mineacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.total_queries} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generation_time(gen_end - gen_start)
Expand Down
1 change: 0 additions & 1 deletion pycona/active_algorithms/mquacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.membership_queries_count} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generation_time(gen_end - gen_start)
Expand Down
1 change: 0 additions & 1 deletion pycona/active_algorithms/mquacq2.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.membership_queries_count} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generated_queries()
Expand Down
1 change: 0 additions & 1 deletion pycona/active_algorithms/pquacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.membership_queries_count} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generation_time(gen_end - gen_start)
Expand Down
1 change: 0 additions & 1 deletion pycona/active_algorithms/quacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.membership_queries_count} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generation_time(gen_end - gen_start)
Expand Down
4 changes: 1 addition & 3 deletions pycona/benchmarks/nqueens.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..answering_queries.constraint_oracle import ConstraintOracle
from ..problem_instance import ProblemInstance, absvar

def construct_nqueens_problem(n):
def construct_nqueens_problem(n=8):

parameters = {"n": n}

Expand Down Expand Up @@ -43,6 +43,4 @@ def construct_nqueens_problem(n):
for c in oracle.constraints:
print(c)

input("Press Enter to continue...")

return instance, oracle
14 changes: 14 additions & 0 deletions tests/test_finc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,19 @@ def test_findc2_with_golomb4(self):
learned_not_oracle += cp.any([~c for c in oracle.constraints])
assert not learned_not_oracle.solve()

# test growacq
alg = ca.GrowAcq(ca_env, alg)
li2 = alg.learn(instance, oracle)

# oracle model imply learned?
oracle_not_learned = cp.Model(oracle.constraints)
oracle_not_learned += cp.any([~c for c in li2._cl])
assert not oracle_not_learned.solve()

# learned model imply oracle?
learned_not_oracle = cp.Model(li2._cl)
learned_not_oracle += cp.any([~c for c in oracle.constraints])
assert not learned_not_oracle.solve()