int DesignOfExperiments_Impl::createNextIteration(Analysis& analysis) { int result(0); // to make sure problem type check has already occurred. this is stated usage in header. OS_ASSERT(analysis.algorithm().get() == getPublicObject<DesignOfExperiments>()); // nothing else is supported yet DesignOfExperimentsOptions options = designOfExperimentsOptions(); OS_ASSERT(options.designType() == DesignOfExperimentsType::FullFactorial); if (isComplete()) { LOG(Info,"Algorithm is already marked as complete. Returning without creating new points."); return result; } if (options.maxIter() && options.maxIter().get() < 1) { LOG(Info,"Maximum iterations set to less than one. No DataPoints will be added to Analysis '" << analysis.name() << "', and the Algorithm will be marked complete."); markComplete(); return result; } OptionalInt mxSim = options.maxSims(); DataPointVector dataPoints = analysis.getDataPoints("DOE"); int totPoints = dataPoints.size(); if (mxSim && (totPoints >= *mxSim)) { LOG(Info,"Analysis '" << analysis.name() << "' already contains " << totPoints << " DataPoints added by the DesignOfExperiments algorithm, which meets or exceeds the " << "maximum number specified in this algorithm's options object, " << *mxSim << ". " << "No data points will be added and the Algorithm will be marked complete."); markComplete(); return result; } m_iter = 1; // determine all combinations std::vector< std::vector<QVariant> > variableValues; for (const Variable& variable : analysis.problem().variables()) { // variable must be DiscreteVariable, otherwise !isCompatibleProblemType(analysis.problem()) DiscreteVariable discreteVariable = variable.cast<DiscreteVariable>(); IntVector dvValues = discreteVariable.validValues(true); std::vector< std::vector<QVariant> > currentValues = variableValues; for (IntVector::const_iterator it = dvValues.begin(), itEnd = dvValues.end(); it != itEnd; ++it) { std::vector< std::vector<QVariant> > nextSet = currentValues; if (currentValues.empty()) { variableValues.push_back(std::vector<QVariant>(1u,QVariant(*it))); } else { for (std::vector<QVariant>& point : nextSet) { point.push_back(QVariant(*it)); } if (it == dvValues.begin()) { variableValues = nextSet; } else { variableValues.insert(variableValues.end(),nextSet.begin(),nextSet.end()); } } } } // create data points and add to analysis for (const std::vector<QVariant>& value : variableValues) { DataPoint dataPoint = analysis.problem().createDataPoint(value).get(); dataPoint.addTag("DOE"); bool added = analysis.addDataPoint(dataPoint); if (added) { ++result; ++totPoints; if (mxSim && (totPoints == mxSim.get())) { break; } } } if (result == 0) { LOG(Trace,"No new points were added, so marking this DesignOfExperiments complete."); markComplete(); } return result; }
// Test not yet to scale re: total data points. TEST_F(ProjectFixture,Profile_UpdateAnalysis) { Analysis analysis = getAnalysisToRun(100,500); // save to database ProjectDatabase db = getCleanDatabase(toPath("./UpdateAnalysis")); ASSERT_TRUE(db.startTransaction()); AnalysisRecord record(analysis,db); db.save(); ASSERT_TRUE(db.commitTransaction()); // add output data to 1 data point DataPointVector dataPoints = analysis.dataPoints(); boost::mt19937 mt; typedef boost::uniform_real<> uniform_dist_type; typedef boost::variate_generator<boost::mt19937&, uniform_dist_type> uniform_gen_type; uniform_gen_type responseGenerator(mt,uniform_dist_type(50.0,500.0)); for (int i = 0; i < 1; ++i) { std::stringstream ss; ss << "dataPoint" << i + 1; DoubleVector responseValues; for (int j = 0, n = analysis.problem().responses().size(); j < n; ++j) { responseValues.push_back(responseGenerator()); } openstudio::path runDir = toPath(ss.str()); dataPoints[i] = DataPoint(dataPoints[i].uuid(), createUUID(), dataPoints[i].name(), dataPoints[i].displayName(), dataPoints[i].description(), analysis.problem(), true, false, true, DataPointRunType::Local, dataPoints[i].variableValues(), responseValues, runDir, FileReference(runDir / toPath("ModelToIdf/in.osm")), FileReference(runDir / toPath("ModelToIdf/out.idf")), FileReference(runDir / toPath("EnergyPlus/eplusout.sql")), FileReferenceVector(1u,FileReference(runDir / toPath("Ruby/report.xml"))), boost::optional<runmanager::Job>(), std::vector<openstudio::path>(), TagVector(), AttributeVector()); dataPoints[i].setName(dataPoints[i].name()); // set dirty } analysis = Analysis(analysis.uuid(), analysis.versionUUID(), analysis.name(), analysis.displayName(), analysis.description(), analysis.problem(), analysis.algorithm(), analysis.seed(), analysis.weatherFile(), dataPoints, false, false); analysis.setName(analysis.name()); // set dirty // time the process of updating the database ptime start = microsec_clock::local_time(); db.unloadUnusedCleanRecords(); ASSERT_TRUE(db.startTransaction()); record = AnalysisRecord(analysis,db); db.save(); ASSERT_TRUE(db.commitTransaction()); time_duration updateTime = microsec_clock::local_time() - start; std::cout << "Time: " << to_simple_string(updateTime) << std::endl; }
//! Recarrega a lista de analises disponiveis e os arquivos associados a cada uma delas void TerraMEPlayerDialog::reloadInterface() { // Limpar interface e objetos que guardam em memoria os resultados das analises TerraME _terraMEAnalysisListWidget->clear(); _datetimeListWidget->clear(); _terraMEImageAnalysisWidget->setImageAnalysis(""); _terraMEResult.clear(); _currentAnalysis.clear(); _currentAnalysisResult.clear(); _currentAnalysisImageIndex = 0; _imageCountLabel->setText(""); _changeResultTimer.stop(); // Obter lista de analises TerraME que estao na base de dados e atualizar a interface AnalysisList* analysisList = _manager->analysisList(); for(int i = 0; analysisList && i < analysisList->count(); ++i) { Analysis* ana = analysisList->at(i); if(ana->getAnalysisType() == WS_ANALYSISTYPE_TERRAME) { QListWidgetItem* item = new QListWidgetItem(ana->name()); item->setData(Qt::UserRole, ana->id()); _terraMEAnalysisListWidget->addItem(item); } } // Carregar os logs das analises TerraME std::vector<wsAnalysisLog> terraMEAnalysisLogs; _manager->getAllTerraMEAnalysisLogs(terraMEAnalysisLogs); // Montar objeto que vai guardar, para cada analise TerraME, um conjunto de timestamps que // representa os momentos em que cada analise foi executada. E para cada timestamp estara associado // um conjunto de imagens geradas. for(int i = 0; i < terraMEAnalysisLogs.size(); ++i) { wsAnalysisLog log = terraMEAnalysisLogs[i]; // Acessar diretorio de imagens desta analise QDir dir(log.terraMEImagePath.c_str()); if(dir.exists()) { // Obter lista de imagens, ordenadas pela hora da modificacao do arquivo. QFileInfoList imageFileNameList = dir.entryInfoList(_imageFileFilter, QDir::Files, QDir::Name); // Se foram encontradas imagens, guardar referencia para elas if(!imageFileNameList.isEmpty()) { QDateTime dateTime(QDate(log.dateStartYear, log.dateStartMonth, log.dateStartDay), QTime(log.timeStartHour, log.timeStartMinutes, log.timeStartSeconds)); TerraMEAnalysisResult analysisResult(dateTime, imageFileNameList); _terraMEResult[log.analysisId].push_back(analysisResult); } } } // Ordenar resultados pela data/hora da execucao da analise QMapIterator<int, QList<TerraMEAnalysisResult> > it(_terraMEResult); while(it.hasNext()) { it.next(); qSort(_terraMEResult[it.key()].begin(), _terraMEResult[it.key()].end()); } // Se alguma analise TerraME foi encontrada, selecionar a primeira if(_terraMEAnalysisListWidget->count() > 0) { _terraMEAnalysisListWidget->setCurrentRow(0); } }