PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/farmR/src/java/src/jfm/model/DitchLengthComponent.java

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