Examples of AdjacencyMatrixGraph


Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        vertexSet.add("sommet 2");
        vertexSet.add("sommet 3");
        vertexSet.add("sommet 4");
        vertexSet.add("sommet 5");

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph();
        graph.setVertex(vertexSet);
        try {

            // on ajoute des arêtes entre les sommets déclarés dans le graphe
            graph.addEdge("sommet 1", "sommet 2");
            graph.addEdge("sommet 1", "sommet 3");
            graph.addEdge("sommet 2", "sommet 3");
            graph.addEdge("sommet 2", "sommet 4");

            // si on arrive ici sans problème, alors le test est passé avec succès.
            assertTrue(true);
        }
        catch(VertexNotFoundException e) {
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        Set<String> vertexSet = new HashSet<String>(5);

        // on déclare un seul sommet dans le graphe.
        vertexSet.add("sommet 1");

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph();
        graph.setVertex(vertexSet);
        try {
            // on ajoute une arête avec une extremité non déclarée dans le graphe
            graph.addEdge("sommet 1", "sommet 2");

            // si on arrive ici, c'est qu'il y a eu un problème, une exception aurait du
            // être levée pour indiqué qu'il n'est pas possible de créer une arête avec un
            // sommet inconnu
            assertTrue("Un sommet trouvé dans le graphe n'aurait pas du être trouvé", false);
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        vertexSet.add("sommet 2");
        vertexSet.add("sommet 3");
        vertexSet.add("sommet 4");
        vertexSet.add("sommet 5");

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(5);
        graph.setVertex(vertexSet);
        try {
            graph.addEdge("sommet 1", "sommet 2");
            graph.addEdge("sommet 1", "sommet 3");
            graph.addEdge("sommet 2", "sommet 3");
            graph.addEdge("sommet 2", "sommet 4");

            assertTrue(true);
        }
        catch(VertexNotFoundException e) {
            assertTrue("sommet non trouvé dans le graphe", false);
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        vertexSet.add("B");
        vertexSet.add("C");
        vertexSet.add("D");
        vertexSet.add("E");

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(5);

       
        graph.setVertex(vertexSet);
        try {
            graph.addEdge("A", "B");
            graph.addEdge("A", "C");
            graph.addEdge("B", "C");
            graph.addEdge("B", "D");

            System.out.println(graph.toString());
            assertTrue(true);

            System.out.println("Vertex:");
            for( Vertex v : graph.getVertexSet()) {
                System.out.println(v.toString());
            }

            System.out.println("Edges:");
            for( Edge e : graph.getEdgeSet()) {
                System.out.println(e.toString());
            }
        }
        catch(VertexNotFoundException e) {
            assertTrue("sommet non trouvé dans le graphe", false);
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        vertexSet.add("sommet 4");
        vertexSet.add("sommet 5");

        // on créé un graphe avec une capacité de 2 et on lui ajoute plus de
        // sommet que possible. Il ne devrait pas y avoir d'erreur.
        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(2);
        graph.setVertex(vertexSet);
        try {
            graph.addEdge("sommet 1", "sommet 2");
            graph.addEdge("sommet 1", "sommet 3");
            graph.addEdge("sommet 2", "sommet 3");
            graph.addEdge("sommet 2", "sommet 4");

            assertTrue(true);
        }
        catch(VertexNotFoundException e) {
            assertTrue("sommet non trouvé dans le graphe", false);
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        }
    }

    public void testGetVertex1() {

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(5);

        graph.addVertex("A");
        graph.addVertex("B");
        graph.addVertex("C");
        graph.addVertex("D");
        graph.addVertex("E");

        try {
            graph.addEdge("A", "B");
            graph.addEdge("A", "C");
            graph.addEdge("B", "C");
            graph.addEdge("B", "D");

            Set<Vertex> vertexSet2 = graph.getVertexSet();
            for( Vertex v : vertexSet2 ) {
                String vId = v.getId();
                assertTrue("un sommet inconnu a été trouvé",(("A".equals(vId)) || ("B".equals(vId)) || ("C".equals(vId)) ||("D".equals(vId)) ||("E".equals(vId)) ));
            }
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        }
    }

    public void testGetVertex2()  {

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(2);
        Set<Vertex> set = graph.getVertexSet();
        assertTrue("Le graphe n'est pas vide alors qu'il le devrait", set.isEmpty());

    }
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        vertexSet.add("B");
        vertexSet.add("C");
        vertexSet.add("D");
        vertexSet.add("E");

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(2);
        graph.setVertex(vertexSet);
        try {
            graph.addEdge("A", "B", 2);
            graph.addEdge("A", "C", 4);
            graph.addEdge("B", "C", 6);
            graph.addEdge("B", "D", 1);

            Set<Edge> setA = graph.getEdgeSet("A");
            assertEquals(2, setA.size());
            for( Edge e : setA) {
                assertEquals(2, e.getVertex().size());
                for( Vertex v : e.getVertex()) {
                    assertTrue(v.getId().equals("A") ||
                            (v.getId().equals("B") && e.getValue() == 2 ) ||
                            (v.getId().equals("C") && e.getValue() == 4 ));
                }
            }

            Set<Edge> setB = graph.getEdgeSet("B");
            assertEquals(3, setB.size());
            for( Edge e : setB) {
                assertEquals(2, e.getVertex().size());
                for( Vertex v : e.getVertex()) {
                    assertTrue(v.getId().equals("B") ||
                            (v.getId().equals("A") && e.getValue() == 2 ) ||
                            (v.getId().equals("C") && e.getValue() == 6 ) ||
                            (v.getId().equals("D") && e.getValue() == 1 )
                            );
                }
            }

            Set<Edge> setC = graph.getEdgeSet("C");
            assertEquals(2, setC.size());
            for( Edge e : setC) {
                assertEquals(2, e.getVertex().size());
                for( Vertex v : e.getVertex()) {
                    assertTrue(v.getId().equals("C") ||
                            (v.getId().equals("B") && e.getValue() == 6 ) ||
                            (v.getId().equals("A") && e.getValue() == 4 ));
                }
            }

            Set<Edge> setD = graph.getEdgeSet("D");
            assertEquals(1, setD.size());
            for( Edge e : setD) {
                assertEquals(2, e.getVertex().size());
                for( Vertex v : e.getVertex()) {
                    assertTrue(v.getId().equals("D") ||
                            (v.getId().equals("B") && e.getValue() == 1 ));
                }
            }

            Set<Edge> setE = graph.getEdgeSet("E");
            assertTrue(setE.isEmpty());

            Set<Edge> setF = graph.getEdgeSet("F");
            assertTrue(setF.isEmpty());
        }
        catch(VertexNotFoundException e) {
            assertTrue("sommet non trouvé dans le graphe", false);
        }
View Full Code Here

Examples of org.openjgraph.model.adjacencymatrix.AdjacencyMatrixGraph

        Set<String> vertexSet = new HashSet<String>(10);
        for( int i = 0; i < 10; i++) {
            vertexSet.add(Integer.toString(i));
        }

        AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(10);
        graph.setVertex(vertexSet);

        for( int i = 0; i < 10; i++) {
            for( int j = 0; j < i; j++) {
                try {
                    graph.addEdge(Integer.toString(i), Integer.toString(i), 1);
                } catch (VertexNotFoundException ex) {
                    assertTrue("Impossible d'ajouter l'arete (" + i + "," + j +")",false);
                }
            }
        }

        graph.addVertex("11");
       
        Set<Vertex> newVertexSet = graph.getVertexSet();
        assertEquals(11, newVertexSet.size());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.