Ejemplo n.º 1
0
  /**
   * Construct an attribute with the given name contained by the specified container. The container
   * argument must not be null, or a NullPointerException will be thrown. This attribute will use
   * the workspace of the container for synchronization and version counts. If the name argument is
   * null, then the name is set to the empty string. Increment the version of the workspace.
   *
   * @param container The container.
   * @param name The name of this attribute.
   * @exception IllegalActionException If the attribute is not of an acceptable class for the
   *     container, or if the name contains a period.
   * @exception NameDuplicationException If the name coincides with an attribute already in the
   *     container.
   */
  public IDAttribute(Entity container, String name)
      throws IllegalActionException, NameDuplicationException {
    super(container, name);

    // name for the model
    this.name = new StringAttribute(this, "name");
    this.name.setExpression(container.getName());

    // This should not be persistent, in case the name changes outside
    // of this parameter.
    this.name.setPersistent(false);

    // This should not be editable, since the name is set by saveAs.
    this.name.setVisibility(Settable.NOT_EDITABLE);

    // FIXME: Need to listen for changes to the name.
    // How to do that?
    // The current design is also a solution in that the name of this
    // attribute and model must be consistent with the name of the file.
    // boolean isClass = false;
    // if (container instanceof InstantiableNamedObj) {
    /* isClass = */ ((InstantiableNamedObj) container).isClassDefinition();
    // }

    String className = container.getClassName();

    baseClass = new StringAttribute(this, "baseClass");
    baseClass.setExpression(className);

    // This should not be persistent, because the base class
    // is set already, generally.
    baseClass.setPersistent(false);

    // Cannot change the base class.
    baseClass.setVisibility(Settable.NOT_EDITABLE);

    URIAttribute modelURI = (URIAttribute) container.getAttribute("_uri", URIAttribute.class);

    if (modelURI != null) {
      StringAttribute definedIn = new StringAttribute(this, "definedIn");
      definedIn.setExpression(modelURI.getURI().toString());
      definedIn.setPersistent(false);
      definedIn.setVisibility(Settable.NOT_EDITABLE);
    }

    // The date when this model is created.
    // Actually, it is the date when this attribute is created.
    // We assume that when the model is created, this attribute
    // is also created.
    // We may force this to happen.:-) Further more, we may force
    // that only the top level contains an model ID.
    created = new StringAttribute(this, "created");
    created.setExpression(DateFormat.getDateTimeInstance().format(new Date()));
    created.setVisibility(Settable.NOT_EDITABLE);
    created.setPersistent(true);

    // The date when this model is modified.
    // Everytime the model gets modified, the updateContent method
    // defined below is called and the lastUpdated attribute gets
    // updated.
    lastUpdated = new StringAttribute(this, "lastUpdated");
    _updateDate();
    lastUpdated.setVisibility(Settable.NOT_EDITABLE);
    lastUpdated.setPersistent(true);

    // The name of the author who creates the model.
    // This attribute can not be changed so that the
    // intellectual property (IP) is preserved.
    author = new StringAttribute(this, "author");
    author.setVisibility(Settable.NOT_EDITABLE);

    String userName = null;

    try {
      userName = StringUtilities.getProperty("user.name");
    } catch (Exception ex) {
      System.out.println(
          "Warning, in IDAttribute, failed to read "
              + "'user.name' property (-sandbox or applets always cause "
              + "this)");
    }

    if (userName != null) {
      author.setExpression(userName);
    }

    author.setPersistent(true);

    // The names of the contributors who modify the model.
    contributors = new StringAttribute(this, "contributors");

    String contributorsNames = "";
    contributors.setExpression(contributorsNames);
    author.setPersistent(true);

    // Hide the name of this ID attribute.
    SingletonParameter hide = new SingletonParameter(this, "_hideName");
    hide.setToken(BooleanToken.TRUE);
    hide.setVisibility(Settable.EXPERT);

    BoxedValuesIcon icon = new BoxedValuesIcon(this, "_icon");
    icon.setPersistent(false);

    // No need to display any parameters when the "_showParameters"
    // preference asks for such display because presumably all the
    // parameters are reflected in the visual display already.
    Parameter hideAllParameters = new Parameter(this, "_hideAllParameters");
    hideAllParameters.setVisibility(Settable.EXPERT);
    hideAllParameters.setExpression("true");
  }
