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/client.h"
19 #include "polymake/topaz/is_sphere_h.h"
20 #include <sstream>
21
22 namespace polymake { namespace topaz {
23
is_manifold_client(BigObject p,OptionSet options)24 Int is_manifold_client(BigObject p, OptionSet options)
25 {
26 const Lattice<BasicDecoration>& HD = p.give("HASSE_DIAGRAM");
27 const bool is_closed = p.give("CLOSED_PSEUDO_MANIFOLD");
28
29 const Int strategy=options["strategy"];
30 Int n_stable_rounds = 0; // meaningless initialization to avoid a compiler warning
31 if (!(options["stable_rounds"] >> n_stable_rounds))
32 n_stable_rounds = (HD.rank()-2)*1000;
33
34 const bool verbose = options["verbose"];
35 const RandomSeed seed(options["seed"]);
36 UniformlyRandom<Integer> random_source(seed);
37
38 bool res_undef = false;
39 for (const auto n : HD.nodes_of_rank(1)) {
40 Int local_strategy = strategy;
41 const std::list<Set<Int>> link = as_iterator_range(link_in_HD(HD, n));
42
43 bool is_bos = (is_closed ? is_sphere_h(link, random_source, local_strategy, n_stable_rounds)
44 : is_ball_or_sphere_h(link, random_source, local_strategy, n_stable_rounds)) > 0;
45
46 while (!is_bos && ++local_strategy <= 1) {
47 if (verbose)
48 cout << "is_manifold_h: after " << n_stable_rounds
49 << " iterations without improvement:\nUnable to determine, whether link("
50 << HD.face(n) << ") is a ball or a sphere.\n"
51 << "Trying strategy " << local_strategy << "." << endl;
52
53 is_bos = (is_closed ? is_sphere_h(link, random_source, local_strategy, n_stable_rounds)
54 : is_ball_or_sphere_h(link, random_source, local_strategy, n_stable_rounds)) > 0;
55 }
56
57 if (!is_bos) {
58 res_undef = true;
59
60 if (verbose)
61 cout << "is_manifold_h: after " << n_stable_rounds
62 << " iterations without improvement:\nUnable to determine, whether link("
63 << HD.face(n) << ") is a ball or a sphere." << endl;
64
65 if (!options["all"]) break;
66 }
67 }
68
69 if (res_undef)
70 return -1;
71 else
72 return 1;
73 }
74
75 Function4perl(&is_manifold_client, "is_manifold_h(SimplicialComplex { strategy=>0, stable_rounds=>undef, verbose=>0, all=>0, seed=>undef })");
76
77 } }
78
79 // Local Variables:
80 // mode:C++
81 // c-basic-offset:3
82 // indent-tabs-mode:nil
83 // End:
84