1*7583db5aSClemens Zeidler /* 2*7583db5aSClemens Zeidler * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de> 3*7583db5aSClemens Zeidler * Distributed under the terms of the MIT License. 4*7583db5aSClemens Zeidler */ 5*7583db5aSClemens Zeidler #ifndef ACTICE_SET_SOLVER_H 6*7583db5aSClemens Zeidler #define ACTICE_SET_SOLVER_H 7*7583db5aSClemens Zeidler 8*7583db5aSClemens Zeidler 9*7583db5aSClemens Zeidler #include "LinearSpec.h" 10*7583db5aSClemens Zeidler 11*7583db5aSClemens Zeidler 12*7583db5aSClemens Zeidler class EquationSystem { 13*7583db5aSClemens Zeidler public: 14*7583db5aSClemens Zeidler EquationSystem(int32 rows, int32 columns); 15*7583db5aSClemens Zeidler ~EquationSystem(); 16*7583db5aSClemens Zeidler 17*7583db5aSClemens Zeidler void SetRows(int32 rows); 18*7583db5aSClemens Zeidler int32 Rows(); 19*7583db5aSClemens Zeidler int32 Columns(); 20*7583db5aSClemens Zeidler 21*7583db5aSClemens Zeidler inline double& A(int32 row, int32 column); 22*7583db5aSClemens Zeidler inline double& B(int32 row); 23*7583db5aSClemens Zeidler /*! Copy the solved variables into results, keeping the original 24*7583db5aSClemens Zeidler variable order. */ 25*7583db5aSClemens Zeidler inline void Results(double* results, int32 size); 26*7583db5aSClemens Zeidler 27*7583db5aSClemens Zeidler inline void SwapColumn(int32 i, int32 j); 28*7583db5aSClemens Zeidler inline void SwapRow(int32 i, int32 j); 29*7583db5aSClemens Zeidler 30*7583db5aSClemens Zeidler bool GaussJordan(); 31*7583db5aSClemens Zeidler /*! Gauss Jordan elimination just for one column, the diagonal 32*7583db5aSClemens Zeidler element must be none zero. */ 33*7583db5aSClemens Zeidler void GaussJordan(int32 column); 34*7583db5aSClemens Zeidler 35*7583db5aSClemens Zeidler void RemoveLinearlyDependentRows(); 36*7583db5aSClemens Zeidler void RemoveUnusedVariables(); 37*7583db5aSClemens Zeidler 38*7583db5aSClemens Zeidler void MoveColumnRight(int32 i, int32 target); 39*7583db5aSClemens Zeidler 40*7583db5aSClemens Zeidler void Print(); 41*7583db5aSClemens Zeidler private: 42*7583db5aSClemens Zeidler int32* fRowIndices; 43*7583db5aSClemens Zeidler int32* fColumnIndices; 44*7583db5aSClemens Zeidler double** fMatrix; 45*7583db5aSClemens Zeidler double* fB; 46*7583db5aSClemens Zeidler int32 fRows; 47*7583db5aSClemens Zeidler int32 fColumns; 48*7583db5aSClemens Zeidler }; 49*7583db5aSClemens Zeidler 50*7583db5aSClemens Zeidler 51*7583db5aSClemens Zeidler class ActiveSetSolver : public LinearProgramming::SolverInterface { 52*7583db5aSClemens Zeidler public: 53*7583db5aSClemens Zeidler ActiveSetSolver(LinearSpec* linearSpec); 54*7583db5aSClemens Zeidler ~ActiveSetSolver(); 55*7583db5aSClemens Zeidler 56*7583db5aSClemens Zeidler ResultType Solve(); 57*7583db5aSClemens Zeidler 58*7583db5aSClemens Zeidler bool VariableAdded(Variable* variable); 59*7583db5aSClemens Zeidler bool VariableRemoved(Variable* variable); 60*7583db5aSClemens Zeidler bool VariableRangeChanged(Variable* variable); 61*7583db5aSClemens Zeidler 62*7583db5aSClemens Zeidler bool ConstraintAdded(Constraint* constraint); 63*7583db5aSClemens Zeidler bool ConstraintRemoved(Constraint* constraint); 64*7583db5aSClemens Zeidler bool LeftSideChanged(Constraint* constraint); 65*7583db5aSClemens Zeidler bool RightSideChanged(Constraint* constraint); 66*7583db5aSClemens Zeidler bool OperatorChanged(Constraint* constraint); 67*7583db5aSClemens Zeidler 68*7583db5aSClemens Zeidler bool SaveModel(const char* fileName); 69*7583db5aSClemens Zeidler 70*7583db5aSClemens Zeidler BSize MinSize(Variable* width, Variable* height); 71*7583db5aSClemens Zeidler BSize MaxSize(Variable* width, Variable* height); 72*7583db5aSClemens Zeidler 73*7583db5aSClemens Zeidler public: 74*7583db5aSClemens Zeidler const VariableList& fVariables; 75*7583db5aSClemens Zeidler const ConstraintList& fConstraints; 76*7583db5aSClemens Zeidler 77*7583db5aSClemens Zeidler ConstraintList fVariableGEConstraints; 78*7583db5aSClemens Zeidler ConstraintList fVariableLEConstraints; 79*7583db5aSClemens Zeidler }; 80*7583db5aSClemens Zeidler 81*7583db5aSClemens Zeidler 82*7583db5aSClemens Zeidler #endif // ACTICE_SET_SOLVER_H 83