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