rundotdec.cc 4.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (C) 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING.  If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.

#include <sstream>
#include "rundotdec.hh"
#include "tgba/succiter.hh"

namespace spot
{

  tgba_run_dotty_decorator::tgba_run_dotty_decorator(const tgba_run* run)
    : run_(run)
  {
    int n = 1;
    for (tgba_run::steps::const_iterator i = run->prefix.begin();
	 i != run->prefix.end(); ++i, ++n)
      map_[i->s].first.push_back(step_num(i, n));
    for (tgba_run::steps::const_iterator i = run->cycle.begin();
	 i != run->cycle.end(); ++i, ++n)
      map_[i->s].second.push_back(step_num(i, n));
  }

  tgba_run_dotty_decorator::~tgba_run_dotty_decorator()
  {
  }

  std::string
  tgba_run_dotty_decorator::state_decl(const tgba*, const state* s, int,
				       tgba_succ_iterator*,
				       const std::string& label)
  {
    step_map::const_iterator i = map_.find(s);
    if (i == map_.end())
      return "[label=\"" + label + "\"]";

    std::ostringstream os;
    std::string sep = "(";
    bool in_prefix = false;
    bool in_cycle = false;
    for (step_set::const_iterator j = i->second.first.begin();
	 j != i->second.first.end(); ++j)
      {
	os << sep << j->second;
	sep = ", ";
	in_prefix = true;
      }
    if (sep == ", ")
      sep = "; ";
    for (step_set::const_iterator j = i->second.second.begin();
	 j != i->second.second.end(); ++j)
      {
	os << sep << j->second;
	sep = ", ";
	in_cycle = true;
      }
    assert(in_cycle || in_prefix);
    os << ")\\n" << label;
    std::string color = in_prefix ? (in_cycle ? "violet" : "blue") : "red";
    return "[label=\"" + os.str() + "\", style=bold, color=" + color + "]";
  }

  std::string
  tgba_run_dotty_decorator::link_decl(const tgba*,
				      const state* in_s, int,
				      const state* out_s, int,
				      const tgba_succ_iterator* si,
				      const std::string& label)
  {
    step_map::const_iterator i = map_.find(in_s);
    if (i != map_.end())
      {
	std::ostringstream os;
	std::string sep = "(";
	bool in_prefix = false;
	bool in_cycle = false;
	for (step_set::const_iterator j = i->second.first.begin();
	     j != i->second.first.end(); ++j)
	  if (j->first->label == si->current_condition()
	      && j->first->acc == si->current_acceptance_conditions())
	    {
	      tgba_run::steps::const_iterator j2 = j->first;
	      ++j2;
	      if (j2 == run_->prefix.end())
		j2 = run_->cycle.begin();
	      if (out_s->compare(j2->s))
		continue;

	      os << sep << j->second;
	      sep = ", ";
	      in_prefix = true;
	    }
	if (sep == ", ")
	  sep = "; ";
	for (step_set::const_iterator j = i->second.second.begin();
	     j != i->second.second.end(); ++j)
	  if (j->first->label == si->current_condition()
	      && j->first->acc == si->current_acceptance_conditions())
	    {
	      tgba_run::steps::const_iterator j2 = j->first;
	      ++j2;
	      if (j2 == run_->cycle.end())
		j2 = run_->cycle.begin();
	      if (out_s->compare(j2->s))
		continue;

	      os << sep << j->second;
	      sep = ", ";
	      in_cycle = true;
	    }
	os << ")\\n";
	if (in_prefix || in_cycle)
	  {
	    std::string
132
	      color = in_prefix ? (in_cycle ? "violet" : "blue") : "red";
133
134
135
136
137
138
139
140
141
142
143
	    return ("[label=\"" + os.str() + label
		    + "\", style=bold, color=" + color + "]");

	  }
      }
    return "[label=\"" + label + "\"]";
  }



}