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
|
////////////////////////////////////////////////////////////////////////////////
//
// 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 "Global.hh"
#ifdef USE_SPARSEINTSET
#include "SparseIntegerSet.hh"
#else
#include "LabelSet.hh"
#endif
#include "CommandlineOptions.hh"
#include "StairCaseMatrix.hh"
#include "PointConfiguration.hh"
#include "Permutation.hh"
namespace topcom {
#ifdef USE_SPARSEINTSET
typedef SparseIntegerSet basis_type;
#else
typedef LabelSet basis_type;
#endif
#ifdef STL_CHIROTOPE
#include <unordered_map>
typedef std::unordered_map<basis_type, std::pair<short int, Field>, Hash<basis_type> > chirotope_data;
#else
#include "HashMap.hh"
typedef HashMap<basis_type, Pair<short int, Field> > chirotope_data;
#endif
inline const char int2sign(const short int i) {
switch(i) {
case 1: return '+';
case -1: return '-';
default: return '0';
}
}
inline const short int sign2int(const char c) {
switch(c) {
case '+': return 1;
case '-': return -1;
default: return 0;
}
}
class RealChiro : public chirotope_data {
private:
static const char start_char;
static const char end_char;
static const char delim_char;
static const char* map_chars;
private:
parameter_type _no;
parameter_type _rank;
protected:
bool _has_dets;
public:
// constructors:
inline RealChiro();
inline RealChiro(const RealChiro&);
inline RealChiro(const parameter_type&, const parameter_type&, const bool = false);
RealChiro(const PointConfiguration&, bool preprocess=true);
// destructor:
inline ~RealChiro();
//assignment:
inline RealChiro& operator=(const RealChiro& chiro);
// accessors:
inline parameter_type no() const;
inline parameter_type rank() const;
inline bool has_dets() const;
inline size_type size() const;
inline Field det(const basis_type&) const;
inline Field det(const Permutation&) 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::istream& read(std::istream&);
std::istream& read_string(std::istream&);
std::ostream& write(std::ostream&) const;
std::ostream& print_string(std::ostream&) const;
std::ostream& print_dualstring(std::ostream&) const;
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), _has_dets(false) {
}
inline RealChiro::RealChiro(const RealChiro& chiro) :
chirotope_data(chiro), _no(chiro._no), _rank(chiro._rank), _has_dets(false) {
}
inline RealChiro::RealChiro(const parameter_type& no,
const parameter_type& rank,
const bool has_dets) :
chirotope_data(), _no(no), _rank(rank), _has_dets(has_dets) {}
// destructor:
inline RealChiro::~RealChiro() {
#ifdef CONSTRUCTOR_DEBUG
std::cerr << "RealChiro::~RealChiro(): destructor called" << std::endl;
#endif
}
//assignment:
inline RealChiro& RealChiro::operator=(const RealChiro& chiro) {
if (this == &chiro) {
return *this;
}
chirotope_data::operator=(chiro);
_no = chiro._no;
_rank = chiro._rank;
_has_dets = chiro._has_dets;
return *this;
}
// accessors:
inline parameter_type RealChiro::no() const { return _no; }
inline parameter_type RealChiro::rank() const { return _rank; }
inline bool RealChiro::has_dets() const { return _has_dets; }
inline size_type RealChiro::size() const {
#ifdef STL_CHIROTOPE
return static_cast<size_type>(chirotope_data::size());
#else
return static_cast<size_type>(chirotope_data::size());
#endif
}
inline Field RealChiro::det(const basis_type& basis) const {
if (!_has_dets) {
std::cerr << "Field RealChiro::det(const basis_type&) const: "
<< "det requested, but chirotope has no dets - exiting" << std::endl;
exit(1);
}
return find(basis)->second.second;
}
inline Field RealChiro::det(const Permutation& basisperm) const {
int permsign = basisperm.sign();
if (permsign > 0) {
return det(basis_type(basisperm));
}
else {
return -det(basis_type(basisperm));
}
}
// operators:
inline const int RealChiro::operator()(const basis_type& basis) const {
#ifdef INDEX_CHECK
std::cerr << "basis: " << basis << std::endl;
if (!(member(basis))) {
std::cerr << *this << " does not contain " << basis << std::endl;
exit(1);
}
#endif
#ifndef STL_CHIROTOPE
return member(basis)->first;
#else
return find(basis)->second.first;
#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::istream& operator>>(std::istream& ist, RealChiro& chiro) {
return chiro.read(ist);
}
inline std::ostream& operator<<(std::ostream& ost, const RealChiro& chiro) {
return chiro.write(ost);
}
}; // namespace topcom
#endif
// eof RealChiro.hh
|