@Test
  public void record_stats_information_from_simple_vertices() {
    VertexStatsRecorder recorder = new VertexStatsRecorder();

    Vertex simple = VertexFactory.makeSimpleVertex();
    Vertex simple2 = VertexFactory.makeSimpleVertex();
    Vertex simple3 = VertexFactory.makeSimpleVertex();
    Vertex simple4 = VertexFactory.makeSimpleVertex();

    simple.addNeighbour(simple2).addNeighbour(simple3).addNeighbour(simple4);

    simple2.addNeighbour(simple3).addNeighbour(simple4);

    simple3.addNeighbour(simple4);

    simple.publishYourStatsOn(recorder);
    simple2.publishYourStatsOn(recorder);
    simple3.publishYourStatsOn(recorder);
    simple4.publishYourStatsOn(recorder);

    Map<PlainTextStatsComponents, Integer> expected =
        new HashMap<PlainTextStatsComponents, Integer>();

    expected.put(PlainTextStatsComponents.NOfVertices, 4);
    expected.put(PlainTextStatsComponents.NOfEdges, 6);
    expected.put(PlainTextStatsComponents.NOfSources, 1);
    expected.put(PlainTextStatsComponents.NOfSinks, 1);
    expected.put(PlainTextStatsComponents.NOfWhites, 2);

    Assert.assertTrue(recorder.isSimpleVerticesVotesEquals(expected));
    Assert.assertFalse(
        recorder.isSimpleVerticesVotesEquals(new HashMap<PlainTextStatsComponents, Integer>()));
  }
コード例 #2
0
  private static InternalRelation readRelation(
      final InternalVertex vertex,
      final RelationCache relation,
      final Entry data,
      final TypeInspector types,
      final VertexFactory vertexFac) {
    InternalRelationType type =
        TypeUtil.getBaseType((InternalRelationType) types.getExistingRelationType(relation.typeId));

    if (type.isPropertyKey()) {
      assert relation.direction == Direction.OUT;
      return new CacheProperty(
          relation.relationId, (PropertyKey) type, vertex, relation.getValue(), data);
    }

    if (type.isEdgeLabel()) {
      InternalVertex otherVertex = vertexFac.getInternalVertex(relation.getOtherVertexId());
      switch (relation.direction) {
        case IN:
          return new CacheEdge(relation.relationId, (EdgeLabel) type, otherVertex, vertex, data);

        case OUT:
          return new CacheEdge(relation.relationId, (EdgeLabel) type, vertex, otherVertex, data);

        default:
          throw new AssertionError();
      }
    }

    throw new AssertionError();
  }
  @Test
  public void check_consistency_for_simple_vertices_votes() {
    VertexStatsRecorder recorder = new VertexStatsRecorder();

    Vertex simple = VertexFactory.makeSimpleVertex();
    Vertex simple2 = VertexFactory.makeSimpleVertex();
    Vertex simple3 = VertexFactory.makeSimpleVertex();
    Vertex simple4 = VertexFactory.makeSimpleVertex();

    simple.addNeighbour(simple2).addNeighbour(simple3).addNeighbour(simple4);

    simple2.addNeighbour(simple3).addNeighbour(simple4);

    simple3.addNeighbour(simple4);

    simple.publishYourStatsOn(recorder);
    simple2.publishYourStatsOn(recorder);
    simple3.publishYourStatsOn(recorder);
    simple4.publishYourStatsOn(recorder);

    Assert.assertTrue(recorder.isSimpleVerticesVoteAccepterConsistent());
  }
  @Test
  public void record_average_with_two_model_stats_information_from_simple_vertices_should_change() {
    VertexStatsRecorder recorder = new VertexStatsRecorder();

    Vertex simple = VertexFactory.makeSimpleVertex();
    Vertex simple2 = VertexFactory.makeSimpleVertex();
    Vertex simple3 = VertexFactory.makeSimpleVertex();
    Vertex simple4 = VertexFactory.makeSimpleVertex();

    simple.addNeighbour(simple2).addNeighbour(simple3).addNeighbour(simple4);

    simple2.addNeighbour(simple3).addNeighbour(simple4);

    simple3.addNeighbour(simple4);

    simple.publishYourStatsOn(recorder);
    simple2.publishYourStatsOn(recorder);
    simple3.publishYourStatsOn(recorder);
    simple4.publishYourStatsOn(recorder);

    Map<PlainTextStatsComponents, Integer> expected =
        new HashMap<PlainTextStatsComponents, Integer>();

    int counter = 2;

    expected.put(
        PlainTextStatsComponents.NOfVertices, VertexVoteAccepter.DivideAndRound(4, counter));
    expected.put(PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(6, counter));
    expected.put(
        PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(1, counter));
    expected.put(PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(1, counter));
    expected.put(PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(2, counter));

    Assert.assertTrue(recorder.average(counter).isSimpleVerticesVotesEquals(expected));
    Assert.assertFalse(
        recorder
            .average(counter)
            .isSimpleVerticesVotesEquals(new HashMap<PlainTextStatsComponents, Integer>()));
  }
