/* * TODO: this methods needs to be changed/removed; this will done by the SmartDevice class * mechanism which will be an Observer and get updated from aggregator (observable) * * This method receives the centralised value signal and stores it to the * Prosumer's memory. * * @param signal - the array containing the cost signal - one member per time tick * @param length - the length of the signal * @param validTime - the time (in ticks) from which the signal is valid */ public boolean receiveValueSignal(double[] signal, int length) { if (Consts.DEBUG) System.out.println("ProsumerAgent:: receiveValueSignal()"); boolean success = true; // Can only receive if we have a smart meter to receive data int validTime = (int) RepastEssentials.GetTickCount(); if (hasSmartMeter) { // Note the time from which the signal is valid. // Note - Repast can cope with fractions of a tick (a double is returned) // but I am assuming here we will deal in whole ticks and alter the resolution should we need int time = (int) RepastEssentials.GetTickCount(); int newSignalLength = length; setPredictionValidTime(validTime); double[] tempArray; int signalOffset = time - validTime; // if (Consts.DEBUG) System.out.println("time: "+time+ " validTime"+validTime); if (signalOffset != 0) { if (Consts.DEBUG) { if (Consts.DEBUG) System.out.println("ProsumerAgent: Signal valid from time other than current time"); } newSignalLength = newSignalLength - signalOffset; } if ((getPredictedCostSignal() == null) || (newSignalLength != predictedCostSignal.length)) { if (Consts.DEBUG) { if (Consts.DEBUG) System.out.println("ProsumerAgent: Re-defining length of signal in agent" + agentID); } setPredictedCostSignal(new double[newSignalLength]); } if (signalOffset < 0) { // This is a signal projected into the future. // pad the signal with copies of what was in it before and then add the new signal on System.arraycopy(signal, 0, getPredictedCostSignal(), 0 - signalOffset, length); } else { // This was valid from now or some point in the past. Copy in the portion that is still // valid and // then "wrap" the front bits round to the end of the array. System.arraycopy(signal, signalOffset, predictedCostSignal, 0, length); } } return success; }
public double getCurrentPrediction() { int timeSinceSigValid = (int) RepastEssentials.GetTickCount() - getPredictionValidTime(); if (predictedCostSignal.length > 0 && timeSinceSigValid >= 0) { return getPredictedCostSignal()[timeSinceSigValid % predictedCostSignal.length]; } else { return 0; } }
public double getUnadaptedDemand() { // Cope with tick count being null between project initialisation and start. int index = Math.max(((int) RepastEssentials.GetTickCount() % baseDemandProfile.length), 0); return (baseDemandProfile[index]) - currentGeneration(); }