It sounds to me like what you are doing is attempting to run a model through some complete execution in each state. Indeed, it is awkward to do that using the 3.0.2 or earlier infrastructure.

We are working on making this much easier.  One part of the solution
is the SetVariable actor (attached) which sets or creates a parameter
in its container and sets the value to the value of its input.

A more comprehensive solution also involves flow of control.

I'm working on two actors that will solve this problem:

ModelReference

This has a FileAttribute pointing to a MoML file defining a model, and
when it fires, it executes the model completely, start to finish.
Input ports on ModelReference are used to set parameter values
of the destination model (by name matching), and output ports
are used to retrieve parameter values.

RunCompositeActor

This is similar, except that instead of referring to another
MoML file, it contains the model to be executed within it.

These are very much in progress, not really ready for prime
time, but I would be happy to share them when they are ready...

Edward


At 11:49 AM 8/28/2003 +0200, Michail Chavkin (sgraja) wrote:


Hi,

While in the "setActions" field of a transition in FSM models one can
use ahierarchical destination (like state.parameter or even
state.actor.parameter) it is impossible to use a hierarchical source.
Sometimes it just causes an
inconvinience of having a doubling parameter in the top model (i.e. it
is impossible to write state.parameter=state.parameter + 1, one ought to

have  Parameter in the top model, e.g. TopPar, first increment it,
TopPar=TopPar+1, and when set, state.parameter=TopPar).

But there are more serious drawbacks, because of this.
As an output of my SDF refinement all I needed was the final result of
the simultaion. I wanted to use a Recorder actor in that refinement to
be
able to access the final result in the top model by setting the source
in the
"setActions" field to be something like: "state.Recorder.getLatest(0)".
This does not work, the message I got was that "state ID is not known".

Therefore I have two questions.

First, whether the possibility to use a
hierarchical source is going to be implemented. This was one of the
issues of a message sent to the list two years ago. You can find it here

http://groups.yahoo.com/group/ptolemy-hackers/message/1722

Second, maybe, somebody could
advice another way to get only the last result of a refinement (with an
SDF director in it with vectorization factor set not to 1)

Thanks,

Michail Chavkin






---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]

------------ Edward A. Lee, Professor 518 Cory Hall, UC Berkeley, Berkeley, CA 94720 phone: 510-642-0455, fax: 510-642-2739 [EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal
/* Set the value of a variable contained by the container.

 Copyright (c) 1998-2003 The Regents of the University of California.
 All rights reserved.
 Permission is hereby granted, without written agreement and without
 license or royalty fees, to use, copy, modify, and distribute this
 software and its documentation for any purpose, provided that the above
 copyright notice and the following two paragraphs appear in all copies
 of this software.

 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
 ENHANCEMENTS, OR MODIFICATIONS.

                                        PT_COPYRIGHT_VERSION_2
                                        COPYRIGHTENDKEY

@ProposedRating Red ([EMAIL PROTECTED])
@AcceptedRating Red ([EMAIL PROTECTED])
*/

package ptolemy.actor.lib;

import ptolemy.actor.TypedAtomicActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.Token;
import ptolemy.data.expr.Variable;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.ChangeListener;
import ptolemy.kernel.util.ChangeRequest;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.NamedObj;
import ptolemy.kernel.util.StringAttribute;

//////////////////////////////////////////////////////////////////////////
//// SetVariable
/**
Set the value of a variable contained by the container.
The change to the value of the variable is implemented in a
change request, and consequently will not take hold until the
end of the current iteration.  This helps ensure that users
of value of the variable will see changes to the value
deterministically (independent of the schedule of execution
of the actors).
<p>
Note that the variable name is observed during preinitialize().
If it is changed after that, the change will not take effect
until the next time the model is executed.

@author Edward A. Lee
@version $Id: SetVariable.java,v 1.1 2003/05/22 19:49:23 eal Exp $
*/

public class SetVariable extends TypedAtomicActor implements ChangeListener {

    /** Construct an actor with the given container and name.
     *  @param container The container.
     *  @param name The name of this actor.
     *  @exception IllegalActionException If this actor cannot be contained
     *   by the proposed container.
     *  @exception NameDuplicationException If the container already has an
     *   actor with this name.
     */
    public SetVariable(CompositeEntity container, String name)
        throws NameDuplicationException, IllegalActionException {
        super(container, name);

        input = new TypedIOPort(this, "input", true, false);

        variableName = new StringAttribute(this, "variableName");
        variableName.setExpression("parameter");
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    /** The input port. */
    public TypedIOPort input;

    /** The name of the variable in the container to set. */
    public StringAttribute variableName;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    /** Do nothing.
     *  @param change The change that executed. 
     */
    public void changeExecuted(ChangeRequest change) {
    }

    /** React to the fact that a change failed by setting a flag
     *  that causes an exception to be thrown in next call to prefire()
     *  or wrapup().
     *  @param change The change request.
     *  @param exception The exception that resulted.
     */
    public void changeFailed(
            ChangeRequest change,
            java.lang.Exception exception) {
        // FIXME
        System.out.println(exception.toString());
    }

    /** Read at most one token from the input port and issue a change
     *  request to update variables as indicated by the input.
     *  @exception IllegalActionException If thrown reading the input.
     */
    public boolean postfire() throws IllegalActionException {
        if (input.hasToken(0)) {
            final Token value = input.get(0);
            final NamedObj container = (NamedObj) getContainer();
            ChangeRequest request =
                new ChangeRequest(this, "SetVariable change request") {
                protected void _execute() throws IllegalActionException {
                    Variable variable =
                        (Variable) container.getAttribute(
                            _variableName,
                            Variable.class);
                    variable.setToken(value);
                    // NOTE: If we don't call validate(), then the
                    // change will not propagate to dependents.
                    variable.validate();
                }
            };
            // To prevent prompting for saving the model, mark this
            // change as non-persistent.
            request.setPersistent(false);
            request.addChangeListener(this);
            requestChange(request);
        }
        return true;
    }

    /** If there is no variable with the specified name, then create one.
     *  This is done in preinitialize() so that we can set up a type
     *  constraint that ensures that the variable and the input port
     *  have the same type.
     *  @exception IllegalActionException If the superclass throws it,
     *   or if there is no container.
     */
    public void preinitialize() throws IllegalActionException {
        super.preinitialize();
        NamedObj container = (NamedObj) getContainer();
        if (container == null) {
            throw new IllegalActionException(this, "No container.");
        }
        _variableName = variableName.getExpression();
        Variable variable =
            (Variable) container.getAttribute(_variableName, Variable.class);
        if (variable == null) {
            try {
                variable = new Variable(this, _variableName);
            } catch (NameDuplicationException ex) {
                throw new IllegalActionException(
                    this,
                    "Existing attribute that is not a Variable with specified name: "
                        + _variableName);
            }
        }
        variable.setTypeSameAs(input);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    // Name of the variable to set.
    private String _variableName;
}

Reply via email to