File: PointConfiguration.cc

package info (click to toggle)
topcom 1.1.2%2Bds-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 31,788 kB
  • sloc: cpp: 37,616; sh: 4,262; makefile: 497; ansic: 49
file content (249 lines) | stat: -rw-r--r-- 7,524 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
////////////////////////////////////////////////////////////////////////////////
// 
// PointConfiguration.cc
//
//    produced: 13/03/98 jr
// last change: 13/03/98 jr
// 
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <ctype.h>
#include <string.h>

#include "PointConfiguration.hh"
#include "Chirotope.hh"
#include "PlacingTriang.hh"
#include "StairCaseMatrix.hh"
#include "StrictStairCaseMatrix.hh"
#include "StrictStairCaseMatrixTrans.hh"
#include "Symmetry.hh"
#include "SimplicialComplex.hh"


namespace topcom {

  const int PointConfiguration::zeroes_in_row(const size_type index) const {
    int result = 0;
    for (size_type i = 0; i < coldim(); ++i) {
      if ((*this)(index,i) == FieldConstants::ZERO) {
	++result;
      }
    }
    return result;
  }

  const int PointConfiguration::zeroes_in_col(const size_type index) const {
    int result = 0;
    for (size_type i = 0; i < rowdim(); ++i) {
      if ((*this)(i,index) == FieldConstants::ZERO) {
	++result;
      }
    }
    return result;
  }

  const Field PointConfiguration::volume() const {
    Field result(0);
    const PlacingTriang pt(Chirotope(*this, false));
    for (SimplicialComplex::const_iterator iter = pt.begin();
	 iter != pt.end();
	 ++iter) {
      result += volume(*iter);
    }
    return result;
  }

  const Field PointConfiguration::volume(const Simplex& simp) const {
    StairCaseMatrix basis_matrix;
    for (Simplex::const_iterator iter = simp.begin();
	 iter != simp.end();
	 ++iter) {
      basis_matrix.augment(this->col(*iter));
    }
    return abs(basis_matrix.det());
  }
  
  PointConfiguration& PointConfiguration::prism() {
    PointConfiguration new_cols(*this);
    for (size_type i = 0; i < no(); ++i) {
      this->col(i).push_back(FieldConstants::ZERO);
      new_cols.col(i).push_back(FieldConstants::ONE);
    }
#ifndef STL_CONTAINERS
    push_back(new_cols);
#else
    insert(end(), new_cols.begin(), new_cols.end());
#endif
    return *this;
  }

  PointConfiguration& PointConfiguration::pyramid() {
    Vector new_col(rank(), FieldConstants::ZERO);
    for (size_type i = 0; i < no(); ++i) {
      this->col(i).push_back(FieldConstants::ZERO);
    }
    new_col.push_back(FieldConstants::ONE);
    push_back(new_col);
    return *this;
  }

  PointConfiguration& PointConfiguration::direct_sum(const PointConfiguration& p) {
    PointConfiguration new_cols = Matrix(rank(), p.no(), FieldConstants::ZERO);
    for (size_type i = 0; i < no(); ++i) {
#ifndef STL_CONTAINERS
      this->(i).push_back(Vector(p.rank(), FieldConstants::ZERO));
#else
      Vector extension(p.rank(), FieldConstants::ZERO);
      this->col(i).insert(this->col(i).end(), extension.begin(), extension.end()); 
#endif
    }
    for (size_type i = 0; i < p.no(); ++i) {
#ifndef STL_CONTAINERS
      new_cols.col(i).push_back(p.col(i));
#else
      new_cols.col(i).insert(new_cols.col(i).end(), p.col(i).begin(), p.col(i).end());
#endif
    }
#ifndef STL_CONTAINERS
    push_back(new_cols);
#else
    insert(end(), new_cols.begin(), new_cols.end());
#endif
    return *this;
  }

  PointConfiguration& PointConfiguration::homogenize() {
    stack(Matrix(1, no(), FieldConstants::ONE));
    return *this;
  }

  PointConfiguration& PointConfiguration::transform_to_full_rank() {
    pretty_print(std::cerr);
    Matrix::row_echelon_form();
    return *this;
  }

