Skip to content

Commit

Permalink
update example.py to get the count
Browse files Browse the repository at this point in the history
  • Loading branch information
enadeau committed Aug 27, 2019
1 parent ba9f041 commit 9abcc1b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
"""
In this file an example of how to perform combinatorial exploration on words
with respect to factor order is given.
>>> alphabet = ['a', 'b']
>>> start_class = AvoidingWithPrefix("", ['b'], alphabet)
>>> searcher = CombinatorialSpecificationSearcher(start_class, pack)
>>> tree = searcher.auto_search(status_update=10)
>>> [tree.count_objects_of_length(i) for i in range(10)]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> start_class = AvoidingWithPrefix("", ['ab'], alphabet)
>>> searcher = CombinatorialSpecificationSearcher(start_class, pack)
>>> tree = searcher.auto_search(status_update=10)
>>> [tree.count_objects_of_length(i) for i in range(10)]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> start_class = AvoidingWithPrefix("", ['aa', 'bb'], alphabet)
>>> searcher = CombinatorialSpecificationSearcher(start_class, pack)
>>> tree = searcher.auto_search(status_update=10)
>>> [tree.count_objects_of_length(i) for i in range(10)]
[1, 2, 2, 2, 2, 2, 2, 2, 2, 2]
>>> start_class = AvoidingWithPrefix("", ['bb'], alphabet)
>>> searcher = CombinatorialSpecificationSearcher(start_class, pack)
>>> tree = searcher.auto_search(status_update=10)
>>> [tree.count_objects_of_length(i) for i in range(11)]
[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
"""
from itertools import product

Expand Down Expand Up @@ -119,6 +141,17 @@ def __repr__(self):
repr(self.patterns),
repr(self.alphabet))

# Method required to get the counts

def is_epsilon(self):
return self.is_empty()

def is_atom(self):
return len(self.prefix) == 1 and self.just_prefix

def is_positive(self):
return len(self.prefix) > 0


# the strategies

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test=pytest

[tool:pytest]
addopts = --pep8 --isort --cov=comb_spec_searcher --cov-report=term-missing
testpaths = comb_spec_searcher test_readme.txt
testpaths = comb_spec_searcher test_readme.txt example.py

[tool:isort]
known_first_party = comb_spec_searcher,permuta
Expand Down

0 comments on commit 9abcc1b

Please sign in to comment.