//------------------------------------------------------------------- // Author........: Aleksander Øhrn // Date..........: // Description...: Simple main program for ad hoc programming using // the ROSETTA C++ library. // Revisions.....: // Comments......: //=================================================================== #include #include #include #include #include #include #include #include #include //------------------------------------------------------------------- // Method........: main // Author........: Aleksander Øhrn // Date..........: // Description...: // Comments......: Implements the example on page 128 of my thesis, // with some minor variations and additions. // // The sole purpose of this program is to demonstrate // how a pipeline can be defined and executed using // the top-level methods. Not terribly exciting, but // shows how you initialize the library, etc. // // Revisions.....: // Comments......: Some ugly Handle::GetPointer calls here and // there, due to current lack of member template // support. //=================================================================== int main(int argc, char *argv[]) { Message message; // Check command-line parameters. if (argc != 2) { message.Notify("Usage: " + String(argv[0]) + " "); return 0; } // Name parameters. String filename = argv[1]; // Install prototypes. Installer::Install(); #if defined(_RSES) // Unlock RSES restriction? // ... #endif Handle algorithm[6]; // Set up the pipeline topology. algorithm[0] = ObjectManager::GetIdentifiedAlgorithm(MYDECISIONTABLEIMPORTER); // Import the data table... algorithm[1] = ObjectManager::GetIdentifiedAlgorithm(BRORTHOGONALSCALER); // ...discretize numerical attributes... algorithm[2] = ObjectManager::GetIdentifiedAlgorithm(EQUALFREQUENCYSCALER); // ...deal with unprocessed numerical attributes, if any... algorithm[3] = ObjectManager::GetIdentifiedAlgorithm(SAVGENETICREDUCER); // ...compute reducts... algorithm[4] = ObjectManager::GetIdentifiedAlgorithm(RULEGENERATOR); // ...overlay them the last decision table to get rules... algorithm[5] = ObjectManager::GetIdentifiedAlgorithm(PROLOGRULEEXPORTER); // ...and export the rules, in this example to Prolog. // Set parameters. Accessor methods can be called directly, too, of course. algorithm[0]->SetParameters("FILENAME = " + filename + ".txt"); algorithm[1]->SetParameters("MODE = Save; MASK = T; FILENAME = cuts.txt"); algorithm[2]->SetParameters("MODE = Save; MASK = T; INTERVALS = 1; FILENAME = dummycutsifany.txt"); algorithm[3]->SetParameters("SEED = 1234; DISCERNIBILITY = Object"); algorithm[4]->SetParameters(""); algorithm[5]->SetParameters("FILENAME = " + filename + ".pl"); // Instantiate initial structure. Handle structure = dynamic_cast(Structure *, Creator::DecisionTable()); // Add the structure to a project to enable structural backtracking via the FindParent method. // See library documentation for details. Handle project = Creator::Project(); project->AppendChild(structure.GetPointer()); ProjectManager::InsertProject(project.GetPointer()); int i; // Process the pipeline. Exit gracefully. Make a "chain" for backtracking's sake. for (i = 0; i < 6; i++) { // Apply algorithm. Handle result = structure->Apply(*algorithm[i]); // Failure? if (result == NULL) { message.Error("Failed to apply " + IdHolder::GetClassname(algorithm[i]->GetId()) + "."); return 0; } // New structure? if (structure != result) { structure->AppendChild(result.GetPointer()); structure = result; } } return 1; }