int main()
{
    // Start the other thread
    Thread parallelTask(&parallel);
    
    float f= 0.0f;    
    while(1)
    {
        // unformatted text
        pc.puts("Hi! this uses puts.\r\n");
        
        // formatted text
        pc.printf("And this is formatted. Here is the sin(%f)=%f.\r\n", f, sinf(f));
        f+= 0.25f;
    }
}
Example #2
0
void File::simulatedAnnealing(vector<Process> processes_list) {
    srand(time(NULL));
    parallelTask(processes_list);
    if (time_is_over == true) {
        cout << "Time is over before first Parallel Task ordering\n";
        cout << "No file saved\n";
        return;
    }
    if (processes_list.size() <= 2) {
        return;
    }
    averageCalculating(processes_list);
    //this->saveToFile(alternative_solution, "PRL");

    cout << "this->averageReadyTime = " << this->averageReadyTime << endl;
    cout << "this->averageProcsAmount = " << this->averageProcsAmount << endl;
    vector<Process> actual_solution = alternative_solution;
    lastTaskTime = alternative_last_task_time;
    vector<Process> old_good_solution = actual_solution;
    old_last_task_time = lastTaskTime;
    int temperature = TEMPERATURE;
    int min_temperature = MIN_TEMPERATURE;
    unsigned int counter_worse_solution = 0;
    unsigned int counter_better_solution = 0;
    unsigned int max_counter_better_solution = MAX_COUNTER_BETTER_SOLUTION;
    unsigned int max_counter_worse_solution = MAX_COUNTER_WORSE_SOLUTION;
    int minutes_amount = MINUTES_AMOUNT;
    int i = 0;
    while (temperature > min_temperature) {
        //cout << "temperature " << temperature << endl;
        if ((clock() - start2) / CLOCKS_PER_SEC > minutes_amount * 60) {
            cout << "Time is over\n";
            actual_solution = old_good_solution;
            lastTaskTime = old_last_task_time;
            this->saveToFile(actual_solution,"SA");
            return;
        }
        if (counter_worse_solution >= max_counter_worse_solution) {
            cout << "Counter_worse_solution is max\n";
            counter_worse_solution = 0;
            actual_solution = old_good_solution;
            lastTaskTime = old_last_task_time;
        }
        // FIND ALTERNATIVE SOLUTION
        this->findAlternativeSolution(actual_solution);
        if (time_is_over) {
            cout << "Time is over\n";
            actual_solution = old_good_solution;
            lastTaskTime = old_last_task_time;
            this->saveToFile(actual_solution,"SA");
            return;
        }
        //this->saveToFile(alternative_solution, "ALTER");
        if (alternative_last_task_time < lastTaskTime) {
            //cout << "Processing better scheduling\n";
            actual_solution.clear();
            if (old_last_task_time > alternative_last_task_time) {
                cout << "*********************Found new better scheduling************************** \n";
                old_good_solution.clear();
                old_good_solution = alternative_solution;
                old_last_task_time = alternative_last_task_time;
            }
            actual_solution = alternative_solution;
            lastTaskTime = alternative_last_task_time;
            counter_better_solution++;
            counter_worse_solution = 0;
            if (counter_better_solution == max_counter_better_solution) {
                temperature = (int)temperature_reducing(temperature);
            }
        }
        else if ((rand() % 100 + 0) < (probability(actual_solution.back().f_t, temperature))*100) {

           //cout << "get worse solution\n";
            actual_solution.clear();
            actual_solution = alternative_solution;
            lastTaskTime = alternative_last_task_time;
            counter_worse_solution++;
            counter_better_solution = 0;
            temperature = (int)temperature_reducing(temperature);
        }
        else {
            //cout <<"I've done nothing\n";
            temperature = (int)temperature_reducing(temperature);
        }
    }
    cout << "Actual temperature is lower than boundary\n" << temperature << endl;
    actual_solution = old_good_solution;
    lastTaskTime = old_last_task_time;
    this->saveToFile(actual_solution,"SA");
}
Example #3
0
void AsyncAlgo::run() {
    parallelTask();
    Gecode::Support::Event dummy;
    dummy.wait();
}