예제 #1
0
  /**
   * Method compares the average edge-length and the average node-distance with the optimal
   * Sugiyama-distance.
   *
   * @param graph
   */
  public static String smallestSeparation_Test(OperatorGraph graph) {
    HashMap<GraphWrapper, GraphBox> boxes = graph.getBoxes();
    int nodeAmount = boxes.size();
    double scaleConst = 1.0;
    int width = GraphHelper.graphWidth(graph);
    int height = GraphHelper.graphHeight(graph);
    LinkedList<Double> distances = new LinkedList<Double>();
    // compute optimal distance after Sugiyama
    double optiDist = scaleConst * Math.sqrt((width * height) / nodeAmount);

    double ariMiddle = 0.0;
    int edges = 0;
    LinkedList<Double> length = new LinkedList<Double>();

    for (GraphWrapper gw : boxes.keySet()) {
      LinkedList<GraphWrapper> children = gw.getPrecedingElements();
      for (GraphWrapper child : children) {
        double edgeLen = edgeLength(graph, gw, child);
        length.add(edgeLen);
        ariMiddle += edgeLen;
        edges++;
      }
    }

    ariMiddle = ariMiddle / edges;

    double avrDist = 0.0;
    for (GraphWrapper node1 : boxes.keySet()) {
      LinkedList<GraphWrapperIDTuple> childrenTuple = node1.getSucceedingElements();
      LinkedList<GraphWrapper> children = new LinkedList<GraphWrapper>();
      for (GraphWrapperIDTuple child : childrenTuple) {
        children.add(child.getOperator());
      }
      GraphBox box1 = boxes.get(node1);
      for (GraphWrapper node2 : boxes.keySet()) {
        if ((!node2.equals(node1))) {
          GraphBox box2 = boxes.get(node2);
          // compute distance between node1 and node 2
          int x = box2.getX() - box1.getX();
          int y = box2.getY() - box1.getY();
          double distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
          distances.add(distance);
          avrDist += distance;
        }
      }
    }

    avrDist = avrDist / distances.size();

    String result = "Test: Smallest Separation:\n";
    result += "The optimal distance based on Sugiyama is " + optiDist + ".\n";
    result += "The average distance between not connected nodes is " + avrDist + ".\n";
    result += "The average edge length is " + ariMiddle + ".\n";

    return result;
  }
예제 #2
0
  public Set<String> hyponyms(String word) {
    String[] parsed;
    Set<Integer> id = new HashSet<>();

    for (int x = 0; x < map.size(); x += 1) {
      parsed = map.get(x).split(" ");
      for (int y = 0; y < parsed.length; y += 1) {
        if (word.equals(parsed[y])) {
          id.add(x);
        }
      }
    }

    Set<String> hyponyms = new HashSet<>();
    Set<Integer> hyponymsid = GraphHelper.descendants(synsets, id);
    String[] listids;

    for (int x : hyponymsid) {
      listids = map.get(x).split(" ");
      for (int i = 0; i < listids.length; i += 1) {
        if (!hyponyms.contains(listids[i])) {
          hyponyms.add(listids[i]);
        }
      }
    }

    return hyponyms;
  }
