/farmR/src/java/src/jfm/mou/ObjectiveU.java

https://code.google.com/p/javawfm/ · Java · 83 lines · 48 code · 8 blank · 27 comment · 5 complexity · 120771800237ec9d4238a3f976749f57 MD5 · raw file

  1. /**
  2. *
  3. */
  4. package jfm.mou;
  5. import jfm.model.Types;
  6. /** Data container for farmer survey data relating to a single objective.
  7. * There is a one to one mapping
  8. * between this objective and an objective that is actually implemented in the model */
  9. public class ObjectiveU {
  10. private final double min;
  11. private final double max;
  12. public final double slope;
  13. public final double rawWeight;
  14. // --- FOR CURVED --- //
  15. public boolean isCurved=false;
  16. public boolean replacesObjective=false;
  17. private double[] xVals=null;
  18. private double[] yVals=null;
  19. /** Slopes of the satisfaction curve on each segment */
  20. public final Types.ObjectiveType type;
  21. public final String units;
  22. ObjectiveU(Types.ObjectiveType type_,String units_,double min_,double max_,double rw){
  23. max=max_;
  24. min=min_;
  25. type=type_;
  26. units=units_;
  27. rawWeight=rw;
  28. slope=100/(max-min);
  29. }
  30. public void setCurve(double[] x,double[] y){
  31. xVals=x;
  32. yVals=y;
  33. isCurved=true;
  34. replacesObjective=true;
  35. }
  36. public double[] xVals(){
  37. if ( xVals!=null){
  38. return xVals;
  39. } else {
  40. throw new Error("x Vals is null");
  41. }
  42. }
  43. public double[] yVals(){
  44. if ( yVals!=null){
  45. return yVals;
  46. } else {
  47. throw new Error("Yvals is null");
  48. }
  49. };
  50. public double slope(){
  51. if ( isCurved ){
  52. throw new Error("Slope is not a valid quantity for curved Objectives");
  53. }
  54. return slope;
  55. };
  56. // -- UNUSED STUFF FOR PIECEWISE LINEAR OBJECTIVES --//
  57. /** Points on the satisfaction curve which maps natural units for the objective onto satisfaction
  58. * units */
  59. // private final List<Double> xVals = new ArrayList<Double>();
  60. // private final List<Double> yVals = new ArrayList<Double>();
  61. // private final List<Double> segmentSlopes = new ArrayList<Double>();
  62. /** Based on the points in the satisfaction vs objective value curve we work out the conversion
  63. * rate between the units of this objective and satisfaction */
  64. /* private void calculateSlopes(){
  65. if ( xVals.size()!= yVals.size()){
  66. throw new Error("xVals and yVals must have equal numbers of elements");
  67. }
  68. for ( int i=1;i<xVals.size();i++){
  69. double xdiff=xVals.get(i)-xVals.get(i-1);
  70. double ydiff=yVals.get(i)-yVals.get(i-1);
  71. segmentSlopes.add(ydiff/xdiff);
  72. }
  73. }
  74. */
  75. }