initialCommit 4 ans en retard
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
#include "Planification.h"
|
||||
#include "CreneauHoraire.h"
|
||||
#include "Decision.hpp"
|
||||
#include "STFMockInstance.hpp"
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
namespace modellib {
|
||||
long Planification::sommeRetardsPonderes(bool withExclusion) {
|
||||
long somme = 0.;
|
||||
bool sol = false;
|
||||
for (OperationPlanifie &op: m_operationsOrdonnance) {
|
||||
if (op.getCreneau().first <= STFMockInstance::jobs[op.getOperationRequise()]->getDateDue().getRelativeDate()) {
|
||||
somme += 0;
|
||||
} else {
|
||||
somme += (op.getCreneau().first - STFMockInstance::jobs[op.getOperationRequise()]->getDateDue().getRelativeDate()) *
|
||||
STFMockInstance::jobs[op.getOperationRequise()]->getPoidsRetard();
|
||||
}
|
||||
sol = true;
|
||||
}
|
||||
if (withExclusion) {
|
||||
for (auto &exc: m_opImplanifiables) {
|
||||
somme += STFMockInstance::jobs[exc]->getPoidsRetard() * MAXIMUM_TIME_OFFSET;
|
||||
}
|
||||
}
|
||||
if (sol) {
|
||||
return somme;
|
||||
} else { return -1; }
|
||||
}
|
||||
|
||||
long Planification::sommeRejetsPonderes() {
|
||||
long somme = 0;
|
||||
bool sol = false;
|
||||
for (OperationPlanifie &op: m_operationsOrdonnance) {
|
||||
somme += op.getRejete() * STFMockInstance::jobs[op.getOperationRequise()]->getPoidsRejet();
|
||||
sol = true;
|
||||
}
|
||||
if (sol) { return somme; }
|
||||
else { return -1; }
|
||||
}
|
||||
|
||||
|
||||
long Planification::sommeRejets() {
|
||||
long somme = 0;
|
||||
bool sol = false;
|
||||
for (OperationPlanifie &op: m_operationsOrdonnance) {
|
||||
somme += op.getRejete();
|
||||
sol = true;
|
||||
}
|
||||
if (sol) { return somme; }
|
||||
else { return -1; }
|
||||
}
|
||||
|
||||
long Planification::sommeSwapCosts() {
|
||||
long somme = 0;
|
||||
for(auto& s : m_croisementsEffectues)
|
||||
{
|
||||
somme += s.cost;
|
||||
}
|
||||
return somme;
|
||||
}
|
||||
|
||||
long Planification::sommmeRecompoCosts() {
|
||||
long somme = 0;
|
||||
for(auto& s : m_recompositionsEffectuees)
|
||||
{
|
||||
somme += s.cost;
|
||||
}
|
||||
return somme;
|
||||
}
|
||||
|
||||
unsigned long Planification::countSwap() {
|
||||
return m_croisementsEffectues.size();
|
||||
}
|
||||
|
||||
unsigned long Planification::countRecompo() {
|
||||
return m_recompositionsEffectuees.size();
|
||||
}
|
||||
unsigned long Planification::countDoubleRecompo(){
|
||||
unsigned long nb =0;
|
||||
for(auto& recompo : m_recompositionsEffectuees){
|
||||
if(recompo.is_double_recompo.first){
|
||||
nb++;
|
||||
}
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
unsigned long Planification::countDiag(int h) {
|
||||
long c = 0;
|
||||
for(auto& d : m_operationsOrdonnance)
|
||||
{
|
||||
if(d.getRejete() && (STFMockInstance::jobs[d.getOperationRequise()]->getHierarchie() == (unsigned int)h || h == -1))
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
unsigned long Planification::countExcluded(int h) {
|
||||
long c = 0;
|
||||
for(auto& d : m_opImplanifiables)
|
||||
{
|
||||
if(STFMockInstance::jobs[d]->getHierarchie() == (unsigned int)h || h == -1)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void Planification::cleanSwap(){
|
||||
std::vector<size_t> idx_to_remove;
|
||||
for(auto& recompo : m_recompositionsEffectuees){
|
||||
if(recompo.is_double_recompo.first){
|
||||
auto pos = std::find(m_recompositionsEffectuees.begin(), m_recompositionsEffectuees.end(), *recompo.is_double_recompo.second);
|
||||
if(pos != m_recompositionsEffectuees.end()){
|
||||
recompo.recompo_done.push_back(pos->recompo_done[0]);
|
||||
if(recompo.um_crit_init.find(pos->recompo_done[0].rame_critique)){
|
||||
recompo.um_crit_end.swap(pos->recompo_done[0].rame_critique,pos->recompo_done[0].rame_saine);
|
||||
recompo.um_saine_end.swap( pos->recompo_done[0].rame_saine, pos->recompo_done[0].rame_critique);
|
||||
}else{
|
||||
recompo.um_crit_end.swap(pos->recompo_done[0].rame_saine, pos->recompo_done[0].rame_critique);
|
||||
recompo.um_saine_end.swap( pos->recompo_done[0].rame_critique,pos->recompo_done[0].rame_saine);
|
||||
}
|
||||
recompo.UM_crit_TM_arrival = pos->UM_crit_TM_arrival;
|
||||
recompo.UM_saine_TM_arrival = pos->UM_saine_TM_arrival;
|
||||
idx_to_remove.push_back(std::distance(m_recompositionsEffectuees.begin(), pos));
|
||||
}else{
|
||||
loggerlib::Logger::systemNotify(loggerlib::LOGGER_ERRORS, "[cleanSwap] - Recomposition double trouvé mais pas trouvé sa première recomposition");
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(idx_to_remove.rbegin(), idx_to_remove.rend());
|
||||
for(size_t idx : idx_to_remove){
|
||||
m_recompositionsEffectuees.erase(m_recompositionsEffectuees.begin()+idx);
|
||||
}
|
||||
idx_to_remove.clear();
|
||||
for(auto recompoptr : state->recompos){
|
||||
RecompoUM& recompo = *recompoptr;
|
||||
if(recompo.is_double_recompo.first){
|
||||
auto pos = std::find_if(state->recompos.begin(), state->recompos.end(),[&](std::shared_ptr<RecompoUM> recptr){
|
||||
return *recptr == *recompo.is_double_recompo.second;
|
||||
});
|
||||
if(pos != state->recompos.end()){
|
||||
RecompoUM& other_recompo = **pos;
|
||||
recompo.recompo_done.push_back(other_recompo.recompo_done[0]);
|
||||
if(recompo.um_crit_init.find(other_recompo.recompo_done[0].rame_critique)){
|
||||
recompo.um_crit_end.swap(other_recompo.recompo_done[0].rame_critique,other_recompo.recompo_done[0].rame_saine);
|
||||
recompo.um_saine_end.swap( other_recompo.recompo_done[0].rame_saine, other_recompo.recompo_done[0].rame_critique);
|
||||
}else{
|
||||
recompo.um_crit_end.swap(other_recompo.recompo_done[0].rame_saine, other_recompo.recompo_done[0].rame_critique);
|
||||
recompo.um_saine_end.swap( other_recompo.recompo_done[0].rame_critique,other_recompo.recompo_done[0].rame_saine);
|
||||
}
|
||||
recompo.UM_crit_TM_arrival = other_recompo.UM_crit_TM_arrival;
|
||||
recompo.UM_saine_TM_arrival = other_recompo.UM_saine_TM_arrival;
|
||||
idx_to_remove.push_back(std::distance(state->recompos.begin(), pos));
|
||||
}else{
|
||||
loggerlib::Logger::systemNotify(loggerlib::LOGGER_ERRORS, "[cleanSwap] - Recomposition double trouvé mais pas trouvé sa première recomposition");
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(idx_to_remove.rbegin(), idx_to_remove.rend());
|
||||
for(size_t idx : idx_to_remove){
|
||||
//delete state->recompos[idx];
|
||||
state->recompos.erase(state->recompos.begin()+idx);
|
||||
}
|
||||
}
|
||||
|
||||
void Planification::clean()
|
||||
{
|
||||
/*if(state)
|
||||
delete state;*/
|
||||
}
|
||||
|
||||
nlohmann::json Planification::to_json() {
|
||||
nlohmann::json planif = nlohmann::json::object();
|
||||
planif["sommeRetardPondere"] = sommeRetardsPonderes();
|
||||
planif["sommeRetardPondereWithExclusions"] = sommeRetardsPonderes(true);
|
||||
planif["sommeRejetPondere"] = sommeRejetsPonderes();
|
||||
planif["operationsPlanifiees"] = nlohmann::json::array();
|
||||
planif["opImplanifiables"] = nlohmann::json::array();
|
||||
planif["rdvNonOrientes"] = nlohmann::json::array();
|
||||
|
||||
planif["statistiques"] = infos.to_json();
|
||||
|
||||
for (auto& croi : m_croisementsEffectues) {
|
||||
planif["croisementsEffectues"].push_back(croi.to_json());
|
||||
}
|
||||
for (auto& rec : m_recompositionsEffectuees) {
|
||||
planif["recompositionsEffectues"].push_back(rec.to_json());
|
||||
}
|
||||
for (auto& opo : m_operationsOrdonnance) {
|
||||
planif["operationsPlanifiees"].push_back(opo.to_json(state));
|
||||
}
|
||||
|
||||
for (auto& opi : m_opImplanifiables) {
|
||||
planif["opImplanifiables"].push_back(STFMockInstance::jobs[opi]->to_json(false));
|
||||
}
|
||||
|
||||
for(auto& rdv : getPlanificationState()->preventiveMaintenanceRdvms)
|
||||
{
|
||||
if(!rdv->isOriented())
|
||||
planif["rdvNonOrientes"].push_back(rdv->to_json());
|
||||
}
|
||||
|
||||
return planif;
|
||||
}
|
||||
|
||||
std::unordered_map<unsigned short, Decision> Planification::getMapOfDecisions()
|
||||
{
|
||||
std::unordered_map<unsigned short, Decision> map;
|
||||
|
||||
for(auto& opPlan : this->getOperationsPlan())
|
||||
{
|
||||
map[opPlan.getOperationRequise()] = {
|
||||
opPlan.getRentree(),
|
||||
state->trajectoryStops[opPlan.getRentree()].getDispoStop(),
|
||||
opPlan.getTrackInterval(),
|
||||
opPlan.getRejete(),
|
||||
false,
|
||||
opPlan.getVoie(),
|
||||
opPlan.getSite(),
|
||||
opPlan.getCreneau()
|
||||
};
|
||||
}
|
||||
|
||||
for(auto& opPlan : this->getOpImplanifiables())
|
||||
{
|
||||
map[opPlan] = {
|
||||
0,
|
||||
CreneauHoraire(),
|
||||
0,
|
||||
false,
|
||||
true,
|
||||
0,
|
||||
0,
|
||||
{0,0}
|
||||
};
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user