TEST(EDGE, Hash) { std::vector<ade::DimT> slist = {94, 78, 70, 82, 62, 29, 38}; ade::Opcode mock_code{"MOCK_EDGE", 435}; ade::Opcode mock_code2{"MOCK_EDGE2", 436}; ade::Shape shape(slist); ade::TensptrT parent(new MockTensor(shape)); ade::TensptrT parent2(new MockTensor(shape)); ade::TensptrT child(new MockTensor(shape)); ade::TensptrT child2(new MockTensor(shape)); ade::Edge expired_edge; ade::Edge expired_edge2 = { ade::TensrefT(), ade::TensrefT(), ade::Opcode{"SOMETHING", 123}, }; ASSERT_TRUE(expired_edge.expired()); ASSERT_TRUE(expired_edge2.expired()); std::unordered_set<ade::Edge,ade::EdgeHash> edges = { ade::Edge{parent, child, mock_code}, ade::Edge{parent2, child, mock_code}, ade::Edge{parent, child2, mock_code}, ade::Edge{parent2, child2, mock_code}, ade::Edge{parent, child, mock_code2}, ade::Edge{parent, child, mock_code}, expired_edge, expired_edge2, }; EXPECT_EQ(6, edges.size()); }
TEST(EDGE, Equality) { std::vector<ade::DimT> slist = {94, 78, 70, 82, 62, 29, 38}; ade::Opcode mock_code{"MOCK_EDGE", 435}; ade::Opcode mock_code2{"MOCK_EDGE2", 436}; ade::Shape shape(slist); ade::TensptrT parent(new MockTensor(shape)); ade::TensptrT parent2(new MockTensor(shape)); ade::TensptrT child(new MockTensor(shape)); ade::TensptrT child2(new MockTensor(shape)); ade::Edge orig_edge{parent, child, mock_code}; ade::Edge edge{parent2, child, mock_code}; ade::Edge edge2{parent, child2, mock_code}; ade::Edge edge3{parent2, child2, mock_code}; ade::Edge edge4{parent, child, mock_code2}; ade::Edge expired_edge; ASSERT_TRUE(expired_edge.expired()); ade::Edge edge_eq{parent, child, mock_code}; EXPECT_FALSE(orig_edge == edge); EXPECT_FALSE(orig_edge == edge2); EXPECT_FALSE(orig_edge == edge3); EXPECT_FALSE(orig_edge == edge4); EXPECT_FALSE(orig_edge == expired_edge); EXPECT_TRUE(orig_edge == edge_eq); }
void MCObjectTest::testChildTranslate() { MCWorld world; world.setDimensions(0, 1024, 0, 768, 0, 100, 1); MCObject root("root"); MCObjectPtr child1(new MCObject("child1")); MCObjectPtr child2(new MCObject("child2")); root.addChildObject(child1, MCVector3dF(1, 1, 1)); root.addChildObject(child2, MCVector3dF(2, 2, 2)); root.addToWorld(); // Root at (0, 0, 0) vector3dCompare(root.location(), MCVector3dF(0, 0, 0)); vector3dCompare(child1->location(), MCVector3dF(0, 0, 0)); vector3dCompare(child2->location(), MCVector3dF(0, 0, 0)); // Now move the root root.translate(MCVector3dF(1, 2, 3)); // Translate children only when root translates vector3dCompare(root.location(), MCVector3dF(1, 2, 3)); vector3dCompare(child1->location(), MCVector3dF(2, 3, 4)); vector3dCompare(child2->location(), MCVector3dF(3, 4, 5)); }
void MCObjectTest::testAddChildren() { MCWorld world; MCObject root("root"); MCObjectPtr child1(new MCObject("child1")); MCObjectPtr child2(new MCObject("child2")); QVERIFY(&root.parent() == &root); QVERIFY(&child1->parent() == child1.get()); QVERIFY(&child2->parent() == child2.get()); root.addChildObject(child1); root.addChildObject(child2); QVERIFY(&child1->parent() == &root); QVERIFY(&child2->parent() == &root); QVERIFY(root.index() == -1); QVERIFY(child1->index() == -1); QVERIFY(child2->index() == -1); world.addObject(root); // Currently world doesn't add children QVERIFY(root.index() >= 0); QVERIFY(child1->index() == -1); QVERIFY(child2->index() == -1); root.addToWorld(); // Adding via object adds also children QVERIFY(root.index() >= 0); QVERIFY(child1->index() >= 0); QVERIFY(child2->index() >= 0); }
int triple (int arg) { int read_arg (void) { return arg; } int parent (int nested_arg) { int child1 (void) { return parent (zero (5)); } int child2 (void) { return nested_arg + read_arg (); } return (nested_arg == 0 ? 0 : child1 ()) + child2 (); }
void reheap_down(unsigned index) { unsigned child1_index = child1(index); unsigned child2_index = child2(index); if( child1_index != 0 ) { if( child2_index != 0 ) { if( !(*heap[index] < *heap[child1_index]) || !(*heap[index] < *heap[child2_index]) ) { if( *heap[child1_index] < *heap[child2_index] ) { swap(child1_index, index); reheap_down(child1_index); } else { swap(child2_index, index); reheap_down(child2_index); } } } else { if( *heap[child1_index] < *heap[index] ) { swap(index, child1_index); reheap_down(child1_index); } } } }
int main (int argc, char *argv[]) { shared_t *shared; int fds[2], size, prot, flags; sem_t semp; sem_init(&semp, 1, 0); assert(pipe(fds) == 0); size = sizeof(struct shared *); prot = PROT_READ | PROT_WRITE; flags = MAP_SHARED | MAP_ANONYMOUS; shared = (shared_t *)mmap(NULL, size, prot, flags, -1, 0); shared->semp = semp; switch (fork()) { case -1: exit(EXIT_FAILURE); case 0: child1(shared, fds); exit(EXIT_SUCCESS); } switch (fork()) { case -1: exit(EXIT_FAILURE); case 0: child2(shared, fds); exit(EXIT_SUCCESS); } parent(shared, fds); return 0; }
void child1(void) { pid_parent=getppid(); pid_t pid=fork(); if (pid==0) { child2(); } else { if (pid>0) { pid_child2=pid; if (signal(SIGUSR1, sig_child1)==SIG_ERR) { fprintf(stderr, "Can't catch SIGUSR1."); } if (signal(SIGUSR2, sig_child1)==SIG_ERR) { fprintf(stderr, "Can't catch SIGUSR2."); } for (;;) { printf("Child1: running waiting for signal\n"); sleep(3); sigsuspend(&pOldMask); sigsuspend(&cOldMask); } } else { fprintf(stderr, "Can't create new child."); } } sigprocmask(SIG_UNBLOCK, &cMask, NULL); return; }
void Node::convertToPutByOffsetHint() { ASSERT(m_op == PutByOffset); convertToPutHint( PromotedLocationDescriptor(NamedPropertyPLoc, storageAccessData().identifierNumber), child2().node(), child3().node()); }
void Node::convertToPutClosureVarHint() { ASSERT(m_op == PutClosureVar); convertToPutHint( PromotedLocationDescriptor(ClosureVarPLoc, scopeOffset().offset()), child1().node(), child2().node()); }
void init_fn() { int j; for (j = 0; j < 2; j++) { switch(sched_fork()) { case -1: fprintf(stderr, "fork error!\n"); exit(1); case 0: if (!j) { sched_nice(-20); child1(); } else { sched_nice(20); child2(); } exit(0); } } //sched_nice(5); parent(); exit(0); }
void GA::CycleCrossover(Candidate p1, Candidate p2){ int startingGene = std::rand() % p1.getCandidate().size(); int currentGene = -1; std::vector<City> child1(p1.getCandidate()); std::vector<City> child2(p2.getCandidate()); CycleCrossover_MixGenes(child1,child2,currentGene,startingGene); //newPopulation.push_back(p1); //newPopulation.push_back(p2); Candidate newChild1 = Candidate(child1,distances); Candidate newChild2 = Candidate(child2,distances); if(!newChild1.isUnique() || !newChild2.isUnique()) throw new std::logic_error("Invalid child sequence"); newPopulation.push_back(newChild1); newPopulation.push_back(newChild2); //std::cout << "P1 " << p1 << "\n"; //std::cout << "P2 " << p2 << "\n"; //std::cout << "C1 " << newChild1 << "\n"; //std::cout << "C2 " << newChild2 << "\n"; //if(newChild1.getFitness() > p1.getFitness()) }
void nextNode(vector<TreeNode*>& s, const T& child1, const U& child2) { if (!s.empty()) { if (child2(s)) { s.emplace_back(child2(s)); while (child1(s)) { s.emplace_back(child1(s)); } } else { auto child = s.back(); s.pop_back(); while (!s.empty() && child == child2(s)) { child = s.back(); s.pop_back(); } } } }
void Node::convertToIdentity() { RELEASE_ASSERT(child1()); RELEASE_ASSERT(!child2()); NodeFlags result = canonicalResultRepresentation(this->result()); setOpAndDefaultFlags(Identity); setResult(result); }
void MCObjectTest::testChildRotate() { MCWorld world; world.setDimensions(0, 1024, 0, 768, 0, 100, 1); MCObject root("root"); MCObjectPtr child1(new MCObject("child1")); MCObjectPtr child2(new MCObject("child2")); float child1Angle = 45; root.addChildObject(child1, MCVector3dF(1, 1, 1), child1Angle); const float child2Angle = 90; root.addChildObject(child2, MCVector3dF(2, 2, 2), 90); root.addToWorld(); // Root at (0, 0, 0) const float rootAngle = 69; root.rotate(rootAngle); // Rotate children only when root rotates QVERIFY(root.angle() == rootAngle); QVERIFY(child1->angle() == child1Angle + rootAngle); QVERIFY(child2->angle() == child2Angle + rootAngle); vector3dCompare(child1->location(), MCVector3dF(MCTrigonom::rotatedVector(MCVector2dF(1.0, 1.0), rootAngle), 1.0f)); vector3dCompare(child2->location(), MCVector3dF(MCTrigonom::rotatedVector(MCVector2dF(2.0, 2.0), rootAngle), 2.0f)); // Now move the root const MCVector3dF rootLocation(3, 4, 5); root.translate(rootLocation); QVERIFY(root.angle() == rootAngle); QVERIFY(child1->angle() == child1Angle + rootAngle); QVERIFY(child2->angle() == child2Angle + rootAngle); vector3dCompare(child1->location(), rootLocation + MCVector3dF(MCTrigonom::rotatedVector(MCVector2dF(1.0, 1.0), rootAngle), 1.0f)); vector3dCompare(child2->location(), rootLocation + MCVector3dF(MCTrigonom::rotatedVector(MCVector2dF(2.0, 2.0), rootAngle), 2.0f)); // Rotate child relatively child1Angle = 47; child1->rotateRelative(child1Angle); root.translate(rootLocation); vector3dCompare(child1->location(), rootLocation + MCVector3dF(MCTrigonom::rotatedVector(MCVector2dF(1.0, 1.0), rootAngle), 1.0f)); QVERIFY(child1->angle() == rootAngle + child1Angle); }
void Node::convertToPutHint(const PromotedLocationDescriptor& descriptor, Node* base, Node* value) { m_op = PutHint; m_opInfo = descriptor.imm1(); m_opInfo2 = descriptor.imm2(); child1() = base->defaultEdge(); child2() = value->defaultEdge(); child3() = Edge(); }
void ElementXMLTest::testBinaryData() { soarxml::ElementXML* pXML1 = createXML1(); soarxml::ElementXML* pXML2 = createXML2(); soarxml::ElementXML* pXML4 = createXML4(); soarxml::ElementXML* pXML5 = createXML5(); pXML4->AddChild( pXML1 ) ; pXML4->AddChild( pXML2 ) ; pXML4->AddChild( pXML5 ) ; char* pStr = pXML4->GenerateXMLString( true ) ; soarxml::ElementXML* pParsedXML = soarxml::ElementXML::ParseXMLFromString( pStr ) ; CPPUNIT_ASSERT( pParsedXML != NULL ) ; CPPUNIT_ASSERT( pParsedXML->GetNumberChildren() == 3 ) ; soarxml::ElementXML child0(NULL) ; soarxml::ElementXML const* pChild0 = &child0 ; CPPUNIT_ASSERT( pParsedXML->GetChild(&child0, 0) ); CPPUNIT_ASSERT( pChild0->GetTagName() != NULL ); CPPUNIT_ASSERT( std::string( pChild0->GetTagName() ) == tag1 ) ; CPPUNIT_ASSERT( pChild0->GetCharacterData() != NULL ); CPPUNIT_ASSERT( std::string( pChild0->GetCharacterData() ) == data1 ) ; CPPUNIT_ASSERT( pChild0->GetNumberAttributes() == 2 ) ; CPPUNIT_ASSERT( pChild0->GetNumberChildren() == 0 ) ; soarxml::ElementXML child1(NULL) ; soarxml::ElementXML const* pChild1 = &child1 ; CPPUNIT_ASSERT( pParsedXML->GetChild(&child1, 1) ) ; CPPUNIT_ASSERT( pChild1->GetTagName() != NULL ); CPPUNIT_ASSERT( std::string( pChild1->GetTagName() ) == tag2 ) ; CPPUNIT_ASSERT( pChild1->GetCharacterData() != NULL ); CPPUNIT_ASSERT( std::string( pChild1->GetCharacterData() ) == data2 ) ; CPPUNIT_ASSERT( pChild0->GetNumberChildren() == 0 ) ; CPPUNIT_ASSERT( pChild1->GetAttribute( att21.c_str() ) != NULL ); CPPUNIT_ASSERT( std::string( pChild1->GetAttribute( att21.c_str() ) ) == val21 ) ; soarxml::ElementXML child2(NULL) ; soarxml::ElementXML const* pChild2 = &child2 ; CPPUNIT_ASSERT( pParsedXML->GetChild(&child2, 2) ); CPPUNIT_ASSERT( pChild2->IsCharacterDataBinary() ) ; const char* pBuffer = pChild2->GetCharacterData() ; int bufferLen = pChild2->GetCharacterDataLength() ; CPPUNIT_ASSERT( bufferLen == BUFFER_LENGTH ) ; CPPUNIT_ASSERT( verifyBuffer( pBuffer ) ) ; soarxml::ElementXML::DeleteString(pStr) ; delete pXML4 ; delete pParsedXML ; }
int foo1() { int a = 0; int ii; for (ii = 0; ii < 3; ++ii) { a += child1(); a += child2(); a += child3(); } return a; }
//! exits before child 2 int child1() { printf("child 1 process group: %ld\n", getpgrp()); pid_t child = fork(); if (child == 0) return child2(); sleep(1); return 1; }
ComponentDescription readComponent(Element &componentElem) { //Check for illegal nodes here Iterator< Node > c; for ( c = c.begin(&componentElem); c != c.end(); c++ ) { if(c->Type() == TiXmlNode::ELEMENT) { string s = c->Value(); if(s != "port" && s != "parameter") { LOG(LFATAL) << "Illegal element in xml file: " << s; throw XmlParsingException("Illegal element in xml file: " + s); } } } ComponentDescription theComponent; //Parse the component type and name theComponent.name = componentElem.GetAttribute("name"); theComponent.type = componentElem.GetAttribute("class"); boost::to_lower(theComponent.name); boost::to_lower(theComponent.type); LOG(LINFO) << "Parsed component: " << theComponent.name; //Parse all the parameters and add to the component description Iterator< Element > child("parameter"); for ( child = child.begin(&componentElem); child != child.end(); child++ ) { ParameterDescription param; param.name = child->GetAttribute("name"); param.value = child->GetAttribute("value"); boost::to_lower(param.name); boost::to_lower(param.value); theComponent.parameters.push_back(param); } //Parse all the ports and add to the component description Iterator< Element > child2("port"); for ( child2 = child2.begin(&componentElem); child2 != child2.end(); child2++ ) { PortDescription port; port.name = child2->GetAttribute("name"); port.type = child2->GetAttribute("class"); boost::to_lower(port.name); boost::to_lower(port.type); theComponent.ports.push_back(port); } return theComponent; }
void child1() { do_hog(unit); pid_t res = fork(); if (res < 0) return; if (res == 0) { child2(); return; } waitpid(res); do_hog(2 * unit); return; }
std::vector < Individual > Individual::cruzaAcentuada (Individual& spouse) { std::vector < Individual > result; std::vector < bool > parent1 = getChromosome(); std::vector < bool > parent2 = spouse.getChromosome(); size_t size = parent1.size(); size_t genNumber = chromosome.size(); std::vector < bool > child1_ch, child2_ch, child1_marks(size, false), child2_marks(size, false); bool cross = false; std::vector <bool>::iterator mark_it = crossPoints.begin(); std::vector <bool>::iterator mark_spouse_it = spouse.crossPoints.begin(); for( size_t i = 0; i < size; i++, mark_it++, mark_spouse_it++ ) { if (*mark_it || *mark_spouse_it) { cross = !cross; } if(!cross) { if(*mark_it) { child2_marks.at(i) = true; } if (*mark_spouse_it) { child1_marks.at(i) = true; } child1_ch.push_back( parent1.at(i) ); child2_ch.push_back( parent2.at(i) ); } else { if(*mark_it) { child1_marks.at(i) = true; } if (*mark_spouse_it) { child2_marks.at(i) = true; } child1_ch.push_back( parent2.at(i) ); child2_ch.push_back( parent1.at(i) ); } } Individual child1 (child1_ch,genNumber); Individual child2 (child2_ch,genNumber); child1.crossPoints = child1_marks; child2.crossPoints = child2_marks; result.push_back( child1 ); result.push_back( child2 ); return result; }
void child1(void) { int status; #if 0 setuid(1); #endif close(pp1[1]); close(p1p[0]); close(masterfd); ptyint_void_association(); slavefd = open(slave, O_RDWR|O_NONBLOCK); if (slavefd < 0) { perror("child1: open slave"); exit(1); } #ifdef TIOCSCTTY ioctl(slavefd, TIOCSCTTY, 0); #endif printf("child1: opened slave\n"); testctty("child1: after slave open"); if (pipe(p21) < 0) { perror("pipe child2->child1"); exit(1); } pid2 = fork(); if (!pid2) { child2(); } else if (pid2 == -1) { perror("child1: fork child2"); exit(1); } close(p21[1]); printf("child1: forked child2=%ld\n", (long)pid2); fflush(stdout); rdsync(p21[0], &status, "[00] child2->child1"); exit(status); }
void readSoftwareRadio(Element &headElem, RadioRepresentation& theRadio) { //Check for illegal nodes here Iterator< Node > c; for ( c = c.begin(&headElem); c != c.end(); c++ ) { if(c->Type() == TiXmlNode::ELEMENT) { string s = c->Value(); if(s != "controller" && s != "engine" && s!= "link") { LOG(LFATAL) << "Illegal element in xml file: " << s; throw XmlParsingException("Illegal element in xml file: " + s); } } } //Parse all the controllers Iterator< Element > child("controller"); for ( child = child.begin(&headElem); child != child.end(); child++ ) { ControllerDescription con = readController(*child); theRadio.addControllerDescription(con); } //Parse all the engines Iterator< Element > child1("engine"); for ( child1 = child1.begin(&headElem); child1 != child1.end(); child1++ ) { EngineDescription eng = readEngine(*child1); theRadio.addEngineDescription(eng); } //Parse all the links Iterator< Element > child2("link"); for ( child2 = child2.begin(&headElem); child2 != child2.end(); child2++ ) { LinkDescription link = readLink(*child2); theRadio.addLinkDescription(link); } }
int main() { int semid; union semun { int val; struct semid_ds *buf; unsigned short *array; } ctl_arg; unsigned short vals[2] = {0, 0}; int child_cnt; if ((semid = semget(IPC_PRIVATE, 2, 0600)) == -1){ perror("main : semget "); exit(EXIT_FAILURE); } ctl_arg.array = vals; if (semctl(semid, 0, SETALL, ctl_arg) == -1){ perror("main : semctl "); exit(EXIT_FAILURE); } if (fork() == 0) { child1(semid); } if (fork() == 0) { child2(semid); } for (child_cnt = 0; child_cnt < 2; ++child_cnt) { wait(NULL); } if (semctl(semid, 0, IPC_RMID, ctl_arg) == -1){ perror("main : semctl "); exit(EXIT_FAILURE); } printf("親プロセス終了\n"); return EXIT_SUCCESS; }
int main() { std::shared_ptr<Node> root(new Node("C:")); std::shared_ptr<Node> child1(new Node("dir1")); std::shared_ptr<Node> child2(new Node("dir2")); root->SetLeft(child1); child1->SetParent(root); root->SetRight(child2); child2->SetParent(root); std::shared_ptr<Node> child11(new Node("dir11")); child1->SetLeft(child11); child11->SetParent(child1); std::cout << "path: " << path(child11) << std::endl; return 0; }
//---------------------------------------- // main //---------------------------------------- int main(int /*argc*/, char** /*argv*/) { PrepareConsoleLogger logger(Poco::Logger::ROOT, Poco::Message::PRIO_INFORMATION); ScopedLogMessage msg("TimedNotificationQueueTest ", "start", "end"); Poco::TimedNotificationQueue queue; Child child1("Child 1", queue, msg); Child child2("Child 2", queue, msg); Child child3("Child 3", queue, msg); Poco::ThreadPool::defaultPool().start(child1); Poco::ThreadPool::defaultPool().start(child2); Poco::ThreadPool::defaultPool().start(child3); int numDequeued = 0; while(numDequeued < Child::NumEnqueued()) { Poco::Notification::Ptr pNf(queue.waitDequeueNotification()); if(pNf) { Child::ChildNotificationPtr pChildNf = pNf.cast<ChildNotification>(); if(pChildNf) { msg.Message(Poco::format(" got child notification #%d from %s (%s)" , pChildNf->data() , pChildNf->name() , pChildNf->datetime())); ++numDequeued; Poco::Thread::sleep(kSleepTime); } } else break; } return 0; }
void MCObjectTest::testRenderLayerRelative() { MCWorld world; world.setDimensions(0, 1024, 0, 768, 0, 100, 1); MCObject root("root"); MCObjectPtr child1(new MCObject("child1")); MCObjectPtr child2(new MCObject("child2")); root.addChildObject(child1); root.addChildObject(child2); root.addToWorld(); QVERIFY(root.renderLayer() == 0); QVERIFY(child1->renderLayer() == 0); QVERIFY(child2->renderLayer() == 0); root.setRenderLayer(2); QVERIFY(root.renderLayer() == 2); QVERIFY(child1->renderLayer() == 2); QVERIFY(child2->renderLayer() == 2); child1->setRenderLayerRelative(1); child2->setRenderLayerRelative(-1); QVERIFY(root.renderLayer() == 2); QVERIFY(child1->renderLayer() == 3); QVERIFY(child2->renderLayer() == 1); root.setRenderLayer(3); QVERIFY(root.renderLayer() == 3); QVERIFY(child1->renderLayer() == 4); QVERIFY(child2->renderLayer() == 2); }
int main(int argc, char* argv[]) { pid_t child1_pid, child2_pid; child1_pid = fork(); if (child1_pid < 0) { return 1; } else if (child1_pid == 0) { child1(); exit(0); } child2_pid = fork(); if (child2_pid < 0) { return 1; } else if (child2_pid == 0) { child2(); exit(0); } setpriority(PRIO_PROCESS, child1_pid, 15); setpriority(PRIO_PROCESS, child2_pid, 16); return 0; }
void MCObjectTest::testCollisionLayer() { MCWorld world; world.setDimensions(0, 1024, 0, 768, 0, 100, 1); MCObject root("root"); MCObjectPtr child1(new MCObject("child1")); MCObjectPtr child2(new MCObject("child2")); root.addChildObject(child1); root.addChildObject(child2); root.addToWorld(); QVERIFY(root.collisionLayer() == 0); QVERIFY(child1->collisionLayer() == 0); QVERIFY(child2->collisionLayer() == 0); root.setCollisionLayer(1); QVERIFY(root.collisionLayer() == 1); QVERIFY(child1->collisionLayer() == 1); QVERIFY(child2->collisionLayer() == 1); }