00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OMC_CHIROTOPE_H
00025 #define OMC_CHIROTOPE_H
00026
00027 #include "Core.h"
00028 #include "Tuple.h"
00029 #include "SignedSet.h"
00030 #include "OrientedMatroid.h"
00031 #include "Verifiable.h"
00032 #include "Combination.h"
00033 #include "Permutation.h"
00034 #include "Util.h"
00035 #include <algorithm>
00036 #include <iostream>
00037 #include <sstream>
00038 #include <vector>
00039 #include <string>
00040 #include <typeinfo>
00041
00042 namespace omc
00043 {
00044 class Chirotope : public OrientedMatroid, Verifiable {
00045 friend inline std::ostream & operator<< (std::ostream &, Chirotope &);
00046 friend inline std::istream & operator>> (std::istream &, Chirotope &);
00047
00048 public:
00049 Chirotope (size_t, size_t, OrientedMatroid::om_type);
00050 Chirotope (size_t, size_t, std::string);
00051 Chirotope (const Chirotope &);
00052
00053 ~Chirotope () {};
00054
00055 Chirotope* clone () const;
00056
00057 sign_t getSign (const Tuple &) const;
00058 sign_t getSign (const std::string &) const;
00059
00060 void setSign (const Tuple &, sign_t);
00061 void setSign (const std::string &, sign_t);
00062
00063 void setSigns (std::string);
00064
00065 void relabel (index_t, index_t);
00066 void relabel (const Permutation &);
00067
00068 void reorient (index_t);
00069 void reorient (const std::set<index_t> &);
00070 void reorient (const Combination &);
00071
00072 void remove (index_t);
00073 void contract (index_t);
00074
00075 bool operator== (const OrientedMatroid &) const;
00076
00077 bool verify ();
00078
00079
00080 class basis_iterator
00081 : public std::iterator <std::input_iterator_tag, Tuple>
00082 {
00083 public:
00084 basis_iterator () {};
00085 basis_iterator (const Chirotope *, const Tuple &);
00086
00087 ~basis_iterator () {};
00088
00089 Tuple & operator* ();
00090 Tuple * operator-> ();
00091
00092 Tuple & operator++ ();
00093 Tuple operator++ (int);
00094
00095 bool operator== (basis_iterator);
00096 bool operator!= (basis_iterator);
00097
00098 private:
00099 const Chirotope *m_Chi_p;
00100 Tuple m_basis;
00101 };
00102
00103
00104 basis_iterator basis_begin () const;
00105 basis_iterator basis_end () const;
00106
00107 protected:
00108 SignedSet m_Sign;
00109
00110 };
00111
00112
00114 inline Chirotope::Chirotope (size_t r, size_t n,
00115 OrientedMatroid::om_type omt = OrientedMatroid::empty)
00116 : OrientedMatroid (r, n), m_Sign (util::choose(n,r))
00117 {
00118 if (omt == alternating)
00119 for (int i=0; i<m_Sign.size(); i++)
00120 m_Sign[i] = 1;
00121 }
00122
00124 inline Chirotope::Chirotope (size_t r, size_t n, std::string signs)
00125 : OrientedMatroid (r, n), m_Sign (util::choose(n,r))
00126 {
00127 setSigns (signs);
00128 }
00129
00131 inline Chirotope::Chirotope (const Chirotope & C)
00132 : OrientedMatroid (C.m_rank, C.m_numElements), m_Sign (C.m_Sign)
00133 {}
00134
00136 inline Chirotope* Chirotope::clone () const {
00137 return new Chirotope (*this);
00138 }
00139
00140
00142 inline Chirotope::basis_iterator::basis_iterator (const Chirotope * c_p,
00143 const Tuple & t)
00144 : m_Chi_p (c_p), m_basis (t)
00145 {}
00146
00148 inline Tuple & Chirotope::basis_iterator::operator* () {
00149 return m_basis;
00150 }
00151
00153 inline Tuple * Chirotope::basis_iterator::operator-> () {
00154 return & m_basis;
00155 }
00156
00158 inline Tuple & Chirotope::basis_iterator::operator++ () {
00159 while (m_basis.next())
00160 if (m_Chi_p->getSign (m_basis) != 0) return m_basis;
00161
00162
00163 m_basis = Tuple();
00164 return m_basis;
00165 }
00166
00168 inline Tuple Chirotope::basis_iterator::operator++ (int dummy) {
00169 Tuple basis = m_basis;
00170
00171 while (m_basis.next())
00172 if (m_Chi_p->getSign (m_basis) != 0) return basis;
00173
00174
00175 m_basis = Tuple ();
00176 return basis;
00177 }
00178
00180 inline bool Chirotope::basis_iterator::operator== (basis_iterator bi) {
00181 return (m_Chi_p == bi.m_Chi_p && m_basis == bi.m_basis);
00182 }
00183
00185 inline bool Chirotope::basis_iterator::operator!= (basis_iterator bi) {
00186 return (m_Chi_p != bi.m_Chi_p || m_basis != bi.m_basis);
00187 }
00188
00189
00191 inline std::ostream & operator<< (std::ostream & os, Chirotope & C) {
00192 os << C.m_Sign;
00193 return os;
00194 }
00195
00197 inline std::istream & operator>> (std::istream & is, Chirotope & C) {
00198 is >> C.m_Sign;
00199 return is;
00200 }
00201
00202 };
00203
00204 #endif // OMC_CHIROTOPE_H