/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

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