예제 #3
0
  /**
   * Method tests if a graph-layout is symmetric to an axis and shows the result on command-line
   *
   * @param graph
   */
  public static String symmetry_Test(OperatorGraph graph) {
    int width = GraphHelper.graphWidth(graph);
    double symLine = width / 2;

    HashMap<GraphWrapper, GraphBox> boxes = graph.getBoxes();
    LinkedList<GraphBox> left = new LinkedList<GraphBox>();
    LinkedList<GraphBox> right = new LinkedList<GraphBox>();

    String result = "Test: Axially Symmetry:\n";
    // get boxes of left and right side of symmetry-line
    for (GraphBox box : boxes.values()) {
      if ((box.getX() + box.width) <= symLine) {
        left.add(box);
      } else if (box.getX() >= symLine) {
        right.add(box);
      } else { // test if node is centered on symmetry-line
        if ((box.getX() + (box.width / 2)) != symLine) {
          result += "Node not in the middle of the symmetry axe!\n";
          result += "Node with x = " + box.getX() + "    y = " + box.getY() + ".\n";
        }
      }
    }

    // test if node-amount on left and right side of symmetry-line is equal
    if (left.size() != right.size()) {
      result += "Different number of nodes on both sides of the symmetry axe:\n";
      result += "Left: " + left.size() + "    Right: " + right.size() + "\n";
    }

    // compute symmetric node-counter-parts
    int symCounter = 0;
    boolean sym = true;
    for (GraphBox box1 : left) {
      double symSpace = symLine - (box1.getX() + box1.width);
      int y = box1.getY();
      for (GraphBox box2 : right) {
        if (y == box2.getY()) {
          if ((symLine + symSpace) == box2.getX()) {
            sym = true;
            symCounter++;
            break;
          } else {
            sym = false;
          }
        }
        sym = false;
      }
    }

    // compute number of symmetric nodes
    final int sumSizes = left.size() + right.size();
    double p = (sumSizes == 0) ? 100 : (2 * symCounter * 100) / ((double) sumSizes);

    if (sym == false) {
      result += "The graph is " + p + "% axially symmetric!\n";
    } else {
      result += "The graph is 100% axially symmetric!\n";
    }
    return result;
  }
예제 #4
0
  /**
   * Method tests if graph-nodes are uniform distributed over the screen.
   *
   * @param op the graph
   */
  public static String uniformDistribution_Test(OperatorGraph op) {
    HashMap<GraphWrapper, GraphBox> boxes = op.getBoxes();
    double width = GraphHelper.graphWidth(op);
    double height = GraphHelper.graphHeight(op);
    int nodeAmount = boxes.size();
    int fieldNumber = 0;

    // compute number of grid-fields
    fieldNumber = (int) Math.floor(Math.sqrt(nodeAmount));

    int[][] grid = new int[fieldNumber][fieldNumber];

    // compute width and height of grid-fields
    int fieldSpaceX = (int) Math.ceil(width / fieldNumber);
    int fieldSpaceY = (int) Math.ceil(height / fieldNumber);
    int x = fieldSpaceX;
    int y = fieldSpaceY;

    // compute how many nodes are in the grid-fields
    for (int i = 0; i < fieldNumber; i++) {
      for (int j = 0; j < fieldNumber; j++) {
        for (GraphBox box : boxes.values()) {
          if ((box.getX() + box.width < x)
              && (box.getX() >= x - fieldSpaceX)
              && (box.getY() + box.height < y)
              && (box.getY() >= y - fieldSpaceY)) {
            grid[i][j]++;
          }
        }
        y += fieldSpaceY;
      }
      x += fieldSpaceX;
      y = fieldSpaceY;
    }

    // test if nodes are uniformly distributed
    int notUniform = 0;
    boolean equ = true;
    for (int i = 0; i < fieldNumber; i++) {
      for (int j = 0; j < fieldNumber; j++) {
        if ((grid[i][j] > 2) || (grid[i][j] < 1)) {
          equ = false;
          notUniform++;
        }
      }
    }

    String result = "Test: uniform distribution of nodes:\n";
    result += "Size of grid: " + fieldNumber + " * " + fieldNumber + "\n";
    System.out.println("");
    if (equ == false) {
      int fields = fieldNumber * fieldNumber;
      // compute percent of uniform node distribution
      double p = 100 - ((notUniform * 100) / fields);
      result += "The graph is about " + p + "% uniformly filled with nodes...\n";
    } else {
      result += "All grid fields contain 1 or 2 nodes.\n";
      result += "The graph is 100% uniformly filled with nodes...\n";
    }
    return result;
  }