Ejemplo n.º 2
0
  /**
   * Return the parameterized scheduling sequence. An exception will be thrown if the graph is not
   * schedulable.
   *
   * @return A schedule of the deeply contained opaque entities in the firing order.
   * @exception NotSchedulableException If a parameterized schedule cannot be derived for the model.
   * @exception IllegalActionException If the rate parameters of the model are not correct, or the
   *     computed rates for external ports are not correct.
   */
  @SuppressWarnings("unused")
  protected Schedule _getSchedule() throws NotSchedulableException, IllegalActionException {
    PSDFDirector director = (PSDFDirector) getContainer();
    CompositeActor model = (CompositeActor) director.getContainer();

    // Get the vectorization factor.
    String vectorizationFactorExpression = "1";

    String vectorizationName = director.vectorizationFactor.getName(model);
    vectorizationFactorExpression = vectorizationName.replaceAll("\\.", "::");

    if (vectorizationFactorExpression.indexOf(" ") != -1) {
      throw new InternalErrorException(
          "The vectorizationFactor "
              + "PSDFDirector parameter must "
              + "not have spaces in its value.  The original value "
              + "was \""
              + vectorizationName
              + "\". Try changing the name of "
              + "director.");
    }

    PSDFGraphReader graphReader = new PSDFGraphReader();
    PSDFGraph graph = (PSDFGraph) graphReader.convert(model);
    _debug("PSDF graph = \n" + graph.toString());

    if (_debugFlag) {
      graph.printEdgeRateExpressions();
    }

    PSDFAPGANStrategy strategy = new PSDFAPGANStrategy(graph);
    ptolemy.graph.sched.Schedule graphSchedule = strategy.schedule();
    _debug("P-APGAN schedule = \n" + graphSchedule.toString());

    SymbolicScheduleElement resultSchedule =
        _expandAPGAN(graph, strategy.getClusterManager().getRootNode(), strategy);
    resultSchedule.setIterationCount(vectorizationFactorExpression);

    _debug("Final schedule = \n" + resultSchedule.toString());

    if (_debugging) {
      _debug("The buffer size map:\n");

      Iterator relations = _bufferSizeMap.keySet().iterator();

      while (relations.hasNext()) {
        Relation relation = (Relation) relations.next();
        _debug(relation.getName() + ": " + _bufferSizeMap.get(relation) + "\n");
      }
    }

    _saveBufferSizes(_bufferSizeMap);

    // Crazy hack to infer firing counts for each actor.
    try {
      _inferFiringCounts(resultSchedule, null);
    } catch (NameDuplicationException ex) {
      throw new NotSchedulableException(new LinkedList(), ex, "Error recording firing counts");
    }

    // Crazy hack to Infer port production: FIXME: This should be
    // done as part of the APGAN expansion where the rates of
    // external ports are unknown The reason is that it will make
    // rate information propagate from an actor input port to
    // another actors input port that are connected on the inside
    // to the same external input port.  See
    // BaseSDFScheduler.setContainerRates.
    Iterator ports = model.portList().iterator();

    while (ports.hasNext()) {
      IOPort port = (IOPort) ports.next();

      if (_debugging && VERBOSE) {
        _debug("External Port " + port.getName());
      }

      if (port.isInput() && port.isOutput()) {
        throw new NotSchedulableException(
            port,
            "External port is both an input and an output, " + "which is not allowed in SDF.");
      } else if (port.isInput()) {
        List sinks = port.insideSinkPortList();

        if (sinks.size() > 0) {
          IOPort connectedPort = (IOPort) sinks.get(0);
          Entity entity = (Entity) connectedPort.getContainer();
          String name = connectedPort.getName(model);
          String identifier = name.replaceAll("\\.", "::");

          String sinkExpression;
          Variable sinkRateVariable =
              DFUtilities.getRateVariable(connectedPort, "tokenConsumptionRate");

          if (sinkRateVariable == null) {
            sinkExpression = "1";
          } else {
            sinkExpression = identifier + "::" + sinkRateVariable.getName();
          }

          String expression = sinkExpression + " * " + entity.getName() + "::firingsPerIteration";

          DFUtilities.setExpressionIfNotDefined(port, "tokenConsumptionRate", expression);

          if (_debugging && VERBOSE) {
            _debug("Setting tokenConsumptionRate to " + expression);
          }
        }
      } else if (port.isOutput()) {
        List sources = port.insideSourcePortList();

        if (sources.size() > 0) {
          IOPort connectedPort = (IOPort) sources.get(0);
          Entity entity = (Entity) connectedPort.getContainer();
          String name = connectedPort.getName(model);
          String identifier = name.replaceAll("\\.", "::");
          Variable sourceRateVariable =
              DFUtilities.getRateVariable(connectedPort, "tokenProductionRate");
          String sourceExpression;

          if (sourceRateVariable == null) {
            sourceExpression = "1";
          } else {
            sourceExpression = identifier + "::" + sourceRateVariable.getName();
          }

          String expression = sourceExpression + " * " + entity.getName() + "::firingsPerIteration";

          DFUtilities.setExpressionIfNotDefined(port, "tokenProductionRate", expression);

          if (_debugging && VERBOSE) {
            _debug("Setting tokenProductionRate to " + expression);
          }
        }

        // Infer init production.
        // Note that this is a very simple type of inference...
        // However, in general, we don't want to try to
        // flatten this model...
        //  Iterator connectedPorts =
        //                     port.insideSourcePortList().iterator();
        //                 IOPort foundOutputPort = null;
        //                 int inferredRate = 0;
        //                 while (connectedPorts.hasNext()) {
        //                     IOPort connectedPort = (IOPort) connectedPorts.next();
        //                     int newRate;
        //                     if (connectedPort.isOutput()) {
        //                         newRate =
        //                             DFUtilities.getTokenInitProduction(connectedPort);
        //                     } else {
        //                         newRate = 0;
        //                     }
        //                     // If we've already set the rate, then check that the
        //                     // rate for any other internal port is correct.
        //                     if (foundOutputPort != null &&
        //                             newRate != inferredRate) {
        //                         throw new NotSchedulableException(
        //                                 "External output port " + port
        //                                 + " is connected on the inside to ports "
        //                                 + "with different initial production: "
        //                                 + foundOutputPort + " and "
        //                                 + connectedPort);
        //                     }
        //                     foundOutputPort = connectedPort;
        //                     inferredRate = newRate;
        //                 }
        //                 DFUtilities._setIfNotDefined(
        //                         port, "tokenInitProduction", inferredRate);
        //                 if (_debugging && VERBOSE) {
        //                     _debug("Setting tokenInitProduction to "
        //                             + inferredRate);
        //                 }
      } else {
        throw new NotSchedulableException(
            port,
            "External port is neither an input and an output, " + "which is not allowed in SDF.");
      }
    }

    // Set the schedule to be valid.
    setValid(true);

    if (resultSchedule instanceof Schedule) {
      return (Schedule) resultSchedule;
    } else {
      // Must be ScheduleElement.
      Schedule schedule = new Schedule();
      schedule.add((ScheduleElement) resultSchedule);
      return schedule;
    }
  }
