Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Game Theory AIC
GTLib2
Commits
9bea44fc
Commit
9bea44fc
authored
Mar 22, 2019
by
Michal Sustr
Browse files
Add incremental depth cache building test
parent
74a8aa98
Changes
2
Hide whitespace changes
Inline
Side-by-side
algorithms/tree.cpp
View file @
9bea44fc
...
...
@@ -40,7 +40,7 @@ namespace algorithms {
void
buildTree
(
EFGCache
*
cache
,
int
maxDepth
)
{
auto
traverse
=
[
&
cache
,
maxDepth
](
const
shared_ptr
<
EFGNode
>
&
node
,
const
auto
&
traverse
)
{
if
(
node
->
getDepth
()
>
maxDepth
)
return
;
if
(
node
->
getDepth
()
>
=
maxDepth
)
return
;
for
(
const
auto
&
action
:
node
->
availableActions
())
{
for
(
auto
const
&
nodeDist
:
cache
->
getChildrenFor
(
node
,
action
))
{
...
...
tests/treeTest.cpp
View file @
9bea44fc
...
...
@@ -40,7 +40,7 @@ using algorithms::buildTree;
BOOST_AUTO_TEST_SUITE
(
EFGTests
)
BOOST_AUTO_TEST_CASE
(
BuildTree
)
{
BOOST_AUTO_TEST_CASE
(
BuildTree
MaxDepth
)
{
MatchingPenniesDomain
mp
;
auto
rootNodes
=
createRootEFGNodes
(
mp
.
getRootStatesDistribution
());
EFGCache
cache
(
rootNodes
);
...
...
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(BuildTree) {
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
rootNode
->
performAction
(
actions
[
0
]);
rootNode
->
performAction
(
actions
[
0
]);
rootNode
->
performAction
(
actions
[
1
]);
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
0
]));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
...
...
@@ -67,6 +67,48 @@ BOOST_AUTO_TEST_CASE(BuildTree) {
// todo: make test(s) based on comparing domain statistics
}
BOOST_AUTO_TEST_CASE
(
BuildTreeLimitedDepth
)
{
MatchingPenniesDomain
mp
;
auto
rootNodes
=
createRootEFGNodes
(
mp
.
getRootStatesDistribution
());
EFGCache
cache
(
rootNodes
);
auto
rootNode
=
rootNodes
[
0
].
first
;
auto
actions
=
rootNode
->
availableActions
();
BOOST_CHECK
(
cache
.
hasNode
(
rootNode
));
BOOST_CHECK
(
cache
.
hasInfoset
(
rootNode
->
getAOHInfSet
()));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
0
]));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
auto
node0
=
rootNode
->
performAction
(
actions
[
0
])[
0
].
first
;
auto
node1
=
rootNode
->
performAction
(
actions
[
1
])[
0
].
first
;
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
0
]));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
buildTree
(
&
cache
,
0
);
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
0
]));
BOOST_CHECK
(
!
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
BOOST_CHECK
(
!
cache
.
hasChildren
(
node0
));
BOOST_CHECK
(
!
cache
.
hasChildren
(
node1
));
buildTree
(
&
cache
,
1
);
BOOST_CHECK
(
cache
.
hasChildren
(
rootNode
));
BOOST_CHECK
(
cache
.
hasChildren
(
rootNode
,
actions
[
0
]));
BOOST_CHECK
(
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
BOOST_CHECK
(
!
cache
.
hasChildren
(
node0
));
BOOST_CHECK
(
!
cache
.
hasChildren
(
node1
));
buildTree
(
&
cache
,
2
);
BOOST_CHECK
(
cache
.
hasChildren
(
rootNode
));
BOOST_CHECK
(
cache
.
hasChildren
(
rootNode
,
actions
[
0
]));
BOOST_CHECK
(
cache
.
hasChildren
(
rootNode
,
actions
[
1
]));
BOOST_CHECK
(
cache
.
hasChildren
(
node0
));
BOOST_CHECK
(
cache
.
hasChildren
(
node1
));
}
BOOST_AUTO_TEST_SUITE_END
()
}
// namespace GTLib2
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment