Exemplo n.º 1
0
  public boolean removeVertex(V vertex) {
    if (!containsVertex(vertex)) return false;

    // copy to avoid concurrent modification in removeEdge
    ArrayList<E> incident = new ArrayList<E>(getIncoming_internal(vertex));
    incident.addAll(getOutgoing_internal(vertex));

    for (E edge : incident) removeEdge(edge);

    vertices.remove(vertex);

    return true;
  }
  private void addRuleNodes(boolean[] filter) {
    Iterator<String> e = edgeList.iterator();
    while (e.hasNext()) {
      graph.removeEdge(e.next());
    }

    Iterator<String> n = nodeList.iterator();
    while (n.hasNext()) {
      graph.removeVertex(n.next());
    }

    edgeList.clear();
    nodeList.clear();

    toolTipInfos.clear();
    asPremise.clear();
    asConclusion.clear();

    int ruleIndex = 1;
    for (int r = 0; r < rules.getNumberOfRules(); r++) {
      if (filter[r]) {
        AssociationRule rule = rules.getRule(r);

        // define conjunction node
        String conjunctionNode =
            "Rule "
                + ruleIndex
                + " ("
                + Tools.formatNumber(rule.getTotalSupport())
                + " / "
                + Tools.formatNumber(rule.getConfidence())
                + ")";
        toolTipInfos.put(
            conjunctionNode,
            "<html><b>Rule "
                + ruleIndex
                + "</b><br>"
                + SwingTools.addLinebreaks(
                    rule.toPremiseString() + " --> " + rule.toConclusionString())
                + "<br><b>Support:</b> "
                + rule.getTotalSupport()
                + "<br><b>Confidence:</b> "
                + rule.getConfidence()
                + "<br><b>Lift:</b> "
                + rule.getLift()
                + "<br><b>Gain:</b> "
                + rule.getGain()
                + "<br><b>Conviction:</b> "
                + rule.getConviction()
                + "<br><b>Laplace:</b> "
                + rule.getLaplace()
                + "<br><b>Ps:</b> "
                + rule.getPs()
                + "</html>");
        nodeList.add(conjunctionNode);

        // add premise nodes
        Iterator<Item> p = rule.getPremiseItems();
        while (p.hasNext()) {
          Item premiseItem = p.next();
          String edgeId = edgeFactory.create();
          edgeList.add(edgeId);
          nodeList.add(premiseItem.toString());
          graph.addEdge(edgeId, premiseItem.toString(), conjunctionNode);
          List<String> premiseList = asPremise.get(premiseItem.toString());
          if (premiseList == null) {
            premiseList = new LinkedList<String>();
            asPremise.put(premiseItem.toString(), premiseList);
          }
          premiseList.add("Rule " + ruleIndex);
        }

        // add conclusion nodes
        Iterator<Item> c = rule.getConclusionItems();
        while (c.hasNext()) {
          Item conclusionItem = c.next();
          String edgeId = edgeFactory.create();
          edgeList.add(edgeId);
          nodeList.add(conclusionItem.toString());
          graph.addEdge(edgeId, conjunctionNode, conclusionItem.toString());
          List<String> conclusionList = asConclusion.get(conclusionItem.toString());
          if (conclusionList == null) {
            conclusionList = new LinkedList<String>();
            asConclusion.put(conclusionItem.toString(), conclusionList);
          }
          conclusionList.add("Rule " + ruleIndex);
        }
      }
      ruleIndex++;
    }
  }