mCRL2
Loading...
Searching...
No Matches
bdd2dot.h
Go to the documentation of this file.
1// Author(s): Luc Engelen
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 mcrl2/data/detail/prover/bdd2dot.h
10/// \brief Interface to class BDD2Dot
11
12#ifndef MCRL2_DATA_DETAIL_PROVER_BDD2DOT_H
13#define MCRL2_DATA_DETAIL_PROVER_BDD2DOT_H
14
15#include "mcrl2/data/detail/prover/bdd_info.h"
16#include <fstream>
17
18namespace mcrl2::data::detail
19{
20
21/// \brief The class BDD2Dot offers the ability to write binary decision diagrams to dot files.
22/// The method BDD2Dot::output_bdd receives a binary decision diagram as parameter a_bdd and writes it to a file in dot
23/// format with the name passed as parameter a_file_name.
24
26{
27 private:
28 /// \brief The smallest unused node number.
30
31 /// \brief The file the output is written to.
33
34 /// \brief A table containing all the visited nodes. It maps these nodes to the corresponding node numbers.
36
37 /// \brief A class that gives information about the structure of BDDs.
39
40 /// \brief Writes the BDD it receives to BDD2Dot::f_dot_file.
41 /// \param a_bdd A binary decision diagram.
42 /// \pre The argument passed as parameter a_bdd is a data expression in internal mCRL2 format with the
43 /// following restrictions: It either represents the constant true or the constant false, or it is an if-then-else
44 /// expression with an expression of Bool as guard, and a then-branch and an else-branch that again follow these
45 /// restrictions
47 {
48 if (f_visited.count(a_bdd)>0) // a_bdd has already been visited.
49 {
50 return;
51 }
52
53 if (f_bdd_info.is_true(a_bdd))
54 {
55 f_dot_file << " " << f_node_number << " [shape=box, label=\"T\"];" << std::endl;
56 }
57 else if (f_bdd_info.is_false(a_bdd))
58 {
59 f_dot_file << " " << f_node_number << " [shape=box, label=\"F\"];" << std::endl;
60 }
61 else if (f_bdd_info.is_if_then_else(a_bdd))
62 {
63 const data_expression v_true_branch = f_bdd_info.get_true_branch(a_bdd);
64 const data_expression v_false_branch = f_bdd_info.get_false_branch(a_bdd);
65 aux_output_bdd(v_true_branch);
66 aux_output_bdd(v_false_branch);
67 std::size_t v_true_number = f_visited[v_true_branch].value();
68 std::size_t v_false_number = f_visited[v_false_branch].value();
69 const data_expression v_guard = f_bdd_info.get_guard(a_bdd);
70 f_dot_file << " " << f_node_number << " [label=\"" << mcrl2::data::pp(v_guard) << "\"];" << std::endl;
71 f_dot_file << " " << f_node_number << " -> " << v_true_number << ";" << std::endl;
72 f_dot_file << " " << f_node_number << " -> " << v_false_number << " [style=dashed];" << std::endl;
73 }
74 else
75 {
76 f_dot_file << " " << f_node_number << " [shape=box, label=\"" << mcrl2::data::pp(a_bdd) << "\"];" << std::endl;
77 }
78 f_visited[a_bdd]= atermpp::aterm_int(f_node_number++);
79 }
80
81 public:
82 /// \brief Writes the BDD it receives as input to a file
83 /// \brief in dot format with the name received as input.
84 /// precondition: The argument passed as parameter a_bdd is a data expression in internal mCRL2 format with the
85 /// following restrictions: It either represents the constant true or the constant false, or it is an if-then-else
86 /// expression with an expression of Bool as guard, and a then-branch and an else-branch that again follow these
87 /// restrictions
88 /// \param a_bdd A binary decision diagram.
89 /// \param a_file_name A file name.
90 void output_bdd(const data_expression &a_bdd, const std::string& a_file_name)
91 {
92 f_node_number = 0;
93 f_dot_file.open(a_file_name);
94 f_dot_file << "digraph BDD {" << std::endl;
96 f_dot_file << "}" << std::endl;
97 f_dot_file.close();
98 }
99};
100
101} // namespace mcrl2::data::detail
102
103#endif
The class BDD2Dot offers the ability to write binary decision diagrams to dot files....
Definition bdd2dot.h:26
std::ofstream f_dot_file
The file the output is written to.
Definition bdd2dot.h:32
void output_bdd(const data_expression &a_bdd, const std::string &a_file_name)
Writes the BDD it receives as input to a file.
Definition bdd2dot.h:90
std::map< atermpp::aterm, atermpp::aterm_int > f_visited
A table containing all the visited nodes. It maps these nodes to the corresponding node numbers.
Definition bdd2dot.h:35
void aux_output_bdd(const data_expression &a_bdd)
Writes the BDD it receives to BDD2Dot::f_dot_file.
Definition bdd2dot.h:46
BDD_Info f_bdd_info
A class that gives information about the structure of BDDs.
Definition bdd2dot.h:38
int f_node_number
The smallest unused node number.
Definition bdd2dot.h:29
The class BDD_Info provides information about the structure of binary decision diagrams.
Definition bdd_info.h:22
static const mcrl2::data::data_expression & get_true_branch(const mcrl2::data::data_expression &a_bdd)
Method that returns the true-branch of a BDD.
Definition bdd_info.h:43
static bool is_if_then_else(const data_expression &a_bdd)
Method that indicates wether or not the root of a BDD is a guard node.
Definition bdd_info.h:78
static bool is_false(const data_expression &a_bdd)
Method that indicates whether or not a BDD equals false.
Definition bdd_info.h:69
static const mcrl2::data::data_expression & get_guard(const mcrl2::data::data_expression &a_bdd)
Method that returns the guard of a BDD.
Definition bdd_info.h:35
static const mcrl2::data::data_expression & get_false_branch(const mcrl2::data::data_expression &a_bdd)
Method that returns the false-branch of a BDD.
Definition bdd_info.h:51
static bool is_true(const data_expression &a_bdd)
Method that indicates whether or not a BDD equals true.
Definition bdd_info.h:60