12 for (
size_t i = 0; i < g.
size(); ++i)
15 for (
size_t i = 0; i < g.
size(); ++i) {
16 for (
size_t j = i; j < g.
size(); ++j) {
17 g[i][j] = g[j][i] = ChebyshevDistance(ps[i], ps[j]) <= 1;
24 static void MakeConnectivitiesRec(
size_t i,
size_t j,
graph& g,
const graph& ag, std::set<size_t>& visited) {
25 for (
size_t k = 0; k < g.
size(); ++k) {
26 if (visited.find(k) == visited.end() && ag[j][k]) {
30 MakeConnectivitiesRec(i, k, g, ag, visited);
39 for (
size_t i = 0; i < g.
size(); ++i) {
41 std::set<size_t> visited;
42 MakeConnectivitiesRec(i, i, g, ag, visited);
49 static void MakeConnectivitiesRecSpecial(
size_t i,
size_t j,
graph& g,
const graph& ag, std::set<size_t>& visited,
const std::vector<std::string>& pixel_list) {
50 for (
size_t k = 0; k < g.
size(); ++k) {
51 if (visited.find(k) == visited.end() && ag[j][k]) {
54 if (std::count(pixel_list.begin(), pixel_list.end(), g.
nodes_[k]) == 0)
55 MakeConnectivitiesRecSpecial(i, k, g, ag, visited, pixel_list);
64 for (
size_t i = 0; i < g.
size(); ++i) {
66 std::set<size_t> visited;
67 MakeConnectivitiesRecSpecial(i, i, g, ag, visited, pixel_list);
75 using std::copy;
using std::begin;
using std::end;
using std::string;
77 copy(begin(g.
nodes_), end(g.
nodes_), std::ostream_iterator<string>(os,
" "));
80 for (
size_t i = 0; i < g.
arcs_.size(); ++i) {
82 copy(begin(g.
arcs_[i]), end(g.
arcs_[i]), std::ostream_iterator<int>(os,
" "));
91 std::ofstream os(filename);
104 bool operator()(
const std::bitset<N>& lhs,
const std::bitset<N>& rhs)
const {
105 return lhs.to_string() < rhs.to_string();
112 auto nconds = ag.
size();
113 auto nrules = 1u << nconds;
114 std::set<std::bitset<128>,
less<128>> actions_set;
115 std::vector<std::string> actions = {
"nothing" };
117 auto posx = ag.
rnodes_.at(
"x");
119 if ((
rule >> posx) & 1) {
120 std::bitset<128> cur_action = 0;
121 std::vector<size_t> cur_conds;
122 for (
size_t j = 0; j < nconds; ++j) {
123 if (j != posx && ((
rule >> j) & 1) == 1) {
125 for (
size_t k = 0; k < cur_conds.size(); ++k) {
126 if (ag[j][cur_conds[k]] == 1) {
131 cur_conds.push_back(j);
137 actions_set.insert(cur_action);
141 for (
const auto& a : actions_set) {
142 std::string action =
"x<-";
143 for (
size_t j = 0; j < nconds; ++j) {
145 action += ag.
nodes_[j] +
"+";
149 action +=
"newlabel";
151 action.resize(action.size() - 1);
153 actions.push_back(action);
163 auto nconds = ag.
size();
164 auto nrules = 1u << nconds;
165 std::set<std::bitset<128>,
less<128>> actions_set;
166 std::vector<std::string> actions = {
"nothing" };
168 auto posx = ag.
rnodes_.at(ref_pixel_name);
170 if ((
rule >> posx) & 1) {
171 std::bitset<128> cur_action = 0;
172 std::vector<size_t> cur_conds;
173 for (
size_t j = 0; j < nconds; ++j) {
174 if (j != posx && ((
rule >> j) & 1) == 1) {
176 for (
size_t k = 0; k < cur_conds.size(); ++k) {
177 if (ag[j][cur_conds[k]] == 1) {
182 cur_conds.push_back(j);
188 actions_set.insert(cur_action);
192 for (
const auto& a : actions_set) {
193 std::string action = ref_pixel_name +
"<-";
194 for (
size_t j = 0; j < nconds; ++j) {
196 action += ag.
nodes_[j] +
"+";
199 if (action == ref_pixel_name +
"<-")
200 action +=
"newlabel";
202 action.resize(action.size() - 1);
204 actions.push_back(action);
211 for (
const auto& x : to_print) {
212 os << x.to_string().substr(119) <<
"\n";
341 std::set<std::string> actions;
343 auto nconds = ag.
size();
344 auto nrules = 1u << nconds;
346 for (
int i = 0; i < static_cast<int>(nrules); ++i) {
350 for (
size_t j = 0; j < lag.size(); ++j) {
351 if (((i >> j) & 1) == 0)
355 std::vector<std::string> e_actions;
359 con.data_ = cg.
arcs_;
361 MultiMergeSet mse(con, std::vector<std::string>({
"e",
"g",
"i" }), std::string(
"e"));
364 std::string action =
"e<-";
366 action +=
"newlabel";
369 for (
size_t i = 1; i < s.size(); ++i)
370 action +=
"+" + s[i];
372 e_actions.push_back(action);
376 e_actions.push_back(
"nothing");
379 std::vector<std::string> g_actions;
383 con.data_ = cg.
arcs_;
384 MultiMergeSet msg(con, std::vector<std::string>({
"g",
"i" }), std::string(
"g"));
388 std::string action =
"g<-";
390 action +=
"newlabel";
393 for (
size_t i = 1; i < s.size(); ++i)
394 action +=
"+" + s[i];
396 g_actions.push_back(action);
400 g_actions.push_back(
"nothing");
403 std::vector<std::string> i_actions;
407 con.data_ = cg.
arcs_;
408 MultiMergeSet msi(con, std::vector<std::string>({
"i" }), std::string(
"i"));
412 std::string action =
"i<-";
414 action +=
"newlabel";
417 for (
size_t i = 1; i < s.size(); ++i)
418 action +=
"+" + s[i];
420 i_actions.push_back(action);
424 i_actions.push_back(
"nothing");
427 for (
const auto& ae : e_actions) {
428 for (
const auto& ag : g_actions) {
429 for (
const auto& ai : i_actions) {
430 std::string es = ae, gs = ag, is = ai;
431 size_t found = es.find(gs.substr(3));
432 if (found != std::string::npos && es !=
"nothing" && es !=
"e<-newlabel") {
435 found = es.find(is.substr(3));
436 if (found != std::string::npos && es !=
"nothing" && es !=
"e<-newlabel") {
439 found = gs.find(is.substr(3));
440 if (found != std::string::npos && gs !=
"nothing" && gs !=
"g<-newlabel") {
443 actions.insert(es +
"," + gs +
"," + is);
449 std::vector<std::string> return_val(actions.size());
450 std::copy(actions.begin(), actions.end(), return_val.begin());
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)
void PrintActionsSet(std::set< std::bitset< 128 >, less< 128 >> &to_print, std::ostream &os)
std::set< std::vector< std::string > > mergesets_
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)
void DetachNode(size_t i)
bool operator()(const std::bitset< N > &lhs, const std::bitset< N > &rhs) const
std::vector< std::string > conditions