@Override
  public void execute(GraphModel gm, AttributeModel am) {
    Graph graph = gm.getUndirectedGraphVisible();
    graph.readLock();

    // calculate all Euclidean distances between all nodes
    double[] distances = geometry.calculateManyEuclideanDistances(graph.getNodes().toArray());
    // calculate the variation of coefficient over the distances
    result = String.valueOf(math.variationCoefficient(distances));
    graph.readUnlockAll();
  }
  private void calculateMinMax(Graph graph) {
    minX = Float.POSITIVE_INFINITY;
    maxX = Float.NEGATIVE_INFINITY;
    minY = Float.POSITIVE_INFINITY;
    maxY = Float.NEGATIVE_INFINITY;
    minZ = Float.POSITIVE_INFINITY;
    maxZ = Float.NEGATIVE_INFINITY;
    minSize = Float.POSITIVE_INFINITY;
    maxSize = Float.NEGATIVE_INFINITY;

    for (Node node : graph.getNodes()) {
      NodeData nodeData = node.getNodeData();
      minX = Math.min(minX, nodeData.x());
      maxX = Math.max(maxX, nodeData.x());
      minY = Math.min(minY, nodeData.y());
      maxY = Math.max(maxY, nodeData.y());
      minZ = Math.min(minZ, nodeData.z());
      maxZ = Math.max(maxZ, nodeData.z());
      minSize = Math.min(minSize, nodeData.getSize());
      maxSize = Math.max(maxSize, nodeData.getSize());
    }
  }
