Commit e1a2b340 authored by Romina Julieta Parada Venossa's avatar Romina Julieta Parada Venossa
Browse files

erase and add v not working

parent e7b80441
......@@ -107,7 +107,7 @@ struct genericGraph {
std::pair<AdjacencyIterator, AdjacencyIterator> vs() { return vertices(g); }
int deg(pos p) { return degree(positions[p], g); }
int deg(pos p) { return out_degree(positions[p], g); }
};
template <typename graph>
......@@ -170,6 +170,13 @@ struct collapsedGraph : genericGraph<graph> {
boost::unordered_set<pos> full_graph;
boost::unordered_map<pos, bool> is_local_min;
int deg(pos p) {
pos_set adj_p = all_adj(p);
return accumulate(adj_p.begin(), adj_p.end(), 0,
[this](int deg, pos n) { return deg + is_elem(full_graph, n); });
}
// vertex is uncollapsed
bool is_uncollapsed(pos p) { return is_elem(this->positions, p); }
......@@ -178,15 +185,33 @@ struct collapsedGraph : genericGraph<graph> {
// TODO
bool is_collapsable(pos p) {
if(deg(p) != 2){
return false;
}
return super::deg(p) == 2 && true;//!is_local_min[p];
AdjacencyIterator it, it_end;
boost::tie(it, it_end) = super::neighbors(p);
pos n1 = this->g[*it].p;
pos dir1 = n1 - p;
it++;
pos n2 = this->g[*it].p;
pos dir2 = n2 - p;
return same_direction(dir1,dir2);
}
bool is_uncollapsable(pos p) { return !is_collapsable(p); }
// get
pos get_uncollapsed_neighbor(pos p, pos dir) {
for (p += dir; !is_uncollapsed(p); p += dir);
for (p += dir; !is_uncollapsed(p); p += dir){
cout<<p<<endl;
if(!is_elem(full_graph, p)){
cout<<"warning: "<<p<<endl;
return p - dir;
}
}
return p;
}
......@@ -194,6 +219,7 @@ struct collapsedGraph : genericGraph<graph> {
// from: a---------b
// to: a----p----b
void uncollapse(pos p) {
cout<<"uncollapsing p "<<p<<endl;
super::add_v(p);
// check for neighbors
......@@ -224,15 +250,14 @@ struct collapsedGraph : genericGraph<graph> {
AdjacencyIterator it, it_end;
boost::tie(it, it_end) = super::neighbors(p);
pos adj1 = this->g[*it].p - p;
++it;
pos adj2 = this->g[*it].p - p;
if(same_direction(adj1,adj2)){
super::add_e(adj1, adj2);
super::add_e(adj2, adj1);
super::erase_v(p);
}
pos n1 = this->g[*it].p;
it++;
pos n2 = this->g[*it].p;
super::add_e(n1, n2);
super::add_e(n2, n1);
super::erase_v(p);
cout<<"SE COLAPSO P: "<<p<<endl;
}
// uncollapse all collapsed of neighbors p
......@@ -262,6 +287,7 @@ struct collapsedGraph : genericGraph<graph> {
// Los vecinos de los vecinos de un nodo p, que se agrega o se remueve no van a colapsarse o descolapsarse. Solo los vecinos del grafo full.
void erase_v(pos p) {
cout<<"ENTRO AL ERASE V CON P: "<<p<<endl;
// 0. erase from uncollapsed
full_graph.erase(p);
......@@ -278,9 +304,10 @@ struct collapsedGraph : genericGraph<graph> {
}
void add_v(pos p) {
/*if (is_elem(full_graph, p)) {
cout<<"ENTRO AL ADD V CON P: "<<p<<endl;
if (is_elem(full_graph, p)) {
/// update local min
if(is_local_min[p]){
/*if(is_local_min[p]){
if(is_collapsed(p)){
uncollapse(p);
}
......@@ -288,35 +315,51 @@ struct collapsedGraph : genericGraph<graph> {
if(is_collapsable(p)){
collapse(p);
}
}
}*/
return;
}*/
// 0. add to uncollapsed
full_graph.insert(p);
}
// TODO may not be true (adding an aleardy added)
// 1. uncolloapse collapsed neighbors of p
// 0. uncolloapse collapsed neighbors of p
cout<<"PASO 0 CON P: "<<p<<endl;
uncollapse_neighbors(p, true);
// 1. add to uncollapsed
cout<<"PASO 1 CON P: "<<p<<endl;
full_graph.insert(p);
// 2. connect all the neighbors of p (already done in step 1)
cout<<"PASO 2 CON P: "<<p<<endl;
super::add_v(p);
pos_set adj = all_adj(p);
for (auto it = adj.begin(); it != adj.end(); it++) {
pos n = *it;
if(is_elem(full_graph, n)){
super::add_e(p, n);
super::add_e(n, p);
}
}
// 3. collapse p if possible
cout<<"PASO 3 CON P: "<<p<<endl;
if(is_collapsable(p)){
collapse(p);
}
// 4. collapse neighbors of p if possible
cout<<"PASO 4 CON P: "<<p<<endl;
collapse_neighbors(p);
}
void add_v(pos_set to_add) {
for (auto it = to_add.begin(); it != to_add.end(); it++) {
pos p = *it;
//add_v(*it); //TODO descomentar esto y borrar lo de abajo (lo hice para probar)
super::add_v(p);
full_graph.insert(p);
//pos p = *it;
add_v(*it); //TODO descomentar esto y borrar lo de abajo (lo hice para probar)
//super::add_v(p);
//full_graph.insert(p);
}
}
};
......
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment