Ejemplo n.º 1
0
  public SearchTest(CompositeEntity container, String name)
      throws NameDuplicationException, IllegalActionException {
    super(container, name);

    search.setTypeEquals(BaseType.STRING);
    // searchMatch.setTypeEquals(BaseType.STRING);
    resultsOutput.setTypeEquals(BaseType.STRING);
  }
Ejemplo n.º 2
0
  /**
   * Initializes the NocMapper
   *
   * @throws NameDuplicationException
   * @throws IllegalActionException
   */
  public NocMapper(CompositeEntity container, String name)
      throws IllegalActionException, NameDuplicationException {
    super(container, name);

    // Create ports
    input = new TypedIOPort(this, "input", true, false);
    input.setTypeEquals(BaseType.GENERAL);
    output = new TypedIOPort(this, "output", false, true);
    output.setMultiport(true);
    output.setTypeEquals(BaseType.GENERAL);
  }
Ejemplo n.º 3
0
  public ScramblerRx(TypedCompositeActor container, String name)
      throws NameDuplicationException, IllegalActionException {
    super(container, name);

    input = new TypedIOPort(this, "input", true, false);
    input.setTypeEquals(ObjectToken.class);

    output = new TypedIOPort(this, "output", false, true);
    output.setTypeEquals(ObjectToken.class);

    LS0Bytes = new Parameter(this, "LS0Bytes", new IntToken(8));
    LS0Map = new Parameter(this, "LS0Map", new BooleanToken(false));

    S = new Parameter(this, "S", new IntToken(1));
  }
Ejemplo n.º 4
0
  public Dispatcher(CompositeEntity container, String name)
      throws NameDuplicationException, IllegalActionException {

    super(container, name);

    input = new TypedIOPort(this, "input", true, false);
    input.setTypeEquals(BaseType.GENERAL);

    queueUpdate = new TypedIOPort(this, "update", true, false);
    queueUpdate.setMultiport(true);

    output = new TypedIOPort(this, "output", false, true);
    output.setMultiport(true);
    output.setTypeEquals(BaseType.GENERAL);
  }
Ejemplo n.º 5
0
 private void setChannel(int channel) throws IllegalActionException {
   waitTime = getDirector().getModelTime();
   System.out.println("SETTING CHANNEL: " + channel + " at " + waitTime);
   channelOutput.setTypeEquals(BaseType.INT);
   channelOutput.send(0, new IntToken(channel));
   currentChannel = channel;
 }
  /**
   * Initialize particle filter parameters.
   *
   * @exception IllegalActionException
   * @exception NameDuplicationException
   */
  private void _init() throws IllegalActionException, NameDuplicationException {

    StringToken[] stateNames = new StringToken[2];
    stateNames[0] = new StringToken("x");
    stateNames[1] = new StringToken("y");
    stateVariableNames.setToken(new ArrayToken(BaseType.STRING, stateNames));
    stateVariableNames.setVisibility(Settable.EXPERT);

    observerPosition = new PortParameter(this, "observerPosition");
    observerPosition.setExpression("{0.0,0.0}");
    SingletonParameter showName =
        (SingletonParameter) observerPosition.getPort().getAttribute("_showName");
    if (showName == null) {
      showName = new SingletonParameter(observerPosition.getPort(), "_showName");
      showName.setToken("true");
    } else {
      showName.setToken("true");
    }

    // The input port for range measurements.
    z_m = new TypedIOPort(this, "z_m", true, false);
    z_m.setTypeEquals(BaseType.DOUBLE);
    showName = (SingletonParameter) z_m.getAttribute("_showName");
    z_m.setDisplayName("rangeMeasurement");
    if (showName == null) {
      showName = new SingletonParameter(z_m, "_showName");
      showName.setToken("true");
    } else {
      showName.setToken("true");
    }

    // The parameter that contains the measurement expression.
    z = new Parameter(this, "z");
    z.setExpression("sqrt((x-observerPosition(0))^2 + (y-observerPosition(1))^2)");
    z.setVisibility(Settable.EXPERT);

    x_update = new Parameter(this, "x_update");
    x_update.setExpression("x");

    y_update = new Parameter(this, "y_update");
    y_update.setExpression("y");

    measurementCovariance.setExpression("[2.0]");
    prior.setExpression("{random()*200-100,random()*200-100}");

    processNoise.setExpression("multivariateGaussian({0.0,0.0},[3.0,0.0;0.0,3.0])");

    particleCount.setExpression("2000");

    bootstrap.setVisibility(Settable.EXPERT);
    lowVarianceSampler.setVisibility(Settable.EXPERT);
  }
Ejemplo n.º 7
0
  public void initialize() throws IllegalActionException {

    nqueues =
        queueUpdate
            .getWidth(); // initialises number of queues by checking how many channels link to
    // queueUpdate port
    queues = new int[nqueues];
    for (int i = 0; i < nqueues; i++) {
      queues[i] = 0;
    }

    output.setTypeEquals(input.getType());
  }
