'ElMo-Knock'

main.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>   // file I/O
00003 #include <getopt.h>
00004 #include <string.h>
00005 #include <time.h>
00006 #include <iomanip>
00007 #include <assert.h>
00008 #ifdef PARALLEL
00009         #include <mpi.h>
00010 #endif
00011 
00012 using namespace std;
00013 
00014 //#include "knocktest.h"
00015 //#include "cpptest-htmloutput.h"
00016 #include "general_hash_functions.h"
00017 #include "ufes.h"
00018 #include "enumeffknocks.h"
00019 #include "options.h"
00020 #include "util.h"
00021 #include "bitefm.h"
00022 
00034 int main(int argc, char** argv) {
00035         
00036 
00037         int c,init_only=0;
00038         //string efm_fname,reac_fname,substrate_fname,target_fname, init_knocks_fname,yield_fname, coreefm_fname;
00039         
00040         int nump=1, proc_id=0;
00041         string ko_fname,config_fname;
00042 
00043         #ifdef PARALLEL
00044         MPI_Init(&argc,&argv);
00045         util::get_proc_id_nump(proc_id,nump);
00046         #endif
00047                 
00048 
00049 
00050         Options options;
00051 
00052         config_fname="configs.knock";
00053         while ((c = getopt(argc, argv, "c:y:")) >= 0) {
00054                 switch (c) {
00055                         case 'c':  //efm file name
00056                                 config_fname=optarg;
00057                                 break;
00058                         case 'y': 
00059                                 init_only=1;
00060                                 break;
00061                 }
00062         }       
00063         
00064         options.load(config_fname);
00065         if (proc_id==0)
00066                 options.print();
00067 
00068 
00069         if (init_only && proc_id==0) 
00070                 cout << endl << "\t"<<util::get_time_str()<<": loading and initializing network only."<<endl;
00071 
00072         MetabolicNetwork metab_network(options);
00073 
00074         if (init_only) {
00075                 if (proc_id==0)
00076                         cout << endl << "\t"<<util::get_time_str()<<": network loaded and initialized only."<<endl;
00077                 #ifdef PARALLEL         
00078                 MPI_Finalize(); 
00079                 #endif
00080                 return 0;
00081         }
00082 
00083 
00084 
00085         ko_fname=options.get_output_fname();
00086         long ts = time (NULL);
00087         ko_fname=ko_fname+".";
00088         stringstream oss;
00089         oss << ts;
00090         ko_fname=ko_fname+oss.str();
00091         //add timestamp to ko_fname
00092 
00093         if (util::trim(ko_fname)=="") {
00094                 if (proc_id==0)
00095                         cout << endl << "\t"<<util::get_time_str()<<": Output file name not given."<<endl;
00096 
00097         }
00098 
00099         if (nump>1) {
00100                 stringstream proc_id_str;
00101                 proc_id_str << "."<<proc_id;
00102                 ko_fname=ko_fname+proc_id_str.str();
00103         }
00104 
00105         if (proc_id==0) {
00106                 cout << endl << "\t"<<util::get_time_str()<<": metabolic network loaded..." <<endl;
00107                 cout << endl << "\t"<<util::get_time_str();
00108         }
00109 
00110 
00111         EnumEffKnocks enum_eff_knocks(&metab_network);
00112 
00113 
00114 
00115         double start_enum, end_enum;
00116         
00117         //is direct enumeration requested
00118         if (options.get_algorithm().compare("direct")==0) {
00119 
00120                 cout << endl << "\t"<<util::get_time_str()<<": direct enumeration..." <<endl;
00121                 util::current_time(&start_enum);
00122                 enum_eff_knocks.enum_erk_direct();              
00123                 cout << endl << "\t"<<util::get_time_str()  << ": (pid="<<proc_id<<") # accepted ERK: "<<enum_eff_knocks.get_erk_map().size();
00124                 util::current_time(&end_enum);
00125                 enum_eff_knocks.set_erk_enum_time(end_enum-start_enum);
00126                 enum_eff_knocks.print_erk(ko_fname);
00127 
00128                 
00129                 cout << endl << "\t"<<util::get_time_str()  << ": ERKs enumerated in "<< (end_enum-start_enum)<<" seconds";
00130 
00131         
00132         } else {
00133         //is indirect enumeration requested
00134 
00135                 cout << endl << "\t"<<util::get_time_str()<<": indirect enumeration..." <<endl;
00136                 
00137                 util::current_time(&start_enum);
00138                 
00139                 //enumerated UFES
00140                 enum_eff_knocks.enum_ufes();
00141                 //exchange UFES subsets between compute nodes
00142                 enum_eff_knocks.communicate_ufes_map();
00143                 cout << endl << "\t"<<util::get_time_str()  << ": (pid="<<proc_id<<") # accepted UFES: "<<enum_eff_knocks.get_ufes_map().size();
00144                 //cout << endl << "\t"<<util::get_time_str()  << ": (pid="<<proc_id<<") # accepted UFES: "<<enum_eff_knocks.get_ufes_hash().size();
00145 
00146                 #ifdef PARALLEL         
00147                         MPI_Barrier(MPI_COMM_WORLD);
00148                 #endif
00149                 util::current_time(&end_enum);
00150                 enum_eff_knocks.set_ufes_enum_time(end_enum-start_enum);
00151                 cout << endl << "\t"<<util::get_time_str()  << ": UFES enumerated in "<< (end_enum-start_enum)<<" seconds";
00152                 //enum_eff_knocks.print_ufes("ufes.txt");
00153                 util::current_time(&start_enum);
00154                 enum_eff_knocks.enum_erk();
00155                 enum_eff_knocks.communicate_erk_map();
00156 
00157                 cout << endl << "\t"<<util::get_time_str()  << ": (pid="<<proc_id<<") # accepted ERK: "<<enum_eff_knocks.get_erk_map().size();
00158                 util::current_time(&end_enum);
00159                 cout << endl << "\t"<<util::get_time_str()  << ": ERKs enumerated in "<< (end_enum-start_enum)<<" seconds";
00160 
00161                 enum_eff_knocks.set_erk_enum_time(end_enum-start_enum);
00162                 enum_eff_knocks.print_erk(ko_fname);
00163                 //if (proc_id==0)
00164                 //      cout << endl << "\t"<<util::get_time_str()<<": done"<<endl;
00165         }
00166 
00167         #ifdef PARALLEL         
00168                 MPI_Barrier(MPI_COMM_WORLD);
00169                 MPI_Finalize(); 
00170         #endif
00171         return 0;
00172 
00173 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines