Examples of WeightedGraph


Examples of bgu.bio.adt.graphs.WeightedGraph

  }

  private static void testShortestPaths() {
    int[][] neighbors = { { 1, 5 }, { 2 }, { 3, 5 }, {}, { 3 }, { 4, 1 } };
    double[][] weights = { { 4, 2 }, { 3 }, { 0, 0 }, {}, { 3 }, { 2, 1 } };
    WeightedGraph graph = new WeightedGraph(neighbors, weights);
    ShortestPaths sssp = new ShortestPaths();
    double[] delta = sssp.computeShortestPaths(graph, 0);
  }
View Full Code Here

Examples of bgu.bio.adt.graphs.WeightedGraph

  }

  private static void testShortestPaths() {
    int[][] neighbors = { { 1, 5 }, { 2 }, { 3, 5 }, {}, { 3 }, { 4, 1 } };
    double[][] weights = { { 4, 2 }, { 3 }, { 0, 0 }, {}, { 3 }, { 2, 1 } };
    WeightedGraph graph = new WeightedGraph(neighbors, weights);
    ShortestPaths sssp = new ShortestPaths();
    double[] delta = sssp.computeShortestPaths(graph, 0);
  }
View Full Code Here

Examples of de.timefinder.algo.graph.WeightedGraph

        float floatMax = AssignmentHelper.getFloatMax(Math.max(costMatrix.length, costMatrix[0].length));
        matching[0].setFloatMax(floatMax);
        matching[1].setFloatMax(floatMax);

        WeightedGraph graph = new WeightedGraph(NO_X + NO_Y);
        int ALL_NODES = NO_X + NO_Y;
        for (int x = 0; x < NO_X; x++) {
            int tmpY = 0;
            for (int y = NO_X; y < ALL_NODES; y++, tmpY++) {
                if (costMatrix[tmpY][x] < floatMax) {
                    graph.addEdge(x, y, costMatrix[tmpY][x]);
                } else {
                    // we would not need this line, if we would have a better graph.getOneNodeWithAnEdge()
                    // see within the while(true) loop
                    graph.addEdge(x, y, floatMax);
                }
            }
        }

        // x is somewhat missleading, because the x and y nodes swap
        // in every iteration (in the while(true) loop)
        int x = graph.getOneNodeWithAnEdge();
        int saveFirstNode = x;
        Map<Integer, Float> saveNeighbors =
                new FastMap<Integer, Float>(graph.getNeighbors(x));
        int yForExtremalWeight = -1;
        while (graph.getNoOfEdges() > 0) {
            while (true) {
                if (graph.getNeighbors(x).size() == 0) {
                    // EITHER return only x node if they are required (or y) via:
                    //x = graph.getOneNodeWithAnEdge();
                    //if (x < 0) { break; }
                    // OR assume a complete graph and simply break (no while(graph.getNoOfEdges() > 0) would be required)
                    break;
                }

                float minWeight = floatMax + 1;
                yForExtremalWeight = -1;
                for (Entry<Integer, Float> entry : graph.getNeighbors(x).entrySet()) {
                    if (entry.getValue() < minWeight) {
                        yForExtremalWeight = entry.getKey();
                        minWeight = entry.getValue();
                    }
                }
                assert yForExtremalWeight != -1;

                // even add it if float is floatMax, because otherwise we will
                // will have a wrong totalSum
                matching[i].addEdge(x, yForExtremalWeight, minWeight);

                i = 1 - i;
                boolean ret = graph.removeNodeAndNeighbors(x);
                assert ret;
                x = yForExtremalWeight;
            }
        }
View Full Code Here

Examples of de.timefinder.algo.graph.WeightedGraph

     */
    @Test
    public void testAddEdge() {
        System.out.println("addEdge");

        WeightedGraph graph = new WeightedGraph(10);
        graph.addEdge(3, 4, 7f);
        graph.addEdge(3, 4, 8f);
        graph.addEdge(2, 4, 9f);

        assertEquals(2, graph.getNoOfEdges());
        assertTrue(graph.getNeighbors(4).containsValue(8f));

        boolean ret = graph.removeEdge(3, 4);
        assertTrue(ret);
        assertEquals(1, graph.getNoOfEdges());

        ret = graph.removeEdge(3, 4);
        assertFalse(ret);
        assertEquals(1, graph.getNoOfEdges());
    }
