本文整理汇总了C++中Analysis::algorithm方法的典型用法代码示例。如果您正苦于以下问题:C++ Analysis::algorithm方法的具体用法?C++ Analysis::algorithm怎么用?C++ Analysis::algorithm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analysis
的用法示例。
在下文中一共展示了Analysis::algorithm方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: seedModel
TEST_F(AnalysisDriverFixture,RuntimeBehavior_StopAndRestartDakotaAnalysis) {
// RETRIEVE PROBLEM
Problem problem = retrieveProblem("SimpleHistogramBinUQ",true,false);
// DEFINE SEED
Model model = model::exampleModel();
openstudio::path p = toPath("./example.osm");
model.save(p,true);
FileReference seedModel(p);
// CREATE ANALYSIS
SamplingAlgorithmOptions algOptions;
algOptions.setSamples(10);
Analysis analysis("Stop and Restart Dakota Analysis",
problem,
SamplingAlgorithm(algOptions),
seedModel);
// RUN ANALYSIS
if (!dakotaExePath().empty()) {
ProjectDatabase database = getCleanDatabase("StopAndRestartDakotaAnalysis");
AnalysisDriver analysisDriver(database);
AnalysisRunOptions runOptions = standardRunOptions(analysisDriver.database().path().parent_path());
StopWatcher watcher(analysisDriver);
watcher.watch(analysis.uuid());
CurrentAnalysis currentAnalysis = analysisDriver.run(analysis,runOptions);
analysisDriver.waitForFinished();
EXPECT_FALSE(analysisDriver.isRunning());
// check conditions afterward
boost::optional<runmanager::JobErrors> jobErrors = currentAnalysis.dakotaJobErrors();
ASSERT_TRUE(jobErrors);
EXPECT_FALSE(jobErrors->errors().empty());
EXPECT_FALSE(currentAnalysis.analysis().dataPoints().empty());
EXPECT_FALSE(currentAnalysis.analysis().dataPointsToQueue().empty());
EXPECT_FALSE(currentAnalysis.analysis().completeDataPoints().empty());
EXPECT_FALSE(currentAnalysis.analysis().successfulDataPoints().empty());
EXPECT_TRUE(currentAnalysis.analysis().failedDataPoints().empty());
EXPECT_FALSE(currentAnalysis.analysis().algorithm()->isComplete());
EXPECT_FALSE(currentAnalysis.analysis().algorithm()->failed());
EXPECT_EQ(0u,analysisDriver.currentAnalyses().size());
LOG(Debug,"After initial stop, there are " << currentAnalysis.analysis().dataPoints().size()
<< " data points, of which " << currentAnalysis.analysis().completeDataPoints().size()
<< " are complete.");
// try to restart from database contents
Analysis analysis = AnalysisRecord::getAnalysisRecords(database)[0].analysis();
ASSERT_TRUE(analysis.algorithm());
EXPECT_FALSE(analysis.algorithm()->isComplete());
EXPECT_FALSE(analysis.algorithm()->failed());
currentAnalysis = analysisDriver.run(analysis,runOptions);
analysisDriver.waitForFinished();
EXPECT_EQ(10u,analysis.dataPoints().size());
EXPECT_EQ(0u,analysis.dataPointsToQueue().size());
EXPECT_EQ(10u,analysis.completeDataPoints().size());
EXPECT_EQ(10u,analysis.successfulDataPoints().size());
EXPECT_EQ(0u,analysis.failedDataPoints().size());
}
}
示例2: toPath
TEST_F(AnalysisDriverFixture,SimpleProject_Create) {
openstudio::path projectDir = toPath("AnalysisDriverFixtureData");
if (!boost::filesystem::exists(projectDir)) {
boost::filesystem::create_directory(projectDir);
}
projectDir = projectDir / toPath("NewProject");
boost::filesystem::remove_all(projectDir);
OptionalSimpleProject project = SimpleProject::create(projectDir);
ASSERT_TRUE(project);
EXPECT_TRUE(boost::filesystem::exists(projectDir));
EXPECT_TRUE(boost::filesystem::is_directory(projectDir));
EXPECT_TRUE(boost::filesystem::exists(projectDir / toPath("project.osp")));
EXPECT_TRUE(boost::filesystem::exists(projectDir / toPath("run.db")));
EXPECT_TRUE(boost::filesystem::exists(projectDir / toPath("project.log")));
Analysis analysis = project->analysis();
EXPECT_EQ(0,analysis.problem().numVariables());
EXPECT_FALSE(analysis.algorithm());
EXPECT_EQ(0u,analysis.dataPoints().size());
AnalysisRecord analysisRecord = project->analysisRecord();
EXPECT_EQ(0u,analysisRecord.problemRecord().inputVariableRecords().size());
EXPECT_EQ(0u,analysisRecord.dataPointRecords().size());
}
示例3: name
boost::optional<DataPoint> DakotaAlgorithm_Impl::createNextDataPoint(
Analysis& analysis,const DakotaParametersFile& params)
{
OS_ASSERT(analysis.algorithm().get() == getPublicObject<DakotaAlgorithm>());
// TODO: Update iteration counter.
OptionalDataPoint result = analysis.problem().createDataPoint(params,
getPublicObject<DakotaAlgorithm>());
if (result) {
bool added = analysis.addDataPoint(*result);
if (!added) {
// get equivalent point already in analysis
DataPointVector candidates = analysis.getDataPoints(result->variableValues());
OS_ASSERT(candidates.size() == 1u);
result = candidates[0];
}
std::stringstream ss;
ss << name() << "_" << m_iter;
result->addTag(ss.str());
}
return result;
}
示例4: seedModel
TEST_F(AnalysisDriverFixture, DDACE_LatinHypercube_MixedOsmIdf_MoveProjectDatabase) {
openstudio::path oldDir, newDir;
{
// GET SIMPLE PROJECT
SimpleProject project = getCleanSimpleProject("DDACE_LatinHypercube_MixedOsmIdf");
Analysis analysis = project.analysis();
analysis.setName("DDACE Latin Hypercube Sampling - MixedOsmIdf");
// SET PROBLEM
Problem problem = retrieveProblem("MixedOsmIdf",false,false);
analysis.setProblem(problem);
// SET SEED
Model model = model::exampleModel();
openstudio::path p = toPath("./example.osm");
model.save(p,true);
FileReference seedModel(p);
analysis.setSeed(seedModel);
// SET ALGORITHM
DDACEAlgorithmOptions algOptions(DDACEAlgorithmType::lhs);
algOptions.setSamples(12); // test reprinting results.out for copies of same point
DDACEAlgorithm algorithm(algOptions);
analysis.setAlgorithm(algorithm);
// RUN ANALYSIS
AnalysisDriver driver = project.analysisDriver();
AnalysisRunOptions runOptions = standardRunOptions(project.projectDir());
CurrentAnalysis currentAnalysis = driver.run(analysis,runOptions);
EXPECT_TRUE(driver.waitForFinished());
boost::optional<runmanager::JobErrors> jobErrors = currentAnalysis.dakotaJobErrors();
ASSERT_TRUE(jobErrors);
EXPECT_TRUE(jobErrors->errors().empty());
EXPECT_TRUE(driver.currentAnalyses().empty());
Table summary = analysis.summaryTable();
EXPECT_EQ(5u,summary.nRows()); // 4 points (all combinations)
summary.save(project.projectDir() / toPath("summary.csv"));
EXPECT_EQ(4u,analysis.dataPoints().size());
BOOST_FOREACH(const DataPoint& dataPoint,analysis.dataPoints()) {
EXPECT_TRUE(dataPoint.isComplete());
EXPECT_FALSE(dataPoint.failed());
EXPECT_TRUE(dataPoint.workspace()); // should be able to load data from disk
}
oldDir = project.projectDir();
newDir = project.projectDir().parent_path() / toPath("DDACELatinHypercubeMixedOsmIdfCopy");
// Make copy of project
boost::filesystem::remove_all(newDir);
ASSERT_TRUE(project.saveAs(newDir));
}
// Blow away old project.
// TODO: Reinstate. This was failing on Windows and isn't absolutely necessary.
// try {
// boost::filesystem::remove_all(oldDir);
// }
// catch (std::exception& e) {
// EXPECT_TRUE(false) << "Boost filesystem was unable to delete the old folder, because " << e.what();
// }
// Open new project
SimpleProject project = getSimpleProject("DDACE_LatinHypercube_MixedOsmIdf_Copy");
EXPECT_TRUE(project.projectDir() == newDir);
EXPECT_EQ(toString(newDir),toString(project.projectDir()));
// After move, should be able to retrieve results.
EXPECT_FALSE(project.analysisIsLoaded());
Analysis analysis = project.analysis();
EXPECT_TRUE(project.analysisIsLoaded());
EXPECT_EQ(4u,analysis.dataPoints().size());
BOOST_FOREACH(const DataPoint& dataPoint,analysis.dataPoints()) {
EXPECT_TRUE(dataPoint.isComplete());
EXPECT_FALSE(dataPoint.failed());
LOG(Debug,"Attempting to load workspace for data point at '" << dataPoint.directory() << "'.");
if (dataPoint.idfInputData()) {
LOG(Debug,"Says there should be input data at " << toString(dataPoint.idfInputData()->path()));
}
EXPECT_TRUE(dataPoint.workspace()); // should be able to load data from disk
if (!dataPoint.workspace()) {
LOG(Debug,"Unsuccessful.")
}
}
// Should be able to blow away results and run again
project.removeAllDataPoints();
EXPECT_EQ(0u,analysis.dataPoints().size());
EXPECT_FALSE(analysis.algorithm()->isComplete());
EXPECT_FALSE(analysis.algorithm()->failed());
EXPECT_EQ(-1,analysis.algorithm()->iter());
EXPECT_FALSE(analysis.algorithm()->cast<DakotaAlgorithm>().restartFileReference());
EXPECT_FALSE(analysis.algorithm()->cast<DakotaAlgorithm>().outFileReference());
AnalysisRunOptions runOptions = standardRunOptions(project.projectDir());
AnalysisDriver driver = project.analysisDriver();
CurrentAnalysis currentAnalysis = driver.run(analysis,runOptions);
EXPECT_TRUE(driver.waitForFinished());
boost::optional<runmanager::JobErrors> jobErrors = currentAnalysis.dakotaJobErrors();
ASSERT_TRUE(jobErrors);
EXPECT_TRUE(jobErrors->errors().empty());
EXPECT_TRUE(driver.currentAnalyses().empty());
Table summary = analysis.summaryTable();
//.........这里部分代码省略.........
示例5: record
// 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;
}
示例6: seedModel
TEST_F(AnalysisDriverFixture,DataPersistence_DakotaErrors) {
{
// Create and populate project
SimpleProject project = getCleanSimpleProject("DataPersistence_DakotaErrors");
Analysis analysis = project.analysis();
Problem problem = retrieveProblem(AnalysisDriverFixtureProblem::BuggyBCLMeasure,
true,
false);
analysis.setProblem(problem);
model::Model model = model::exampleModel();
openstudio::path p = toPath("./example.osm");
model.save(p,true);
FileReference seedModel(p);
project.setSeed(seedModel);
DDACEAlgorithmOptions algOpts(DDACEAlgorithmType::lhs);
// do not set samples so Dakota job will have errors
DDACEAlgorithm alg(algOpts);
analysis.setAlgorithm(alg);
// Run analysis
AnalysisRunOptions runOptions = standardRunOptions(project.projectDir());
project.analysisDriver().run(analysis,runOptions);
project.analysisDriver().waitForFinished();
// Check Dakota job and error information
ASSERT_TRUE(alg.job());
Job job = alg.job().get();
EXPECT_FALSE(job.running());
EXPECT_FALSE(job.outOfDate());
EXPECT_FALSE(job.canceled());
EXPECT_TRUE(job.lastRun());
JobErrors errors = job.errors();
EXPECT_EQ(OSResultValue(OSResultValue::Fail),errors.result);
EXPECT_FALSE(errors.succeeded());
EXPECT_FALSE(errors.errors().empty());
EXPECT_TRUE(errors.warnings().empty());
EXPECT_TRUE(errors.infos().empty());
}
{
// Re-open project
SimpleProject project = getSimpleProject("DataPersistence_DakotaErrors");
Analysis analysis = project.analysis();
DDACEAlgorithm alg = analysis.algorithm()->cast<DDACEAlgorithm>();
// Verify job and error information still there
ASSERT_TRUE(alg.job());
Job job = alg.job().get();
EXPECT_FALSE(job.running());
EXPECT_FALSE(job.outOfDate());
EXPECT_FALSE(job.canceled());
EXPECT_TRUE(job.lastRun());
JobErrors errors = job.errors();
EXPECT_EQ(OSResultValue(OSResultValue::Fail),errors.result);
EXPECT_FALSE(errors.succeeded());
EXPECT_FALSE(errors.errors().empty());
EXPECT_TRUE(errors.warnings().empty());
EXPECT_TRUE(errors.infos().empty());
}
}
示例7: createNextIteration
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;
}