Skip to content

Commit ed1ed3f

Browse files
authored
Kill tactic recursively (#27)
* fix: use kill_tactic of graph rather than node for recursive calls * fix: store ancestor set before iterating * test: propagate killed tactic through two theorems
1 parent 44c1d75 commit ed1ed3f

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

src/graph/graph.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,9 +1535,14 @@ namespace htps {
15351535
std::shared_ptr<T> node_ptr = std::make_shared<T>(node);
15361536
nodes.set(th, node_ptr);
15371537
if (node.is_bad()) {
1538-
for (const auto &[parent_th, tactic_id]: ancestors.get_ancestors(th)) {
1538+
const AncestorSet anc = ancestors.get_ancestors(th);
1539+
for (const auto &[parent_th, tactic_id]: anc) {
15391540
if (!parent_th.empty()) {
1540-
nodes.at(parent_th)->kill_tactic(tactic_id);
1541+
if (!nodes.contains(parent_th)) {
1542+
std::string msg = "Parent node not found: " + parent_th;
1543+
throw std::runtime_error(msg);
1544+
}
1545+
kill_tactic(nodes.at(parent_th), tactic_id);
15411546
}
15421547
}
15431548
continue;

tests/htps_tests.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,65 @@ TEST_F(HTPSTest, TestAddToKilled) {
920920
EXPECT_TRUE(proof_samples_tactics.empty());
921921
}
922922

923+
/* If the last child of a node is killed, the corresponding parent should be killed too.
924+
*/
925+
TEST_F(HTPSTest, TestKilledRecursively) {
926+
htps_instance->theorems_to_expand();
927+
928+
TheoremPointer child1 = static_pointer_cast<htps::theorem>(std::make_shared<DummyTheorem>("B1"));
929+
std::vector<std::shared_ptr<htps::env_effect>> effects;
930+
auto effect = std::make_shared<htps::env_effect>();
931+
effect->goal = root;
932+
effect->tac = dummyTac;
933+
effect->children = {child1};
934+
effects.push_back(effect);
935+
936+
std::vector<std::shared_ptr<htps::tactic>> tactics = {dummyTac};
937+
std::vector<std::vector<htps::TheoremPointer>> childrenForTactic = {{child1}};
938+
std::vector<double> priors = {1.0};
939+
std::vector<size_t> envDurations = {1};
940+
941+
htps::env_expansion expansion(root, 1, 1, envDurations, effects, 0.0, tactics, childrenForTactic, priors);
942+
std::vector<std::shared_ptr<htps::env_expansion>> expansions = {std::make_shared<htps::env_expansion>(expansion)};
943+
944+
htps_instance->expand_and_backup(expansions);
945+
expansions.clear();
946+
947+
auto theorems = htps_instance->theorems_to_expand();
948+
EXPECT_TRUE(theorems[0] == child1 && theorems.size() == 1);
949+
950+
TheoremPointer child2 = static_pointer_cast<htps::theorem>(std::make_shared<DummyTheorem>("B2"));
951+
effects.clear();
952+
effect = std::make_shared<htps::env_effect>();
953+
effect->goal = root;
954+
effect->tac = dummyTac2;
955+
effect->children = {child2};
956+
effects.push_back(effect);
957+
958+
tactics = {dummyTac2};
959+
childrenForTactic = {{child2}};
960+
priors = {1.0};
961+
envDurations = {1};
962+
expansion = {child1, 1, 1, envDurations, effects, 0.0, tactics, childrenForTactic, priors};
963+
expansions = {std::make_shared<htps::env_expansion>(expansion)};
964+
htps_instance->expand_and_backup(expansions);
965+
expansions.clear();
966+
967+
theorems = htps_instance->theorems_to_expand();
968+
EXPECT_TRUE(theorems[0] == child2 && theorems.size() == 1);
969+
970+
envDurations = {1, 1, 1};
971+
std::string error = "This is broken!";
972+
expansion = {child2, 1, 1, envDurations, error};
973+
expansions = {std::make_shared<htps::env_expansion>(expansion)};
974+
htps_instance->expand_and_backup(expansions);
975+
976+
htps_instance->theorems_to_expand();
977+
EXPECT_TRUE(htps_instance->is_done());
978+
EXPECT_FALSE(htps_instance->is_proven());
979+
EXPECT_TRUE(htps_instance->dead_root());
980+
}
981+
923982
/* Two tactics leading to the same children from the same starting node.
924983
*/
925984
TEST_F(HTPSTest, TestMultipleSame) {

0 commit comments

Comments
 (0)