コード例 #5
0
  /** {@inheritDoc} */
  public void generateGraph(
      Graph<V, E> target, VertexFactory<V> vertexFactory, Map<String, V> resultMap) {
    if (size < 1) {
      return;
    }

    // Add all the vertices to the set
    for (int i = 0; i < size; i++) {
      V newVertex = vertexFactory.createVertex();
      target.addVertex(newVertex);
    }

    /*
     * We want two iterators over the vertex set, one fast and one slow.
     * The slow one will move through the set once. For each vertex,
     * the fast iterator moves through the set, adding an edge to all
     * vertices we haven't connected to yet.
     *
     * If we have an undirected graph, the second addEdge call will return
     * nothing; it will not add a second edge.
     */
    Iterator<V> slowI = target.vertexSet().iterator();
    Iterator<V> fastI;

    while (slowI.hasNext()) { // While there are more vertices in the set

      V latestVertex = slowI.next();
      fastI = target.vertexSet().iterator();

      // Jump to the first vertex *past* latestVertex
      while (fastI.next() != latestVertex) {;
      }

      // And, add edges to all remaining vertices
      V temp;
      while (fastI.hasNext()) {
        temp = fastI.next();
        target.addEdge(latestVertex, temp);
        target.addEdge(temp, latestVertex);
      }
    }
  }
コード例 #6
0
  /** {@inheritDoc} */
  public void generateGraph(
      Graph<V, E> target, final VertexFactory<V> vertexFactory, Map<String, V> resultMap) {
    if (size < 1) {
      return;
    }

    // A little trickery to intercept the rim generation.  This is
    // necessary since target may be initially non-empty, meaning we can't
    // rely on its vertex set after the rim is generated.
    final Collection<V> rim = new ArrayList<V>();
    VertexFactory<V> rimVertexFactory =
        new VertexFactory<V>() {
          public V createVertex() {
            V vertex = vertexFactory.createVertex();
            rim.add(vertex);

            return vertex;
          }
        };

    RingGraphGenerator<V, E> ringGenerator = new RingGraphGenerator<V, E>(size - 1);
    ringGenerator.generateGraph(target, rimVertexFactory, resultMap);

    V hubVertex = vertexFactory.createVertex();
    target.addVertex(hubVertex);

    if (resultMap != null) {
      resultMap.put(HUB_VERTEX, hubVertex);
    }

    for (V rimVertex : rim) {
      if (inwardSpokes) {
        target.addEdge(rimVertex, hubVertex);
      } else {
        target.addEdge(hubVertex, rimVertex);
      }
    }
  }
