00001 00002 // MathCore = a WYSIWYG equation editor + a powerful math engine // 00003 // Copyright (C) 2003 by Francesco Montorsi // 00004 // // 00005 // This library is free software; you can redistribute it and/or // 00006 // modify it under the terms of the GNU Lesser General Public // 00007 // License as published by the Free Software Foundation; either // 00008 // version 2.1 of the License, or (at your option) any later // 00009 // version. // 00010 // // 00011 // This library is distributed in the hope that it will be useful, // 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00014 // GNU Lesser General Public License for more details. // 00015 // // 00016 // You should have received a copy of the GNU Lesser General Public // 00017 // License along with this program; if not, write to the Free // 00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // 00019 // MA 02111-1307, USA. // 00020 // // 00021 // For any comment, suggestion or feature request, please contact // 00022 // the administrator of the project at frm@users.sourceforge.net // 00023 // // 00031 00032 00033 00034 #ifndef SOLVER_H 00035 #define SOLVER_H 00036 00037 // optimization for GCC compiler 00038 #ifdef __GNUG__ 00039 #pragma interface "Solver.h" 00040 #endif 00041 00042 // required includes 00043 #include <wx/panel.h> 00044 #include "mc/Range.h" 00045 #include "mc/MathLine.h" 00046 00047 00048 // these will be defined later... 00049 class mcMathOrSystem; 00050 class mcLineStepArray; 00051 class mcSystemStepArray; 00052 00053 00055 #define mcSOLVER_MAXLINES 16 00056 00058 #define mcTXTSTEP(x) ((x).io_GetInlinedExpr().c_str()) 00059 00060 00064 class mcSolver 00065 { 00066 protected: // member variables 00067 00070 mcSolverType m_nType; 00071 00074 wxString m_strName; 00075 00078 wxString m_strDesc; 00079 00081 wxString m_strLastErr; 00082 00084 mcRealValue m_fLastLenght; 00085 00086 00087 protected: // handy variables 00088 00090 const mcSymbolProperties *m_pUnkArr[mcSOLVER_MAXLINES]; 00091 00093 void math_ResetUnkArray(); 00094 00095 00096 protected: // utilities 00097 00101 //mcMathMng *math_GetNewStep(const mcMathMng *last); 00102 00106 //mcMathMng *math_GetNewSmartStep(const mcMathMng *last); 00107 00109 mcSymbolProperties *math_GetUnknown(const mcMathOrSystem &sys, int n) const; 00110 00111 00112 protected: // simplify/expand 00113 00118 void math_DoSimplifyStep(long lflags, long rflags, mcMathLine &tosimplify, 00119 mcSystemStepArray &steps, mcExpSimRes *p = NULL); 00120 00124 void math_DoCompleteSimplification(long lflags, long rflags, mcMathLine &tosimplify, 00125 mcSystemStepArray &steps); 00126 00128 void math_DoExpandStep(long lflags, long rflags, mcMathLine &tosimplify, 00129 mcSystemStepArray &steps, mcExpSimRes *p = NULL); 00130 00132 void math_DoCompleteExpansion(long lflags, long rflags, mcMathLine &tosimplify, 00133 mcSystemStepArray &steps); 00134 00136 void math_SplitInTwoEquations(const mcPolynomial &lfirsteq, const mcPolynomial &lseceq, 00137 const mcPolynomial &rfirsteq, const mcPolynomial &rseceq, mcSystemStepArray &steps, 00138 mcLogicOperator conn = mcLO_OR); 00139 void math_SplitInTwoEquations(mcMathLine *firsteq, mcMathLine *seceq, 00140 mcSystemStepArray &steps, mcLogicOperator conn = mcLO_OR); 00141 void math_SplitInTwoEquations(const mcMathLine &firsteq, const mcMathLine &seceq, 00142 mcSystemStepArray &steps, mcLogicOperator conn = mcLO_OR); 00143 00144 00145 public: 00146 mcSolver() { math_ResetUnkArray(); } 00147 virtual ~mcSolver() {} 00148 00149 00150 00154 00156 wxString math_GetDesc() const { return m_strDesc; } 00157 00159 wxString math_GetName() const { return m_strName; } 00160 00163 wxString math_GetLastErr() const { return m_strLastErr; } 00164 00166 mcSolverType math_GetType() const { return m_nType; } 00167 00169 00170 00171 00175 00178 virtual void data_Check() const; 00179 00180 virtual bool math_PreSolve(const mcMathOrSystem &, mcSystemStepArray &); 00181 virtual bool math_PostSolve(const mcMathOrSystem &, mcSystemStepArray &); 00182 00184 00185 00186 00190 00198 virtual bool math_WorksOn(const mcMathOrSystem &) const = 0; 00199 00205 virtual bool math_WorksOn(const mcMathOrSystem &, 00206 const mcSymbolProperties *unk) const { return TRUE; } 00207 00211 virtual bool math_Solve(const mcMathOrSystem &, mcSystemStepArray &); 00212 00216 virtual bool math_SolveLine(mcMathLine &, const mcSymbolProperties *unk, 00217 mcSystemStepArray &) = 0; 00218 00223 virtual bool math_isReady() const = 0; 00224 00230 virtual wxPanel *gui_GetOptionsPanel() const = 0; 00231 00233 }; 00234 00235 00236 00237 00242 class mcSolverArray : public mcAbstractArray 00243 { 00244 protected: 00245 void data_Delete(int n) 00246 { delete data_Get(n); } 00247 00248 public: 00249 mcSolverArray() {} 00250 virtual ~mcSolverArray() { data_Clear(); } 00251 00252 00257 bool math_Add(mcSolver *solver); 00258 00261 bool math_Contains(const mcSolver *) const; 00262 00265 wxArrayString io_GetDescArray() const; 00266 00268 void data_Check() const; 00269 00270 mcSolver *data_Get(int i) { return (mcSolver *)data_GetItem(i); } 00271 const mcSolver *data_Get(int i) const { return (mcSolver *)data_GetItem(i); } 00272 }; 00273 00274 00275 00276 /* 00278 class mcLineStepArray : public mcAbstractArray 00279 { 00280 protected: 00281 void data_Delete(int n) { delete data_Get(n); } 00282 00283 public: 00284 mcLineStepArray() {} 00285 virtual ~mcLineStepArray() { data_Clear(); } 00286 00292 int data_RemoveSimpleSteps(); 00293 00294 const mcMathMng *data_Get(int n) const { return (const mcMathMng *)data_GetItem(n); } 00295 mcMathMng *data_Get(int n) { return (mcMathMng *)data_GetItem(n); } 00296 00298 void data_Check() const; 00299 };*/ 00300 00301 00303 #define mcSYSTEMSTEPARR_NOFLAGS 0 00304 00312 #define mcSYSTEMSTEPARR_DISCARD_SIMPLE 1 00313 00314 00317 class mcSystemStepArray : public mcAbstractArray 00318 { 00319 #ifdef mcENABLE_DATA 00320 protected: 00321 00324 long m_nFlags; 00325 00326 #endif 00327 00328 00329 00330 public: 00331 mcSystemStepArray(long flags = mcSYSTEMSTEPARR_NOFLAGS) { m_nFlags=flags; } 00332 virtual ~mcSystemStepArray() { data_Clear(); } 00333 00334 00335 #ifdef mcENABLE_DATA 00336 protected: 00337 00339 void data_Delete(int n); 00340 00341 public: 00342 00347 int math_RemoveIdenticSteps(); 00348 00354 int math_RemoveSimpleSteps(); 00355 00357 void data_AddSys(mcMathOrSystem *pointer); 00358 00361 void data_AddFinalSys(mcMathOrSystem *pointer); 00362 00368 void data_AddSysOnlyIfComplexEnough(mcMathOrSystem *pointer); 00369 00372 void data_AddLine(const mcMathLine &p); 00373 00378 void data_AddKeyLine(const mcMathLine &p); 00379 00381 void data_AddLineOnlyIfComplexEnough(const mcMathLine &p); 00382 00386 //void data_AddLines(mcLineStepArray &steps, int j); 00387 00389 void data_MergeSystems(mcSystemStepArray &, int i); 00390 00392 void data_Check() const; 00393 00394 const mcMathOrSystem *data_Get(int n) const 00395 { return (const mcMathOrSystem *)data_GetItem(n); } 00396 mcMathOrSystem *data_Get(int n) 00397 { return (mcMathOrSystem *)data_GetItem(n); } 00398 const mcMathOrSystem *data_GetLast() const 00399 { return data_Get(data_GetCount()-1); } 00400 mcMathOrSystem *data_GetLast() 00401 { return data_Get(data_GetCount()-1); } 00402 00403 #endif // mcENABLE_DATA 00404 00405 00406 #ifdef mcENABLE_MATH 00407 public: 00408 00415 void math_AppendCombinationOf(const mcSystemStepArray &arr1, 00416 const mcSystemStepArray &arr2, 00417 mcLogicOperator lo); 00418 #endif // mcENABLE_MATH 00419 00420 00421 #ifdef mcENABLE_IO 00422 public: 00423 00426 wxString io_GetInlinedExpr() const; 00427 00428 #endif // mcENABLE_IO 00429 }; 00430 00431 #endif // SOLVER_H
[ Top ] |