Beispiel #1
0
  protected static long domSize(MoralGraphNode node) {
    long dom = node.getBruseNode().getStates().size();
    ArrayList<GraphNode> neighbors = node.getNeighbors();

    for (int i = 0; i < neighbors.size(); i++) {
      MoralGraphNode neighbor = (MoralGraphNode) neighbors.get(i);
      dom *= neighbor.getBruseNode().getStates().size();
    }

    return dom;
  }
Beispiel #2
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);
  }
Beispiel #3
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;
  }
Beispiel #4
0
  protected static void createFillIns(MoralGraphNode node) {
    ArrayList<GraphNode> neighbors = node.getNeighbors();

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

      for (int j = 0; j < neighbors.size(); j++) {
        if (i != j) {
          MoralGraphNode otherNeighbor = (MoralGraphNode) neighbors.get(j);

          // Add the neighbor
          // Note this will ignore if already a neighbor
          neighbor.addNeighbor(otherNeighbor);
        }
      }
    }
  }
Beispiel #5
0
  protected static Clique createClique(MoralGraphNode node) {
    BruseNode[] family = new BruseNode[node.getNeighbors().size() + 1];
    ArrayList<GraphNode> neighbors = node.getNeighbors();

    // add the simplicial node to the family
    family[0] = node.getBruseNode();

    // add the simplicial nodes neighbors to the family
    for (int i = 0; i < neighbors.size(); i++) {
      MoralGraphNode neighbor = (MoralGraphNode) neighbors.get(i);
      family[i + 1] = neighbor.getBruseNode();
    }

    // System.out.println("Clique size: " + domSize(node));

    return (new Clique(family));
  }
Beispiel #6
0
  private static int numFillIns(MoralGraphNode node) {
    ArrayList<GraphNode> neighbors = node.getNeighbors();
    int numFillIns = 0;

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

      for (int j = 0; j < neighbors.size(); j++) {
        if (i != j) {
          MoralGraphNode otherNeighbor = (MoralGraphNode) neighbors.get(j);

          // If neighbor is not connected then a fillin would be required
          if (neighbor.getNeighbors().contains(otherNeighbor) == false) numFillIns++;
        }
      }
    }
    return numFillIns;
  }
Beispiel #7
0
  protected static boolean isSimplicialNode(MoralGraphNode node) {
    ArrayList<GraphNode> neighbors = node.getNeighbors();

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

      for (int j = 0; j < neighbors.size(); j++) {
        if (i != j) {
          MoralGraphNode otherNeighbor = (MoralGraphNode) neighbors.get(j);

          // If neighbor is not fully connected then this is not a simplicial node
          if (neighbor.getNeighbors().contains(otherNeighbor) == false) return false;
        }
      }
    }

    // must be a simplicial node if we make it here
    return true;
  }