示例#1
0
  @Override
  public Graph transform(Graph g) {
    System.err.println("This is not working completely yet, so don't expect good results!");

    initIDSpace(g);

    /*
     * Phase 1
     */
    Node currentNode = null;
    List<Node> nodeList = Arrays.asList(g.getNodes());
    List<Edge> removalList = new ArrayList<Edge>();
    Collections.sort(nodeList, new NodeDegreeComparator());
    for (int counter = 1; counter < (nodeList.size() - 3); counter++) {
      Boolean selectedANodeForThisIteration = false;
      if (currentNode != null) {
        // try to get a wave front / wave center node
      }
      if (!selectedANodeForThisIteration) {
        // We got no node yet - choose one with lowest degree
        currentNode = nodeList.get(0);
      }
      List<Edge> establishedEdges = getPairEdges(currentNode);
    }

    for (Node n : nodeList) System.out.println(n + " has degree " + n.getDegree());

    //		countAllCrossings(g);
    writeIDSpace(g);
    return g;
  }
示例#2
0
 private List<Edge> getPairEdges(Node n) {
   List<Edge> result = new ArrayList<Edge>();
   int[] incomingEdges = n.getIncomingEdges();
   for (int eDst : incomingEdges) {
     if (isPairEdge(n.getIndex(), eDst)) result.add(new Edge(n.getIndex(), eDst));
   }
   return result;
 }
示例#3
0
 /**
  * returns the list of neighbors as candidates
  *
  * @param g Graph
  * @param n Current node
  * @return List of candidates
  */
 @Override
 public List<Node> resolveCandidates(Graph g, Node n) {
   int[] nids = n.getOutgoingEdges();
   ArrayList<Node> nn = new ArrayList<Node>();
   for (int i : nids) {
     nn.add(g.getNode(i));
   }
   return nn;
 }
  /*
   * (non-Javadoc)
   *
   * @see gtna.io.graphReader.GraphReader#read(java.lang.String)
   */
  @Override
  public Graph read(String filename) {
    String sep1 = Config.get("SNAP_SEPARATOR_1");
    String ffd = Config.get("FILESYSTEM_FOLDER_DELIMITER");
    SNAPFileReader fr = new SNAPFileReader(filename);
    try {
      String line = null;
      String name = filename.substring(filename.lastIndexOf(ffd) + 1);

      Graph graph = new Graph(name);

      Map<Integer, Integer> idMapping = new HashMap<Integer, Integer>();
      int nodecounter = 0;

      LinkedList<String> edges = new LinkedList<String>();

      graphtype type = null;

      line = fr.readLine();
      type = (line.contains("Directed graph")) ? graphtype.DIRECTED : graphtype.UNDIRECTED;

      while (!line.contains("FromNodeId") && !line.contains("ToNodeId")) {
        line = fr.readLine();
      }
      nodecounter = parseEdges(sep1, fr, idMapping, nodecounter, edges, type);

      Node[] nodes = Node.init(idMapping.size(), graph);
      Edges e = new Edges(nodes, edges.size());
      ListIterator<String> edgeIterator = edges.listIterator();
      while (edgeIterator.hasNext()) {
        String[] pair = edgeIterator.next().split("-");
        e.add(Integer.parseInt(pair[0]), Integer.parseInt(pair[1]));
      }

      e.fill();
      graph.setNodes(nodes);
      return graph;
    } catch (Exception e) {
      return null;
    } finally {
      fr.close();
    }
  }
示例#5
0
  @Override
  public Graph read(String filename) {
    String delimiter = Config.get("GRAPH_WRITER_DELIMITER");
    Filereader fr = new Filereader(filename);

    String name = fr.readLine();
    int N = Integer.parseInt(fr.readLine());
    int E = Integer.parseInt(fr.readLine());

    Graph graph = new Graph(name);
    Node[] nodes = Node.init(N, graph);
    Edges edges = new Edges(nodes, E);

    String line = null;
    while ((line = fr.readLine()) != null) {
      String[] temp = line.split(delimiter);
      edges.add(Integer.parseInt(temp[0]), Integer.parseInt(temp[1]));
    }
    edges.fill();
    graph.setNodes(nodes);
    fr.close();
    return graph;
  }
示例#6
0
  public static Graph read(String filename) throws Exception {
    Timer timer = new Timer();

    RandomAccessFile file = new RandomAccessFile(new File(filename), "r");

    // seek to names
    while (!file.readLine().startsWith("names/")) {}

    // read names
    Vector<WOTNode> wotNodes = new Vector<WOTNode>();
    int index = 0;
    String line;
    while (!(line = file.readLine()).startsWith("keys/")) {
      if (!line.equals("")) {
        WOTNode node = new WOTNode(index, line);
        wotNodes.add(node);
        index += 1;
      }
    }

    // read keys
    for (index = 0; index < wotNodes.size(); index++) {
      byte[] key = new byte[4];
      file.read(key);
      WOTNode node = wotNodes.get(index);
      node.key = Util.toInt(key);
    }

    // skip the "signatures/" line
    String signaturesLine = file.readLine();
    if (!signaturesLine.startsWith("signatures/")) {
      // FIXME an IllegalArgumentException isn't really semantically
      // correct
      throw new IllegalArgumentException("A line starting with \"signatures/\" was expected.");
    }

    // read signatures
    for (index = 0; index < wotNodes.size(); index++) {
      WOTNode node = wotNodes.get(index);

      // read how many keys are signed by this key
      byte[] buffer = new byte[4];
      file.read(buffer);
      int signatureCount = Util.toInt(buffer);

      // inspect all signatures
      for (int signatureIndex = 0; signatureIndex < signatureCount; signatureIndex++) {
        byte[] signatureBuffer = new byte[4];
        file.read(signatureBuffer);

        int signature = Util.toInt(signatureBuffer);

        // get the signature type
        // TODO do something with the signature type
        // int signatureType = signature & SIGNATURE_TYPE_MASK;

        // get the target key
        int targetIndex = signature & SIGNATURE_INDEX_MASK;
        if (targetIndex >= wotNodes.size()) {
          // FIXME an IllegalArgumentException isn't really
          // semantically correct
          throw new IllegalArgumentException("A target index that matches a node was expected.");
        }

        // retrieve the target node
        WOTNode target = wotNodes.get(targetIndex);
        node.signatures.add(target);
      }
    }
    // skip the "debug/" line
    String debugLine = file.readLine();
    if (!debugLine.startsWith("debug/")) {
      // FIXME an IllegalArgumentException isn't really semantically
      // correct
      throw new IllegalArgumentException("A line starting with \"debug/was expected.");
    }

    file.close();
    timer.end();

    // prepare return graph
    Graph graph = new Graph("WOT - read from " + filename);
    Node[] nodes = Node.init(wotNodes.size(), graph);
    Edges edges = new Edges(nodes, nodes.length);
    for (WOTNode source : wotNodes) {
      for (WOTNode target : source.signatures) {
        edges.add(source.index, target.index);
      }
    }
    edges.fill();
    graph.setNodes(nodes);
    return graph;
  }
示例#7
0
 @Override
 public int compare(Node n1, Node n2) {
   double n1ID = partitions[n1.getIndex()].getStart().getPosition();
   double n2ID = partitions[n2.getIndex()].getStart().getPosition();
   return Double.compare(n1ID, n2ID);
 }
示例#8
0
 @Override
 public int compare(Node n1, Node n2) {
   if (n1.getDegree() == n2.getDegree()) return 0;
   else if (n1.getDegree() > n2.getDegree()) return 1;
   else return -1;
 }