1 #////////////////////////////////////////////////////////////////////////////////
2 //
3 // Cocircuits.cc
4 //
5 // produced: 12/09/2006 jr
6 // last change: 12/09/2006 jr
7 //
8 ////////////////////////////////////////////////////////////////////////////////
9 #include <iostream>
10 #include <ctype.h>
11 #include <string.h>
12 #include <assert.h>
13
14 #include "Cocircuits.hh"
15
16 // Cocircuit:
17
Cocircuit(const Chirotope & chiro,const IntegerSet & coplanar_set)18 Cocircuit::Cocircuit(const Chirotope& chiro, const IntegerSet& coplanar_set) {
19 assert(coplanar_set.card() == chiro.rank() - 1);
20 basis_type basis(coplanar_set);
21 int pm(0);
22 bool found_nonzero(false);
23 IntegerSet universe(0, chiro.no());
24 for (IntegerSet::iterator iter = universe.begin();
25 iter != universe.end();
26 ++iter) {
27 if (coplanar_set.contains(*iter)) {
28 pm = -pm;
29 }
30 else {
31 basis += *iter;
32 if (CommandlineOptions::debug()) {
33 std::cerr << "chiro(" << basis << ") = " << std::endl;
34 }
35 int chiro_on_basis = chiro(basis);
36 if (CommandlineOptions::debug()) {
37 std::cerr << chiro_on_basis << std::endl;
38 }
39 if (!found_nonzero && (chiro_on_basis != 0)) {
40 found_nonzero = true;
41 pm = chiro_on_basis;
42 first += *iter;
43 }
44 else {
45 if (chiro_on_basis * pm > 0) {
46 first += *iter;
47 }
48 else if (chiro_on_basis * pm < 0) {
49 second += *iter;
50 }
51 }
52 basis -= *iter;
53 }
54 }
55 }
56
57 // Cocircuits:
Cocircuits(const Chirotope & chiro,const bool only_positive)58 Cocircuits::Cocircuits(const Chirotope& chiro, const bool only_positive) :
59 cocircuits_data(), _no(chiro.no()), _rank(chiro.rank()) {
60 size_type count(0);
61 // if (_no == _rank) {
62 // return;
63 // }
64 Permutation coplanar_perm(_no, _rank - 1);
65 do {
66 IntegerSet coplanar_set(coplanar_perm);
67 if (CommandlineOptions::debug()) {
68 std::cerr << "computing ";
69 if (only_positive) {
70 std::cerr << " positive ";
71 }
72 std::cerr << " sign vectors from spanning "
73 << _rank - 1 << "-subset "
74 << coplanar_set
75 << " ..."
76 << std::endl;
77 }
78 Cocircuit cocircuit(chiro, coplanar_set);
79 if (CommandlineOptions::debug()) {
80 std::cerr << "... done." << std::endl;
81 std::cerr << "result: " << cocircuit << std::endl;
82 }
83 if ((only_positive) && !cocircuit.first.is_empty() && !cocircuit.second.is_empty()) {
84 continue;
85 }
86 if (!cocircuit.first.is_empty() || !cocircuit.second.is_empty()) {
87 insert(cocircuit.first + cocircuit.second, cocircuit);
88 if (CommandlineOptions::verbose() && (++count % 10000 == 0)) {
89 std::cerr << load();
90 if (only_positive) {
91 std::cerr << " positive ";
92 }
93 std::cerr << " cocircuits computed so far." << std::endl;
94 }
95 }
96 } while (coplanar_perm.lexnext());
97 if (CommandlineOptions::verbose()) {
98 std::cerr << load() << " cocircuits in total." << std::endl;
99 }
100 }
101
102 // stream output/input:
print_string(std::ostream & ost) const103 std::ostream& Cocircuits::print_string(std::ostream& ost) const {
104 ost << _no << ',' << _rank << ':' << std::endl;
105 ost << '{' << std::endl;
106 for (const_iterator iter = begin(); iter != end(); ++iter) {
107 ost << '[' << iter->dataptr()->first << ',' << iter->dataptr()->second << ']' << '\n';
108 }
109 ost << '}' << std::endl;
110 return ost;
111 }
read_string(std::istream & ist)112 std::istream& Cocircuits::read_string(std::istream& ist) {
113 char c;
114 Cocircuit cocircuit;
115
116 clear();
117 if (!(ist >> std::ws >> _no)) {
118 #ifdef READ_DEBUG
119 std::cerr << "Cocircuits::read_string(std::istream&): "
120 << "number of points not found." << std::endl;
121 #endif
122 ist.clear(std::ios::failbit);
123 return ist;
124 }
125 if (!(ist >> std::ws >> c)) {
126 #ifdef READ_DEBUG
127 std::cerr << "Cocircuits::read_string(std::istream&): "
128 << "separator not found." << std::endl;
129 #endif
130 ist.clear(std::ios::failbit);
131 return ist;
132 }
133 if (!(ist >> std::ws >> _rank)) {
134 #ifdef READ_DEBUG
135 std::cerr << "Cocircuits::read_string(std::istream&): "
136 << "rank not found." << std::endl;
137 #endif
138 ist.clear(std::ios::failbit);
139 return ist;
140 }
141 if (!(ist >> std::ws >> c)) {
142 #ifdef READ_DEBUG
143 std::cerr << "Cocircuits::read_string(std::istream&): "
144 << "separator not found." << std::endl;
145 #endif
146 ist.clear(std::ios::failbit);
147 return ist;
148 }
149 while (ist >> std::ws >> c) {
150 if (c == '{') {
151 continue;
152 }
153 else if (c == '}') {
154 break;
155 }
156 else {
157 ist.putback(c);
158 if (ist >> cocircuit) {
159 insert(cocircuit.first + cocircuit.second, cocircuit);
160 }
161 else {
162 #ifdef READ_DEBUG
163 std::cerr << "Cocircuits::read_string(std::istream&): "
164 << "not of appropriate type." << std::endl;
165 #endif
166 ist.clear(std::ios::failbit);
167 return ist;
168 }
169 }
170 }
171 return ist;
172 }
173
174 // eof Cocircuits.cc
175