Ejemplo n.º 8
0
  /**
   * Override the base class to set type constraints between the output ports and parameters of this
   * actor whose name matches the output port. If there is no such parameter, then create an
   * instance of Variable with a matching name and set up the type constraints to that instance. The
   * type of the output port is constrained to be at least that of the parameter or variable.
   *
   * @exception IllegalActionException If there is no director, or if the director's preinitialize()
   *     method throws it, or if this actor is not opaque.
   */
  public void preinitialize() throws IllegalActionException {
    super.preinitialize();

    Iterator ports = outputPortList().iterator();

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

      // Ensure that the production rate is one.
      // FIXME: This may not be right if there is no
      // actual source of data for this port (e.g. no
      // SetVariable actor).
      Variable rate = (Variable) port.getAttribute("tokenProductionRate");

      if (rate == null) {
        try {
          rate = new Variable(port, "tokenProductionRate");
        } catch (NameDuplicationException e) {
          throw new InternalErrorException(e);
        }
      }

      rate.setToken(new IntToken(1));

      String portName = port.getName();
      Attribute attribute = getAttribute(portName);

      if (attribute == null) {
        try {
          workspace().getWriteAccess();
          attribute = new Variable(this, portName);
        } catch (NameDuplicationException ex) {
          throw new InternalErrorException(ex);
        } finally {
          workspace().doneWriting();
        }
      }

      // attribute is now assured to be non-null.
      if (attribute instanceof Variable) {
        port.setTypeAtLeast((Variable) attribute);
      } else {
        // Assume the port type must be a string.
        port.setTypeEquals(BaseType.STRING);
      }
    }
  }
Ejemplo n.º 9
0
  /**
   * Add a new port.
   *
   * @param aPortName name of new port
   * @param aPortType Type of new port
   * @throws IllegalActionException When bad things happen.
   */
  void initializePort(String aPortName, Type aPortType) throws IllegalActionException {
    try {
      String columnName = aPortName.trim();
      // Create a new port for each Column in the resultset
      TypedIOPort port = (TypedIOPort) this.getPort(columnName);
      boolean aIsNew = (port == null);
      if (aIsNew) {
        // Create a new typed port and add it to this container
        port = new TypedIOPort(this, columnName, false, true);
        new ptolemy.kernel.util.Attribute(port, "_showName");
        log.debug("Creating port [" + columnName + "]" + this);
      }
      port.setTypeEquals(aPortType);

    } catch (ptolemy.kernel.util.NameDuplicationException nde) {
      throw new IllegalActionException(
          "One or more attributes has the same name.  Please correct this and try again.");
    }
  }
Ejemplo n.º 10
0
  /**
   * For each Argument, a port of the same name is created, belonging to this argument.
   *
   * @exception IllegalActionException If there is a problem creating the ports.
   */
  public void createPorts() throws IllegalActionException {
    Iterator arguments = this.argumentsList().iterator();
    TypedIOPort port;

    while (arguments.hasNext()) {
      Argument argument = (Argument) arguments.next();
      port = (TypedIOPort) this.getPort(argument.getName());

      if (port == null) {
        if (argument.isReturn()) {
          try {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + "</port>");
            request.setUndoable(true);
            requestChange(request);

          } catch (Exception ex) {
            throw new IllegalActionException(
                this,
                ex,
                "Unable to construct port " + "port for argument \"" + argument.getName() + "\"");
          }
        } else if (argument.isInput() && argument.isOutput()) {
          try {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<group>\n"
                        + " <port name=\""
                        + argument.getName()
                        + "in"
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"input\"/>\n"
                        + " </port>\n"
                        + " <port name=\""
                        + argument.getName()
                        + "out"
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + " </port>\n"
                        + "</group>");
            request.setUndoable(true);
            requestChange(request);
          } catch (Exception ex) {
            throw new IllegalActionException(
                this,
                ex,
                "Unable to construct "
                    + "input or output "
                    + "port for argument \""
                    + argument.getName()
                    + "\"");
          }
        } else {
          try {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + (argument.isInput() ? "    <property name=\"input\"/>\n" : "")
                        + (argument.isOutput() ? "    <property name=\"output\"/>\n" : "")
                        + "</port>");
            request.setUndoable(true);
            requestChange(request);
          } catch (Exception ex) {
            throw new IllegalActionException(
                this,
                ex,
                "Unable to construct " + "port for argument \"" + argument.getName() + "\"");
          }
        }
      } else {

        // synchronized the arguments and the ports
        if (argument.isReturn()) {
          MoMLChangeRequest request =
              new MoMLChangeRequest(
                  this,
                  this,
                  "<port name=\""
                      + argument.getName()
                      + "\" class=\"ptolemy.actor.TypedIOPort\"\n"
                      + "    <property name=\"output\"/>\n"
                      + "</port>");
          request.setUndoable(true);
          requestChange(request);
        } else {
          MoMLChangeRequest request =
              new MoMLChangeRequest(
                  this,
                  this,
                  "<port name=\""
                      + argument.getName()
                      + "\" class=\"ptolemy.actor.TypedIOPort\"\n"
                      + "    <property name=\"input\"/>\n"
                      + "</port>");
          request.setUndoable(true);
          requestChange(request);
        }
      }
      port = (TypedIOPort) this.getPort(argument.getName());
      if (port != null) {
        port.setTypeEquals(BaseType.GENERAL);
      }
    }
  }