Example #1
0
File: Entity.cpp Project: A-K/naali
 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;
 }
Example #2
0
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;
}
Example #3
0
// 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);
  }
Example #4
0
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;
}
Example #5
0
// 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;
  }
}