  PointConfiguration PointConfiguration::gale() const {
    if (coldim() == 0) {
      return *this;
    }
    StrictStairCaseMatrixTrans eliminator;
    eliminator.augment(*this);
    const Matrix kernel(eliminator.transformation(), rowdim(), coldim());
    if (CommandlineOptions::debug()) {
      std::cerr << "points:" << std::endl;
      pretty_print(std::cerr);
      std::cerr << "kernel:" << std::endl;    
      kernel.pretty_print(std::cerr);
      std::cerr << "points * kernel = " << multiply(*this, kernel) << std::endl;
    }
    return PointConfiguration(kernel.transpose());
  }

  PointConfiguration PointConfiguration::product(const PointConfiguration& p) const {
    PointConfiguration result = Matrix(0, no() * p.no());
    const ProductIndex product_index(no(), p.no());
    if ((no() == 0) || (p.no() == 0)) {
      return result;
    }
    for (size_type i = 0; i < no(); ++i) {
      for (size_type j = 0; j < p.no(); ++j) {
	result.col(product_index(i,j)) = this->col(i);
#ifndef STL_CONTAINERS
	result[product_index(i,j)].push_back(p[j]);
#else
	result.col(product_index(i,j)).insert(result.col(product_index(i,j)).end(), p.col(j).begin(), p.col(j).end());
#endif
      }
    }
    return result;
  } 

  PointConfiguration& PointConfiguration::sort_rows() {
    for (size_type i = 0; i < rowdim(); ++i) {
      for (size_type j = i + 1; j < rowdim(); ++j) {
	if (zeroes_in_row(j) < zeroes_in_row(i)) {
	  swap_rows(i, j);
	}
      }
    }
    return *this;
  }

  PointConfiguration& PointConfiguration::lex_abs_sort_cols(Symmetry& sym) {
    std::cerr << "sorting the points " << std::endl;
    pretty_print(std::cerr);
    std::cerr << "with transformation permutation " << sym << std::endl;
    Symmetry new_sym(no());
    for (size_type i = 0; i < no(); ++i) {
      for (size_type j = i + 1; j < no(); ++j) {
	if (lex_abs_compare(this->col(j), this->col(i))) {
	  swap_cols(i, j);
	  new_sym.transpose(i, j);
	}
      }
    }
    std::cerr << "resulting in " << std::endl;
    pretty_print(std::cerr);
    std::cerr << "with transformation permutation " << new_sym << std::endl;
    sym = sym * new_sym;
    std::cerr << "with total permutation of " << sym << std::endl;
    return *this;
  }

  // preprocessing the points can help the (co-)circuits enumeration
  // to start with easy eliminations in the beginning and hoping
  // that later combinations with more numbers are covered by symmetries:
  PointConfiguration& PointConfiguration::preprocess(Symmetry& sym) {
    // Symmetry new_sym(no());
    std::cerr << "preprocessing the points ..." << std::endl;
    sort_rows();
    row_echelon_form();
    // lex_abs_sort_cols(new_sym);
    // reverse(new_sym);
    // sym = sym * new_sym;
    // std::cerr << "... done - resulting transformation permutation " << sym << std::endl;
    std::cerr << "resulting in " << std::endl;
    pretty_print(std::cerr);
    return *this;
  }

  PointConfiguration& PointConfiguration::reverse(Symmetry& sym) {
    Symmetry new_sym(Symmetry(no()).reverse());
    std::cerr << "reversing the points " << std::endl;
    pretty_print(std::cerr);
    std::cerr << "with transformation permutation " << sym << std::endl;
    PointConfiguration tmp(*this);
    for (size_type i = 0; i < tmp.no(); ++i) {
      this->col(coldim() - i - 1) = tmp.col(i);
    }
    std::cerr << "resulting in " << std::endl;
    pretty_print(std::cerr);
    std::cerr << "with transformation permutation " << new_sym << std::endl;
    sym = sym * new_sym;
    std::cerr << "with total permutation of " << sym << std::endl;
    return *this;
  }

  const parameter_type PointConfiguration::_compute_rank() const {
    if (empty()) {
      return 0;
    }
    parameter_type rank(0);
    parameter_type i(0);
    StrictStairCaseMatrix transformed_points(this->col(i));
    if (!this->col(i).is_zero()) {
      ++rank;
    }
    ++i;
    while ((i < coldim()) && (rank < rowdim())) {
      transformed_points.augment(this->col(i));
      rank = transformed_points.rank();
      ++i;
    }
    return rank;
  }

}; // namespace topcom

// eof PointConfiguration.cc