Esempio n. 1
0
 /**
  * This is the edge writing part of the {@link #writeToDot writeToDot} procedure. This part of the
  * visualization gets affected by the probabilities that are displayed at XOR-splits.
  *
  * @param bw the writer used by the framework to create the temporary dot file
  * @throws IOException if writing to the writer fails
  * @todo Peter: figure out how to place the probabilities at the tail of the edge
  */
 protected void writeEdgesToDot(Writer bw) throws IOException {
   try {
     Iterator it = this.getEdges().iterator();
     while (it.hasNext()) {
       ExtendedPNEdge e = (ExtendedPNEdge) (it.next());
       if (e.isPT()) {
         ExtendedPlace p = (ExtendedPlace) e.getSource();
         Transition t = (Transition) e.getDest();
         if (p.getOutEdges().size() > 1) {
           // for all edges coming from places with more than one
           // outgoing edge, display probability in 2 decimal
           // digits
           double prob =
               e.getProbability(
                   currentlySelectedInstances,
                   p.getTotalOutEdgeFrequency(
                       currentlySelectedInstances, advancedSettings[1], failedInstances),
                   advancedSettings[1],
                   failedInstances);
           DecimalFormat digits = new DecimalFormat();
           digits.setMaximumFractionDigits(2);
           digits.setMinimumFractionDigits(2);
           String chance = digits.format(prob);
           // replace commas with dots, since dot forces use of
           // US-Locale
           chance = chance.replace(",", ".");
           bw.write("p" + p.getNumber() + " -> t" + t.getNumber() + " [label=" + chance + "];\n");
         } else {
           // write a normal edge
           bw.write("p" + p.getNumber() + " -> t" + t.getNumber() + ";\n");
         }
       } else {
         // write a normal edge
         Place p = (Place) e.getDest();
         Transition t = (Transition) e.getSource();
         bw.write("t" + t.getNumber() + " -> p" + p.getNumber() + ";\n");
       }
     }
   } catch (Exception ex) {
     Message.add("Failure while updating the visualization.\n" + ex.toString(), 2);
     ex.printStackTrace();
   }
 }