2003-02-28 09:49:49 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Graph.h
|
2003-02-28 09:49:49 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-28 09:49:49 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#ifndef GRAPH_H
|
|
|
|
#define GRAPH_H
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#include <queue>
|
|
|
|
#include <vector>
|
|
|
|
|
2003-09-07 21:25:37 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
class Graph {
|
2003-03-04 09:27:27 +00:00
|
|
|
public:
|
2003-02-28 09:49:49 +00:00
|
|
|
Graph() : numedges_(0) {};
|
|
|
|
///
|
|
|
|
typedef std::vector<int> EdgePath;
|
2009-11-09 00:55:37 +00:00
|
|
|
/// \return a vector of the vertices from which "to" can be reached
|
|
|
|
std::vector<int> const getReachableTo(int to, bool clear_visited);
|
|
|
|
/// \return a vector of the vertices that can be reached from "from"
|
2003-02-28 09:49:49 +00:00
|
|
|
std::vector<int> const
|
2009-11-09 00:55:37 +00:00
|
|
|
getReachable(int from, bool only_viewable, bool clear_visited);
|
|
|
|
/// Can "from" be reached from "to"?
|
|
|
|
bool isReachable(int from, int to);
|
|
|
|
/// Find a path from "from" to "to".
|
|
|
|
EdgePath const getPath(int from, int to);
|
|
|
|
/// Called repeatedly to build the graph.
|
|
|
|
void addEdge(int from, int to);
|
|
|
|
/// Reset the internal data structures.
|
2003-02-28 09:49:49 +00:00
|
|
|
void init(int size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
int bfs_init(int, bool clear_visited = true);
|
|
|
|
|
|
|
|
///
|
2005-01-19 15:03:31 +00:00
|
|
|
class Vertex {
|
|
|
|
public:
|
2003-02-28 09:49:49 +00:00
|
|
|
std::vector<int> in_vertices;
|
|
|
|
std::vector<int> out_vertices;
|
|
|
|
std::vector<int> out_edges;
|
|
|
|
};
|
|
|
|
///
|
2009-11-09 00:55:37 +00:00
|
|
|
static std::vector<Vertex> vertices_;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
std::vector<bool> visited_;
|
|
|
|
///
|
|
|
|
std::queue<int> Q_;
|
|
|
|
|
|
|
|
int numedges_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#endif //GRAPH_H
|