boolean runServices(){ boolean OK = true; for(int i=0; i<servicesN; i++){ int sleepPeriod = services[i]->getSleepPeriod(); if(sleepPeriod <=0){ //services with sleep period as 0 or <0 are always served if(!services[i]->run()) OK = false; } else if((getSecs() - lastExecution[i]) >= sleepPeriod){ lastExecution[i] = getSecs(); if(!services[i]->run()) OK = false; } } return OK; }
void end_time() { getSecs(); secs = theseSecs - startSecs; millisecs = (int)(1000.0 * secs); return; }
void start_time() { getSecs(); startSecs = theseSecs; return; }
void quality_benchmark_fann_som(unsigned int width, unsigned int height, char *topology, char *neighborhood, char *decay, struct fann_train_data *train_data, struct fann_train_data *test_data, FILE * train_out, unsigned int num_input, unsigned int max_training_examples, double seconds_between_reports) { float test_error; double elapsed = 0; double total_elapsed = 0; struct fann *ann; unsigned int current_example = 0; ann = fann_create_som(width, height, num_input); /* Set the topology */ if (!strcmp(topology, "hexagonal")) { ann->som_params->som_topology = FANN_SOM_TOPOLOGY_HEXAGONAL; } else if (!strcmp(topology, "rectangular")) { ann->som_params->som_topology = FANN_SOM_TOPOLOGY_RECTANGULAR; } else { fprintf(stderr, "Error: Unknown topology: %s\n", topology); exit(1); } /* Set the neighborhood */ if (!strcmp(neighborhood, "distance")) { ann->som_params->som_neighborhood = FANN_SOM_NEIGHBORHOOD_DISTANCE; } else if (!strcmp(neighborhood, "gaussian")) { ann->som_params->som_neighborhood = FANN_SOM_NEIGHBORHOOD_GAUSSIAN; } else { fprintf(stderr, "Error: Unknown neighborhood: %s\n", neighborhood); exit(1); } /* Set the decay */ if (!strcmp(decay, "linear")) { ann->som_params->som_learning_decay = FANN_SOM_LEARNING_DECAY_LINEAR; } else if (!strcmp(decay, "inverse")) { ann->som_params->som_learning_decay = FANN_SOM_LEARNING_DECAY_INVERSE; } else { fprintf(stderr, "Error: Unknown decay type: %s\n", decay); exit(1); } calibrate_timer(); while (current_example < max_training_examples) { /* train */ elapsed = 0; start_timer(); while((elapsed < (double) seconds_between_reports) && (current_example < max_training_examples)) { fann_train_example_som(ann, train_data, current_example, max_training_examples); elapsed = time_elapsed(); current_example++; } stop_timer(); total_elapsed += getSecs(); /* make report */ test_error = fann_get_MSE_som(ann, test_data); /* output the statistics */ fprintf(train_out, "%8.2f %8.6f %5d\n", total_elapsed, test_error, current_example); fprintf(stderr, "secs: %8.2f, test_error: %8.6f training_examples: %5d\r", total_elapsed, test_error, current_example); } fprintf(stdout, "\nTraining samples: %d, samples/sec: %f\n", max_training_examples, (float)max_training_examples / total_elapsed); fann_destroy(ann); }
void start_timer() { startSecs = getSecs(); return; }
double stop_timer() { return getSecs() - startSecs; }