Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnGraphUtils.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnGraphUtils.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 ** DESCRIPTION:
11 ** Generic graph utilities.
12 **
13 *****************************************************************************/
14 
21 #pragma once
22 
23 #include <cassert>
24 #include <vector>
25 #include <map>
26 #include <set>
27 
28 using namespace std;
29 
30 // basic data types ---------------------------------------------------------
31 
33 typedef std::pair<int, int> drwnEdge;
34 ostream& operator<<(ostream& os, const drwnEdge& e);
35 
37 typedef std::set<int> drwnClique;
38 
40  public:
41  int nodeA;
42  int nodeB;
43  double wAB;
44  double wBA;
45 
46  public:
47  drwnWeightedEdge() :
48  nodeA(-1), nodeB(-1), wAB(0.0), wBA(0.0) { /* do nothing */ };
49  drwnWeightedEdge(int a, int b, double w = 0.0, double v = 0.0) :
50  nodeA(a), nodeB(b), wAB(w), wBA(v) { /* do nothing */ };
51  ~drwnWeightedEdge() { /* do nothing */ };
52 };
53 
57 } drwnTriangulationHeuristic;
58 
59 // graph utilities ----------------------------------------------------------
60 
62 vector<drwnClique> findNeighbors(const vector<drwnEdge>& graph);
63 
65 int findSuperset(const vector<drwnClique>& cliques, const drwnClique& subclique);
66 
70 vector<drwnEdge> minSpanningTree(int numNodes, const vector<drwnEdge>& edges,
71  const vector<double>& weights);
72 
77 bool maxCardinalitySearch(int numNodes, const vector<drwnEdge>& edges,
78  vector<int>& perfectOrder, int startNode = -1);
79 
83 void triangulateGraph(int numNodes, vector<drwnEdge>& edges,
84  drwnTriangulationHeuristic method = DRWN_MINFILLIN);
85 
87 vector<drwnClique> variableEliminationCliques(const vector<drwnEdge>& edges,
88  const vector<int>& nodeOrder);
89 
91 vector<vector<double> > allShortestPaths(int numNodes, const vector<drwnEdge>& edges,
92  const vector<double>& weights);
93 
95 vector<int> shortestPath(int numNodes, const vector<drwnEdge>& edges,
96  const vector<double>& weights, int source, int sink);
vector< drwnClique > findNeighbors(const vector< drwnEdge > &graph)
Finds the neighbors for each node in a graph.
Definition: drwnGraphUtils.cpp:36
vector< vector< double > > allShortestPaths(int numNodes, const vector< drwnEdge > &edges, const vector< double > &weights)
Floyd-Warshall algorithm for all paths shortest path.
Definition: drwnGraphUtils.cpp:321
int nodeB
target node
Definition: drwnGraphUtils.h:42
int findSuperset(const vector< drwnClique > &cliques, const drwnClique &subclique)
Find a clique containing the subclique.
Definition: drwnGraphUtils.cpp:51
vector< int > shortestPath(int numNodes, const vector< drwnEdge > &edges, const vector< double > &weights, int source, int sink)
Dijkstra's shortest path algorithm.
Definition: drwnGraphUtils.cpp:356
bool maxCardinalitySearch(int numNodes, const vector< drwnEdge > &edges, vector< int > &perfectOrder, int startNode=-1)
Maximum cardinality search. Returns an elimination ordering for a chordal graph (true) or three nodes...
Definition: drwnGraphUtils.cpp:109
minimum fill-in heuristic
Definition: drwnGraphUtils.h:56
maximum cardinality search (MCS)
Definition: drwnGraphUtils.h:55
std::set< int > drwnClique
variable clique
Definition: drwnGraphUtils.h:37
_drwnTriangulationHeuristic
Definition: drwnGraphUtils.h:54
std::pair< int, int > drwnEdge
directed or undirected edges
Definition: drwnGraphUtils.h:33
Definition: drwnGraphUtils.h:39
double wAB
weight from source to target
Definition: drwnGraphUtils.h:43
vector< drwnEdge > minSpanningTree(int numNodes, const vector< drwnEdge > &edges, const vector< double > &weights)
Finds the minimum weight spanning tree (forest) given a graph structure and weights for each edge (mi...
Definition: drwnGraphUtils.cpp:68
int nodeA
source node
Definition: drwnGraphUtils.h:41
void triangulateGraph(int numNodes, vector< drwnEdge > &edges, drwnTriangulationHeuristic method=DRWN_MINFILLIN)
Triangulate an undirected graph. Modifies the adjacency list inline. The resulting graph contains no ...
Definition: drwnGraphUtils.cpp:195
double wBA
weight from target to source
Definition: drwnGraphUtils.h:44
vector< drwnClique > variableEliminationCliques(const vector< drwnEdge > &edges, const vector< int > &nodeOrder)
Finds cliques obtained by variable elimination.
Definition: drwnGraphUtils.cpp:278