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 <ObjectList.h>
10#include <String.h>
11#include <SupportDefs.h>
12
13#include "LinearProgrammingTypes.h"
14#include "Summand.h"
15#include "Variable.h"
16
17
18namespace LinearProgramming {
19
20class LinearSpec;
21
22/**
23 * Hard linear constraint, i.e.&nbsp;one that must be satisfied.
24 * May render a specification infeasible.
25 */
26class Constraint {
27public:
28								Constraint();
29			/*! Creates a soft copy of the constraint which is not connected
30			to the solver. Variables are not copied or cloned but the soft copy
31			has its own summand list with summands. */
32								Constraint(Constraint* constraint);
33
34			int32				Index() const;
35
36			SummandList*		LeftSide();
37
38			bool				SetLeftSide(SummandList* summands,
39									bool deleteOldSummands);
40
41			bool				SetLeftSide(double coeff1, Variable* var1);
42			bool				SetLeftSide(double coeff1, Variable* var1,
43									double coeff2, Variable* var2);
44			bool				SetLeftSide(double coeff1, Variable* var1,
45									double coeff2, Variable* var2,
46									double coeff3, Variable* var3);
47			bool				SetLeftSide(double coeff1, Variable* var1,
48									double coeff2, Variable* var2,
49									double coeff3, Variable* var3,
50									double coeff4, Variable* var4);
51
52			OperatorType		Op();
53			void				SetOp(OperatorType value);
54			double				RightSide() const;
55			void				SetRightSide(double value);
56			double				PenaltyNeg() const;
57			void				SetPenaltyNeg(double value);
58			double				PenaltyPos() const;
59			void				SetPenaltyPos(double value);
60
61			const char*			Label();
62			void				SetLabel(const char* label);
63
64			bool				IsValid();
65			void				Invalidate();
66
67			BString				ToString() const;
68			void				PrintToStream();
69
70								~Constraint();
71
72protected:
73								Constraint(LinearSpec* ls,
74									SummandList* summands, OperatorType op,
75									double rightSide,
76									double penaltyNeg = -1,
77									double penaltyPos = -1);
78
79private:
80			LinearSpec*			fLS;
81			SummandList*		fLeftSide;
82			OperatorType		fOp;
83			double				fRightSide;
84
85			double				fPenaltyNeg;
86			double				fPenaltyPos;
87			BString				fLabel;
88
89public:
90	friend class		LinearSpec;
91};
92
93
94typedef BObjectList<Constraint> ConstraintList;
95
96
97}	// namespace LinearProgramming
98
99using LinearProgramming::Constraint;
100using LinearProgramming::ConstraintList;
101
102#endif	// CONSTRAINT_H
103
104