Exemplo n.º 1
0
  /**
   * @param graph the graph to be ordered
   * @param orderByDegree should the vertices be ordered by their degree. This speeds up the VF2
   *     algorithm.
   * @param cacheEdges if true, the class creates a adjacency matrix and two arrays for incoming and
   *     outgoing edges for fast access.
   */
  public GraphOrdering(Graph<V, E> graph, boolean orderByDegree, boolean cacheEdges) {
    this.graph = graph;
    this.cacheEdges = cacheEdges;

    List<V> vertexSet = new ArrayList<>(graph.vertexSet());
    if (orderByDegree) {
      java.util.Collections.sort(vertexSet, new GeneralVertexDegreeComparator<>(graph));
    }

    vertexCount = vertexSet.size();
    mapVertexToOrder = new HashMap<>();
    mapOrderToVertex = new ArrayList<>(vertexCount);

    if (cacheEdges) {
      outgoingEdges = new int[vertexCount][];
      incomingEdges = new int[vertexCount][];
      adjMatrix = new Boolean[vertexCount][vertexCount];
    }

    Integer i = 0;
    for (V vertex : vertexSet) {
      mapVertexToOrder.put(vertex, i++);
      mapOrderToVertex.add(vertex);
    }
  }
Exemplo n.º 2
0
 /**
  * be careful: there's no check against an invalid vertexNumber
  *
  * @param vertexNumber the number identifying the vertex v
  * @return v
  */
 public V getVertex(int vertexNumber) {
   return mapOrderToVertex.get(vertexNumber);
 }
Exemplo n.º 3
0
  public String toString(Molecule molecule) {
    // write header
    String returnString =
        String.format(
            "%%mem=%dGB\n%%nprocshared=%d\n#p geom=connect %s/genecp empiricaldispersion=gd3bj opt\n",
            mem, nprocshared, method);
    returnString += "\ntitle\n\n0 1\n";

    // write geometry
    returnString = returnString + molecule.getGJFstring() + "\n";

    // initialize some variables
    Atom fromAtom = null;
    Atom toAtom = null;
    Integer fromAtomNumber = 0;
    Integer toAtomNumber = 0;
    Double bondOrder = 0.0;
    DefaultWeightedEdge thisEdge = null;

    // read connectivity data into parallel arrays
    ArrayList<Integer> fromAtoms = new ArrayList<Integer>();
    ArrayList<Integer> toAtoms = new ArrayList<Integer>();
    ArrayList<Double> bondOrders = new ArrayList<Double>();
    ArrayList<Boolean> visited = new ArrayList<Boolean>();
    for (DefaultWeightedEdge e : molecule.connectivity.edgeSet()) {
      fromAtom = molecule.connectivity.getEdgeSource(e);
      fromAtomNumber = molecule.contents.indexOf(fromAtom) + 1;
      toAtom = molecule.connectivity.getEdgeTarget(e);
      toAtomNumber = molecule.contents.indexOf(toAtom) + 1;
      bondOrder = molecule.connectivity.getEdgeWeight(e);

      fromAtoms.add(fromAtomNumber);
      toAtoms.add(toAtomNumber);
      bondOrders.add(bondOrder);
      visited.add(false);
    }

    // write connectivity data
    for (int i = 0; i < molecule.contents.size(); i++) {
      returnString = returnString + (i + 1) + " ";
      for (int j = 0; j < fromAtoms.size(); j++) {
        if (fromAtoms.get(j) == i + 1 && visited.get(j) == false) {
          returnString =
              returnString + toAtoms.get(j) + " " + String.format("%.1f ", bondOrders.get(j));
          visited.set(j, true);
        }
        if (toAtoms.get(j) == i + 1 && visited.get(j) == false) {
          returnString =
              returnString + fromAtoms.get(j) + " " + String.format("%.1f ", bondOrders.get(j));
          visited.set(j, true);
        }
      }
      returnString = returnString + "\n";
    }

    // write footer
    returnString += String.format("\n@%s\n\n", basis);
    return returnString;
  }