00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031
00032
00033
00034 #ifndef SOLVER_H
00035 #define SOLVER_H
00036
00037
00038 #ifdef __GNUG__
00039 #pragma interface "Solver.h"
00040 #endif
00041
00042
00043 #include <wx/panel.h>
00044 #include "mc/Range.h"
00045 #include "mc/MathLine.h"
00046
00047
00048
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:
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:
00088
00090 const mcSymbolProperties *m_pUnkArr[mcSOLVER_MAXLINES];
00091
00093 void math_ResetUnkArray();
00094
00095
00096 protected:
00097
00101
00102
00106
00107
00109 mcSymbolProperties *math_GetUnknown(const mcMathOrSystem &sys, int n) const;
00110
00111
00112 protected:
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
00279
00280
00281
00282
00283
00284
00285
00286
00292
00293
00294
00295
00296
00298
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
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