PageRenderTime 27ms CodeModel.GetById 22ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/farmR/src/java/src/jfm/model/Rotation.java

https://code.google.com/p/javawfm/
Java | 46 lines | 29 code | 5 blank | 12 comment | 2 complexity | 7bc50a14c28cb02957e9280b24b05d76 MD5 | raw file
 1package jfm.model;
 2
 3import java.util.*;
 4
 5import jfm.model.Types.DiseaseType;
 6import jfm.model.Types.CropType;
 7
 8
 9
10/** Cost and yield penalties for rotating to a particular DiseaseType. 
11 * 
12 * This class defines the value of penalties for rotation from 
13 * any disease type to one in particular (many from .. single to ). The values of these 
14 * penalties are not specific to a particular period and therefore this class is not a 
15 * ModelPrimitive.  The equivalent ModelPrimitive class is RotationPenalty, which 
16 * defines the penalty in a particular period. The rotation penalties in the RotationPenalty class 
17 * are typically derived from those in this class
18 * 
19 * @author Ira Cooke */
20public final class Rotation {
21	private final Map<DiseaseType,double[]> rotPenalties=new HashMap<DiseaseType,double[]>();
22	private final Set<DiseaseType> forbiddenDiseases=new HashSet<DiseaseType>();
23	/** Each pair of numbers here is a yield penalty and a cost penalty in that order */
24	/** The disease class of the crop to which rotation is to */
25	public final CropType to;
26	public Rotation(CropType totype,Map<DiseaseType,double[]> rps,Set<DiseaseType> forbidden){
27		rotPenalties.putAll(Collections.unmodifiableMap(rps));
28		forbiddenDiseases.addAll(forbidden);
29		to=totype;
30	}
31	public double[] getPenalty(DiseaseType fromType){
32		if ( rotPenalties!=null){
33			if ( rotPenalties.containsKey(fromType)){
34				return rotPenalties.get(fromType);
35			} 
36		} 
37		double[] nocosts={0,0};
38		return nocosts;
39	}
40	public boolean isForbidden(DiseaseType dis){
41		return forbiddenDiseases.contains(dis);
42	}
43	public Rotation copy(){
44		return new Rotation(to,rotPenalties,forbiddenDiseases);
45	}
46}