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_4 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_4 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_4(CompositeEntity container, String name) 071 throws IllegalActionException, NameDuplicationException { 072 super(container, name); 073 074 RP_5 = new TypedIOPort(this, "RP_5", true, false); 075 RP_6 = new TypedIOPort(this, "RP_6", true, false); 076 RP_7 = new TypedIOPort(this, "RP_7", true, false); 077 RP_8 = new TypedIOPort(this, "RP_8", true, false); 078 RP_9 = new TypedIOPort(this, "RP_9", true, false); 079 RP_10 = new TypedIOPort(this, "RP_10", true, false); 080 081 WP_5 = new TypedIOPort(this, "WP_5", false, true); 082 WP_12 = new TypedIOPort(this, "WP_12", false, true); 083 WP_3 = new TypedIOPort(this, "WP_3", false, true); 084 WP_7 = new TypedIOPort(this, "WP_7", false, true); 085 WP_9 = new TypedIOPort(this, "WP_9", false, true); 086 087 RP_5.setTypeEquals(BaseType.DOUBLE); 088 RP_6.setTypeEquals(BaseType.DOUBLE); 089 RP_7.setTypeEquals(BaseType.DOUBLE); 090 RP_8.setTypeEquals(BaseType.DOUBLE); 091 RP_9.setTypeEquals(BaseType.DOUBLE); 092 RP_10.setTypeEquals(BaseType.DOUBLE); 093 094 WP_5.setTypeEquals(BaseType.DOUBLE); 095 WP_12.setTypeEquals(BaseType.DOUBLE); 096 WP_3.setTypeEquals(BaseType.DOUBLE); 097 WP_7.setTypeEquals(BaseType.DOUBLE); 098 WP_9.setTypeEquals(BaseType.DOUBLE); 099 100 // The Type of these Parameters is set by the First 101 // Token placed in the parameters when created. 102 parameter_N = new Parameter(this, "N", new IntToken(6)); 103 parameter_K = new Parameter(this, "K", new IntToken(6)); 104 } 105 106 /////////////////////////////////////////////////////////////////// 107 //// ports and parameters //// 108 // -- Part of the Actor 109 public TypedIOPort RP_5; 110 111 public TypedIOPort RP_6; 112 113 public TypedIOPort RP_7; 114 115 public TypedIOPort RP_8; 116 117 public TypedIOPort RP_9; 118 119 public TypedIOPort RP_10; 120 121 public TypedIOPort WP_5; 122 123 public TypedIOPort WP_12; 124 125 public TypedIOPort WP_3; 126 127 public TypedIOPort WP_7; 128 129 public TypedIOPort WP_9; 130 131 // -- Public interface of the Actor 132 public Parameter parameter_N; 133 134 public Parameter parameter_K; 135 136 /////////////////////////////////////////////////////////////////// 137 //// public methods //// 138 139 /** Initialize the PN actor. 140 * @exception IllegalActionException If the parent class throws it. 141 */ 142 @Override 143 public void initialize() throws IllegalActionException { 144 super.initialize(); 145 //_returnValue = true; 146 147 // Get the correct value from the parameters 148 N = ((IntToken) parameter_N.getToken()).intValue(); 149 K = ((IntToken) parameter_K.getToken()).intValue(); 150 } 151 152 /** Fire the actor. 153 * @exception IllegalActionException If there is no director. 154 */ 155 @Override 156 public void fire() throws IllegalActionException { 157 super.fire(); 158 for (int k = 1; k <= 1 * K; k += 1) { 159 for (int j = 1; j <= 1 * N + -1; j += 1) { 160 for (int i = 1 * j + 1; i <= 1 * N; i += 1) { 161 if (k - 2 >= 0) { 162 r_3.add(Double.valueOf( 163 ((DoubleToken) RP_5.get(0)).doubleValue())); 164 in_0 = ((Double) r_3.elementAt(w_r_3++)).doubleValue(); 165 } 166 167 if (k - 1 == 0) { 168 r_1.add(Double.valueOf( 169 ((DoubleToken) RP_6.get(0)).doubleValue())); 170 in_0 = ((Double) r_1.elementAt(w_r_1++)).doubleValue(); 171 } 172 173 if (j - 2 >= 0) { 174 x_3.add(Double.valueOf( 175 ((DoubleToken) RP_7.get(0)).doubleValue())); 176 in_1 = ((Double) x_3.elementAt(w_x_3++)).doubleValue(); 177 } 178 179 if (j - 1 == 0) { 180 x_1.add(Double.valueOf( 181 ((DoubleToken) RP_8.get(0)).doubleValue())); 182 in_1 = ((Double) x_1.elementAt(w_x_1++)).doubleValue(); 183 } 184 185 if (i - j - 2 >= 0) { 186 t_2.add(Double.valueOf( 187 ((DoubleToken) RP_9.get(0)).doubleValue())); 188 in_2 = ((Double) t_2.elementAt(w_t_2++)).doubleValue(); 189 } 190 191 if (-i + j + 1 == 0) { 192 t_1.add(Double.valueOf( 193 ((DoubleToken) RP_10.get(0)).doubleValue())); 194 in_2 = ((Double) t_1.elementAt(w_t_1++)).doubleValue(); 195 } 196 197 _Rotate(in_0, in_1, in_2); 198 out_0 = _argOut0; 199 out_1 = _argOut1; 200 out_2 = _argOut2; 201 202 if (K - k - 1 >= 0) { 203 WP_5.broadcast(new DoubleToken(out_0)); 204 } 205 206 if (-K + k == 0) { 207 WP_12.broadcast(new DoubleToken(out_0)); 208 } 209 210 if (-i + j + 1 == 0) { 211 WP_3.broadcast(new DoubleToken(out_1)); 212 } 213 214 if (i - j - 2 >= 0) { 215 WP_7.broadcast(new DoubleToken(out_1)); 216 } 217 218 if (N - i - 1 >= 0) { 219 WP_9.broadcast(new DoubleToken(out_2)); 220 } 221 } 222 } 223 } 224 } 225 226 /** Post fire the actor. Return false to indicated that the 227 * process has finished. If it returns true, the process will 228 * continue indefinitely. 229 */ 230 @Override 231 public boolean postfire() { 232 return false; 233 } 234 235 /////////////////////////////////////////////////////////////////// 236 //// private methods //// 237 private void _Rotate(double arg0, double arg1, double arg2) { 238 _argOut0 = Math.cos(arg2) * arg0 - Math.sin(arg2) * arg1; 239 _argOut1 = Math.sin(arg2) * arg0 + Math.cos(arg2) * arg1; 240 _argOut2 = arg2; 241 } 242 243 /////////////////////////////////////////////////////////////////// 244 //// private variables //// 245 // -- Get private copies of the parameters 246 private int N; 247 248 private int K; 249 250 private double in_0; 251 252 private double in_1; 253 254 private double in_2; 255 256 private double out_0; 257 258 private double out_1; 259 260 private double out_2; 261 262 // Needed to communicate results from the function 263 private double _argOut0; 264 265 private double _argOut1; 266 267 private double _argOut2; 268 269 private Vector r_3 = new Vector(); 270 271 private Vector r_1 = new Vector(); 272 273 private Vector x_3 = new Vector(); 274 275 private Vector x_1 = new Vector(); 276 277 private Vector t_2 = new Vector(); 278 279 private Vector t_1 = new Vector(); 280 281 private int w_r_3 = 0; 282 283 private int w_r_1 = 0; 284 285 private int w_x_3 = 0; 286 287 private int w_x_1 = 0; 288 289 private int w_t_2 = 0; 290 291 private int w_t_1 = 0; 292 293 //private boolean _returnValue = true; 294}