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

main.cpp

Go to the documentation of this file.
00001 
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif
00035 
00036 #include <iostream>
00037 #include <fstream>
00038 #include "MSApriori.hpp"
00039 using namespace std;
00040 
00041 
00043 
00044 void usage()
00045 {
00046    cerr << "\nUsage: ./msapriori basketfile outcomefile mis_file [min_conf]\n";
00047    cerr << "\n basketfile\t    file, that contains the baskets of itemcodes";
00048    cerr << "\n outcomefile\t    file to write the outcome";
00049    cerr << "\n mis_file\t    file, that contain mis values";
00050    cerr << "\n min_conf\t    confidence threshold";
00051 
00052    cerr << "\n\nFile formats:";
00053    cerr << "\n\nThe basket file is a plan text file. Each row represents a basket. ";
00054    cerr << "A basket is a set of items seperated by a nonnumeric character (for example white space, comma, colon, etc.). ";   
00055    cerr << "An item is represented by its code which is an integer number greater than or equal with 0.";
00056    cerr << "\n\nThe mis file is a plan text file. Each row represents an item and its mis value (a real vaule between 0 and 1). ";
00057    cerr << "They have to be seperated by a non-whitespace cahacter (for example comma, colon, semi-colon, dot,etc.). ";
00058    cerr << "The white spaces are ignored automaically.\n";
00059    cerr << "\nFor more options please check the configuration file: .apriori_config.";
00060    cerr << "\n\nHave a succesful mining ;-)";
00061    cerr << "\n\n\n\t\t\t\t\tFerenc Bodon\n\n";
00062 }
00063 
00064 void process_config_file(bool& quiet, bool& store_input, unsigned long& 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!"<<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 from the configuration file!";
00084          cerr<<"\nDefault value (false) is used.";
00085       }
00086       config_file.getline(temp_string, 256);
00087       config_file>>store_input;
00088       if( config_file.fail() )
00089       { 
00090          cerr<<"\nWarning: Failed to read in store_input value from the configuration file!";
00091          cerr<<"\nDefault value (true) is used.";
00092       }
00093       config_file.getline(temp_string, 256);
00094       config_file>>size_threshold;
00095       if( config_file.fail() )
00096       { 
00097          cerr<<"\nWarning: Failed to read in size_threshold value from the configuration file!";
00098          cerr<<"\nDefault value (0) is used.";
00099       }
00100       config_file.close();
00101    }
00102 }
00103 
00105 int process_arguments( int argc, char *argv[], ifstream& basket_file, ifstream& mis_file, double& min_conf )
00106 {
00107    if ( argc < 4 )
00108    {
00109      usage();
00110      cerr<<"\nError! There are 3 mandatory arguments!"<<flush;
00111      return 1;
00112    }
00113    basket_file.open(argv[1]);
00114    if( !basket_file )
00115    {
00116       usage();
00117       cerr << "\nError! The basket file can not be read!"<< flush;
00118       return 1;
00119    }
00120    
00121    mis_file.open(argv[3]);
00122    if( !mis_file )
00123    {
00124       usage();
00125       cerr << "\nError!The file that contain minimal threshold values can not be read!"<< flush; 
00126       return 1;
00127    }
00128    if ( argc == 5 )
00129    {
00130       min_conf = atof(argv[4]);
00131       if ( min_conf <= 0 || min_conf > 1 )
00132       {
00133          usage();
00134          cerr << "\nError!\n min_conf should be in the interval (0,1].\n"<<flush;
00135          return 1;
00136       }
00137    }
00138    else min_conf = 0;
00139    return 0;
00140 }
00141 
00142 int main( int argc, char *argv[] )
00143 {
00144    double min_conf;
00145    bool store_input = true,
00146               quiet = false;
00147    unsigned long size_threshold;      
00148    ifstream basket_file, mis_file;
00149    
00150    process_config_file(quiet, store_input, size_threshold);
00151    if( process_arguments( argc, argv, basket_file, mis_file, min_conf ) ) return 1;
00152       
00153    if( !quiet )
00154    {
00155       cout << "\n********************************************************************";
00156       cout << "\n***                                                              ***";
00157       cout << "\n***                Trie based MSApriori algorithm                ***";
00158       cout << "\n***                       version: 2.2.24                        ***";
00159       cout << "\n***                                                              ***";
00160       cout << "\n***       Implemented by: Ferenc Bodon (bodon@cs.bme.hu)         ***";
00161       cout << "\n***                                                              ***";
00162       cout << "\n********************************************************************\n\n";
00163    }
00164 
00165    MSApriori msapriori( basket_file, argv[2] , store_input );
00166    msapriori.MSAPRIORI_alg( mis_file, min_conf, quiet, size_threshold );
00167    basket_file.close();
00168    return 0;
00169 }
00170 

Generated on Sun Jun 20 23:41:08 2004 for APRIORI algorithm by doxygen 1.3.5