本文整理汇总了C++中OSArgument::setValue方法的典型用法代码示例。如果您正苦于以下问题:C++ OSArgument::setValue方法的具体用法?C++ OSArgument::setValue怎么用?C++ OSArgument::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSArgument
的用法示例。
在下文中一共展示了OSArgument::setValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: userScript
TEST_F(AnalysisFixture, RubyContinuousVariable_UserScript) {
RubyMeasure userScript(toPath("setGeometry.rb"),
FileReferenceType::OSM,
FileReferenceType::OSM,
true);
OSArgument arg = OSArgument::makeDoubleArgument("floorToFloorHeight");
arg.setValue(3.0);
userScript.addArgument(arg);
arg = OSArgument::makeIntegerArgument("numFloors");
arg.setValue(1);
userScript.addArgument(arg);
EXPECT_EQ(2u,userScript.arguments().size());
EXPECT_TRUE(userScript.isUserScript());
EXPECT_EQ(toString(completeAndNormalize(toPath("setGeometry.rb"))),
toString(userScript.perturbationScript().path()));
arg = OSArgument::makeDoubleArgument("floorArea");
RubyContinuousVariable var("Floor Area (m^2)",arg,userScript);
var.setMinimum(500.0);
var.setMaximum(1000.0);
EXPECT_EQ(2u,var.measure().arguments().size());
EXPECT_TRUE(var.measure().isUserScript());
EXPECT_EQ(toString(completeAndNormalize(toPath("setGeometry.rb"))),
toString(var.measure().perturbationScript().path()));
ASSERT_TRUE(var.minimum());
EXPECT_DOUBLE_EQ(500.0,var.minimum().get());
ASSERT_TRUE(var.maximum());
EXPECT_DOUBLE_EQ(1000.0,var.maximum().get());
EXPECT_FALSE(var.increment());
EXPECT_FALSE(var.nSteps());
EXPECT_TRUE(var.isFeasible(500.0));
EXPECT_FALSE(var.isFeasible(1500.0));
ASSERT_TRUE(var.truncate(1500.0));
EXPECT_DOUBLE_EQ(1000.0,var.truncate(1500.0).get());
WeibullDistribution distribution(1.5,1.0);
EXPECT_DOUBLE_EQ(1.5,distribution.alpha());
EXPECT_DOUBLE_EQ(1.0,distribution.beta());
EXPECT_FALSE(var.uncertaintyDescription());
EXPECT_TRUE(var.setUncertaintyDescription(distribution));
ASSERT_TRUE(var.uncertaintyDescription());
ASSERT_TRUE(var.uncertaintyDescription().get().optionalCast<WeibullDistribution>());
EXPECT_DOUBLE_EQ(1.5,var.uncertaintyDescription().get().cast<WeibullDistribution>().alpha());
EXPECT_DOUBLE_EQ(1.0,var.uncertaintyDescription().get().cast<WeibullDistribution>().beta());
var.resetUncertaintyDescription();
EXPECT_FALSE(var.uncertaintyDescription());
}
示例2: problem
openstudio::analysis::Analysis AnalysisFixture::analysis2(bool simulate) {
// Create problem and analysis
Problem problem("My Problem");
BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/v2/SetWindowToWallRatioByFacade"));
RubyMeasure measure(bclMeasure);
StringVector choices;
choices.push_back("North");
choices.push_back("South");
choices.push_back("East");
choices.push_back("West");
OSArgument facade = OSArgument::makeChoiceArgument("facade",choices);
OSArgument wwr = OSArgument::makeDoubleArgument("wwr");
// RubyContinuousVariable for South Facade
measure = measure.clone().cast<RubyMeasure>();
OSArgument arg = facade.clone();
arg.setValue("South");
measure.setArgument(arg);
arg = wwr.clone();
RubyContinuousVariable southWWR("South Window to Wall Ratio",arg,measure);
problem.push(southWWR);
// RubyContinuousVariable for North Facade
measure = measure.clone().cast<RubyMeasure>();
arg = facade.clone();
arg.setValue("North");
measure.setArgument(arg);
arg = wwr.clone();
RubyContinuousVariable northWWR("North Window to Wall Ratio",arg,measure);
problem.push(northWWR);
if (simulate) {
problem.push(WorkItem(JobType::ModelToIdf));
problem.push(WorkItem(JobType::EnergyPlusPreProcess));
problem.push(WorkItem(JobType::EnergyPlus));
problem.push(WorkItem(JobType::OpenStudioPostProcess));
}
Analysis analysis("My Analysis",problem,FileReferenceType::OSM);
return analysis;
}
示例3:
TEST_F(RulesetFixture, OSArgument_Domain) {
OSArgument doubleArg = OSArgument::makeDoubleArgument("double", true);
OSArgument integerArg = OSArgument::makeIntegerArgument("integer", true);
OSArgument stringArg = OSArgument::makeStringArgument("string", true);
EXPECT_FALSE(doubleArg.hasDomain());
EXPECT_FALSE(integerArg.hasDomain());
EXPECT_FALSE(stringArg.hasDomain());
double d = 0.0;
int i = 0;
EXPECT_TRUE(doubleArg.setMinValue(d));
EXPECT_TRUE(integerArg.setMinValue(i));
EXPECT_FALSE(stringArg.setMinValue(0.0));
ASSERT_TRUE(doubleArg.hasDomain());
ASSERT_TRUE(integerArg.hasDomain());
EXPECT_FALSE(stringArg.hasDomain());
EXPECT_EQ(0.0, doubleArg.domainAsDouble()[0]);
EXPECT_EQ(std::numeric_limits<double>::max(), doubleArg.domainAsDouble()[1]);
EXPECT_EQ(0, integerArg.domainAsInteger()[0]);
EXPECT_EQ(std::numeric_limits<int>::max(), integerArg.domainAsDouble()[1]);
d = 1.0;
i = 1;
EXPECT_TRUE(doubleArg.setMaxValue(i));
EXPECT_TRUE(integerArg.setMaxValue(d));
EXPECT_FALSE(stringArg.setMaxValue(1));
ASSERT_TRUE(doubleArg.hasDomain());
ASSERT_TRUE(integerArg.hasDomain());
EXPECT_FALSE(stringArg.hasDomain());
EXPECT_EQ(0.0, doubleArg.domainAsDouble()[0]);
EXPECT_EQ(1.0, doubleArg.domainAsDouble()[1]);
EXPECT_EQ(0, integerArg.domainAsInteger()[0]);
EXPECT_EQ(1, integerArg.domainAsDouble()[1]);
// the domain is not currently used to validate these values
EXPECT_TRUE(doubleArg.setValue(-1.0));
EXPECT_TRUE(doubleArg.setValue(0.0));
EXPECT_TRUE(doubleArg.setValue(0.5));
EXPECT_TRUE(doubleArg.setValue(1.0));
EXPECT_TRUE(doubleArg.setValue(2.0));
EXPECT_TRUE(integerArg.setValue(-1));
EXPECT_TRUE(integerArg.setValue(0));
EXPECT_TRUE(integerArg.setValue(1));
EXPECT_TRUE(integerArg.setValue(2));
}
示例4: problem
TEST_F(ProjectFixture, RubyMeasureRecord_BCLMeasure) {
// Construct problem with RubyMeasure that points to BCLMeasure
Problem problem("Problem",VariableVector(),runmanager::Workflow());
MeasureGroup dvar("Variable",MeasureVector());
problem.push(dvar);
openstudio::path measuresPath = resourcesPath() / toPath("/utilities/BCL/Measures");
openstudio::path dir = measuresPath / toPath("SetWindowToWallRatioByFacade");
BCLMeasure measure = BCLMeasure::load(dir).get();
RubyMeasure rpert(measure);
dvar.push(rpert);
OSArgument arg = OSArgument::makeDoubleArgument("wwr");
arg.setValue(0.4);
rpert.setArgument(arg);
arg = OSArgument::makeIntegerArgument("typo_arg");
arg.setDefaultValue(1);
rpert.setArgument(arg);
// Serialize to database
{
ProjectDatabase database = getCleanDatabase("RubyMeasureRecord_BCLMeasure");
bool didStartTransaction = database.startTransaction();
EXPECT_TRUE(didStartTransaction);
// Problem Record
ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);
database.save();
if (didStartTransaction) {
EXPECT_TRUE(database.commitTransaction());
}
}
// Re-open database, de-serialize, verify that RubyMeasure is intact.
openstudio::path tempDir1 = measuresPath / toPath(toString(createUUID()));
{
ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_BCLMeasure");
ASSERT_EQ(1u,ProblemRecord::getProblemRecords(database).size());
ASSERT_EQ(1u,MeasureGroupRecord::getMeasureGroupRecords(database).size());
EXPECT_EQ(1u,RubyMeasureRecord::getRubyMeasureRecords(database).size());
MeasureRecordVector dprs = MeasureGroupRecord::getMeasureGroupRecords(database)[0].measureRecords(false);
ASSERT_EQ(1u,dprs.size());
ASSERT_TRUE(dprs[0].optionalCast<RubyMeasureRecord>());
RubyMeasureRecord rpr = dprs[0].cast<RubyMeasureRecord>();
RubyMeasure rp = rpr.rubyMeasure();
EXPECT_TRUE(rp.usesBCLMeasure());
EXPECT_TRUE(rp.measure());
EXPECT_EQ(dir,rp.measureDirectory());
EXPECT_EQ(measure.uuid(),rp.measureUUID());
EXPECT_EQ(measure.versionUUID(),rp.measureVersionUUID());
EXPECT_ANY_THROW(rp.perturbationScript());
EXPECT_EQ(2u,rp.arguments().size());
EXPECT_FALSE(rp.hasIncompleteArguments());
// Update measure and save
BCLMeasure newVersion = measure.clone(tempDir1).get();
newVersion.setDescription("Window to wall ratio with sill height configurable.");
newVersion.save();
EXPECT_NE(measure.versionUUID(),newVersion.versionUUID());
OSArgumentVector args;
args.push_back(OSArgument::makeDoubleArgument("wwr"));
args.push_back(OSArgument::makeDoubleArgument("sillHeight"));
Problem problemCopy = ProblemRecord::getProblemRecords(database)[0].problem();
problemCopy.updateMeasure(newVersion,args,false);
bool didStartTransaction = database.startTransaction();
EXPECT_TRUE(didStartTransaction);
// Problem Record
ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problemCopy,database);
database.save();
if (didStartTransaction) {
EXPECT_TRUE(database.commitTransaction());
}
}
// Re-open database, check that old argument records are gone, check that de-serialized object ok
openstudio::path tempDir2 = measuresPath / toPath(toString(createUUID()));
{
ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_BCLMeasure");
ASSERT_EQ(1u,ProblemRecord::getProblemRecords(database).size());
EXPECT_EQ(1u,MeasureGroupRecord::getMeasureGroupRecords(database).size());
EXPECT_EQ(1u,RubyMeasureRecord::getRubyMeasureRecords(database).size());
EXPECT_EQ(1u,FileReferenceRecord::getFileReferenceRecords(database).size());
EXPECT_EQ(2u,OSArgumentRecord::getOSArgumentRecords(database).size());
Problem problemCopy = ProblemRecord::getProblemRecords(database)[0].problem();
InputVariableVector vars = problemCopy.variables();
ASSERT_FALSE(vars.empty());
ASSERT_TRUE(vars[0].optionalCast<MeasureGroup>());
MeasureVector dps = vars[0].cast<MeasureGroup>().measures(false);
ASSERT_FALSE(dps.empty());
ASSERT_TRUE(dps[0].optionalCast<RubyMeasure>());
RubyMeasure rp = dps[0].cast<RubyMeasure>();
EXPECT_TRUE(rp.usesBCLMeasure());
EXPECT_TRUE(rp.measure());
EXPECT_EQ(tempDir1,rp.measureDirectory());
//.........这里部分代码省略.........
示例5: dv
TEST_F(AnalysisDriverFixture,SimpleProject_UpdateMeasure) {
// create a new project
SimpleProject project = getCleanSimpleProject("SimpleProject_UpdateMeasure");
Problem problem = project.analysis().problem();
// insert a measure into the project, extract and register its arguments
openstudio::path measuresDir = resourcesPath() / toPath("/utilities/BCL/Measures");
openstudio::path dir = measuresDir / toPath("SetWindowToWallRatioByFacade");
BCLMeasure measure = BCLMeasure::load(dir).get();
BCLMeasure projectMeasure = project.insertMeasure(measure);
OSArgumentVector args = argumentGetter->getArguments(projectMeasure,
project.seedModel(),
project.seedIdf());
project.registerArguments(projectMeasure,args);
EXPECT_EQ(1u,project.measures().size());
// use the measure to create a new variable/ruby measure
MeasureGroup dv("New Measure Group",MeasureVector());
EXPECT_TRUE(problem.push(dv));
RubyMeasure rp(projectMeasure);
rp.setArguments(args);
EXPECT_TRUE(dv.push(rp));
EXPECT_EQ(args.size(),rp.arguments().size());
EXPECT_TRUE(rp.hasIncompleteArguments());
BOOST_FOREACH(const OSArgument& arg,args) {
if (arg.name() == "wwr") {
OSArgument temp = arg.clone();
temp.setValue(0.6);
rp.setArgument(temp);
}
if (arg.name() == "sillHeight") {
OSArgument temp = arg.clone();
temp.setValue(1.0);
rp.setArgument(temp);
}
if (arg.name() == "facade") {
OSArgument temp = arg.clone();
temp.setValue("South");
rp.setArgument(temp);
}
}
EXPECT_FALSE(rp.hasIncompleteArguments());
openstudio::path tempDir = measuresDir / toPath(toString(createUUID()));
{
// create fake new version of the measure
BCLMeasure newVersion = measure.clone(tempDir).get();
newVersion.incrementVersionId();
newVersion.save();
OSArgumentVector newArgs = args;
newArgs.push_back(OSArgument::makeDoubleArgument("frame_width"));
// update the measure
project.updateMeasure(newVersion,newArgs);
// verify the final state of SimpleProject and RubyMeasure
EXPECT_EQ(1u,project.measures().size());
BCLMeasure retrievedMeasure = project.getMeasureByUUID(measure.uuid()).get();
EXPECT_NE(measure.versionUUID(),retrievedMeasure.versionUUID());
EXPECT_EQ(newVersion.versionUUID(),retrievedMeasure.versionUUID());
ASSERT_TRUE(project.hasStoredArguments(retrievedMeasure));
OSArgumentVector retrievedArgs = project.getStoredArguments(retrievedMeasure);
EXPECT_EQ(args.size() + 1u,retrievedArgs.size());
EXPECT_EQ(retrievedArgs.size(),rp.arguments().size());
EXPECT_TRUE(rp.hasIncompleteArguments());
}
boost::filesystem::remove_all(tempDir);
}
示例6: problem
openstudio::analysis::Analysis AnalysisFixture::analysis1(AnalysisState state) {
// Create problem and analysis
Problem problem("My Problem");
BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/SetWindowToWallRatioByFacade"));
RubyMeasure measure(bclMeasure);
// Measure Group
StringVector choices;
choices.push_back("North");
choices.push_back("South");
choices.push_back("East");
choices.push_back("West");
OSArgument facade = OSArgument::makeChoiceArgument("facade",choices);
OSArgument arg = facade.clone();
arg.setValue("South");
measure.setArgument(arg);
OSArgument wwr = OSArgument::makeDoubleArgument("wwr");
MeasureVector measures(1u,NullMeasure());
measures.push_back(measure.clone().cast<Measure>());
arg = wwr.clone();
arg.setValue(0.1);
measures.back().cast<RubyMeasure>().setArgument(arg);
measures.push_back(measure.clone().cast<Measure>());
arg = wwr.clone();
arg.setValue(0.2);
measures.back().cast<RubyMeasure>().setArgument(arg);
measures.push_back(measure.clone().cast<Measure>());
arg = wwr.clone();
arg.setValue(0.3);
measures.back().cast<RubyMeasure>().setArgument(arg);
problem.push(MeasureGroup("South Windows",measures));
// Continuous Variables Attached to Arguments
arg = facade.clone();
arg.setValue("North");
measure.setArgument(arg);
arg = wwr.clone();
RubyContinuousVariable wwrCV("Window to Wall Ratio",arg,measure);
wwrCV.setMinimum(0.0);
wwrCV.setMaximum(1.0);
TriangularDistribution td(0.2,0.0,0.5);
wwrCV.setUncertaintyDescription(td);
problem.push(wwrCV);
OSArgument offset = OSArgument::makeDoubleArgument("offset");
RubyContinuousVariable offsetCV("Offset",offset,measure);
offsetCV.setMinimum(0.0);
offsetCV.setMaximum(1.5);
NormalDistribution nd(0.9,0.05);
offsetCV.setUncertaintyDescription(nd);
problem.push(offsetCV);
// Simulation
problem.push(WorkItem(JobType::ModelToIdf));
problem.push(WorkItem(JobType::EnergyPlusPreProcess));
problem.push(WorkItem(JobType::EnergyPlus));
problem.push(WorkItem(JobType::OpenStudioPostProcess));
// Responses
LinearFunction response1("Energy Use Intensity",
VariableVector(1u,OutputAttributeVariable("EUI","site.eui")));
problem.pushResponse(response1);
VariableVector vars;
vars.push_back(OutputAttributeVariable("Heating Energy","heating.energy.gas"));
vars.push_back(OutputAttributeVariable("Cooling Energy","cooling.energy.elec"));
DoubleVector coeffs;
coeffs.push_back(1.0); // approx. source factor
coeffs.push_back(2.5); // approx. source factor
LinearFunction response2("Approximate Source Energy",vars,coeffs);
problem.pushResponse(response2);
LinearFunction response3("North WWR",VariableVector(1u,wwrCV)); // input variable as output
problem.pushResponse(response3);
Analysis analysis("My Analysis",problem,FileReferenceType::OSM);
if (state == PreRun) {
// Add three DataPoints
std::vector<QVariant> values;
values.push_back(0);
values.push_back(0.2);
values.push_back(0.9);
OptionalDataPoint dataPoint = problem.createDataPoint(values);
analysis.addDataPoint(*dataPoint);
values[0] = 1; values[1] = 0.21851789; values[2] = 1.1681938;
dataPoint = problem.createDataPoint(values);
analysis.addDataPoint(*dataPoint);
values[0] = 2; values[1] = 0.0; values[2] = 0.581563892;
dataPoint = problem.createDataPoint(values);
analysis.addDataPoint(*dataPoint);
}
else {
// state == PostRun
// Add one complete DataPoint
std::vector<QVariant> values;
values.push_back(1);
values.push_back(0.3);
values.push_back(0.9);
DoubleVector responseValues;
responseValues.push_back(58.281967);
responseValues.push_back(718952.281);
//.........这里部分代码省略.........
示例7: problem
TEST_F(AnalysisFixture, Problem_UpdateMeasure_MeasureGroups) {
// open up example measure
openstudio::path measuresPath = resourcesPath() / toPath("/utilities/BCL/Measures/v2");
openstudio::path dir = measuresPath / toPath("SetWindowToWallRatioByFacade");
ASSERT_TRUE(BCLMeasure::load(dir));
BCLMeasure measure1 = BCLMeasure::load(dir).get();
openstudio::path tempDir1 = measuresPath / toPath(toString(createUUID()));
openstudio::path tempDir2 = measuresPath / toPath(toString(createUUID()));
{
// create multiple BCLMeasures
BCLMeasure measure1_1 = measure1.clone(tempDir1).get();
measure1_1.setDescription("Window to wall ratio by wwr and offset.");
measure1_1.save();
EXPECT_TRUE(measure1_1.uuid() == measure1.uuid());
EXPECT_FALSE(measure1_1.versionUUID() == measure1.versionUUID());
BCLMeasure measure2 = measure1.clone(tempDir2).get();
measure2.changeUID();
measure2.incrementVersionId();
measure2.save();
EXPECT_FALSE(measure2.uuid() == measure1.uuid());
EXPECT_FALSE(measure2.versionUUID() == measure1.versionUUID());
// create args for those measures
OSArgumentVector args1, args1_1, args2;
args1.push_back(OSArgument::makeDoubleArgument("wwr"));
args1.push_back(OSArgument::makeDoubleArgument("sillHeight"));
args1_1.push_back(OSArgument::makeDoubleArgument("wwr"));
args1_1.push_back(OSArgument::makeDoubleArgument("offset"));
args1_1.push_back(OSArgument::makeDoubleArgument("vt"));
args2.push_back(OSArgument::makeIntegerArgument("numPeople"));
// create a problem that uses multiple BCLMeasures
Problem problem("Problem",VariableVector(),runmanager::Workflow());
MeasureGroup dv("South WWR",MeasureVector(1u,NullMeasure()));
problem.push(dv);
RubyMeasure rp(measure1);
rp.setArguments(args1);
dv.push(rp);
dv.push(rp.clone().cast<RubyMeasure>());
ASSERT_EQ(3u,dv.numMeasures(false));
rp = dv.measures(false)[2].cast<RubyMeasure>();
EXPECT_EQ(2u,rp.arguments().size());
EXPECT_TRUE(rp.hasIncompleteArguments());
dv = MeasureGroup("Occupancy",MeasureVector(1u,NullMeasure()));
problem.push(dv);
rp = RubyMeasure(measure2);
rp.setArguments(args2);
dv.push(rp);
OSArgument arg = args2[0].clone();
arg.setValue(100);
rp.setArgument(arg);
EXPECT_EQ(1u,rp.arguments().size());
EXPECT_FALSE(rp.hasIncompleteArguments());
dv = MeasureGroup("North WWR",MeasureVector(1u,NullMeasure()));
problem.push(dv);
rp = RubyMeasure(measure1);
rp.setArguments(args1);
arg = args1[0].clone();
arg.setValue(0.32);
rp.setArgument(arg);
arg = args1[1].clone();
arg.setValue(1.0);
rp.setArgument(arg);
EXPECT_EQ(2u,rp.arguments().size());
EXPECT_FALSE(rp.hasIncompleteArguments());
dv.push(rp);
EXPECT_EQ(2u,dv.numMeasures(false));
// call update
problem.clearDirtyFlag();
problem.updateMeasure(measure1_1,args1_1,false);
// check state
VariableVector vars = castVector<Variable>(problem.variables());
ASSERT_EQ(3u,vars.size());
EXPECT_TRUE(vars[0].isDirty());
EXPECT_FALSE(vars[1].isDirty());
EXPECT_TRUE(vars[2].isDirty());
dv = vars[0].cast<MeasureGroup>();
ASSERT_EQ(3u,dv.numMeasures(false));
MeasureVector ps = dv.measures(false);
EXPECT_FALSE(ps[0].isDirty());
EXPECT_TRUE(ps[1].isDirty());
rp = ps[1].cast<RubyMeasure>();
EXPECT_EQ(3u,rp.arguments().size());
EXPECT_EQ(3u,rp.incompleteArguments().size());
EXPECT_TRUE(ps[2].isDirty());
rp = ps[2].cast<RubyMeasure>();
EXPECT_EQ(3u,rp.arguments().size());
EXPECT_EQ(3u,rp.incompleteArguments().size());
dv = vars[2].cast<MeasureGroup>();
ASSERT_EQ(2u,dv.numMeasures(false));
ps = dv.measures(false);
EXPECT_FALSE(ps[0].isDirty());
EXPECT_TRUE(ps[1].isDirty());
rp = ps[1].cast<RubyMeasure>();
EXPECT_EQ(3u,rp.arguments().size());
EXPECT_EQ(2u,rp.incompleteArguments().size());
//.........这里部分代码省略.........
示例8: convertOSArgumentVectorToMap
TEST_F(RulesetFixture, OSArgument_Clone) {
std::vector<std::string> choices;
choices.push_back("On");
choices.push_back("Off");
OSArgument boolArgument = OSArgument::makeBoolArgument("bool");
OSArgument doubleArgument = OSArgument::makeDoubleArgument("double");
OSArgument integerArgument = OSArgument::makeIntegerArgument("integer");
OSArgument stringArgument = OSArgument::makeStringArgument("string");
OSArgument choiceArgument = OSArgument::makeChoiceArgument("choice", choices);
EXPECT_FALSE(boolArgument.hasValue());
EXPECT_FALSE(doubleArgument.hasValue());
EXPECT_FALSE(integerArgument.hasValue());
EXPECT_FALSE(stringArgument.hasValue());
EXPECT_FALSE(choiceArgument.hasValue());
EXPECT_TRUE(boolArgument.setValue(true));
EXPECT_TRUE(doubleArgument.setValue(1.0));
EXPECT_TRUE(doubleArgument.setValue((int)1)); // can also set double arg using int
EXPECT_TRUE(integerArgument.setValue((int)1));
EXPECT_TRUE(stringArgument.setValue(std::string("value")));
EXPECT_TRUE(choiceArgument.setValue(std::string("On")));
ASSERT_TRUE(boolArgument.hasValue());
ASSERT_TRUE(doubleArgument.hasValue());
ASSERT_TRUE(integerArgument.hasValue());
ASSERT_TRUE(stringArgument.hasValue());
ASSERT_TRUE(choiceArgument.hasValue());
EXPECT_EQ(true, boolArgument.valueAsBool());
EXPECT_EQ(1.0, doubleArgument.valueAsDouble());
EXPECT_EQ(1, integerArgument.valueAsInteger());
EXPECT_EQ("value", stringArgument.valueAsString());
EXPECT_EQ("On", choiceArgument.valueAsString());
OSArgument boolArgument2 = boolArgument.clone();
OSArgument doubleArgument2 = doubleArgument.clone();
OSArgument integerArgument2 = integerArgument.clone();
OSArgument stringArgument2 = stringArgument.clone();
OSArgument choiceArgument2 = choiceArgument.clone();
ASSERT_TRUE(boolArgument2.hasValue());
ASSERT_TRUE(doubleArgument2.hasValue());
ASSERT_TRUE(integerArgument2.hasValue());
ASSERT_TRUE(stringArgument2.hasValue());
ASSERT_TRUE(choiceArgument2.hasValue());
EXPECT_EQ(true, boolArgument2.valueAsBool());
EXPECT_EQ(1.0, doubleArgument2.valueAsDouble());
EXPECT_EQ(1, integerArgument2.valueAsInteger());
EXPECT_EQ("value", stringArgument2.valueAsString());
EXPECT_EQ("On", choiceArgument2.valueAsString());
std::vector<OSArgument> argumentVector;
argumentVector.push_back(boolArgument);
argumentVector.push_back(doubleArgument);
argumentVector.push_back(integerArgument);
argumentVector.push_back(stringArgument);
argumentVector.push_back(choiceArgument);
std::map<std::string,OSArgument> argumentMap = convertOSArgumentVectorToMap(argumentVector);
ASSERT_FALSE(argumentMap.find("bool") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("double") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("integer") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("string") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("choice") == argumentMap.end());
ASSERT_TRUE(argumentMap.find("bool")->second.hasValue());
ASSERT_TRUE(argumentMap.find("double")->second.hasValue());
ASSERT_TRUE(argumentMap.find("integer")->second.hasValue());
ASSERT_TRUE(argumentMap.find("string")->second.hasValue());
ASSERT_TRUE(argumentMap.find("choice")->second.hasValue());
EXPECT_EQ(true, argumentMap.find("bool")->second.valueAsBool());
EXPECT_EQ(1.0, argumentMap.find("double")->second.valueAsDouble());
EXPECT_EQ(1, argumentMap.find("integer")->second.valueAsInteger());
EXPECT_EQ("value", argumentMap.find("string")->second.valueAsString());
EXPECT_EQ("On", argumentMap.find("choice")->second.valueAsString());
}
示例9: perturbation
TEST_F(AnalysisFixture, RubyPerturbation_BCLMeasure) {
// construct
openstudio::path measuresPath = resourcesPath() / toPath("/utilities/BCL/Measures");
openstudio::path dir = measuresPath / toPath("SetWindowToWallRatioByFacade");
BCLMeasure measure = BCLMeasure::load(dir).get();
RubyPerturbation perturbation(measure);
EXPECT_TRUE(perturbation.usesBCLMeasure());
ASSERT_TRUE(perturbation.measure());
EXPECT_TRUE(perturbation.measure().get() == measure);
EXPECT_EQ(dir,perturbation.measureDirectory());
EXPECT_TRUE(measure.uuid() == perturbation.measureUUID());
EXPECT_TRUE(measure.versionUUID() == perturbation.measureVersionUUID());
EXPECT_ANY_THROW(perturbation.perturbationScript());
// isUserScript value is ignored in this case
EXPECT_TRUE(perturbation.arguments().empty());
EXPECT_FALSE(perturbation.hasIncompleteArguments());
// add arguments to fill in
OSArgumentVector args;
args.push_back(OSArgument::makeDoubleArgument("wwr"));
args.push_back(OSArgument::makeDoubleArgument("sillHeight"));
perturbation.setArguments(args);
// verify that arguments are incomplete
EXPECT_EQ(2u,perturbation.incompleteArguments().size());
// fill in argument values
OSArgument arg = OSArgument::makeDoubleArgument("wwr");
EXPECT_TRUE(arg.setValue(0.8));
perturbation.setArgument(arg);
EXPECT_EQ(2u,perturbation.arguments().size());
EXPECT_EQ(1u,perturbation.incompleteArguments().size());
EXPECT_TRUE(perturbation.hasIncompleteArguments());
arg = OSArgument::makeDoubleArgument("sillHeight");
arg.setValue("0.1");
perturbation.setArgument(arg);
EXPECT_EQ(2u,perturbation.arguments().size());
EXPECT_EQ(0u,perturbation.incompleteArguments().size());
EXPECT_FALSE(perturbation.hasIncompleteArguments());
// update measure
openstudio::path tempDir = measuresPath / toPath(toString(createUUID()));
{
BCLMeasure newVersion = measure.clone(tempDir).get();
newVersion.setDescription("Window to wall ratio by wwr and offset.");
newVersion.save();
EXPECT_TRUE(newVersion.uuid() == measure.uuid());
EXPECT_FALSE(newVersion.versionUUID() == measure.versionUUID());
args.pop_back();
args.push_back(OSArgument::makeDoubleArgument("offset"));
perturbation.updateMeasure(newVersion,args);
EXPECT_TRUE(perturbation.usesBCLMeasure());
ASSERT_TRUE(perturbation.measure());
EXPECT_TRUE(perturbation.measure().get() == newVersion);
EXPECT_EQ(tempDir,perturbation.measureDirectory());
EXPECT_TRUE(newVersion.uuid() == perturbation.measureUUID());
EXPECT_TRUE(newVersion.versionUUID() == perturbation.measureVersionUUID());
EXPECT_ANY_THROW(perturbation.perturbationScript());
// verify that arguments updated correctly, values retained
EXPECT_EQ(2u,perturbation.arguments().size());
ASSERT_EQ(1u,perturbation.incompleteArguments().size());
EXPECT_TRUE(perturbation.hasIncompleteArguments());
EXPECT_EQ("offset",perturbation.incompleteArguments()[0].name());
EXPECT_EQ("wwr",perturbation.arguments()[0].name());
EXPECT_EQ(0.8,perturbation.arguments()[0].valueAsDouble());
// set measure and verify that arguments cleared
perturbation.setMeasure(newVersion); // always goes through setting motions, even if same
EXPECT_TRUE(perturbation.usesBCLMeasure());
ASSERT_TRUE(perturbation.measure());
EXPECT_TRUE(perturbation.measure().get() == newVersion);
EXPECT_EQ(tempDir,perturbation.measureDirectory());
EXPECT_TRUE(newVersion.uuid() == perturbation.measureUUID());
EXPECT_TRUE(newVersion.versionUUID() == perturbation.measureVersionUUID());
EXPECT_ANY_THROW(perturbation.perturbationScript());
// isUserScript value is ignored in this case
EXPECT_TRUE(perturbation.arguments().empty());
EXPECT_FALSE(perturbation.hasIncompleteArguments());
}
boost::filesystem::remove_all(tempDir);
}
示例10: lightsDef
TEST_F(RulesetFixture, UserScript_TestModelUserScript2) {
TestModelUserScript2 script;
EXPECT_EQ("TestModelUserScript2", script.name());
Model model;
// serialize ossrs
openstudio::path fileDir = toPath("./OSResultOSSRs");
boost::filesystem::create_directory(fileDir);
// call with no arguments
TestOSRunner runner;
std::map<std::string, OSArgument> user_arguments;
bool ok = script.run(model,runner,user_arguments);
EXPECT_FALSE(ok);
OSResult result = runner.result();
EXPECT_TRUE(result.value() == OSResultValue::Fail);
EXPECT_EQ(2u,result.errors().size()); // missing required and defaulted arguments
EXPECT_EQ(0u,result.warnings().size());
EXPECT_EQ(0u,result.info().size());
EXPECT_FALSE(result.initialCondition());
EXPECT_FALSE(result.finalCondition());
EXPECT_TRUE(result.attributes().empty());
result.save(fileDir / toPath("TestModelUserScript2_1.ossr"),true);
// call with required argument, but no lights definitions in model
LightsDefinition lightsDef(model);
OSArgumentVector definitions = script.arguments(model);
user_arguments = runner.getUserInput(definitions);
OSArgument arg = definitions[0];
arg.setValue(toString(lightsDef.handle()));
user_arguments["lights_definition"] = arg;
lightsDef.remove();
EXPECT_EQ(0u,model.numObjects());
ok = script.run(model,runner,user_arguments);
EXPECT_FALSE(ok);
result = runner.result();
EXPECT_TRUE(result.value() == OSResultValue::Fail);
EXPECT_EQ(1u,result.errors().size()); // object not in model
EXPECT_EQ(0u,result.warnings().size());
EXPECT_EQ(0u,result.info().size());
EXPECT_FALSE(result.initialCondition());
EXPECT_FALSE(result.finalCondition());
EXPECT_EQ(2u,result.attributes().size()); // registers argument values
result.save(fileDir / toPath("TestModelUserScript2_2.ossr"),true);
// save attributes json for inspection
saveJSON(result.attributes(),fileDir / toPath("TestModelUserScript2_2.json"),true);
// call properly using default multiplier, but lights definition not Watts/Area
lightsDef = LightsDefinition(model);
lightsDef.setLightingLevel(700.0);
definitions = script.arguments(model);
user_arguments = runner.getUserInput(definitions);
arg = definitions[0];
arg.setValue(toString(lightsDef.handle()));
user_arguments["lights_definition"] = arg;
ok = script.run(model,runner,user_arguments);
EXPECT_TRUE(ok);
result = runner.result();
EXPECT_TRUE(result.value() == OSResultValue::NA);
EXPECT_EQ(0u,result.errors().size());
EXPECT_EQ(0u,result.warnings().size());
EXPECT_EQ(1u,result.info().size()); // Measure not applicable as called
EXPECT_FALSE(result.initialCondition());
EXPECT_FALSE(result.finalCondition());
EXPECT_EQ(3u,result.attributes().size()); // Registers lights definition name, then fails
result.save(fileDir / toPath("TestModelUserScript2_3.ossr"),true);
// save attributes json for inspection
saveJSON(result.attributes(),fileDir / toPath("TestModelUserScript2_3.json"),true);
// call properly using default multiplier
lightsDef.setWattsperSpaceFloorArea(10.0);
ok = script.run(model,runner,user_arguments);
EXPECT_TRUE(ok);
result = runner.result();
EXPECT_TRUE(result.value() == OSResultValue::Success);
EXPECT_EQ(0u,result.errors().size());
EXPECT_EQ(0u,result.warnings().size());
EXPECT_EQ(0u,result.info().size());
EXPECT_TRUE(result.initialCondition()); // describes original state
EXPECT_TRUE(result.finalCondition()); // describes changes
EXPECT_EQ(8u,result.attributes().size());
result.save(fileDir / toPath("TestModelUserScript2_4.ossr"),true);
EXPECT_DOUBLE_EQ(8.0,lightsDef.wattsperSpaceFloorArea().get());
// save attributes json for inspection
saveJSON(result.attributes(),fileDir / toPath("TestModelUserScript2_4.json"),true);
// call properly using different multiplier
arg = definitions[1];
arg.setValue(0.5);
user_arguments["multiplier"] = arg;
ok = script.run(model,runner,user_arguments);
EXPECT_TRUE(ok);
result = runner.result();
EXPECT_TRUE(result.value() == OSResultValue::Success);
EXPECT_EQ(0u,result.errors().size());
EXPECT_EQ(0u,result.warnings().size());
EXPECT_EQ(0u,result.info().size());
EXPECT_TRUE(result.initialCondition()); // describes original state
EXPECT_TRUE(result.finalCondition()); // describes changes
//.........这里部分代码省略.........