コード例 #7
0
  /** {@inheritDoc} */
  public void generateGraph(
      Graph<V, E> target, VertexFactory<V> vertexFactory, Map<String, V> resultMap) {
    V lastVertex = null;

    for (int i = 0; i < size; ++i) {
      V newVertex = vertexFactory.createVertex();
      target.addVertex(newVertex);

      if (lastVertex == null) {
        if (resultMap != null) {
          resultMap.put(START_VERTEX, newVertex);
        }
      } else {
        target.addEdge(lastVertex, newVertex);
      }

      lastVertex = newVertex;
    }

    if ((resultMap != null) && (lastVertex != null)) {
      resultMap.put(END_VERTEX, lastVertex);
    }
  }
  @Test
  public void check_consistency_for_connected_components_vertices_votes() {
    VertexStatsRecorder recorder = new VertexStatsRecorder();

    ConnectedComponentWrapperVertex simple = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple2 = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple3 = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple4 = VertexFactory.makeConnectedComponentWrapperVertex();

    simple.includeMember(VertexFactory.makeSimpleVertex());
    simple.includeMember(VertexFactory.makeSimpleVertex());
    simple.includeMember(VertexFactory.makeSimpleVertex());

    simple.addNeighbour(simple2);

    simple2.includeMember(VertexFactory.makeSimpleVertex());

    simple2.addNeighbour(simple3).addNeighbour(simple4);

    simple3.includeMember(VertexFactory.makeSimpleVertex());
    simple3.includeMember(VertexFactory.makeSimpleVertex());

    simple3.addNeighbour(simple4);

    simple4.includeMember(VertexFactory.makeSimpleVertex());
    simple4.includeMember(VertexFactory.makeSimpleVertex());
    simple4.includeMember(VertexFactory.makeSimpleVertex());

    simple.publishYourStatsOn(recorder);
    simple2.publishYourStatsOn(recorder);
    simple3.publishYourStatsOn(recorder);
    simple4.publishYourStatsOn(recorder);

    Assert.assertTrue(recorder.isConnectedComponentsVoteAccepterConsistent());
  }
  @Test
  public void record_stats_information_from_connected_components() {
    VertexStatsRecorder recorder = new VertexStatsRecorder();

    ConnectedComponentWrapperVertex simple = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple2 = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple3 = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple4 = VertexFactory.makeConnectedComponentWrapperVertex();

    simple.includeMember(VertexFactory.makeSimpleVertex());
    simple.includeMember(VertexFactory.makeSimpleVertex());
    simple.includeMember(VertexFactory.makeSimpleVertex());

    simple.addNeighbour(simple2);

    simple2.includeMember(VertexFactory.makeSimpleVertex());

    simple2.addNeighbour(simple3).addNeighbour(simple4);

    simple3.includeMember(VertexFactory.makeSimpleVertex());
    simple3.includeMember(VertexFactory.makeSimpleVertex());

    simple3.addNeighbour(simple4);

    simple4.includeMember(VertexFactory.makeSimpleVertex());
    simple4.includeMember(VertexFactory.makeSimpleVertex());
    simple4.includeMember(VertexFactory.makeSimpleVertex());

    simple.publishYourStatsOn(recorder);
    simple2.publishYourStatsOn(recorder);
    simple3.publishYourStatsOn(recorder);
    simple4.publishYourStatsOn(recorder);

    Map<PlainTextStatsComponents, Integer> expectedFor3members =
        new HashMap<PlainTextStatsComponents, Integer>();

    expectedFor3members.put(PlainTextStatsComponents.NOfComponents, 2);
    expectedFor3members.put(PlainTextStatsComponents.NOfSources, 1);
    expectedFor3members.put(PlainTextStatsComponents.NOfSinks, 1);
    expectedFor3members.put(PlainTextStatsComponents.NOfWhites, 0);
    expectedFor3members.put(PlainTextStatsComponents.NOfEdges, 1);

    Map<PlainTextStatsComponents, Integer> expectedFor2members =
        new HashMap<PlainTextStatsComponents, Integer>();

    expectedFor2members.put(PlainTextStatsComponents.NOfComponents, 1);
    expectedFor2members.put(PlainTextStatsComponents.NOfSources, 0);
    expectedFor2members.put(PlainTextStatsComponents.NOfSinks, 0);
    expectedFor2members.put(PlainTextStatsComponents.NOfWhites, 1);
    expectedFor2members.put(PlainTextStatsComponents.NOfEdges, 1);

    Map<PlainTextStatsComponents, Integer> expectedFor1members =
        new HashMap<PlainTextStatsComponents, Integer>();

    expectedFor1members.put(PlainTextStatsComponents.NOfComponents, 1);
    expectedFor1members.put(PlainTextStatsComponents.NOfSources, 0);
    expectedFor1members.put(PlainTextStatsComponents.NOfSinks, 0);
    expectedFor1members.put(PlainTextStatsComponents.NOfWhites, 1);
    expectedFor1members.put(PlainTextStatsComponents.NOfEdges, 2);

    Assert.assertTrue(recorder.isComponentsVotesEquals(3, expectedFor3members));
    Assert.assertTrue(recorder.isComponentsVotesEquals(2, expectedFor2members));
    Assert.assertTrue(recorder.isComponentsVotesEquals(1, expectedFor1members));
  }
  @Test
  public void record_average_with_two_model_stats_information_from_connected_components() {
    VertexStatsRecorder recorder = new VertexStatsRecorder();

    ConnectedComponentWrapperVertex simple = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple2 = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple3 = VertexFactory.makeConnectedComponentWrapperVertex();

    ConnectedComponentWrapperVertex simple4 = VertexFactory.makeConnectedComponentWrapperVertex();

    simple.includeMember(VertexFactory.makeSimpleVertex());
    simple.includeMember(VertexFactory.makeSimpleVertex());
    simple.includeMember(VertexFactory.makeSimpleVertex());

    simple.addNeighbour(simple2);

    simple2.includeMember(VertexFactory.makeSimpleVertex());

    simple2.addNeighbour(simple3).addNeighbour(simple4);

    simple3.includeMember(VertexFactory.makeSimpleVertex());
    simple3.includeMember(VertexFactory.makeSimpleVertex());

    simple3.addNeighbour(simple4);

    simple4.includeMember(VertexFactory.makeSimpleVertex());
    simple4.includeMember(VertexFactory.makeSimpleVertex());
    simple4.includeMember(VertexFactory.makeSimpleVertex());

    simple.publishYourStatsOn(recorder);
    simple2.publishYourStatsOn(recorder);
    simple3.publishYourStatsOn(recorder);
    simple4.publishYourStatsOn(recorder);

    int counter = 1;

    Map<PlainTextStatsComponents, Integer> expectedFor3members =
        new HashMap<PlainTextStatsComponents, Integer>();

    expectedFor3members.put(
        PlainTextStatsComponents.NOfComponents, VertexVoteAccepter.DivideAndRound(2, counter));
    expectedFor3members.put(
        PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(1, counter));
    expectedFor3members.put(
        PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(1, counter));
    expectedFor3members.put(
        PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(0, counter));
    expectedFor3members.put(
        PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(1, counter));

    Map<PlainTextStatsComponents, Integer> expectedFor2members =
        new HashMap<PlainTextStatsComponents, Integer>();

    expectedFor2members.put(
        PlainTextStatsComponents.NOfComponents, VertexVoteAccepter.DivideAndRound(1, counter));
    expectedFor2members.put(
        PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(0, counter));
    expectedFor2members.put(
        PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(0, counter));
    expectedFor2members.put(
        PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(1, counter));
    expectedFor2members.put(
        PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(1, counter));

    Map<PlainTextStatsComponents, Integer> expectedFor1members =
        new HashMap<PlainTextStatsComponents, Integer>();

    expectedFor1members.put(
        PlainTextStatsComponents.NOfComponents, VertexVoteAccepter.DivideAndRound(1, counter));
    expectedFor1members.put(
        PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(0, counter));
    expectedFor1members.put(
        PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(0, counter));
    expectedFor1members.put(
        PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(1, counter));
    expectedFor1members.put(
        PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(2, counter));

    Assert.assertTrue(recorder.average(counter).isComponentsVotesEquals(3, expectedFor3members));
    Assert.assertTrue(recorder.average(counter).isComponentsVotesEquals(2, expectedFor2members));
    Assert.assertTrue(recorder.average(counter).isComponentsVotesEquals(1, expectedFor1members));
  }