PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/farmR/src/java/src/jfm/model/HedgerowLengthComponent.java

https://code.google.com/p/javawfm/
Java | 56 lines | 36 code | 8 blank | 12 comment | 2 complexity | 720fc5bc7bd4af32a64646f738acc02e MD5 | raw file
 1/**
 2 * 
 3 */
 4package jfm.model;
 5
 6import jfm.lp.ConstraintBuilder;
 7import jfm.lp.LPX;
 8import jfm.lp.MatrixElement;
 9import jfm.lp.MatrixRow;
10import jfm.lp.ModelComponent;
11import jfm.lp.SOS2Primitive;
12import jfm.lp.ConstraintBuilder.CBType;
13import jfm.lp.ModelComponent.MCType;
14import jfm.model.Types.ObjectiveType;
15
16/**
17 * @author iracooke
18 *
19 */
20public class HedgerowLengthComponent extends BoundaryComponent {
21	public HedgerowLengthComponent(double maxLen_,double hist,double createCost,double destCost,double maintain,double discountRate_){
22		super(MCType.HEDGEROWS,ObjectiveType.HEDGEROWS,maxLen_,hist,createCost,destCost,maintain,discountRate_);
23		this.addConstraintBuilder(new HedgerowSOS2Constraints(CBType.HEDGEROWSOS2,MCType.HEDGEROWS));
24	}
25	
26	public class HedgerowSOS2Constraints extends ConstraintBuilder {
27
28		public HedgerowSOS2Constraints(CBType type_,ModelComponent.MCType assoc){
29			super(type_,assoc);
30		}
31		
32		public void build(){
33		//	System.out.println("Building hedge constraints");
34			SOS2Primitive.buildConstraints(profit, matrix);
35			if ( curve!=null){ // If we have set a curved attitude then we need to link it to profit
36//				SOS2Primitive.buildConstraints(attitude, matrix);
37		//		System.out.println("Building link");
38				SOS2Primitive.buildLink(curve,profit,matrix);
39			} else {
40				// If there is no curve we need to bind the profit curve to the hedgerow counter directly
41				int row=matrix.numRows();
42				MatrixRow rowpointer =new MatrixRow(0,0,LPX.LPX_FX,
43						row,"BindHedges","BindingRow");
44				matrix.addRow(rowpointer);
45				row++;
46				rowpointer.addElement(new MatrixElement(profit.getDependentColumn(0),-1));
47//				System.out.println("building binding row with "+obj.variables().size()+" "+obj.type);
48				rowpointer.addElement(new MatrixElement(lengthCounter.column(),1));
49
50				matrix.flagForAlwaysRebuild();
51				
52			}
53		}
54	}
55	
56}