GraphStream Users

Archives de la liste Aide


Re: how can I display 20,000 nodes in graph


Chronologique Discussions 
  • 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

PNG image

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);
}

}



On Feb 19, 2015, at 7:23 AM, guilhelm savin <guilhelm.savin AT gmail.com> wrote:

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.

2015-02-18 21:27 GMT+01:00 Prathyusha Meka <mekaprathyusha AT gmail.com>:
Hello,

Thanks for your response,

Here is my code,

Graph graph = new SingleGraph("StudentGraph");
String stylesheet = "node {"+
"shape: box;"+
" fill-color: white;"+
" size: 40px;"+
" stroke-mode: plain;"+
" stroke-color: blue;"+
" stroke-width: 1px;"+
"};

graph.addAttribute("ui.quality");
graph.addAttribute("ui.antialias");
graph.addAttribute("ui.stylesheet", stylesheet);
for(int i=0; i< 22300; i++){
Node currentNextStudent = graph.addNode(Integer.toString(i));
currentNextStudent.addAttribute("ui.label", Integer.toString(i));
inc = inc+45;
currentNextStudent.addAttribute("xyz", 0.0, 0.0, inc);
String edgevalue = Integer.toString(nodeiter.getStudentId()) + ": " +  Integer.toString(nextNode.getStudentId());
if(edgeList.contains(edgevalue)){
Edge e = graph.getEdge(edgevalue);
int weight = e.getAttribute("layout.weight");
weight++;
e.setAttribute(edgevalue, Integer.toString(weight));

}else{
Edge e = graph.addEdge(edgevalue, currentStudent, currentNextStudent);
e.addAttribute("weight", numberofinteractions);
edgeList.add(edgevalue);
}
}
graph.display();

}

I attached my output graph for your reference.

Thanks,
Prathyusha<Screen Shot 2015-02-16 at 12.27.47 PM.png>

On Feb 18, 2015, at 11:02 AM, guilhelm savin <guilhelm.savin AT gmail.com> wrote:

Hi,

We need more informations about how you create your graph. Maybe a sample of code to reproduce your problem ?
Why do you use "layout.frozen" ? Because layout will not be computed for nodes and so no coordinate will be provided to the renderer.

Cheers.

2015-02-18 7:51 GMT+01:00 <mekaprathyusha AT gmail.com>:
Hello,

I created 20,000 nodes and edges for each other node but I can't see all the
nodes in the graph.

I am newbie to graphstream, I used
System.setProperty("org.graphstream.ui.renderer",
"org.graphstream.ui.j2dviewer.J2DGraphRenderer");

and also "layout.frozen" for each node, but it doesn't work.

All my nodes are forming into a circle and I am unable to see the edges.

Thanks for any help.



--
Guilhelm Savin
PhD of Computer Science




--
Guilhelm Savin
PhD of Computer Science




Archives gérées par MHonArc 2.6.16.

Top of page