Ejemplo n.º 3
0
  /**
   * Construct a Unit Solver Dialog.
   *
   * @param dialogTableau The DialogTableau.
   * @param owner The object that, per the user, appears to be generating the dialog.
   * @param target The object whose units are being solved.
   * @param configuration The configuration to use to open the help screen.
   */
  public UnitSolverDialog(
      DialogTableau dialogTableau, Frame owner, Entity target, Configuration configuration) {
    super("Solve units for " + target.getName(), dialogTableau, owner, target, configuration);

    SelectionRenderer tempSelectionRenderer = null;
    _tableau = ((TableauFrame) owner).getTableau();

    _model = (TypedCompositeActor) target;

    // ((TypedCompositeActor) (((PtolemyEffigy) (_tableau.getContainer()))
    //      .getModel()));
    BasicGraphFrame parent = (BasicGraphFrame) (_tableau.getFrame());
    JGraph jGraph = parent.getJGraph();
    GraphPane graphPane = jGraph.getGraphPane();
    _controller = graphPane.getGraphController();
    _selectionModel = _controller.getSelectionModel();

    Interactor interactor = _controller.getEdgeController(new Object()).getEdgeInteractor();
    _graphModel = (AbstractBasicGraphModel) _controller.getGraphModel();
    _selectionInteractor = (SelectionInteractor) interactor;
    _defaultSelectionRenderer = _selectionInteractor.getSelectionRenderer();
    tempSelectionRenderer = new BasicSelectionRenderer(new BasicEdgeHighlighter());

    if (_model == getTarget()) {
      _entities = _getSelectedNodes();
      _relations = _getSelectedRelations();

      if (_entities.isEmpty() && _relations.isEmpty()) {
        _entities = new Vector(_model.entityList(ComponentEntity.class));
        _relations = new Vector(_model.relationList());
      }
    } else {
      _entities = new Vector();
      _entities.add(getTarget());
      _relations = new Vector();
    }

    _selectionModel.clearSelection();
    _selectionInteractor.setSelectionRenderer(tempSelectionRenderer);
    _showComponents();
    _selectionModel.addSelectionListener(this);

    JPanel fullSolverPanel = new JPanel();
    fullSolverPanel.setLayout(new BoxLayout(fullSolverPanel, BoxLayout.Y_AXIS));
    fullSolverPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Full Solution"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    _runFullSolverButton.addActionListener(this);
    fullSolverPanel.add(_runFullSolverButton);
    _fullSolutionResult.setOpaque(true);
    _fullSolutionResult.setBackground(Color.white);
    fullSolverPanel.add(_fullSolutionResult);

    JPanel componentsPanel = new JPanel();
    componentsPanel.setLayout(new BoxLayout(componentsPanel, BoxLayout.Y_AXIS));
    componentsPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Components"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    _setToSelectedButton.setEnabled(false);
    componentsPanel.add(_setToSelectedButton);
    _setToSelectedButton.addActionListener(this);
    componentsPanel.add(_showComponentsButton);
    _showComponentsButton.addActionListener(this);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
    topPanel.add(fullSolverPanel);
    topPanel.add(componentsPanel);

    JPanel minimalSpanPanel = new JPanel(new BorderLayout());
    minimalSpanPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Minimal Spanning Solutions"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    minimalSpanPanel.add(_runMinimalSpanSolverButton, BorderLayout.NORTH);
    _runMinimalSpanSolverButton.addActionListener(this);
    _solutionsListModel = new SolutionListModel();
    _solutionsList = new JList(_solutionsListModel);
    _solutionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _solutionsList.addListSelectionListener(this);

    JScrollPane scrollPane = new JScrollPane(_solutionsList);
    minimalSpanPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel mainPane = new JPanel();
    mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
    mainPane.add(topPanel);
    mainPane.add(minimalSpanPanel);
    setContents(mainPane);
  }