void goUp(Task * task) { while (task->cur->rel->relType != TREL_END) task->cur = task->cur->rel->next; task->cur = task->cur->rel->next; checkRelation(task); }
//========PUBLIC FUNCTIONS========== void Interface::start() { char ch = ' '; while(ch != 'q') { checkRelation(); printMainMenu(); setStatus(""); //reset status message cout << "Choice: "; cin >> ch; switch(ch) { case 'a': about(); break; case 's': enterTheMatrixQuestion(); break; case '1': addCompOrPerson(); break; case '2': viewCompsOrPersons(); break; case '3': settingsMain(); break; default: break; } } }
void generarVecinoRandom( string &relation, vector< bool> &vecino) { int num_atributos; int num_ejemplos; checkRelation( relation, num_atributos, num_ejemplos); for( int i = 0; i < num_atributos-1; i++) { if( Rand() >= 0.5) { flip( vecino, i); } } }
virtual bool check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo) { try { if (checkRelation(m_relation, m_name, keyLocator.getName())) return true; failInfo = "KeyLocatorChecker failed!"; return false; } catch (KeyLocator::Error& e) { failInfo = "KeyLocator does not have name"; return false; } }
void getNextJob(Task * task) { if (task == NULL || task->cur == NULL) return; switch (task->cur->cmdType) { case TCMD_SCRIPT: case TCMD_LIST: goDown(task); break; case TCMD_PIPE: case TCMD_SIMPLE: if (!task->firstly) checkRelation(task); break; } if (task->firstly) task->firstly = 0; }
virtual bool check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo) { try { if (m_hyperPRegex->match(packetName) && m_hyperKRegex->match(keyLocator.getName()) && checkRelation(m_hyperRelation, m_hyperKRegex->expand(), m_hyperPRegex->expand())) return true; failInfo = "KeyLocatorChecker failed!"; return false; } catch (KeyLocator::Error& e) { failInfo = "KeyLocator does not have name"; return false; } }
void greedyAleatorio( string &relation, vector< vector< float> > &training, vector< vector< float> > &test, vector< bool> &seleccion, float tolerancia) { float acierto = 0; bool fin = false; bool vacio = false; int fp; float mejor = 0; float max = 0; int total = 0; int num_atributos; int num_ejemplos; vector< int> LRC; float cmejor = -1000000; float cpeor = 1000000; float umbral; int iaux; checkRelation( relation, num_atributos, num_ejemplos); vector< bool> solucion(num_atributos, 0); vector< bool> LC( num_atributos, 0); if( num_ejemplos % 2 == 0) { num_ejemplos = num_ejemplos/2; } else { num_ejemplos = (num_ejemplos/2)-1; } // Mientras que no acabemos o la lista de atributos esté vacía while( !vacio && !fin) { // Identificamos cual es el mejor y el peor valor for( int i = 0; i < num_atributos-1; i++) { if( LC[i] == 0) { LC[i] = 1; acierto = getExito( relation, training, test, LC); if( acierto > cmejor) { cmejor = acierto; } if( acierto < cpeor) { cpeor = acierto; } LC[i] = 0; } } // Calculamos el umbral umbral = cmejor - tolerancia*( cmejor - cpeor); // Metemos en LRC las características cuyo éxito superan el umbral for( int i = 0; i < num_atributos-1; i++) { if( LC[i] == 0) { LC[i] = 1; acierto = getExito( relation, training, test, LC); if( acierto >= umbral) { LRC.push_back(i); } LC[i] = 0; } } // Cogemos una característica de LRC de forma aleatoria iaux = Randint(0, LRC.size()-1); fp = LRC[iaux]; solucion[fp] = 1; max = getExito( relation, training, test, solucion); // Comprobamos si el mejor éxito anterior es mejor que el mejor éxito hasta el momento, en caso contrario acabamos if( max >= mejor) { seleccion = solucion; LC = solucion; LRC.clear(); mejor = max; } else { fin = true; } // Comprobamos todos los atributos total++; if( total == num_atributos-1) { vacio = true; } } }
/* * relation -> nombre de los datos, se utiliza para cargar los valores * trainig -> datos de entrenamiento * test -> datos para probar nuestro clasificador * seleccion -> características más óptimas que hemos encontrado */ void greedy( string &relation, vector< vector< float> > &training, vector< vector< float> > &test, vector< bool> &seleccion) { float acierto = 0; bool fin = false; bool vacio = false; int fp; float mejor = 0; float max = 0; int total = 0; int num_atributos; int num_ejemplos; checkRelation( relation, num_atributos, num_ejemplos); //Vemos con que datos estamos tratando if( num_ejemplos % 2 == 0) { num_ejemplos = num_ejemplos/2; } else { num_ejemplos = (num_ejemplos/2)-1; } // Mientras que no acabemos o la lista de atributos esté vacía while( !vacio && !fin) { // Por cada atributo, probamos uno a uno cual produce el mayor éxito for( int i = 0; i < num_atributos-1; i++) { if( seleccion[i] == 0) { seleccion[i] = 1; acierto = getExito( relation, training, test, seleccion); if( max < acierto) { //Actualizamos el exito al máximo que hemos encontrado fp = i; max = acierto; } seleccion[i] = 0; } } // Comprobamos si el mejor éxito anterior es mejor que el mejor éxito hasta el momento, en caso contrario acabamos if( max >= mejor) { seleccion[fp] = 1; mejor = max; } else { //En caso contrario actualizamos una de las conciciones para salir del bucle fin = true; } // Comprobamos todos los atributos total++; if( total == num_atributos-1) { //Si ya hemos recorrido todos los atributos, salimos vacio = true; } } }
int main( int argc, char const *argv[] ){ FILE *configFile; /*Pointer to config file*/ FILE *queryFile; /*Poiner to query file*/ char command[COMMAND_LENGTH]; /*A temp string for the query command*/ char relName[MAX_STRING]; /*A temp string for the relation name*/ char attrName[MAX_STRING]; /*A temp string for attribute name*/ char relop[RELOP_LENGTH]; /*Array to hold relational operator*/ char value[MAX_STRING]; /*Array to hold string to compare*/ int numericValue; /*Int to hold integer value to compare*/ /*If the wrong number of arguments is given, print an error message and exit. */ if( argc != NUM_ARGS){ fprintf( stderr, "Incorrect number of arguments\n" ); exit(1); } /*If the config file cannot be opened for reading, print an error message and exit. */ if( (configFile = ( fopen( argv[CONFIG_FILE_ARG], "r"))) == NULL){ fprintf( stderr, "There was an error trying to open config file %s\n", argv[CONFIG_FILE_ARG]); exit(1); } /*If the query file cannot be opened for reading, print an error message and exit. */ if( (queryFile = ( fopen( argv[QUERY_FILE_ARG], "r"))) == NULL){ fprintf( stderr, "There was an error trying to open query file %s\n", argv[QUERY_FILE_ARG]); exit(1); } /*Keep checking query file for another command */ while( fscanf( queryFile, "%s", command) == 1){ /*If command entered is "nattr", get the relation name after the cmd, and check to see if it is in the db. If so, call function to get the number of attributes for the specified relation. If not, print an error message and move to the next query. */ if( strcmp( command, "nattr") == 0){ fscanf( queryFile, "%s", relName); if( checkRelation( configFile, relName) == 1){ nattr( relName); } else{ printf(" Error: %s relation is not in the database.\n\n", relName); fflush( stdout); continue; } } /*If command entered is "tuplen", get the relation name after the cmd and check to see if it is in the db. If so, call the function to get the length of each tuple in this relation. If the relation is not in the db, print an error message and move to the next query. */ else if( strcmp( command, "tuplen") == 0){ fscanf( queryFile, "%s", relName); if( checkRelation( configFile, relName) == 1){ tuplen( relName, 1); } else{ printf(" Error: %s relation is not in the database.\n\n", relName); fflush( stdout); continue; } } /*If command entered is "infattr", get the relation and attribute names after the cmd. Check if the relation is in the database. If it is, call the function to check if the attribute is in that relation (and if it is, print the type and number of bytes of the attribute). If the relation is not in the db, print an error message and move to the next query. */ else if( strcmp( command, "infattr") == 0){ fscanf( queryFile, "%s", relName); fscanf( queryFile, "%s", attrName); if( checkRelation( configFile, relName) == 1){ infattr( relName, attrName, 1); } else{ printf(" Error: %s relation is not in the database.\n\n", relName); fflush( stdout); continue; } } /*If the command entered is "count", get the relation name after the cmd and check that it is a relation in the db. If so, call the function which prints the number of tuples in this relation. If the relation is not in the db, print an error message and move to the next query in the query file. */ else if( strcmp( command, "count") == 0){ fscanf( queryFile, "%s", relName); if( checkRelation( configFile, relName) == 1){ count( relName, 1); } else{ printf(" Error: %s relation is not in the database.\n\n", relName); fflush( stdout); continue; } } /*If command entered is "project", get the relation name and attribute name after the cmd. Check that the relation is indeed a relation in the database. If so, call the function which prints all non duplicate values for this relation in the database. If this is not a relation in the database, print an error message and move on to the next query. */ else if( strcmp( command, "project") == 0){ fscanf( queryFile, "%s", relName); fscanf( queryFile, "%s", attrName); if( checkRelation( configFile, relName) == 1){ project( relName, attrName); } else{ printf(" Error: %s relation is not in the database.\n\n", relName); fflush( stdout); continue; } } /*If command entered is "select", get the relation name, attribute name, and relational operator that follow, and store their values. Check if relation is in db, then check that the attribute belongs to the relation. Then get the type. If the type is INT, then get the int from the next position in the query file, and set the string to "". If the type is STRING, then get the string from the next position in the query file, and set the int to -1. In either case ("I" or "S") call the function which prints out all tuples who satisfy the condition in the query. If this is not a relation in the db, print an error message and go on to the next query. */ else if( strcmp( command, "select") == 0){ fscanf( queryFile, "%s", relName); fscanf( queryFile, "%s", attrName); fscanf( queryFile, "%s", relop); /*If the relation is in db */ if( checkRelation( configFile, relName) == 1){ /*If the attribute belongs to the relation */ if( (infattr( relName, attrName, 0)) == 1){ /*If the relation type is "I" */ if( whatType( relName, attrName, 0) == 1){ /*INT type*/ fscanf( queryFile, "%d", &numericValue); /*Store int*/ /*Dummy value used to determine if we are trying to compare an int and a string, later on in select function */ strcpy( value, "\0"); select( relName, attrName, relop, numericValue, value, "I"); } /*If the relation type is "S" */ else{ fscanf( queryFile, "%s", value); /*Store string*/ /*Dummy value used to determine if we are trying to compare a string and an int, later on in select function */ numericValue = -1; select( relName, attrName, relop, numericValue, value, "S"); } } } /*If the relation is not in db, print an error message and go to next query */ else{ printf(" Error: %s relation is not in the database.\n\n", relName); fflush( stdout); continue; } } /*If the command entered is "quit", then close the files and exit the program. */ else if( strcmp( command, "quit") == 0){ /*Close query file*/ if( fclose( queryFile) == EOF){ fprintf( stderr, "Error closing query file.\n"); exit(1); } /*Close config file*/ if( fclose( configFile) == EOF){ fprintf( stderr, "Error closing config file.\n"); exit(1); } exit(1); } } return 0; }