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