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 13namespace LinearProgramming { 14 15class Constraint; 16class LinearSpec; 17class Summand; 18 19/** 20 * Contains minimum and maximum values. 21 */ 22class Variable { 23public: 24 int32 Index() const; 25 int32 GlobalIndex() const; 26 LinearSpec* LS() const; 27 double Value() const; 28 void SetValue(double value); 29 double Min() const; 30 void SetMin(double min); 31 double Max() const; 32 void SetMax(double max); 33 void SetRange(double min, double max); 34 35 const char* Label(); 36 void SetLabel(const char* label); 37 38 BString ToString() 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 virtual ~Variable(); 57 58protected: 59 Variable(LinearSpec* ls); 60 61 //! returns the ref count 62 int32 AddReference(); 63 int32 RemoveReference(); 64private: 65 LinearSpec* fLS; 66 67 double fValue; 68 double fMin; 69 double fMax; 70 BString fLabel; 71 72 bool fIsValid; 73 74 int32 fReferenceCount; 75public: 76 friend class LinearSpec; 77}; 78 79 80typedef BObjectList<Variable> VariableList; 81 82 83} // namespace LinearProgramming 84 85using LinearProgramming::Variable; 86using LinearProgramming::VariableList; 87 88#endif // VARIABLE_H 89