int sched_prepare(void){ if ( hwpl_debug_init() ){ _hwpl_core_priv_disable_interrupts(NULL); gled_priv_error(0); } #if CAOSLIB_USECOND_TMR_SLEEP_OC > -1 if ( sched_timing_init() ){ return -1; } #endif //Load any possible faults from the last reset hwpl_fault_load((fault_t*)&sched_fault.fault); #if USE_MEMORY_PROTECTION > 0 if ( task_init_mpu(&_data, caoslib_system_memory_size) < 0 ){ sched_debug("Failed to initialize memory protection\n"); gled_priv_error(0); } #endif _hwpl_core_unprivileged_mode(); //Enter unpriv mode return 0; }
void Schedule::add_job(vector<int> times, vector<int> machines) { /* Ajout personnalisé - Vecteurs * i machines doivent être de la même longueur. le i-ème élément correspond * la i-ième composante de la machine. */ if (times.size() != machines.size()) // quelque chose a mal tourné:) { sched_debug("---number of times(%d) doesn't match the number of machines(%d)!\n"); return; } int no_operations = times.size(); // le nombre d'opérations jobs.push_back(Job(times, machines)); // ajouter une travail à la liste des travaux for (int i=0; i<no_operations; i++) // pour chaque travail { operations_number++; // augmente le nombre actuel d'opérations (à noter qu'il symbolise aussi le nombre de sommets qui représente cette opération) this->machines[machines[i]].push_back(operations_number); // l'opération est effectuée sur la i-ième machine vertex_weights.push_back(times[i]); // enregistrer le poids de chaque arête provenant du sommet } }
double Schedule::solve_using_SA(double modulation, double initial_temperature, double alpha_warming, double alpha_cooling, int cooling_age_length, double warming_threshold, int max_moves_without_improvement) { srand(time(NULL)); int mode; //réchauffe // réfrigération int accepted_moves; list<bool> last_moves; vector<int> last_inverted_arc; last_inverted_arc.resize(2); const int last_moves_size = 500; last_moves.resize(last_moves_size); std::fill(last_moves.begin(), last_moves.end(), false); int accepted_moves_out_of_last_n = 0; bool halt = false; double temperature; int cmax; int best_cmax; Graph best_graph; create_graph(); best_cmax = get_cmax(); sched_debug("begin with cmax = %d\n", best_cmax); deque<int> crit_path; mode = WARMING; accepted_moves = 0; temperature = initial_temperature; vector<int> random_arc; random_arc.resize(2); int new_cmax; bool time_exceeded = false; bool cmax_is_optimal = false; int moves_without_improvement = 0; int max_temperature; //mesure du temps //struct timespec start, stop; time_t *start, *stop; double totaltime = 0.0; //clock_gettime(CLOCK_REALTIME, &start); *start = time(start); while (moves_without_improvement < max_moves_without_improvement && !cmax_is_optimal && !time_exceeded) { //sched_debug("calculating critical path from %d to %d\n", 0, operations_number + 1); crit_path = graph.critical_path(0, operations_number + 1); cmax = get_cmax(); int attempts = 0; do { random_arc = select_arc(crit_path); ++attempts; if (attempts > 100000) { halt = true; break; } } while (random_arc[0] == 0 || random_arc[1] == operations_number + 1 || (random_arc[1] - random_arc[0] == 1)); if (halt) break; graph.invert_arc(random_arc[0], random_arc[1]); last_inverted_arc = random_arc; graph.set_arc_length(random_arc[1], random_arc[0], vertex_weights[random_arc[1]]); new_cmax = get_cmax(); sched_debug("%d\t", new_cmax); if(new_cmax < cmax) { if (mode == WARMING) { last_moves.push_back(true); if (last_moves.front() == false) accepted_moves_out_of_last_n++; last_moves.pop_front(); } accepted_moves++; cmax = new_cmax; sched_debug(" +a\t"); if (new_cmax < best_cmax) { moves_without_improvement = 0; best_cmax = new_cmax; best_graph = graph; if (lower_bound && upper_bound && best_cmax <= upper_bound && best_cmax >= lower_bound) cmax_is_optimal = true; } } else if (new_cmax == cmax) { accepted_moves++; sched_debug("==\t"); moves_without_improvement++; if (mode == WARMING) { last_moves.push_back(true); if (last_moves.front() == false) accepted_moves_out_of_last_n++; last_moves.pop_front(); } } else { if(success_chance(cmax, new_cmax, temperature, modulation) == true) { //failed_moves = 0; accepted_moves++; cmax = new_cmax; sched_debug(" -a\t"); moves_without_improvement++; if (mode == WARMING) { last_moves.push_back(true); if (last_moves.front() == false) { accepted_moves_out_of_last_n++; } last_moves.pop_front(); } } else // success_chance == false, aucune possibilité pour le trafic de succès { sched_debug(" -r\t"); moves_without_improvement++; if(mode == WARMING) { if (accepted_moves > cooling_age_length/10) { accepted_moves = 0; temperature += alpha_warming * initial_temperature; } last_moves.push_back(false); if (last_moves.front() == true) accepted_moves_out_of_last_n--; last_moves.pop_front(); } graph.invert_arc(random_arc[1], random_arc[0]); graph.set_arc_length(random_arc[0], random_arc[1], vertex_weights[random_arc[0]]); } } sched_debug("%4.2f\t", temperature); sched_debug(mode == WARMING ? "+" : "-"); sched_debug("\t%d\t%d\t%4.2f\t", accepted_moves, moves_without_improvement, (double)accepted_moves_out_of_last_n / last_moves_size); if (mode == WARMING && (double)accepted_moves_out_of_last_n / last_moves_size >= warming_threshold) { accepted_moves = 0; mode = COOLING; max_temperature = temperature; } else if (mode == COOLING && accepted_moves >= cooling_age_length) { temperature *= alpha_cooling; accepted_moves = 0; } //clock_gettime(CLOCK_REALTIME, &stop); *stop = time(stop); //totaltime += (double) (stop.tv_sec - start.tv_sec)+1.e-9*(stop.tv_nsec - start.tv_nsec); totaltime += (double) (stop - start)+1.e-9*(stop - start); //si on a depassé un certain nombre de secondes if(totaltime > 180.0) time_exceeded = true; //clock_gettime(CLOCK_REALTIME, &start); *start = time(start); sched_debug("\n"); } #ifdef SCHED_DEBUG sched_debug("Stopped due to: "); if (!(moves_without_improvement < max_moves_without_improvement)) sched_debug("moves_without_improvement >= limit\n"); else if(time_exceeded) sched_debug("time exceeded\n"); else if (cmax_is_optimal) sched_debug("cmax_is_optimal\n"); #endif graph = best_graph; printf("%d\n", get_cmax()); print_start_times(); printf("\n"); return totaltime; }