Commit d1e1dc06 authored by Antoine's avatar Antoine

Added a test for the LinLog layout.

The LinLog layout is in core but needs components in this package.
parent d68658c1
...@@ -32,24 +32,37 @@ ...@@ -32,24 +32,37 @@
package org.graphstream.ui.layout.test; package org.graphstream.ui.layout.test;
import org.graphstream.algorithm.generator.BarabasiAlbertGenerator;
import org.graphstream.algorithm.generator.Generator;
import org.graphstream.algorithm.generator.GridGenerator; import org.graphstream.algorithm.generator.GridGenerator;
import org.graphstream.graph.Graph; import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.MultiGraph; import org.graphstream.graph.implementations.MultiGraph;
public class TestLayout { public class TestLayout {
public static void main(String args[]) { public static void main(String args[]) {
System.getProperties().put("gs.ui.layout", "org.graphstream.ui.layout.springbox.implementations.LinLog");
(new TestLayout()).test(); (new TestLayout()).test();
} }
public void test() { public void test() {
Graph graph = new MultiGraph("test"); Graph graph = new MultiGraph("test");
graph.addAttribute("layout.force", 0.8); // int steps = 50;
graph.display(); // Generator gen = new BarabasiAlbertGenerator(2);
GridGenerator gen = new GridGenerator(); int steps = 6;
Generator gen = new GridGenerator();
gen.addSink(graph); gen.addSink(graph);
gen.begin(); gen.begin();
for(int i=0; i<30; i++) gen.nextEvents(); for(int i=0; i<steps; i++) {
gen.nextEvents();
sleep(10);
}
gen.end(); gen.end();
// try { graph.write("grid7x7.dgs"); } catch(Exception e) { }
graph.display();
}
public static void sleep(long ms) {
try { Thread.sleep(ms); } catch(Exception e) {}
} }
} }
\ No newline at end of file
/*
* Copyright 2006 - 2012
* Stefan Balev <stefan.balev@graphstream-project.org>
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* GraphStream is a library whose purpose is to handle static or dynamic
* graph, create them from scratch, file or any source and display them.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.ui.layout.test;
import java.io.IOException;
import org.graphstream.algorithm.ConnectedComponents;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.stream.ProxyPipe;
import org.graphstream.stream.file.FileSource;
import org.graphstream.stream.file.FileSourceDGS;
import org.graphstream.stream.file.FileSourceGML;
import org.graphstream.stream.thread.ThreadProxyPipe;
import org.graphstream.ui.geom.Point3;
import org.graphstream.ui.graphicGraph.GraphPosLengthUtils;
import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units;
import org.graphstream.ui.layout.springbox.implementations.LinLog;
import org.graphstream.ui.spriteManager.Sprite;
import org.graphstream.ui.spriteManager.SpriteManager;
import org.graphstream.ui.swingViewer.Viewer;
/**
* This test creates a layout (instead of using the default layout of
* the viewer) and creates a loop :
*
* <pre>
* Graph ------> Layout --+
* ^ |
* | |
* +--------------------+
* </pre>
*/
public class TestLinLogLayout {
// public static final String GRAPH = "data/dorogovtsev_mendes6000.dgs"; public static final double a= 0; public static final double r=-1.3; public static double force = 3;
public static final String GRAPH = "data/karate.gml"; public static double a= 0; public static double r=-1.3; public static double force = 3;
// public static final String GRAPH = "data/dolphins.gml"; public static double a= 0; public static double r=-1.2; public static double force = 8;
// public static final String GRAPH = "data/polbooks.gml"; public static double a= 0; public static double r=-2; public static double force = 3;
// public static final String GRAPH = "data/triangles.dgs"; public static double a= 1; public static double r=-1; public static double force = 0.5;
// public static final String GRAPH = "data/FourClusters.dgs"; public static double a= 0; public static double r=-1; public static double force = 3;
// public static final String GRAPH = "data/grid7x7.dgs"; public static double a= 0; public static double r=-1; public static double force = 100;
// public static final String GRAPH = "data/imdb.dgs";
protected Graph graph;
protected Viewer viewer;
protected LinLog layout;
protected Sprite CC;
protected ConnectedComponents cc;
public static void main(String args[]) {
new TestLinLogLayout();
}
public TestLinLogLayout() {
boolean loop = true;
graph = new MultiGraph("test");
viewer = new Viewer(new ThreadProxyPipe(graph));
ProxyPipe fromViewer = viewer.newThreadProxyOnGraphicGraph();
layout = new LinLog(false);
SpriteManager sm = new SpriteManager(graph);
CC = sm.addSprite("CC");
cc = new ConnectedComponents(graph);
cc.setCutAttribute("cut");
CC.setPosition(Units.PX, 20, 20, 0);
layout.configure(a, r, true, force);
graph.addAttribute("ui.antialias");
graph.addAttribute("ui.stylesheet", styleSheet);
fromViewer.addSink(graph);
viewer.addDefaultView(true);
graph.addSink(layout);
layout.addAttributeSink(graph);
FileSource dgs = GRAPH.endsWith(".gml") ? new FileSourceGML() : new FileSourceDGS();
dgs.addSink(graph);
try {
dgs.begin(getClass().getResourceAsStream(GRAPH));
for (int i = 0; i < 5000 && dgs.nextEvents(); i++) {
// fromViewer.pump();
// layout.compute();
// sleep(100);
}
dgs.end();
} catch (IOException e1) {
e1.printStackTrace();
System.exit(1);
}
System.out.println("Finished creating the graph.");
while (loop) {
fromViewer.pump();
if (graph.hasAttribute("ui.viewClosed")) {
loop = false;
} else {
//sleep(1000);
layout.compute();
findCommunities(1.3);
updateCC();
}
}
System.exit(0);
}
protected void findCommunities(double threshold) {
int nedges = graph.getEdgeCount();
double avgDist = 0;
double edgesDists[] = new double[nedges];
for(int i=0; i<nedges; i++) {
Edge edge = graph.getEdge(i);
Point3 posFrom = GraphPosLengthUtils.nodePointPosition(edge.getNode0());
Point3 posTo = GraphPosLengthUtils.nodePointPosition(edge.getNode1());
edgesDists[i] = posFrom.distance(posTo);
avgDist += edgesDists[i];
}
avgDist /= nedges;
// Nothing happened to the graph so the order remains.
for(int i=0; i<nedges; i++) {
Edge edge = graph.getEdge(i);
if(edgesDists[i] > avgDist*threshold) {
edge.addAttribute("ui.class", "cut");
edge.addAttribute("cut");
} else {
edge.removeAttribute("ui.class");
edge.removeAttribute("cut");
}
}
}
protected void updateCC() {
CC.setAttribute("ui.label", String.format("CC %d", cc.getConnectedComponentsCount()));
}
protected static void sleep(long ms) {
try { Thread.sleep(ms); } catch(Exception e) {}
}
protected static String styleSheet =
"node { size: 7px; fill-color: rgb(150,150,150); }" +
"edge { fill-color: rgb(255,50,50); size: 2px; }" +
"edge.cut { fill-color: rgba(200,200,200,128); }" +
"sprite#CC { size: 0px; text-color: rgb(100,100,100); text-size: 20; }";
}
\ No newline at end of file
DGS004
null 0 0
an "0"
an "1"
an "2"
an "3"
an "10"
an "11"
an "12"
an "13"
an "20"
an "21"
an "22"
an "23"
an "30"
an "31"
an "32"
an "33"
ae "0-1" "0" "1"
ae "0-2" "0" "2"
ae "0-3" "0" "3"
ae "1-2" "1" "2"
ae "1-3" "1" "3"
ae "2-3" "2" "3"
ae "10-11" "10" "11"
ae "10-12" "10" "12"
ae "10-13" "10" "13"
ae "11-12" "11" "12"
ae "11-13" "11" "13"
ae "12-13" "12" "13"
ae "20-11" "20" "21"
ae "20-12" "20" "22"
ae "20-13" "20" "23"
ae "21-12" "21" "22"
ae "21-13" "21" "23"
ae "22-13" "22" "23"
ae "30-31" "30" "31"
ae "30-32" "30" "32"
ae "30-33" "30" "33"
ae "31-32" "31" "32"
ae "31-33" "31" "33"
ae "32-33" "32" "33"
ae "inter1" "0" "10"
ae "inter2" "10" "20"
ae "inter3" "20" "30"
ae "inter4" "30" "0"
This diff is collapsed.
DGS004
null 0 0
an "0_0"
cn "0_0" "xy":{0.000000,0.000000}
an "1_0"
cn "1_0" "xy":{1.000000,0.000000}
an "0_1"
cn "0_1" "xy":{0.000000,1.000000}
an "1_1"
cn "1_1" "xy":{1.000000,1.000000}
an "2_0"
cn "2_0" "xy":{2.000000,0.000000}
an "2_1"
cn "2_1" "xy":{2.000000,1.000000}
an "0_2"
cn "0_2" "xy":{0.000000,2.000000}
an "1_2"
cn "1_2" "xy":{1.000000,2.000000}
an "2_2"
cn "2_2" "xy":{2.000000,2.000000}
an "3_0"
cn "3_0" "xy":{3.000000,0.000000}
an "3_1"
cn "3_1" "xy":{3.000000,1.000000}
an "3_2"
cn "3_2" "xy":{3.000000,2.000000}
an "0_3"
cn "0_3" "xy":{0.000000,3.000000}
an "1_3"
cn "1_3" "xy":{1.000000,3.000000}
an "2_3"
cn "2_3" "xy":{2.000000,3.000000}
an "3_3"
cn "3_3" "xy":{3.000000,3.000000}
an "4_0"
cn "4_0" "xy":{4.000000,0.000000}
an "4_1"
cn "4_1" "xy":{4.000000,1.000000}
an "4_2"
cn "4_2" "xy":{4.000000,2.000000}
an "4_3"
cn "4_3" "xy":{4.000000,3.000000}
an "0_4"
cn "0_4" "xy":{0.000000,4.000000}
an "1_4"
cn "1_4" "xy":{1.000000,4.000000}
an "2_4"
cn "2_4" "xy":{2.000000,4.000000}
an "3_4"
cn "3_4" "xy":{3.000000,4.000000}
an "4_4"
cn "4_4" "xy":{4.000000,4.000000}
an "5_0"
cn "5_0" "xy":{5.000000,0.000000}
an "5_1"
cn "5_1" "xy":{5.000000,1.000000}
an "5_2"
cn "5_2" "xy":{5.000000,2.000000}
an "5_3"
cn "5_3" "xy":{5.000000,3.000000}
an "5_4"
cn "5_4" "xy":{5.000000,4.000000}
an "0_5"
cn "0_5" "xy":{0.000000,5.000000}
an "1_5"
cn "1_5" "xy":{1.000000,5.000000}
an "2_5"
cn "2_5" "xy":{2.000000,5.000000}
an "3_5"
cn "3_5" "xy":{3.000000,5.000000}
an "4_5"
cn "4_5" "xy":{4.000000,5.000000}
an "5_5"
cn "5_5" "xy":{5.000000,5.000000}
ae "0" "0_0" "1_0"
ae "1" "0_0" "0_1"
ae "2" "1_0" "1_1"
ae "3" "0_1" "1_1"
ae "4" "1_0" "2_0"
ae "5" "1_1" "2_1"
ae "6" "2_0" "2_1"
ae "7" "0_1" "0_2"
ae "8" "1_1" "1_2"
ae "9" "0_2" "1_2"
ae "10" "2_1" "2_2"
ae "11" "1_2" "2_2"
ae "12" "2_0" "3_0"
ae "13" "2_1" "3_1"
ae "14" "3_0" "3_1"
ae "15" "2_2" "3_2"
ae "16" "3_1" "3_2"
ae "17" "0_2" "0_3"
ae "18" "1_2" "1_3"
ae "19" "0_3" "1_3"
ae "20" "2_2" "2_3"
ae "21" "1_3" "2_3"
ae "22" "3_2" "3_3"
ae "23" "2_3" "3_3"
ae "24" "3_0" "4_0"
ae "25" "3_1" "4_1"
ae "26" "4_0" "4_1"
ae "27" "3_2" "4_2"
ae "28" "4_1" "4_2"
ae "29" "3_3" "4_3"
ae "30" "4_2" "4_3"
ae "31" "0_3" "0_4"
ae "32" "1_3" "1_4"
ae "33" "0_4" "1_4"
ae "34" "2_3" "2_4"
ae "35" "1_4" "2_4"
ae "36" "3_3" "3_4"
ae "37" "2_4" "3_4"
ae "38" "4_3" "4_4"
ae "39" "3_4" "4_4"
ae "40" "4_0" "5_0"
ae "41" "4_1" "5_1"
ae "42" "5_0" "5_1"
ae "43" "4_2" "5_2"
ae "44" "5_1" "5_2"
ae "45" "4_3" "5_3"
ae "46" "5_2" "5_3"
ae "47" "4_4" "5_4"
ae "48" "5_3" "5_4"
ae "49" "0_4" "0_5"
ae "50" "1_4" "1_5"
ae "51" "0_5" "1_5"
ae "52" "2_4" "2_5"
ae "53" "1_5" "2_5"
ae "54" "3_4" "3_5"
ae "55" "2_5" "3_5"
ae "56" "4_4" "4_5"
ae "57" "3_5" "4_5"
ae "58" "5_4" "5_5"
ae "59" "4_5" "5_5"
DGS004
null 0 0
an "0_0"
cn "0_0" "xy":{0.000000,0.000000}
an "1_0"
cn "1_0" "xy":{1.000000,0.000000}
an "0_1"
cn "0_1" "xy":{0.000000,1.000000}
an "1_1"
cn "1_1" "xy":{1.000000,1.000000}
an "2_0"
cn "2_0" "xy":{2.000000,0.000000}
an "2_1"
cn "2_1" "xy":{2.000000,1.000000}
an "0_2"
cn "0_2" "xy":{0.000000,2.000000}
an "1_2"
cn "1_2" "xy":{1.000000,2.000000}
an "2_2"
cn "2_2" "xy":{2.000000,2.000000}
an "3_0"
cn "3_0" "xy":{3.000000,0.000000}
an "3_1"
cn "3_1" "xy":{3.000000,1.000000}
an "3_2"
cn "3_2" "xy":{3.000000,2.000000}
an "0_3"
cn "0_3" "xy":{0.000000,3.000000}
an "1_3"
cn "1_3" "xy":{1.000000,3.000000}
an "2_3"
cn "2_3" "xy":{2.000000,3.000000}
an "3_3"
cn "3_3" "xy":{3.000000,3.000000}
an "4_0"
cn "4_0" "xy":{4.000000,0.000000}
an "4_1"
cn "4_1" "xy":{4.000000,1.000000}
an "4_2"
cn "4_2" "xy":{4.000000,2.000000}
an "4_3"
cn "4_3" "xy":{4.000000,3.000000}
an "0_4"
cn "0_4" "xy":{0.000000,4.000000}
an "1_4"
cn "1_4" "xy":{1.000000,4.000000}
an "2_4"
cn "2_4" "xy":{2.000000,4.000000}
an "3_4"
cn "3_4" "xy":{3.000000,4.000000}
an "4_4"
cn "4_4" "xy":{4.000000,4.000000}
an "5_0"
cn "5_0" "xy":{5.000000,0.000000}
an "5_1"
cn "5_1" "xy":{5.000000,1.000000}
an "5_2"
cn "5_2" "xy":{5.000000,2.000000}
an "5_3"
cn "5_3" "xy":{5.000000,3.000000}
an "5_4"
cn "5_4" "xy":{5.000000,4.000000}
an "0_5"
cn "0_5" "xy":{0.000000,5.000000}
an "1_5"
cn "1_5" "xy":{1.000000,5.000000}
an "2_5"
cn "2_5" "xy":{2.000000,5.000000}
an "3_5"
cn "3_5" "xy":{3.000000,5.000000}
an "4_5"
cn "4_5" "xy":{4.000000,5.000000}
an "5_5"
cn "5_5" "xy":{5.000000,5.000000}
an "6_0"
cn "6_0" "xy":{6.000000,0.000000}
an "6_1"
cn "6_1" "xy":{6.000000,1.000000}
an "6_2"
cn "6_2" "xy":{6.000000,2.000000}
an "6_3"
cn "6_3" "xy":{6.000000,3.000000}
an "6_4"
cn "6_4" "xy":{6.000000,4.000000}
an "6_5"
cn "6_5" "xy":{6.000000,5.000000}
an "0_6"
cn "0_6" "xy":{0.000000,6.000000}
an "1_6"
cn "1_6" "xy":{1.000000,6.000000}
an "2_6"
cn "2_6" "xy":{2.000000,6.000000}
an "3_6"
cn "3_6" "xy":{3.000000,6.000000}
an "4_6"
cn "4_6" "xy":{4.000000,6.000000}
an "5_6"
cn "5_6" "xy":{5.000000,6.000000}
an "6_6"
cn "6_6" "xy":{6.000000,6.000000}
ae "0" "0_0" "1_0"
ae "1" "0_0" "0_1"
ae "2" "1_0" "1_1"
ae "3" "0_1" "1_1"
ae "4" "1_0" "2_0"
ae "5" "1_1" "2_1"
ae "6" "2_0" "2_1"
ae "7" "0_1" "0_2"
ae "8" "1_1" "1_2"
ae "9" "0_2" "1_2"
ae "10" "2_1" "2_2"
ae "11" "1_2" "2_2"
ae "12" "2_0" "3_0"
ae "13" "2_1" "3_1"
ae "14" "3_0" "3_1"
ae "15" "2_2" "3_2"
ae "16" "3_1" "3_2"
ae "17" "0_2" "0_3"
ae "18" "1_2" "1_3"
ae "19" "0_3" "1_3"
ae "20" "2_2" "2_3"
ae "21" "1_3" "2_3"
ae "22" "3_2" "3_3"
ae "23" "2_3" "3_3"
ae "24" "3_0" "4_0"
ae "25" "3_1" "4_1"
ae "26" "4_0" "4_1"
ae "27" "3_2" "4_2"
ae "28" "4_1" "4_2"
ae "29" "3_3" "4_3"
ae "30" "4_2" "4_3"
ae "31" "0_3" "0_4"
ae "32" "1_3" "1_4"
ae "33" "0_4" "1_4"
ae "34" "2_3" "2_4"
ae "35" "1_4" "2_4"
ae "36" "3_3" "3_4"
ae "37" "2_4" "3_4"
ae "38" "4_3" "4_4"
ae "39" "3_4" "4_4"
ae "40" "4_0" "5_0"
ae "41" "4_1" "5_1"
ae "42" "5_0" "5_1"
ae "43" "4_2" "5_2"
ae "44" "5_1" "5_2"
ae "45" "4_3" "5_3"
ae "46" "5_2" "5_3"
ae "47" "4_4" "5_4"
ae "48" "5_3" "5_4"
ae "49" "0_4" "0_5"
ae "50" "1_4" "1_5"
ae "51" "0_5" "1_5"
ae "52" "2_4" "2_5"
ae "53" "1_5" "2_5"
ae "54" "3_4" "3_5"
ae "55" "2_5" "3_5"
ae "56" "4_4" "4_5"
ae "57" "3_5" "4_5"
ae "58" "5_4" "5_5"
ae "59" "4_5" "5_5"
ae "60" "5_0" "6_0"
ae "61" "5_1" "6_1"
ae "62" "6_0" "6_1"
ae "63" "5_2" "6_2"
ae "64" "6_1" "6_2"
ae "65" "5_3" "6_3"
ae "66" "6_2" "6_3"
ae "67" "5_4" "6_4"
ae "68" "6_3" "6_4"
ae "69" "5_5" "6_5"
ae "70" "6_4" "6_5"
ae "71" "0_5" "0_6"
ae "72" "1_5" "1_6"
ae "73" "0_6" "1_6"
ae "74" "2_5" "2_6"
ae "75" "1_6" "2_6"
ae "76" "3_5" "3_6"
ae "77" "2_6" "3_6"
ae "78" "4_5" "4_6"
ae "79" "3_6" "4_6"
ae "80" "5_5" "5_6"
ae "81" "4_6" "5_6"
ae "82" "6_5" "6_6"
ae "83" "5_6" "6_6"
This diff is collapsed.
Creator "Mark Newman on Fri Jul 21 12:39:27 2006"
graph
[
node [ id 1 ]
node [ id 2 ]
node
[
id 3
]
node
[
id 4
]
node
[
id 5
]
node
[
id 6
]
node
[
id 7
]
node
[
id 8
]