19#ifndef MCRL2_LTS_DETAIL_LTS_CONVERT_H
20#define MCRL2_LTS_DETAIL_LTS_CONVERT_H
44 throw mcrl2::runtime_error(
"Cannot convert the probability " +
pp(d) +
" to an arbitrary size denominator/enumerator pair.");
49template <
class PROBABILISTIC_STATE1,
class PROBABILISTIC_STATE2>
57lts_convert_probabilistic_state<probabilistic_state<std::size_t, lps::probabilistic_data_expression>,
65inline probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>
66lts_convert_probabilistic_state<probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>,
67 probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction> >(
68 const probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>& state_in)
74inline probabilistic_state<std::size_t, lps::probabilistic_data_expression>
75lts_convert_probabilistic_state<probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>,
76 probabilistic_state<std::size_t, lps::probabilistic_data_expression> >(
77 const probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>& state_in)
79 if (state_in.size()<=1)
81 return probabilistic_state<std::size_t, lps::probabilistic_data_expression>(state_in.get());
84 std::vector<lps::state_probability_pair<std::size_t, lps::probabilistic_data_expression> > result;
85 for(
const lps::state_probability_pair<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>& p: state_in)
87 result.emplace_back(p.state(), lps::probabilistic_data_expression(
pp(p.probability().enumerator()),
pp(p.probability().denominator())));
89 return probabilistic_state<std::size_t, lps::probabilistic_data_expression>(result.begin(), result.end());
99 throw mcrl2::runtime_error(
"Cannot convert the probability " +
pp(d) +
" to an explicit denominator/enumerator pair.");
106lts_convert_probabilistic_state<probabilistic_state<std::size_t, lps::probabilistic_data_expression>,
110 if (state_in.size()<=1)
115 std::vector<lps::state_probability_pair<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction> > result;
120 translate_probability_data_prob(p.probability())));
122 return probabilistic_state<std::size_t, mcrl2::utilities::probabilistic_arbitrary_precision_fraction>(result.begin(), result.end());
137template <
class BASE_LTS_IN,
class BASE_LTS_OUT>
206 (l.substr(0,1)==
"\"") &&
207 (l.substr(l.size()-1,l.size())==
"\""))
209 l=l.substr(1,l.size()-1);
235 const bool extra_data_is_defined=
true)
237 if (extra_data_is_defined)
239 mCRL2log(
log::warning) <<
"While translating .lts to .lts, additional information (data specification, action declarations and process parameters) is ignored.\n";
251 state_label_out=state_label_in;
266 lts_out(lts_base_out)
291 const bool extra_data_is_defined=
true)
293 if (extra_data_is_defined)
295 mCRL2log(
log::warning) <<
"While translating .lts to .fsm, additional information (data specification, action declarations and process parameters) are ignored.\n";
302 state_label_out.clear();
305 if (state_label_in.
size()!=1)
307 assert(state_label_in.
size()>1);
311 static bool warning_is_already_printed=
false;
312 if (!warning_is_already_printed)
315 " state vectors and all but the first label are ignored. This warning is only printed once. ";
316 warning_is_already_printed=
true;
321 local_state_label_in=state_label_in;
325 std::map <data::data_expression , std::size_t >::const_iterator index=c.state_element_values_sets[i].find(t);
326 if (index==c.state_element_values_sets[i].end())
328 const std::size_t element_index=c.state_element_values_sets[i].size();
329 state_label_out.push_back(element_index);
330 c.lts_out.add_state_element_value(i,
data::pp(t));
331 c.state_element_values_sets[i][t]=element_index;
335 state_label_out.push_back(index->second);
353 const bool extra_data_is_defined=
true)
355 if (extra_data_is_defined)
357 mCRL2log(
log::warning) <<
"While translating .lts to .aut, additional information (data specification, action declarations and process parameters) are ignored.\n";
396 const bool extra_data_is_defined=
true)
398 if (extra_data_is_defined)
400 mCRL2log(
log::warning) <<
"While translating .lts to .dot, additional information (data specification, action declarations and process parameters) are ignored.\n";
412 std::stringstream state_name;
413 state_name <<
"s" << c.m_state_count;
430 m_lts_in(lts_base_in), m_lts_out(lts_base_out),
431 m_typechecker(lts_base_out.data(), data::
variable_list(), lts_base_out.action_label_declarations())
438 throw mcrl2::runtime_error(
"Cannot translate .fsm into .lts format without additional LPS information (data, action declarations and process parameters).");
446 const bool extra_data_is_defined=
true)
448 if (extra_data_is_defined)
470 std::vector < data::data_expression > state_label;
474 for (state_label_fsm::const_iterator i=state_label_in.begin(); i!=state_label_in.end(); ++i, ++idx)
476 assert(parameters.
empty() || parameter_iterator!=parameters.
end());
478 if (!parameters.
empty() && (d.
sort()!=parameter_iterator->sort()))
493 pp(parameter_iterator->sort()) +
" does not match with the sort " +
pp(d.
sort()) +
494 " of actual value " +
pp(d) +
".\n" + e.what());
497 state_label.push_back(d);
498 if (!parameters.
empty())
500 ++parameter_iterator;
503 assert(parameter_iterator==parameters.
end());
520 const bool extra_data_is_defined=
true)
522 if (extra_data_is_defined)
524 mCRL2log(
log::warning) <<
"While translating .fsm to .fsm, additional information (data specification, action declarations and process parameters) are ignored.\n";
531 state_label_out=state_label_in;
551 const bool extra_data_is_defined=
true)
553 if (extra_data_is_defined)
555 mCRL2log(
log::warning) <<
"While translating .fsm to .aut, additional information (data specification, action declarations and process parameters) are ignored.\n";
581 : m_state_count(0), m_lts_in(lts_base_in)
596 const bool extra_data_is_defined=
true)
598 if (extra_data_is_defined)
600 mCRL2log(
log::warning) <<
"While translating .fsm to .aut, additional information (data specification, action declarations and process parameters) are ignored.\n";
607 std::stringstream state_name;
608 state_name <<
"s" << c.m_state_count;
611 std::string state_label;
612 if (!state_label_in.empty())
615 for (std::size_t i=0; i<state_label_in.size(); ++i)
617 state_label=state_label + c.m_lts_in.state_element_value(i,state_label_in[i])+(i+1==state_label_in.size()?
")":
",");
640 : m_data(lts_base_out.data()),
641 m_typechecker(m_data, data::
variable_list(), lts_base_out.action_label_declarations())
648 throw mcrl2::runtime_error(
"Cannot translate .aut into .lts format without additional information (data, action declarations and process parameters)");
656 const bool extra_data_is_defined=
true)
658 if (extra_data_is_defined)
699 const bool extra_data_is_defined=
true)
701 if (extra_data_is_defined)
703 mCRL2log(
log::warning) <<
"While translating .aut to .fsm, additional information (data specification, action declarations and process parameters) are ignored.\n";
730 const bool extra_data_is_defined=
true)
732 if (extra_data_is_defined)
734 mCRL2log(
log::warning) <<
"While translating .aut to .aut, additional information (data specification, action declarations and process parameters) are ignored.\n";
741 state_label_out=state_label_in;
761 const bool extra_data_is_defined=
true)
763 if (extra_data_is_defined)
765 mCRL2log(
log::warning) <<
"While translating .aut to .dot, additional information (data specification, action declarations and process parameters) are ignored.\n";
788template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
class STATE_LABEL2,
class ACTION_LABEL2,
class LTS_BASE2>
794 if (lts_in.has_state_info())
796 for (std::size_t i=0; i<lts_in.num_states(); ++i)
800 lts_out.add_state(s);
805 lts_out.set_num_states(lts_in.num_states(),
false);
808 for (std::size_t i=0; i<lts_in.num_action_labels(); ++i)
813 const std::vector<transition>& trans=lts_in.get_transitions();
816 lts_out.add_transition(t);
818 lts_out.set_initial_state(lts_in.initial_state());
820 lts_out.set_hidden_label_set(lts_in.hidden_label_set());
825template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
class STATE_LABEL2,
class ACTION_LABEL2,
class LTS_BASE2>
830 lts_convert_aux<STATE_LABEL1, ACTION_LABEL1, LTS_BASE1,STATE_LABEL2, ACTION_LABEL2, LTS_BASE2>(lts_in,lts_out);
833template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
834 class STATE_LABEL2,
class ACTION_LABEL2,
class LTS_BASE2>
840 const bool extra_data_is_defined=
true)
842 lts_convert_base_class(
static_cast<const LTS_BASE1&
>(lts_in),
static_cast<LTS_BASE2&
>(lts_out), ds, all, vl, extra_data_is_defined);
843 lts_convert_aux<STATE_LABEL1, ACTION_LABEL1, LTS_BASE1,STATE_LABEL2, ACTION_LABEL2, LTS_BASE2>(lts_in,lts_out);
848template <
class STATE_LABEL1,
class ACTION_LABEL1,
class PROBABILISTIC_STATE1,
class LTS_BASE1,
class STATE_LABEL2,
class ACTION_LABEL2,
class LTS_BASE2>
858 throw mcrl2::runtime_error(
"Initial state is probabilistic and cannot be transformed into a non probabilistic state.");
862 std::size_t transition_number=1;
865 std::size_t probabilistic_target_state_number=t.to();
868 throw mcrl2::runtime_error(
"Transition " + std::to_string(transition_number) +
" is probabilistic.");
878template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
class PROBABILISTIC_STATE1,
class STATE_LABEL2,
class ACTION_LABEL2,
class LTS_BASE2>
882 lts_convert<STATE_LABEL1, ACTION_LABEL1, LTS_BASE1, STATE_LABEL2, ACTION_LABEL2, LTS_BASE2>(lts_in,lts_out);
889template <
class STATE_LABEL1,
class ACTION_LABEL1,
class PROBABILISTIC_STATE1,
class LTS_BASE1,
890 class STATE_LABEL2,
class ACTION_LABEL2,
class LTS_BASE2>
896 const bool extra_data_is_defined=
true)
898 lts_convert<STATE_LABEL1, ACTION_LABEL1, LTS_BASE1,STATE_LABEL2, ACTION_LABEL2, LTS_BASE2>(lts_in,lts_out,data,action_label_list,process_parameters,extra_data_is_defined);
904template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
905 class STATE_LABEL2,
class ACTION_LABEL2,
class PROBABILISTIC_STATE2,
class LTS_BASE2>
910 for(std::size_t i=0; i<lts_out.
num_states(); ++i)
917template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
class STATE_LABEL2,
class ACTION_LABEL2,
class PROBABILISTIC_STATE2,
class LTS_BASE2>
921 lts_convert<STATE_LABEL1, ACTION_LABEL1, LTS_BASE1, STATE_LABEL2, ACTION_LABEL2, LTS_BASE2>(lts_in,lts_out);
925template <
class STATE_LABEL1,
class ACTION_LABEL1,
class LTS_BASE1,
926 class STATE_LABEL2,
class ACTION_LABEL2,
class PROBABILISTIC_STATE2,
class LTS_BASE2>
932 const bool extra_data_is_defined=
true)
934 lts_convert<STATE_LABEL1, ACTION_LABEL1, LTS_BASE1,STATE_LABEL2, ACTION_LABEL2, LTS_BASE2>(lts_in,lts_out,data,action_label_list,process_parameters,extra_data_is_defined);
940template <
class STATE_LABEL1,
class ACTION_LABEL1,
class PROBABILISTIC_STATE1,
class LTS_BASE1,
941 class STATE_LABEL2,
class ACTION_LABEL2,
class PROBABILISTIC_STATE2,
class LTS_BASE2>
954template <
class STATE_LABEL1,
class ACTION_LABEL1,
class PROBABILISTIC_STATE1,
class LTS_BASE1,
955 class STATE_LABEL2,
class ACTION_LABEL2,
class PROBABILISTIC_STATE2,
class LTS_BASE2>
964template <
class STATE_LABEL1,
class ACTION_LABEL1,
class PROBABILISTIC_STATE1,
class LTS_BASE1,
965 class STATE_LABEL2,
class ACTION_LABEL2,
class PROBABILISTIC_STATE2,
class LTS_BASE2>
971 const bool extra_data_is_defined=
true)
975 data, action_label_list, process_parameters, extra_data_is_defined);
size_type size() const
Returns the size of the term_list.
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
const Term & front() const
Returns the first element of the list.
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
bool empty() const
Returns true if the list's size is 0.
A vector class in which aterms can be stored.
An application of a data expression to a number of arguments.
const data_expression & head() const
Get the function at the head of this expression.
sort_expression sort() const
Returns the sort of the data expression.
data_expression typecheck_data_expression(const data_expression &x, const sort_expression &expected_sort, const detail::variable_context &variable_context)
void add_context_variables(const VariableContainer &variables)
A class containing the values for action labels for the .lts format.
This class contains strings to be used as values for action labels in lts's.
lps::multi_action_type_checker m_typechecker
convertor(const lts_aut_base &, const lts_lts_base <s_base_out)
const data::data_specification & m_data
const lts_fsm_base & m_lts_in
std::size_t m_state_count
convertor(const lts_fsm_base <s_base_in, const lts_dot_base &)
convertor(const lts_fsm_base <s_base_in, lts_lts_base <s_base_out)
const lts_fsm_base & m_lts_in
lps::multi_action_type_checker m_typechecker
const lts_lts_base & m_lts_out
convertor(const lts_lts_base &, lts_dot_base &)
std::size_t m_state_count
std::vector< std::map< data::data_expression, std::size_t > > state_element_values_sets
convertor(const lts_lts_base <s_base_in, lts_fsm_base <s_base_out)
convertor(const BASE_LTS_IN &, const BASE_LTS_OUT &)
void clear_process_parameters()
Clear the state parameters for this LTS.
void add_process_parameter(const std::string &name, const std::string &sort)
Set the state parameters for this LTS.
a base class for lts_lts_t and probabilistic_lts_t.
void set_process_parameters(const data::variable_list ¶ms)
Set the state parameters for this LTS.
void set_action_label_declarations(const process::action_label_list &decls)
Set the action label information for this LTS.
const data::variable_list & process_parameters() const
Return the process parameters stored in this LTS.
void set_data(const data::data_specification &spec)
Set the mCRL2 data specification of this LTS.
A class that contains a labelled transition system.
states_size_type num_states() const
Gets the number of states of this LTS.
A class that contains a labelled transition system.
void set_initial_probabilistic_state(const PROBABILISTIC_STATE_T &state)
Sets the probabilistic initial state number of this LTS.
const PROBABILISTIC_STATE_T & initial_probabilistic_state() const
Gets the initial state number of this LTS.
labels_size_type num_probabilistic_states() const
Gets the number of probabilistic states of this LTS.
void clear_probabilistic_states()
Clear the probabilistic states in this probabilistic transitions system.
states_size_type add_probabilistic_state(const PROBABILISTIC_STATE_T &s)
Adds a probabilistic state to this LTS.
const PROBABILISTIC_STATE_T & probabilistic_state(const states_size_type index) const
Gets the probabilistic label of an index.
A class that contains a probabilistic state.
This class contains labels for states in dot format.
Contains empty state values, used for lts's without state valued.
This class contains state labels for the fsm format.
This class contains state labels for an labelled transition system in .lts format.
A class containing triples, source label and target representing transitions.
Standard exception class for reporting runtime errors.
This class contains labels for probabilistic transistions, consisting of a numerator and a denominato...
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
This file contains a class that contains labelled transition systems in aut format.
This file contains a class that contains labelled transition systems in dot format.
This file contains a class that contains labelled transition systems in fsm format.
This file contains a class that contains labelled transition systems in lts (mcrl2) format.
std::string pp(const detail::lhs_t &lhs)
bool is_integer_constant(const data_expression &n)
Determines whether n is an integer constant.
bool is_positive_constant(const data_expression &n)
Determines whether n is a positive constant.
const function_symbol & creal()
Constructor for function symbol @cReal.
data_expression parse_data_expression(std::istream &in, const VariableContainer &variables, const data_specification &dataspec=detail::default_specification(), bool type_check=true, bool translate_user_notation=true, bool normalize_sorts=true)
Parses and type checks a data expression.
std::string pp(const abstraction &x)
void translate_probability_labels(const probabilistic_lts< STATE_LABEL1, ACTION_LABEL1, PROBABILISTIC_STATE1, LTS_BASE1 > <s_in, probabilistic_lts< STATE_LABEL2, ACTION_LABEL2, PROBABILISTIC_STATE2, LTS_BASE2 > <s_out)
void lts_convert(const lts< STATE_LABEL1, ACTION_LABEL1, LTS_BASE1 > <s_in, lts< STATE_LABEL2, ACTION_LABEL2, LTS_BASE2 > <s_out)
void lts_convert_aux(const lts< STATE_LABEL1, ACTION_LABEL1, LTS_BASE1 > <s_in, lts< STATE_LABEL2, ACTION_LABEL2, LTS_BASE2 > <s_out)
void lts_convert_base_class(const lts_lts_base &base_in, lts_lts_base &base_out)
void remove_probabilities(const probabilistic_lts< STATE_LABEL1, ACTION_LABEL1, PROBABILISTIC_STATE1, LTS_BASE1 > <s_in, lts< STATE_LABEL2, ACTION_LABEL2, LTS_BASE2 > <s_out)
void lts_convert_translate_state(const state_label_lts &state_label_in, state_label_lts &state_label_out, convertor< lts_lts_base, lts_lts_base > &)
utilities::probabilistic_arbitrary_precision_fraction translate_probability_data_to_arbitrary_size_probability(const data::data_expression &d)
Translate a fraction given as a data_expression to a representation with an arbitrary size fraction.
PROBABILISTIC_STATE2 lts_convert_probabilistic_state(const PROBABILISTIC_STATE1 &)
action_label_lts translate_label_aux(const action_label_string &l1, const data::data_specification &data, lps::multi_action_type_checker &typechecker)
mcrl2::utilities::probabilistic_arbitrary_precision_fraction translate_probability_data_prob(const data::data_expression &d)
void add_probabilities(const lts< STATE_LABEL1, ACTION_LABEL1, LTS_BASE1 > <s_in, probabilistic_lts< STATE_LABEL2, ACTION_LABEL2, PROBABILISTIC_STATE2, LTS_BASE2 > <s_out)
action_label_lts lts_convert_translate_label(const action_label_lts &l_in, convertor< lts_lts_base, lts_lts_base > &)
action_label_lts parse_lts_action(const std::string &multi_action_string, const data::data_specification &data_spec, lps::multi_action_type_checker &typechecker)
Parse a string into an action label.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...