diff --git a/src/main.cpp b/src/main.cpp index 935221155545d4e91d429f8158e74e20ce1ebb1f..53a8cc4f77812226812ab78fc1f124b164a2cd71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,14 +23,14 @@ #include "algo/fcfs.hpp" #include "algo/rejecter.hpp" #include "algo/sequencer.hpp" -#include "algo/psc.hpp" // Inclusion de l'algorithme Psc +#include "algo/carbone.hpp" + using namespace std; using namespace boost; namespace n = network; namespace r = rapidjson; -//Modification : Karim/Adem void run(Network & n, ISchedulingAlgorithm * algo, SchedulingDecision &d, Workload &workload, bool call_make_decisions_on_single_nop = true); @@ -56,13 +56,12 @@ void run(Network & n, ISchedulingAlgorithm * algo, SchedulingDecision &d, int main(int argc, char ** argv) { - const set<string> variants_set = {"easy_bf", "fcfs", "rejecter", "sequencer", "psc" }; // Ajout de Psc + const set<string> variants_set = {"easy_bf", "fcfs", "rejecter", "sequencer", "carbone"}; const set<string> policies_set = {"basic", "contiguous"}; const set<string> queue_orders_set = {"fcfs", "lcfs", "desc_bounded_slowdown", "desc_slowdown", "asc_size", "desc_size", "asc_walltime", "desc_walltime"}; const set<string> verbosity_levels_set = {"debug", "info", "quiet", "silent"}; - const string variants_string = "{" + boost::algorithm::join(variants_set, ", ") + "}"; const string policies_string = "{" + boost::algorithm::join(policies_set, ", ") + "}"; const string queue_orders_string = "{" + boost::algorithm::join(queue_orders_set, ", ") + "}"; @@ -243,9 +242,8 @@ int main(int argc, char ** argv) algo = new Rejecter(&w, &decision, queue, selector, rjms_delay, &json_doc_variant_options); else if (scheduling_variant == "sequencer") algo = new Sequencer(&w, &decision, queue, selector, rjms_delay, &json_doc_variant_options); - else if (scheduling_variant == "psc") // Ajout de psc - algo = new Psc(&w, &decision, queue, selector, rjms_delay, &json_doc_variant_options); - + else if (scheduling_variant == "carbone") + algo = new CarboneAlgorithm(&w, &decision, queue, selector, rjms_delay, &json_doc_variant_options); // Network Network n; n.bind(socket_endpoint); @@ -316,6 +314,7 @@ void run(Network & n, ISchedulingAlgorithm * algo, SchedulingDecision & d, current_date = event_object["timestamp"].GetDouble(); const r::Value & event_data = event_object["data"]; + if (event_type == "SIMULATION_BEGINS") { int nb_resources; @@ -444,6 +443,28 @@ void run(Network & n, ISchedulingAlgorithm * algo, SchedulingDecision & d, } } + else if (event_type == "carbon_co2") { + int val_dcA = 0, val_dcB = 0, val_dcC = 0; // Initialisation + + if (event_data.HasMember("some_field_dcA")) { + val_dcA = event_data["some_field_dcA"].GetInt(); + } + if (event_data.HasMember("another_field_dcB")) { + val_dcB = event_data["another_field_dcB"].GetInt(); + } + if (event_data.HasMember("additional_field_dcC")) { + val_dcC = event_data["additional_field_dcC"].GetInt(); + } + + CarboneAlgorithm* carboneAlgo = dynamic_cast<CarboneAlgorithm*>(algo); + if (carboneAlgo != nullptr) { + carboneAlgo->updateCarbonFootprint(val_dcA, val_dcB, val_dcC); + } + else { + std::cerr << "Erreur : l'algorithme en cours n'est pas une instance de CarboneAlgorithm." << std::endl; + } + } + else { throw runtime_error("Unknown event received. Type = " + event_type);