Main Page | Namespace List | Class List | File List | Class Members | File Members

main.cpp

Go to the documentation of this file.
00001 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include <iostream>
00036 #include <fstream>
00037 #include "Apriori.hpp"
00038 using namespace std;
00039 
00040 
00042 
00043 void usage()
00044 {
00045    cerr << "\nUsage: apriori basketfile outcomefile min_supp\n";
00046    cerr << "\n basketfile\t    file, that contains the baskets of itemcodes";
00047    cerr << "\n outcomefile\t    file to write the outcome";
00048    cerr << "\n min_supp\t    support threshold";
00049 
00050    cerr << "\n\nFile formats:";
00051    cerr << "\n\nThe basket file is a plan text file. Each row represents";
00052    cerr << " a basket. "<<endl;
00053    cerr << "A basket is a set of items seperated by a nonnumeric character.";
00054    cerr << "\nIt can be for example a white space, comma, colon, etc. \n";
00055    cerr << "An item is represented by its code which is an integer number\n";
00056    cerr << "greater than or equal to 0.";
00057    cerr << "\nFor more options please check the configuration";
00058    cerr << " file: .apriori_config.";
00059    cerr << "\n\nHave a succesful mining ;-)";
00060    cerr << "\n\n\n\t\t\t\t\tFerenc Bodon\n\n";
00061 }
00062 
00063 void process_config_file( bool& quiet, bool& store_input, 
00064                           unsigned int& size_threshold )
00065 {
00066    ifstream config_file(".apriori_config");
00067    quiet=false;
00068    store_input=true;
00069 
00070    if( !config_file ) 
00071    {
00072       cerr << "Warning: There is no configuration file (.apriori_config)!\n";
00073       cerr << "Default values are used!\n"<<flush;
00074    }
00075    else
00076    {
00077       char temp_string[256];
00078       config_file.getline(temp_string, 256);
00079       config_file.getline(temp_string, 256);
00080       config_file>>quiet;
00081       if( config_file.fail() )
00082       { 
00083          cerr<<"\nWarning: Failed to read in quiet value ";
00084          cerr<< "from the configuration file!";
00085          cerr<<"\nDefault value (false) is used.\n";
00086       }
00087       config_file.getline(temp_string, 256);
00088       config_file>>store_input;
00089       if( config_file.fail() )
00090       { 
00091          cerr<<"\nWarning: Failed to read in store_input value ";
00092          cerr<<"from the configuration file!";
00093          cerr<<"\nDefault value (true) is used.\n";
00094       }
00095       config_file.getline(temp_string, 256);
00096       config_file>>size_threshold;
00097       if( config_file.fail() )
00098       { 
00099          cerr<<"\nWarning: Failed to read in size_threshold value ";
00100          cerr<<"from the configuration file!";
00101          cerr<<"\nDefault value (0) is used.\n";
00102       }
00103       config_file.close();
00104    }
00105 }
00106 
00108 int process_arguments( int argc, char *argv[], ifstream& basket_file, 
00109                        double& min_supp )
00110 {
00111    if ( argc < 4 )
00112    {
00113      usage();
00114      cerr<<"\nError! There are 3 mandatory arguments!\n"<<flush;
00115      return 1;
00116    }
00117    basket_file.open(argv[1]);
00118    if( !basket_file )
00119    {
00120       usage();
00121       cerr << "\nError! The basket file can not be read!"<< flush;
00122       return 1;
00123    }
00124    
00125    min_supp = atof(argv[3]);
00126    if ( min_supp <= 0 || min_supp > 1 )
00127    {
00128       usage();
00129       cerr<<"\nError!\n min_supp should be in the interval (0,1].\n"<<flush;
00130       return 1;
00131    }
00132       
00133    return 0;
00134 }
00135 
00136 int main( int argc, char *argv[] )
00137 {
00138    double min_supp;
00139    bool store_input = true,
00140               quiet = false;
00141    unsigned int size_threshold;
00142    ifstream basket_file;
00143    
00144    process_config_file(quiet, store_input, size_threshold);
00145    if( process_arguments( argc, argv, basket_file, min_supp ) ) return 1;
00146       
00147    if( !quiet )
00148    {
00149       cout << "\n  **********************************************************";
00150       cout << "\n  ***                                                    ***";
00151       cout << "\n  ***        Trie based APRIORI algorithm                ***";
00152       cout << "\n  ***               version: 2.4.9                       ***";
00153       cout << "\n  ***                                                    ***";
00154       cout << "\n  ***    Implemented by: Ferenc Bodon (bodon@cs.bme.hu)  ***";
00155       cout << "\n  ***                                                    ***";
00156       cout << "\n  **********************************************************";
00157       cout<< endl<<endl;
00158    }
00159   
00160    Apriori apriori( basket_file, argv[2], store_input );
00161    apriori.APRIORI_alg( min_supp, quiet, size_threshold );
00162    basket_file.close();
00163    return 0;
00164 }
00165 

Generated on Fri Mar 11 14:48:06 2005 for APRIORI algorithm by  doxygen 1.3.9.1