Debian Codegraph @

src/xmpsolve/polynomialsolver.h

raw
1 #ifndef POLYNOMIALSOLVER_H
2 #define POLYNOMIALSOLVER_H
3
4 #include <QObject>
5 #include "root.h"
6 #include "mpsolveworker.h"
7 #include "rootsmodel.h"
8 #include "monomial.h"
9 #include <mps/mps.h>
10 #include <stdio.h>
11
12 namespace xmpsolve {
13
14 /**
15 * @brief The PolynomialSolver class aims to solve a polynomial given
16 * its coefficients or the content of the line edit to parse.
17 *
18 * When the polynomial will be solve a solved() signal will be emitted
19 * and the roots will be reachable through the get_roots() method.
20 */
21 class PolynomialSolver : public QObject
22 {
23 Q_OBJECT
24
25 public:
26
27 explicit PolynomialSolver(QObject *parent = 0);
28 ~PolynomialSolver();
29
30 public slots:
31
32 /**
33 * @brief Solve a polynomial.
34 *
35 * @return The degree of the polynomial.
36 */
37 int solvePoly(mps_polynomial * poly, PolynomialBasis basis = MONOMIAL,
38 mps_algorithm selected_algorithm = MPS_ALGORITHM_SECULAR_GA,
39 int required_digits = 16, mps_output_goal goal = MPS_OUTPUT_GOAL_APPROXIMATE);
40
41 /**
42 * @brief Solve a polynomial specified by a .pol file.
43 *
44 * @return The degree of the polynomial.
45 */
46 int solvePolFile(QString selectedFile, mps_algorithm selected_algorithm = MPS_ALGORITHM_SECULAR_GA,
47 int required_digits = 16, mps_output_goal goal = MPS_OUTPUT_GOAL_APPROXIMATE);
48
49 /**
50 * @brief solvePolFileFromContent solves a .pol file given its ontent
51 * @param content The content of the desired .pol file
52 * @param selected_algorithm The algorithm to use.
53 * @param required_digits The number of accurate digits required.
54 * @return The degree of the polynomial.
55 */
56 int solvePolFileFromContent(QString content,
57 mps_algorithm selected_algorithm,
58 int required_digits,
59 mps_output_goal goal = MPS_OUTPUT_GOAL_APPROXIMATE);
60
61 /** @brief Parse the string describing the polynomial
62 * and solve it.
63 *
64 * @return The degree of the polynomial.
65 */
66 int solvePoly(QString inputString, PolynomialBasis basis = xmpsolve::MONOMIAL,
67 mps_algorithm = MPS_ALGORITHM_SECULAR_GA,
68 int required_digits = 16,
69 mps_output_goal goal = MPS_OUTPUT_GOAL_APPROXIMATE);
70
71 /**
72 * @brief errorMessage can be used to access the last error message,
73 * if solvePoly() returns -1.
74 * @return A QString describing the last error.
75 */
76 QString errorMessage();
77
78 /**
79 * @brief CPUTime can be used to access the CPU time consumed by the last polynomial
80 * solved. Calling it before solvePoly() leads to undefined behaviour.
81 * @return the number of ms spent on the last polynomial solution.
82 */
83 unsigned long int CPUTime();
84
85 /**
86 * @brief rootsModel returns a pointer to the internal rootsModel that
87 * holds the approximations computed by the algorithm.
88 * @return A pointer to the internal rootsModel.
89 */
90 RootsModel* rootsModel();
91
92 /**
93 * @brief abortComputations kills every current computation.
94 */
95 void abortComputations();
96
97 /** @brief Called when the thread solving the polynomial exits. */
98 void workerExited();
99
100 private:
101 MPSolveWorker m_worker;
102 mps_context * m_mpsContext;
103 mps_polynomial * m_currentPoly;
104 QString m_errorMessage;
105
106 RootsModel m_rootsModel;
107
108 signals:
109 /** @brief Signal emitted when the computation ends. */
110 void solved();
111
112 };
113
114 } // Namespace xmpsolve
115
116 #endif // POLYNOMIALSOLVER_H