summaryrefslogtreecommitdiff
path: root/lib/include/network.hpp
blob: 37f19122d29d027c681c93d90b9f7e20a653a154 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

#pragma once

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

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

#define CURRENT_CUTOFF 1e-10

class fuse_network;
class elastic_network;
class percolation_network;

class network {
  friend class fuse_network;
  friend class elastic_network;
  friend class percolation_network;

private:
  problem px;
  problem py;
  std::unordered_map<std::array<unsigned, 2>, bool> seen_pairs_x;
  std::unordered_map<std::array<unsigned, 2>, bool> seen_pairs_y;

  void update_backbone(const std::vector<double>& c, const std::array<double, 2>& cond);
  void break_edge(unsigned, bool unbreak = false);
  void get_cycle_edges_helper(std::set<unsigned>&, std::set<unsigned>&, unsigned, unsigned) const;
  bool find_cycle_helper(std::array<unsigned, 2>&, const std::set<unsigned>&, unsigned, unsigned,
                         unsigned) const;
  bool get_cycle_helper(std::array<unsigned, 2>&, std::set<unsigned>&, const std::set<unsigned>&, unsigned, unsigned,
                         unsigned) const;
  std::array<unsigned, 2> find_cycle(const std::set<unsigned>&, unsigned, unsigned) const;
  void get_cluster_edges_helper(std::set<unsigned>&, unsigned) const;
  std::set<unsigned> get_cluster_edges(unsigned) const;
  void get_tie_flaps_helper(std::set<unsigned>&, unsigned, unsigned) const;
  std::list<std::set<unsigned>> get_tie_flaps(unsigned) const;

public:
  bool two_sides;
  const graph& G;

  ClusterTree C;

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

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

  void set_thresholds(double, std::mt19937&);
  void fracture(hooks&);

  std::set<unsigned> get_cycle_edges(unsigned) const;
  std::pair<std::array<unsigned, 2>, std::set<unsigned>> get_cycle(const std::set<unsigned>&, unsigned, unsigned) const;

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

  std::string write();
};

class fuse_network : public network {
private:
  double weight;

public:
  fuse_network(const graph&, cholmod_common*);
  fuse_network(const fuse_network&);

  current_info get_current_info() 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() override;
};

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

  current_info get_current_info() override;
};