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 96c7a658dSClemens 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 30056207eeSczeidler bool GaussianElimination(); 317583db5aSClemens Zeidler bool GaussJordan(); 327583db5aSClemens Zeidler /*! Gauss Jordan elimination just for one column, the diagonal 337583db5aSClemens Zeidler element must be none zero. */ 347583db5aSClemens Zeidler void GaussJordan(int32 column); 357583db5aSClemens Zeidler 367583db5aSClemens Zeidler void RemoveLinearlyDependentRows(); 377583db5aSClemens Zeidler void RemoveUnusedVariables(); 387583db5aSClemens Zeidler 397583db5aSClemens Zeidler void MoveColumnRight(int32 i, int32 target); 407583db5aSClemens Zeidler 417583db5aSClemens Zeidler void Print(); 427583db5aSClemens Zeidler private: 43056207eeSczeidler inline void _EliminateColumn(int32 column, int32 startRow, 44056207eeSczeidler int32 endRow); 45056207eeSczeidler 467583db5aSClemens Zeidler int32* fRowIndices; 477583db5aSClemens Zeidler int32* fColumnIndices; 487583db5aSClemens Zeidler double** fMatrix; 497583db5aSClemens Zeidler double* fB; 507583db5aSClemens Zeidler int32 fRows; 517583db5aSClemens Zeidler int32 fColumns; 527583db5aSClemens Zeidler }; 537583db5aSClemens Zeidler 547583db5aSClemens Zeidler 556c7a658dSClemens Zeidler class ActiveSetSolver : public QPSolverInterface { 567583db5aSClemens Zeidler public: 577583db5aSClemens Zeidler ActiveSetSolver(LinearSpec* linearSpec); 587583db5aSClemens Zeidler ~ActiveSetSolver(); 597583db5aSClemens Zeidler 607583db5aSClemens Zeidler ResultType Solve(); 617583db5aSClemens Zeidler 627583db5aSClemens Zeidler bool VariableAdded(Variable* variable); 637583db5aSClemens Zeidler bool VariableRemoved(Variable* variable); 647583db5aSClemens Zeidler bool VariableRangeChanged(Variable* variable); 657583db5aSClemens Zeidler 667583db5aSClemens Zeidler bool ConstraintAdded(Constraint* constraint); 677583db5aSClemens Zeidler bool ConstraintRemoved(Constraint* constraint); 687583db5aSClemens Zeidler bool LeftSideChanged(Constraint* constraint); 697583db5aSClemens Zeidler bool RightSideChanged(Constraint* constraint); 707583db5aSClemens Zeidler bool OperatorChanged(Constraint* constraint); 717583db5aSClemens Zeidler 727583db5aSClemens Zeidler bool SaveModel(const char* fileName); 737583db5aSClemens Zeidler 747583db5aSClemens Zeidler BSize MinSize(Variable* width, Variable* height); 757583db5aSClemens Zeidler BSize MaxSize(Variable* width, Variable* height); 767583db5aSClemens Zeidler 77*419fe0b8SAlex Wilson ResultType FindMaxs(const VariableList* variables); 78*419fe0b8SAlex Wilson ResultType FindMins(const VariableList* variables); 79*419fe0b8SAlex Wilson 807583db5aSClemens Zeidler public: 81a0ad88e0SClemens Zeidler void _RemoveSoftConstraint(ConstraintList& list); 82a0ad88e0SClemens Zeidler void _AddSoftConstraint(const ConstraintList& list); 83a0ad88e0SClemens Zeidler 847583db5aSClemens Zeidler const VariableList& fVariables; 857583db5aSClemens Zeidler const ConstraintList& fConstraints; 867583db5aSClemens Zeidler 877583db5aSClemens Zeidler ConstraintList fVariableGEConstraints; 887583db5aSClemens Zeidler ConstraintList fVariableLEConstraints; 897583db5aSClemens Zeidler }; 907583db5aSClemens Zeidler 917583db5aSClemens Zeidler 927583db5aSClemens Zeidler #endif // ACTICE_SET_SOLVER_H 93