xref: /haiku/headers/libs/linprog/Constraint.h (revision d2e1e872611179c9cfaa43ce11bd58b1e3554e4b)
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 
7 #ifndef	CONSTRAINT_H
8 #define	CONSTRAINT_H
9 
10 #include "OperatorType.h"
11 #include "Variable.h"
12 #include "Summand.h"
13 
14 #include <List.h>
15 #include <String.h>
16 #include <SupportDefs.h>
17 #include <math.h>
18 
19 
20 namespace LinearProgramming {
21 
22 class LinearSpec;
23 
24 /**
25  * Hard linear constraint, i.e.&nbsp;one that must be satisfied.
26  * May render a specification infeasible.
27  */
28 class Constraint {
29 
30 public:
31 	int32				Index();
32 
33 	BList*				LeftSide();
34 	void				SetLeftSide(BList* summands);
35 	void				UpdateLeftSide();
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();
50 	void				SetRightSide(double value);
51 	double				PenaltyNeg();
52 	void				SetPenaltyNeg(double value);
53 	double				PenaltyPos();
54 	void				SetPenaltyPos(double value);
55 
56 	Variable*			DNeg() const;
57 	Variable*			DPos() const;
58 
59 	BString				ToString();
60 						~Constraint();
61 
62 protected:
63 						Constraint(LinearSpec* ls, BList* summands,
64 								OperatorType op, double rightSide,
65 								double penaltyNeg, double penaltyPos);
66 
67 private:
68 	LinearSpec*			fLS;
69 	BList*				fLeftSide;
70 	OperatorType		fOp;
71 	double				fRightSide;
72 	Summand*			fDNegObjSummand;
73 	Summand*			fDPosObjSummand;
74 
75 public:
76 	friend class		LinearSpec;
77 
78 };
79 
80 }	// namespace LinearProgramming
81 
82 using LinearProgramming::Constraint;
83 
84 #endif	// CONSTRAINT_H
85 
86