Compare commits

..

2 commits
master ... loic

Author SHA1 Message Date
Loic Guegan
e513bd7e53 Edit grid 2016-03-01 12:11:16 +01:00
Loic Guegan
a685b7db4a Merge branch 'master' into develop 2016-03-01 11:31:07 +01:00
17 changed files with 31 additions and 992 deletions

View file

@ -1,12 +1 @@
Routage Opportuniste
===================
This project is a graphical routing simulator. This project was design for proving that take care about radio conditions can improve **wifi** performance.
![Test](https://raw.githubusercontent.com/manzerbredes/routage-optimiste/master/resources/screen.png)
Library
-------------
This project was made with **GraphStream** to easily build graphical representation of the network (routers, links and weight).
# routage-optimiste

Binary file not shown.

View file

@ -1,17 +0,0 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAABCAAGBQJVI85YAAoJEFcic6tDtcUcvnoP+QFbmAiUFHOY5NzZ+TXory/+
vPys1yfmc3bDtCrVoSSY7IDBXOKHgWyFbpHvIriFB/03NdbOWeKv4wkwLzaZ1UQB
03fuHjLbzzXgXx5gtH5kjzar04DOMVOt/uAZObtgF+zksHbeJgTX5I/puj2qXYSM
T1d7wh2hqufxwXJFSHfsKO0RS4Q35eqRJffprZG7o40j/1Jew05dxm+7n7jkNyF8
zXtAEUAd8XCFxyxM/4Mig6aXJn1TZ4GOPgRt/N5WH3MJ12qPIakPUNU7qCyK+VHS
habbi07pmQ0q9maYp1zKcVauOd3jNeDr1jHrvJRZN2oK70jBhNNRMn26WNKU8SFt
YwlxlO3jkzmuKlML2C86eQpLYnqiqEY7080i0BOvWgWuPIFQgBrUOLnBqaNiEl+H
wy0OTWRXtx9nmsIl08OdmqF5IYIyXnUA3Rg9WdxM6dL2HANyNiBf0TT/g7zhrjID
YxZaSI9sb/DFBg6CDAqKR9B9qWo6SceLEX4LYK6uL3Ar9u9QCM+v7gDf+5vs97nt
tQkT/uhPKgFfFuU1Cflm3qlh7/x63qgtq0qT5P3cljKl3Zr7qVGdOuLlqGJyvV6w
A/7pnGK3QeVa8ygir/QZQDoNXla6busU7NWFGcejRL6smoJ5GBPh3bDIIrJyB74/
j263b0HdiYvEsQHo8V/B
=ddRY
-----END PGP SIGNATURE-----

Binary file not shown.

View file

@ -1,17 +0,0 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAABCAAGBQJVI84tAAoJEFcic6tDtcUcP2kP/0YnPFOaKqxqIio68UwHZp7Y
fMfp1a1pJt1Tu93fyr/zGA7MCrJ020pwW4V8qFJrsc/Bz2mV8Q013vTTBc3g/zmy
aClw1WItf5IrNIJ25s66U2xmqzBSzcEKjPIeI6aQfBRa10yQbLQ80hw0XtzoS55p
+ZgtgnoXfgvEDsOi/n5pc24P37JHbX2ZHVHFu2+hi5vhVdih8BUnRntf5Kc/t47r
d/vGEIhEe89UgWJOwsrkkaMDI/9O1/c9A7uvJIrT/nvRLBEbQsyeuZZsmCM0gP5d
ugetYRj6Y8/j0nMspQqYfVATdlTKQCr5rUhREB49hatU8mt9bBIkdXzpYl784zX5
Vi5HmVBLQx9ETBgItSYfifsT80kcnYu+azJzSXSQiP2Kpyphi4+Za7o+jTGucW/M
ncKciq3kZOVlBpodn2k4Bl0x+uDwMrvyF4roR7X05OPwAQQpRS6Wz4hnDFz24pbC
vSggRZtoDLWdluY9/VgPpzMkC9BZnzwY8mgHX7GMq+gQFF9/BTJhvDx2MTU8qOF0
P149EIiYL4d47L7djtiale07b3KN1muMeh2d3yFSAwJfL/X2I98eZDgOwz15EGWG
7KyHeJSUzOjfhIk6OGqmol3WrERsE6RRmdOHFfboCdd2yLbtCgiBBve9GnwE63ew
p7sjKHK+gu8hobzH8Jla
=8Uq+
-----END PGP SIGNATURE-----

Binary file not shown.

View file

@ -1,17 +0,0 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAABCAAGBQJVI84tAAoJEFcic6tDtcUcGOYQAJxx6xLnze2kiv6dWSaiJMwc
Lq5IrJPAWn1Ed89g3Ay2E8cYSTwYxGafBkGTyL3KyefS6W2xrnJjhHOj4GckZqSU
O8x6vLJL5/i4uXY3EtN594nRH23U1fXCFz+oVXBREprrUZ9Z+x3DiD3zzjMHCI9H
Js349kbLXkTM9JNdA9I7Zf4rJyENwQznG5Q7X6s2YHebulh9rdJnG9aVGm66Hx5+
AktlcctqwUd9fdK50lo+UBHOI/RksX88WR+JyNh/mMzRdLJuHyxotAPQl9sXnJdq
qX7P4vI2i4V2parPuk4JFe0weJ0NQCYL//0E81KPABj2F859K6DtsoHn8Zqw5dtw
J0Luj5GNGPirQRPgDdmVc7ewKAKOdJAFmejMAR8ShKNK9E1D+gp/wgbzgsQqy9t0
f47d2dWOk1WZa5Q5LzU8gpJc4IV7t6EAbbSMj4uS+gkVWpTwRnQcUMl0dsOg8fw+
Z9bL6zenamyD8boE7e/jCrDMaYvZCm/hD9Y9qtWupbYYX3c95Yy3WTeQSITBAq11
gdHG6GDPdb3A1wm+h8oI2xVLgB/7Al1a/jnppnDuORZBhAdLKXevef6dYyIa5Ppc
PzYNwjqbybARLW9HtjGtKqGNt8EzMYyipC9eaGYEqJC2ZkcYLKhSg1UM1ItJTXmr
6AuIR0liKH3Oyp+Q4KxH
=Qoor
-----END PGP SIGNATURE-----

View file

@ -1,369 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of GraphStream <http://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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<groupId>org.graphstream</groupId>
<artifactId>gs-ui</artifactId>
<version>1.3</version>
<name>gs-ui</name>
<description>
The GraphStream library. With GraphStream you deal with
graphs. Static and Dynamic. You create them from scratch, from a file
or any source. You display and render them.
</description>
<url>http://graphstream-project.org</url>
<!-- Source code of GraphStream is hosted on GitHub. -->
<scm>
<connection>scm:git:git://github.com/graphstream/gs-ui.git</connection>
<developerConnection>scm:git:git://github.com/graphstream/gs-ui.git</developerConnection>
<url>https://github.com/graphstream/gs-ui</url>
</scm>
<!-- GraphStream is using the GitHub issue tracker. -->
<issueManagement>
<system>github</system>
<url>https://github.com/graphstream/gs-core/issues</url>
</issueManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.10.1</scala.version>
</properties>
<!-- The GraphStream Team. Members are sorted in alphabetically. -->
<developers>
<developer>
<id>sbalev</id>
<name>Stefan Balev</name>
<email>stefan.balev@graphstream-project.org</email>
<organization>LITIS</organization>
<organizationUrl>http://www.litislab.eu</organizationUrl>
</developer>
<developer>
<id>jbaudry</id>
<name>Julien Baudry</name>
<email>julien.baudry@graphstream-project.org</email>
<organization>LITIS</organization>
<organizationUrl>http://www.litislab.eu</organizationUrl>
</developer>
<developer>
<id>adutot</id>
<name>Antoine Dutot</name>
<email>antoine.dutot@graphstream-project.org</email>
<organization>LITIS</organization>
<organizationUrl>http://www.litislab.eu</organizationUrl>
</developer>
<developer>
<id>ypigne</id>
<name>Yoann Pigné</name>
<email>yoann.pigne@graphstream-project.org</email>
<organization>University of Luxembourg</organization>
<organizationUrl>http://www.uni.lu</organizationUrl>
</developer>
<developer>
<id>gsavin</id>
<name>Guilhelm Savin</name>
<email>guilhelm.savin@graphstream-project.org</email>
<organization>LITIS</organization>
<organizationUrl>http://www.litislab.eu</organizationUrl>
</developer>
</developers>
<licenses>
<license>
<name>LGPL3</name>
<url>http://www.gnu.org/copyleft/lesser.html</url>
</license>
<license>
<name>Cecill-C</name>
<url>http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
</url>
</license>
</licenses>
<profiles>
<profile>
<!--
This profile uses the proguard plugin to reduce the size of the
output jar. It is usefull when combined with nodeps profile which
includes scalalib : size gain is about 9Mo.
-->
<id>proguard</id>
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<options>
<option>-dontwarn scala.**</option>
<option>-keep public class
org.graphstream.**</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
</libs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!--
This profile includes the scalalib in the output jar. One who want
to use this profile has to provide a scalalib folder at the same
hierarchic level that this project and that contains scalalib
classes.
-->
<id>nodeps</id>
<build>
<resources>
<resource>
<directory>../scalalib</directory>
<includes>
<include>scala/**/*.class</include>
</includes>
</resource>
</resources>
</build>
</profile>
<profile>
<!--
This profile has to be enabled when releasing the package. It will
enable the sign phase.
-->
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<keyname><![CDATA[GraphStream Team <team@graphstream-project.org>]]></keyname>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>scala-2.9.0</id>
<properties>
<scala.version>2.9.0</scala.version>
</properties>
</profile>
<profile>
<id>scala-2.10.1</id>
<properties>
<scala.version>2.10.1</scala.version>
</properties>
</profile>
</profiles>
<build>
<sourceDirectory>src-scala</sourceDirectory>
<outputDirectory>bin/classes</outputDirectory>
<defaultGoal>compile</defaultGoal>
<resources>
<!-- Resources other than classes are included here. -->
<!-- -->
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.9</version>
<configuration>
<sourceIncludes>
<include>**</include>
</sourceIncludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>org/graphstream/ui/j2dviewer/renderer/test</exclude>
<exclude>org/graphstream/ui/j2dviewer/renderer/test/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<!--<classifier>${scala.version}</classifier>-->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<tags>
<tag>
<name>complexity</name>
<placement>a</placement>
<head>Computational Complexity :</head>
</tag>
<tag>
<name>reference</name>
<placement>a</placement>
<head>Scientific Reference :</head>
</tag>
</tags>
<author>true</author>
<nodeprecated>false</nodeprecated>
<nodeprecatedlist>false</nodeprecatedlist>
<noindex>false</noindex>
<nonavbar>false</nonavbar>
<notree>false</notree>
<show>public</show>
<source>1.5</source>
<splitindex>true</splitindex>
<use>true</use>
<version>true</version>
<windowtitle>The GraphStream ${project.version} API</windowtitle>
<includes>
<include>**.scala</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<!--<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<filesets>
<fileset>
<directory>bin/</directory>
<includes>
<include>classes.timestamp</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-core</artifactId>
<version>${project.version}</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-algo</artifactId>
<version>${project.version}</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<optional>false</optional>
</dependency>
</dependencies>
</project>

View file

@ -1,17 +0,0 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAABCAAGBQJVI84tAAoJEFcic6tDtcUcTBoP/2T2fMfMkEevIGuDkvwnDTlv
M2EVbe8zvUuYoX9AWtvv5K2SmsilCfjhw1mfgcMOa2ckgs2ke6F6u+cAY08yKd/7
prFUxN8BAVmIp7Z7Dk+APOjfyTKbxCug/zESseN6WUb1Q2z2fsSdDLvHE5olTM+J
Kbi0w7xrBKD0/4WZ17v/P8FC2u2mtQAi9a4/OAqR7bmh09CRfEI9M4RfPfyg/Rjx
O/vxdyPO8TdRlDYfrL992At+GvsEPO1nfRJPP2CHHZEB9xWziET0MDQxrLFicE8G
sRVZuJV+Hp7Z7XDWk63VTtcECCrQbUjX1PGGXlIZsamouUosnuf9WeCtlpgQAYQd
zK6O394Z2rHCF/2ZxIKJle6z0wr7YRg+X/O8nLO4scLPU+JYMn3jKmAQBFGEKJKe
l5lVbYRlRPgFt0wk13G5X+/nvhOrfN+IF1BASGLC/R0aybqz7iPnYxWEDJrFayPq
zJeQJsClq5QeZYgYlNATB/9hKgEjuvryUE+mQ7ZMiD0zYAvcfcOqPetqNxWv/O7r
JYZetfE0CDPEr+p6IOCGX0xghFxpMk+fMxTwbnD7nUqXubykfqWytZXlMap01ycG
okVD0zDcCTKA4n5EeCGeCzyrDbvq8xjm/fR1uO3qjzKSNbpX/3cjtwp70kH/xQT8
r6Lo4IgCX7utoBQTDZrT
=lZ+K
-----END PGP SIGNATURE-----

View file

@ -1,43 +1,16 @@
package main;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.layout.springbox.EdgeSpring;
import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer;
import org.graphstream.ui.util.EdgePoints;
import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
import structure.Grid;
import structure.MyGraph;
import structure.Router;
public class Main {
public static void main(String[] args) {
Grid g=new Grid(Grid.Protocol.AODV);
// Build Graph for graphstream
MyGraph gr=new MyGraph("Routage Oportuniste", g);
gr.display();
// Update Graph
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g.buildEdgeWithRandomWeigth();
System.out.println("Update !");
gr.update();
}
Grid g=new Grid(5, 6,25);
g.displayGrid();
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

View file

@ -1,18 +0,0 @@
node {
size: 64px;
fill-mode: image-scaled;
fill-image: url('resources/images/r1.png');
text-offset:30,30;
text-size: 20;
}
edge {
text-size: 20;
size:2;
text-offset:25,25;
}
graph {
padding: 50;
}

View file

@ -1,300 +1,44 @@
package structure;
// cedric.gueguen@irisa.fr
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.*;
import java.util.Map.Entry;
public class Grid {
public enum Protocol {
AODV, DSDV, CUSTOM
}
private ArrayList<ArrayList<Integer>> m_grid=new ArrayList<>();
private ArrayList<Router> routers=new ArrayList<>();
private ArrayList<ArrayList<Integer>> links=new ArrayList<>();
private int bestLink;
private Protocol protocol;
private int counterCUSTOM=5;
private Random rand = new Random();
private final int maxWeight=100;
/**
* Build a 3x3 Grid
*/
public Grid(Protocol protocol){
// Build router liste
for(int i=0;i<9;i++){
this.routers.add(new Router());
}
this.buildEdgeWithRandomWeigth();
this.buildPath();
this.protocol=protocol;
switch(protocol){
case AODV:
this.bestLink=this.getBestLinkIndex();
break;
case DSDV:
case CUSTOM:
HashMap<Integer,Integer> currentBestLink=new HashMap<>();
for(int i=0;i<100000;i++){
int current=this.getBestLinkIndex();
if(currentBestLink.containsKey(current)){
currentBestLink.put(current, currentBestLink.get(current)+1);
}
else{
currentBestLink.put(current, 1);
}
this.buildEdgeWithRandomWeigth();
}
Set<Integer> entryTMP = currentBestLink.keySet();
int max=currentBestLink.get(entryTMP.iterator().next());
int maxId=0;
entryTMP = currentBestLink.keySet();
Iterator<Integer> it=entryTMP.iterator();
while(it.hasNext()) {
int entryId=it.next();
int entry=currentBestLink.get(entryId);
if(entry> max){
max=entry;
maxId=entryId;
}
System.out.println("Id : "+ entryId + " max "+ entry);
}
this.bestLink=maxId;
System.out.println("Retenu :"+maxId);
break;
}
public Grid(int size_x, int size_y, int max_rand){
this.generateGrid(size_x,size_y, max_rand);
}
public void buildEdgeWithRandomWeigth(){
// First line
this.buildLinkWithRandomWeight(routers.get(0), routers.get(1));
this.buildLinkWithRandomWeight(routers.get(1), routers.get(2));
// Second line
this.buildLinkWithRandomWeight(routers.get(3), routers.get(4));
this.buildLinkWithRandomWeight(routers.get(4), routers.get(5));
// Third line
this.buildLinkWithRandomWeight(routers.get(6), routers.get(7));
this.buildLinkWithRandomWeight(routers.get(7), routers.get(8));
// First column
this.buildLinkWithRandomWeight(routers.get(0), routers.get(3));
this.buildLinkWithRandomWeight(routers.get(3), routers.get(6));
// Second column
this.buildLinkWithRandomWeight(routers.get(1), routers.get(4));
this.buildLinkWithRandomWeight(routers.get(4), routers.get(7));
// Third column
this.buildLinkWithRandomWeight(routers.get(2), routers.get(5));
this.buildLinkWithRandomWeight(routers.get(5), routers.get(8));
}
private void buildPath(){
// Link1
ArrayList<Integer> link1=new ArrayList<>();
link1.add(0);link1.add(1);link1.add(2);link1.add(5);link1.add(4);link1.add(3);link1.add(6);link1.add(7);link1.add(8);
this.links.add(link1);
// Link2
ArrayList<Integer> link2=new ArrayList<>();
link2.add(0);link2.add(1);link2.add(2);link2.add(5);link2.add(4);link2.add(7);link2.add(8);
this.links.add(link2);
// link3
ArrayList<Integer> link3=new ArrayList<>();
link3.add(0);link3.add(1);link3.add(2);link3.add(5);link3.add(8);
this.links.add(link3);
// link4
ArrayList<Integer> link4=new ArrayList<>();
link4.add(0);link4.add(1);link4.add(4);link4.add(5);link4.add(8);
this.links.add(link4);
// link5
ArrayList<Integer> link5=new ArrayList<>();
link5.add(0);link5.add(3);link5.add(4);link5.add(5);link5.add(8);
this.links.add(link5);
// link6
ArrayList<Integer> link6=new ArrayList<>();
link6.add(0);link6.add(3);link6.add(4);link6.add(7);link6.add(8);
this.links.add(link6);
// link7
ArrayList<Integer> link7=new ArrayList<>();
link7.add(0);link7.add(3);link7.add(6);link7.add(7);link7.add(8);
this.links.add(link7);
// link8
ArrayList<Integer> link8=new ArrayList<>();
link8.add(0);link8.add(3);link8.add(6);link8.add(7);link8.add(4);link8.add(5);link8.add(8);
this.links.add(link8);
// link9
ArrayList<Integer> link9=new ArrayList<>();
link9.add(0);link9.add(3);link9.add(6);link9.add(7);link9.add(4);link9.add(1);link9.add(2);link9.add(5);link9.add(8);
this.links.add(link9);
// link10
ArrayList<Integer> link10=new ArrayList<>();
link10.add(0);link10.add(3);link10.add(4);link10.add(1);link10.add(2);link10.add(5);link10.add(8);
this.links.add(link10);
// link11
ArrayList<Integer> link11=new ArrayList<>();
link11.add(0);link11.add(1);link11.add(4);link11.add(3);link11.add(6);link11.add(7);link11.add(8);
this.links.add(link11);
}
private void buildLinkWithRandomWeight(Router router1, Router router2){
router1.buildLink(router2, rand.nextInt(this.maxWeight));
}
public int getBestLinkIndex(){
int currentBestLink=0;
int currentBestLinkBottleneck=0;
for(int i=0;i<this.links.size();i++){
ArrayList<Integer> currentLink=this.links.get(i);
int currentLinkBottleneck=this.getMaxBottleneck(currentLink);
if(currentBestLinkBottleneck<currentLinkBottleneck){
currentBestLink=i;
currentBestLinkBottleneck=currentLinkBottleneck;
private void generateGrid(int size_x, int size_y, int max_rand){
for(int x=0;x<size_x;x++){
m_grid.add(new ArrayList<Integer>());
for(int y=0;y<size_y;y++){
m_grid.get(x).add( (int) (Math.random() * max_rand ));
}
}
return currentBestLink;
}
private int getMaxBottleneck(ArrayList<Integer> link){
int max=this.getWeigthOfLink(link.get(0), link.get(1));
for(int j=1;j<link.size()-1;j++){
int currentMax=this.getWeigthOfLink(link.get(j), link.get(j+1));
if(max>currentMax){
max=currentMax;
public void displayGrid(){
Iterator<ArrayList<Integer>> i=m_grid.iterator();
while(i.hasNext()){
ArrayList<Integer> current=i.next();
Iterator<Integer> j=current.iterator();
while(j.hasNext()){
System.out.print(j.next() + " ");
}
}
return max;
}
private int getWeigthOfLink(int router1,int router2){
return this.routers.get(router1).getWeight(this.routers.get(router2));
}
public void printLinkWeight(){
for(int i=0;i<this.links.size();i++){
ArrayList<Integer> link=this.links.get(i);
System.out.print("Link number " + i + " ==> ");
for(int j=0;j<link.size()-1;j++){
System.out.print(this.getWeigthOfLink(link.get(j), link.get(j+1)) + " ");
}
System.out.println(" Goulot :"+this.getMaxBottleneck(link));
//System.out.println();
System.out.println();
}
}
public boolean isEdgeOfLink(ArrayList<Integer>link, Router src, Router dest){
for(int j=0;j<link.size()-1;j++){
Router current=this.routers.get(link.get(j));
if(src.name.equals(current.name)){
if(j<link.size()-1){
Router currentDest=this.routers.get(link.get(j+1));
if(currentDest.name.equals(dest.name)){
return true;
}
}
}
}
for(int j=0;j<link.size()-1;j++){
Router current=this.routers.get(link.get(j));
if(dest.name.equals(current.name)){
if(j<link.size()-1){
Router currentDest=this.routers.get(link.get(j+1));
if(currentDest.name.equals(src.name)){
return true;
}
}
}
}
return false;
}
public ArrayList<Router> getGrid() {
return routers;
}
public void setGrid(ArrayList<Router> grid) {
this.routers = grid;
}
public ArrayList<ArrayList<Integer>> getLinks() {
return links;
}
public void setLinks(ArrayList<ArrayList<Integer>> links) {
this.links = links;
}
/**
* @return the bestLinkByProtocol
*/
public int getBestLinkByProtocol() {
if(this.protocol==Protocol.CUSTOM){
this.counterCUSTOM--;
if(this.counterCUSTOM==0){
this.bestLink=this.getBestLinkIndex();
this.counterCUSTOM=5;
}
}
return bestLink;
}
}

View file

@ -1,162 +0,0 @@
package structure;
import java.util.*;
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.layout.springbox.EdgeSpring;
import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer;
import org.graphstream.ui.util.EdgePoints;
public class MyGraph extends SingleGraph{
private Grid grid;
private int miss=0;
private int success=0;
public MyGraph(String title, Grid grid) {
super(title);
// Allow CSS on view
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
// Set graph CSS
this.addAttribute("ui.stylesheet", "url('resources/style.css')");
// Assign grid
this.grid=grid;
int i=0;
int ll=this.grid.getGrid().size();
// Build node
for(Router r : this.grid.getGrid()){
if(i==0){
this.addNode(r.name).setAttribute("ui.label", "Source");
}
else{
if(i==ll-1){
this.addNode(r.name).setAttribute("ui.label", "Destination");
}
else{
this.addNode(r.name);
}
}
i++;
}
// Build Edges
this.buildEdges();
//Build bestLink
this.showBestLink();
}
public void buildEdges(){
/*Iterator<Edge> edges=this.getEdgeIterator();
while(edges.hasNext()){
Edge edge=edges.next();
this.removeEdge(edge);
}*/
for(Router r : this.grid.getGrid()){
String current=r.name;
HashMap<Router, Integer> relier=r.getLinks();
Set<Router> k=relier.keySet();
Iterator<Router> i=k.iterator();
while(i.hasNext()){
Router currentRouter=i.next();
String currentRouterName=currentRouter.name;
try{
Edge toAdd=this.addEdge(current+currentRouterName, current, currentRouterName);
toAdd.setAttribute("ui.label", relier.get(currentRouter));
}
catch(Exception e){
// System.out.println("Bug de merde.");
}
}
}
}
public void showBestLink(){
ArrayList<Integer> bestLink=this.grid.getLinks().get(this.grid.getBestLinkByProtocol());
for(int i=0;i<bestLink.size();i++){
Iterator<Node> nodes= this.getNodeIterator();
while(nodes.hasNext()){
Node node=nodes.next();
Iterator<Edge> edges=node.getEdgeIterator();
while(edges.hasNext()){
Edge edge=edges.next();
if(i<(bestLink.size()-1)){
int destIndex=bestLink.get(i+1);
String src=this.grid.getGrid().get(bestLink.get(i)).name;
String dest=this.grid.getGrid().get(bestLink.get(i+1)).name;
if((edge.getNode0().getId().equals(src) && edge.getNode1().getId().equals(dest))||(edge.getNode1().getId().equals(src) && edge.getNode0().getId().equals(dest))){
edge.setAttribute("ui.style", "fill-color:red;");
}
}
}
}
}
}
public void update(){
// Reset color
Iterator<Edge> edges=this.getEdgeIterator();
while(edges.hasNext()){
Edge edge=edges.next();
edge.setAttribute("ui.style", "fill-color:black;");
}
// Update label
edges=this.getEdgeIterator();
while(edges.hasNext()){
Edge edge=edges.next();
for(Router r : this.grid.getGrid()){
String current=r.name;
HashMap<Router, Integer> relier=r.getLinks();
Set<Router> k=relier.keySet();
Iterator<Router> i=k.iterator();
while(i.hasNext()){
Router currentRouter=i.next();
String currentRouterName=currentRouter.name;
if(edge.getId().equals(current+currentRouterName)||edge.getId().equals(currentRouterName+current)){
edge.setAttribute("ui.label", relier.get(currentRouter));
}
}
}
}
if(this.grid.getBestLinkByProtocol()==this.grid.getBestLinkIndex()){
this.success++;
}
else{
this.miss++;
}
System.out.println("Success = " + this.success + " Miss = " + this.miss + " try number :"+(this.success+this.miss)) ;
//Build bestLink
this.showBestLink();
}
}

View file

@ -1,50 +0,0 @@
package structure;
import java.util.ArrayList;
import java.util.HashMap;
public class Router {
private static int id=-1;
public String name;
private HashMap<Router,Integer> links=new HashMap<>();
public Router() {
// TODO Auto-generated constructor stub
id++;
this.name=""+id;
}
public void resetLinks(){
this.links=new HashMap<>();
}
public void buildLink(Router router, int weight){
this.links.remove(router);
router.removeLink(this);
this.links.put(router, weight);
router.addLink(this, weight);
}
public void addLink(Router router, int weight){
this.links.put(router, weight);
}
public int getWeight(Router router){
return this.links.get(router);
}
public HashMap<Router, Integer> getLinks() {
return links;
}
public void removeLink(Router router){
this.links.remove(router);
}
public void setLinks(HashMap<Router, Integer> links) {
this.links = links;
}
}