src/ell/BarrierSampling.cc
Go to the documentation of this file.00001 #include "ell/BarrierSampling.hh"
00002
00003 namespace ell
00004 {
00005
00007 BarrierSampling::~BarrierSampling()
00009 {
00010 }
00011
00012 }
00013
00014 #include "ell/StateCollector.hh"
00015
00016 namespace ell
00017 {
00018
00020 BS_DirectWalk::
00021 BS_DirectWalk( const DirectWalk* const dw_)
00022 : dw(dw_)
00024 {
00025 assertbiu(dw!=NULL, "no direct walk given (==NULL)");
00026 }
00027
00029 BS_DirectWalk::
00030 ~BS_DirectWalk()
00032 {
00033 }
00034
00036 size_t
00037 BS_DirectWalk::
00038 findBarriers( LandscapeTopology* const lt
00039 , MinimumSelector* const ms
00040 , SamplingAbortionCriterion * const sac
00041 )
00043 {
00044 assertbiu(lt!=NULL, "no landscape topology given (==NULL)");
00045 assertbiu(ms!=NULL, "no minimum selector given (==NULL)");
00046 assertbiu(sac!=NULL, "no sampling abortion criterion given (==NULL)");
00047
00048 if (lt->getMinCount() < 2) {
00049 return 0;
00050 }
00051
00052
00053 size_t iterations = 0;
00054
00055 bool wasChanged = true;
00056
00057
00058 size_t m1 = ms->select(lt, false);
00059
00060 if (m1 == LandscapeTopology::INVALID_INDEX) {
00061 return 0;
00062 }
00063 size_t m2 = m1;
00064
00065
00066 while( !sac->abortSampling( lt, wasChanged ) ) {
00067 iterations++;
00068
00069 m1 = ms->select(lt, false);
00070 assertbiu(m1!=LandscapeTopology::INVALID_INDEX,
00071 "no minimum m1 was selected");
00072 do {
00073 m2 = ms->select(lt, false);
00074 } while (m1 == m2);
00075 assertbiu(m2!=LandscapeTopology::INVALID_INDEX,
00076 "no minimum m2 was selected");
00077
00078
00079 SC_Maximum scMax;
00080 dw->walk(lt->getMin(m1), lt->getMin(m2), &scMax);
00081
00082 wasChanged = lt->addSaddle(m1,m2,scMax.getMaximumState());
00083 }
00084
00085 return iterations;
00086 }
00087
00088
00089 }
00090
00091 #include "ell/StateCollector.hh"
00092
00093 namespace ell
00094 {
00095
00097 BS_UpDown::
00098 BS_UpDown( const Walk* const up
00099 , const Walk* const down
00100 , const bool addNewMin )
00101 : upWalk(up)
00102 , downWalk(down)
00103 , addNewMinima(addNewMin)
00105 {
00106 assertbiu(upWalk!=NULL, "no up walk given (==NULL)");
00107 assertbiu(downWalk!=NULL, "no down walk given (==NULL)");
00108 }
00109
00111 BS_UpDown::
00112 ~BS_UpDown()
00114 {
00115 }
00116
00118 size_t
00119 BS_UpDown::
00120 findBarriers( LandscapeTopology* const lt
00121 , MinimumSelector* const ms
00122 , SamplingAbortionCriterion * const sac
00123 )
00125 {
00126 assertbiu(lt!=NULL, "no landscape topology given (==NULL)");
00127 assertbiu(ms!=NULL, "no minimum selector given (==NULL)");
00128 assertbiu(sac!=NULL, "no sampling abortion criterion given (==NULL)");
00129
00130 if (lt->getMinCount() < 1 ) {
00131 return 0;
00132 }
00133 if (!addNewMinima && lt->getMinCount() < 2 ) {
00134 return 0;
00135 }
00136
00137
00138 size_t iterations = 0;
00139
00140 bool wasChanged = true;
00141
00142 bool minimaChanged = addNewMinima;
00143
00144
00145 size_t m1 = ms->select(lt, false);
00146
00147 if (m1 == LandscapeTopology::INVALID_INDEX) {
00148 return 0;
00149 }
00150 size_t m2 = m1;
00151
00152 State * upWalkEnd = NULL;
00153
00154
00155 while( !sac->abortSampling( lt, wasChanged ) ) {
00156 iterations++;
00157
00158 m1 = ms->select(lt, minimaChanged);
00159 assertbiu(m1!=LandscapeTopology::INVALID_INDEX,
00160 "no minimum m1 was selected");
00161
00162
00163 SC_Maximum scMax;
00164 upWalk->walk( lt->getMin(m1), &scMax, NULL );
00165 assertbiu(scMax.getLastAdded() != NULL, "nothing was added to scMax");
00166 upWalkEnd = scMax.getLastAdded()->clone(upWalkEnd);
00167 downWalk->walk( upWalkEnd, &scMax, NULL );
00168
00169 m2 = lt->getMinIndex(scMax.getLastAdded());
00170 if ( m2 == LandscapeTopology::INVALID_INDEX )
00171 {
00172 if (addNewMinima) {
00173
00174 minimaChanged = true;
00175 m2 = lt->addMin(scMax.getLastAdded());
00176 } else {
00177
00178 continue;
00179 }
00180 }
00181
00182 if (m1 != m2) {
00183
00184 wasChanged = lt->addSaddle(m1,m2,scMax.getMaximumState());
00185 } else {
00186 wasChanged = false;
00187 }
00188 }
00189 if (upWalkEnd != NULL) delete upWalkEnd;
00190
00191 return iterations;
00192 }
00193
00194
00195 }