xref: /haiku/headers/libs/linprog/LinearSpec.h (revision b289aaf66bbf6e173aa90fa194fc256965f1b34d)
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	LINEAR_SPEC_H
8 #define	LINEAR_SPEC_H
9 
10 #include "Variable.h"
11 #include "Constraint.h"
12 #include "Summand.h"
13 #include "PenaltyFunction.h"
14 #include "OperatorType.h"
15 #include "ResultType.h"
16 #include "OptimizationType.h"
17 
18 #include "lp_lib.h"
19 
20 #include <List.h>
21 #include <String.h>
22 #include <OS.h>
23 #include <SupportDefs.h>
24 #include <math.h>
25 
26 
27 namespace LinearProgramming {
28 
29 class Constraint;
30 class ObjFunctionSummand;
31 class PenaltyFunction;
32 class Variable;
33 
34 /**
35  * Specification of a linear programming problem.
36  */
37 class LinearSpec {
38 
39 public:
40 						LinearSpec();
41 	virtual				~LinearSpec();
42 
43 	Variable*			AddVariable();
44 
45 	Constraint*			AddConstraint(BList* summands,
46 								OperatorType op, double rightSide);
47 	Constraint*			AddConstraint(double coeff1, Variable* var1,
48 								OperatorType op, double rightSide);
49 	Constraint*			AddConstraint(double coeff1, Variable* var1,
50 								double coeff2, Variable* var2,
51 								OperatorType op, double rightSide);
52 	Constraint*			AddConstraint(double coeff1, Variable* var1,
53 								double coeff2, Variable* var2,
54 								double coeff3, Variable* var3,
55 								OperatorType op, double rightSide);
56 	Constraint*			AddConstraint(double coeff1, Variable* var1,
57 								double coeff2, Variable* var2,
58 								double coeff3, Variable* var3,
59 								double coeff4, Variable* var4,
60 								OperatorType op, double rightSide);
61 
62 	Constraint*			AddConstraint(BList* summands,
63 								OperatorType op, double rightSide,
64 								double penaltyNeg, double penaltyPos);
65 	Constraint*			AddConstraint(double coeff1, Variable* var1,
66 								OperatorType op, double rightSide,
67 								double penaltyNeg, double penaltyPos);
68 	Constraint*			AddConstraint(double coeff1, Variable* var1,
69 								double coeff2, Variable* var2,
70 								OperatorType op, double rightSide,
71 								double penaltyNeg, double penaltyPos);
72 	Constraint*			AddConstraint(double coeff1, Variable* var1,
73 								double coeff2, Variable* var2,
74 								double coeff3, Variable* var3,
75 								OperatorType op, double rightSide,
76 								double penaltyNeg, double penaltyPos);
77 	Constraint*			AddConstraint(double coeff1, Variable* var1,
78 								double coeff2, Variable* var2,
79 								double coeff3, Variable* var3,
80 								double coeff4, Variable* var4,
81 								OperatorType op, double rightSide,
82 								double penaltyNeg, double penaltyPos);
83 
84 	PenaltyFunction*	AddPenaltyFunction(Variable* var, BList* xs, BList* gs);
85 
86 	BList*				ObjFunction();
87 	void				SetObjFunction(BList* summands);
88 	void				UpdateObjFunction();
89 
90 	ResultType			Presolve();
91 	void				RemovePresolved();
92 	ResultType			Solve();
93 	void				Save(const char* fileName);
94 
95 	int32				CountColumns() const;
96 	OptimizationType	Optimization() const;
97 	void				SetOptimization(OptimizationType value);
98 	BList*				Variables() const;
99 	BList*				Constraints() const;
100 	ResultType			Result() const;
101 	double				ObjectiveValue() const;
102 	double				SolvingTime() const;
103 
104 						operator BString() const;
105 	void				GetString(BString& string) const;
106 
107 protected:
108 	int32 				fCountColumns;
109 
110 private:
111 	lprec*				fLpPresolved;
112 	OptimizationType	fOptimization;
113 	lprec*				fLP;
114 	BList*				fObjFunction;
115 	BList*				fVariables;
116 	BList*				fConstraints;
117 	ResultType			fResult;
118 	double 				fObjectiveValue;
119 	double 				fSolvingTime;
120 
121 public:
122 	friend class		Constraint;
123 	friend class		Variable;
124 
125 };
126 
127 }	// namespace LinearProgramming
128 
129 using LinearProgramming::LinearSpec;
130 
131 #endif	// LINEAR_SPEC_H
132