The following example shows how to use the {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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 {@link edu.upc.dama.dex.algorithms.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();