Example #1
0
void Node::convertToPutByOffsetHint()
{
    ASSERT(m_op == PutByOffset);
    convertToPutHint(
        PromotedLocationDescriptor(NamedPropertyPLoc, storageAccessData().identifierNumber),
        child2().node(), child3().node());
}
Example #2
0
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();
}
Example #3
0
int foo2()
{
  int a = 0;

  int ii;
  for (ii = 0; ii < 2; ++ii) {
    a += child3();
    a += child4();
    a += child5();
  }
  return a;
}
Example #4
0
int foo1()
{
  int a = 0;

  int ii;
  for (ii = 0; ii < 3; ++ii) {
    a += child1();
    a += child2();
    a += child3();
  }
  return a;
}
Example #5
0
void
child2(void)
{
    struct sigaction sa;

    close(p21[0]);
    setpgid(0, 0);
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);
    sa.sa_handler = handler;
    if (sigaction(SIGHUP, &sa, NULL) < 0) {
	wrsync(p21[1], 1, "[00] child2->child1");
	perror("child2: sigaction");
	fflush(stdout);
	exit(1);
    }
    printf("child2: set up signal handler\n");
    testctty("child2: after start");
    testwr(slavefd, "child2: after start");
    wrsync(p21[1], 0, "[00] child2->child1");
    rdsync(pp1[0], NULL, "[01] parent->child2");

    testctty("child2: after child1 exit");
    testex(slavefd, "child2: after child1 exit");
    testwr(slavefd, "child2: after child1 exit");
    close(slavefd);
    testctty("child2: after close of slavefd");
    slavefd = open(slave, O_RDWR|O_NONBLOCK);
    if (slavefd < 0) {
	wrsync(p1p[1], 1, "[02] child2->parent");
	printf("child2: failed reopen of slave\n");
	fflush(stdout);
	exit(1);
    }
#ifdef TIOCSCTTY
    ioctl(slavefd, TIOCSCTTY, 0);
#endif
    printf("child2: reopened slave\n");
    testctty("child2: after reopen of slave");
    fflush(stdout);
    close(slavefd);
    pid3 = fork();
    if (!pid3) {
	child3();
    } else if (pid3 == -1) {
	wrsync(p1p[1], 1, "[02] child2->parent");
	perror("child2: fork of child3");
	exit(1);
    }
    printf("child2: forked child3=%ld\n", (long)pid3);
    fflush(stdout);
    exit(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;
}
Example #7
0
void main()
{
	std::cout<< "\n PNode<T> class demonstration";
	std::cout<< "\n ============================\n";
	//initialize
	PNode<std::string > root("root");
	PNode<std::string > child1("child1");
	PNode<std::string > child2("child2");
	PNode<std::string > grandchild11("grandchild11");
	PNode<std::string > grandchild21("grandchild21");
	PNode<std::string > grandchild22("grandchild22");
	PNode<std::string > grandgrandchild211("grandgrandchild211");
	PNode<std::string > child3("child3");
	
	//test adding
	child1.add(&grandchild11);
	grandchild21.add(&grandgrandchild211);
	child2.add(&grandchild21);
	child2.add(&grandchild22);
	root.add(&child1);
	root.add(&child2);
	root.add(&child3);
	WalkTree(&root);
	
	//test removing, mark operation
	std::cout<<"\n\n removing first child";
	root.remove(&child1);
	std::cout<<"\n unmarked all nodes";
	root.setMarkState(true);
	child1.setMarkState(true);
	grandchild11.setMarkState(true);
	child2.setMarkState(true);
	grandchild21.setMarkState(true);
	grandchild22.setMarkState(true);
	grandgrandchild211.setMarkState(true);
	child3.setMarkState(true);

	//show the tree
	WalkTree(&root);
	std::cout<<"\n\n";
	
	std::cout<<"===========================XMLValues Test==================================="<<std::endl;
	XMLValue xmlv(XMLValue::TAG, "MyTag");
	Attribute attr1("ATTR1","1");
	Attribute attr2("ATTR2","2");
	Attribute attr3("ATTR3","3");
	xmlv.AddAttr("ATTR1","1");
	xmlv.AddAttr("ATTR2","2");
	xmlv.AddAttr("ATTR3","3");

	//test == operator
	std::cout<<"Attribute Compare:\n"<<"attr1 == attr1: "<< (attr1 == attr1) <<"; attr2 == attr1: "<< (attr2 == attr1)<<std::endl;

	//test search and find attributes
	for(size_t i=0; i< xmlv.attributes().size();++i)
		std::cout<<xmlv.attributes().at(i).AttrName.c_str()<<"  "<<xmlv.attributes().at(i).AttrValue.c_str()  <<std::endl;
	std::cout<<"Find ATTR2's index: "<<xmlv.Find("ATTR2","2")<<std::endl;
	std::cout<<"Find ATTR4's index: "<<xmlv.Find("ATTR4","4")<<std::endl;
	//test removing attributes
	xmlv.RemoveAttr("ATTR2","2");
	std::cout<<"====================ATTR2 Removed==========================\n";
	for(size_t i=0; i< xmlv.attributes().size();++i)
		std::cout<<xmlv.attributes().at(i).AttrName.c_str()<<"  "<<xmlv.attributes().at(i).AttrValue.c_str()  <<std::endl;
	std::cout<<"=================Nodes with XMLValues======================"<<std::endl;
	PNode<XMLValue> xmlroot(xmlv);
	PNode<XMLValue> xmlcld1(XMLValue(XMLValue::TAG,"xmlChild1"));
	PNode<XMLValue> xmlcld2(XMLValue(XMLValue::TAG,"xmlChild2"));
	xmlroot.add(&xmlcld1);
	xmlroot.add(&xmlcld2);
	PNode<XMLValue> *pTemp;

	//test searching through the tree
	while (pTemp = xmlroot.nextUnmarkedChild())
	{
		std::cout<<"The child of root: "<<pTemp->value().TagName()<<std::endl; 
		pTemp->setMarkState(true);
	}

	std::cout<<"=================Children of Nodes======================"<<std::endl;
	for (size_t i = 0; i < xmlroot.getChildren().size(); i++)
		std::cout<<"a Child of ROOT: "<<xmlroot.getChildren()[i].TagName()<<std::endl;
	::system("pause");
}
/**
 * @brief Test if getting random solution works
 */
