xref: /haiku/headers/libs/linprog/Constraint.h (revision ef93b55df49f5296bdb03867215cb1793596e845)
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 <ObjectList.h>
13 #include <String.h>
14 #include <SupportDefs.h>
15 
16 #include "LinearProgrammingTypes.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 public:
31 			int32				Index() const;
32 
33 			SummandList*		LeftSide();
34 			void				SetLeftSide(SummandList* summands);
35 
36 			void				SetLeftSide(double coeff1, Variable* var1);
37 			void				SetLeftSide(double coeff1, Variable* var1,
38 									double coeff2, Variable* var2);
39 			void				SetLeftSide(double coeff1, Variable* var1,
40 									double coeff2, Variable* var2,
41 									double coeff3, Variable* var3);
42 			void				SetLeftSide(double coeff1, Variable* var1,
43 									double coeff2, Variable* var2,
44 									double coeff3, Variable* var3,
45 									double coeff4, Variable* var4);
46 
47 			OperatorType		Op();
48 			void				SetOp(OperatorType value);
49 			double				RightSide() const;
50 			void				SetRightSide(double value);
51 			double				PenaltyNeg() const;
52 			void				SetPenaltyNeg(double value);
53 			double				PenaltyPos() const;
54 			void				SetPenaltyPos(double value);
55 
56 			const char*			Label();
57 			void				SetLabel(const char* label);
58 
59 			Variable*			DNeg() const;
60 			Variable*			DPos() const;
61 
62 			bool				IsSoft() const;
63 
64 			bool				IsValid();
65 			void				Invalidate();
66 
67 			BString				ToString() const;
68 			void				PrintToStream();
69 
70 								~Constraint();
71 
72 protected:
73 								Constraint(LinearSpec* ls,
74 									SummandList* summands, OperatorType op,
75 									double rightSide,
76 									double penaltyNeg = -1,
77 									double penaltyPos = -1);
78 
79 private:
80 			LinearSpec*			fLS;
81 			SummandList*		fLeftSide;
82 			OperatorType		fOp;
83 			double				fRightSide;
84 
85 			double				fPenaltyNeg;
86 			double				fPenaltyPos;
87 			Summand*			fDNegObjSummand;
88 			Summand*			fDPosObjSummand;
89 			BString				fLabel;
90 
91 			bool				fIsValid;
92 
93 public:
94 	friend class		LinearSpec;
95 	friend class		LPSolveInterface;
96 
97 };
98 
99 
100 typedef BObjectList<Constraint> ConstraintList;
101 
102 
103 }	// namespace LinearProgramming
104 
105 using LinearProgramming::Constraint;
106 using LinearProgramming::ConstraintList;
107 
108 #endif	// CONSTRAINT_H
109 
110