Exemple #1
0
  public DirectedAcyclicGraph<AbstractElement, DefaultEdge> generatePOG()
      throws DirectedAcyclicGraph.CycleFoundException {
    DirectedAcyclicGraph<AbstractElement, DefaultEdge> DAG = this.dag;
    Iterator<AbstractElement> iterator = DAG.iterator();

    /** 将node和Relationship都加入POG的顶点集 */
    while (iterator.hasNext()) {
      AbstractElement element = iterator.next();
      POG.addVertex(element);

      if (element instanceof RelationshipTemplate) {
        RelationshipTemplate rt = (RelationshipTemplate) element;
        NodeTemplate source_nt =
            Topology2DAG.nodeId2Object.get(capAndReq2NodeId.get(rt.getSourceElement()));
        NodeTemplate target_nt =
            Topology2DAG.nodeId2Object.get(capAndReq2NodeId.get(rt.getTargetElement()));
        if (element.getName().contains("hosted")) {
          POG.addDagEdge(target_nt, rt);
          POG.addDagEdge(rt, source_nt);
        } else if (element.getName().contains("connects")) {
          POG.addDagEdge(target_nt, rt);
          POG.addDagEdge(source_nt, rt);
        }
      }
    }

    return POG;
  }
Exemple #2
0
 public boolean addStream(final OPNode src, final OPNode dst) {
   DStream dstream = new DStream(src, dst);
   if (!super.vertexSet().contains(dstream.getSrc())) super.addVertex(dstream.getSrc());
   if (!super.vertexSet().contains(dstream.getDst())) super.addVertex(dstream.getDst());
   try {
     if (super.addDagEdge(dstream.getSrc(), dstream.getDst(), dstream)) {
       super.setEdgeWeight(dstream, dstream.getWeight());
       return true;
     }
     return false;
   } catch (CycleFoundException exc) {
     return false;
   }
 }
  public Inference(DecomposableModel model, String[] variableNames, String[][] outcomes) {

    try {
      this.bn = model.getBayesianNetwork();
    } catch (CycleFoundException e) {
      e.printStackTrace();
    }

    this.jnodes = new HashMap<Integer, BayesNode>();
    this.nodesNumber = new HashMap<BayesNode, Integer>();
    this.nodeNames = new HashMap<Integer, String>();
    this.nodeIDFromName = new HashMap<String, Integer>();
    this.jbn = new BayesNet();
    for (Integer nodeID : bn.vertexSet()) {
      String name = variableNames[nodeID];
      BayesNode node = jbn.createNode(name);
      node.addOutcomes(outcomes[nodeID]);

      nodeNames.put(nodeID, name);
      nodeIDFromName.put(name, nodeID);
      nodesNumber.put(node, nodeID);
      jnodes.put(nodeID, node);
    }

    for (Integer nodeID : bn.vertexSet()) {
      BayesNode node = jnodes.get(nodeID);
      ArrayList<BayesNode> parents = new ArrayList<BayesNode>();
      for (DefaultEdge e : bn.edgesOf(nodeID)) {
        if (bn.getEdgeTarget(e) == nodeID) {
          BayesNode oneParent = jnodes.get(bn.getEdgeSource(e));
          parents.add(oneParent);
        }
      }
      if (!parents.isEmpty()) {
        node.setParents(parents);
      }
    }
  }