From 0d37a06d588281bab2a9112cbf60e67222bc77a1 Mon Sep 17 00:00:00 2001 From: William Pettersson Date: Mon, 29 Jun 2020 09:41:17 +0100 Subject: [PATCH] Add quicker data structure for descending --- .../Allocation.cpp | 24 +++++++++++++++---- .../Allocation.h | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.cpp b/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.cpp index 2ac8d91..11931d7 100644 --- a/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.cpp +++ b/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.cpp @@ -199,13 +199,15 @@ void Allocation::printProb(){ } -int Allocation::reductionMineDoctors(int mode) { +int Allocation::reductionMineDoctors(int mode, bool alt_store) { int nbTotRem = 0; for (int i = 0; i < nbDoctors; i++) { set candidates; set positions; int worst_rank = 0; + int cand_size = 0; + vector cand_in(nbDoctors, false); unsigned int count = 0; AgentIterator iter(doctors[i], candidates, positions, doctors, hospitals, mode); for(std::pair p: iter) { @@ -219,7 +221,12 @@ int Allocation::reductionMineDoctors(int mode) { for (auto & group: hospitals[idxHos].preferences) { bool break_yet = false; for(int pref: group) { - candidates.insert(pref); + if ((alt_store && cand_in[pref] == false) || + (!alt_store && candidates.count(pref) == 0)) { + candidates.insert(pref); + cand_in[pref] = true; + cand_size++; + } if (pref == doctors[i].id) { break_yet = true; } @@ -228,7 +235,7 @@ int Allocation::reductionMineDoctors(int mode) { break; } } - if (count >= candidates.size()) { + if (count >= cand_size) { #ifdef DEBUG std::cout << "doctor worst rank of " << doctors[i].id << " is " << worst_rank << std::endl; int remHere = 0; @@ -265,13 +272,14 @@ int Allocation::reductionMineDoctors(int mode) { return nbTotRem; } -int Allocation::reductionMineHospitals(int mode) { +int Allocation::reductionMineHospitals(int mode, bool alt_store) { int nbTotRem = 0; for (int i = 0; i < nbHospitals; i++) { set candidates; set positions; unsigned int candidate_cap = 0; + vector cand_in(nbHospitals, false); int worst_rank = 0; unsigned int count = 0; #ifdef DEBUG @@ -289,8 +297,10 @@ int Allocation::reductionMineHospitals(int mode) { count += 1; for(const auto & group: doctors[idxDoc].preferences) { for (int pref: group) { - if (candidates.count(pref) == 0) { + if ((alt_store && cand_in[pref] == false) || + (!alt_store && candidates.count(pref) == 0)) { candidates.insert(pref); + cand_in[pref] = true; candidate_cap += hospitals[pref-1].cap; } if (pref == hospitals[i].id) { @@ -740,6 +750,10 @@ void Allocation::reduction(int mode){ this_time += num; } total_removed += this_time; + } else if (mode == 13) { + // Use descending with faster algo + this_time = reductionMineDoctors(0, true); + this_time += reductionMineHospitals(0, true); } else { this_time = reductionMineHospitals(mode); this_time += reductionMineDoctors(mode); diff --git a/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.h b/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.h index 364bca6..5376cc6 100644 --- a/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.h +++ b/HRT/4_YESBIN_2STA_NOMERGED_BOTHTIES/Allocation.h @@ -105,8 +105,8 @@ int reductionResApp(); void polish(); void reduction(int mode); - int reductionMineDoctors(int mode); - int reductionMineHospitals(int mode); + int reductionMineDoctors(int mode, bool alt_store=false); + int reductionMineHospitals(int mode, bool alt_store=false); int reductionExactHospital(bool supp); int reductionExactDoctor(bool supp); void printSol();