PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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