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 #ifndef VARIABLE_H 7 #define VARIABLE_H 8 9 10 #include <ObjectList.h> 11 #include <String.h> 12 13 namespace LinearProgramming { 14 15 class Constraint; 16 class LinearSpec; 17 class Summand; 18 19 /** 20 * Contains minimum and maximum values. 21 */ 22 class Variable { 23 public: 24 int32 Index() const; 25 LinearSpec* LS() const; 26 double Value() const; 27 void SetValue(double value); 28 double Min() const; 29 void SetMin(double min); 30 double Max() const; 31 void SetMax(double max); 32 void SetRange(double min, double max); 33 34 const char* Label(); 35 void SetLabel(const char* label); 36 37 operator BString() const; 38 void GetString(BString& string) const; 39 40 Constraint* IsEqual(Variable* var); 41 Constraint* IsSmallerOrEqual(Variable* var); 42 Constraint* IsGreaterOrEqual(Variable* var); 43 44 Constraint* IsEqual(Variable* var, 45 double penaltyNeg, double penaltyPos); 46 Constraint* IsSmallerOrEqual(Variable* var, 47 double penaltyNeg, double penaltyPos); 48 Constraint* IsGreaterOrEqual(Variable* var, 49 double penaltyNeg, double penaltyPos); 50 51 bool IsValid(); 52 //! Dangerous the variable don't belong to the LinearSpec anymore, 53 //! delete it yourself! 54 void Invalidate(); 55 56 ~Variable(); 57 58 protected: 59 Variable(LinearSpec* ls); 60 61 private: 62 LinearSpec* fLS; 63 64 BObjectList<Summand> fUsingSummands; 65 // All Summands that link to this Variable 66 double fValue; 67 double fMin; 68 double fMax; 69 BString fLabel; 70 71 bool fIsValid; 72 73 public: 74 friend class LinearSpec; 75 friend class Summand; 76 }; 77 78 79 typedef BObjectList<Variable> VariableList; 80 81 82 } // namespace LinearProgramming 83 84 using LinearProgramming::Variable; 85 using LinearProgramming::VariableList; 86 87 #endif // VARIABLE_H 88