xref: /haiku/src/libs/linprog/ActiveSetSolver.h (revision 6c7a658d1c50c9776f99c34185f7e447f4db17bd)
17583db5aSClemens Zeidler /*
27583db5aSClemens Zeidler  * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
37583db5aSClemens Zeidler  * Distributed under the terms of the MIT License.
47583db5aSClemens Zeidler  */
57583db5aSClemens Zeidler #ifndef ACTICE_SET_SOLVER_H
67583db5aSClemens Zeidler #define ACTICE_SET_SOLVER_H
77583db5aSClemens Zeidler 
87583db5aSClemens Zeidler 
9*6c7a658dSClemens Zeidler #include "QPSolverInterface.h"
107583db5aSClemens Zeidler 
117583db5aSClemens Zeidler 
127583db5aSClemens Zeidler class EquationSystem {
137583db5aSClemens Zeidler public:
147583db5aSClemens Zeidler 								EquationSystem(int32 rows, int32 columns);
157583db5aSClemens Zeidler 								~EquationSystem();
167583db5aSClemens Zeidler 
177583db5aSClemens Zeidler 			void				SetRows(int32 rows);
187583db5aSClemens Zeidler 			int32				Rows();
197583db5aSClemens Zeidler 			int32				Columns();
207583db5aSClemens Zeidler 
217583db5aSClemens Zeidler 	inline	double&				A(int32 row, int32 column);
227583db5aSClemens Zeidler 	inline	double&				B(int32 row);
237583db5aSClemens Zeidler 			/*! Copy the solved variables into results, keeping the original
247583db5aSClemens Zeidler 			variable order. */
257583db5aSClemens Zeidler 	inline	void				Results(double* results, int32 size);
267583db5aSClemens Zeidler 
277583db5aSClemens Zeidler 	inline	void				SwapColumn(int32 i, int32 j);
287583db5aSClemens Zeidler 	inline	void				SwapRow(int32 i, int32 j);
297583db5aSClemens Zeidler 
307583db5aSClemens Zeidler 			bool				GaussJordan();
317583db5aSClemens Zeidler 			/*! Gauss Jordan elimination just for one column, the diagonal
327583db5aSClemens Zeidler 			element must be none zero. */
337583db5aSClemens Zeidler 			void				GaussJordan(int32 column);
347583db5aSClemens Zeidler 
357583db5aSClemens Zeidler 			void				RemoveLinearlyDependentRows();
367583db5aSClemens Zeidler 			void				RemoveUnusedVariables();
377583db5aSClemens Zeidler 
387583db5aSClemens Zeidler 			void				MoveColumnRight(int32 i, int32 target);
397583db5aSClemens Zeidler 
407583db5aSClemens Zeidler 			void				Print();
417583db5aSClemens Zeidler private:
427583db5aSClemens Zeidler 			int32*				fRowIndices;
437583db5aSClemens Zeidler 			int32*				fColumnIndices;
447583db5aSClemens Zeidler 			double**			fMatrix;
457583db5aSClemens Zeidler 			double*				fB;
467583db5aSClemens Zeidler 			int32				fRows;
477583db5aSClemens Zeidler 			int32				fColumns;
487583db5aSClemens Zeidler };
497583db5aSClemens Zeidler 
507583db5aSClemens Zeidler 
51*6c7a658dSClemens Zeidler class ActiveSetSolver : public QPSolverInterface {
527583db5aSClemens Zeidler public:
537583db5aSClemens Zeidler 								ActiveSetSolver(LinearSpec* linearSpec);
547583db5aSClemens Zeidler 								~ActiveSetSolver();
557583db5aSClemens Zeidler 
567583db5aSClemens Zeidler 			ResultType			Solve();
577583db5aSClemens Zeidler 
587583db5aSClemens Zeidler 			bool				VariableAdded(Variable* variable);
597583db5aSClemens Zeidler 			bool				VariableRemoved(Variable* variable);
607583db5aSClemens Zeidler 			bool				VariableRangeChanged(Variable* variable);
617583db5aSClemens Zeidler 
627583db5aSClemens Zeidler 			bool				ConstraintAdded(Constraint* constraint);
637583db5aSClemens Zeidler 			bool				ConstraintRemoved(Constraint* constraint);
647583db5aSClemens Zeidler 			bool				LeftSideChanged(Constraint* constraint);
657583db5aSClemens Zeidler 			bool				RightSideChanged(Constraint* constraint);
667583db5aSClemens Zeidler 			bool				OperatorChanged(Constraint* constraint);
677583db5aSClemens Zeidler 
687583db5aSClemens Zeidler 			bool				SaveModel(const char* fileName);
697583db5aSClemens Zeidler 
707583db5aSClemens Zeidler 			BSize				MinSize(Variable* width, Variable* height);
717583db5aSClemens Zeidler 			BSize				MaxSize(Variable* width, Variable* height);
727583db5aSClemens Zeidler 
737583db5aSClemens Zeidler public:
74a0ad88e0SClemens Zeidler 			void				_RemoveSoftConstraint(ConstraintList& list);
75a0ad88e0SClemens Zeidler 			void				_AddSoftConstraint(const ConstraintList& list);
76a0ad88e0SClemens Zeidler 
777583db5aSClemens Zeidler 	const	VariableList&		fVariables;
787583db5aSClemens Zeidler 	const	ConstraintList&		fConstraints;
797583db5aSClemens Zeidler 
807583db5aSClemens Zeidler 			ConstraintList		fVariableGEConstraints;
817583db5aSClemens Zeidler 			ConstraintList		fVariableLEConstraints;
827583db5aSClemens Zeidler };
837583db5aSClemens Zeidler 
847583db5aSClemens Zeidler 
857583db5aSClemens Zeidler #endif // ACTICE_SET_SOLVER_H
86