View Full Code Here

Examples of de.timefinder.algo.graph.WeightedGraph

     */
    @Test
    public void testGetNeighbors() {
        System.out.println("getNeighbors");

        WeightedGraph graph = new WeightedGraph(10);
        graph.addEdge(3, 4, 7f);
        graph.addEdge(3, 4, 7f);
        graph.addEdge(2, 4, 7f);

        assertEquals(1, graph.getNeighbors(2).size());
        assertEquals(2, graph.getNeighbors(4).size());
    }
View Full Code Here

Examples of de.timefinder.algo.graph.WeightedGraph

     * Test of getOneNodeWithAnEdge method, of class WeightedGraph.
     */
    @Test
    public void testGetOneNodeWithAnEdge() {
        System.out.println("getOneNodeWithAnEdge");
        WeightedGraph graph = new WeightedGraph(10);
        graph.addEdge(3, 4, 7f);
        graph.addEdge(3, 4, 7f);
        graph.addEdge(2, 4, 7f);

        assertTrue(graph.getOneNodeWithAnEdge() != -1);

        graph.removeEdge(3, 4);
        assertTrue(graph.getOneNodeWithAnEdge() != -1);

        graph.removeEdge(2, 4);
        assertTrue(graph.getOneNodeWithAnEdge() == -1);
    }
View Full Code Here

Examples of de.timefinder.algo.graph.WeightedGraph

     * Test of removeNodeAndNeighbors method, of class WeightedGraph.
     */
    @Test
    public void testRemoveNodeAndNeighbors() {
        System.out.println("removeNodeAndNeighbors");
        WeightedGraph graph = new WeightedGraph(10);
        graph.addEdge(3, 4, 7f);
        graph.addEdge(1, 5, 7f);
        graph.addEdge(2, 4, 7f);

        assertTrue(graph.removeNodeAndNeighbors(4));

        assertEquals(graph.getNoOfEdges(), 1);
        assertTrue(graph.getOneNodeWithAnEdge() != -1);

        assertEquals(graph.getNeighbors(4).keySet().size(), 0);
        assertEquals(graph.getNeighbors(1).keySet().iterator().next(), 5d, 0.001);

        assertTrue(graph.removeNodeAndNeighbors(5));

        assertTrue(graph.getOneNodeWithAnEdge() == -1);
    }
View Full Code Here

Examples of edu.WeightedGraph

        // Lese alle Wege/Städte aus der xml-Datei ein
        WayList = handler.getMapWayList();
        NodeList = handler.getMapNodeList();

        // Erstelle einen Graph G
        G = new WeightedGraph(NodeList.size());

        // Befülle den Graph mit Knoten
        for (int i = 0; i < G.getNumVertices(); i++) {
            G.setStadt(i, NodeList.get(i));
            landKarte2.testNode.add(new Ellipse2D.Float(NodeList.get(i).getX()-10, NodeList.get(i).getY()-10, 20, 20));
View Full Code Here

Examples of edu.WeightedGraph

        // Lese alle Wege/Städte aus der xml-Datei ein
        WayList = handler.getMapWayList();
        NodeList = handler.getMapNodeList();

        // Erstelle einen Graph G
        G = new WeightedGraph(NodeList.size());

        // Befülle den Graph mit Knoten
        for (int i = 0; i < G.getNumVertices(); i++) {
            G.setStadt(i, NodeList.get(i));
        }
View Full Code Here

Examples of navi.WeightedGraph

        if (G != null) {
            G = null;
        }

        // System.out.println("1 okey");
        G = new WeightedGraph(MapNode.size());
        // System.out.println("2 okey");

        for (int index = 0; index < MapNode.size(); index++) {
            G.addVertex(index, MapNode.get(index));
        }
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.