PageRenderTime 25ms CodeModel.GetById 1ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/farmR/src/java/src/jfm/model/FieldMarginsComponent.java

https://code.google.com/p/javawfm/
Java | 109 lines | 63 code | 17 blank | 29 comment | 2 complexity | 6e9bf5ec14673ea2923c49bf6012fcf0 MD5 | raw file
  1/**
  2 * 
  3 */
  4package jfm.model;
  5
  6import java.util.HashSet;
  7import java.util.Set;
  8
  9import jfm.lp.ConstraintBuilder;
 10import jfm.lp.LPX;
 11import jfm.lp.MatrixElement;
 12import jfm.lp.MatrixRow;
 13import jfm.lp.MatrixVariable;
 14import jfm.lp.ModelComponent;
 15import jfm.lp.ModelComponent.MCType;
 16import jfm.model.Types.ELSCode;
 17import jfm.model.Types.ObjectiveType;
 18
 19/** For 2,4,and 6 m buffer strips.  Not yet implemented. Needs to have a cost that varies depending on crop. 
 20 * Should probably assume lowest gross margin crop and then implement constraints to ensure no more than available per crop
 21 * unit area.
 22 * 
 23 * @author iracooke
 24 *
 25 */
 26public class FieldMarginsComponent extends ELSOptionComponent {
 27	public static Set<ELSCode> elscodes = new HashSet<ELSCode>();
 28	static {
 29		elscodes.add(ELSCode.EE3);
 30		elscodes.add(ELSCode.EE2);
 31		elscodes.add(ELSCode.EF1);
 32	}
 33	
 34	public FieldMarginsComponent(double perhaEstablishmentCost,double perhaMaintenanceCost,double discountRate){ 
 35		super(ModelComponent.MCType.FIELDMARGINS);
 36		requireObjective(ObjectiveType.PROFIT);
 37		
 38		double perAreaCost= perhaEstablishmentCost*discountRate + perhaMaintenanceCost;
 39		
 40		options.put(ELSCode.EE3,new ELSOption(ELSCode.EE3,perAreaCost,ELSCode.EE3.defaultPoints));
 41		options.put(ELSCode.EE2,new ELSOption(ELSCode.EE2,perAreaCost,ELSCode.EE2.defaultPoints));
 42		options.put(ELSCode.EF1,new ELSOption(ELSCode.EF1,perAreaCost,ELSCode.EF1.defaultPoints));
 43		
 44
 45		
 46		
 47	}
 48	/* (non-Javadoc)
 49	 * @see jfm.lp.ModelComponent#copy()
 50	 */
 51	@Override
 52	public ModelComponent copy() {
 53		// TODO Auto-generated method stub
 54		return null;
 55	}
 56
 57	/* (non-Javadoc)
 58	 * @see jfm.lp.ModelComponent#initializeStructure()
 59	 */
 60	@Override
 61	protected void initializeStructure() throws BadModelException {
 62		for(ELSCode ecode:elscodes){
 63			MatrixVariable newVariable=new MatrixVariable(-options.get(ecode).costPerUnit,0.0,0.0,LPX.LPX_LO,LPX.LPX_CV,matrix.numCols(),ObjectiveType.PROFIT);
 64			newVariable.setTag(ecode.toString());	
 65			matrix.addVariable(newVariable);	
 66			options.get(ecode).registerVariable(newVariable, 0);
 67			options.get(ecode).registerParent(this);
 68		}
 69	}
 70
 71	/* (non-Javadoc)
 72	 * @see jfm.lp.ModelComponent#name()
 73	 */
 74	@Override
 75	protected String name() {
 76		// TODO Auto-generated method stub
 77		return null;
 78	}
 79
 80	/* (non-Javadoc)
 81	 * @see jfm.lp.ModelComponent#setFormulaVariables()
 82	 */
 83	@Override
 84	public void setFormulaVariables() {
 85		// TODO Auto-generated method stub
 86
 87	}
 88
 89	/* (non-Javadoc)
 90	 * @see jfm.lp.ModelComponent#updateStructure()
 91	 */
 92	@Override
 93	protected void updateStructure() {
 94		for(ELSOption op:options.values()){
 95			op.updateStructure(this);
 96		}
 97		structureUpdateDone();
 98	}
 99	
100	public final class FieldMarginsMaxAreaConstraint extends ConstraintBuilder {
101		public FieldMarginsMaxAreaConstraint(){
102			super(ConstraintBuilder.CBType.FIELDMARGINSMAXAREA,ModelComponent.MCType.FIELDMARGINS);
103		}
104		protected void build(){
105			// Not yet implemented
106		}
107	}
108
109}