Exemple #1
0
  protected static void removeNode(MoralGraph graph, MoralGraphNode node) {
    ArrayList<GraphNode> neighbors = node.getNeighbors();

    for (int i = 0; i < neighbors.size(); i++) {
      MoralGraphNode neighbor = (MoralGraphNode) neighbors.get(i);

      neighbor.removeNeighbor(node);
    }

    graph.removeNode(node);
  }
Exemple #2
0
  protected static MoralGraphNode findSimplicialNode(MoralGraph graph) {
    ArrayList<GraphNode> nodes = graph.getNodes();
    MoralGraphNode node = null;

    for (int i = 0; i < nodes.size(); i++) {
      node = (MoralGraphNode) nodes.get(i);
      if (isSimplicialNode(node)) return node;
    }

    // No simplicial node exists return null
    return null;
  }
Exemple #3
0
  protected static ArrayList<Clique> triangulate(MoralGraph graph) {
    // Heuristic: Repeatedly remove a simplicial node and if none exists
    // then remove a node with the smallest size(family)
    ArrayList<Clique> cliques = new ArrayList<Clique>();

    // make a working copy of the graph
    MoralGraph workingGraph = (MoralGraph) graph.clone();

    // While there are more nodes in the working graph
    while (workingGraph.size() > 0) {
      // Find next node to process as a clique
      MoralGraphNode node = processNextNode(workingGraph);

      // create clique
      cliques.add(createClique(node));

      // remove node from graph
      removeNode(workingGraph, node);
    }

    return cliques;
  }
Exemple #4
0
  protected static MoralGraphNode findMinFillInNode(MoralGraph graph) {
    ArrayList<GraphNode> nodes = graph.getNodes();
    MoralGraphNode minFillInNode = null, node = null;
    int fillIns = 0, minFillIns = Integer.MAX_VALUE;

    for (int i = 0; i < nodes.size(); i++) {
      node = (MoralGraphNode) nodes.get(i);
      fillIns = numFillIns(node);

      if (fillIns < minFillIns) {
        minFillIns = fillIns;
        minFillInNode = node;
      }
    }

    return minFillInNode;
  }
Exemple #5
0
  protected static MoralGraphNode findBestNode(MoralGraph graph) {
    ArrayList<GraphNode> nodes = graph.getNodes();
    MoralGraphNode bestNode = null, node = null;
    long dom = 0, minDom = Long.MAX_VALUE;

    for (int i = 0; i < nodes.size(); i++) {
      node = (MoralGraphNode) nodes.get(i);
      dom = domSize(node) / node.getBruseNode().getStates().size();

      if ((dom < minDom) && (dom > 0)) {
        minDom = dom;
        bestNode = node;
      }
    }

    return bestNode;
  }