From a0cce10512a00c15d97349a168a626db4f4616b9 Mon Sep 17 00:00:00 2001 From: Thomas Badie Date: Sat, 18 Aug 2012 15:30:43 +0200 Subject: [PATCH] Create the iterated simulations. * src/tgbaalgos/simulation.cc: Create the iterated_simulations. (direct_simulation) Add an attribute "stat" that represents the number of states and transitions of the resulting automaton. * src/tgbaalgos/simulation.hh: Declare the iterated_simulations. * src/tgbatest/spotlbtt.test: Test the iterated_simulations. * src/tgbatest/ltl2tgba.cc: Associate the option -RIS to the iterated_simulations. --- src/tgbaalgos/simulation.cc | 69 +++++++++++++++++++++++++++++++++++-- src/tgbaalgos/simulation.hh | 6 ++++ src/tgbatest/ltl2tgba.cc | 20 +++++++++++ src/tgbatest/spotlbtt.test | 8 +++++ 4 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/tgbaalgos/simulation.cc b/src/tgbaalgos/simulation.cc index be4c9831e..4131c2c67 100644 --- a/src/tgbaalgos/simulation.cc +++ b/src/tgbaalgos/simulation.cc @@ -28,6 +28,7 @@ #include "misc/minato.hh" #include "tgba/bddprint.hh" #include "tgbaalgos/reachiter.hh" +#include "tgbaalgos/sccfilter.hh" // The way we developed this algorithm is the following: We take an // automaton, and reverse all these acceptance conditions. We reverse @@ -104,6 +105,22 @@ namespace spot typedef std::map, bdd_less_than> map_bdd_lstate; + struct automaton_size + { + automaton_size() + : transitions(0), + states(0) + { + } + + inline bool operator!= (const automaton_size& r) + { + return transitions != r.transitions || states != r.states; + } + + int transitions; + int states; + }; // This class takes an automaton and creates a copy with all // acceptance conditions complemented. @@ -146,7 +163,6 @@ namespace spot int src = get_state(in_s); int dst = get_state(out_s); - // In the case of the cosimulation, we want to have all the // ingoing transition, and to keep the rest of the code // similar, we just create equivalent transition in the other @@ -223,7 +239,6 @@ namespace spot bdd init = bdd_ithvar(set_num++); used_var_.push_back(init); - all_class_var_ = init; // We fetch the result the run of acc_compl_automaton which // has recorded all the state in a hash table, and we set all @@ -240,6 +255,7 @@ namespace spot // of these in a variable all_class_var_ which will be used // to understand the destination part in the signature when // building the resulting automaton. + all_class_var_ = init; for (unsigned i = set_num; i < set_num + size_a_ - 1; ++i) { free_var_.push(i); @@ -443,6 +459,14 @@ namespace spot } } + automaton_size get_stat() const + { + assert(stat.states != 0); + + return stat; + } + + // Build the minimal resulting automaton. tgba* build_result() { @@ -489,6 +513,9 @@ namespace spot bdd2state[relation_[part]] = current_max; } + stat.states = bdd_lstate_.size(); + stat.transitions = 0; + // For each partition, we will create // all the transitions between the states. for (map_bdd_lstate::iterator it = bdd_lstate_.begin(); @@ -533,6 +560,8 @@ namespace spot bdd cond_acc_dest; while ((cond_acc_dest = isop.next()) != bddfalse) { + ++stat.transitions; + // Take the transition, and keep only the variable which // are used to represent the class. bdd dest = bdd_existcomp(cond_acc_dest, @@ -665,6 +694,8 @@ namespace spot // Initial state of the automaton we are working on state* initial_state; + automaton_size stat; + }; } // End namespace anonymous. @@ -685,4 +716,38 @@ namespace spot return simul.run(); } + tgba* + iterated_simulations(const tgba* t) + { + tgba* res = const_cast (t); + automaton_size prev; + automaton_size next; + + do + { + prev = next; + direct_simulation simul(res); + + tgba* after_simulation = simul.run(); + + if (res != t) + delete res; + + direct_simulation cosimul(after_simulation); + + tgba* after_cosimulation = cosimul.run(); + + next = cosimul.get_stat(); + + res = scc_filter(after_cosimulation, false); + + delete after_cosimulation; + delete after_simulation; + } + while (prev != next); + + return res; + } + + } // End namespace spot. diff --git a/src/tgbaalgos/simulation.hh b/src/tgbaalgos/simulation.hh index b6e6b21d1..4a3159126 100644 --- a/src/tgbaalgos/simulation.hh +++ b/src/tgbaalgos/simulation.hh @@ -85,6 +85,12 @@ namespace spot /// one tgba* cosimulation(const tgba* automaton); + + /// \brief Run a loop: simulation / cosimulation / scc_filter until + /// a fix point is reached. + tgba* iterated_simulations(const tgba* automaton); + + /// @} } // End namespace spot. diff --git a/src/tgbatest/ltl2tgba.cc b/src/tgbatest/ltl2tgba.cc index c06fac474..555c5cb6b 100644 --- a/src/tgbatest/ltl2tgba.cc +++ b/src/tgbatest/ltl2tgba.cc @@ -206,6 +206,9 @@ syntax(char* prog) << std::endl << " -RRS minimize the automaton with reverse simulation" << std::endl + << " -RPS minimize the automaton with an alternance" + << " reverse simulation and simulation" + << std::endl << " -Rm attempt to WDBA-minimize the automata" << std::endl << std::endl @@ -355,6 +358,7 @@ main(int argc, char** argv) bool assume_sba = false; bool reduction_dir_sim = false; bool reduction_rev_sim = false; + bool reduction_iterated_sim = false; spot::tgba* temp_dir_sim = 0; bool ta_opt = false; bool tgta_opt = false; @@ -362,6 +366,8 @@ main(int argc, char** argv) bool opt_single_pass_emptiness_check = false; bool opt_with_artificial_livelock = false; spot::tgba* temp_rev_sim = 0; + spot::tgba* temp_iterated_sim = 0; + for (;;) { @@ -663,6 +669,10 @@ main(int argc, char** argv) { reduction_dir_sim = true; } + else if (!strcmp(argv[formula_index], "-RIS")) + { + reduction_iterated_sim = true; + } else if (!strcmp(argv[formula_index], "-rL")) { simpltl = true; @@ -1062,6 +1072,15 @@ main(int argc, char** argv) assume_sba = false; } + if (reduction_iterated_sim) + { + tm.start("Reduction w/ iterated simulations"); + temp_iterated_sim = spot::iterated_simulations(a); + a = temp_iterated_sim; + tm.stop("Reduction w/ iterated simulations"); + assume_sba = false; + } + unsigned int n_acc = a->number_of_acceptance_conditions(); if (echeck_inst @@ -1523,6 +1542,7 @@ main(int argc, char** argv) delete echeck_inst; delete temp_dir_sim; delete temp_rev_sim; + delete temp_iterated_sim; } else { diff --git a/src/tgbatest/spotlbtt.test b/src/tgbatest/spotlbtt.test index 241f7b178..ec5d830c5 100755 --- a/src/tgbatest/spotlbtt.test +++ b/src/tgbatest/spotlbtt.test @@ -207,6 +207,14 @@ Algorithm Enabled = yes } +Algorithm +{ + Name = "Spot (Couvreur -- FM), iterated simulation" + Path = "${LBTT_TRANSLATE}" + Parameters = "--spot '../ltl2tgba -F -f -t -RIS -r4 -R3'" + Enabled = yes +} + Algorithm {