103069455SIngo Weinhold /* 203069455SIngo Weinhold * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz 303069455SIngo Weinhold * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz 444032741SClemens Zeidler * Copyright 2010, Clemens Zeidler, haiku@clemens-zeidler.de 503069455SIngo Weinhold * Distributed under the terms of the MIT License. 603069455SIngo Weinhold */ 7a101e99aSIngo Weinhold #ifndef LINEAR_SPEC_H 8a101e99aSIngo Weinhold #define LINEAR_SPEC_H 9a101e99aSIngo Weinhold 1003069455SIngo Weinhold #include <math.h> 11a101e99aSIngo Weinhold 1244032741SClemens Zeidler #include <List.h> 1344032741SClemens Zeidler #include <OS.h> 1444032741SClemens Zeidler #include <String.h> 1544032741SClemens Zeidler #include <SupportDefs.h> 1644032741SClemens Zeidler 1744032741SClemens Zeidler #include "Constraint.h" 1844032741SClemens Zeidler #include "OperatorType.h" 1944032741SClemens Zeidler #include "OptimizationType.h" 2044032741SClemens Zeidler #include "PenaltyFunction.h" 2144032741SClemens Zeidler #include "ResultType.h" 2244032741SClemens Zeidler #include "Summand.h" 2344032741SClemens Zeidler #include "Variable.h" 2444032741SClemens Zeidler 2544032741SClemens Zeidler #include "lp_lib.h" 26a101e99aSIngo Weinhold 27cd88ee00SClemens Zeidler 28a101e99aSIngo Weinhold namespace LinearProgramming { 29a101e99aSIngo Weinhold 3044032741SClemens Zeidler /*! 31a101e99aSIngo Weinhold * Specification of a linear programming problem. 32a101e99aSIngo Weinhold */ 33a101e99aSIngo Weinhold class LinearSpec { 34a101e99aSIngo Weinhold public: 35a101e99aSIngo Weinhold LinearSpec(); 36676ef01bSAxel Dörfler virtual ~LinearSpec(); 375bced18eSIngo Weinhold 38a101e99aSIngo Weinhold Variable* AddVariable(); 39*fc691d7dSClemens Zeidler bool AddVariable(Variable* variable); 40*fc691d7dSClemens Zeidler bool RemoveVariable(Variable* variable, 41*fc691d7dSClemens Zeidler bool deleteVariable = true); 42*fc691d7dSClemens Zeidler int32 IndexOf(const Variable* variable) const; 43*fc691d7dSClemens Zeidler bool SetRange(Variable* variable, double min, 44*fc691d7dSClemens Zeidler double max); 45a101e99aSIngo Weinhold 46601eded9SClemens Zeidler Constraint* AddConstraint(SummandList* summands, 47a101e99aSIngo Weinhold OperatorType op, double rightSide); 48a101e99aSIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 49a101e99aSIngo Weinhold OperatorType op, double rightSide); 50a101e99aSIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 51a101e99aSIngo Weinhold double coeff2, Variable* var2, 52a101e99aSIngo Weinhold OperatorType op, double rightSide); 53a101e99aSIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 54a101e99aSIngo Weinhold double coeff2, Variable* var2, 55a101e99aSIngo Weinhold double coeff3, Variable* var3, 56a101e99aSIngo Weinhold OperatorType op, double rightSide); 57a101e99aSIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 58a101e99aSIngo Weinhold double coeff2, Variable* var2, 59a101e99aSIngo Weinhold double coeff3, Variable* var3, 60a101e99aSIngo Weinhold double coeff4, Variable* var4, 61a101e99aSIngo Weinhold OperatorType op, double rightSide); 62a101e99aSIngo Weinhold 63601eded9SClemens Zeidler Constraint* AddConstraint(SummandList* summands, 64a101e99aSIngo Weinhold OperatorType op, double rightSide, 65a101e99aSIngo Weinhold double penaltyNeg, double penaltyPos); 6603069455SIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 67a101e99aSIngo Weinhold OperatorType op, double rightSide, 68a101e99aSIngo Weinhold double penaltyNeg, double penaltyPos); 6903069455SIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 70a101e99aSIngo Weinhold double coeff2, Variable* var2, 71a101e99aSIngo Weinhold OperatorType op, double rightSide, 72a101e99aSIngo Weinhold double penaltyNeg, double penaltyPos); 7303069455SIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 74a101e99aSIngo Weinhold double coeff2, Variable* var2, 75a101e99aSIngo Weinhold double coeff3, Variable* var3, 76a101e99aSIngo Weinhold OperatorType op, double rightSide, 77a101e99aSIngo Weinhold double penaltyNeg, double penaltyPos); 7803069455SIngo Weinhold Constraint* AddConstraint(double coeff1, Variable* var1, 79a101e99aSIngo Weinhold double coeff2, Variable* var2, 80a101e99aSIngo Weinhold double coeff3, Variable* var3, 81a101e99aSIngo Weinhold double coeff4, Variable* var4, 82a101e99aSIngo Weinhold OperatorType op, double rightSide, 83a101e99aSIngo Weinhold double penaltyNeg, double penaltyPos); 84a101e99aSIngo Weinhold 8544032741SClemens Zeidler PenaltyFunction* AddPenaltyFunction(Variable* var, BList* xs, 8644032741SClemens Zeidler BList* gs); 875bced18eSIngo Weinhold 88cad0c434SClemens Zeidler SummandList* ObjectiveFunction(); 89cad0c434SClemens Zeidler //! Caller takes ownership of the Summand's and the SummandList. 90cad0c434SClemens Zeidler SummandList* ReplaceObjectiveFunction( 91cad0c434SClemens Zeidler SummandList* objFunction); 92cad0c434SClemens Zeidler void SetObjectiveFunction(SummandList* objFunction); 93cad0c434SClemens Zeidler void UpdateObjectiveFunction(); 945bced18eSIngo Weinhold 95a101e99aSIngo Weinhold ResultType Solve(); 96b8ec67f4SStephan Aßmus void Save(const char* fileName); 97a101e99aSIngo Weinhold 985bced18eSIngo Weinhold int32 CountColumns() const; 99a101e99aSIngo Weinhold OptimizationType Optimization() const; 100a101e99aSIngo Weinhold void SetOptimization(OptimizationType value); 10144032741SClemens Zeidler 102a101e99aSIngo Weinhold ResultType Result() const; 103a101e99aSIngo Weinhold double ObjectiveValue() const; 104a101e99aSIngo Weinhold double SolvingTime() const; 105a101e99aSIngo Weinhold 106b8ec67f4SStephan Aßmus operator BString() const; 107b8ec67f4SStephan Aßmus void GetString(BString& string) const; 108676ef01bSAxel Dörfler 109*fc691d7dSClemens Zeidler const ConstraintList& Constraints() const; 110a101e99aSIngo Weinhold 111a101e99aSIngo Weinhold private: 112*fc691d7dSClemens Zeidler ResultType Presolve(); 113*fc691d7dSClemens Zeidler void RemovePresolved(); 114*fc691d7dSClemens Zeidler 115a101e99aSIngo Weinhold lprec* fLpPresolved; 116a101e99aSIngo Weinhold OptimizationType fOptimization; 117a101e99aSIngo Weinhold lprec* fLP; 118601eded9SClemens Zeidler SummandList* fObjFunction; 119cd88ee00SClemens Zeidler VariableList fVariables; 120cd88ee00SClemens Zeidler ConstraintList fConstraints; 121a101e99aSIngo Weinhold ResultType fResult; 122a101e99aSIngo Weinhold double fObjectiveValue; 1235bced18eSIngo Weinhold double fSolvingTime; 124a101e99aSIngo Weinhold 125a101e99aSIngo Weinhold public: 12603069455SIngo Weinhold friend class Constraint; 127a101e99aSIngo Weinhold 128a101e99aSIngo Weinhold }; 129a101e99aSIngo Weinhold 130a101e99aSIngo Weinhold } // namespace LinearProgramming 131a101e99aSIngo Weinhold 132a101e99aSIngo Weinhold using LinearProgramming::LinearSpec; 133a101e99aSIngo Weinhold 134a101e99aSIngo Weinhold #endif // LINEAR_SPEC_H 135