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