001/* A PN process actor object.
002
003 Copyright (c) 1999-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.domains.pn.demo.QR;
029
030import java.util.Vector;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.TypedIOPort;
034import ptolemy.data.DoubleToken;
035import ptolemy.data.IntToken;
036import ptolemy.data.expr.Parameter;
037import ptolemy.data.type.BaseType;
038import ptolemy.kernel.CompositeEntity;
039import ptolemy.kernel.util.IllegalActionException;
040import ptolemy.kernel.util.NameDuplicationException;
041
042///////////////////////////////////////////////////////////////////
043//// ND_5
044
045/**
046
047 This class defines a PN actor object. This actor is automatically
048 generated, as part of the <A
049 HREF="http://www.gigascale.org/compaan">Compaan</A> project. Although
050 most of the actor is generated automatically, some parts have been
051 manually tuned for this demo especially when reading and writing of
052 matrices is involved; they may change in future releases.
053
054 @author Bart Kienhuis
055 @version $Id$
056 @since Ptolemy II 1.0
057 @Pt.ProposedRating Red (kienhuis)
058 @Pt.AcceptedRating Red (kienhuis)
059 */
060public class ND_5 extends TypedAtomicActor {
061    /** Construct an actor that is an SBF object with the given container
062     *  and name.
063     *  @param container The container.
064     *  @param name The name of this actor.
065     *  @exception IllegalActionException If the actor cannot be contained
066     *   by the proposed container.
067     *  @exception NameDuplicationException If the container already has an
068     *   actor with this name.
069     */
070    public ND_5(CompositeEntity container, String name)
071            throws IllegalActionException, NameDuplicationException {
072        super(container, name);
073
074        RP_11 = new TypedIOPort(this, "RP_11", true, false);
075        RP_12 = new TypedIOPort(this, "RP_12", true, false);
076
077        // Manually added
078        out = new TypedIOPort(this, "out0", false, true);
079
080        RP_11.setTypeEquals(BaseType.DOUBLE);
081        RP_12.setTypeEquals(BaseType.DOUBLE);
082
083        out.setTypeEquals(BaseType.DOUBLE);
084
085        // The Type of these Parameters is set by the First
086        // Token placed in the parameters when created.
087        parameter_N = new Parameter(this, "N", new IntToken(6));
088        parameter_K = new Parameter(this, "K", new IntToken(6));
089    }
090
091    ///////////////////////////////////////////////////////////////////
092    ////                     ports and parameters                  ////
093    // -- Part of the Actor
094    public TypedIOPort RP_11;
095
096    public TypedIOPort RP_12;
097
098    // Manually Added.
099    public TypedIOPort out;
100
101    // -- Public interface of the Actor
102    public Parameter parameter_N;
103
104    public Parameter parameter_K;
105
106    ///////////////////////////////////////////////////////////////////
107    ////                         public methods                    ////
108
109    /** Initialize the PN actor.
110     *  @exception IllegalActionException If the parent class throws it.
111     */
112    @Override
113    public void initialize() throws IllegalActionException {
114        super.initialize();
115        //_returnValue = true;
116
117        // Get the correct value from the parameters
118        N = ((IntToken) parameter_N.getToken()).intValue();
119        // FIXME: Why ignore this?
120        /*K = */((IntToken) parameter_K.getToken()).intValue();
121    }
122
123    /** Fire the actor.
124     *  @exception IllegalActionException If there is no director.
125     */
126    @Override
127    public void fire() throws IllegalActionException {
128        super.fire();
129        for (int j = 1; j <= 1 * N; j += 1) {
130            for (int i = 1 * j; i <= 1 * N; i += 1) {
131                if (-i + j == 0) {
132                    r_2.add(Double.valueOf(
133                            ((DoubleToken) RP_11.get(0)).doubleValue()));
134                    in_0 = ((Double) r_2.elementAt(w_r_2++)).doubleValue();
135                }
136
137                if (i - j - 1 >= 0) {
138                    r_3.add(Double.valueOf(
139                            ((DoubleToken) RP_12.get(0)).doubleValue()));
140                    in_0 = ((Double) r_3.elementAt(w_r_3++)).doubleValue();
141                }
142
143                _debug(" Broadcast from ND_5: " + in_0);
144
145                // Manually added
146                out.broadcast(new DoubleToken(in_0));
147            }
148        }
149    }
150
151    /** Post fire the actor. Return false to indicated that the
152     *  process has finished. If it returns true, the process will
153     *  continue indefinitely.
154     *  @exception IllegalActionException If thrown by the parent
155     *  class.
156     */
157    @Override
158    public boolean postfire() throws IllegalActionException {
159        // We intentially ignore the return value of super.postfire()
160        // here.
161        super.postfire();
162        return true;
163    }
164
165    ///////////////////////////////////////////////////////////////////
166    ////                         private variables                 ////
167    // -- Get private copies of the parameters
168    private int N;
169
170    //private int K;
171
172    private double in_0;
173
174    //private double out_0;
175
176    private Vector r_2 = new Vector();
177
178    private Vector r_3 = new Vector();
179
180    private int w_r_2 = 0;
181
182    private int w_r_3 = 0;
183
184    //private boolean _returnValue = true;
185}