ExactConstraintSatisfaction.hh 2.85 KB
Newer Older
1
2
3
4
#ifndef EXACTCONSTRAINTSATISFACTION_HH
#define EXACTCONSTRAINTSATISFACTION_HH

#include <CoMISo/Config/config.hh>
Robin Brost's avatar
Robin Brost committed
5
#include <CoMISo/Config/CoMISoDefines.hh>
6
7
8

#include <CoMISo/NSolver/NProblemInterface.hh>
#include <vector>
9
#include <time.h>
10

11
12
namespace COMISO {

Robin Brost's avatar
Robin Brost committed
13
class COMISODLLEXPORT ExactConstraintSatisfaction
14
15
16
17
{
public:
    ExactConstraintSatisfaction();

18
    typedef Eigen::SparseVector<int>::InnerIterator iteratorV;
19
20
21
    typedef Eigen::SparseVector<int> sparseVec;
    typedef Eigen::SparseMatrix<int, Eigen::ColMajor> SP_Matrix_C;
    typedef Eigen::SparseMatrix<int, Eigen::RowMajor> SP_Matrix_R;
22
23

    //-----------------------helpfull methods---------------------------------
24
    void   print_matrix(const SP_Matrix_R& A);
25
    void   print_vector(Eigen::VectorXi b);
26
27


Robin Brost's avatar
Robin Brost committed
28
    int    gcd(const int a, const int b);
29
    int    gcd_row(const SP_Matrix_R& A, int row, const int b);
30

Robin Brost's avatar
Robin Brost committed
31
    int    lcm(const int a, const int b);
32
    int    lcm(const std::vector<int>& D);
33

34
    void   swap_rows(SP_Matrix_R& mat,  int row1, int row2);
35
    void   eliminate_row(SP_Matrix_R& mat, Eigen::VectorXi& b, int row1, int row2, int pivot_column);
36
    int    largest_exponent(const Eigen::VectorXd& x);
37
    int    index_pivot(const sparseVec& row);
Robin Brost's avatar
Robin Brost committed
38
    double F_delta(double x);
39
    double get_delta();
Robin Brost's avatar
Robin Brost committed
40

41
42
    //--------------------matrix transformation-------------------------------

43
    void   IREF_Gaussian(SP_Matrix_R& A, Eigen::VectorXi& b, const Eigen::VectorXd& x);
44
    void   IRREF_Jordan(SP_Matrix_R& A, Eigen::VectorXi& b);
45
46
47

    //-------------------Evaluation--------------------------------------------

48
    void   evaluation(SP_Matrix_R& _A, Eigen::VectorXi& b, Eigen::VectorXd& x);
49
    double makeDiv(const std::vector<int>& D, double x);
50
    double safeDot(const std::vector<std::pair<int, double> >& S);
51
    void   evaluate(const SP_Matrix_R& _A, const Eigen::VectorXi& b, Eigen::VectorXd& x);
52
53
54

private:

55
56
57
58
    // for IREF
    int get_pivot_col_student(SP_Matrix_R& _A, int k, int& col_index);
    int get_pivot_col_new(SP_Matrix_R& _A, int k, int& col_index);

59
60
    // for evaluation

61
62
63
    int get_pivot_row_student(const SP_Matrix_C& A, int col);
    int get_pivot_row_new(const SP_Matrix_C& A, const SP_Matrix_R& _A, int col);

64
65
66
    std::vector<int> get_divisors_student(const SP_Matrix_C& A, int col);
    std::vector<int> get_divisors_new(const SP_Matrix_C& A, const SP_Matrix_R& _A, int col);

67
68
69
    std::vector<std::pair<int, double>> get_dot_product_elements_student(const SP_Matrix_C& A, const Eigen::VectorXd& x, int k, int pivot_row);
    std::vector<std::pair<int, double>> get_dot_product_elements_new(const SP_Matrix_R& A, const Eigen::VectorXd& x, int pivot_row);

70
71
    //-----------------------helpfull variables-------------------------------

Robin Brost's avatar
Robin Brost committed
72
73
74
    int    number_pivots_ = 0; //number of rows with a pivot;
    int    largest_exponent_ = 0;
    double delta_ = 0;
75
76
};

77
78
}

79
#endif // EXACTCONSTRAINTSATISFACTION_HH