Пример #1
0
  private void mergeGraph(GraphModel merge) {

    // Add any new nodes
    for (GraphNode node : merge.getNodes()) {
      if (null == resultModel.findNode(node.getId())) {
        // TODO: Should be cloning the node.
        resultModel.addNode(node);

        // Speed up edge lookups
        Set<GraphEdge> empty = Sets.newHashSet();
        headToEdges.put(node, empty);
      }
    }

    // Add any new edges
    for (GraphEdge edge : merge.getEdges()) {
      Set<GraphEdge> forHead = headToEdges.get(edge.getHead());
      if (null == forHead) {
        continue;
      }
      if (!forHead.contains(edge)) {
        resultModel.addEdge(edge.getRelation(), edge.getHead(), edge.getTail());
        forHead.add(edge);
      }
    }
  }
Пример #2
0
  public static GraphNode[] buildComplete(GraphModel graph, int degree, Relation relation) {
    GraphNode nodes[] = new GraphNode[degree];
    GraphBuilder builder = graph.getBuilder();
    for (int nodeCnt = 0; nodeCnt < degree; nodeCnt++) {
      GraphNode node = new MethodElement("FakeSig", nameGen("complete", nodeCnt), "boolean");
      nodes[nodeCnt] = builder.newNode(node);
    }

    for (int head = 0; head < (degree - 1); head++) {
      for (int tail = head + 1; tail < degree; tail++) {
        graph.addEdge(relation, nodes[head], nodes[tail]);
      }
    }

    return nodes;
  }