File: Cocircuits.cc

package info (click to toggle)
topcom 0.17.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,572 kB
  • sloc: cpp: 16,640; sh: 975; makefile: 345; ansic: 40
file content (174 lines) | stat: -rw-r--r-- 4,584 bytes parent folder | download
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
#////////////////////////////////////////////////////////////////////////////////
// 
// Cocircuits.cc
//
//    produced: 12/09/2006 jr
// last change: 12/09/2006 jr
// 
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <ctype.h>
#include <string.h>
#include <assert.h>

#include "Cocircuits.hh"

// Cocircuit:

Cocircuit::Cocircuit(const Chirotope& chiro, const IntegerSet& coplanar_set) {
  assert(coplanar_set.card() == chiro.rank() - 1);
  basis_type basis(coplanar_set);
  int pm(0);
  bool found_nonzero(false);
  IntegerSet universe(0, chiro.no());
  for (IntegerSet::iterator iter = universe.begin();
       iter != universe.end();
       ++iter) {
    if (coplanar_set.contains(*iter)) {
      pm = -pm;
    }
    else {
      basis += *iter;
      if (CommandlineOptions::debug()) {
	std::cerr << "chiro(" << basis << ") = " << std::endl;
      }
      int chiro_on_basis = chiro(basis);
      if (CommandlineOptions::debug()) {
	std::cerr << chiro_on_basis << std::endl;
      }
      if (!found_nonzero && (chiro_on_basis != 0)) {
	found_nonzero = true;
	pm = chiro_on_basis;
	first += *iter;
      }
      else {
	if (chiro_on_basis * pm > 0) {
	  first += *iter;
	}
	else if (chiro_on_basis * pm < 0) {
	  second += *iter;
	}
      }
      basis -= *iter;
    }
  }
}

// Cocircuits:
Cocircuits::Cocircuits(const Chirotope& chiro, const bool only_positive) : 
  cocircuits_data(), _no(chiro.no()), _rank(chiro.rank()) {
  size_type count(0);
  // if (_no == _rank) {
  //   return;
  // }
  Permutation coplanar_perm(_no, _rank - 1);
  do {
    IntegerSet coplanar_set(coplanar_perm);
    if (CommandlineOptions::debug()) {
      std::cerr << "computing ";
      if (only_positive) {
	std::cerr << " positive ";
      }
      std::cerr << " sign vectors from spanning " 
	       << _rank - 1 << "-subset " 
	       << coplanar_set
	       << " ..."
	       << std::endl;
    }
    Cocircuit cocircuit(chiro, coplanar_set);
    if (CommandlineOptions::debug()) {
      std::cerr << "... done." << std::endl;
      std::cerr << "result: " << cocircuit << std::endl;
    }
    if ((only_positive) && !cocircuit.first.is_empty() && !cocircuit.second.is_empty()) {
      continue;
    }
    if (!cocircuit.first.is_empty() || !cocircuit.second.is_empty()) {
      insert(cocircuit.first + cocircuit.second, cocircuit);
      if (CommandlineOptions::verbose() && (++count % 10000 == 0)) {
	std::cerr << load();
	if (only_positive) {
	  std::cerr << " positive ";
	}
	std::cerr << " cocircuits computed so far." << std::endl;
      }
    }
  } while (coplanar_perm.lexnext());
  if (CommandlineOptions::verbose()) {
    std::cerr << load() << " cocircuits in total." << std::endl;
  }
}

// stream output/input:
std::ostream& Cocircuits::print_string(std::ostream& ost) const {
  ost << _no << ',' << _rank << ':' << std::endl;
  ost << '{' << std::endl;
  for (const_iterator iter = begin(); iter != end(); ++iter) {
    ost << '[' << iter->dataptr()->first << ',' << iter->dataptr()->second << ']' << '\n';
  }
  ost << '}' << std::endl;
  return ost;
}
std::istream& Cocircuits::read_string(std::istream& ist) {
  char     c;
  Cocircuit  cocircuit;

  clear();
  if (!(ist >> std::ws >> _no)) {
#ifdef READ_DEBUG
    std::cerr << "Cocircuits::read_string(std::istream&): "
	 << "number of points not found." << std::endl;
#endif
    ist.clear(std::ios::failbit);
    return ist;
  }
  if (!(ist >> std::ws >> c)) {
#ifdef READ_DEBUG
    std::cerr << "Cocircuits::read_string(std::istream&): "
	 << "separator not found." << std::endl;
#endif
    ist.clear(std::ios::failbit);
    return ist;
  }
  if (!(ist >> std::ws >> _rank)) {
#ifdef READ_DEBUG
    std::cerr << "Cocircuits::read_string(std::istream&): "
	 << "rank not found." << std::endl;
#endif
    ist.clear(std::ios::failbit);
    return ist;
  }
  if (!(ist >> std::ws >> c)) {
#ifdef READ_DEBUG
    std::cerr << "Cocircuits::read_string(std::istream&): "
	 << "separator not found." << std::endl;
#endif
    ist.clear(std::ios::failbit);
    return ist;
  }
  while (ist >> std::ws >> c) {
    if (c == '{') {
      continue;
    }
    else if (c == '}') {
      break;
    }
    else {
      ist.putback(c);
      if (ist >> cocircuit) {
	insert(cocircuit.first + cocircuit.second, cocircuit);
      }
      else {
#ifdef READ_DEBUG
	std::cerr << "Cocircuits::read_string(std::istream&): "
	     << "not of appropriate type." << std::endl;
#endif
	ist.clear(std::ios::failbit);
	return ist;		
      }
    }
  }
  return ist;
}

// eof Cocircuits.cc