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
|
////////////////////////////////////////////////////////////////////////////////
//
// RealChiro.hh
//
// produced: 13/03/98 jr
// last change: 13/03/98 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef REALCHIRO_HH
#define REALCHIRO_HH
#include <assert.h>
#include <iostream>
#include "Array.hh"
#ifdef USE_SPARSEINTSET
#include "SparseIntegerSet.hh"
#else
#include "IntegerSet.hh"
#endif
#include "HashMap.hh"
#ifdef STL_CHIROTOPE
#include <tr1/unordered_map>
#endif
#include "CommandlineOptions.hh"
#include "StairCaseMatrix.hh"
#include "PointConfiguration.hh"
#include "Permutation.hh"
#ifdef USE_SPARSEINTSET
typedef SparseIntegerSet basis_type;
#else
typedef IntegerSet basis_type;
#endif
#ifdef STL_CHIROTOPE
typedef std::tr1::unordered_map<basis_type, int> chirotope_data;
inline std::ostream& operator<<(std::ostream& ost, const chirotope_data& cd) {
for (chirotope_data::const_iterator iter = cd.begin();
iter != cd.end();
++iter) {
ost << iter->first << "->" << iter->second;
}
return ost;
}
inline std::istream& operator>>(std::istream& ist, chirotope_data& cd) {
char dash;
char arrow;
basis_type basis_reader;
int int_reader;
char c;
cd.clear();
ist >> std::ws >> c;
if (c == '[') {
while (ist >> std::ws >> c) {
if (c == ']') {
break;
}
if (c == ',') {
continue;
}
ist.putback(c);
if (!(ist >> std::ws >> basis_reader)) {
#ifdef READ_DEBUG
std::cerr << "std::istream& operator>>(std::istream&, chirotope_data&): "
<< "key not found." << std::endl;
#endif
ist.clear(std::ios::failbit);
return ist;
}
if (!(ist >> std::ws >> dash >> arrow)) {
#ifdef READ_DEBUG
std::cerr << "std::istream& operator>>(std::istream&, chirotope_data&): "
<< "`->' not found." << std::endl;
#endif
ist.clear(std::ios::failbit);
return ist;
}
if (!(ist >> std::ws >> int_reader)) {
#ifdef READ_DEBUG
std::cerr << "std::istream& operator>>(std::istream&, chirotope_data&): "
<< "data not found." << std::endl;
#endif
ist.clear(std::ios::failbit);
return ist;
}
cd[basis_reader] = int_reader;
}
}
else {
#ifdef READ_DEBUG
std::cerr << "std::istream& operator>>(std::istream&, chirotope_data&): "
<< "missing `" << '[' << "'." << std::endl;
#endif
ist.clear(std::ios::failbit);
return ist;
}
ist.clear(std::ios::goodbit);
return ist;
}
#else
typedef HashMap<basis_type, int> chirotope_data;
#endif
inline const char int2sign(const int i) {
switch(i) {
case 1: return '+';
case -1: return '-';
default: return '0';
}
}
inline const int sign2int(const char c) {
switch(c) {
case '+': return 1;
case '-': return -1;
default: return 0;
}
}
class RealChiro : public chirotope_data {
parameter_type _no;
parameter_type _rank;
public:
// constructors:
inline RealChiro();
inline RealChiro(const RealChiro&);
inline RealChiro(const parameter_type&, const parameter_type&);
RealChiro(const PointConfiguration&, bool preprocess=true);
//assignment:
inline RealChiro& operator=(const RealChiro& chiro);
// accessors:
inline parameter_type no() const;
inline parameter_type rank() const;
inline size_type load() const;
// functions:
void erase_random();
const basis_type find_non_deg_basis() const;
RealChiro dual() const;
// operators:
inline const int operator()(const basis_type&) const;
const int operator()(const basis_type& prebasis,
const Permutation& lex_extension_perm) const;
inline const bool operator==(const RealChiro&) const;
inline const bool operator!=(const RealChiro&) const;
// stream output/input:
std::ostream& print_string(std::ostream&) const;
std::ostream& print_dualstring(std::ostream&) const;
std::istream& read_string(std::istream&);
inline friend std::ostream& operator<<(std::ostream&, const RealChiro& chiro);
inline friend std::istream& operator>>(std::istream&, RealChiro& chiro);
private:
// internal algorithms:
void _recursive_chiro(const StairCaseMatrix& current,
const PointConfiguration& points,
const basis_type& basis,
const parameter_type start,
const parameter_type step,
const bool already_dependent);
void _recursive_find_nd_basis(const StairCaseMatrix& current,
const PointConfiguration& points,
const basis_type& basis,
const parameter_type start,
const parameter_type step,
const bool already_dependent);
};
inline RealChiro::RealChiro() : chirotope_data(), _no(0), _rank(0) {
}
inline RealChiro::RealChiro(const RealChiro& chiro) :
chirotope_data(chiro), _no(chiro._no), _rank(chiro._rank) {
}
inline RealChiro::RealChiro(const parameter_type& no,
const parameter_type& rank) :
chirotope_data(), _no(no), _rank(rank) {}
//assignment:
inline RealChiro& RealChiro::operator=(const RealChiro& chiro) {
if (this == &chiro) {
return *this;
}
chirotope_data::operator=(chiro);
_no = chiro._no;
_rank = chiro._rank;
return *this;
}
// accessors:
inline parameter_type RealChiro::no() const { return _no; }
inline parameter_type RealChiro::rank() const { return _rank; }
inline parameter_type RealChiro::load() const {
#ifdef STL_CHIROTOPE
return chirotope_data::size();
#else
return chirotope_data::load();
#endif
}
// operators:
inline const int RealChiro::operator()(const basis_type& basis) const {
#ifdef INDEX_CHECK
if (!(member(basis))) {
std::cerr << *this << " does not contain " << basis << std::endl;
exit(1);
}
#endif
#ifndef STL_CHIROTOPE
return *member(basis);
#else
return find(basis)->second;
#endif
}
inline const bool RealChiro::operator==(const RealChiro& chiro) const {
#ifdef STL_CHIROTOPE
return ((*this) == chiro);
#else
return chirotope_data::operator==(chiro);
#endif
}
inline const bool RealChiro::operator!=(const RealChiro& chiro) const {
return !operator==(chiro);
}
// stream output/input:
inline std::ostream& operator<<(std::ostream& ost, const RealChiro& chiro) {
ost << chiro._no << ',' << chiro._rank << ':' << (chirotope_data&)(chiro);
return ost;
}
inline std::istream& operator>>(std::istream& ist, RealChiro& chiro) {
char c;
ist >> std::ws >> chiro._no >> std::ws >> c >> std::ws >> chiro._rank >> std::ws >> c >> std::ws >> (chirotope_data&)(chiro);
return ist;
}
#endif
// eof RealChiro.hh
|