/** * Implements update() method * * @throws DAVEException */ public void update() throws DAVEException { int numInputs; Iterator<Signal> theInputs; Signal theInput; double[] iwv; // index and weights vector int[] iv; // index vector int index = 0; boolean ready = true; boolean verbose = this.isVerbose(); if (verbose) { System.out.println(); System.out.println("Entering update method for function '" + this.getName() + "'"); } // sanity check to see if number of inputs matches our dimensionality numInputs = this.inputs.size(); if (numInputs != this.functionTableDef.numDim()) throw new DAVEException( "Number of inputs doesn't match function dimensions in '" + this.getName() + "'"); // see if each input variable is ready theInputs = this.inputs.iterator(); iwv = new double[numInputs]; // index and weights vector iv = new int[numInputs]; // index vector if (verbose) System.out.println(" Allocated index-and-weights vector of size " + this.inputs.size()); // Here to do table lookup while (theInputs.hasNext()) { theInput = theInputs.next(); if (!theInput.sourceReady()) { ready = false; if (verbose) System.out.println(" Upstream signal '" + theInput.getName() + "' is not ready."); iwv[index] = 0.0; iv[index] = 0; } else { iwv[index] = theInput.sourceValue(); iv[index] = (int) theInput.sourceValue(); if (verbose) System.out.println(" Input # " + index + " value is " + iwv[index]); } index++; } if (!ready) return; // At this point we have the index-and-weights vector in iwv. // Call recursive interpolation routine this.value = this.interpolate(iwv, iv, numInputs); if (verbose) System.out.println(" Interpolate returned value " + this.value); // record current cycle counter resultsCycleCount = ourModel.getCycleCounter(); }
/** * Implements update() method * * <p>Passes input 0 if input 1 > 0.; otherwise passes input 2 to output * * @throws DAVEException */ public void update() throws DAVEException { int numInputs; Iterator<Signal> theInputs; Signal theInput; double[] theInputValue; int index = 0; int requiredInputs = 3; boolean verbose = this.isVerbose(); if (verbose) { System.out.println(); System.out.println("Entering update method for switch '" + this.getName() + "'"); } // sanity check to see if we have exact number of inputs numInputs = this.inputs.size(); if (numInputs != requiredInputs) { throw new DAVEException( "Number of inputs to '" + this.getName() + "' wrong - should be " + requiredInputs + "."); } // allocate memory for the input values theInputValue = new double[requiredInputs]; // see if each input variable is ready theInputs = this.inputs.iterator(); while (theInputs.hasNext()) { theInput = theInputs.next(); if (!theInput.sourceReady()) { if (verbose) { System.out.println(" Upstream signal '" + theInput.getName() + "' is not ready."); } return; } else { theInputValue[index] = theInput.sourceValue(); } index++; } // Calculate our output this.value = theInputValue[2]; if (Math.abs(theInputValue[1]) > 0.0001) // choose input 3 if input 2 non-zero { this.value = theInputValue[0]; } // record current cycle counter resultsCycleCount = ourModel.getCycleCounter(); }
/** * Implements update() method * * @throws DAVEException */ public void update() throws DAVEException { int numInputs; Iterator<Signal> theInputs; Signal theInput; double[] theInputValue; int index = 0; int requiredInputs = 2; boolean verbose = this.isVerbose(); if (verbose) { System.out.println(); System.out.println("Entering update method for function '" + this.getName() + "'"); } // sanity check to see if we have exact number of inputs numInputs = this.inputs.size(); if (numInputs != requiredInputs) throw new DAVEException( "Number of inputs to '" + this.getName() + "' wrong - should be " + requiredInputs + "."); // allocate memory for the input values theInputValue = new double[requiredInputs]; // see if each input variable is ready theInputs = this.inputs.iterator(); while (theInputs.hasNext()) { theInput = theInputs.next(); if (!theInput.sourceReady()) { if (verbose) System.out.println(" Upstream signal '" + theInput.getName() + "' is not ready."); return; } else { theInputValue[index] = theInput.sourceValue(); } index++; } // Calculate our output this.value = Double.NaN; switch (this.relation) { case LT: if (theInputValue[0] < theInputValue[1]) this.value = 1.0; else this.value = 0.0; break; case LEQ: if (theInputValue[0] <= theInputValue[1]) this.value = 1.0; else this.value = 0.0; break; case EQ: if (theInputValue[0] == theInputValue[1]) this.value = 1.0; else this.value = 0.0; break; case GEQ: if (theInputValue[0] >= theInputValue[1]) this.value = 1.0; else this.value = 0.0; break; case GT: if (theInputValue[0] > theInputValue[1]) this.value = 1.0; else this.value = 0.0; break; case NEQ: if (theInputValue[0] != theInputValue[1]) this.value = 1.0; else this.value = 0.0; break; } if (this.value == Double.NaN) throw new DAVEException( "Unrecognized operator " + this.relationOp + " in block " + this.getName()); // record current cycle counter resultsCycleCount = ourModel.getCycleCounter(); }