- From: Prathyusha Meka <mekaprathyusha AT gmail.com>
- To: guilhelm savin <guilhelm.savin AT gmail.com>
- Cc: "graphstream-users AT litislab.fr" <graphstream-users AT litislab.fr>
- Subject: Re: how can I display 20,000 nodes in graph
- Date: Mon, 23 Feb 2015 11:28:34 -0800
Hello,
I included the graph and sample working code. Can you please help me on how to see all the edges with edge weight between the nodes and also the graph keeps changing after few minutes. How can I restrict it from viewing different views.
Thanks for any help.
Regards, Prathyusha |

package edu.rit.mobilitygraph;
/*
* Student Graph with student as nodes and edges between students if they
attend any common session
*/
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.swingViewer.Viewer;
import edu.rit.mobilitygraph.common.*;
public class StudentGraph {
static List<MGNode> studentNodes = new ArrayList<MGNode>();
static List<MGSession> sessionList = new ArrayList<MGSession>();
static Map<MGSession, List<MGNode>> sessionMap = new
HashMap<MGSession, List<MGNode>>();
static Map<MGNode, List<MGSession>> studentGrpMap = new
HashMap<MGNode, List<MGSession>>();
static Map<List<MGNode>, Integer> StudentsinSameSession = new
HashMap<List<MGNode>, Integer>();
static Map<MGNode, Set<List<String>>> studentswithSessions = new
HashMap<MGNode, Set<List<String>>>();
Graph graph = new SingleGraph("StudentGraph");
String stylesheet = "node {"+
" fill-color: white;"+
" stroke-mode: plain;"+
" stroke-color: blue;"+
"}";
/*
* Graph for student with students as nodes, edges between them are
common sessions & edge weight is how many sessions they attend in common
* @param StudentsinSameSession List of students in same session
* @see StudentGraph
*/
void drawGraph(Map<List<MGNode>, Integer> StudentsinSameSession){
graph.addAttribute("ui.quality");
graph.addAttribute("ui.antialias");
graph.addAttribute("ui.stylesheet", stylesheet);
Viewer viewer = graph.display(false);
viewer.disableAutoLayout();
Iterator<MGNode> studentasNodes = studentNodes.iterator();
while(studentasNodes.hasNext()){
int studentID = studentasNodes.next().getStudentId();
Node currentNodeasStudent =
graph.addNode(Integer.toString(studentID));
//currentNodeasStudent.addAttribute("ui.label",
Integer.toString(studentID));
}
Collection<Edge> createdEdges = graph.getEdgeSet();
for(Map.Entry<List<MGNode>, Integer> entry:
StudentsinSameSession.entrySet()){
List<MGNode> groupedNodes = entry.getKey();
List<MGNode> groupedNodescopy = new
CopyOnWriteArrayList<MGNode>(groupedNodes);
if(groupedNodes.size()>1){
for(MGNode node: groupedNodes){
for(MGNode nodecopy:
groupedNodescopy){
if(node.equals(nodecopy)){
groupedNodescopy.remove(nodecopy);
}else{
Node currentNode =
graph.getNode(node.getStudentId());
Node nextNode =
graph.getNode(nodecopy.getStudentId());
String edgeValue =
Integer.toString(node.getStudentId()) + ":" +
Integer.toString(nodecopy.getStudentId());
if(createdEdges.contains(edgeValue)){
Edge e =
graph.getEdge(edgeValue);
int weight =
(e.getAttribute("weight"));
int newweight
= weight+ entry.getValue();
e.setAttribute("weight", newweight);
}else{
Edge e =
graph.addEdge(edgeValue, currentNode, nextNode);
e.setAttribute("weight", entry.getValue());
}
}
}
}
}
}
drawEdgesWithOtherGroups(studentswithSessions, createdEdges,
StudentsinSameSession);
//graph.display();
viewer.enableAutoLayout();
}
/*
* Draw Edges with other sessions
* @param studentswithSessions students with list of Sessions
* @param createdEdges List of edges in graph
* @param StudentsinSameSession Get other students with same set of
Sessions
*/
void drawEdgesWithOtherGroups(Map<MGNode, Set<List<String>>>
studentswithSessions, Collection<Edge> createdEdges, Map<List<MGNode>,
Integer> StudentsinSameSession){
Set<MGNode> setofNodes = studentswithSessions.keySet();
List<MGNode> setofNodescopy = new
CopyOnWriteArrayList<MGNode>(setofNodes);
for(MGNode node: setofNodes){
for(MGNode nodecopy: setofNodescopy){
if(node.equals(nodecopy)){
setofNodescopy.remove(nodecopy);
}else{
Set<List<String>> sessionListofNode =
node.getListGroupID();
List<String> studentSessionList =new
ArrayList<String>();
Iterator<List<String>> sessionsofNode
= sessionListofNode.iterator();
while(sessionsofNode.hasNext()){
studentSessionList =
sessionsofNode.next();
}
Set<List<String>>
sessionListofNodeCopy = nodecopy.getListGroupID();
Iterator<List<String>>
sessionsofNodeCopy = sessionListofNodeCopy.iterator();
List<String> studentSessionListCopy =
new ArrayList<String>();
while(sessionsofNodeCopy.hasNext()){
studentSessionListCopy =
sessionsofNodeCopy.next();
}
studentSessionList.retainAll(studentSessionListCopy);
int aftersize =
studentSessionList.size();
if(aftersize>=1){
Node currentNode =
graph.getNode(node.getStudentId());
Node nextNode =
graph.getNode(nodecopy.getStudentId());
String edgeValue =
Integer.toString(node.getStudentId()) + ":" +
Integer.toString(nodecopy.getStudentId());
if(createdEdges.contains(edgeValue)){
Edge e =
graph.getEdge(edgeValue);
int weight =
(e.getAttribute("weight"));
int newweight =
weight+aftersize ;
e.setAttribute("weight", newweight);
}else{
Edge e =
graph.addEdge(edgeValue, currentNode, nextNode);
e.setAttribute("weight", aftersize);
List<MGNode>
NodeswithsameSession = node.getListofsameNodes();
for(MGNode
samesessionNode: NodeswithsameSession){
Node
sameotherNode = graph.getNode(samesessionNode.getStudentId());
String
edgeweight = Integer.toString(samesessionNode.getStudentId()) + ":" +
Integer.toString(nodecopy.getStudentId());
if(createdEdges.contains(edgeweight)){
Edge
e1 = graph.getEdge(edgeValue);
int
weight = (e.getAttribute("weight"));
int
newweight = weight+aftersize ;
e1.setAttribute("weight", newweight);
}else{
Edge
e2 = graph.addEdge(edgeweight, sameotherNode, nextNode);
e2.setAttribute("weight", aftersize);
}
}
}
}
}
}
}
}
public static void main(String[] args){
System.setProperty("org.graphstream.ui.renderer",
"org.graphstream.ui.j2dviewer.J2DGraphRenderer");
DataParser data = new DataParser();
data.initializeData();
studentNodes = data.studentasNodes;
sessionList = data.sessionList;
sessionMap = data.sessionMap;
studentGrpMap = data.studentMap;
SessionGrouping sessionGroup = new
SessionGrouping(sessionList);
sessionGroup.groupSession(sessionMap,sessionList);
StudentsinSameSession =
sessionGroup.generateStudentMapwithCommonSessions(sessionGroup.generateStudentSessionMap(studentGrpMap));
studentswithSessions = sessionGroup.studentswithSessions;
StudentGraph grahset = new StudentGraph();
grahset.drawGraph(StudentsinSameSession);
}
}
Hi,
Please post a WORKING sample of code, so I could try to see what is your problem ! This one has a lot of missing part of code so it is not runnable. Cheers.
|
Archives gérées par MHonArc 2.6.16.