Пример #1
0
 @Override
 public String toString() {
   StringBuffer s = new StringBuffer();
   for (Node n : thing) {
     s.append(n.getName());
   }
   return s.toString() + ": " + reward;
 }
Пример #2
0
 public List<Predication> process(
     Node tg, String graphOutputFileName, EvalLinearization... criteria) throws Exception {
   unpackEvents(tg);
   if (graphOutputFileName != null) tg.toGDLGraph(graphOutputFileName);
   Set<Node> nodes = tg.getAllNodes();
   nodes.remove(tg);
   PriorityQueue<Element> result = permutations(nodes, 3, criteria);
   Element top = null;
   while (!result.isEmpty()) top = result.poll();
   List<Predication> ps = null;
   for (Node n : top.thing) {
     if (n != null) {
       List<Predication> predications = ((EventNode) n).getPredications();
       if (predications != null) {
         if (ps == null) ps = new ArrayList<Predication>();
         ps.add(predications.get(0));
       }
     }
   }
   return ps;
 }
Пример #3
0
 /**
  * for each node in the timegraph, extract its associated predications and add parallel nodes for
  * each predication.
  *
  * @param tg
  * @return
  * @throws Exception
  */
 private void unpackEvents(Node tg) throws Exception {
   Stack<Node> s = new Stack<Node>();
   Set<Node> visited = new HashSet<Node>();
   s.push(tg);
   while (!s.isEmpty()) {
     Node n = s.pop();
     if (!visited.contains(n)) {
       visited.add(n);
       if (n != null && n instanceof EventNode) {
         List<Predication> ps = ((EventNode) n).getPredications();
         if (ps != null && ps.size() > 1) {
           // change only if the size is greater than 1
           List<Edge> ins = n.getIncomingEdges();
           List<Edge> outs = n.getOutgoingEdges();
           boolean first = true;
           int counter = 1;
           for (Predication p : ps) {
             String nname = n.getName() + "_" + counter;
             ArrayList<Predication> nps = new ArrayList<Predication>();
             nps.add(p);
             if (first) {
               // reuse the existing node
               ((EventNode) n).setPredications(nps);
               n.setName(nname);
               first = false;
             } else {
               // add a new parallel node
               EventNode nn = new EventNode(nname);
               for (Edge in : ins) {
                 Node source = in.getSource();
                 source.addEdgeTo(nn, true, true);
               }
               for (Edge out : outs) {
                 Node target = out.getTarget();
                 nn.addEdgeTo(target, true, true);
               }
               ((EventNode) nn).setPredications(nps);
             }
             counter++;
           }
         }
       }
       Collection cs = n.getImmediateChildren();
       if (cs != null) s.addAll(cs);
     }
   }
 }