Entity::ComponentVector Entity::GetComponents(const QString &type_name) const { ComponentVector ret; for(size_t i = 0; i < components_.size() ; ++i) if (components_[i]->TypeName() == type_name) ret.push_back(components_[i]); return ret; }
Entity::ComponentVector Entity::ComponentsOfType(u32 typeId) const { ComponentVector ret; for (ComponentMap::const_iterator i = components_.begin(); i != components_.end(); ++i) if (i->second->TypeId() == typeId) ret.push_back(i->second); return ret; }
Entity::ComponentVector Entity::ComponentsOfType(u32 typeId) const { ComponentVector ret; for (ComponentMap::ConstIterator i = components_.Begin(); i != components_.End(); ++i) if (i->second_->TypeId() == typeId) ret.Push(i->second_); return ret; }
// test similar to ruby test, but without saving to osp, to see if problem // can be replicated in C++ TEST_F(ModelFixture, Component_CreateScheduleLibrary) { Model model = exampleModel(); ScheduleVector schedules = model.getModelObjects<Schedule>(); ComponentVector components; BOOST_FOREACH(const Schedule& schedule, schedules) { Component newComponent = schedule.createComponent(); bool ok = newComponent.componentData().setName(schedule.name().get()); EXPECT_TRUE(ok); components.push_back(newComponent); }
vector<string> Generator::Generate(string baseRule) const { ComponentVector mainList; ComponentVector tempList; static std::random_device rd; static std::mt19937 gen(rd()); { const pair< RuleMap::const_iterator, RuleMap::const_iterator > &range = mpRuleset->GetRulesFor(baseRule); std::pair< DistributionMap::const_iterator, DistributionMap::const_iterator > weightData = mpRuleset->GetWeightsFor(baseRule); vector< float > weights = iterator_to_vector(weightData.first, weightData.second); std::discrete_distribution<int> dist(weights.begin(), weights.end()); RuleMap::const_iterator it = range.first; std::advance(it, dist(gen)); ComponentVector initial = it->second; mainList = initial; } bool run; do { run = false; tempList.clear(); for(ComponentVector::const_iterator it = mainList.begin(); it != mainList.end(); ++it) { if(mpRuleset->IsTerminal(*it)) tempList.push_back(*it); else { run = true; const pair< RuleMap::const_iterator, RuleMap::const_iterator > &rules = mpRuleset->GetRulesFor(*it); if ( rules.first != rules.second ) { // Fetch weights for the current to-be-decomposed rules std::pair< DistributionMap::const_iterator, DistributionMap::const_iterator > ruleWeightData = mpRuleset->GetWeightsFor(*it); vector< float > ruleWeights = iterator_to_vector(ruleWeightData.first, ruleWeightData.second); // Setup distribution with the weights and choose a random rule to apply std::discrete_distribution<int> dist(ruleWeights.begin(), ruleWeights.end()); RuleMap::const_iterator it = rules.first; std::advance(it, dist(gen)); const ComponentVector &tobeadded = it->second; tempList.insert(tempList.end(), tobeadded.begin(), tobeadded.end()); } } } mainList = tempList; } while(run); return mainList; }
// test similar to ruby test, but without saving to osp, to see if problem // can be replicated in C++ TEST_F(ModelFixture, Component_CreateScheduleLibrary) { Model model = exampleModel(); ScheduleVector schedules = model.getModelObjects<Schedule>(); ComponentVector components; for (const Schedule& schedule : schedules) { Component newComponent = schedule.createComponent(); bool ok = newComponent.componentData().setName(schedule.name().get()); EXPECT_TRUE(ok); components.push_back(newComponent); } int index(1); for (Component& component : components) { std::stringstream ss; ss << "./component" << index; openstudio::path p = toPath(ss.str()); if (boost::filesystem::exists(p)) { boost::filesystem::remove_all(p); } component.save(p / toPath("component.osc")); ++index; } }
/// \brief Add a set of components that we should consider relevant to the /// container. void addComponents(const ComponentVector &Components) { // FIXME: add sort(on ID)+unique to avoid extra work. for (ComponentVector::const_iterator I = Components.begin(), E = Components.end(); I != E; ++I) addComponent(*I); }
void FGStateSpace::numericalJacobian(std::vector< std::vector<double> > & J, ComponentVector & y, ComponentVector & x, const std::vector<double> & y0, const std::vector<double> & x0, double h, bool computeYDerivative) { size_t nX = x.getSize(); size_t nY = y.getSize(); double f1 = 0, f2 = 0, fn1 = 0, fn2 = 0; J.resize(nY); for (unsigned int iY=0;iY<nY;iY++) { J[iY].resize(nX); for (unsigned int iX=0;iX<nX;iX++) { x.set(x0); x.set(iX,x.get(iX)+h); if (computeYDerivative) f1 = y.getDeriv(iY); else f1 = y.get(iY); x.set(x0); x.set(iX,x.get(iX)+2*h); if (computeYDerivative) f2 = y.getDeriv(iY); else f2 = y.get(iY); x.set(x0); x.set(iX,x.get(iX)-h); if (computeYDerivative) fn1 = y.getDeriv(iY); else fn1 = y.get(iY); x.set(x0); x.set(iX,x.get(iX)-2*h); if (computeYDerivative) fn2 = y.getDeriv(iY); else fn2 = y.get(iY); double diff1 = f1-fn1; double diff2 = f2-fn2; // correct for angle wrap if (x.getComp(iX)->getUnit().compare("rad") == 0) { while(diff1 > M_PI) diff1 -= 2*M_PI; if(diff1 < -M_PI) diff1 += 2*M_PI; if(diff2 > M_PI) diff2 -= 2*M_PI; if(diff2 < -M_PI) diff2 += 2*M_PI; } else if (x.getComp(iX)->getUnit().compare("deg") == 0) { if(diff1 > 180) diff1 -= 360; if(diff1 < -180) diff1 += 360; if(diff2 > 180) diff2 -= 360; if(diff2 < -180) diff2 += 360; } J[iY][iX] = (8*diff1-diff2)/(12*h); // 3rd order taylor approx from lewis, pg 203 x.set(x0); if (m_fdm->GetDebugLevel() > 1) { std::cout << std::scientific << "\ty:\t" << y.getName(iY) << "\tx:\t" << x.getName(iX) << "\tfn2:\t" << fn2 << "\tfn1:\t" << fn1 << "\tf1:\t" << f1 << "\tf2:\t" << f2 << "\tf1-fn1:\t" << f1-fn1 << "\tf2-fn2:\t" << f2-fn2 << "\tdf/dx:\t" << J[iY][iX] << std::fixed << std::endl; } } } }
void FGStateSpace::numericalJacobian(std::vector< std::vector<double> > & J, ComponentVector & y, ComponentVector & x, const std::vector<double> & y0, const std::vector<double> & x0, double h, bool computeYDerivative) { int nX = x.getSize(); int nY = y.getSize(); double f1 = 0, f2 = 0, fn1 = 0, fn2 = 0; J.resize(nY); for (int iY=0;iY<nY;iY++) { J[iY].resize(nX); for (int iX=0;iX<nX;iX++) { x.set(x0); x.set(iX,x.get(iX)+h); if (computeYDerivative) f1 = y.getDeriv(iY); else f1 = y.get(iY); x.set(x0); x.set(iX,x.get(iX)+2*h); if (computeYDerivative) f2 = y.getDeriv(iY); else f2 = y.get(iY); x.set(x0); x.set(iX,x.get(iX)-h); if (computeYDerivative) fn1 = y.getDeriv(iY); else fn1 = y.get(iY); x.set(x0); x.set(iX,x.get(iX)-2*h); if (computeYDerivative) fn2 = y.getDeriv(iY); else fn2 = y.get(iY); J[iY][iX] = (8*(f1-fn1)-(f2-fn2))/(12*h); // 3rd order taylor approx from lewis, pg 203 x.set(x0); if (m_fdm->GetDebugLevel() > 1) { std::cout << std::scientific << "\ty:\t" << y.getName(iY) << "\tx:\t" << x.getName(iX) << "\tfn2:\t" << fn2 << "\tfn1:\t" << fn1 << "\tf1:\t" << f1 << "\tf2:\t" << f2 << "\tf1-fn1:\t" << f1-fn1 << "\tf2-fn2:\t" << f2-fn2 << "\tdf/dx:\t" << J[iY][iX] << std::fixed << std::endl; } } } }