void Solution::print_file_format_buses(const char* f_p) { FILE *file; /*File*/ /* Check that it was possible to make an assignment */ assert(is_assignment_feasible()); /* Open the file to store the solution*/ file = fopen(f_p, "w"); /* Check if the file could be opened or not.*/ if (file == NULL) { printf(" ERROR! The file in which a solution is going to be stored" "could not be opened (Class Solution).\n"); return; } /* Print the total number of paths that need to be drawn*/ fprintf(file, "%d\n", routes->get_num_routes()); /* Print the total distance*/ fprintf(file, "%lf\n", get_total_distance()); /* Print the total time*/ fprintf(file, "%lf\n", get_total_time()); /* Print the routes traversed by the buses*/ routes->print_file_format(file); fclose(file); }
void Solution::print_file_format_students(const char* f_p) { FILE *file; /*File*/ /* Assignment calculated by the assignment maker */ //StopAssignment* assignment = assignments; /* Check that it was possible to make an assignment */ assert(assignments != NULL); /* Open the file to store the solution*/ file = fopen(f_p, "w"); /* Check if the file could be opened or not.*/ if (file == NULL) { printf(" ERROR! The file in which a solution is going to be stored" " could not be opened (Class Solution).\n"); return; } /* Print the total number of paths that need to be drawn*/ fprintf(file, "%d\n", instance->get_num_students()); /* Print the total distance*/ fprintf(file, "%lf\n", get_total_distance()); /* Print the total time*/ fprintf(file, "%lf\n", get_total_time()); /* Print paths of the students to the stops they are assigned to*/ assignments->print_file_format(file); fclose(file); }
/**@brief Function for populating simulated running speed and cadence measurement. */ static void rsc_sim_measurement(ble_rscs_meas_t * p_measurement) { static uint32_t last_step_count = 0, last_step = 0; static uint8_t sec = 0; static uint32_t sigma_step = 0; uint32_t step; int32_t delta_step, cadence; #define P 45 #define I 0 #define D 10 if(++sec >= 60) { sec = 0; sigma_step = 0; } step = get_the_step_count() - last_step_count; last_step_count = get_the_step_count(); delta_step = step - last_step; last_step = step; sigma_step += step; cadence = (uint32_t)(P*step + I*sigma_step + D*delta_step); if(cadence < 0) cadence = 0; oled_update_step_count(); p_measurement->is_inst_stride_len_present = true; p_measurement->is_total_distance_present = true; p_measurement->is_running = false; p_measurement->inst_cadence = cadence; p_measurement->inst_speed = (uint16_t)(cadence * 3.2); //uint:m/s (3.2 = 0.75/60*256) p_measurement->inst_stride_length = 75; p_measurement->total_distance = get_total_distance(); if (p_measurement->inst_speed > (uint32_t)(MIN_RUNNING_SPEED * 256)) { p_measurement->is_running = true; } //first connect to send the steps to mobile app // if(rsc_first_conn_flag) // { // p_measurement->inst_stride_length = get_the_step_count(); // rsc_first_conn_flag = false; // } }
void Set_routes::print() { /* Code to be executed only if the flag _DEBUG is set*/ #ifdef _DEBUG /* Check the integrity of the route (distance and travel time)*/ assert_routes_structure(); #endif printf(" - Total distance traversed: %.2lf\n", get_total_distance()); printf(" - Total time: %.2lf\n", get_total_time()); printf(" - Set of routes traversed by the buses: \n"); for (int i = 0; i < get_num_routes(); i++) { route[i]->print(); } }