Skip to content

Commit d235b32

Browse files
committed
clean up HOA accepting states
The HOAs generated by Spot can now be transformed into a graph. This graph is used to remove accepting states that are not part of a cycle.
1 parent 8b6c449 commit d235b32

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/temporal-logic/hoa.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,40 @@ void hoat::output(std::ostream &out) const
543543

544544
out << "--END--\n";
545545
}
546+
547+
grapht<graph_nodet<hoat::graph_edget>> hoat::graph() const
548+
{
549+
grapht<graph_nodet<hoat::graph_edget>> graph;
550+
551+
graph.resize(numeric_cast_v<std::size_t>(max_state_number() + 1));
552+
553+
for(auto &state : body)
554+
{
555+
for(auto &edge : state.second)
556+
for(auto &dest : edge.dest_states)
557+
{
558+
graph.add_edge(state.first.number, dest);
559+
graph.edge(state.first.number, dest).label = edge.label;
560+
}
561+
}
562+
563+
return graph;
564+
}
565+
566+
void hoat::buechi_acceptance_cleanup()
567+
{
568+
using hoa_grapht = grapht<graph_nodet<hoat::graph_edget>>;
569+
auto as_graph = graph();
570+
for(auto &state : body)
571+
{
572+
if(state.first.is_accepting())
573+
{
574+
hoa_grapht::patht loop_path;
575+
as_graph.shortest_loop(state.first.number, loop_path);
576+
// when this state is not part of any cycle,
577+
// then we cannot have Buechi acceptance via this state
578+
if(loop_path.empty())
579+
state.first.acc_sig.clear();
580+
}
581+
}
582+
}

src/temporal-logic/hoa.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, dkr@amazon.com
99
#ifndef CPROVER_TEMPORAL_LOGIC_HOA_H
1010
#define CPROVER_TEMPORAL_LOGIC_HOA_H
1111

12+
#include <util/graph.h>
1213
#include <util/irep.h>
1314

1415
#include <cstdint>
@@ -68,6 +69,19 @@ class hoat
6869

6970
// atomic propositions
7071
std::map<intt, std::string> ap_map;
72+
73+
// convert into a graph
74+
struct graph_edget
75+
{
76+
labelt label;
77+
};
78+
79+
grapht<graph_nodet<graph_edget>> graph() const;
80+
81+
// Remove accepting states that are not part of a cycle.
82+
// These are irrelevant when using the standard Buechi
83+
// acceptance criterion.
84+
void buechi_acceptance_cleanup();
7185
};
7286

7387
#endif // CPROVER_TEMPORAL_LOGIC_HOA_H

src/temporal-logic/ltl_to_buechi.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ ltl_to_buechi(const exprt &property, message_handlert &message_handler)
135135

136136
message.debug() << hoa << messaget::eom;
137137

138+
// clean up accepting states
139+
hoa.buechi_acceptance_cleanup();
140+
138141
auto max_state_number = hoa.max_state_number();
139142
auto state_type = range_typet{0, max_state_number};
140143
const auto buechi_state = symbol_exprt{"buechi::state", state_type};

0 commit comments

Comments
 (0)