1 /* Copyright (c) 1997-2021
2    Ewgenij Gawrilow, Michael Joswig, and the polymake team
3    Technische Universität Berlin, Germany
4    https://polymake.org
5 
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version: http://www.gnu.org/licenses/gpl.txt.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 --------------------------------------------------------------------------------
16 */
17 
18 #include "polymake/topaz/complex_tools.h"
19 
20 namespace polymake { namespace topaz {
21 
is_pure(const Lattice<BasicDecoration> & HD)22 bool is_pure(const Lattice<BasicDecoration>& HD)
23 {
24    Int test_dim = -1;
25    for (auto it=entire(HD.in_edges(HD.top_node())); !it.at_end(); ++it) {
26       const Int n = it.from_node();
27 
28       if (test_dim == -1)  // first facet
29          test_dim = HD.face(n).size()-1;
30       else if ( HD.face(n).size()-1 != test_dim )
31          return false;
32    }
33    return true;
34 }
35 
vertices_of_vertex_link(const Lattice<BasicDecoration> & HD,const Int v)36 Set<Int> vertices_of_vertex_link(const Lattice<BasicDecoration>& HD, const Int v)
37 {
38    Set<Int> V;
39    accumulate_in(vertex_star_in_HD(HD,v), operations::add(), V);
40    V -= v;
41    return V;
42 }
43 
remove_vertex_star(ShrinkingLattice<BasicDecoration> & HD,const Int v)44 void remove_vertex_star(ShrinkingLattice<BasicDecoration>& HD, const Int v)
45 {
46    graph::BFSiterator< Graph<Directed> > n_it(HD.graph(), find_vertex_node(HD,v));
47    const Int top_node = HD.top_node();
48 
49    // remove all nodes of the HD that can be reached from start_node
50    while (!n_it.at_end()) {
51       const Int n = *n_it;  ++n_it;
52       if (n != top_node) {
53          for (auto e=entire(HD.in_edges(n)); !e.at_end(); ++e) {
54             const Int nn = e.from_node();
55             if (HD.out_degree(nn) == 1)
56                HD.graph().edge(nn,top_node);
57          }
58          HD.graph().out_edges(n).clear();
59          HD.graph().in_edges(n).clear();
60       }
61    }
62 
63    HD.delete_nodes(n_it.node_visitor().get_visited_nodes()-top_node);
64    HD.set_implicit_top_rank();
65 }
66 
remove_facet_node(ShrinkingLattice<BasicDecoration> & HD,const Int start_node)67 void remove_facet_node(ShrinkingLattice<BasicDecoration>& HD, const Int start_node)
68 {
69    graph::BFSiterator<Graph<Directed>, graph::TraversalDirectionTag<int_constant<-1>>> n_it(HD.graph(), start_node);
70    const Int bottom_node = HD.bottom_node();
71    HD.graph().out_edges(start_node).clear();
72    Set<Int> to_delete;
73 
74    // remove all nodes of the HD that can be reached from start_node only
75    while (!n_it.at_end()) {
76       const Int n = *n_it;
77       if (n == bottom_node || HD.graph().out_degree(n)) {
78          n_it.skip_node();
79       } else {
80          to_delete+=n;
81          ++n_it;
82          HD.graph().in_edges(n).clear();
83       }
84    }
85 
86    HD.delete_nodes(to_delete);
87    HD.set_implicit_top_rank();
88 }
89 
90 } }
91 
92 // Local Variables:
93 // mode:C++
94 // c-basic-offset:3
95 // indent-tabs-mode:nil
96 // End:
97