Version: 1.0
connectivity_graph.h
Go to the documentation of this file.
1 // Copyright (c) 2020, the GRAPHGEN contributors, as
2 // shown by the AUTHORS file. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6 
7 #ifndef GRAPHGEN_CONNECTIVITY_GRAPH_H_
8 #define GRAPHGEN_CONNECTIVITY_GRAPH_H_
9 
10 
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #include "pixel_set.h"
16 
17 #include "rule_set.h" // Da rimuove, provvisorio
18 
19 struct graph {
20  std::vector<std::string> nodes_; // Index -> Name
21  std::map<std::string, size_t> rnodes_; // Name -> Index
22  std::vector<std::vector<int>> arcs_;
23 
24  graph(size_t n) : nodes_(n), arcs_(n, std::vector<int>(n)) {}
25 
26  auto size() const { return nodes_.size(); }
27 
28  auto& operator[](size_t i) { return arcs_[i]; }
29  auto& operator[](size_t i) const { return arcs_[i]; }
30 
31  void set_name(size_t i, const std::string& name) {
32  nodes_[i] = name;
33  rnodes_[name] = i;
34  }
35 
36  // This functions remove the connections between a node and all others
37  void DetachNode(size_t i) {
38  for (size_t j = 0; j < size(); ++j) {
39  arcs_[i][j] = arcs_[j][i] = 0;
40  }
41  }
42  void DetachNode(const std::string& name) { DetachNode(rnodes_[name]); }
43 
44  bool Write(const std::string& filename);
45 };
46 
48 
49 graph MakeConnectivities(const graph& ag);
50 
51 graph MakeConnectivitiesSpecial(const graph& ag, const std::vector<std::string>& pixel_list);
52 
53 std::ostream& operator<<(std::ostream& os, const graph& g);
54 
55 
56 
57 std::vector<std::string> GenerateAllPossibleLabelingActions(const graph& ag);
58 std::vector<std::string> GenerateAllPossibleLabelingActionsGivenTheSetOfPixelToBeLabeled(const graph& ag, const std::vector<std::string>& to_be_labeled_pixels, rule_set& rs);
59 
60 std::vector<std::string> GenerateAllPossibleLabelingActions(const graph& ag, const std::string& ref_pixel_name);
61 
62 #endif // !GRAPHGEN_CONNECTIVITY_GRAPH_H_
graph MakeConnectivitiesSpecial(const graph &ag, const std::vector< std::string > &pixel_list)
std::ostream & operator<<(std::ostream &os, const graph &g)
std::vector< std::string > GenerateAllPossibleLabelingActionsGivenTheSetOfPixelToBeLabeled(const graph &ag, const std::vector< std::string > &to_be_labeled_pixels, rule_set &rs)
VERSION WITH MANY MORE ACTIONS THAN NECESSARY / This function generates all possible actions,...
std::vector< std::string > GenerateAllPossibleLabelingActions(const graph &ag)
graph MakeAdjacencies(const pixel_set &ps)
graph MakeConnectivities(const graph &ag)
std::vector< std::vector< int > > arcs_
void set_name(size_t i, const std::string &name)
std::vector< std::string > nodes_
std::map< std::string, size_t > rnodes_
bool Write(const std::string &filename)
auto size() const
graph(size_t n)
auto & operator[](size_t i)
auto & operator[](size_t i) const
void DetachNode(const std::string &name)
void DetachNode(size_t i)