1 /* 2 * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz 3 * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz 4 * Distributed under the terms of the MIT License. 5 */ 6 7 #ifndef LINEAR_SPEC_H 8 #define LINEAR_SPEC_H 9 10 #include "Variable.h" 11 #include "Constraint.h" 12 #include "Summand.h" 13 #include "PenaltyFunction.h" 14 #include "OperatorType.h" 15 #include "ResultType.h" 16 #include "OptimizationType.h" 17 18 #include "lp_lib.h" 19 20 #include <List.h> 21 #include <OS.h> 22 #include <SupportDefs.h> 23 #include <math.h> 24 25 26 namespace LinearProgramming { 27 28 class Constraint; 29 class ObjFunctionSummand; 30 class PenaltyFunction; 31 class Variable; 32 33 /** 34 * Specification of a linear programming problem. 35 */ 36 class LinearSpec { 37 38 public: 39 LinearSpec(); 40 ~LinearSpec(); 41 42 Variable* AddVariable(); 43 44 Constraint* AddConstraint(BList* summands, 45 OperatorType op, double rightSide); 46 Constraint* AddConstraint(double coeff1, Variable* var1, 47 OperatorType op, double rightSide); 48 Constraint* AddConstraint(double coeff1, Variable* var1, 49 double coeff2, Variable* var2, 50 OperatorType op, double rightSide); 51 Constraint* AddConstraint(double coeff1, Variable* var1, 52 double coeff2, Variable* var2, 53 double coeff3, Variable* var3, 54 OperatorType op, double rightSide); 55 Constraint* AddConstraint(double coeff1, Variable* var1, 56 double coeff2, Variable* var2, 57 double coeff3, Variable* var3, 58 double coeff4, Variable* var4, 59 OperatorType op, double rightSide); 60 61 Constraint* AddConstraint(BList* summands, 62 OperatorType op, double rightSide, 63 double penaltyNeg, double penaltyPos); 64 Constraint* AddConstraint(double coeff1, Variable* var1, 65 OperatorType op, double rightSide, 66 double penaltyNeg, double penaltyPos); 67 Constraint* AddConstraint(double coeff1, Variable* var1, 68 double coeff2, Variable* var2, 69 OperatorType op, double rightSide, 70 double penaltyNeg, double penaltyPos); 71 Constraint* AddConstraint(double coeff1, Variable* var1, 72 double coeff2, Variable* var2, 73 double coeff3, Variable* var3, 74 OperatorType op, double rightSide, 75 double penaltyNeg, double penaltyPos); 76 Constraint* AddConstraint(double coeff1, Variable* var1, 77 double coeff2, Variable* var2, 78 double coeff3, Variable* var3, 79 double coeff4, Variable* var4, 80 OperatorType op, double rightSide, 81 double penaltyNeg, double penaltyPos); 82 83 PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, BList* gs); 84 85 BList* ObjFunction(); 86 void SetObjFunction(BList* summands); 87 void UpdateObjFunction(); 88 89 ResultType Presolve(); 90 void RemovePresolved(); 91 ResultType Solve(); 92 void Save(char* fname); 93 94 int32 CountColumns() const; 95 OptimizationType Optimization() const; 96 void SetOptimization(OptimizationType value); 97 BList* Variables() const; 98 BList* Constraints() const; 99 ResultType Result() const; 100 double ObjectiveValue() const; 101 double SolvingTime() const; 102 103 protected: 104 int32 fCountColumns; 105 106 private: 107 lprec* fLpPresolved; 108 OptimizationType fOptimization; 109 lprec* fLP; 110 BList* fObjFunction; 111 BList* fVariables; 112 BList* fConstraints; 113 ResultType fResult; 114 double fObjectiveValue; 115 double fSolvingTime; 116 117 public: 118 friend class Constraint; 119 friend class Variable; 120 121 }; 122 123 } // namespace LinearProgramming 124 125 using LinearProgramming::LinearSpec; 126 127 #endif // LINEAR_SPEC_H 128