Level.hpp 2.7 KB
Newer Older
1
2
3
#ifndef LEVEL_HPP
#define LEVEL_HPP

niklas.baumgarten's avatar
niklas.baumgarten committed
4
#include "Logging.hpp"
5
6
7
8
9
10
#include <vector>
#include <map>


/*
 * Todo:
niklas.baumgarten's avatar
niklas.baumgarten committed
11
 * * idea: make second key template for degree
12
 *   to realize MultidegreeMonteCarlo
niklas.baumgarten's avatar
niklas.baumgarten committed
13
 * && ?
14
15
16
 */

template<typename T>
niklas.baumgarten's avatar
niklas.baumgarten committed
17
18
struct LevelMap {
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
19
    std::map<int, T> _levelMap;
niklas.baumgarten's avatar
niklas.baumgarten committed
20
21

public:
22
23
    LevelMap() {};

niklas.baumgarten's avatar
niklas.baumgarten committed
24
25
    LevelMap(std::initializer_list<std::pair<int, T>> levelMap) {
        for (std::pair<int, T> pair : levelMap) {
niklas.baumgarten's avatar
niklas.baumgarten committed
26
            _levelMap.emplace(pair.first, T(pair.second));
27
        }
28
29
    }

30
31
    std::vector<int> GetLevelVector() const {
        std::vector<int> levelVector;
niklas.baumgarten's avatar
niklas.baumgarten committed
32
        for (auto &&[level, entry]: _levelMap)
niklas.baumgarten's avatar
niklas.baumgarten committed
33
            levelVector.push_back(level);
34
        return levelVector;
35
36
    }

37
38
    std::vector<double> GetQVector() const {
        std::vector<double> qVector;
niklas.baumgarten's avatar
niklas.baumgarten committed
39
        for (auto &&[level, entry]: _levelMap)
40
41
            qVector.push_back(entry.Q);
        return qVector;
42
43
    }

44
45
    std::vector<double> GetYVector() const {
        std::vector<double> yVector;
niklas.baumgarten's avatar
niklas.baumgarten committed
46
        for (auto &&[level, entry]: _levelMap)
47
48
            yVector.push_back(entry.Y);
        return yVector;
49
50
    }

51
52
    std::vector<double> GetCostVector() const {
        std::vector<double> costVector;
niklas.baumgarten's avatar
niklas.baumgarten committed
53
        for (auto &&[level, entry]: _levelMap)
niklas.baumgarten's avatar
niklas.baumgarten committed
54
            costVector.push_back(entry.C);
55
        return costVector;
56
57
    }

58
59
    std::vector<int> GetMVector() const {
        std::vector<int> mVector;
niklas.baumgarten's avatar
niklas.baumgarten committed
60
        for (auto &&[level, entry]: _levelMap)
61
62
            mVector.push_back(entry.M);
        return mVector;
63
64
    }

65
66
    std::vector<int> GetdMVector() const {
        std::vector<int> dMVector;
niklas.baumgarten's avatar
niklas.baumgarten committed
67
        for (auto &&[level, entry]: _levelMap)
68
69
            dMVector.push_back(entry.dM);
        return dMVector;
70
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
71
72
73
74
75

    auto size() const { return _levelMap.size(); }

    auto clear() { _levelMap.clear(); }

niklas.baumgarten's avatar
niklas.baumgarten committed
76
    auto insert(std::pair<int, T> pair) { _levelMap.insert(pair); }
niklas.baumgarten's avatar
niklas.baumgarten committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

    auto begin() { return _levelMap.begin(); }

    auto rbegin() { return _levelMap.rbegin(); }

    auto end() { return _levelMap.end(); }

    auto rend() { return _levelMap.end(); }

    auto begin() const { return _levelMap.begin(); }

    auto rbegin() const { return _levelMap.rbegin(); }

    auto end() const { return _levelMap.end(); }

    auto rend() const { return _levelMap.end(); }

niklas.baumgarten's avatar
niklas.baumgarten committed
94
    auto operator[](int level) { return _levelMap[level]; }
niklas.baumgarten's avatar
niklas.baumgarten committed
95

niklas.baumgarten's avatar
niklas.baumgarten committed
96
    auto at(int level) { return _levelMap.at(level); }
niklas.baumgarten's avatar
niklas.baumgarten committed
97

niklas.baumgarten's avatar
niklas.baumgarten committed
98
    auto find(int level) { return _levelMap.find(level); }
niklas.baumgarten's avatar
niklas.baumgarten committed
99
100
101
102
103
104
105
106
107

    friend Logging &operator<<(Logging &s, const LevelMap<T> &levelMap) {
        s << "[";
        for(auto &[level, entry] : levelMap) {
            if(level != levelMap.rbegin()->first) s << entry << ", ";
            else s << entry;
        }
        return s << "]";
    }
108
109
110
};

#endif //LEVEL_HPP