Esempio n. 1
0
  private SimpleGraph<Integer, DefaultEdge> buildGraphForTestDisconnected(int size) {
    SimpleGraph<Integer, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);

    VertexFactory<Integer> vertexFactory = new IntegerVertexFactory();

    CompleteGraphGenerator<Integer, DefaultEdge> completeGraphGenerator =
        new CompleteGraphGenerator<>(size);
    // two complete graphs
    SimpleGraph<Integer, DefaultEdge> east = new SimpleGraph<>(DefaultEdge.class);
    completeGraphGenerator.generateGraph(east, vertexFactory, null);

    SimpleGraph<Integer, DefaultEdge> west = new SimpleGraph<>(DefaultEdge.class);
    completeGraphGenerator.generateGraph(west, vertexFactory, null);

    Graphs.addGraph(graph, east);
    Graphs.addGraph(graph, west);
    // connected by single edge
    graph.addEdge(size - 1, size);

    return graph;
  }
  protected Graph<String, DefaultWeightedEdge> createWithBias(boolean negate) {
    Graph<String, DefaultWeightedEdge> g;
    double bias = 1;
    if (negate) {
      // negative-weight edges are being tested, so only a directed graph
      // makes sense
      g = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
      bias = -1;
    } else {
      // by default, use an undirected graph
      g = new SimpleWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
    }

    g.addVertex(V1);
    g.addVertex(V2);
    g.addVertex(V3);
    g.addVertex(V4);
    g.addVertex(V5);

    e12 = Graphs.addEdge(g, V1, V2, bias * 2);

    e13 = Graphs.addEdge(g, V1, V3, bias * 3);

    e24 = Graphs.addEdge(g, V2, V4, bias * 5);

    e34 = Graphs.addEdge(g, V3, V4, bias * 20);

    e45 = Graphs.addEdge(g, V4, V5, bias * 5);

    e15 = Graphs.addEdge(g, V1, V5, bias * 100);

    return g;
  }