| 1 | package PIANOS.datastructures; |
| 2 | |
| 3 | import PIANOS.exceptions.*; |
| 4 | import PIANOS.datastructures.*; |
| 5 | |
| 6 | import java.util.*; |
| 7 | |
| 8 | /* |
| 9 | Note: The thing calling generaterFreqCode and generateGenCode |
| 10 | must add _dp to real constants. For example, "1.0_dp", not "1.0". |
| 11 | */ |
| 12 | |
| 13 | public class ContinuousUniformDistribution extends Distribution |
| 14 | { |
| 15 | public ContinuousUniformDistribution() |
| 16 | { |
| 17 | super(2); |
| 18 | super.parameterType[0] = 1; // real |
| 19 | super.parameterType[1] = 1; // real |
| 20 | } |
| 21 | |
| 22 | public ArrayList<String> getIntroduction() |
| 23 | { |
| 24 | ArrayList<String> result = new ArrayList<String>(); |
| 25 | result.add("EXTERNAL G05FAF"); |
| 26 | return result; |
| 27 | } |
| 28 | |
| 29 | public ArrayList<String> getFreqCode(String[] parameters) throws IllegalParametersException |
| 30 | { |
| 31 | // This is not done with NAG because it's a trivial calculation |
| 32 | // Parameters are: m, n, point, result |
| 33 | |
| 34 | if (parameters.length != 4) |
| 35 | { |
| 36 | throw new IllegalParametersException("Trying to use continuous uniform distribution with illegal parameters."); |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | The code we want to generate looks like this: |
| 41 | IF (point < m .OR. point > n) THEN |
| 42 | result = 0 |
| 43 | ELSE |
| 44 | result = 1 / (n - (m)) |
| 45 | END IF |
| 46 | */ |
| 47 | |
| 48 | ArrayList<String> result = new ArrayList<String>(); |
| 49 | |
| 50 | result.add("IF (" + parameters[2] + " < " + parameters[0] + " .OR. " + |
| 51 | parameters[2] + " > " + parameters[1] + ") THEN"); |
| 52 | result.add(parameters[3] + " = 0"); |
| 53 | result.add("ELSE"); |
| 54 | result.add(parameters[3] + " = 1.0 / (" + parameters[1] + " - (" + parameters[0] + "))"); |
| 55 | result.add("END IF"); |
| 56 | |
| 57 | return result; |
| 58 | } |
| 59 | |
| 60 | public ArrayList<String> getGenCode(String[] parameters) throws IllegalParametersException |
| 61 | { |
| 62 | // Parameters are: m, n, result |
| 63 | |
| 64 | if (parameters.length != 3) |
| 65 | { |
| 66 | throw new IllegalParametersException("Trying to use continuous uniform distribution with illegal parameters."); |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | The code we want to generate looks like this: |
| 71 | CALL G05FAF(m, n, SIZE(result), result) |
| 72 | */ |
| 73 | |
| 74 | ArrayList<String> result = new ArrayList<String>(); |
| 75 | |
| 76 | result.add("CALL G05FAF(" + parameters[0] + ", " + parameters[1] + |
| 77 | ", SIZE(" + parameters[2] + "), " + parameters[2] + ")"); |
| 78 | |
| 79 | return result; |
| 80 | } |
| 81 | } |