diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..26d33521af10bcc7fd8cea344038eaaeb78d0ef5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000000000000000000000000000000000000..919ce1f1f77253454105acb2aad9997c1047a0e6 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <ScalaCodeStyleSettings> + <option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" /> + </ScalaCodeStyleSettings> + </code_scheme> +</component> \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000000000000000000000000000000000000..a55e7a179bde3e4e772c29c0c85e53354aa54618 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ +<component name="ProjectCodeStyleConfiguration"> + <state> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" /> + </state> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..37e641e9151ca9f6d070a5d9f15bda303604a540 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="13" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..bdfda3bac257f756f8340a95d0a30edc6ae9f640 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/tp3-git.iml" filepath="$PROJECT_DIR$/tp3-git.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..e96534fb27b68192f27f985d3879e173ec77adb8 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/Makefile b/Makefile index 42161a500c325c4a47de09ae4cddc7b2fb67ea7e..88798851576c3bad3cfccb4a079d327941f1dc75 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,45 @@ -# Cible qui pour compiler +# Le nom de votre classe principale +# Renommez si nécessaire +MAINCLASS=Main +## Le chemin vers où votre classe compilée est installée +# Renommez si nécessaire +INSTALLDIR=out/production/TP3 + +all: compile install exec + +# Cible pour compiler compile: + cd src ; make compile + +install: + cd src ; make install + +clean: + cd src ; make clean ; make cleanInstall + rm *.zip # Cible qui explique comment executer exec: + java -classpath $(INSTALLDIR) $(MAINCLASS) # Demarre automatiquement une demonstration de votre programme # Il faut que cette demo soit convaincante demo: + java -classpath $(INSTALLDIR) $(MAINCLASS) # Executer automatiquent les test # On s'attend (d'habitude) que pour claque classe MaClasse il y ait une # classe TestMaClasse qui vorifie le bon comportment de chaque methode de la classe # sur au moins une entrée +# A vous de completer test: + + +# Cible pour créer son rendu de tp +zip: + moi=$$(whoami) ; zip -r $${moi}_renduTP2.zip * -# Pour la cible suivante, on vous laisse faire -clean: +# Cible pour vérifier le contenu de son rendu de tp +zipVerify: + moi=$$(whoami) ; unzip -l $${moi}_renduTP2.zip diff --git a/pdf/tp3.pdf b/pdf/tp3.pdf index 6a5b75186dd5af51ffb688f2a5c9bf1cc507937c..5bdc13c4a4b178d0b49c990303ae797ab7c8c8af 100644 Binary files a/pdf/tp3.pdf and b/pdf/tp3.pdf differ diff --git a/src/Graph.java b/src/Graph.java deleted file mode 100644 index 4862b8e864f2963b32730560f4ef298df270bc19..0000000000000000000000000000000000000000 --- a/src/Graph.java +++ /dev/null @@ -1,51 +0,0 @@ -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - - -public class Graph implements Iterable<Edge>{ - // classe de graphe non orientés permettant de manipuler - // en même temps des arcs (orientés) - // pour pouvoir stocker un arbre couvrant, en plus du graphe - - int order; - int edgeCardinality; - - ArrayList<LinkedList<Edge>> adjacency; - ArrayList<LinkedList<Arc>> inAdjacency; - ArrayList<LinkedList<Arc>> outAdjacency; - - public boolean isVertex(int index) { - // à remplir - } - - public <T> ArrayList<LinkedList<T>> makeList(int size) { - ArrayList<LinkedList<T>> res = new ArrayList<>(size); - for(int i = 0; i <= size; i++) { - res.add(null); - } - return res; - } - - public Graph(int upperBound) { - // à remplir - } - - public void addVertex(int indexVertex) { - // à remplir - } - - public void ensureVertex(int indexVertex) { - // à remplir - } - - public void addArc(Arc arc) { - // à remplir - } - - public void addEdge(Edge e) { - // à remplir - } - -} diff --git a/src/Arc.java b/src/Graphs/Arc.java similarity index 89% rename from src/Arc.java rename to src/Graphs/Arc.java index f11872382d58e6dc00fb84d813166a6fb3462076..ae8ce2a6a90bb24a3142e3442ca013c9c673693d 100644 --- a/src/Arc.java +++ b/src/Graphs/Arc.java @@ -1,6 +1,7 @@ +package Graphs; public class Arc { - Edge support; + public Edge support; boolean reversed; public Arc(Edge e, boolean reversed) { diff --git a/src/Edge.java b/src/Graphs/Edge.java similarity index 90% rename from src/Edge.java rename to src/Graphs/Edge.java index 19c02e092afd4ca060f7a79b432f263430b6f6a6..da68eacf9b7f788c258f67c304f975deba85a25c 100644 --- a/src/Edge.java +++ b/src/Graphs/Edge.java @@ -1,8 +1,9 @@ +package Graphs; public class Edge implements Comparable<Edge> { - protected int source; - protected int dest; + public int source; + public int dest; double weight; public Edge(int source, int dest, double weight) { diff --git a/src/Graphs/Graph.java b/src/Graphs/Graph.java new file mode 100644 index 0000000000000000000000000000000000000000..f70ccb6e87009119357066c246b8ecf8ef2d22d6 --- /dev/null +++ b/src/Graphs/Graph.java @@ -0,0 +1,49 @@ +package Graphs; + +import java.util.ArrayList; +import java.util.LinkedList; + + +public class Graph { + // classe de graphe non orientés permettant de manipuler + // en même temps des arcs (orientés) + // pour pouvoir stocker un arbre couvrant, en plus du graphe + + public int order; + int edgeCardinality; + + ArrayList<LinkedList<Edge>> adjacency; + ArrayList<LinkedList<Arc>> inAdjacency; + ArrayList<LinkedList<Arc>> outAdjacency; + + public Graph(int upperBound) { + // à remplir + } + + public boolean isVertex(int index) { + // à remplir + return true; + } + + public void addVertex(int indexVertex) { + // à remplir + } + + public void ensureVertex(int indexVertex) { + // à remplir + } + + public void addArc(Arc arc) { + // à remplir + } + + public void addEdge(Edge e) { + // à remplir + } + + public Arc[] outNeighbours(int sommet) { + // à remplir + return outAdjacency.get(sommet).toArray(new Arc[0]); + } + +} diff --git a/src/Complete.java b/src/Graphs/GraphClasses/Complete.java similarity index 75% rename from src/Complete.java rename to src/Graphs/GraphClasses/Complete.java index 15b22f37c51d119a21e746c4e7ef0c6a90f73485..1b699843a7ad2163a0c5e3e429662f80c2b2b0bc 100644 --- a/src/Complete.java +++ b/src/Graphs/GraphClasses/Complete.java @@ -1,7 +1,9 @@ +package Graphs.GraphClasses; +import Graphs.* ; public class Complete { - Graph graph; + public Graph graph; public Complete(int order) { this.graph = new Graph(order); diff --git a/src/ErdosRenyi.java b/src/Graphs/GraphClasses/ErdosRenyi.java similarity index 87% rename from src/ErdosRenyi.java rename to src/Graphs/GraphClasses/ErdosRenyi.java index 35991ae60fcf688ebf34e46621a28025c7c44dce..bf2199ed7492ee998825d487027a117c8df66ab4 100644 --- a/src/ErdosRenyi.java +++ b/src/Graphs/GraphClasses/ErdosRenyi.java @@ -1,3 +1,7 @@ +package Graphs.GraphClasses; +import Graphs.* ; +import RandomTreeAlgos.BreadthFirstSearch; + import java.util.ArrayList; import java.util.Random; @@ -5,7 +9,7 @@ import java.util.Random; public class ErdosRenyi { private final static Random gen = new Random(); - Graph graph; + public Graph graph; private int order; private double edgeProbability; diff --git a/src/Grid.java b/src/Graphs/GraphClasses/Grid.java similarity index 96% rename from src/Grid.java rename to src/Graphs/GraphClasses/Grid.java index db4e1d5974e7c1f1086e9dbfce34571abd2ddc5e..9ca60c2f23d31816023fd36613f1cd4da26d13c6 100644 --- a/src/Grid.java +++ b/src/Graphs/GraphClasses/Grid.java @@ -1,3 +1,6 @@ +package Graphs.GraphClasses; +import Graphs.*; + import java.util.BitSet; @@ -7,7 +10,7 @@ public class Grid { int height; int maxVertex; - Graph graph; + public Graph graph; public int abscissaOfVertex(int vertex) { return vertex % width; diff --git a/src/Labyrinth.java b/src/Graphs/GraphClasses/Labyrinth.java similarity index 99% rename from src/Labyrinth.java rename to src/Graphs/GraphClasses/Labyrinth.java index dd31a36eee9ddeacda9584eb3c297e697ef00b5f..0e8532dbeeef3f4b40ac09b4950f888d94f746a3 100644 --- a/src/Labyrinth.java +++ b/src/Graphs/GraphClasses/Labyrinth.java @@ -1,3 +1,7 @@ +package Graphs.GraphClasses; +import Graphs.*; + + import java.awt.Color; import java.awt.Dimension; import java.awt.GradientPaint; diff --git a/src/Lollipop.java b/src/Graphs/GraphClasses/Lollipop.java similarity index 90% rename from src/Lollipop.java rename to src/Graphs/GraphClasses/Lollipop.java index ea416a96c79e5896e6ef3c1896473afc0dd297bb..bdf29718bcfe5cb10a11fb4b233192d89682fe34 100644 --- a/src/Lollipop.java +++ b/src/Graphs/GraphClasses/Lollipop.java @@ -1,10 +1,13 @@ +package Graphs.GraphClasses; +import Graphs.*; + import java.util.ArrayList; import java.util.Collections; public class Lollipop { - Graph graph; + public Graph graph; public Lollipop(int order) { graph = new Graph(order); diff --git a/src/RootedTree.java b/src/Graphs/RootedTree.java similarity index 99% rename from src/RootedTree.java rename to src/Graphs/RootedTree.java index 4e697184da8593584bc0e395b6cf53b973c06d73..699eb01140de66522bd6d7f6af99bdecfa306ecd 100644 --- a/src/RootedTree.java +++ b/src/Graphs/RootedTree.java @@ -1,3 +1,7 @@ +package Graphs; + +import RandomTreeAlgos.BreadthFirstSearch; + import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; diff --git a/src/Main.java b/src/Main.java index 5eeb465afbf1f520b2b74fcbd4ae40ec3595148b..902b09b29db51822062ccc8ad3df5e5469c865f1 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,125 +1,147 @@ -import java.awt.image.BufferedImage; +import Graphs.*; +import Graphs.GraphClasses.*; +import RandomTreeAlgos.BreadthFirstSearch; + import java.io.IOException; import java.util.ArrayList; import java.util.Random; import javax.swing.JFrame; -import javax.swing.SwingUtilities; - - -public class MainStub { - - @SuppressWarnings("unused") - private final static Random gen = new Random(); - - public static ArrayList<Edge> genTree(Graph graph) { - ArrayList<Edge> randomTree; - - // TOOO : modifier l'algorithme utiliser ici. - - // Non-random BFS - ArrayList<Arc> randomArcTree = - BreadthFirstSearch.generateTree(graph,0); - randomTree = new ArrayList<>(); - for (Arc a : randomArcTree) randomTree.add(a.support); - - - - return randomTree; - } - - - public static void main(String argv[]) throws InterruptedException { - - Grid grid = null; - grid = new Grid(1920/11,1080/11); - Graph graph = grid.graph; - + + +public class Main { + + @SuppressWarnings("unused") + private final static Random gen = new Random(); + + static Grid grid = null; + + + public static void main(String argv[]) throws InterruptedException { + + Graph graph = chooseFromGraphFamily(); + ArrayList<Edge> randomTree = null; + + int noOfSamples = 10; + Stats stats = new Stats(noOfSamples); + for (int i = 0; i < noOfSamples; i++) { + randomTree = genTree(graph); + stats.update(randomTree); + } + stats.print(); + + if (grid != null) showGrid(grid, randomTree); + } + + private static Graph chooseFromGraphFamily() { + // Parametriser ici cette fonction afon de pouvoir choisir + // quelle classe de graohe utiliser + + grid = new Grid(1920 / 11, 1080 / 11); + Graph graph = grid.graph; // Graph graph = new Complete(400).graph; - // Graph graph = new ErdosRenyi(1_000, 100).graph; - // Graph graph = new Lollipop(1_000).graph; - - int nbrOfSamples = 10; - int diameterSum = 0; - double eccentricitySum = 0; - long wienerSum = 0; - int degreesSum[] = {0, 0, 0, 0, 0}; - int degrees[]; - - ArrayList<Edge> randomTree = null; - RootedTree rooted = null; - - long startingTime = System.nanoTime(); - for (int i = 0; i < nbrOfSamples; i++) { - randomTree= genTree(graph); - - rooted = new RootedTree(randomTree,0); + return grid.graph; + } + + public static ArrayList<Edge> genTree(Graph graph) { + ArrayList<Edge> randomTree; + + // TOOO : modifier l'algorithme utilisé ici + // ou bien parametriser à l'aide de la ligne de commande + + // Non-random BFS + ArrayList<Arc> randomArcTree = + BreadthFirstSearch.generateTree(graph, 0); + randomTree = new ArrayList<>(); + for (Arc a : randomArcTree) randomTree.add(a.support); + return randomTree; + } + + + private static class Stats { + public int nbrOfSamples = 10; + private int diameterSum = 0; + private double eccentricitySum = 0; + private long wienerSum = 0; + private int degreesSum[] = {0, 0, 0, 0, 0}; + private int degrees[]; + long startingTime = 0; + + public Stats(int noOfSamples) { + int nbrOfSamples = noOfSamples; + long startingTime = System.nanoTime(); + } + + public void print() { + long delay = System.nanoTime() - startingTime; + + System.out.println("On " + nbrOfSamples + " samples:"); + System.out.println("Average eccentricity: " + + (eccentricitySum / nbrOfSamples)); + System.out.println("Average wiener index: " + + (wienerSum / nbrOfSamples)); + System.out.println("Average diameter: " + + (diameterSum / nbrOfSamples)); + System.out.println("Average number of leaves: " + + (degreesSum[1] / nbrOfSamples)); + System.out.println("Average number of degree 2 vertices: " + + (degreesSum[2] / nbrOfSamples)); + System.out.println("Average computation time: " + + delay / (nbrOfSamples * 1_000_000) + "ms"); + + } + + public void update(ArrayList<Edge> randomTree) { + RootedTree rooted = new RootedTree(randomTree, 0); // rooted.printStats(); - diameterSum = diameterSum + rooted.getDiameter(); - eccentricitySum = eccentricitySum + rooted.getAverageEccentricity(); - wienerSum = wienerSum + rooted.getWienerIndex(); - - degrees = rooted.getDegreeDistribution(4); - for (int j = 1; j < 5; j++) { - degreesSum[j] = degreesSum[j] + degrees[j]; - } - } - long delay = System.nanoTime() - startingTime; - - System.out.println("On " + nbrOfSamples + " samples:"); - System.out.println("Average eccentricity: " - + (eccentricitySum / nbrOfSamples)); - System.out.println("Average wiener index: " - + (wienerSum / nbrOfSamples)); - System.out.println("Average diameter: " - + (diameterSum / nbrOfSamples)); - System.out.println("Average number of leaves: " - + (degreesSum[1] / nbrOfSamples)); - System.out.println("Average number of degree 2 vertices: " - + (degreesSum[2] / nbrOfSamples)); - System.out.println("Average computation time: " - + delay / (nbrOfSamples * 1_000_000) + "ms"); - - - if (grid != null) showGrid(grid,rooted,randomTree); - } - - private static void showGrid( - Grid grid, - RootedTree rooted, - ArrayList<Edge> randomTree - ) throws InterruptedException { - JFrame window = new JFrame("solution"); - final Labyrinth laby = new Labyrinth(grid, rooted); - - laby.setStyleBalanced(); + diameterSum = diameterSum + rooted.getDiameter(); + eccentricitySum = eccentricitySum + rooted.getAverageEccentricity(); + wienerSum = wienerSum + rooted.getWienerIndex(); + + degrees = rooted.getDegreeDistribution(4); + for (int j = 1; j < 5; j++) { + degreesSum[j] = degreesSum[j] + degrees[j]; + } + } + + } + + private static void showGrid( + Grid grid, + ArrayList<Edge> randomTree + ) throws InterruptedException { + RootedTree rooted = new RootedTree(randomTree, 0); + + JFrame window = new JFrame("solution"); + final Labyrinth laby = new Labyrinth(grid, rooted); + + laby.setStyleBalanced(); // laby.setShapeBigNodes(); // laby.setShapeSmallAndFull(); - laby.setShapeSmoothSmallNodes(); - - window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - window.getContentPane().add(laby); - window.pack(); - window.setLocationRelativeTo(null); - - - for (final Edge e : randomTree) { - laby.addEdge(e); - } - laby.drawLabyrinth(); - - window.setVisible(true); - - // Pour générer un fichier image. -// try { -// laby.saveImage("resources/random.png"); -// } catch (IOException e1) { -// e1.printStackTrace(); -// } - - } - - + laby.setShapeSmoothSmallNodes(); + + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.getContentPane().add(laby); + window.pack(); + window.setLocationRelativeTo(null); + + + for (final Edge e : randomTree) { + laby.addEdge(e); + } + laby.drawLabyrinth(); + + window.setVisible(true); + + // Pour générer un fichier image. + try { + laby.saveImage("resources/random.png"); + } catch (IOException e1) { + e1.printStackTrace(); + } + + } + } diff --git a/src/Parcours.java b/src/Parcours.java deleted file mode 100644 index a6db088ea3b38019b8b63e28af09640ddcba6960..0000000000000000000000000000000000000000 --- a/src/Parcours.java +++ /dev/null @@ -1,65 +0,0 @@ -import java.util.ArrayList; -import java.util.BitSet; -import java.util.LinkedList; -import java.util.Stack; - - -public class Parcours { - - Graph graph; - Stack<Arc> frontier; - BitSet reached; - ArrayList<Arc> predecessor; - - private void etendsFrontiere(int sommet) { - for (Arc a : graph.outNeighbours(sommet)) - frontier.add(a); - } - - - private void explore(Arc a) { - if (reached.get(a.getDest())) return; - reached.set(a.getDest()); - etendsFrontiere(a.getDest()); - predecessor.set(a.getDest(), a); - } - - private void parcours(int source) { - reached.set(source); - etendsFrontiere(source); - while (!frontier.isEmpty()) - explore(frontier.pop()); - - } - - private Parcours(Graph graph) { - this.graph = graph; - this.frontier = new Stack<>(); - this.reached = new BitSet(graph.order); - this.predecessor = new ArrayList<>(graph.order); - for (int i = 0; i < graph.order; i++) { - predecessor.add(null); - } - } - - - public static ArrayList<Arc> algo(Graph graph, int source) { - Parcours p = new Parcours(graph); - p.parcours(source); - return p.predecessor; - } - - - - - - - - - - - - - - -} diff --git a/src/BreadthFirstSearch.java b/src/RandomTreeAlgos/BreadthFirstSearch.java similarity index 89% rename from src/BreadthFirstSearch.java rename to src/RandomTreeAlgos/BreadthFirstSearch.java index f370f25f79b648930c7e383c6f29ab3235e15b86..bdfbb41af0a59ababa405ddf3d55c2c6adda98a9 100644 --- a/src/BreadthFirstSearch.java +++ b/src/RandomTreeAlgos/BreadthFirstSearch.java @@ -1,7 +1,9 @@ -import java.util.ArrayList; -import java.util.BitSet; -import java.util.LinkedList; -import java.util.Queue; +package RandomTreeAlgos; + +import Graphs.Arc; +import Graphs.Graph; + +import java.util.*; public class BreadthFirstSearch { @@ -42,5 +44,5 @@ public class BreadthFirstSearch { algo.bfs(root); return algo.tree; } - + } diff --git a/tp3-git.iml b/tp3-git.iml new file mode 100644 index 0000000000000000000000000000000000000000..c90834f2d607afe55e6104d8aa2cdfffb713f688 --- /dev/null +++ b/tp3-git.iml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file