3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
22 int Graph::bfs_init(int s, bool clear_visited)
27 Q_ = std::queue<int>();
30 fill(visited_.begin(), visited_.end(), false);
31 if (visited_[s] == false) {
40 Graph::getReachableTo(int target, bool clear_visited)
43 int const s = bfs_init(target, clear_visited);
48 int const i = Q_.front();
50 if (i != s || formats.get(target).name() != "lyx") {
54 vector<int>::iterator it = vertices_[i].in_vertices.begin();
55 vector<int>::iterator end = vertices_[i].in_vertices.end();
56 for (; it != end; ++it) {
69 Graph::getReachable(int from, bool only_viewable,
73 if (bfs_init(from, clear_visited) < 0)
77 int const i = Q_.front();
79 Format const & format = formats.get(i);
80 if (format.name() == "lyx")
82 if (!only_viewable || !format.viewer().empty() ||
83 format.isChildFormat())
86 vector<int>::const_iterator cit =
87 vertices_[i].out_vertices.begin();
88 vector<int>::const_iterator end =
89 vertices_[i].out_vertices.end();
90 for (; cit != end; ++cit)
91 if (!visited_[*cit]) {
92 visited_[*cit] = true;
101 bool Graph::isReachable(int from, int to)
106 int const s = bfs_init(from);
110 while (!Q_.empty()) {
111 int const i = Q_.front();
116 vector<int>::const_iterator cit =
117 vertices_[i].out_vertices.begin();
118 vector<int>::const_iterator end =
119 vertices_[i].out_vertices.end();
120 for (; cit != end; ++cit) {
121 if (!visited_[*cit]) {
122 visited_[*cit] = true;
132 Graph::EdgePath const
133 Graph::getPath(int from, int t)
139 int const s = bfs_init(from);
143 vector<int> prev_edge(formats.size());
144 vector<int> prev_vertex(formats.size());
147 while (!Q_.empty()) {
148 int const i = Q_.front();
155 vector<int>::const_iterator beg =
156 vertices_[i].out_vertices.begin();
157 vector<int>::const_iterator cit = beg;
158 vector<int>::const_iterator end =
159 vertices_[i].out_vertices.end();
160 for (; cit != end; ++cit)
161 if (!visited_[*cit]) {
165 int const k = cit - beg;
166 prev_edge[j] = vertices_[i].out_edges[k];
174 path.push_back(prev_edge[t]);
177 reverse(path.begin(), path.end());
181 void Graph::init(int size)
183 vertices_ = vector<Vertex>(size);
184 visited_.resize(size);
188 void Graph::addEdge(int s, int t)
190 vertices_[t].in_vertices.push_back(s);
191 vertices_[s].out_vertices.push_back(t);
192 vertices_[s].out_edges.push_back(numedges_++);
195 vector<Graph::Vertex> Graph::vertices_;