|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Interface Summary | |
|---|---|
| Algorithm | Common interface for all the algorithm implementations. |
| Class Summary | |
|---|---|
| ConnectedComponents | This class contains the results processed on a Connectivity algorithm. |
| Connectivity | Any class implementing this abstract class can be used to solve a problem related to graph connectivity as finding the strongly connected components or finding the weakly connected components. |
| ShortestPath | Any class implementing this abstract class can be used to solve the single pair shortest path problem, single-source pair shortest path problem, single-destination shortest path problem or all-pairs shortest path problem. |
| SinglePairShortestPath | Any class implementing this abstract class can be used to solve the problem of finding a path between two nodes with the condition that the sum of the weights of the edges which belong to the path is minimized. |
| SinglePairShortestPathBFS | This class can be used to solve the single-pair shortest path problem in an unweighted graph. |
| SinglePairShortestPathDijkstra | This class can be used to solve the single-pair shortest path problem in a weighted graph. |
| StrongConnectivity | Any class implementing this abstract class can be used to solve the problem of finding strongly connected components in a directed graph or in an undirected graph which will be considered as a directed one. |
| StrongConnectivityGabow | This class can be used to solve the problem of finding strongly connected components in a directed graph. |
| Traversal | Any class implementing this abstract class can be used to traverse a graph. |
| TraversalBFS | This class can be used to traverse the graph using the breadth-first search algorithm (BFS). |
| TraversalDFS | This class can be used to traverse the graph using the depth-first search algorithm (DFS). |
| WeakConnectivity | Any class implementing this abstract class can be used to solve the problem of finding weakly connected components in an undirected graph or in a directed graph which will be considered as an undirected one. |
| WeakConnectivityDFS | This class can be used to solve the problem of finding weakly connected components in an undirected graph or in a directed graph which will be considered as an undirected one. |
Provides classes in order to run algorithms among graphs. Specifically, this package contains the following classes:
ConnectivityStrongConnectivity, to find all
the strongly connected components in a directed graph. Each node of
the same strongly connected component is reachable from any
other node of the same strongly connected component.
StrongConnectivityGabow,
is an implementation of StrongConnectivity
following the Gabow algorithm.
WeakConnectivity, to find all
the weakly connected components in an undirected graph. Each node of
the same weakly connected component is reachable from any
other node of the same weakly connected component.
WeakConnectivityDFS,
is an implementation of WeakConnectivity
following the DFS algorithm.
ShortestPathSinglePairShortestPath, to solve
the problem of finding a path between two nodes with the condition
that the sum of the weights of the edges which belong to the path
is minimized.
SinglePairShortestPathBFS,
is an implementation of SinglePairShortestPath
following the BFS algorithm. This algorithm can be used to
solve the single pair shortest problem in unweighted graphs.
SinglePairShortestPathDijkstra,
is an implementation of SinglePairShortestPath
following the Dijkstra algorithm. This algorithm can be used to
solve the single pair shortest problem in weighted graphs.
TraversalTraversalBFS, to traverse
a graph using the BFS algorithm.
TraversalDFS, to traverse
a graph using the DFS algorithm.
The following example shows how to use the
SinglePairShortestPathBFS class:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
long iddestination = graph.findObj(nodetype, new Value("Rome"));
SinglePairShortestPathBFS sp = new SinglePairShortestPathBFS(graph, idsource, iddestination);
// Adding the allowed edge types for traversing the graph
int edgetype1 = graph.findType("street");
sp.addEdge(edgetype1, Algorithm.NAVIGATION_FORWARD);
int edgetype2 = graph.findType("road");
sp.addEdge(edgetype2, Algorithm.NAVIGATION_UNDIRECTED);
// Setting the maximum hops
sp.setMaximumHops(7);
// Running the algorithm
sp.run();
// Retrieving the generated results
long[] spAsNodes;
long[] spAsEdges;
int hopsDone;
if (sp.existsShortestPath()) {
spAsNodes = sp.getPathAsNodes();
spAsEdges = sp.getPathAsEdges();
hopsDone = sp.getCost();
}
// Closing the instance
sp.close();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
SinglePairShortestPathDijkstra class:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
long iddestination = graph.findObj(nodetype, new Value("Rome"));
SinglePairShortestPathDijkstra sp = new SinglePairShortestPathDijkstra(graph, idsource, iddestination);
// Adding the allowed edge types for traversing the graph
int edgetype1 = graph.findType("street");
long weightedattr1 = graph.findAttribute(edgetype1, "weight");
sp.addWeightedEdge(edgetype1, Algorithm.NAVIGATION_FORWARD, weightedattr1);
int edgetype2 = graph.findType("road");
long weightedattr2 = graph.findAttribute(edgetype2, "weight");
sp.addWeightedEdge(edgetype2, Algorithm.NAVIGATION_UNDIRECTED, weightedattr1);
// Setting no maximum hops (not calling the method)
// Running the algorithm
sp.run();
// Retrieving the generated results
long[] spAsNodes;
long[] spAsEdges;
double cost;
if (sp.existsShortestPath()) {
spAsNodes = sp.getPathAsNodes();
spAsEdges = sp.getPathAsEdges();
cost = sp.getCost();
}
// Closing the instance
sp.close();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
TraversalBFS class:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
TraversalBFS bfs = new TraversalBFS(graph, idsource);
// Adding the allowed edge types for traversing the graph
int edgetype1 = graph.findType("street");
bfs.addEdge(edgetype1, Algorithm.NAVIGATION_FORWARD);
int edgetype2 = graph.findType("road");
bfs.addEdge(edgetype2, Algorithm.NAVIGATION_FORWARD);
// Adding the allowed node types for traversing the graph
bfs.addAllNodes();
// Running the algorithm
long idnode;
while (bfs.hasNext()) {
idnode = bfs.next();
}
// Closing the instance
bfs.close();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
TraversalDFS class:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
TraversalDFS dfs = new TraversalDFS(graph, idsource);
// Adding the allowed edge types for traversing the graph
dfs.addAllEdges(Algorithm.NAVIGATION_BACKWARD);
// Adding the allowed node types for traversing the graph
int nodetype1 = graph.findType("city");
dfs.addNode(nodetype1);
int nodetype2 = graph.findType("town");
dfs.addNode(nodetype2);
// Running the algorithm
long idnode;
while (dfs.hasNext()) {
idnode = dfs.next();
}
// Closing the instance
dfs.close();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
WeakConnectivityDFS class:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
WeakConnectivityDFS wcc = new WeakConnectivityDFS(graph);
// Adding the allowed edge types for traversing the graph
wcc.addAllEdges();
// Adding the allowed node types for traversing the graph
int nodetype1 = graph.findType("city");
wcc.addNode(nodetype1);
int nodetype2 = graph.findType("town");
wcc.addNode(nodetype2);
// Running the algorithm
wcc.run();
// Getting the instance which has the results
ConnectedComponents ccs = wcc.getConnectedComponents();
// Closing the instance of the algorithm
wcc.close();
/***** Retrieving information from the resulting instance *****/
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
// Retrieving the connected component where the given node belongs to.
long idComponent = ccs.getConnectedComponent(idsource);
// Retrieving the collection of node contained in the given component.
Objects nodes = ccs.getNodes(idComponent);
// Retrieving the number of nodes contained in the given component.
long nodes1size = ccs.getSize(idComponent);
// Retrieving the number of connected components found.
long totalCCS = ccs.getCount();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
WeakConnectivityDFS materializing
its results:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
WeakConnectivityDFS wcc = new WeakConnectivityDFS(graph);
// Adding the allowed edge types for traversing the graph
wcc.addAllEdges();
// Setting the common attribute type in order to materialize
// the results
wcc.setMaterializedAttribute("component_24_09_2009");
// Adding the allowed node types for traversing the graph
int nodetype1 = graph.findType("city");
wcc.addNode(nodetype1);
int nodetype2 = graph.findType("town");
wcc.addNode(nodetype2);
// Running the algorithm
wcc.run();
// Closing the instance of the algorithm
wcc.close();
// Closing the graph
sess.close();
gp.close();
dex.close();
// Opening the graph again
dex = new DEX();
gp = dex.open("./data.dex");
sess = gp.newSession();
graph = sess.getDbGraph();
/***** Retrieving information materialized in the graph *****/
ConnectedComponents ccs = new ConnectedComponents(graph, "component_24_09_2009");
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
// Retrieving the connected component where the given node belongs to.
long idComponent = ccs.getConnectedComponent(idsource);
// Retrieving the collection of node contained in the given component.
Objects nodes = ccs.getNodes(idComponent);
// Retrieving the number of nodes contained in the given component.
long nodes1size = ccs.getSize(idComponent);
// Retrieving the number of connected components found.
long totalCCS = ccs.getCount();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
StrongConnectivityGabow class:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
StrongConnectivityGabow scc = new StrongConnectivityGabow(graph);
// Adding the allowed edge types for traversing the graph
scc.addAllEdges();
// Adding the allowed node types for traversing the graph
int nodetype1 = graph.findType("city");
scc.addNode(nodetype1);
int nodetype2 = graph.findType("town");
scc.addNode(nodetype2);
// Running the algorithm
scc.run();
// Getting the instance which has the results
ConnectedComponents ccs = scc.getConnectedComponents();
// Closing the instance of the algorithm
scc.close();
/***** Retrieving information from the resulting instance *****/
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
// Retrieving the connected component where the given node belongs to.
long idComponent = ccs.getConnectedComponent(idsource);
// Retrieving the collection of node contained in the given component.
Objects nodes = ccs.getNodes(idComponent);
// Retrieving the number of nodes contained in the given component.
long nodes1size = ccs.getSize(idComponent);
// Retrieving the number of connected components found.
long totalCCS = ccs.getCount();
// Closing the graph
sess.close();
gp.close();
dex.close();
The following example shows how to use the
StrongConnectivityGabow class
materializing its results:
// Opening the graph
DEX dex = new DEX();
GraphPool gp = dex.open("./data.dex");
Session sess = gp.newSession();
DbGraph graph = sess.getDbGraph();
// Creating a new instance and setting its parameters
StrongConnectivityGabow scc = new StrongConnectivityGabow(graph);
// Adding the allowed edge types for traversing the graph
scc.addAllEdges();
// Setting the common attribute type in order to materialize
// the results
scc.setMaterializedAttribute("component_24_09_2009");
// Adding the allowed node types for traversing the graph
int nodetype1 = graph.findType("city");
scc.addNode(nodetype1);
int nodetype2 = graph.findType("town");
scc.addNode(nodetype2);
// Running the algorithm
scc.run();
// Closing the instance of the algorithm
scc.close();
// Closing the graph
sess.close();
gp.close();
dex.close();
// Opening the graph again
dex = new DEX();
gp = dex.open("./data.dex");
sess = gp.newSession();
graph = sess.getDbGraph();
/***** Retrieving information materialized in the graph *****/
ConnectedComponents ccs = new ConnectedComponents(graph, "component_24_09_2009");
int nodetype = graph.findType("city");
long idsource = graph.findObj(nodetype, new Value("Barcelona"));
// Retrieving the connected component where the given node belongs to.
long idComponent = ccs.getConnectedComponent(idsource);
// Retrieving the collection of node contained in the given component.
Objects nodes = ccs.getNodes(idComponent);
// Retrieving the number of nodes contained in the given component.
long nodes1size = ccs.getSize(idComponent);
// Retrieving the number of connected components found.
long totalCCS = ccs.getCount();
// Closing the graph
sess.close();
gp.close();
dex.close();
|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||