11
12
13
14
15
16
18#ifndef MCRL2_LTS_LTS_UTILITIES_H
19#define MCRL2_LTS_LTS_UTILITIES_H
21#include "mcrl2/lts/lts_lts.h"
27
28
29
30
31template<
class LTS_TYPE>
34 for (
const transition& tr: ltsspec.get_transitions())
36 std::size_t label = tr.label();
37 if (label >= ltsspec.action_labels().size())
39 throw mcrl2::runtime_error(
"Invalid LTS detected: there are not enough action labels");
45
46
47
48template<
class LTS_TYPE>
51 std::set<std::size_t> used_labels;
52 for (
const transition& tr: ltsspec.get_transitions())
54 used_labels.insert(tr.label());
56 std::set<process::action_label> result;
57 const auto& action_labels = ltsspec.action_labels();
58 for (std::size_t index: used_labels)
60 for (
const process::
action& a: action_labels[index].actions())
62 result.insert(a.label());
69
70
71
72
73
122
123
124
125
126
134template <
bool USE_STACK>
143 for(std::pair<std::size_t, std::size_t> p: count_sum_transitions_per_action){ assert(p.first==0); }
144 assert(todo_stack.empty());
149 todo_stack.push_back(tau_label_index);
151 for(std::vector<transition>::iterator ti=begin; ti!=end; ++ti)
153 const transition& t=*ti;
154 std::size_t label=get_label(t);
155 if (USE_STACK && label!=tau_label_index && count_sum_transitions_per_action[label].first==0)
157 todo_stack.push_back(label);
159 count_sum_transitions_per_action[label].first++;
168 for(std::size_t a: todo_stack)
170 sum=sum+count_sum_transitions_per_action[a].first;
171 count_sum_transitions_per_action[a].second=sum;
176 for(std::pair<std::size_t, std::size_t>& p: count_sum_transitions_per_action)
184 std::vector<transition>::iterator current_leftmost_position=begin;
185 std::vector<std::size_t>::iterator current_leftmost_label=todo_stack.begin();
186 std::size_t current_label=USE_STACK?*current_leftmost_label:0;
187 while (current_leftmost_position!=end)
191 assert(current_leftmost_label!=todo_stack.end());
192 while (count_sum_transitions_per_action[current_label].first==0)
194 current_leftmost_label++;
195 if (current_leftmost_label==todo_stack.end())
199 current_label=*current_leftmost_label;
202 if (current_leftmost_label==todo_stack.end())
209 while (current_label<count_sum_transitions_per_action.size() &&
210 count_sum_transitions_per_action[current_label].first==0)
215 if (current_label==count_sum_transitions_per_action.size())
220 current_leftmost_position=begin+
221 static_cast<std::ptrdiff_t>(count_sum_transitions_per_action[current_label].second-
222 count_sum_transitions_per_action[current_label].first);
227 while (current_leftmost_position!=end && get_label(*current_leftmost_position)==current_label)
229 current_leftmost_position++;
230 count_sum_transitions_per_action[current_label].first--;
234 if (count_sum_transitions_per_action[current_label].first>0)
238 transition transition_on_the_move= *current_leftmost_position;
241 std::size_t label=get_label(transition_on_the_move);
242 std::size_t new_position=count_sum_transitions_per_action[label].second-count_sum_transitions_per_action[label].first;
243 assert(0<std::distance(begin,end)-new_position);
244 count_sum_transitions_per_action[label].first--;
246 while (get_label(*(begin+
static_cast<std::ptrdiff_t>(new_position)))==label)
249 count_sum_transitions_per_action[label].first--;
251 assert(get_label(transition_on_the_move)!=get_label(*(begin+new_position)));
252 std::swap(transition_on_the_move,*(begin+
static_cast<std::ptrdiff_t>(new_position)));
254 while (get_label(transition_on_the_move)!=current_label);
256 *current_leftmost_position=transition_on_the_move;
257 current_leftmost_position++;
258 count_sum_transitions_per_action[current_label].first--;
432
433
434
570 return i->first.first;
576 return i->first.second;
588 outgoing_transitions_per_state_action_t result;
589 for (
const transition& t: trans)
591 result.insert(std::pair<std::pair<transition::size_type, transition::size_type>, transition::size_type>(
592 std::pair<transition::size_type, transition::size_type>(t.from(), t.label()), t.to()));
602 outgoing_transitions_per_state_action_t result;
603 for (
const transition& t: trans)
605 result.insert(std::pair<std::pair<transition::size_type, transition::size_type>, transition::size_type>(
606 std::pair<transition::size_type, transition::size_type>(t.from(), detail::apply_hidden_labels(t.label(),hide_label_set)), t.to()));
614 outgoing_transitions_per_state_action_t result;
615 for (
const transition& t: trans)
617 result.insert(std::pair<std::pair<transition::size_type, transition::size_type>, transition::size_type>(
618 std::pair<transition::size_type, transition::size_type>(t.to(), t.label()), t.from()));
628 outgoing_transitions_per_state_action_t result;
629 for (
const transition& t: trans)
631 result.insert(std::pair<std::pair<transition::size_type, transition::size_type>, transition::size_type>(
632 std::pair<transition::size_type, transition::size_type>(t.to(), detail::apply_hidden_labels(t.label(),hide_label_set)), t.from()));
641template <
class LABEL_TYPE >
645 return LABEL_TYPE(s);
649inline mcrl2::
lts::
action_label_lts make_divergence_label<mcrl2::lts::action_label_lts>(
const std::string& s)
651 return action_label_lts(lps::multi_action(process::action(process::action_label(core::identifier_string(s),
652 data::sort_expression_list()),
653 data::data_expression_list())));
658template <
class LTS_TYPE >
662 const typename LTS_TYPE::action_label_t lab=make_divergence_label<
typename LTS_TYPE::action_label_t>(
"!@*&divergence&*@!");
663 std::size_t divergent_transition_label=l.add_action(lab);
664 assert(divergent_transition_label+1==l.num_action_labels());
665 for(transition& t: l.get_transitions())
667 if (l.is_tau(l.apply_hidden_label_map(t.label())) && t.to()==t.from())
669 t = transition(t.to(),divergent_transition_label,t.to());
672 return divergent_transition_label;
676template <
class LTS_TYPE >
679 for(transition& t: l.get_transitions())
681 if (t.label()==divergent_transition_label)
683 t = transition(t.from(),l.tau_label_index(),t.from());
aterm(const aterm &other) noexcept=default
This class has user-declared copy constructor so declare default copy and move operators.
A unordered_map class in which aterms can be stored.
\brief An untyped parameter
\brief A timed multi-action
const process::action_list & actions() const
A class containing the values for action labels for the .lts format.
std::vector< bool > block_flags
state_type max_state_index
mcrl2::state_formulas::state_formula conjunction(std::set< mcrl2::state_formulas::state_formula > terms) const
conjunction Creates a conjunction of state formulas
regular_formulas::regular_formula create_regular_formula(const mcrl2::lts::action_label_string &a) const
create_regular_formula Creates a regular formula that represents action a
regular_formulas::regular_formula create_regular_formula(const mcrl2::lps::multi_action &a) const
create_regular_formula Creates a regular formula that represents action a
std::vector< bool > block_is_in_to_be_processed
std::vector< bool > state_flags
std::map< block_index_type, block_index_type > right_child
std::vector< block_index_type > BL
bool in_same_class(const std::size_t s, const std::size_t t) const
Returns whether two states are in the same bisimulation equivalence class.
mcrl2::state_formulas::state_formula until_formula(const mcrl2::state_formulas::state_formula &phi1, const label_type &a, const mcrl2::state_formulas::state_formula &phi2)
until_formula Creates a state formula that corresponds to the until operator phi1phi2 from HMLU
std::size_t get_eq_class(const std::size_t s) const
Gives the bisimulation equivalence class number of a state.
bisim_partitioner(LTS_TYPE &l, const bool branching=false, const bool preserve_divergence=false, const bool generate_counter_examples=false)
Creates a bisimulation partitioner for an LTS.
~bisim_partitioner()=default
Destroys this partitioner.
std::map< block_index_type, label_type > split_by_action
std::size_t num_eq_classes() const
Gives the number of bisimulation equivalence classes of the LTS.
mcrl2::state_formulas::state_formula counter_formula(std::size_t s, std::size_t t)
Creates a state formula that distinguishes state s from state t.
void order_recursively_on_tau_reachability(const state_type s, std::map< state_type, std::vector< state_type > > &inert_transition_map, std::vector< non_bottom_state > &new_non_bottom_states, std::set< state_type > &visited)
std::vector< block_index_type > to_be_processed
std::map< block_index_type, block_index_type > split_by_block
void refine_partion_with_respect_to_divergences()
void replace_transition_system(const bool branching, const bool preserve_divergences)
Replaces the transition relation of the current lts by the transitions of the bisimulation reduced tr...
std::vector< block > blocks
void order_on_tau_reachability(std::vector< non_bottom_state > &non_bottom_states)
void split_the_blocks_in_BL(bool &partition_is_unstable, const label_type splitter_label, const block_index_type splitter_block)
void refine_partition_until_it_becomes_stable(const bool branching, const bool preserve_divergence)
void create_initial_partition(const bool branching, const bool preserve_divergences)
std::vector< state_type > block_index_of_a_state
mcrl2::state_formulas::state_formula counter_formula_aux(const block_index_type B1, const block_index_type B2)
void check_internal_consistency_of_the_partitioning_data_structure(const bool branching, const bool preserve_divergence) const
outgoing_transitions_per_state_action_t outgoing_transitions
function object to compare two constln_t pointers based on their contents
A class that can be used to store counterexample trees and.
A class that contains a labelled transition system.
Class for computing the signature for strong bisimulation.
Class for computing the signature for branching bisimulation.
Class for computing the signature for divergence preserving branching bisimulation.
Signature based reductions for labelled transition systems.
\brief An untyped multi action or data application
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
bool is_data_expression(const atermpp::aterm &x)
Test for a data_expression expression.
bool is_untyped_data_parameter(const atermpp::aterm &x)
The main namespace for the LPS library.
bool bisimulation_compare(const LTS_TYPE &l1, const LTS_TYPE &l2, bool branching=false, bool preserve_divergences=false, bool generate_counter_examples=false, const std::string &counter_example_file="", bool structured_output=false)
Checks whether the two initial states of two lts's are strong or branching bisimilar.
lts_type guess_format(std::string const &s, const bool be_verbose)
Determines the LTS format from a filename by its extension.
static const std::array< std::string, 5 > extension_strings
std::string supported_lts_formats_text(const std::set< lts_type > &supported)
Gives a textual list describing supported LTS formats.
std::string string_for_type(const lts_type type)
Gives a string representation of an LTS format.
void unmark_explicit_divergence_transitions(LTS_TYPE &l, const std::size_t divergent_transition_label)
std::string mime_type_for_type(const lts_type type)
Gives the MIME type associated with an LTS format.
void get_trans(const outgoing_transitions_per_state_t &begin, tree_set_store &tss, std::ptrdiff_t d, std::vector< transition > &d_trans, LTS_TYPE &aut)
lts_type parse_format(std::string const &s)
Determines the LTS format from a format specification string.
static const std::array< std::string, 5 > type_strings
std::string extension_for_type(const lts_type type)
Gives the filename extension associated with an LTS format.
LABEL_TYPE make_divergence_label(const std::string &s)
const std::set< lts_type > & supported_lts_formats()
Gives the set of all supported LTS formats.
std::string lts_extensions_as_string(const std::set< lts_type > &supported)
Gives a list of extensions for supported LTS formats.
std::string lts_extensions_as_string(const std::string &sep, const std::set< lts_type > &supported)
Gives a list of extensions for supported LTS formats.
std::size_t mark_explicit_divergence_transitions(LTS_TYPE &l)
bool destructive_bisimulation_compare(LTS_TYPE &l1, LTS_TYPE &l2, bool branching=false, bool preserve_divergences=false, bool generate_counter_examples=false, const std::string &counter_example_file="", bool structured_output=false)
Checks whether the two initial states of two lts's are strong or branching bisimilar.
void bisimulation_reduce(LTS_TYPE &l, bool branching=false, bool preserve_divergences=false)
Reduce transition system l with respect to strong or (divergence preserving) branching bisimulation.
bool lts_named_cmp(const std::array< std::string, Size > &N, T a, T b)
std::string supported_lts_formats_text(lts_type default_format, const std::set< lts_type > &supported)
Gives a textual list describing supported LTS formats.
static const std::array< std::string, 5 > type_desc_strings
static const std::array< std::string, 5 > mime_type_strings
static const std::set< lts_type > & initialise_supported_lts_formats()
bool destructive_compare(LTS_TYPE &l1, LTS_TYPE &l2, lts_preorder pre, bool generate_counter_example, const std::string &counter_example_file="", bool structured_output=false, lps::exploration_strategy strategy=lps::exploration_strategy::es_breadth, bool preprocess=true)
Checks whether this LTS is smaller than another LTS according to a preorder.
void check_lts(const LTS_TYPE <sspec)
Throws a runtime error if the LTS contains a transition with an invalid action label index.
std::set< process::action_label > find_action_labels(const LTS_TYPE <sspec)
Returns the action labels that occur in the transitions of the given LTS.
bool is_deterministic(const LTS_TYPE &l)
Checks whether this LTS is deterministic.
outgoing_transitions_per_state_action_t transitions_per_outgoing_state_action_pair_reversed(const std::vector< transition > &trans)
Provide the transitions as a multimap accessible per from state and label, ordered backwardly.
void group_transitions_on_label(std::vector< transition > &transitions, std::function< std::size_t(const transition &)> get_label, const std::size_t number_of_labels, const std::size_t tau_label_index)
std::size_t to(const outgoing_pair_t &p)
Target state of a label state pair.
outgoing_transitions_per_state_action_t transitions_per_outgoing_state_action_pair(const std::vector< transition > &trans)
Provide the transitions as a multimap accessible per from state and label.
void determinise(LTS_TYPE &l)
Determinises this LTS.
bool compare(const LTS_TYPE &l1, const LTS_TYPE &l2, lts_preorder pre, bool generate_counter_example, const std::string &counter_example_file="", bool structured_output=false, lps::exploration_strategy strategy=lps::exploration_strategy::es_breadth, bool preprocess=true)
Checks whether this LTS is smaller than another LTS according to a preorder.
void reduce(LTS_TYPE &l, lts_equivalence eq)
Applies a reduction algorithm to this LTS.
bool compare(const LTS_TYPE &l1, const LTS_TYPE &l2, lts_equivalence eq, bool generate_counter_examples=false, const std::string &counter_example_file="", bool structured_output=false)
Checks whether this LTS is equivalent to another LTS.
outgoing_transitions_per_state_action_t transitions_per_outgoing_state_action_pair_reversed(const std::vector< transition > &trans, const std::set< transition::size_type > &hide_label_set)
Provide the transitions as a multimap accessible per from state and label, ordered backwardly.
bool destructive_compare(LTS_TYPE &l1, LTS_TYPE &l2, const lts_equivalence eq, const bool generate_counter_examples=false, const std::string &counter_example_file=std::string(), const bool structured_output=false)
Checks whether this LTS is equivalent to another LTS.
outgoing_transitions_per_state_action_t transitions_per_outgoing_state_action_pair(const std::vector< transition > &trans, const std::set< transition::size_type > &hide_label_set)
Provide the transitions as a multimap accessible per from state and label.
void merge(LTS_TYPE &l1, const LTS_TYPE &l2)
Merge the second lts into the first lts.
bool reachability_check(lts< SL, AL, BASE > &l, bool remove_unreachable=false)
Checks whether all states in this LTS are reachable from the initial state and remove unreachable sta...
std::size_t label(const outgoing_pair_t &p)
Label of a pair of a label and target state.
std::size_t from(const outgoing_transitions_per_state_action_t::const_iterator &i)
From state of an iterator exploring transitions per outgoing state and action.
void group_transitions_on_label(const std::vector< transition >::iterator begin, const std::vector< transition >::iterator end, std::function< std::size_t(const transition &)> get_label, std::vector< std::pair< std::size_t, std::size_t > > &count_sum_transitions_per_action, const std::size_t tau_label_index=0, std::vector< std::size_t > &todo_stack=bogus_todo_stack)
bool reachability_check(probabilistic_lts< SL, AL, PROBABILISTIC_STATE, BASE > &l, bool remove_unreachable=false)
Checks whether all states in a probabilistic LTS are reachable from the initial state and remove unre...
void sort_transitions(std::vector< transition > &transitions, const std::set< transition::size_type > &hidden_label_set, transition_sort_style ts=transition_sort_style::src_lbl_tgt)
Sorts the transitions using a sort style.
The main namespace for the Process library.
bool is_untyped_multi_action(const atermpp::aterm &x)
static const atermpp::aterm StateMay
static const atermpp::aterm StateOr
static const atermpp::aterm UntypedRegFrm
static const atermpp::aterm StateFrm
static const atermpp::aterm StateYaled
static const atermpp::aterm RegAlt
static const atermpp::aterm ActNot
static const atermpp::aterm ActImp
static const atermpp::aterm ActTrue
static const atermpp::aterm StateInfimum
static const atermpp::aterm StateAnd
static const atermpp::aterm StateExists
static const atermpp::aterm RegTrans
static const atermpp::aterm ActOr
static const atermpp::aterm StateConstantMultiplyAlt
static const atermpp::aterm ActFrm
static const atermpp::aterm ActForall
static const atermpp::aterm StateYaledTimed
static const atermpp::aterm ActFalse
static const atermpp::aterm StateFalse
static const atermpp::aterm RegFrm
static const atermpp::aterm StateDelay
static const atermpp::aterm StatePlus
static const atermpp::aterm StateMinus
static const atermpp::aterm StateNu
static const atermpp::aterm ActAnd
static const atermpp::aterm StateDelayTimed
static const atermpp::aterm StateSupremum
static const atermpp::aterm StateSum
static const atermpp::aterm ActAt
static const atermpp::aterm ActExists
static const atermpp::aterm StateMu
static const atermpp::aterm RegTransOrNil
static const atermpp::aterm StateVar
static const atermpp::aterm StateImp
static const atermpp::aterm RegSeq
static const atermpp::aterm StateTrue
static const atermpp::aterm StateForall
static const atermpp::aterm StateMust
static const atermpp::aterm StateNot
static const atermpp::aterm ActMultAct
static const atermpp::aterm StateConstantMultiply
std::vector< state_type > bottom_states
block_index_type parent_block_index
block_index_type block_index
void swap(block &b) noexcept
std::vector< transition > non_inert_transitions
std::vector< non_bottom_state > non_bottom_states
std::vector< state_type > inert_transitions
non_bottom_state(const state_type s, const std::vector< state_type > &it)
non_bottom_state(const state_type s)