-
Notifications
You must be signed in to change notification settings - Fork 7
4. Miscellaneous ‐ Stand‐alone Graph Manipulation
Jaewook Byun edited this page Feb 23, 2024
·
1 revision
Users are able to use ChronoGraph in a stand-alone mode. Here is the example to create a temporal property graph and analyze its information diffusion over time.
- Example: temporal information diffusion
- Users can use either in-memory graph or persistent graph
Graph g = new MChronoGraph();
Graph g = new PChronoGraph("mongodb://localhost:27017", "test");- Create a graph
Vertex jack = g.addVertex("Jack");
Vertex sarah = g.addVertex("Sarah");
Vertex david = g.addVertex("David");
Vertex mary = g.addVertex("Mary");
Vertex emma = g.addVertex("Emma");
Edge js = g.addEdge(jack, sarah, "contact");
Edge sj = g.addEdge(sarah, jack, "contact");
Edge jm = g.addEdge(jack, mary, "contact");
Edge mj = g.addEdge(mary, jack, "contact");
Edge sd = g.addEdge(sarah, david, "contact");
Edge ds = g.addEdge(david, sarah, "contact");
Edge sm = g.addEdge(sarah, mary, "contact");
Edge ms = g.addEdge(mary, sarah, "contact");
Edge dm = g.addEdge(david, mary, "contact");
Edge md = g.addEdge(mary, david, "contact");
Edge de = g.addEdge(david, emma, "contact");
Edge ed = g.addEdge(emma, david, "contact");
jm.addEvent(1);
mj.addEvent(1);
sd.addEvent(2);
ds.addEvent(2);
js.addEvent(3);
sj.addEvent(3);
sm.addEvent(4);
ms.addEvent(4);
dm.addEvent(5);
md.addEvent(5);
de.addEvent(6);
ed.addEvent(6);
sd.addEvent(7);
ds.addEvent(7);- Temporal Reachability (Allen Temporal Relation: 'isAfter')
HashMap<Vertex, Long> gamma = new HashMap<Vertex, Long>();
gamma.put(jack, 0l);
HashSet<VertexEvent> traversers = new HashSet<VertexEvent>();
traversers.add(jack.getEvent(0));
while (true) {
HashSet<VertexEvent> newTraversers = new HashSet<VertexEvent>();
for (VertexEvent t : traversers) {
for (VertexEvent ot : t.getVertexEvents(Direction.OUT, TemporalRelation.isAfter, "contact")) {
if (ot == null)
continue;
Vertex o = (Vertex) ot.getElement();
if (gamma.containsKey(o) && (gamma.get(o) > ot.getTime())) {
gamma.put(o, ot.getTime());
newTraversers.add(ot);
} else if (!gamma.containsKey(o)) {
gamma.put(o, ot.getTime());
newTraversers.add(ot);
}
}
}
if (newTraversers.isEmpty())
break;
else
traversers = newTraversers;
}
System.out.println("Reachable from Jack: " + gamma);
}
}