void DAGNode::updateSimulationContext() { if ( !getParents().empty() ) { if( debug_ ) { std::cerr<<"DAGNode::updateContext, node = "<<getName()<<", incoming context = "<< getParents()[0]->getContext() << std::endl; } // TODO // ahem.... not sure here... which parent should I copy my simulation context from exactly ? copySimulationContext(*dynamic_cast<Context*>(getParents()[0])); } simulation::Node::updateSimulationContext(); }
/// Generic list of objects access, possibly searching up or down from the current context /// /// Note that the template wrapper method should generally be used to have the correct return type, void DAGNode::getObjects(const sofa::core::objectmodel::ClassInfo& class_info, GetObjectsCallBack& container, const sofa::core::objectmodel::TagSet& tags, SearchDirection dir) const { if (dir == SearchRoot) { if (!getParents().empty()) { getRootContext()->getObjects(class_info, container, tags, dir); return; } else dir = SearchDown; // we are the root, search down from here. } if (dir != SearchParents) for (ObjectIterator it = this->object.begin(); it != this->object.end(); ++it) { core::objectmodel::BaseObject* obj = it->get(); void* result = class_info.dynamicCast(obj); if (result != NULL && (tags.empty() || (obj)->getTags().includes(tags))) container(result); } { switch(dir) { case Local: break; case SearchParents: case SearchUp: { // WORK IN PROGRESS // TODO: manage diamond setups to avoid multiple getObjects() calls on a Node... Parents parents = getParents(); for (Parents::iterator it = parents.begin(); it!=parents.end(); it++) dynamic_cast<Node*>(*it)->getObjects(class_info, container, tags, SearchUp); } break; case SearchDown: for(ChildIterator it = child.begin(); it != child.end(); ++it) { if ((*it)->isActive()) (*it)->getObjects(class_info, container, tags, dir); } break; case SearchRoot: std::cerr << "SearchRoot SHOULD NOT BE POSSIBLE HERE!\n"; break; } } }
////IMPLEMENTATION1: NO DISJOINT SEPERATION MORE GROUNDING, faster in some cases void LProposalConstructor::constructProposalV1(vector<WClause*>& CNF,vector<Atom*>& potentialParents) { if(CNF.size()==0) return; int powerFactor; bool isDecomposed = lsearch->decomposeCNF(CNF,powerFactor); if(isDecomposed) { //use power rule constructProposalV1(CNF,potentialParents); return; } Atom* tmpSelectedAtom = lsearch->selectAtomToCondition(CNF); if(tmpSelectedAtom == NULL) { cleanup(CNF); return; } Atom* selectedAtom = LvrMLN::create_new_atom(tmpSelectedAtom); vector<Atom*> parents; if(potentialParents.size() > 0) { getParents(CNF,selectedAtom,potentialParents,parents); } //see if atom has isolated terms vector<bool> isolatedTerms; bool isIsolated = LRulesUtil::computeIsolatedTerms(selectedAtom,CNF,isolatedTerms); lpd->insertElement(selectedAtom,parents,isolatedTerms); potentialParents.push_back(selectedAtom); lpg->propagateNormalizedCNF(CNF,selectedAtom,isolatedTerms); constructProposalV1(CNF,potentialParents); cleanup(CNF); }
void Fragment::removeParents() { const vector<CompFragment*>& parentElements = getParents(); //logout << "removing parents of " << frag << ", " << *frag << endl; //writeBuf(); while (! parentElements.empty()) { // let unlinking be done by parent at point of deconstruction, // simply loop while more parent objects remaining CompFragment* thisParent = parentElements.front(); //logout << frag << " remove comp " << thisParent << endl; //writeBuf(); if (! thisParent->removeChild(this)) { logout << "failure to remove child " << *this << "from parent " << thisParent << "," << *thisParent << endl; writeBufWarn(); break; } } if (! parentElements.empty()) { logout << "looping error removing parents of " << this << ", " << *this << endl; writeBufWarn(); } }
void SoundEmitter::update(EventDetails* const details) { OSG_ASSERT(getParents().size() == 1 && "A Sound Emitter NodeCore MUST have 1 and only 1 parent."); Matrix wm; dynamic_cast<Node*>(_mfParents[0])->getToWorld(wm); Pnt3f Position(0, 0, 0); wm.mult(Pnt3f(0.0f,0.0f,0.0f),Position); if(getSound() != NULL) { //Remove all invalid for(std::set<UInt32>::iterator Itor(_EmittedSoundChannels.begin()) ; Itor != _EmittedSoundChannels.end() ;) { if(!getSound()->isValid(*Itor)) { std::set<UInt32>::iterator EraseItor(Itor); ++Itor; _EmittedSoundChannels.erase(EraseItor); } else { //getSound()->setChannelVelocity(_PreviousPosition - Position * (1.0f/dynamic_cast<UpdateEventDetails* const>(details)->getElapsedTime()), *Itor); getSound()->setChannelPosition(Position, *Itor); ++Itor; } } } _PreviousPosition = Position; }
void DAGNode::initVisualContext() { if (!getParents().empty()) { this->setDisplayWorldGravity(false); //only display gravity for the root: it will be propagated at each time step } }
double geneticAlgorithm(double bestA[10]){ srand(time(NULL)); double poblacion [1000][10]; double poblacionN [1000][10]; double parents[2][10]; double hijo [10]; double bestsofarP[10]; double resultN[10]; double bestsofar = -999; double prevresult = -999; double temp; int repetidos = 0; int j = 0; int i = 0; for(i = 0; i < 1000; i++) { for(j = 0; j < 10; j++) { poblacion[i][j] = (rand()%10 < 5 ? -1 : 1)*(double)rand() / ((double)(RAND_MAX)+(double)(1)); } } int k,n = 0; double result = -999; while(result < 9 && numeval <= NUMEVAL){ prevresult = result; for(i = 0; i < 1000; i++){ getParents(poblacion,parents); reproducir(parents[0],parents[1],hijo); if(rand()%10 < 1){ mutar(hijo); } temp = evaluar(hijo); numeval++; if(temp > result){ result = temp; memcpy(&resultN, &hijo, sizeof(double)*10); } memcpy(&poblacionN[i], &hijo,sizeof(double)*10); } memcpy(&poblacion,&poblacionN,sizeof(double)*10000); if(result > bestsofar) { repetidos = 0; bestsofar = result; memcpy(bestsofarP, resultN,sizeof(double)*10); }else if(result == prevresult) { if(repetidos == 5){ result = bestsofar; break; } repetidos++; }else if(result != prevresult) { repetidos = 0; } printf("BestSoFar: %lf Prev: %lf, Result: %lf \n",bestsofar,prevresult,result); } memcpy(bestA,bestsofarP,sizeof(double)*10); return result; }
/// Test if the given context is a parent of this context. bool DAGNode::hasParent(const BaseContext* context) const { if (context == NULL) return getParents().empty(); LinkParents::Container parents = l_parents.getValue(); for ( unsigned int i = 0; i < parents.size() ; i++) if (context == parents[i]->getContext()) return true; return false; }
void LibraryManager::setOntology(shared_ptr<Ontology> _ont, shared_ptr<MediaHolder> _obj){ string type = _ont->getType(); if(type=="category"){ vector<shared_ptr<StoreObject> > & vp = getParents(_obj); vp.clear(); } setHierarchy(_ont, _obj); }
void AnnotatedCluster::connectEntranceEndpoints(node* newendpoint, AnnotatedClusterAbstraction* aca) { for(unsigned int i=0; i<getParents().size(); i++) { /* simplest capabilities (those involving fewest terrains) first and others last. important to avoid creating identical edges NB: assumes capabilities array is sorted accordingly */ node* existingendpoint = getParents()[i]; for(int capindex=0; capindex < NUMCAPABILITIES ; capindex++) { int capability = capabilities[capindex]; /* find paths for largest size agents first and smallest ones last. NB: assumes agentsizes array is sorted accordingly */ for(int sizeindex = NUMAGENTSIZES-1; sizeindex>=0; sizeindex--) { int size = agentsizes[sizeindex]; connectEntranceEndpointsForAGivenCapabilityAndSize(newendpoint, existingendpoint, capability, size, aca); } } } }
void ReparentingStrategy::updateParents(Id id) { TodoNode *node = m_model->m_parentMap.leftToRight(id); if (!node || !node->rowSourceIndex().isValid()) { // kDebug() << id; return; } Q_ASSERT(node); IdList parents = getParents(node->rowSourceIndex()); // kDebug() << id << parents; m_model->reparentNode(id, parents, node->rowSourceIndex()); }
void LProposalConstructor::constructProposal(vector<WClause*>& CNF1,vector<Atom*>& potentialParents) { if(CNF1.size()==0) return; vector<vector<WClause*> > dCNFs; LClusterUtil::seperateDisjointCNF(CNF1,dCNFs); cleanup(CNF1); for(unsigned int t=0;t<dCNFs.size();t++) { vector<WClause*> CNF = dCNFs[t]; int powerFactor; bool isDecomposed = lsearch->decomposeCNF(CNF,powerFactor); if(isDecomposed) { //use power rule constructProposal(CNF,potentialParents); continue; } Atom* tmpSelectedAtom = lsearch->selectAtomToCondition(CNF); if(tmpSelectedAtom == NULL) { cleanup(CNF); continue; } Atom* selectedAtom = LvrMLN::create_new_atom(tmpSelectedAtom); vector<Atom*> parents; if(potentialParents.size() > 0) { getParents(CNF,selectedAtom,potentialParents,parents); } //see if atom has isolated terms vector<bool> isolatedTerms; bool isIsolated = LRulesUtil::computeIsolatedTerms(selectedAtom,CNF,isolatedTerms); lpd->insertElement(selectedAtom,parents,isolatedTerms); potentialParents.push_back(selectedAtom); //remove atom from all clauses for(unsigned int i=0;i<CNF.size();i++) { for(int j=0;j<CNF[i]->atoms.size();j++) { if(CNF[i]->atoms[j]->symbol->id == selectedAtom->symbol->id) { CNF[i]->removeAtom(j); j--; } } } constructProposal(CNF,potentialParents); cleanup(CNF); } }
bool Function::checkNoMissingEntries(map<string, StateObsAct*> mymap, string& info) { stringstream ssinfo; vector<int> commonIndex; if (!sparseT->checkNoMissingEntries(commonIndex)) { ssinfo << " Transition not specified for instance "; for(int i=0;i<commonIndex.size();i++){ if(getParents()[i]!="null"){ StateObsAct* soa = mymap[getParents()[i]]; ssinfo << soa->getValueEnum()[commonIndex[i]] << " "; }else{ ssinfo << "null" << endl; } } ssinfo << endl; info = ssinfo.str(); return false; } else return true; }//end of checkNoMissingEntries(map<string, StateObsAct*> mymap)
void SoundEmitter::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(whichField & ParentsFieldMask && getParents().size() > 0) { Matrix wm; dynamic_cast<Node*>(_mfParents[0])->getToWorld(wm); wm.multFull(Pnt3f(0.0f,0.0f,0.0f),_PreviousPosition); } }
vector< shared_ptr<Ontology> > LibraryManager::getOntologies(shared_ptr<MediaHolder> _media){ vector< shared_ptr<StoreObject> > vp; vector< shared_ptr<Ontology> > vo; vp = getParents(_media); for (int i=0; i<vp.size(); i++) { if(vp[i]->getType()=="tag"||vp[i]->getType()=="category"){ vo.push_back(dynamic_pointer_cast<Ontology>(vp[i])); } } return vo; }
/// Return the full path name of this node std::string DAGNode::getPathName() const { std::string str; Parents parents = getParents(); if (!parents.empty()) { // for the full path name, we arbitrarily take the first parent of the list... // no smarter choice without breaking the "Node" heritage str = parents[0]->getPathName(); str += '/'; str += getName(); } return str; }
void LibraryManager::setOntology(shared_ptr<Ontology> _ont, vector< shared_ptr<MediaHolder> > _objs){ string type = _ont->getType(); for (int i=0; i<_objs.size(); i++) { if(type=="category"){ vector<shared_ptr<StoreObject> > & vp = getParents(_objs[i]); vp.clear(); } setHierarchy(_ont, _objs[i]); } }
void GeneOntology::addParentGeneOntologyIdentifier(GeneOntologyIdentifier term,GeneOntologyIdentifier parent){ #ifdef ASSERT if(hasParent(term)){ vector<GeneOntologyIdentifier> parents; getParents(term,&parents); for(int i=0;i<(int)parents.size();i++){ assert(parent!=parents[i]); } } #endif /* ASSERT */ m_parents[term].push_back(parent); m_children[parent].push_back(term); }
void SoundEmitter::attachUpdateProducer(ReflexiveContainer* const producer) { const EventDescription* Desc(producer->getProducerType().findEventDescription("Update")); if(_UpdateEventConnection.connected()) { _UpdateEventConnection.disconnect(); } _UpdateEventConnection = connectToEvent(Desc, producer); if(getParents().size() > 0) { Matrix wm; dynamic_cast<Node*>(_mfParents[0])->getToWorld(wm); wm.mult(Pnt3f(0.0f,0.0f,0.0f),_PreviousPosition); } }
/****************************************************************************** Function evolutionStep - controls one evolution step, is called for each generation, manages the deffirences between CGP and coevolution Takes parameters: @input - pointer to an array of all training vectors @geneticP - pointer to a struct of all CGP params @geneticArray - pointer to a vector of whole population @functions - pointer to an array of available functions @test - pointer to the test - in variant without coevolution is NULL ******************************************************************************/ void evolutionStep(TData* input, TCgpProperties* geneticP, vector<TIndividual>* geneticArray, TFuncAvailable* functions, TTest* test){ #ifdef COEVOLUTION //copy test vector from shared memory TCoevIndividual* testVect = NULL; testVect = (TCoevIndividual*)malloc(sizeof(struct test)); pthread_mutex_lock(&test->test_sem); testVect->value = new vector<int>(*test->test.value); pthread_mutex_unlock(&test->test_sem); #endif getActiveNodes(geneticArray, geneticP); for(int ind = 0; ind < geneticP->individCount; ind++){ resetFitness(&geneticArray->at(ind)); #ifdef COEVOLUTION for(int i = 0; i < geneticP->testSize; i++){ getValue(&geneticArray->at(ind), geneticP, input->data[testVect->value->at(i)]); getFitness(&geneticArray->at(ind), geneticP, input->data[testVect->value->at(i)]); }//for all tests #else for(int i = 0; i < input->dataCount; i++){ getValue(&geneticArray->at(ind), geneticP, input->data[i]); getFitness(&geneticArray->at(ind), geneticP, input->data[i]); }//for all inputs #endif }//for all individuals #ifdef COEVOLUTION //tidy up the test vector delete(testVect->value); free(testVect); #endif getParents(geneticArray, geneticP); createChildren(geneticArray, geneticP, functions); }
/* returns a list of paths to the root * for a given handle */ void GeneOntology::getPathsFromRoot(GeneOntologyIdentifier handle,vector<vector<GeneOntologyIdentifier> >*paths){ // if there are no parents, //getParents/ simply return the simple path if(!hasParent(handle)){ vector<GeneOntologyIdentifier> path; path.push_back(handle); paths->push_back(path); return; } // get the parents vector<GeneOntologyIdentifier> parents; getParents(handle,&parents); // the paths are: // for each parent: // path to the root of the parent (includes parent) + handle for(int i=0;i<(int)parents.size();i++){ GeneOntologyIdentifier parentHandle=parents[i]; vector<vector<GeneOntologyIdentifier> > parentPaths; getPathsFromRoot(parentHandle,&parentPaths); // for each of these paths, // add the current to the path for(int j=0;j<(int)parentPaths.size();j++){ parentPaths[j].push_back(handle); // add this path to the final list. paths->push_back(parentPaths[j]); } } }
/// Generic object access, possibly searching up or down from the current context /// /// Note that the template wrapper method should generally be used to have the correct return type, void* DAGNode::getObject(const sofa::core::objectmodel::ClassInfo& class_info, const sofa::core::objectmodel::TagSet& tags, SearchDirection dir) const { if (dir == SearchRoot) { if (!getParents().empty()) return getRootContext()->getObject(class_info, tags, dir); else dir = SearchDown; // we are the root, search down from here. } void *result = NULL; #ifdef DEBUG_GETOBJECT std::string cname = class_info.name(); if (cname != std::string("N4sofa4core6ShaderE")) std::cout << "DAGNode: search for object of type " << class_info.name() << std::endl; std::string gname = "N4sofa9component8topology32TetrahedronSetGeometryAlgorithms"; bool isg = cname.length() >= gname.length() && std::string(cname, 0, gname.length()) == gname; #endif if (dir != SearchParents) for (ObjectIterator it = this->object.begin(); it != this->object.end(); ++it) { core::objectmodel::BaseObject* obj = it->get(); if (tags.empty() || (obj)->getTags().includes(tags)) { #ifdef DEBUG_GETOBJECT if (isg) std::cout << "DAGNode: testing object " << (obj)->getName() << " of type " << (obj)->getClassName() << std::endl; #endif result = class_info.dynamicCast(obj); if (result != NULL) { #ifdef DEBUG_GETOBJECT std::cout << "DAGNode: found object " << (obj)->getName() << " of type " << (obj)->getClassName() << std::endl; #endif break; } } } if (result == NULL) { switch(dir) { case Local: break; case SearchParents: case SearchUp: { Parents parents = getParents(); if (!parents.empty()) for (Parents::iterator it = parents.begin(); it!=parents.end() && !result; it++) result = dynamic_cast<Node*>(*it)->getObject(class_info, tags, SearchUp); } break; case SearchDown: for(ChildIterator it = child.begin(); it != child.end(); ++it) { result = (*it)->getObject(class_info, tags, dir); if (result != NULL) break; } break; case SearchRoot: std::cerr << "SearchRoot SHOULD NOT BE POSSIBLE HERE!\n"; break; } } return result; }
/// Generic object access, given a path from the current context /// /// Note that the template wrapper method should generally be used to have the correct return type, void* DAGNode::getObject(const sofa::core::objectmodel::ClassInfo& class_info, const std::string& path) const { if (path.empty()) { // local object return Node::getObject(class_info, Local); } else if (path[0] == '/') { // absolute path; let's start from root Parents parents = getParents(); if (parents.empty()) return getObject(class_info,std::string(path,1)); else return getRootContext()->getObject(class_info,path); } else if (std::string(path,0,2)==std::string("./")) { std::string newpath = std::string(path, 2); while (!newpath.empty() && path[0] == '/') newpath.erase(0); return getObject(class_info,newpath); } else if (std::string(path,0,3)==std::string("../")) { // tricky case: // let's test EACH parent and return the first object found (if any) std::string newpath = std::string(path, 3); while (!newpath.empty() && path[0] == '/') newpath.erase(0); Parents parents = getParents(); if (!parents.empty()) { for (Parents::iterator it = parents.begin(); it!=parents.end(); it++) { void* obj = dynamic_cast<Node*>(*it)->getObject(class_info,newpath); if (obj) return obj; } return 0; // not found in any parent node at all } else return getObject(class_info,newpath); } else { std::string::size_type pend = path.find('/'); if (pend == std::string::npos) pend = path.length(); std::string name ( path, 0, pend ); Node* child = getChild(name); if (child) { while (pend < path.length() && path[pend] == '/') ++pend; return child->getObject(class_info, std::string(path, pend)); } else if (pend < path.length()) { //std::cerr << "ERROR: child node "<<name<<" not found in "<<getPathName()<<std::endl; return NULL; } else { core::objectmodel::BaseObject* obj = simulation::Node::getObject(name); if (obj == NULL) { //std::cerr << "ERROR: object "<<name<<" not found in "<<getPathName()<<std::endl; return NULL; } else { void* result = class_info.dynamicCast(obj); if (result == NULL) { std::cerr << "ERROR: object "<<name<<" in "<<getPathName()<<" does not implement class "<<class_info.name()<<std::endl; return NULL; } else { return result; } } } } }
/// Test if the given node is a parent of this node. bool DAGNode::hasParent(const BaseNode* node) const { Parents p = getParents(); return (p.end() != std::find(p.begin(), p.end(), node)); }
/// TODO: add trivial marker for tagtypes bool isTrivial(const TypePtr& type) { auto ttype = type.isa<TagTypePtr>(); if(!ttype) { if (core::lang::isArray(type)) { // in case of an array, check the enclosed type for triviality return isTrivial(core::lang::ArrayType(type).getElementType()); } // non-tag-type & non-array types are always trivial return true; } auto record = ttype->getRecord(); IRBuilder builder(type->getNodeManager()); auto containsCtor = [&](const LambdaExprPtr& ctor)->bool { return any(record->getConstructors(), [&](const ExpressionPtr& cur) { return *builder.normalize(cur) == *builder.normalize(ctor); }); }; auto containsMemberFunction = [&](const MemberFunctionPtr& member)->bool { return any(record->getMemberFunctions(), [&](const MemberFunctionPtr& cur) { return *builder.normalize(cur) == *builder.normalize(member); }); }; auto thisType = builder.refType(builder.tagTypeReference(record->getName())); ParentsPtr parents = (record.isa<StructPtr>()) ? record.as<StructPtr>()->getParents() : builder.parents(); // check for trivial constructors bool trivialDefaultConstructor = containsCtor(builder.getDefaultConstructor(thisType, parents, record->getFields())); if (!trivialDefaultConstructor) return false; bool trivialCopyConstructor = containsCtor(builder.getDefaultCopyConstructor(thisType, parents, record->getFields())); if (!trivialCopyConstructor) return false; bool trivialMoveConstructor = containsCtor(builder.getDefaultMoveConstructor(thisType, parents, record->getFields())); if (!trivialMoveConstructor) return false; // check for trivial copy and move assignments bool trivialCopyAssignment = containsMemberFunction(builder.getDefaultCopyAssignOperator(thisType, parents, record->getFields())); if (!trivialCopyAssignment) return false; bool trivialMoveAssignment = containsMemberFunction(builder.getDefaultMoveAssignOperator(thisType, parents, record->getFields())); if (!trivialMoveAssignment) return false; // check for trivial, non-virtual destructor if(record->getDestructor().as<LambdaExprPtr>()->getBody().size() != 0 || record->getDestructorVirtual().getValue()) return false; // check for virtual member functions for(auto memFun : record->getMemberFunctions()) { if(memFun->getVirtualFlag().getValue()) return false; } if(!record->getPureVirtualMemberFunctions().empty()) return false; // check for virtual & non-trivial base classes if(ttype->isStruct()) { auto stype = ttype->getStruct(); for(auto par : stype->getParents()) { if(par->getVirtual().getValue()) return false; // if our direct base class is non-trivial, we cannot be trivial per-se if(!isTrivial(par->getType())) return false; } } // check that all non-static members are trivial for(auto field : record->getFields()) { auto fieldType = field->getType(); if(!isTrivial(fieldType)) return false; //check cpp_ref field types if(analysis::isRefType(fieldType) && lang::isCppReference(fieldType)) { //TODO this is an over approximation which has to be refined return false; } } return true; }
std::vector<UInt32> ParticleSystemCore::intersectLine(const Line& Ray, Real32 IntersectionDistance) const { return getSystem()->intersect(Ray,IntersectionDistance,-1, getParents().front()); }
void Manipulator::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details ) { Inherited::changed(whichField, origin, details); if ( (whichField & TargetFieldMask) == TargetFieldMask ) { updateHandleTransform(); } if ( (whichField & ParentsFieldMask) == ParentsFieldMask ) { Node *parent; if ( !getParents().empty() ) { //std::cout << "parent size= " << parents.getSize() << std::endl; parent = dynamic_cast<Node *>(getParents()[0]); // Dangerous! multiple parents? } else { parent = NULL; } //std::cout << " Parent= " << parent << std::endl; //std::cout << " activeParent= " << _activeParent << std::endl; if ( parent != _activeParent ) { if ( NULL != parent ) { // remove old childs from a loaded osb file. while(parent->getNChildren() > 0) { parent->subChild(parent->getChild(0)); } addHandleGeo(parent); } if ( _activeParent != NULL ) { subHandleGeo(_activeParent); } _activeParent = parent; } } if ( (whichField & EnablePivotFieldMask) == EnablePivotFieldMask ) { if (getPivotNode() != 0) // Some manips don't support a pivot and don't create a node for it { if (!getEnablePivot()) { getPivotNode()->setTravMask(0x0); } else { getPivotNode()->setTravMask(0xffffffff); } } } }