LCOV - code coverage report
Current view: top level - lts/source - liblts_dot.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 1 50 2.0 %
Date: 2019-09-14 00:54:39 Functions: 2 6 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Muck van Weerdenburg
       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             : /// \file liblts_dot.cpp
      10             : 
      11             : #include <ostream>
      12             : #include <fstream>
      13             : #include <string>
      14             : #include <vector>
      15             : #include "mcrl2/lts/lts_dot.h"
      16             : #include "mcrl2/lts/lts_io.h"
      17             : #include "mcrl2/lts/parse.h"
      18             : #include "mcrl2/lts/detail/liblts_swap_to_from_probabilistic_lts.h"
      19             : 
      20             : using namespace mcrl2::core;
      21             : 
      22             : using namespace std;
      23             : 
      24             : namespace mcrl2
      25             : {
      26             : namespace lts
      27             : {
      28             : 
      29           0 : void probabilistic_lts_dot_t::save(std::ostream& os) const
      30             : {
      31             :   // Language definition seems to suggest that the name is optional, but tools seem to think otherwise
      32           0 :   os << "digraph G {" << endl;
      33             :   // os << "size=\"7,10.5\";" << endl;
      34           0 :   os << "center = TRUE;" << endl;
      35           0 :   os << "mclimit = 10.0;" << endl;
      36           0 :   os << "nodesep = 0.05;" << endl;
      37           0 :   os << "node [ width=0.25, height=0.25, label=\"\" ];" << endl;
      38           0 :   if (num_states() > 0)
      39             :   {
      40           0 :     if (initial_probabilistic_state().size()==1)
      41             :     { 
      42           0 :       const std::size_t initial_state=initial_probabilistic_state().begin()->state();
      43           0 :       if (has_state_info())
      44             :       {
      45           0 :         os << state_label(initial_state).name();
      46             :       }
      47             :       else
      48             :       {
      49           0 :         os << "S" << initial_state;
      50             :       }
      51             :     }
      52             :     else
      53             :     {
      54           0 :       throw mcrl2::runtime_error("Cannnot save a probabilistic transition system in .dot format.");
      55             :     }
      56             : 
      57           0 :     os << " [ peripheries=2 ];" << endl;
      58           0 :     for (std::size_t i=0; i<num_states(); i++)
      59             :     {
      60           0 :       if (has_state_info())
      61             :       {
      62           0 :         const std::string& label = state_label(i).label();
      63           0 :         if (!label.empty())
      64             :         {
      65           0 :           os << state_label(i).name() << " [label=\"" << label << "\"];" << endl;
      66             :         }
      67             :       }
      68             :       else
      69             :       {
      70           0 :         os << "S" << i << endl;
      71             :       }
      72             :     }
      73             :   }
      74             :   
      75           0 :   for (const transition& t: get_transitions())
      76             :   {
      77           0 :     if (has_state_info())
      78             :     {
      79           0 :       if (probabilistic_state(t.to()).size()>1)
      80             :       {
      81           0 :         throw mcrl2::runtime_error("Cannot save probabilistic states in .dot format.");
      82             :       }
      83           0 :       os << state_label(t.from()).name() << "->" << state_label(probabilistic_state(t.to()).begin()->state()).name() << "[label=\"" <<
      84           0 :          mcrl2::lts::pp(action_label(t.label())) << "\"];" << endl;
      85             :     }
      86             :     else
      87             :     {
      88           0 :       os << "S" << t.from() << " -> " << "S" << t.to() << "[label=\"" <<
      89           0 :          mcrl2::lts::pp(action_label(apply_hidden_label_map(t.label()))) << "\"];" << endl;
      90             :     }
      91             :   }
      92             : 
      93           0 :   os << "}" << endl;
      94           0 : }
      95             : 
      96           0 : void probabilistic_lts_dot_t::save(const string& filename) const
      97             : {
      98           0 :   ofstream os(filename.c_str());
      99           0 :   if (!os.is_open())
     100             :   {
     101           0 :     throw mcrl2::runtime_error("cannot open DOT file '" + filename + "' for writing.");
     102             :   }
     103           0 :   save(os);
     104           0 :   os.close();
     105           0 : }
     106             : 
     107           0 : void lts_dot_t::save(std::ostream& os) const
     108             : {
     109           0 :   probabilistic_lts_dot_t l;
     110             :   detail::translate_to_probabilistic_lts
     111             :             <state_label_dot,
     112             :              action_label_string,
     113             :              probabilistic_state<std::size_t, mcrl2::lts::probabilistic_arbitrary_precision_fraction>,
     114           0 :              detail::lts_dot_base>(*this,l);
     115           0 :   l.save(os);
     116           0 : }
     117             : 
     118           0 : void lts_dot_t::save(const string& filename) const
     119             : {
     120           0 :   ofstream os(filename.c_str());
     121           0 :   if (!os.is_open())
     122             :   {
     123           0 :     throw mcrl2::runtime_error("cannot open DOT file '" + filename + "' for writing.");
     124             :   }
     125           0 :   save(os);
     126           0 :   os.close();
     127           0 : }
     128             : 
     129             : }
     130          21 : }

Generated by: LCOV version 1.12