Exemplo n.º 3
0
 private boolean isRanking(Graph graph, Column column) {
   if (column.isDynamic() && column.isNumber()) {
     ElementIterable<? extends Element> iterable =
         AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges();
     for (Element el : iterable) {
       if (el.getAttribute(column, graph.getView()) != null) {
         iterable.doBreak();
         return true;
       }
     }
   } else if (!column.isDynamic() && column.isIndexed() && column.isNumber()) {
     Index index;
     if (AttributeUtils.isNodeColumn(column)) {
       index = localScale ? graphModel.getNodeIndex(graph.getView()) : graphModel.getNodeIndex();
     } else {
       index = localScale ? graphModel.getEdgeIndex(graph.getView()) : graphModel.getEdgeIndex();
     }
     if (index.countValues(column) > 0) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
 private boolean isPartition(Graph graph, Column column) {
   if (column.isDynamic()) {
     Set<Object> set = new HashSet<Object>();
     boolean hasNullValue = false;
     int elements = 0;
     ElementIterable<? extends Element> iterable =
         AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges();
     for (Element el : iterable) {
       TimeMap val = (TimeMap) el.getAttribute(column);
       if (val != null) {
         Object[] va = val.toValuesArray();
         for (Object v : va) {
           if (v != null) {
             set.add(v);
           } else {
             hasNullValue = true;
           }
           elements++;
         }
       }
     }
     double ratio = set.size() / (double) elements;
     return ratio <= 0.9;
   } else if (column.isIndexed()) {
     Index index;
     if (AttributeUtils.isNodeColumn(column)) {
       index = graphModel.getNodeIndex(graph.getView());
     } else {
       index = graphModel.getEdgeIndex(graph.getView());
     }
     int valueCount = index.countValues(column);
     int elementCount = index.countElements(column);
     double ratio = valueCount / (double) elementCount;
     return ratio <= 0.9;
   }
   return false;
 }
  private void exportData(Graph graph) throws Exception {
    int max = graph.getNodeCount();

    Progress.start(progressTicket, max);

    if (!list) {
      if (header) {
        writer.append(SEPARATOR);
        Node[] nodes = graph.getNodes().toArray();
        for (int i = 0; i < nodes.length; i++) {
          writeMatrixNode(nodes[i], i < nodes.length - 1);
        }
        writer.append(EOL);
      }
    }

    if (list) {
      Node[] nodes = graph.getNodes().toArray();
      for (int i = 0; i < nodes.length; i++) {
        Node n = nodes[i];
        List<Node> neighbours = new ArrayList<Node>();
        for (Edge e : graph.getEdges(n)) {
          if (!e.isDirected() || (e.isDirected() && n == e.getSource())) {
            Node m = graph.getOpposite(n, e);
            neighbours.add(m);
          }
        }

        for (Edge e : ((HierarchicalGraph) graph).getMetaEdges(n)) {
          if (!e.isDirected() || (e.isDirected() && n == e.getSource())) {
            Node m = graph.getOpposite(n, e);
            neighbours.add(m);
          }
        }

        writeListNode(n, !neighbours.isEmpty());
        for (int j = 0; j < neighbours.size(); j++) {
          writeListNode(neighbours.get(j), j < neighbours.size() - 1);
        }
        writer.append(EOL);
      }
    } else {
      if (graph instanceof DirectedGraph) {
        DirectedGraph directedGraph = (DirectedGraph) graph;
        Node[] nodes = graph.getNodes().toArray();
        for (Node n : nodes) {
          if (cancel) {
            break;
          }
          writeMatrixNode(n, true);
          for (int j = 0; j < nodes.length; j++) {
            Node m = nodes[j];
            Edge e = directedGraph.getEdge(n, m);
            e = e == null ? ((HierarchicalDirectedGraph) directedGraph).getMetaEdge(n, m) : e;
            writeEdge(e, j < nodes.length - 1);
          }
          Progress.progress(progressTicket);
          writer.append(EOL);
        }
      } else if (graph instanceof UndirectedGraph) {
        UndirectedGraph undirectedGraph = (UndirectedGraph) graph;
        Node[] nodes = graph.getNodes().toArray();
        for (Node n : nodes) {
          if (cancel) {
            break;
          }
          writeMatrixNode(n, true);
          for (int j = 0; j < nodes.length; j++) {
            Node m = nodes[j];
            Edge e = undirectedGraph.getEdge(n, m);
            e = e == null ? ((HierarchicalUndirectedGraph) undirectedGraph).getMetaEdge(n, m) : e;
            writeEdge(e, j < nodes.length - 1);
          }
          Progress.progress(progressTicket);
          writer.append(EOL);
        }
      } else {
        MixedGraph mixedGraph = (MixedGraph) graph;
        Node[] nodes = graph.getNodes().toArray();
        for (Node n : graph.getNodes()) {
          if (cancel) {
            break;
          }
          writeMatrixNode(n, true);
          for (int j = 0; j < nodes.length; j++) {
            Node m = nodes[j];
            Edge e = mixedGraph.getEdge(n, m);
            e = e == null ? ((HierarchicalMixedGraph) mixedGraph).getMetaEdge(n, m) : e;
            writeEdge(e, j < nodes.length - 1);
          }
          Progress.progress(progressTicket);
          writer.append(EOL);
        }
      }
    }

    graph.readUnlockAll();

    Progress.finish(progressTicket);
  }
  private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();

    double window = statistics.getWindow();
    double tick = statistics.getTick();

    GraphView currentView = graphModel.getVisibleView();
    Interval bounds = statistics.getBounds();
    if (bounds == null) {
      if (currentView.isMainView()) {
        bounds = graphModel.getTimeBounds();
      } else {
        bounds = currentView.getTimeInterval();
      }
      statistics.setBounds(bounds);
    }

    if (dynamicLongTask != null) {
      // Count
      int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
      dynamicLongTask.start(c);
    }

    // Init
    statistics.execute(graphModel);

    // Loop
    for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
      double high = low + window;

      Graph graph = graphModel.getGraphVisible();

      graph.writeLock();

      GraphView view = graphModel.createView();
      Subgraph g = graphModel.getGraph(view);

      TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView);
      if (Double.isInfinite(nodeIndex.getMinTimestamp())
          && Double.isInfinite(nodeIndex.getMaxTimestamp())) {
        for (Node node : graph.getNodes()) {
          g.addNode(node);
        }
      } else {
        for (Node node : nodeIndex.get(new Interval(low, high))) {
          g.addNode(node);
        }
      }

      TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView);
      if (Double.isInfinite(edgeIndex.getMinTimestamp())
          && Double.isInfinite(edgeIndex.getMaxTimestamp())) {
        for (Edge edge : graph.getEdges()) {
          if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
            g.addEdge(edge);
          }
        }
      } else {
        for (Edge edge : edgeIndex.get(new Interval(low, high))) {
          if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
            g.addEdge(edge);
          }
        }
      }

      graph.writeUnlock();

      statistics.loop(g.getView(), new Interval(low, high));

      // Cancelled?
      if (dynamicLongTask != null && dynamicLongTask.isCancelled()) {
        return;
      } else if (dynamicLongTask != null) {
        dynamicLongTask.progress();
      }
    }
    statistics.end();
    model.addReport(statistics);
  }
  public void saveGraph(Graph graph, boolean isFilterGraph) {

    int Counter = 0;
    JsonObject attrJson;

    // clear existing graph
    if (!isFilterGraph) {
      nodesMap.clear();
      edgesMap.clear();
    } else {
      nodesMapFilter.clear();
      edgesMapFilter.clear();
    }

    /*
     * Nodes Iteration
     */
    for (Node node : graph.getNodes()) {
      attrJson = new JsonObject();
      for (String attrKey : node.getAttributeKeys()) {
        attrJson.put(attrKey, node.getAttribute(attrKey));
      }

      attrJson.put("x", node.x());
      attrJson.put("y", node.y());
      attrJson.put("cR", node.r());
      attrJson.put("cG", node.g());
      attrJson.put("cB", node.b());
      attrJson.put("size", node.size());

      if (!isFilterGraph) {
        nodesMap.put(Counter++, attrJson);
      } else {
        nodesMapFilter.put(Counter++, attrJson);
      }
    }

    Counter = 0;

    /*
     * Edges Iteration
     */
    for (Edge edge : graph.getEdges()) {
      attrJson = new JsonObject();
      for (String attrKey : edge.getAttributeKeys()) {
        attrJson.put(attrKey, edge.getAttribute(attrKey));
      }
      attrJson.put("source", edge.getSource().getId());
      attrJson.put("target", edge.getTarget().getId());

      attrJson.put("cR", edge.r());
      attrJson.put("cG", edge.g());
      attrJson.put("cB", edge.b());
      attrJson.put("size", edge.getWeight());
      if (!isFilterGraph) {
        edgesMap.put(Counter++, attrJson);
      } else {
        edgesMapFilter.put(Counter++, attrJson);
      }
    }
  }