/** * Makes a stair set, this is 13 steps each at an angle of 3.38 degrees off * each step leads to a platform that is at the same level as that last step * platforms center are at the 90, 180, 270, and 0 degrees of a circle **/ ComplexObject* mkStairSet( float firstHeight, float baseAngle, float xTrans, float zTrans ) { ComplexObject *stairSet = malloc( sizeof( ComplexObject ) ); if( stairSet == NULL ) { perror( "Could not malloc for stairset\n" ); exit( 1 ); } // there are 13 stairs in a stairSet stairSet->numObjects = 14; stairSet->object = malloc( sizeof( Object* ) * 14 ); float currentAngle = baseAngle; float currentHeight = firstHeight; for( int i = 0; i < 13; i++ ) { stairSet->object[i] = makeStep( currentHeight, currentAngle, xTrans, zTrans ); currentHeight += .25; currentAngle -= 4.4; } int diff = ((int) baseAngle) % 90; currentHeight -= .25; currentAngle = baseAngle - diff; float xDisp = 2 * cos( currentAngle * 3.14159 / 180 ); float zDisp = -2 * sin( currentAngle * 3.14159 / 180 ); stairSet->object[13] = mkLanding( currentHeight, currentAngle, xDisp + xTrans, zDisp + zTrans ); return stairSet; }
void MultiDLA::cMultiDLA(CellsField* fld, double targetPorosity, uint32_t initN, uint32_t step, uint32_t hitCnt) { fld->clear(); double currVol = 0.0; double needVol = fld->cellsCnt() * (1 - targetPorosity); bool needHit = (hitCnt != 1); size_t dimensions = MCoord::defDims(); MCoordVec* mapNeigh = createNeighborsMap(dimensions); MCoordVec* mapSteps = createStepMap(dimensions, step); uint32_t currCnt = 0; MCoord currCoord; while (currCnt != initN) { currCoord = freeRandomPntInField(fld); fld->setElement(currCoord); currVol += vAdd(fld, currCoord); ++currCnt; } CellsField* hitField; if (needHit) { hitField = new CellsField(fld->size(), MCoord(), fld->radius() * 2); } while (currVol < needVol) { currCoord = freeRandomPntInField(fld); if (needHit) { hitField->clear(); } while (true) { if (!fld->isSet(currCoord) && cntNeighbors(fld, mapNeigh, currCoord) != 0) { FieldElement newHitCnt = 1; if (needHit) { newHitCnt = hitField->elementVal(currCoord) + 1; hitField->setElementVal(currCoord, newHitCnt); } if (newHitCnt >= hitCnt) { fld->setElement(currCoord); currVol += vAdd(fld, currCoord); ++currCnt; break; } } MCoord tmpCoord = makeStep(currCoord, mapSteps); tmpCoord = toroidizeCoords(tmpCoord, fld->size()); while (fld->isSet(tmpCoord)) { tmpCoord = makeStep(currCoord, mapSteps); tmpCoord = toroidizeCoords(tmpCoord, fld->size()); } currCoord = tmpCoord; } } delete mapNeigh; mapNeigh = nullptr; delete mapSteps; mapSteps = nullptr; if (needHit) { delete hitField; hitField = nullptr; } }
void HCOD::activeSearch( VectorXd & u ) { // if( isDebugOnce ) { sotDebugTrace::openFile(); isDebugOnce = false; } // else { if(sotDEBUGFLOW.outputbuffer.good()) sotDebugTrace::closeFile(); } //if(sotDEBUGFLOW.outputbuffer.good()) { sotDebugTrace::closeFile();sotDebugTrace::openFile(); } sotDEBUGIN(15); /* * foreach stage: stage.initCOD(Ir_init) * u = 0 * u0 = solve * do * tau,cst_ref = max( violation(stages) ) * u += (1-tau)u0 + tau*u1 * if( tau<1 ) * update(cst_ref); break; * * lambda,w = computeLambda * cst_ref,lmin = min( lambda,w ) * if lmin<0 * downdate( cst_ref ) * */ assert(VectorXi::LinSpaced(3,0,2)[0] == 0 && VectorXi::LinSpaced(3,0,2)[1] == 1 && VectorXi::LinSpaced(3,0,2)[2] == 2 && "new version of Eigen might have change the " "order of arguments in LinSpaced, please correct"); /*struct timeval t0,t1,t2;double time1,time2; gettimeofday(&t0,NULL);*/ initialize(); sotDEBUG(5) << "Y= " << (MATLAB)Y.matrixExplicit<< std::endl; Y.computeExplicitly(); // TODO: this should be done automatically on Y size. sotDEBUG(5) << "Y= " << (MATLAB)Y.matrixExplicit<< std::endl; /*gettimeofday(&t1,NULL); time1 = ((t1.tv_sec-t0.tv_sec)+(t1.tv_usec-t0.tv_usec)/1.0e6);*/ int iter = 0; startTime=getCPUtime(); Index stageMinimal = 0; do { iter ++; sotDEBUG(5) << " --- *** \t" << iter << "\t***.---" << std::endl; //if( iter>1 ) { break; } if( sotDEBUG_ENABLE(15) ) show( sotDEBUGFLOW ); assert( testRecomposition(&std::cerr) ); damp(); computeSolution(); assert( testSolution(&std::cerr) ); double tau = computeStepAndUpdate(); if( tau<1 ) { sotDEBUG(5) << "Update done, make step <1." << std::endl; makeStep(tau); } else { sotDEBUG(5) << "No update, make step ==1." << std::endl; makeStep(); for( ;stageMinimal<=(Index)stages.size();++stageMinimal ) { sotDEBUG(5) << "--- Started to examinate stage " << stageMinimal << std::endl; computeLagrangeMultipliers(stageMinimal); if( sotDEBUG_ENABLE(15) ) show( sotDEBUGFLOW ); //assert( testLagrangeMultipliers(stageMinimal,std::cerr) ); if( searchAndDowndate(stageMinimal) ) { sotDEBUG(5) << "Lagrange<0, downdate done." << std::endl; break; } for( Index i=0;i<stageMinimal;++i ) stages[i]->freezeSlacks(false); if( stageMinimal<nbStages() ) stages[stageMinimal]->freezeSlacks(true); } } lastTime=getCPUtime()-startTime; lastNumberIterations=iter; if( lastTime>maxTime ) throw 667; if( iter>maxNumberIterations ) throw 666; } while(stageMinimal<=nbStages()); sotDEBUG(5) << "Lagrange>=0, no downdate, active search completed." << std::endl; /*gettimeofday(&t2,NULL); time2 = ((t2.tv_sec-t1.tv_sec)+(t2.tv_usec-t1.tv_usec)/1.0e6); std::ofstream fup("/tmp/haset.dat",std::ios::app); fup << time1<<"\t"<<time2<<"\t"<<iter<<"\t";*/ u=solution; sotDEBUG(5) << "uf =" << (MATLAB)u << std::endl; sotDEBUGOUT(15); }
void GraphicalEntity::update() { makeStep(); }