00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GC_HPTHREADING_HH_
00021 #define GC_HPTHREADING_HH_
00022
00023
00024 #include "cpsp/HPThreadingHandler.hh"
00025 #include "cpsp/gecode/GC_ThreadingSpace.hh"
00026
00027 namespace cpsp
00028 {
00029
00037 namespace gecode
00038 {
00039
00044 class GC_HPThreading : public cpsp::HPThreadingHandler
00045 {
00046
00047 public:
00048
00050 enum CORESELECTS { FIRST, ALL_BEST, ALL };
00052 enum RUNMODE { COUNT, ENUMERATE };
00054 enum DISTANCE { DIST_POSITIONS, DIST_ABSMOVES, DIST_SHAPES, DIST_NONE };
00055
00056
00057
00058 protected:
00059
00061 bool verboseOutput;
00063 const biu::LatticeDescriptor* latDescr;
00065 biu::LatticeFrame* latFrame;
00067 HCoreDatabase* coreDB;
00069 std::string sequence;
00071 GC_ThreadingSpace::HullLevel hullLvl;
00073 unsigned int coreSize;
00076 unsigned int minEvenOddHs;
00078 unsigned int contactsInSeq;
00080 unsigned int maxPCoreDistance;
00082 GC_ThreadingSpace::SeqFeatureMap seqFeatureMap;
00084 bool useSymmetryBreaking;
00086 bool useDDS;
00088 unsigned int maxStructures;
00090 CORESELECTS coreSelection;
00092 RUNMODE runMode;
00094 bool noOutput;
00096 bool statisticsOut;
00100 bool noRecomputation;
00102 DISTANCE distanceMode;
00104 unsigned int distanceMin;
00106 bool normalizeStructures;
00107
00108
00109 template<class ENGINE, class SPACE>
00110 unsigned int
00111 enumerateStructures(SPACE *space, unsigned int maxNum,
00112 Gecode::Search::Statistics *stat, std::ostream &out);
00113
00114 template<class Int, class SPACE>
00115 Int
00116 countBAB(SPACE *space, unsigned int c_d, unsigned int a_d,
00117 Gecode::Search::Statistics* stat, Gecode::Search::Stop* st,
00118 Int maxNum);
00119
00120 public:
00122 GC_HPThreading(const biu::LatticeDescriptor* latDescr_ = NULL,
00123 HCoreDatabase* db = NULL, const std::string seq = "")
00124 throw(cpsp::Exception);
00125 virtual ~GC_HPThreading();
00126
00128 unsigned int
00129 enumerateStructures(SuperSpace * space, unsigned int maxNum,
00130 Gecode::Search::Statistics *globalStat = NULL,
00131 std::ostream &out = std::cout);
00132
00134 unsigned int
00135 countStructures(SuperSpace * space, unsigned int maxNum,
00136 bool useDDS = true, Gecode::Search::Statistics *statistic = NULL);
00137
00138
00139 virtual
00140 unsigned int
00141 generateStructures();
00142
00145 virtual
00146 unsigned int
00147 enumerateStructures(StringVec & structs);
00148
00149 public:
00150
00152 void
00153 setVerboseOutput( const bool val ) { verboseOutput = val; }
00155 const bool
00156 getVerboseOutput( void ) const { return verboseOutput; }
00157
00159 void
00160 setLatticeDescriptor( const biu::LatticeDescriptor* val );
00162 const biu::LatticeDescriptor*
00163 getLatticeDescriptor( void ) const { return latDescr; }
00164
00166 void
00167 setCoreDB( HCoreDatabase* db ) { coreDB = db; }
00169 HCoreDatabase*
00170 getCoreDB( void ) const { return coreDB; }
00171
00173 void
00174 setSequence( const std::string& seq ) throw(cpsp::Exception);
00176 const std::string&
00177 getSequence( void ) { return sequence; }
00178
00180 const unsigned int
00181 getCoreSize( void ) const { return coreSize; }
00182
00184 const unsigned int
00185 getContactsInSeq( void ) const { return contactsInSeq; }
00186
00188 void
00189 setSymmetryBreaking( const bool val ) { useSymmetryBreaking = val; }
00191 const bool
00192 getSymmetryBreaking( void ) const { return useSymmetryBreaking; }
00193
00195 void
00196 setUsingDDS( const bool val ) { useDDS = val; }
00198 const bool
00199 getUsingDDS( void ) const { return useDDS; }
00200
00202 void
00203 setMaxStructures( const unsigned int val ) { maxStructures = val; }
00205 const unsigned int
00206 getMaxStructures( void ) const { return maxStructures; }
00207
00209 void
00210 setCoreSelection( const CORESELECTS val ) { coreSelection = val; }
00212 const CORESELECTS
00213 getCoreSelection( void ) const { return coreSelection; }
00214
00216 void
00217 setRunMode( const RUNMODE val ) { runMode = val; }
00219 const RUNMODE
00220 getRunMode( void ) const { return runMode; }
00221
00223 void
00224 setNoOutput( const bool val ) { noOutput = val; if(noOutput) setVerboseOutput(false);}
00226 const bool
00227 getNoOutput( void ) const { return noOutput; }
00228
00230 void
00231 setStatOutput( const bool val ) { statisticsOut = val; }
00233 const bool
00234 getStatOutput( void ) const { return statisticsOut; }
00235
00237 void
00238 setNoRecomputation( const bool val ) { noRecomputation = val; }
00240 const bool
00241 getNoRecomputation( void ) const { return noRecomputation; }
00242
00244 void
00245 setDistanceMode( const DISTANCE val ) { distanceMode = val; }
00247 const DISTANCE
00248 getDistanceMode( void ) const { return distanceMode; }
00249
00251 void
00252 setDistanceMin( const unsigned int val ) { distanceMin = val; }
00254 const unsigned int
00255 getDistanceMin( void ) const { return distanceMin; }
00256
00258 void
00259 setNormalizeStructures( const bool val ) { normalizeStructures = val; }
00261 const bool
00262 getNormalizeStructures( void ) const { return normalizeStructures; }
00263
00264
00265 };
00266
00267 template<class ENGINE, class SPACE>
00268 inline
00269 unsigned int
00270 GC_HPThreading::enumerateStructures(SPACE *space,
00271 unsigned int maxNum, Gecode::Search::Statistics *stat,
00272 std::ostream &out)
00273 {
00274 unsigned int sols = 0;
00275 SPACE* s = dynamic_cast<SPACE*>(space);
00276
00277 ENGINE dfs_e( s,
00278 (noRecomputation?1:Gecode::Search::Config::c_d),
00279 (noRecomputation?1:Gecode::Search::Config::a_d),
00280 NULL );
00281
00282 SPACE* solution = dfs_e.next();
00283
00284 while (solution != NULL && ++sols <= maxNum) {
00285
00286 if (normalizeStructures) {
00287 out <<latFrame->getString(
00288 latFrame->getDescriptor()->normalizeSequence(
00289 latFrame->indicesToAbsMoves(
00290 solution->getSolution())))
00291 <<std::endl;
00292 } else {
00293 out <<latFrame->getString(
00294 latFrame->indicesToAbsMoves(
00295 solution->getSolution()))
00296 <<std::endl;
00297 }
00298
00299 solution->handleSolution(solution);
00300 delete solution;
00301 solution = dfs_e.next();
00302 } ;
00303
00304 if (solution != NULL)
00305 delete solution;
00306
00307 if (stat != NULL) {
00308
00309 *stat = dfs_e.statistics();
00310 }
00311 return (sols > maxNum ? maxNum : sols);
00312 }
00313
00314 template<class Int, class SPACE>
00315 inline
00316 Int
00317 GC_HPThreading::countBAB(SPACE *space, unsigned int c_d, unsigned int a_d,
00318 Gecode::Search::Statistics* stat, Gecode::Search::Stop* st,
00319 Int maxNum)
00320 {
00321
00322 Gecode::BAB<SPACE> engine( space, c_d, a_d, st);
00323
00324 Int sols = 0;
00325
00326
00327 SPACE* nextSol = engine.next();
00328
00329 while( nextSol != NULL && ++sols <= maxNum) {
00330
00331 sols++;
00332
00333 nextSol->handleSolution(nextSol);
00334 delete nextSol;
00335 nextSol = engine.next();
00336 }
00337 if (nextSol != NULL)
00338 delete nextSol;
00339 if (stat != NULL)
00340 *stat = engine.statistics();
00341 return (sols > maxNum ? maxNum : sols);
00342 }
00343
00344
00345 }
00346 }
00347
00348 #endif