本文整理汇总了C++中Physics::calcSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::calcSize方法的具体用法?C++ Physics::calcSize怎么用?C++ Physics::calcSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics::calcSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WWD
//.........这里部分代码省略.........
//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
}
//Show end result if we want to...
Physics* WWDPhysics = new Physics();
//init creature
readDNA(&creatures->at(0).dna,WWDPhysics);
//default glut doesn't return from mainloop
WWDPhysics->calcSize();
WWDPhysics->solveGroundConflicts();
#ifdef _DEBUG
printf("\nPress enter to continue\n");
#endif
getchar();
return glutmain(argc, argv,1024,600,"Walking with dinosaurs",WWDPhysics);
}