当前位置: 首页>>代码示例>>C++>>正文


C++ Physics::runSimulation方法代码示例

本文整理汇总了C++中Physics::runSimulation方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::runSimulation方法的具体用法?C++ Physics::runSimulation怎么用?C++ Physics::runSimulation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Physics的用法示例。


在下文中一共展示了Physics::runSimulation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WWD

int WWD(int argc,char** argv){
	HANDLE *handles =new HANDLE[numCores];

	const int temp[] = {
		//Body
		295,195,95,	//main box: h,w,d
		1,		//1 box attached
		1,/*Joint type*/		50,50,5,/*preXYS*/		50,50,4,/*postXYS*/	45,45,45,/*DofXYZ*/ //Create joint
		295,195,95,	//attached box: h,w,d
		//NN-Effector0-layer 0
		1,	2,10,0,1,100,100,	//2-in-node: f=interpolate, in0=0,in1=1,w0=100,w1=100
		0,	2,0,0,0,0,100,		//2-in-node: f=sum,in0=0,in1=1,w0=0,w1=100 (just sends in1 through unchanged) - No more nodes
		1,0,1,	//NN-Effector: use outputs O0=1,O1=0,O2=1
		0,		//no attached boxes
		//NN-main-layer 0	(sensors not implemented yet)
		1,	0,30,			//constant node 30
		1,	0,62,			//constant node 62
		2,	0,125,			//constant node 125 - change layer
		//NN-main-layer 1
		1,	2,0,0,1,50,23,	//2-in-node: f=sum in0=0 in1=1 w0=50 w1=23
		2,	1,12,2,5,		//1-in node: f=cos in0=2 w0=5 - change layer
		//NN-main-layer 2
		1,	2,1,0,1,1,200,	//2-in node: f=product in0=0 in1=1, w0=1 w1=200
		0,	2,0,0,1,1,1		//2-in node: f=sum in0=0 in1=1, w0=1 w1=1 - No more nodes
	};
	int size = sizeof( temp ) / sizeof ( *temp );
	std::vector<int> ancestor (temp, temp+size);

	std::vector<creature>* creatures = new std::vector<creature>();

	//Creates one ancestor and the rest is mutation of the ancestor
	creatures->push_back(creature());
	creatures->at(0).dna=ancestor;
	creatures->at(0).fitness=0;
	for(int i=1; i<populationSize;i++){
		creatures->push_back(creature());
		creatures->at(i).dna=mutate(ancestor,2);
		creatures->at(i).fitness=0;
	}

	for(int i=0;i<nrOfGenerations;i++){
		//#pragma omp parallel
		{
			//run simulator
			//#pragma omp for schedule(dynamic)
			for(int j =0; j<populationSize; j++){
				//init world
				Physics* WWDPhysics = new Physics();

				//init creature
				readDNA(&creatures->at(j).dna,WWDPhysics);

				//run sim
				WWDPhysics->runSimulation();
				creatures->at(j).fitness = WWDPhysics->getFitness();
				creatures->at(j).treePointer = getMTree(&creatures->at(j).dna);
				delete WWDPhysics;
			}

			/*
			//threads
			for(int j =0; j<numCores; j++){
			handles[j] = (HANDLE)_beginthreadex(0, 0, &threadSim,(void*) j, 0, 0);
			}

			WaitForMultipleObjects(numCores, handles, true,INFINITE);

			for(int j =0; j<numCores; j++){
			CloseHandle(handles[j]);
			} */

			//print all unsorted
			/*for(int j=0;j< (int) worlds.size();j++){
			printf("nr %d %f\n",j,worlds.at(j)->getFitness());
			}*/

			//mutate
			//#pragma omp single nowait
			evolve(creatures); //Evolve cleans up the MTrees so no need for that here
			//print survivors sorted

			//#pragma omp for ordered
			for(int j=0;j< (int) (creatures->size()/5.f);j++){
#ifdef _DEBUG
				printf("nr %d %f\n",j,creatures->at(j).fitness);
#endif
			}
			//#pragma omp for ordered
#ifdef _DEBUG
			printf("round %d \n",i);
#endif
		}
	}

	for (int i = 0; i < (int) creatures->at(0).dna.size(); i++){
#ifdef _DEBUG
		printf("%d,", creatures->at(0).dna.at(i));
#endif
	}

//.........这里部分代码省略.........
开发者ID:kiniry-supervision,项目名称:walking-with-dinosaurs,代码行数:101,代码来源:main.cpp


注:本文中的Physics::runSimulation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。