#include "coptimizer.h" #include "../instance/cinstance.h" #include "../instance/cinstancereduite.h" #include "cgraphe.h" #include "../tuning.h" #include "../instance/indices.h" #include "../filtreAval/filtreAval.h" #include #include #include #include #include #include #include #include "DA.h" using std::vector; using namespace std; COptimizer::COptimizer(time_t time_limit) { deadline = time_limit ; } COptimizer::~COptimizer() { } struct PredAffichePlanDeProduction { vector * m_plans ; PredAffichePlanDeProduction( vector * plans ) { m_plans = plans; } void operator()(CGraphe * g) { std::cout << *(g->m_plan) << std::endl; /* copy( g->m_plan->m_colonne.begin(), g->m_plan->m_colonne.end(), ostream_iterator( cout, " " ) ); std::cout << std::endl ;*/ } } ; struct PredAjoutColonne { int m_passe ; vector * m_plans ; DualAscent * m_da ; PredAjoutColonne( int passe, vector * plans, DualAscent * da ) { m_passe = passe ; m_plans = plans; m_da=da; } void operator()(CGraphe * g) { #ifdef OPTION_REJETE_COUTS_REDUITS_POSITIFS if (m_passe==1 or g->m_plan->m_cout_reduit - CGraphe::m_u[H()+g->m_i]<=0) { #endif m_plans->push_back(g->m_plan); m_da->ajoutcolonne(g->m_plan); g->accepte_colonne(); #ifdef OPTION_REJETE_COUTS_REDUITS_POSITIFS } #endif } } ; void COptimizer::start() { vector graphes; vector plans_de_production ; DualAscent da( CInstanceReduite::getEDEM_min(), I() ); // vecteur des coûts réduits par semaine puis des centrales vector u( H()+I(), 0 ); vector lambda(u); /* Création des graphes */ #ifdef VERBOSE_TEMPS debut_optimization = time(NULL); // N'est-ce pas genant de prendre ce temps *après* avoir lu les données ? #endif /* pour chaque centrale, créer un graphe */ for (powerplants2_t i=(powerplants2_t) 0; i 0) { // calcul fait dans DA.cpp char id[20]; sprintf(id, "passe n°%d", passes); #ifdef VERBOSE_PASSES #ifdef VERBOSE_TEMPS std::cout << " duree : " << time(NULL) - maintenant << std::endl; maintenant = time(NULL); #endif std::cout << " appel au dual ascent" << std::endl ; #endif da.boucle(u, lambda, rechercheBorneSup, id); } /* passage des variables duales aux graphes */ #ifdef VERBOSE_PASSES #ifdef VERBOSE_TEMPS std::cout << " duree : " << time(NULL) - maintenant << std::endl; maintenant = time(NULL); #endif std::cout << " préparation viterbi" << std::endl ; #endif CGraphe::prepare_viterbi(&u) ; /* générer les nouvelles colonnes pour chaque centrale */ #ifdef VERBOSE_PASSES #ifdef VERBOSE_TEMPS std::cout << " duree : " << time(NULL) - maintenant << std::endl; maintenant = time(NULL); #endif std::cout << " génération des colonnes" << std::endl ; #endif std::for_each( graphes.begin(), graphes.end(), CGraphe::creer_colonnes ); #ifdef VERBOSE_PLANS #ifdef VERBOSE_TEMPS std::cout << " duree : " << time(NULL) - maintenant << std::endl; maintenant = time(NULL); #endif PredAffichePlanDeProduction affichePlan(&plans_de_production); std::for_each( graphes.begin(), graphes.end(), affichePlan ); #endif #ifdef VERBOSE_PASSES #ifdef VERBOSE_TEMPS std::cout << " duree : " << time(NULL) - maintenant << std::endl; maintenant = time(NULL); #endif std::cout << " ajout des nouvelles colonnes" << std::endl ; #endif /* ajout des colonnes à la liste des colonnes */ PredAjoutColonne ajoute(passes, &plans_de_production, &da); std::for_each( graphes.begin(), graphes.end(), ajoute ); } Cplex cplex(da); #ifndef NO_CPLEX vector x = cplex.resolution(); #else vector x(I()); for (size_t i=0; i<(unsigned)I(); i++) x[i] = Clique::s_plans.size()-I()+i ; #endif FiltreAval filtreAval(x); ofstream ofs(CInstance::params().getSolutionName().c_str()); filtreAval.printOutput(ofs, debut_optimization); ofs.close(); // destruction des graphes for_each(graphes.begin(), graphes.end(), CGraphe::detruit); }