| 1 | package de.uka.ipd.sdq.measurement.strategies.activeresource.cpu; |
| 2 | |
| 3 | import de.uka.ipd.sdq.measurement.strategies.activeresource.AbstractDemandStrategy; |
| 4 | import de.uka.ipd.sdq.measurement.strategies.activeresource.ResourceTypeEnum; |
| 5 | import flanagan.complex.Complex; |
| 6 | import flanagan.math.FourierTransform; |
| 7 | |
| 8 | public class FFTDemand extends AbstractDemandStrategy { |
| 9 | |
| 10 | public FFTDemand() { |
| 11 | super(-1,-3,-5,262144,2); |
| 12 | } |
| 13 | |
| 14 | private void fft(int lengthOfDistFunc) { |
| 15 | Complex[] points = new Complex[lengthOfDistFunc]; |
| 16 | for (int i = 0; i < lengthOfDistFunc; i++) { |
| 17 | points[i] = new Complex(Math.random(), 0); |
| 18 | } |
| 19 | FourierTransform ft = new FourierTransform(points); |
| 20 | ft.transform(); |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | public void run(long initial) { |
| 25 | int length = (int)initial; |
| 26 | if (!FourierTransform.checkPowerOfTwo(length)) { |
| 27 | int next = FourierTransform.nextPowerOfTwo(length); |
| 28 | int last = FourierTransform.lastPowerOfTwo(length); |
| 29 | length = next - length > length - last || next > defaultIterationCount ? last : next; |
| 30 | } |
| 31 | fft(length); |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public ResourceTypeEnum getStrategysResource() { |
| 36 | return ResourceTypeEnum.CPU; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public String getName() { |
| 41 | return "FFT"; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void cleanup() { |
| 46 | // Do nothing. |
| 47 | } |
| 48 | } |