00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "g-map-vertex.hh"
00026 #include "chrono.hh"
00027 #include <iostream>
00028 using namespace std;
00029 using namespace GMap3d;
00030
00031 int CGMapVertex::findMotif( CGMapVertex* AMap )
00032 {
00033 int index = getNewDirectInfo();
00034
00035 int markTreated = getNewMark();
00036 int markTreated2 = AMap->getNewMark();
00037 bool matchOne = false;
00038 bool matchAll = true;
00039
00040 CChrono c;
00041 c.start();
00042
00043 CDynamicCoverageAll it1(this);
00044 CDynamicCoverageAll it2(AMap);
00045
00046 for ( ; it1.cont(); ++it1 )
00047 setDirectInfo(*it1, index, NULL);
00048
00049 for ( it1.reinit(); matchAll && it1.cont(); ++it1 )
00050 {
00051 if ( getDirectInfo(*it1,index)==NULL )
00052 {
00053 matchOne = false;
00054 for ( it2.reinit(); !matchOne && it2.cont(); ++it2 )
00055 {
00056 matchOne=findMotifFrom(*it1, markTreated, index,
00057 AMap, *it2, markTreated2);
00058
00059 unmarkMotifMark(*it1,markTreated,(matchOne?-1:index),
00060 AMap,*it2,(matchOne?-1:markTreated2));
00061
00062
00063 }
00064
00065 if ( !matchOne ) matchAll = false;
00066 }
00067 }
00068
00069 freeMark(markTreated);
00070
00071 AMap->unmarkAll(markTreated2);
00072 AMap->freeMark(markTreated2);
00073
00074 c.stop();
00075 c.display("Temps de recherche du motif");
00076
00077 if ( !matchAll )
00078 {
00079 freeDirectInfo(index);
00080 return -1;
00081 }
00082
00083 return index;
00084 }
00085
00086 unsigned int CGMapVertex::countNumberOfMotifs( CGMapVertex* AMap )
00087 {
00088 unsigned int res = 0;
00089 int index = getNewDirectInfo();
00090
00091 int markTreated = getNewMark();
00092 int markTreated2 = AMap->getNewMark();
00093 bool match = false;
00094
00095
00096 CChrono c; c.start();
00097
00098 CDynamicCoverageAll it1(this);
00099 CDynamicCoverageAll it2(AMap);
00100
00101 for ( ; it1.cont(); ++it1 )
00102 setDirectInfo(*it1, index, NULL);
00103 it1.reinit();
00104
00105 for ( it2.reinit(); it2.cont(); ++it2 )
00106 {
00107 match=findMotifFrom(*it1, markTreated, index,
00108 AMap, *it2, markTreated2);
00109
00110 unmarkMotifMark(*it1,markTreated,index,
00111 AMap,*it2,markTreated2);
00112
00113 if ( match ) ++res;
00114
00115 }
00116
00117 freeMark(markTreated);
00118 AMap->freeMark(markTreated2);
00119
00120 c.stop();
00121 c.display("Temps de recherche de tout les motifs");
00122
00123 freeDirectInfo(index);
00124
00125 return res;
00126 }
00127
00128 void CGMapVertex::unmarkMotifMark(CDart* ADart, int AMark, int AIndex,
00129 CGMapVertex* AMap, CDart* ADart2, int AMark2)
00130 {
00131 if ( !isMarked(ADart, AMark) ) return;
00132
00133 stack<CDart*> toTreat;
00134 stack<CDart*> toTreat2;
00135
00136 toTreat.push(ADart);
00137 toTreat2.push(ADart2);
00138
00139 CDart* current;
00140 CDart* other;
00141 int i;
00142
00143 while (!toTreat.empty())
00144 {
00145 current = toTreat.top(); toTreat.pop();
00146 other = toTreat2.top(); toTreat2.pop();
00147
00148 if ( isMarked(current, AMark) )
00149 {
00150 for ( i=0; i<=3; ++i )
00151 if ( isMarked(alpha(current,i), AMark) )
00152 {
00153 toTreat.push(alpha(current,i));
00154 toTreat2.push(AMap->alpha(other,i));
00155 }
00156
00157 unsetMark(current, AMark);
00158 if ( AMark2!=-1 ) AMap->unsetMark(other, AMark2);
00159 if ( AIndex!=-1 ) setDirectInfo(current, AIndex, NULL);
00160 }
00161 }
00162 }
00163
00164 bool CGMapVertex::findMotifFrom( CDart* AFromDart, unsigned int AMarkTreated,
00165 unsigned int AIndex,
00166 CGMapVertex* AMap, CDart* ADestDart,
00167 unsigned int AMarkTreated2 )
00168 {
00169 bool match = true;
00170 int i = 0;
00171
00172
00173 stack<CDart*> toTreat;
00174 stack<CDart*> toTreat2;
00175
00176 toTreat.push(AFromDart);
00177 toTreat2.push(ADestDart);
00178
00179
00180 CDart* current;
00181 CDart* other;
00182
00183 while (match && !toTreat.empty())
00184 {
00185
00186 current = toTreat.top(); toTreat.pop();
00187 other = toTreat2.top(); toTreat2.pop();
00188
00189 if ( !isMarked(current, AMarkTreated) )
00190 {
00191 if ( AMap->isMarked(other, AMarkTreated2) )
00192 match = false;
00193 else
00194 {
00195
00196 setDirectInfo(current, AIndex, other);
00197
00198 setMark(current, AMarkTreated);
00199 AMap->setMark(other, AMarkTreated2);
00200
00201
00202
00203 for ( i=0; match && i<=3; ++i )
00204 {
00205 if ( !isFree(current,i) )
00206 {
00207 if (isMarked(alpha(current,i), AMarkTreated) )
00208 {
00209 if ( getDirectInfoAsDart(alpha(current,i), AIndex)!=
00210 AMap->alpha(other,i) )
00211 match = false;
00212 }
00213 else
00214 {
00215 if ( AMap->isMarked(AMap->alpha(other,i),AMarkTreated2) )
00216 match = false;
00217 else
00218 {
00219 toTreat.push(alpha(current,i));
00220 toTreat2.push(AMap->alpha(other,i));
00221 }
00222 }
00223 }
00224 else
00225 {
00226 if (!AMap->isFree(other,i) &&
00227 AMap->isMarked(AMap->alpha(other,i),AMarkTreated2) )
00228 match = false;
00229 }
00230 }
00231 }
00232 }
00233 }
00234
00235 return match;
00236 }
00237