Example #1
0
 @Override
 public void computeData(Graph g, Network n, HashMap<String, Metric> m) {
   Partition p = this.getPartition(g);
   this.largestComponent = p.getComponents()[0].length;
   this.largestComponentFraction = this.largestComponent / (double) g.getNodes().length;
   this.components = new double[p.getComponents().length];
   this.componentsFraction = new double[p.getComponents().length];
   for (int i = 0; i < p.getComponents().length; i++) {
     this.components[i] = p.getComponents()[i].length;
     this.componentsFraction[i] = this.components[i] / (double) g.getNodes().length;
   }
 }
Example #2
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;
  }
Example #3
0
  @Override
  public void read(String filename, Graph graph) {
    Filereader fr = new Filereader(filename);

    // CLASS
    fr.readLine();

    // KEY
    String key = fr.readLine();

    // # MUDULUS
    this.modulus = Double.parseDouble(fr.readLine());

    // # WRAP-AROUND
    this.wrapAround = Boolean.parseBoolean(fr.readLine());

    // # PARTITIONS
    int partitions = Integer.parseInt(fr.readLine());
    this.partitions = new RingPartition[partitions];

    this.maxDistance = this.wrapAround ? this.modulus / 2.0 : this.modulus;

    // PARTITIONS
    String line = null;
    while ((line = fr.readLine()) != null) {
      String[] temp = line.split(":");
      int index = Integer.parseInt(temp[0]);
      this.partitions[index] = new RingPartition(temp[1], this);
    }

    fr.close();

    graph.addProperty(key, this);
  }
Example #4
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;
 }
Example #5
0
  @Override
  public void computeData(Graph g, Network n, HashMap<String, Metric> m) {
    this.runtime = new Timer();
    int[] excludeFirst = this.getExcludeFirst(g.getNodes().length);
    this.isolatedComponentSizeAvg = new double[excludeFirst.length];
    this.isolatedComponentSizeMax = new double[excludeFirst.length];
    this.isolatedComponentSizeMed = new double[excludeFirst.length];
    this.isolatedComponentSizeMin = new double[excludeFirst.length];
    this.numberOfIsolatedComponents = new double[excludeFirst.length];
    this.largestComponentSize = new double[excludeFirst.length];
    this.largestComponentSizeFraction = new double[excludeFirst.length];
    this.criticalPoint = 1.0;
    Random rand = new Random();
    Node[] sorted = this.sorter.sort(g, rand);
    for (int i = 0; i < excludeFirst.length; i++) {
      boolean[] exclude = this.getExclude(sorted, excludeFirst[i]);
      Partition p = this.partition(g, sorted, exclude);

      this.numberOfIsolatedComponents[i] = p.getComponents().length - 1;
      this.largestComponentSize[i] = p.getLargestComponent().length;
      this.largestComponentSizeFraction[i] =
          (double) p.getLargestComponent().length / (double) g.getNodes().length;

      if (this.numberOfIsolatedComponents[i] == 0) {
        this.isolatedComponentSizeAvg[i] = 0;
        this.isolatedComponentSizeMax[i] = 0;
        this.isolatedComponentSizeMed[i] = 0;
        this.isolatedComponentSizeMin[i] = 0;
      } else {
        this.isolatedComponentSizeAvg[i] = this.avgIsolatedSize(p);
        this.isolatedComponentSizeMax[i] = p.getComponents()[p.getComponents().length - 2].length;
        this.isolatedComponentSizeMed[i] =
            p.getComponents()[(int) Math.floor(p.getComponents().length / 2)].length;
        this.isolatedComponentSizeMin[i] = p.getComponents()[p.getComponents().length - 1].length;
      }

      if (this.largestComponentSize[i] < 0.5 * (g.getNodes().length - excludeFirst[i])
          && (double) excludeFirst[i] / (double) g.getNodes().length < this.criticalPoint) {
        this.criticalPoint = (double) excludeFirst[i] / (double) g.getNodes().length;
      }
    }
    this.runtime.end();
  }
  /*
   * (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();
    }
  }
Example #7
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;
  }
Example #8
0
  @Override
  public void computeData(Graph g, Network n, HashMap<String, Metric> m) {
    DataStorageList dsl = (DataStorageList) g.getProperty("DATA_STORAGE_0");

    int max = 0;
    for (DataStorage ds : dsl.getList()) {
      // System.out.println("DS.size = " + ds.size());
      if (ds.size() > max) {
        max = ds.size();
      }
    }

    double[] distr = new double[max + 1];
    for (DataStorage ds : dsl.getList()) {
      distr[ds.size()]++;
    }
    ArrayUtils.divide(distr, dsl.getList().length);

    this.dataItemsDistribution = new Distribution(distr);
  }
Example #9
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;
  }
Example #10
0
 @Override
 public boolean applicable(Graph g, Network n, HashMap<String, Metric> m) {
   return g.hasProperty("DATA_STORAGE_0")
       && g.getProperty("DATA_STORAGE_0") instanceof DataStorageList;
 }