#include #include "cconstraint.h" #include "lecture.h" #include "cinstance.h" #include "cinstancereduite.h" #include using instanceNs::lire_valeur; using instanceNs::lire_intervalle ; using instanceNs::lire_liste ; void CConstraint::lire( int index ) { if (lire_valeur("begin")!="constraint") throw string("section constraint manquante"); if (lire_valeur("type")!=getType()) throw string("mauvais type de contrainte"); if ((m=(constraint_t)lire_valeur("index"))!=index) throw string("mauvais index de contrainte"); lire_contrainte_typee(); if (lire_valeur("end")!="constraint") throw string("end constraint manquant"); } const week_t CConstraint13::inconnu = (week_t) -2 ; const week_t CConstraint13::indefini = (week_t) -1 ; void CConstraint13::lire_contrainte_typee() { i = (powerplants2_t) lire_valeur("powerplant"); k = (campaign_t) lire_valeur("campaign"); m_TO = (week_t) lire_valeur("earliest_stop_time"); m_TA = (week_t) lire_valeur("latest_stop_time"); type2(i).TO(k) = m_TO ; type2(i).TA(k) = m_TA ; type2(i).m_constraints[13].push_back(this); } void CConstraint14::lire_contrainte_typee() { m_C = lire_liste("set"); m_Se = (wlen_t) lire_valeur("spacing"); for ( vector::iterator i=m_C.begin(); i!=m_C.end(); i++) { // enregistrement de cette contrainte dans les centrales concernées constraints(*i, getType()).push_back(this); } } double CConstraint14::concerne( week_t h, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( h >= plan->ha(k) and h < plan->ha(k) + DA(plan->m_i,k) + m_Se ) { return true ; } } return false ; } void CConstraint15::lire_contrainte_typee() { CConstraint14::lire_contrainte_typee(); m_ID = (week_t) lire_valeur("start"); m_IF = (week_t) lire_valeur("end"); } double CConstraint15::concerne( week_t h, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( m_ID - DA(plan->m_i,k) + 1 <= plan->ha(k) and plan->ha(k) <= m_IF ) if (h >= plan->ha(k) and h < plan->ha(k) + DA(plan->m_i,k) + m_Se ) { return true ; } } return false ; } double CConstraint16::concerne( week_t h, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( h >= plan->ha(k) and h < plan->ha(k) + m_Se ) { return true ; } } return false ; } double CConstraint17::concerne( week_t h, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( h >= plan->ha(k) + DA(plan->m_i, k) and h < plan->ha(k) + DA(plan->m_i, k) + m_Se ) { return true ; } } return false ; } double CConstraint18::concerne( week_t h1, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); ++k) { if ( abs(plan->ha(k) + DA(plan->m_i,k) - h1) < m_Se ) { return 1 ; } } return 0 ; } void CConstraint19::lire_contrainte_typee() { m_Q = lire_valeur("quantity"); m_C = lire_liste("set"); size_t inv = 0 ; for ( vector::iterator i=m_C.begin(); i!=m_C.end(); i++, inv++) { // enregistrement de cette contrainte dans les centrales concernées constraints(*i, getType()).push_back(this); m_Cinv[*i] = inv ; } m_L .resize( m_C.back()+1 ); m_TU.resize( m_C.back()+1 ); for (vector::iterator i=m_C.begin(); i!=m_C.end(); i++) { if (lire_valeur("begin")!="period") throw string("section period manquante"); if (lire_valeur("powerplant")!=*i) throw string("mauvais index de powerplant dans la section period"); m_L[*i] = lire_liste("start" , 0, type2(*i).K-1) ; m_TU[*i]= lire_liste("duration", 0, type2(*i).K-1) ; if (lire_valeur("end")!="period") throw string("end period manquant"); } } double CConstraint19::concerne( week_t h, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( h >= plan->ha(k) + m_L[plan->m_i][k] and h < plan->ha(k) + m_L[plan->m_i][k] + m_TU[plan->m_i][k] ) { return 1 ; } } return 0 ; } double CConstraint19::borne( week_t ) { return m_Q ; } void CConstraint20::lire_contrainte_typee() { m_h = (week_t) lire_valeur("week"); // bizarre m_C = lire_liste("set"); m_N = lire_valeur("max"); } double CConstraint20::concerne( week_t h, CPlan * plan) { if (h!=m_h) return 0 ; // bizarre for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( h >= plan->ha(k) and h < plan->ha(k) + DA(plan->m_i, k)) { return 1 ; } } return 0 ; } double CConstraint20::borne( week_t h ) { return m_N ; } void CConstraint21::lire_contrainte_typee() { m_C = lire_liste("set"); lire_intervalle("startend", m_IT.start, m_IT.end); m_IMAX = lire_valeur("max"); } double CConstraint21::concerne( week_t h, CPlan * plan) { for (campaign_t k=(campaign_t)0; (unsigned)km_ha.size(); k=(campaign_t)(k+1)) { if ( h>=m_IT.start and h<=m_IT.end and h >= plan->ha(k) and h < plan->ha(k) + DA(plan->m_i, k) ) { return PMAX(plan->m_i, h) ; } } return 0 ; } double CConstraint21::borne( week_t h ) { return m_IMAX ; }