summaryrefslogtreecommitdiff
path: root/lib/include/network.hpp
blob: bf9015c018576f2d4b8f422d89737452579a8216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

#pragma once

#include <vector>
#include <functional>
#include <utility>
#include <random>
#include <limits>
#include <valarray>
#include <set>

#include "problem.hpp"
#include "graph.hpp"
#include "hooks.hpp"
#include "current_info.hpp"
#include "array_hash.hpp"
#include "clusters.hpp"

#define CURRENT_CUTOFF 1e-10

class network {
  private:
    problem px;
    problem py;
    std::unordered_map<std::array<unsigned, 2>, bool> seen_pairs;

    void update_backbone(const std::vector<double>& c);
    void break_edge(unsigned, bool unbreak = false);
    void get_cycle_edges_helper(std::set<unsigned>&, std::set<unsigned>&, unsigned, unsigned) const;
    std::set<unsigned> get_cycle_edges(unsigned) const;
    std::array<unsigned, 2> find_cycle(const std::set<unsigned>&, unsigned, unsigned) const;

  public:
    const graph& G;

    ClusterTree C;

    std::vector<bool> fuses;
    std::vector<bool> backbone;
    std::vector<long double> thresholds;

    network(const graph&, cholmod_common*);
    network(const network&);

    void set_thresholds(double, std::mt19937&);
    void fracture(hooks&, bool one_axis = true);

    virtual current_info get_current_info() const {current_info empty; return empty;};
};

class fuse_network : public network {
  private:
    double weight;

  public:
    fuse_network(const graph&, cholmod_common*, double weight = 1.0);
    fuse_network(const fuse_network&);

    current_info get_current_info() const override;
};

class elastic_network : public network {
  private:
    double weight;

  public:
    elastic_network(const graph&, cholmod_common*, double weight = 0.5);
    elastic_network(const elastic_network&);

    current_info get_current_info() const override;
};

class percolation_network : public network {
  public:
    percolation_network(const graph&, cholmod_common*);
    percolation_network(const percolation_network&);

    current_info get_current_info() const override;
};