src/biu/LatticeDescriptor.cc
Go to the documentation of this file.00001 #include <biu/LatticeDescriptor.hh>
00002 #include <algorithm>
00003
00004 namespace biu
00005 {
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 LatticeDescriptor::LatticeDescriptor(const std::string& name_)
00023 : name(name_), moveAlphabet(NULL), latNeighborhood(NULL)
00024 {
00025 }
00026
00027 LatticeDescriptor::LatticeDescriptor(const LatticeDescriptor& toCopy)
00028 : name(toCopy.name),
00029 automorphisms(toCopy.automorphisms),
00030 latBase(toCopy.latBase),
00031 moveAlphabet(new MoveAlphabet(*(toCopy.moveAlphabet))),
00032 latNeighborhood(new LatticeNeighborhood(*(toCopy.latNeighborhood)))
00033 {
00034 }
00035
00036 LatticeDescriptor&
00037 LatticeDescriptor::operator= (const LatticeDescriptor &ld2) {
00038 if (this != &ld2) {
00039 name = ld2.name;
00040 automorphisms = ld2.automorphisms;
00041 latBase = ld2.latBase;
00042 if (moveAlphabet != NULL)
00043 delete moveAlphabet;
00044 moveAlphabet = new MoveAlphabet(*(ld2.moveAlphabet));
00045 if (latNeighborhood != NULL)
00046 delete latNeighborhood;
00047 latNeighborhood = new LatticeNeighborhood(*(ld2.latNeighborhood));
00048 }
00049 return *this;
00050 }
00051
00052
00053 LatticeDescriptor::~LatticeDescriptor()
00054 {
00055 if (moveAlphabet != NULL) {
00056 delete moveAlphabet; moveAlphabet = NULL;
00057 }
00058 if (latNeighborhood != NULL) {
00059 delete latNeighborhood; latNeighborhood = NULL;
00060 }
00061 }
00062
00063
00064 bool
00065 LatticeDescriptor::operator== (const LatticeDescriptor &ld2) const {
00066 return this->name == ld2.name
00067 && *(this->moveAlphabet) == *(ld2.moveAlphabet)
00068 && this->automorphisms == ld2.automorphisms
00069 && this->latBase == ld2.latBase
00070 && std::equal( this->latNeighborhood->begin(),
00071 this->latNeighborhood->end(),
00072 ld2.latNeighborhood->begin());
00073 }
00074
00075 bool
00076 LatticeDescriptor::operator!= (const LatticeDescriptor &ld2) const {
00077 return this->name != ld2.name
00078 || *(this->moveAlphabet) != *(ld2.moveAlphabet)
00079 || this->automorphisms != ld2.automorphisms
00080 || this->latBase != ld2.latBase
00081 || !(std::equal( this->latNeighborhood->begin(),
00082 this->latNeighborhood->end(),
00083 ld2.latNeighborhood->begin()));
00084 }
00085
00086
00087
00088 void
00089 LatticeDescriptor::initNeighborhood() {
00090 unsigned int n=getNeighborDataSize();
00091
00092 std::vector<std::string> alphabetVec;
00093
00094 const NeighborData *data = getNeighborData();
00095
00096 NeighSet neighbors;
00097 for (unsigned int i=0; i<n; i++) {
00098 const NeighborData &d = data[i];
00099
00100 alphabetVec.push_back(d.name);
00101
00102 Automorphism mat(d.mat);
00103 Automorphism invmat(d.invmat);
00104
00105 neighbors.insert(NeighborVector(d.vec[0],d.vec[1],d.vec[2],
00106 i,
00107 mat,
00108 invmat
00109 )
00110 );
00111 }
00112
00113
00114 if (moveAlphabet != NULL) delete moveAlphabet;
00115 moveAlphabet = new MoveAlphabet(alphabetVec);
00116
00117 if (latNeighborhood != NULL) delete latNeighborhood;
00118 latNeighborhood = new LatticeNeighborhood(moveAlphabet, neighbors);
00119
00120 assertbiu(neighbors.size() == getNeighborDataSize(),
00121 "neighborhood size and the initialized neighbor number have to be equal");
00122
00123 }
00124
00125
00126 void
00127 LatticeDescriptor::initAutomorphisms() {
00128 unsigned int n=getAutomorphismDataSize();
00129
00130
00131
00132 const AutomorphismData *data = getAutomorphismData();
00133
00134 automorphisms.clear();
00135 for (unsigned int i=0; i<n; i++) {
00136 int d[3][3];
00137 for(unsigned int k=0; k<3; k++) {
00138 d[0][k] = data[i]._0[k];
00139 d[1][k] = data[i]._1[k];
00140 d[2][k] = data[i]._2[k];
00141 }
00142
00143 Automorphism a(d);
00144 automorphisms.push_back(a);
00145 }
00146
00147
00148 symMoveReplacement.clear();
00149
00150 for (unsigned int i=0; i<n; i++) {
00151 MoveSequence symMoves;
00152
00153 for (unsigned int k=0; k<latNeighborhood->size(); k++) {
00154 IntPoint symNV = automorphisms[i] * latNeighborhood->getElement(k);
00155
00156
00157 for (unsigned int l=0; l<latNeighborhood->size(); l++)
00158 if ( symNV == latNeighborhood->getElement(l)) {
00159
00160 symMoves.push_back(l);
00161 break;
00162 }
00163 }
00164
00165 assertbiu(symMoves.size() == latNeighborhood->size(),
00166 "calculated symmetric move vector differs in length with neighbor vectors");
00167
00168 symMoveReplacement.push_back(symMoves);
00169 }
00170 }
00171
00172 MoveSequence
00173 LatticeDescriptor::normalizeSequence(const MoveSequence& origMoveSeq) const {
00174
00175 MoveSequence newSeq = MoveSequence(origMoveSeq);
00176
00177
00178 for (std::vector<MoveSequence>::const_iterator sm = symMoveReplacement.begin();
00179 sm != symMoveReplacement.end(); sm++)
00180 {
00181 bool smaller=false;
00182 for (unsigned int i=0; i<origMoveSeq.size(); i++) {
00183 if (smaller || (*sm)[origMoveSeq[i]] <= newSeq[i]) {
00184 smaller=smaller || (*sm)[origMoveSeq[i]] < newSeq[i];
00185 newSeq[i] = (*sm)[origMoveSeq[i]];
00186 }
00187 else
00188 break;
00189 }
00190 }
00191
00192 return newSeq;
00193 }
00194
00195
00196
00197 }