xref: /haiku/headers/libs/linprog/Constraint.h (revision b329767e2fd45f1b0960ae8f767fc42f94a53cc8)
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	CONSTRAINT_H
7 #define	CONSTRAINT_H
8 
9 #include <math.h>
10 
11 #include <File.h>
12 #include <List.h>
13 #include <String.h>
14 #include <SupportDefs.h>
15 
16 #include "OperatorType.h"
17 #include "Summand.h"
18 #include "Variable.h"
19 
20 
21 namespace LinearProgramming {
22 
23 class LinearSpec;
24 
25 /**
26  * Hard linear constraint, i.e.&nbsp;one that must be satisfied.
27  * May render a specification infeasible.
28  */
29 class Constraint {
30 
31 public:
32 			int32				Index() const;
33 
34 			BList*				LeftSide();
35 			void				SetLeftSide(BList* summands);
36 			void				UpdateLeftSide();
37 			void				SetLeftSide(double coeff1, Variable* var1);
38 			void				SetLeftSide(double coeff1, Variable* var1,
39 									double coeff2, Variable* var2);
40 			void				SetLeftSide(double coeff1, Variable* var1,
41 									double coeff2, Variable* var2,
42 									double coeff3, Variable* var3);
43 			void				SetLeftSide(double coeff1, Variable* var1,
44 									double coeff2, Variable* var2,
45 									double coeff3, Variable* var3,
46 									double coeff4, Variable* var4);
47 
48 			OperatorType		Op();
49 			void				SetOp(OperatorType value);
50 			double				RightSide() const;
51 			void				SetRightSide(double value);
52 			double				PenaltyNeg() const;
53 			void				SetPenaltyNeg(double value);
54 			double				PenaltyPos() const;
55 			void				SetPenaltyPos(double value);
56 
57 			const char*			Label();
58 			void				SetLabel(const char* label);
59 
60 			void				WriteXML(BFile* file);
61 
62 			Variable*			DNeg() const;
63 			Variable*			DPos() const;
64 
65 			void				SetOwner(void* owner);
66 			void*				Owner() const;
67 
68 			bool				IsValid();
69 			void				Invalidate();
70 
71 								operator BString() const;
72 			void				GetString(BString& string) const;
73 
74 								~Constraint();
75 
76 protected:
77 								Constraint(LinearSpec* ls, BList* summands,
78 										OperatorType op, double rightSide,
79 										double penaltyNeg, double penaltyPos);
80 
81 private:
82 			LinearSpec*			fLS;
83 			BList*				fLeftSide;
84 			OperatorType		fOp;
85 			double				fRightSide;
86 			Summand*			fDNegObjSummand;
87 			Summand*			fDPosObjSummand;
88 			void*				fOwner;
89 			BString				fLabel;
90 
91 			bool				fIsValid;
92 
93 public:
94 	friend class		LinearSpec;
95 
96 };
97 
98 }	// namespace LinearProgramming
99 
100 using LinearProgramming::Constraint;
101 
102 #endif	// CONSTRAINT_H
103 
104