File: compactification.h

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (256 lines) | stat: -rw-r--r-- 6,669 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* Copyright (c) 1997-2024
   Ewgenij Gawrilow, Michael Joswig, and the polymake team
   Technische Universität Berlin, Germany
   https://polymake.org

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
*/

#pragma once

#include "polymake/client.h"
#include "polymake/Matrix.h"
#include "polymake/Map.h"
#include "polymake/Set.h"
#include "polymake/linalg.h"
#include "polymake/graph/Decoration.h"
#include "polymake/graph/Lattice.h"
#include "polymake/fan/hasse_diagram.h"

namespace polymake { namespace fan{
namespace compactification {
	
using graph::Lattice;
using namespace graph::lattice;
using namespace fan::lattice;

struct IteratorWrap {
  FacetList groundSet;
  FacetList::const_iterator state;

  IteratorWrap(FacetList&& gs)
    : groundSet(std::move(gs))
    , state(groundSet.begin()) {}

  Set<Int> operator*()
  {
    return *state;
  }

  IteratorWrap& operator++()
  {
    ++state;
    return *this;
  }

  bool at_end()
  {
    return state == groundSet.end();
  }
};


template <typename DecorationType, typename Scalar>
class CellularClosureOperator {
private:
  FaceMap<> face_index_map;
  Map<Int, Set<Int>> int2vertices;
  Map<Set<Int>, Int> vertices2int;
  Int nVertices;
  Set<Int> farVertices;
  Matrix<Scalar> vertices;
  Lattice<BasicDecoration, Nonsequential> oldHasseDiagram;

public:
  typedef Set<Int> ClosureData;

  CellularClosureOperator(BigObject pc)
  {
    pc.give("FAR_VERTICES") >> farVertices;
    pc.give("VERTICES") >> vertices;
    pc.give("HASSE_DIAGRAM") >> oldHasseDiagram;
    nVertices = vertices.rows();
    Set<Int> topNode{-1};
    Int i = 0;

    // Build new vertices
    for (const auto& f : oldHasseDiagram.decoration()) {
      if (f.face != topNode) { 
        Int faceDim = f.rank-1;
        Int tailDim = rank(vertices.minor(f.face * farVertices, All));
        if (faceDim == tailDim) {
          int2vertices[i] = f.face;
          vertices2int[f.face] = i;
          ++i;
        }
      }
    }
  }

  Set<Int> old_closure(const Set<Int>& a) const
  {
    // We find a closure of a face in the old Hasse diagram by starting
    // at the top node and then descending into lower nodes whenever
    // they contain the given set of vertices. If no further descent is
    // possible, we terminate.
    Int currentNode = oldHasseDiagram.top_node();
    const Graph<Directed>& G(oldHasseDiagram.graph());
    bool found = true;
    while (found) {
      found = false;
      for (const auto p : G.in_adjacent_nodes(currentNode)) {
        const BasicDecoration& decor = oldHasseDiagram.decoration(p);
        if (incl(a, decor.face) <= 0) {
          found = true;
          currentNode = p;
          break;
        }
      }
    }
    return oldHasseDiagram.decoration(currentNode).face;
  }

  Set<Int> closure(const Set<Int>& a) const
  {
    Set<Int> originalRealisation;
    for (const auto i : a) {
      originalRealisation += int2vertices[i];
    }
    Set<Int> originalClosure = old_closure(originalRealisation);
    Set<Int> commonRays = originalRealisation * farVertices;
    for (const auto i : a) {
      commonRays = commonRays * int2vertices[i];
    }
    Set<Int> result;
    for (const auto& v : vertices2int) {
      if (incl(commonRays, v.first) <= 0 && incl(v.first, originalClosure) <= 0) {
        result += v.second;
      }
    }
    return result;
  }

  Set<Int> closure_of_empty_set()
  {
    return Set<Int>{};
  }

  FaceIndexingData get_indexing_data(const ClosureData& data)
  {
    Int& fi = face_index_map[data];
    return FaceIndexingData(fi, fi == -1, fi == -2);
  }

  Set<Int> compute_closure_data(const DecorationType& bd) const
  {
    return bd.face;
  }

  IteratorWrap get_closure_iterator(const Set<Int>& face) const
  {
    Set<Int> toadd = sequence(0, int2vertices.size())-face;
    FacetList result;
    for (auto i : toadd) {
      result.insertMin(closure(face+i));
    }
    return IteratorWrap(std::move(result));
  }

  const Map<Int, Set<Int>>& get_int2vertices() const
  {
    return int2vertices;
  }

  const Set<Int>& get_farVertices() const
  {
    return farVertices;
  }
};
   
   
struct SedentarityDecoration
  : public GenericStruct<SedentarityDecoration> {
     DeclSTRUCT( DeclFIELD(face, Set<Int>)
                 DeclFIELD(rank, Int)
                 DeclFIELD(realisation, Set<Int>) 
                 DeclFIELD(sedentarity, Set<Int>) );

     SedentarityDecoration() {}
     SedentarityDecoration(const Set<Int>& f, Int r, const Set<Int>& re, const Set<Int>& se)
       : face(f)
       , rank(r)
       , realisation(re)
       , sedentarity(se) {}
};

class SedentarityDecorator {
private:
  const Map<Int, Set<Int>>& int2vertices;
  const Set<Int>& farVertices;

  Set<Int> realisation(const Set<Int>& face) const
  {
    Set<Int> result;
    for (const auto& e : face) {
      result += int2vertices[e];
    }
    return result;
  }

  Set<Int> sedentarity(const Set<Int>& face) const
  {
    if (face.size() == 0) {
      return Set<Int>{};
    }
    Set<Int> result(farVertices);
    for (const auto& e:face){
      result *= int2vertices[e];
    }
    return result;
  }

public:
  typedef SedentarityDecoration DecorationType;
  SedentarityDecorator(const Map<Int, Set<Int>>& i2v, const Set<Int>& fv)
    : int2vertices(i2v)
    , farVertices(fv) {}

  SedentarityDecoration compute_initial_decoration(const Set<Int>& face) const
  {
    return SedentarityDecoration(face, 0, realisation(face), sedentarity(face));
  }

  SedentarityDecoration compute_decoration(const Set<Int>& face, const SedentarityDecoration& bd) const
  {
    return SedentarityDecoration(face, bd.rank+1, realisation(face), sedentarity(face));
  }

  SedentarityDecoration compute_artificial_decoration(const NodeMap<Directed, SedentarityDecoration>& decor, const std::list<Int>& max_faces) const
  {
    const Set<Int> D{-1};
    Int rank = 0;
    for (const auto& mf : max_faces) {
      assign_max(rank, decor[mf].rank);
    }
    ++rank;
    return SedentarityDecoration(D, rank, D, Set<Int>{});
  }
};

} } }


// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End: