TVFloat CPV::getRangeNrFrc ( int begin , int end ){ TVFloat result; for ( int i = begin ; i < end ; i++ ){ result.push_back( m_vPwFrc->at ( ( i ) % m_vPwFrc->size() ) ); } return result; };
TVFloat CPV::getNextDayNrFrc ( int time_ref ){ TVFloat result; for ( int i = 0 ; i < 1440 ; i++ ){ result.push_back( m_vPwFrc->at( ( i + time_ref ) % m_vPwFrc->size() ) ); } return result; };
TVFloat CADSMCtr::getStatus ( void ){ TVFloat result; sNPower* power = m_pcNode-> getNPower(); result.push_back( power->load ); result.push_back( power->pv ); result.push_back( power->bat ); result.push_back( power->grid ); /* PV SELF-CONSUMPTION */ float self_consumption; self_consumption = min ( power->pv , power->load ); result.push_back( self_consumption ); // if ( m_pcNode->getPV() ){ // result.push_back( m_pcNode->getPV()->getPower() ); // } // result.push_back( m_pcNode->getLoad()->getPower() ); // result.push_back( m_pcNode->getLoad()->getDefPower() ); // result.push_back( m_pcNode->getLoad()->getNDefPower() ); // if ( m_pcNode->getStorage() ){ // result.push_back( m_pcNode->getStorage()->getPower() ); // } return result; };
TVFloat CPV::getNextDayFrc ( int time_ref ){ TVFloat result; result = getNextDayNrFrc( time_ref ); for ( int i = 0 ; i < result.size() ; i++ ){ result[i] *= m_fPAmp; } return result; };
TVFloat CSimulator::getEvaluation ( void ){ TVFloat results; TVFloat* tmp_sgn = m_pcEnvironment->getGSignal(); int ini_ptr = tmp_sgn->size() - 43200; // Evaluate 30 days float tmp_daily_max, tmp_daily_min; TVFloat daily_max, daily_min; float month_max = tmp_sgn->at( ini_ptr ); float month_min = tmp_sgn->at( ini_ptr ); for ( int i = 0 ; i < 43200 ; i++ ){ // Monthly if ( month_max < tmp_sgn->at( ini_ptr + i ) ) month_max = tmp_sgn->at( ini_ptr + i ); if ( month_min > tmp_sgn->at( ini_ptr + i ) ) month_min = tmp_sgn->at( ini_ptr + i ); // Daily if ( i % 1440 == 0 ){ if ( i != 0 ){ daily_max.push_back( tmp_daily_max ); daily_min.push_back( tmp_daily_min ); } tmp_daily_max = tmp_daily_min = tmp_sgn->at( ini_ptr + i ); } if ( tmp_daily_max < tmp_sgn->at( ini_ptr + i ) ) tmp_daily_max = tmp_sgn->at( ini_ptr + i ); if ( tmp_daily_min > tmp_sgn->at( ini_ptr + i ) ) tmp_daily_min = tmp_sgn->at( ini_ptr + i ); } float month_rel = month_max / month_min; TVFloat daily_rel; for ( int i = 0 ; i < daily_max.size() ; i++ ){ daily_rel.push_back( daily_max[i] / daily_min[i] ); } float daily_rel_ave = 0.0; for ( int i = 0 ; i < daily_rel.size() ; i++ ){ daily_rel_ave += daily_rel[i]; } daily_rel_ave /= daily_rel.size(); // Get results results.push_back( month_rel ); results.push_back( daily_rel_ave ); return results; };
int COscillator::_roulette ( TVFloat* prob ){ TVFloat roulette; roulette.push_back( (*prob)[0] ); for ( int i = 1 ; i < prob->size() ; i++ ){ roulette.push_back( (*prob)[i] + roulette.back() ); } float rand = m_pcRandom->nextDouble( roulette.back() ); bool Exit = false; int cnt = 0; while (!Exit){ if ( roulette[cnt] > rand ){ Exit = true; } else{ cnt++; } } return cnt; };
void IRACE_slave ( void ){ /* Create Simulator and take over it */ CSimulator *pcSimulator = new CSimulator ( g_sMainFilename ); CMainControl *pcMainControl = pcSimulator->getMainControl(); /* Set environment */ pcSimulator->setFFTsize ( pow ( 2 , g_ne1 ) ); pcSimulator->setSampling ( g_ne2 * 45 ); /* Set Controllers */ TVFloat param; param.push_back( - g_fk ); param.push_back( g_fp ); param.push_back( g_nr ); param.push_back( g_fb ); pcMainControl->setParameters ( param ); /* Restart Simulator */ pcSimulator->restart ( ); /* Execute the experiment */ pcSimulator->ExecuteSimulation ( ); /* Get the results */ float ave_res = pcMainControl->getAssessment(); /* Write the output */ ofstream output (g_sOutputFile.c_str()); output << ave_res << endl; output.close(); /* cout << " FITNESS: " << ave_res << endl; TVFloat* result = pcMainControl->getEvaluation(); cout << " RESULT: "; if ( result ){ for ( int i = 0 ; i < result->size() ; i++ ){ cout << result->at(i) << " "; } } cout << endl; */ /* Kill simulator */ delete pcSimulator; return; };
void CSimulator::_configureGrid ( XMLElement* elem ){ string attr; // Get Grid maximum amplitude if ( elem->Attribute("amp") ){ attr = elem->Attribute("amp"); m_sSimCnf.GridProfile.amp = atof( attr.c_str() ); } else{ m_sSimCnf.GridProfile.amp = 0.0; } // Configure grid sinusiodal components int nCmp; if ( elem->Attribute("cmp") ){ attr = elem->Attribute("cmp"); nCmp = atoi( attr.c_str() ); } else{ nCmp = 0; } if ( nCmp > 0 ){ m_pcGrid->setSCmp ( elem ); } // Get Profile if ( elem->Attribute("file") ){ string file_name; attr = elem->Attribute("file"); file_name.assign ( m_sSimCnf.sDataFolder ); file_name.append ( attr ); ifstream inputFile ( file_name.c_str() ); if ( inputFile.is_open() ){ TVFloat profile; float tmp_float, tmp_float_old, slope; inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile >> tmp_float_old; inputFile.ignore ( 256, '\n' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); while( !inputFile.eof() ){ inputFile >> tmp_float; slope = (tmp_float - tmp_float_old)/60.0; for ( int j = 0 ; j < 60 ; j++ ){ profile.push_back( tmp_float_old + slope * j ); } tmp_float_old = tmp_float; inputFile.ignore ( 256, '\n' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); inputFile.ignore ( 256, ' ' ); } inputFile.close(); m_sSimCnf.GridProfile.dur = profile.size(); m_sSimCnf.GridProfile.profile = profile; // Normalized profile TVFloat nr_profile; float max = 0.0; for ( int i = 0 ; i < profile.size() ; i++ ){ if ( profile[i] > max ){ max = profile[i]; } } for ( int i = 0 ; i < profile.size() ; i++ ){ nr_profile.push_back( profile[i] / max ); } m_sSimCnf.GridProfile.nr_profile = nr_profile; }
void MPI_slaveLoop ( void ){ cout << "Created process " << g_nMyid << " as SLAVE " << endl; /* Parallel stuff */ int flags_tx [1]; int flags_rx [1]; int nParams [g_nParamN]; int nEnviro [g_nEnvirN]; float fResults [g_nResltN]; int nSeed [1]; bool Exit; MPI_Status stat; std::vector<float> tmp_vec; flags_tx[0] = 0; /* Create Simulator*/ CSimulator *pcSimulator = new CSimulator ( g_sExpConf ); CMainControl *pcMainControl = pcSimulator->getMainControl(); /* SLAVE Main Loop - getting work and executing*/ Exit = false; while(!Exit){ /* Ask for job */ MPI_Send ( flags_tx , 1 , MPI_INT , 0 , 0 , MPI_COMM_WORLD ); MPI_Recv ( flags_rx , 1 , MPI_INT , 0 , 1 , MPI_COMM_WORLD, &stat ); /* Flag to continue working or finish the process */ if ( flags_rx[0] == 1 ){ /* Receives work */ MPI_Recv ( nParams , g_nParamN , MPI_INT , 0 , 3 , MPI_COMM_WORLD, &stat ); MPI_Recv ( nEnviro , g_nEnvirN , MPI_INT , 0 , 8 , MPI_COMM_WORLD, &stat ); MPI_Recv ( nSeed , 1 , MPI_INT , 0 , 6 , MPI_COMM_WORLD, &stat ); /* Restart Simulator */ pcSimulator->setSeed ( nSeed[0] ); pcSimulator->restart ( ); /* Set environment */ TVFloat enviro; for ( int i = 0 ; i < g_nEnvirN ; i++ ){ enviro.push_back( g_vEnvirs[i].step * float(nEnviro[i]) + g_vEnvirs[i].offset ); } //enviro.push_back( g_vEnvirs[0].step * float(nEnviro[0]) + g_vEnvirs[0].offset ); //enviro.push_back( g_vEnvirs[1].step * float(nEnviro[1]) + g_vEnvirs[1].offset ); pcMainControl->setEnvironment ( enviro ); /* Set Controllers */ TVFloat param; for ( int i = 0 ; i < g_nParamN ; i++ ){ param.push_back( g_vParams[i].step * float(nParams[i]) + g_vParams[i].offset ); } //param.push_back( g_vParams[0].step * float(nParams[0]) + g_vParams[0].offset ); //param.push_back( g_vParams[1].step * float(nParams[1]) + g_vParams[1].offset ); pcMainControl->setParameters ( param ); /* Execute the experiment */ pcSimulator->ExecuteSimulation ( ); /* Get the results */ TVFloat* tmp_res = pcMainControl->getEvaluation(); for ( int i = 0 ; i < g_nResltN ; i++ ) fResults[i] = tmp_res->at(i); /* Send the results to the MPI Master*/ MPI_Send ( nParams , g_nParamN , MPI_INT , 0 , 2 , MPI_COMM_WORLD ); MPI_Send ( nEnviro , g_nEnvirN , MPI_INT , 0 , 7 , MPI_COMM_WORLD ); MPI_Send ( nSeed , 1 , MPI_INT , 0 , 5 , MPI_COMM_WORLD ); MPI_Send ( fResults , g_nResltN , MPI_FLOAT , 0 , 4 , MPI_COMM_WORLD ); flags_tx[0] = 1; } else Exit = true; } /* Delete Simulator */ delete pcSimulator; return; };