00001 #ifndef CHAIN_THREADING_ALL
00002 #define CHAIN_THREADING_ALL
00003 #include <biu/LatticeFrame.hh>
00004 #include <cpsp/HCore.hh>
00005 #include "chain_threading.h"
00006 #include <iostream>
00007
00008 #include <gecode/kernel.hh>
00009 #include <gecode/int.hh>
00010 #include <gecode/search.hh>
00011 #include "options/chain_option.h"
00012 #include <cpsp/gecode/GC_ThreadingSymmBreaker.hh>
00013 #include <algorithm>
00014
00015 using namespace Gecode;
00016 using namespace std;
00017 namespace {
00020 class FailTimeStop : public Search::Stop {
00021 private:
00022 Search::TimeStop *ts;
00023 Search::FailStop *fs;
00024 FailTimeStop(int fails, int time) {
00025 ts = new Search::TimeStop(time);
00026 fs = new Search::FailStop(fails);
00027 }
00028 public:
00029 bool stop(const Search::Statistics& s) {
00030 return fs->stop(s) || ts->stop(s);
00031 }
00033 static Search::Stop* create(int fails, int time) {
00034 if (fails < 0 && time < 0) return NULL;
00035 if (fails < 0) return new Search::TimeStop( time);
00036 if (time < 0) return new Search::FailStop(fails);
00037 return new FailTimeStop(fails, time);
00038 }
00039 };
00040 }
00041
00042 namespace cpsp{
00043
00044 namespace scth{
00045
00047 class SideChainThreadingHandler{
00048 private:
00053 int calculateCoreSize(std::string* seq);
00054
00058 pair<int,int> checkParity(const std::string* seq);
00059
00063 pair<int,int> checkHCoreParity(const HCore* hCore);
00064
00068 bool checkSequenceHCoreParity(const std::string *seq, const HCore* hCore);
00069
00071 int solutionsNum;
00072 public:
00074 SideChainThreadingHandler(const SideChainOptions& );
00075 int getSolutionsNum();
00076 };
00077
00079 class RunSideChainThreading{
00080
00081
00082
00083 public:
00084
00086 static void deleteBrackets(std::string& absMoves){
00087 for(size_t i=0;i<absMoves.size();){
00088 if(absMoves[i]=='(' || absMoves[i]==')' ){
00089 absMoves.erase(i,1);
00090 }
00091 i=i+1;
00092 }
00093 }
00094
00102 static void drawElement(const std::string* seq,std::string solution,const std::string* jmlHome, const std::string* viewerHome,const std::string* Description ){
00103 assert(viewerHome!=NULL);
00104 assert(Description!=NULL);
00105
00106 std::string modifiedSeq= *seq;
00107
00108
00109 std::string solutionWithoutBrackets=solution;
00110 RunSideChainThreading::deleteBrackets(solutionWithoutBrackets);
00111 string lat;
00112
00113 if(*(Description)=="fcc" || *(Description)=="FCC")
00114 lat="FCC";
00115 else lat="CUB";
00116 string binary=*viewerHome+" -seq="+modifiedSeq+" -abs="+solutionWithoutBrackets+" -jmolHome="+*jmlHome+" -jmol -lat="+lat+"";
00117
00118
00119
00120 }
00121
00129 template <template<class> class Engine>
00130 static int run(const std::string *sequence,const biu::LatticeFrame* latFrame, const biu::IndexVec* neighVecs,cpsp::HCore* hCore,const cpsp::scth::SideChainOptions& option, const int maxSol){
00131 assert(sequence!=NULL);
00132 assert(latFrame!=NULL);
00133 assert(neighVecs!=NULL);
00134 assert(hCore!=NULL);
00135
00136 biu::IPointVec* symmetryShiftVec=NULL;
00137 if(option.BreakSym)
00138 symmetryShiftVec = cpsp::gecode::GC_ThreadingSymmBreaker::generateGlobalShiftVec(
00139 hCore, latFrame, symmetryShiftVec);
00140 int solutions=0;
00141 SideChainThreading* sideChainInstance=new SideChainThreading(sequence,latFrame,neighVecs,hCore,symmetryShiftVec,option.BreakSym);
00142
00143 unsigned int n_p = 0;
00144 unsigned int n_b = 0;
00145 if (sideChainInstance->status() != SS_FAILED) {
00146 n_p = sideChainInstance->propagators();
00147 n_b = sideChainInstance->branchings();
00148 }
00149
00150
00151 Space* s = dynamic_cast<Space*>(sideChainInstance);
00152 Engine<Space> e(s,Search::Config::c_d,Search::Config::a_d,NULL);
00153 delete s;
00154 while(solutions< maxSol ){
00155 SideChainThreading* ex = dynamic_cast<SideChainThreading*>(e.next());
00156 if (ex == NULL)
00157 break;
00158
00159
00160 std::string sl = ex->print(sequence,latFrame,option.Output);
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 solutions++;
00175 delete ex;
00176 }
00177 return solutions;
00178 }
00179 };
00180 }
00181 }
00182 #endif