mCRL2
Loading...
Searching...
No Matches
liblts_swap_to_from_probabilistic_lts.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9/// \details This file contains two functions to efficiently transform
10// a plain_lts into a probabilistic lts and vice versa. The
11// lts from which the transformation takes place is destroyed.
12
13#ifndef MCRL2_LTS_DETAIL_SWAP_TO_FROM_PROBABILISTIC_LTS_H
14#define MCRL2_LTS_DETAIL_SWAP_TO_FROM_PROBABILISTIC_LTS_H
15
16#include "mcrl2/lts/probabilistic_lts.h"
17#include "mcrl2/utilities/exception.h"
18
19namespace mcrl2::lts::detail
20{
21
22template < class STATE_LABEL_T, class ACTION_LABEL_T, class PROBABILISTIC_STATE_T, class LTS_BASE >
24 probabilistic_lts<STATE_LABEL_T,ACTION_LABEL_T, PROBABILISTIC_STATE_T, LTS_BASE>& l_probabilistic,
25 lts<STATE_LABEL_T,ACTION_LABEL_T, LTS_BASE>& l_plain)
26{
27 static_cast<lts<STATE_LABEL_T, ACTION_LABEL_T, LTS_BASE>& >(l_probabilistic).swap(l_plain);
28
29 if (l_probabilistic.initial_probabilistic_state().size()<=1)
30 {
31 l_plain.set_initial_state(l_probabilistic.initial_probabilistic_state().get());
32 }
33 else
34 {
35 throw mcrl2::runtime_error("Initial state is probabilistic and cannot be transformed into a non probabilistic state.");
36 }
37
38 // Adapt the probabilistic target states to non probabilistic target states.
39 std::size_t transition_number=1;
40 for(transition& t: l_plain.get_transitions())
41 {
42 std::size_t probabilistic_target_state_number=t.to();
43 if (l_probabilistic.probabilistic_state(probabilistic_target_state_number).size()>1)
44 {
45 throw mcrl2::runtime_error("Transition " + std::to_string(transition_number) + " is probabilistic.");
46 }
47 else
48 {
49 t=transition(t.from(), t.label(), l_probabilistic.probabilistic_state(probabilistic_target_state_number).get());
50 }
51 transition_number++;
52 }
53
54
55}
56
57template < class STATE_LABEL_T, class ACTION_LABEL_T, class PROBABILISTIC_STATE_T, class LTS_BASE >
59 const lts<STATE_LABEL_T,ACTION_LABEL_T, LTS_BASE>& l_plain,
60 probabilistic_lts<STATE_LABEL_T,ACTION_LABEL_T, PROBABILISTIC_STATE_T, LTS_BASE>& l_probabilistic)
61{
62 static_cast<lts<STATE_LABEL_T,ACTION_LABEL_T, LTS_BASE>& >(l_probabilistic)=l_plain;
63 l_probabilistic.set_initial_probabilistic_state(PROBABILISTIC_STATE_T(l_plain.initial_state()));
64 for(std::size_t i=0; i<l_plain.num_states(); ++i)
65 {
66 l_probabilistic.add_probabilistic_state(PROBABILISTIC_STATE_T(i));
67 }
68}
69
70} // detail
71// lts
72// mcrl2
73
74#endif // MCRL2_LTS_DETAIL_SWAP_TO_FROM_PROBABILISTIC_LTS_H
function object to compare two constln_t pointers based on their contents
A simple labelled transition format with only strings as action labels.
Definition lts_aut.h:67
void load(const std::string &filename)
Load the labelled transition system from a file.
void load(std::istream &is)
Load the labelled transition system from an input stream.
void save(const std::string &filename) const
Save the labelled transition system to file.
A simple labelled transition format with only strings as action labels.
Definition lts_aut.h:100
void load(const std::string &filename)
Load the labelled transition system from a file.
void load(std::istream &is)
Load the labelled transition system from an input stream.
void save(const std::string &filename) const
Save the labelled transition system to file.
A class that contains a labelled transition system.
static void read_probabilistic_state(std::istream &is, mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &result, const std::size_t line_no)
static void write_probabilistic_state(const mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &prob_state, std::ostream &os)
static void write_to_aut(const lts_aut_t &l, std::ostream &os)
static void read_from_aut(probabilistic_lts_aut_t &l, std::istream &is)
static size_t add_probablistic_state(mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &probabilistic_state, probabilistic_lts_aut_t &l, mcrl2::utilities::unordered_map< std::size_t, std::size_t > &indices_of_single_probabilistic_states, mcrl2::utilities::unordered_map< mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t, std::size_t > &indices_of_multiple_probabilistic_states)
static void read_newline(std::istream &is, const std::size_t line_no)
static void read_aut_header(std::istream &is, mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &initial_state, std::size_t &num_transitions, std::size_t &num_states)
static void write_to_aut(const probabilistic_lts_aut_t &l, std::ostream &os)
static bool read_initial_part_of_an_aut_transition(std::istream &is, std::size_t &from, std::string &label, const std::size_t line_no)
static void read_natural_number_to_string(std::istream &is, std::string &s, const std::size_t line_no)
static void check_states(mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &probability_state, std::size_t number_of_states, std::size_t line_no)
static void check_state(std::size_t state, std::size_t number_of_states, std::size_t line_no)
static bool read_aut_transition(std::istream &is, std::size_t &from, std::string &label, mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &target_probabilistic_state, const std::size_t line_no)
static std::size_t find_label_index(const std::string &s, mcrl2::utilities::unordered_map< action_label_string, std::size_t > &labs, AUT_LTS_TYPE &l)
static void read_from_aut(lts_aut_t &l, std::istream &is)
void translate_to_probabilistic_lts(const lts< STATE_LABEL_T, ACTION_LABEL_T, LTS_BASE > &l_plain, probabilistic_lts< STATE_LABEL_T, ACTION_LABEL_T, PROBABILISTIC_STATE_T, LTS_BASE > &l_probabilistic)
void swap_to_non_probabilistic_lts(probabilistic_lts< STATE_LABEL_T, ACTION_LABEL_T, PROBABILISTIC_STATE_T, LTS_BASE > &l_probabilistic, lts< STATE_LABEL_T, ACTION_LABEL_T, LTS_BASE > &l_plain)