-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from alcides/bfs
Enumerative is now BFS instead of DFS
- Loading branch information
Showing
2 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
|
||
from geneticengine.algorithms.enumerative import iterate_individuals | ||
from geneticengine.grammar.grammar import extract_grammar | ||
|
||
|
||
class Root(ABC): | ||
pass | ||
|
||
|
||
@dataclass | ||
class Leaf(Root): | ||
pass | ||
|
||
|
||
@dataclass | ||
class Branch1(Root): | ||
v1: Root | ||
v2: Root | ||
|
||
|
||
@dataclass | ||
class Branch2(Root): | ||
v1: Root | ||
v2: Root | ||
|
||
|
||
def test_enumerative(): | ||
g = extract_grammar([Leaf, Branch1, Branch2], Root) | ||
exp = [Leaf(), Branch1(Leaf(), Leaf()), Branch2(Leaf(), Leaf())] | ||
|
||
xs = [] | ||
for x in iterate_individuals(g, Root): | ||
xs.append(x.instance) | ||
if len(xs) > 10: | ||
break | ||
print(xs) | ||
|
||
for expected, real in zip(exp, xs): | ||
assert expected == real |