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 <string>
19 #include "polymake/client.h"
20 #include "polymake/Array.h"
21 #include "polymake/PowerSet.h"
22 #include "polymake/vector"
23 #include "polymake/common/labels.h"
24
25 namespace polymake { namespace topaz {
26
clique_complex(BigObject graph,OptionSet options)27 BigObject clique_complex(BigObject graph, OptionSet options)
28 {
29 const PowerSet<Int> maxCliques = graph.give("MAX_CLIQUES");
30 const bool no_labels = options["no_labels"];
31
32 BigObject complex("topaz::SimplicialComplex");
33 complex.set_description() << "Clique complex of graph " << graph.name() << "." << endl;
34 complex.take("FACETS") << as_array(maxCliques);
35
36 if (!no_labels) {
37 const Int n_nodes = graph.give("N_NODES");
38 const std::vector<std::string> labels = common::read_labels(graph, "NODE_LABELS", n_nodes);
39 complex.take("VERTEX_LABELS") << labels;
40 }
41 return complex;
42 }
43
44 UserFunction4perl("# @category Producing a simplicial complex from other objects\n"
45 "# Produce the __clique complex__ of a given graph, that is, the simplicial"
46 "# complex that has an n-dimensional facet for each n+1-clique.\n"
47 "# If //no_labels// is set to 1, the labels are not copied.\n"
48 "# @param Graph graph"
49 "# @option Bool no_labels Do not create [[VERTEX_LABELS]]. default: 0"
50 "# @return SimplicialComplex"
51 "# @example Create the clique complex of a simple graph with one 3-clique and"
52 "# one 2-clique, not creating labels."
53 "# > $g = graph_from_edges([[0,1],[0,2],[1,2],[2,3]]);"
54 "# > $c = clique_complex($g,no_labels=>1);"
55 "# > print $c->FACETS;"
56 "# | {0 1 2}"
57 "# | {2 3}",
58 &clique_complex,"clique_complex(Graph; { no_labels => 0 })");
59 } }
60
61 // Local Variables:
62 // mode:C++
63 // c-basic-offset:3
64 // indent-tabs-mode:nil
65 // End:
66