void TestClusterwiseCrossoverEngine::testCrossover(void)
{

    IntegerVectorEncoding p1(g);
    IntegerVectorEncoding p2(g);
    IntegerVectorEncoding child1(g), child2(g);
    IntegerVectorEncoding child3(g), child4(g);

    // Initialize first parent
    p1.addToCluster(0, 0);
    p1.addToCluster(1, 1);
    p1.addToCluster(2, 2);
    p1.addToCluster(3, 3);
    p1.addToCluster(4, 1);
    p1.addToCluster(5, 0);
    // Initialize second parent
    p2.addToCluster(0, 4);
    p2.addToCluster(1, 5);
    p2.addToCluster(2, 5);
    p2.addToCluster(3, 4);
    p2.addToCluster(4, 6);
    p2.addToCluster(5, 5);

    p1.normalize();
    p2.normalize();


    IntegerVectorEncoding case1_1(g), case2_1(g), case3_1(g);
    IntegerVectorEncoding case1_2(g), case2_2(g), case3_2(g);
    bool found1, found2, found3, foundOther;
    found1 = found2 = found3 = foundOther = false;

    //create all possible cases
    case1_1.addToCluster(0, 0);
    case1_1.addToCluster(1, 1);
    case1_1.addToCluster(2, 2);
    case1_1.addToCluster(3, 0);
    case1_1.addToCluster(4, 1);
    case1_1.addToCluster(5, 1);
    case1_2.addToCluster(0, 0);
    case1_2.addToCluster(1, 1);
    case1_2.addToCluster(2, 1);
    case1_2.addToCluster(3, 2);
    case1_2.addToCluster(4, 3);
    case1_2.addToCluster(5, 0);

    case2_1.addToCluster(0, 0);
    case2_1.addToCluster(1, 1);
    case2_1.addToCluster(2, 1);
    case2_1.addToCluster(3, 2);
    case2_1.addToCluster(4, 3);
    case2_1.addToCluster(5, 0);
    case2_2.addToCluster(0, 0);
    case2_2.addToCluster(1, 1);
    case2_2.addToCluster(2, 2);
    case2_2.addToCluster(3, 0);
    case2_2.addToCluster(4, 1);
    case2_2.addToCluster(5, 1);

    case3_1.addToCluster(0, 0);
    case3_1.addToCluster(1, 1);
    case3_1.addToCluster(2, 1);
    case3_1.addToCluster(3, 2);
    case3_1.addToCluster(4, 3);
    case3_1.addToCluster(5, 1);
    case3_2.addToCluster(0, 0);
    case3_2.addToCluster(1, 1);
    case3_2.addToCluster(2, 2);
    case3_2.addToCluster(3, 0);
    case3_2.addToCluster(4, 1);
    case3_2.addToCluster(5, 0);

    // Crossover 1000 times, make sure all cases appear
    for (int i = 0; i < 1000; i++)
    {
        testObj->crossover(p1, p2, child1, child2);
        if (compareClusters(child1, child2, case1_1, case1_2))
        {
            found1 = true;
        } 
        else if (compareClusters(child1, child2, case2_1, case2_2))
        {
            found2 = true;
        }
        else if (compareClusters(child1, child2, case3_1, case3_2))
        {
            found3 = true;
        }
        else
        {
            foundOther = true;
            break;
        }
        CPPUNIT_ASSERT(6 == child1.getEncoding().size());
        CPPUNIT_ASSERT(6 >= child1.getClusterCount());

        CPPUNIT_ASSERT(6 == child2.getEncoding().size());
        CPPUNIT_ASSERT(6 >= child2.getClusterCount());

    }
    //test makes sure that every case appeared at least once
    CPPUNIT_ASSERT(found1);
    CPPUNIT_ASSERT(found2);
    CPPUNIT_ASSERT(found3);
    CPPUNIT_ASSERT(!foundOther);


}
Example #9
0
void DirectedGraph::addVertex(int pIdx) {
#ifdef DIRECTEDGRAPH_CHECK
	cout << "DAG.addVertex(" << pIdx << ")" << endl;
#endif

	// Seek the lowest DAGNode which contains the point.
	vector<shared_ptr<DAGNode>> leaves = DAGNode::leafNodesContainingPoint(root_, pointSet_, pIdx);

#ifdef DIRECTEDGRAPH_CHECK
	cout << "DAG.addVertex, numLeafNodes containing pt: " << leaves.size() << endl;
	assert(leaves.size() == 1 || leaves.size() == 2);
#endif

	if (leaves.size() == 1) {
		// New point fits cleanly within another triangle,
		// split the triangle into three.

		shared_ptr<DAGNode> node = leaves[0];  // IJK

		TriRecord parentTri = node->tri_;
		int parentIdx1, parentIdx2, parentIdx3;
		parentTri.get(parentIdx1, parentIdx2, parentIdx3);

		// Construct 3 TriRecords, one for each child triangle
		// ASSUMPTION that points for TriRecord are CCW
		shared_ptr<DAGNode> child1(new DAGNode(TriRecord(pIdx, parentIdx1, parentIdx2)));  // RIJ
		shared_ptr<DAGNode> child2(new DAGNode(TriRecord(pIdx, parentIdx2, parentIdx3)));  // RJK
		shared_ptr<DAGNode> child3(new DAGNode(TriRecord(pIdx, parentIdx3, parentIdx1)));  // RKI
		node->children_.push_back(child1);
		node->children_.push_back(child2);
		node->children_.push_back(child3);

		// Add to instance's list of dagNodes
		dagNodes_.push_back(child1);
		dagNodes_.push_back(child2);
		dagNodes_.push_back(child3);

		// Update triangulation
		addVertexInTri(trist_,
		               node->fIndex_,
		               child1,
		               child2,
		               child3);

#ifdef DIRECTEDGRAPH_CHECK
		checkConsistent();
#endif

		// legalizeEdge[ADDVERT(A)]

		/// edges 12, 13, 23 are the "link" of the inserted point.
		/// So, here we 'flip edges' until things are locally delaunday.
		legalizeEdge(pIdx, parentIdx1, parentIdx2);
		legalizeEdge(pIdx, parentIdx2, parentIdx3);
		legalizeEdge(pIdx, parentIdx3, parentIdx1);
	} else if (leaves.size() == 2) {
		// New point on the edge of other triangles,
		// split the two triangles to get four triangles total.

		// new point R lies on edge IJ
		shared_ptr<DAGNode> nodeIJK = leaves[0];
		shared_ptr<DAGNode> nodeILJ = leaves[1];

		// need to sort out the point indices
		int iIdx, jIdx, kIdx, lIdx;
		getIndicesKIJL(nodeIJK->tri_, nodeILJ->tri_, kIdx, iIdx, jIdx, lIdx);

		// Create triangles RJK, RKI, RIL, RLJ
		shared_ptr<DAGNode> nodeRJK(new DAGNode(TriRecord(pIdx, jIdx, kIdx)));
		shared_ptr<DAGNode> nodeRKI(new DAGNode(TriRecord(pIdx, kIdx, iIdx)));
		shared_ptr<DAGNode> nodeRIL(new DAGNode(TriRecord(pIdx, iIdx, lIdx)));
		shared_ptr<DAGNode> nodeRLJ(new DAGNode(TriRecord(pIdx, lIdx, jIdx)));

		nodeIJK->children_.push_back(nodeRJK);
		nodeIJK->children_.push_back(nodeRKI);
		nodeILJ->children_.push_back(nodeRIL);
		nodeILJ->children_.push_back(nodeRLJ);

		dagNodes_.push_back(nodeRJK);
		dagNodes_.push_back(nodeRKI);
		dagNodes_.push_back(nodeRIL);
		dagNodes_.push_back(nodeRLJ);

		// Update triangulation
		addVertexOnEdge(trist_,
		                nodeIJK->fIndex_,
		                nodeILJ->fIndex_,
		                nodeRJK,
		                nodeRKI,
		                nodeRIL,
		                nodeRLJ);

#ifdef DIRECTEDGRAPH_CHECK
		checkConsistent();
#endif

		// legalizeEdge[ADDVERT(B)]
		// legalize il, lj, jk, ki
		legalizeEdge(pIdx, jIdx, kIdx);
		legalizeEdge(pIdx, kIdx, iIdx);
		legalizeEdge(pIdx, iIdx, lIdx);
		legalizeEdge(pIdx, lIdx, jIdx);
	}
}