示例#1
0
  /**
   * applet as an application.
   *
   * @param args ignored.
   */
  public static void main(String[] args) {
    int nbVertex = 10, minInDegree = 1, maxInDegree = 3, minOutDegree = 1, maxOutDegree = 3;
    SDFAdapterDemo applet1 = new SDFAdapterDemo();
    SDFtoDAGDemo applet2 = new SDFtoDAGDemo();

    // Creates a random SDF graph
    int minrate = 1, maxrate = 15;
    try {
      SDFRandomGraph test = new SDFRandomGraph();
      SDFGraph demoGraph =
          test.createRandomGraph(
              nbVertex, minInDegree, maxInDegree, minOutDegree, maxOutDegree, minrate, maxrate);
      // SDFGraph demoGraph =createTestComGraph();
      TopologyVisitor topo = new TopologyVisitor();
      try {
        demoGraph.accept(topo);
      } catch (SDF4JException e) {
        e.printStackTrace();
      }
      applet1.init(demoGraph);

      DAGTransformation<DirectedAcyclicGraph> visitor =
          new DAGTransformation<DirectedAcyclicGraph>(
              new DirectedAcyclicGraph(), DAGVertexFactory.getInstance());
      try {
        demoGraph.accept(visitor);
      } catch (SDF4JException e) {
        e.printStackTrace();
      }
      applet2.init(visitor.getOutput());
      visitor.getOutput();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public Map<String, Object> execute(
      Map<String, Object> inputs,
      Map<String, String> parameters,
      IProgressMonitor monitor,
      String nodeName,
      Workflow workflow)
      throws WorkflowException {

    // Get the SDFGraph to optimize
    @SuppressWarnings("unchecked")
    Set<SDFGraph> graphs = (Set<SDFGraph>) inputs.get(KEY_SDF_GRAPHS_SET);

    // First pass is to clean the graph from useless pairs of join-fork
    // vertices which can hinder scheduling

    // JoinForkCleaner evaluates some rates and delays expressions, and thus
    // can throw InvalidExpressionExceptions, even if at this point of the
    // workflow, there should have been already raised
    for (SDFGraph graph : graphs) {
      try {
        while (JoinForkCleaner.cleanJoinForkPairsFrom(graph)) ;
      } catch (InvalidExpressionException e) {
        System.err.println("SDFGraph " + graph.getName() + " contains invalid expressions.");
        e.printStackTrace();
      } catch (SDF4JException e) {
        System.err.println("Error when cleaning fork/join pairs in SDFGraph " + graph.getName());
        e.printStackTrace();
      }
    }

    Map<String, Object> outputs = new HashMap<String, Object>();
    outputs.put(KEY_SDF_GRAPHS_SET, graphs);
    return outputs;
  }