1 #ifndef GAUSS_ELIMINATION_H2 #define GAUSS_ELIMINATION_H
3
4 #include
5 #include
6 #include
7 #include
9 #include
10 #include
11 #include
12 #include
13 #include //a private matrix library
14
15 namespacejtf{16 namespacealgorithm{17
18 /**19 * @brief store an expression A * i, where A is the coeffieient20 *21 */
22 template
23 classexpression{24 public:25 expression():index(-1),coefficient(0){}26 expression(const size_t & index_, const T &coefficient_)27 : index(index_), coefficient(coefficient_){}28 size_t index;29 T coefficient;30 /**31 * @brief operator < is used to determin which expression ha32 *33 * @param other input other expression34 * @return bool35 */
36 bool operator < (const expression & b) const{37 return index
40 /**41 * @brief To determin whether coefficent of this expression is zeros42 *43 * @return bool44 */
45 bool is_zero() const{ return fabs(coefficient) < 1e-6;}46 };47
48 /**49 * @brief make expression with node_idx and value50 *51 * @param node_idx52 * @param value53 * @return expression54 */
55 template
56 expression make_expression(const size_t & node_idx, const T &value)57 {58 expressiontemp(node_idx, value);59 returntemp;60 }61
62 /**63 * @brief equation class64 *65 */
66 template
67 classequation{68 public:69 typedef typename std::list >::const_iterator eq_const_iterator;70 typedef typename std::list >::iterator eq_iterator;71
72 equation():value_(static_cast(0)){}73
74 eq_const_iterator begin() const {returne_vec_.begin();}75 eq_iterator begin(){returne_vec_.begin();}76
77 eq_const_iterator end() const {returne_vec_.end();}78 eq_iterator end(){returne_vec_.end();}79
80 /**81 * @brief used to standardizate the equation, sort the expressions and merge82 * similar items and normalization to make the first item's coefficient83 * equal 184 *85 * @return int86 */
87 intstandardization(){88 sort_equation();89 merge_similar();90 normalization();91 return 0;92 }93
94 /**95 * @brief update the equation with given node idx and value96 *97 * @param node_idx input node idx98 * @param node_value input node value99 * @return int100 */
101 int update(const size_t & node_idx, const T &node_value);102 /**103 * @brief sort equation accronding to the expressions104 *105 * @return int106 */
107 intsort_equation(){108 e_vec_.sort();109 return 0;110 }111
112 /**113 * @brief merge similar items, WARNING. this function should be used after114 * sorting.115 *