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.
23 int Graph::bfs_init(int s, bool clear_visited)
28 Q_ = std::queue<int>();
31 fill(visited_.begin(), visited_.end(), false);
32 if (visited_[s] == false) {
41 Graph::getReachableTo(int target, bool clear_visited)
44 int const s = bfs_init(target, clear_visited);
49 int const i = Q_.front();
51 if (i != s || formats.get(target).name() != "lyx") {
55 vector<int>::iterator it = vertices_[i].in_vertices.begin();
56 vector<int>::iterator end = vertices_[i].in_vertices.end();
57 for (; it != end; ++it) {
70 Graph::getReachable(int from, bool only_viewable,
74 if (bfs_init(from, clear_visited) < 0)
78 int const i = Q_.front();
80 Format const & format = formats.get(i);
81 if (format.name() == "lyx")
83 if (!only_viewable || !format.viewer().empty() ||
84 format.isChildFormat())
87 vector<int>::const_iterator cit =
88 vertices_[i].out_vertices.begin();
89 vector<int>::const_iterator end =
90 vertices_[i].out_vertices.end();
91 for (; cit != end; ++cit)
92 if (!visited_[*cit]) {
93 visited_[*cit] = true;
102 bool Graph::isReachable(int from, int to)
107 int const s = bfs_init(from);
111 while (!Q_.empty()) {
112 int const i = Q_.front();
117 vector<int>::const_iterator cit =
118 vertices_[i].out_vertices.begin();
119 vector<int>::const_iterator end =
120 vertices_[i].out_vertices.end();
121 for (; cit != end; ++cit) {
122 if (!visited_[*cit]) {
123 visited_[*cit] = true;
133 Graph::EdgePath const
134 Graph::getPath(int from, int t)
140 int const s = bfs_init(from);
144 vector<int> prev_edge(formats.size());
145 vector<int> prev_vertex(formats.size());
148 while (!Q_.empty()) {
149 int const i = Q_.front();
156 vector<int>::const_iterator beg =
157 vertices_[i].out_vertices.begin();
158 vector<int>::const_iterator cit = beg;
159 vector<int>::const_iterator end =
160 vertices_[i].out_vertices.end();
161 for (; cit != end; ++cit)
162 if (!visited_[*cit]) {
166 int const k = cit - beg;
167 prev_edge[j] = vertices_[i].out_edges[k];
175 path.push_back(prev_edge[t]);
178 reverse(path.begin(), path.end());
182 void Graph::init(int size)
184 vertices_ = vector<Vertex>(size);
185 visited_.resize(size);
189 void Graph::addEdge(int s, int t)
191 vertices_[t].in_vertices.push_back(s);
192 vertices_[s].out_vertices.push_back(t);
193 vertices_[s].out_edges.push_back(numedges_++);
196 vector<Graph::Vertex> Graph::vertices_;