void FMMMLayout :: call_MULTILEVEL_step_for_subGraph(Graph& G,NodeArray<NodeAttributes>& A,EdgeArray<EdgeAttributes>& E,int comp_index) { mathExtension M; Multilevel Mult; int max_level = 30;//sufficient for all graphs with upto pow(2,30) nodes! Array<Graph*> G_mult_ptr(max_level+1); Array<NodeArray<NodeAttributes>*> A_mult_ptr (max_level+1); Array<EdgeArray<EdgeAttributes>*> E_mult_ptr (max_level+1); Mult.create_multilevel_representations(G,A,E,randSeed(), galaxyChoice(),minGraphSize(), randomTries(),G_mult_ptr,A_mult_ptr, E_mult_ptr,max_level); for(int i = max_level;i >= 0;i--) { if(i == max_level) create_initial_placement(*G_mult_ptr[i],*A_mult_ptr[i]); else { Mult.find_initial_placement_for_level(i,initialPlacementMult(),G_mult_ptr, A_mult_ptr,E_mult_ptr); update_boxlength_and_cornercoordinate(*G_mult_ptr[i],*A_mult_ptr[i]); } call_FORCE_CALCULATION_step(*G_mult_ptr[i],*A_mult_ptr[i],*E_mult_ptr[i], i,max_level); } Mult.delete_multilevel_representations(G_mult_ptr,A_mult_ptr,E_mult_ptr,max_level); }
void fitSimAnneal::init(chi2type chi2f, double* initParams, unsigned int pcount, double* lBounds, double* uBounds) { lowerBounds=lBounds; upperBounds=uBounds; // reset function evaluation and iteration counters chi2EvalCount=0; iterations=0; chi2=chi2f; fitParamCount=pcount; // init random number generator randSeed(); param=(double*)realloc(param, fitParamCount*sizeof(double)); memcpy(param, initParams, fitParamCount*sizeof(double)); x0=(double*)realloc(x0, fitParamCount*sizeof(double)); memcpy(x0, initParams, fitParamCount*sizeof(double)); currentChi2=chi2(x0, fitParamCount); bestChi2=currentChi2; // init step vector v v=(double*)realloc(v, fitParamCount*sizeof(double)); for (unsigned int i=0; i<fitParamCount; i++) { v[i]=fabs(upperBounds[i]-lowerBounds[i])/10.0; } }
//compute the vector sequence of the Torus algorithm void torus(double *u, int nb, int dim, int *prime, int offset, int ismixed, int usetime) { int i, j; unsigned long state; if (!R_FINITE(nb) || !R_FINITE(dim)) error(_("non finite argument")); if(prime == NULL) error(_("internal error in torus function")); //sanity check if(dim > 100000) error(_("Torus algorithm not yet implemented for dimension %d"), dim); //init the seed of Torus algo if(!isInit) randSeed(); //init the state of SF Mersenne Twister algo if(ismixed) SFMT_init_gen_rand(seed); //u_ij is the Torus sequence term //with n = state + i, s = j + 1, p = primeNumber[j] or prime[j] //u is stored column by column if(ismixed) //SF Mersenne-Twister-mixed Torus algo { for(j = 0; j < dim; j++) { for(i = 0; i < nb; i++) { state = SFMT_gen_rand32(); // Rprintf("state %lu\n", state); u[i + j * nb] = fracPart( state * sqrt( prime[j] ) ) ; } } } else //classic Torus algo { if(usetime) //use the machine time state = ((unsigned int) seed >> 16); else state = offset; //Rprintf("state %u %lu\n", state, state); for(j = 0; j < dim; j++) for(i = 0; i < nb; i++) u[i + j * nb] = fracPart( ( state + i ) * sqrt( prime[j] ) ) ; }
void CRunProc::RunTestL() { TTime theTime; theTime.UniversalTime(); TInt64 randSeed(theTime.Int64()); TInt random(Math::Rand(randSeed) % (1000 * 1000)); User::After(random); RTimer timer; timer.CreateLocal(); TRequestStatus timerStatus = KRequestPending; TTimeIntervalMicroSeconds32 timeout(KTimeOut); timer.After(timerStatus, timeout); TText ch; const TUint8 *bitmap = NULL; TSize bitmapsize; TOpenFontCharMetrics Metrics; do { TInt hitcount = 0; for (ch = 'A'; ch <= 'z'; ch++) { if(iFont->GetCharacterData(iSessionHandle, (TInt)ch, Metrics,bitmap)) { //RDebug::Print(_L("%c hit bitmap[0]=%x"),ch,bitmap[0]); TUint8 testbyte = bitmap[0]; testbyte += testbyte; __ASSERT_ALWAYS((testbyte & 0x01) == 0, User::Panic(KTCacheDeletionProcess, KErrGeneral)); hitcount++; } else { //RDebug::Print(_L("%c missed"),ch); } } __ASSERT_ALWAYS(hitcount > 0, User::Panic(KTCacheDeletionProcess, KErrNotFound)); } while (timerStatus == KRequestPending); timer.Cancel(); timer.Close(); }
void MainWindow::GenerateKey(TDes8& aKey, TInt aLen) { aKey.Zero(); TTime currentTime; currentTime.HomeTime(); // ??000Ä꿪ʼ¼Æ?? TInt startYear = 2000; // µ±Ç°Äê·Ý TInt currentYear = currentTime.DateTime().Year(); TTime time(TDateTime(currentYear, EJanuary, 0, 0, 0, 0, 0)); TTimeIntervalSeconds s; currentTime.SecondsFrom(time, s); // µÃµ½ÃëÊý TInt i = s.Int(); aKey.AppendFormat(_L8("%X"), i); aKey.AppendFormat(_L8("%X"), currentYear - startYear); TInt len = aKey.Length(); if (len > aLen) { aKey.Mid(0, aLen); } else { for (TInt i = 0; i < aLen - len; i++) { TTime theTime; theTime.UniversalTime(); TInt64 randSeed(theTime.Int64()); TInt number(Math::Rand(randSeed) + i); number = number % 10 + 48; aKey.Append(number); } } }
void FMMMLayout :: initialize_all_options() { //setting high level options useHighLevelOptions(false); pageFormat(pfSquare); unitEdgeLength(100); newInitialPlacement(false); qualityVersusSpeed(qvsBeautifulAndFast); //setting low level options //setting general options randSeed(100);edgeLengthMeasurement(elmBoundingCircle); allowedPositions(apInteger);maxIntPosExponent(40); //setting options for the divide et impera step pageRatio(1.0);stepsForRotatingComponents(10); tipOverCCs(toNoGrowingRow);minDistCC(100); presortCCs(psDecreasingHeight); //setting options for the multilevel step minGraphSize(50);galaxyChoice(gcNonUniformProbLowerMass);randomTries(20); maxIterChange(micLinearlyDecreasing);maxIterFactor(10); initialPlacementMult(ipmAdvanced); //setting options for the force calculation step forceModel(fmNew);springStrength(1);repForcesStrength(1); repulsiveForcesCalculation(rfcNMM);stopCriterion(scFixedIterationsOrThreshold); threshold(0.01);fixedIterations(30);forceScalingFactor(0.05); coolTemperature(false);coolValue(0.99);initialPlacementForces(ipfRandomRandIterNr); //setting options for postprocessing resizeDrawing(true);resizingScalar(1);fineTuningIterations(20); fineTuneScalar(0.2);adjustPostRepStrengthDynamically(true); postSpringStrength(2.0);postStrengthOfRepForces(0.01); //setting options for different repulsive force calculation methods frGridQuotient(2); nmTreeConstruction(rtcSubtreeBySubtree);nmSmallCell(scfIteratively); nmParticlesInLeaves(25); nmPrecision(4); }
int main(int argc,char* argv[]) { randSeed(); if(argc!=2){ return -1; } //variable declaration int i=0; struct avlTree* myAvlT = createAvlTree(); struct tree* myBst = createTree(); clock_t start1,end1; clock_t start2,end2; float diff1=0.0,diff2=0.0; struct data *d,*d1; //Insert for(i=0; i<(atoi(argv[1])*1000000); i++) { d = randomData(); d1 = createData(d->v1,d->v2); /*inserting same data struct in both trees for better comparision of performances*/ //avl insert start1 = getTime(); insertAvl(myAvlT,d); end1 = getTime(); diff1 += timeDiff(start1,end1); /*while inserting in avl clock of bst will pause and vice versa */ //bst insert start2 = getTime(); insertBst(myBst,d1); end2 = getTime(); diff2 += timeDiff(start2,end2); } //printf("AVL insertion TIME:"); printf("%f\n",diff1); //printf("BST insertion TIME:"); printf("%f\n",diff2); //Search diff1=0.0; diff2=0.0; for(i=0;i<(atoi(argv[1]) * 1000000);i++) { //AVL Search d = randomData(); d1 = createData(d->v1,d->v2); /*searching same data struct in both trees for better comparision of performances*/ start1 = getTime(); searchAvl(myAvlT,d); end1 = getTime(); diff1 += timeDiff(start1,end1); /*while searching in avl clock of bst will pause and vice versa */ free(d); //BST Search start2 = getTime(); searchBst(myBst,d1); end2 = getTime(); diff2 += timeDiff(start2,end2); free(d1); } //printf("AVL search TIME:"); printf("%f\n",diff1); //printf("BST search TIME:"); printf("%f\n",diff2); cleanBST(myBst); cleanAvl(myAvlT); return 0; }
// FIX - too long (separate into more than one function) // FIX - Make a function that prints out its usage (help function) void initParameters(int argc, char ** argv){ char * arch_filename = DEFAULT_ARCH_FILENAME; char * dfg_filename = DEFAULT_DFG_FILENAME; char * prr_filename = DEFAULT_PRR_FILENAME; int seed = randSeed(); int c; opterr = 0; while((c = getopt(argc, argv, "a:b:c:d:f:g:h:m:n:o:p:r:s:t:Vvw:")) != -1){ switch(c){ case 'a': arch_filename = optarg; break; case 'b': if(strncasecmp("one-point", optarg, strlen(optarg)) == 0 || strncasecmp("one_point", optarg, strlen(optarg)) == 0 || strncasecmp("one point", optarg, strlen(optarg)) == 0 ) crossover_type = 1; else if(strncasecmp("two-point", optarg, strlen(optarg)) != 0 && strncasecmp("two_point", optarg, strlen(optarg)) != 0 && strncasecmp("two point", optarg, strlen(optarg)) != 0 ){ fprintf(stderr, "Unknown crossover option : %s\n", optarg); exit(1); } break; case 'c': setCrossoverRate(atof(optarg)); break; case 'd': dfg_filename = optarg; break; case 'f': setFitnessFunction(optarg); break; case 'g': MAX_NUM_GENERATIONS = atoi(optarg); break; case 'h': setSetupIndex(atoi(optarg)); break; case 'm': setMutationRate(atof(optarg)); break; case 'n': if(strncasecmp("random", optarg, strlen(optarg)) == 0) mutation_type = 2; else if(strncasecmp("rotationally", optarg, strlen(optarg)) != 0){ fprintf(stderr, "Unknown mutation option : %s\n", optarg); exit(1); } break; case 'p': setPopSize(atoi(optarg)); break; case 'r': if(strncasecmp("keep-best", optarg, strlen(optarg)) == 0 || strncasecmp("keep_best", optarg, strlen(optarg)) == 0 || strncasecmp("keep best", optarg, strlen(optarg)) == 0) replacement_type = 2; else if(strncasecmp("all", optarg, strlen(optarg)) != 0){ fprintf(stderr, "Unknown replacement option : %s\n", optarg); exit(1); } break; case 's': if(strncasecmp("random", optarg, strlen(optarg)) == 0) selection_type = 2; else if(strncasecmp("tournament", optarg, strlen(optarg)) != 0){ fprintf(stderr, "Unknown selection option : %s\n", optarg); exit(1); } break; case 't': seed = atoi(optarg); break; case 'V': case 'v': fprintf(stdout, "Offline Scheduler version 2.0 (GA + Napoleon + rcSimulator)\n"); #ifdef DEBUG fprintf(stdout, "Using the DEBUG build\n\n"); #endif #ifdef VERBOSE fprintf(stdout, "Using the VERBOSE build\n\n"); #endif #ifdef STATS fprintf(stdout, "Using the STATS build\n\n"); #endif fprintf(stdout, "Please see https://github.com/Aalwattar/GA for more information\n"); exit(0); case 'w': setRuntimeWeight(atof(optarg)); break; case ':': fprintf(stderr, "Option -%c requires an operand\n", optopt); break; case '?': fprintf(stderr, "Unrecognized option: -%c\n", optopt); default: exit(1); } } if(optind < argc){ printf("Non-option argument %s\n", argv[optind]); exit(1); } // FIX - Check the return value seedRandGenerator(seed); if(initScheduler(arch_filename, dfg_filename, prr_filename) == EXIT_FAILURE) exit(1); if(POP_SIZE == 0){ POP_SIZE = getNumNodes(); } fprintf(stdout, "Parameters:\n"); fprintf(stdout, "\tFitness Function = %s\n\n", getFitnessFunction()); fprintf(stdout, "\tPopulation Size = %d\n", POP_SIZE); fprintf(stdout, "\tNumber of Generations = %d\n\n", MAX_NUM_GENERATIONS); fprintf(stdout, "\tMutation Rate = %.4lf\n", getMutationRate()); fprintf(stdout, "\tCrossover Rate = %.4lf\n", getCrossoverRate()); fprintf(stdout, "\tRuntime Weight = %.4lf\n", getRuntimeWeight()); fprintf(stdout, "\tPower Weight = %.4lf\n\n", 1.0 - getRuntimeWeight()); if(crossover_type == 1) fprintf(stdout, "\tCrossover Algorithm = One point Crossover\n"); else fprintf(stdout, "\tCrossover Algorithm = Two point Crossover\n"); if(mutation_type == 1) fprintf(stdout, "\tMutation Algorithm = Rotational Mutation\n"); else fprintf(stdout, "\tMutation Algorithm = Random Mutation\n"); if(selection_type == 1) fprintf(stdout, "\tSelection Algorithm = Tournament Selection\n"); else fprintf(stdout, "\tSelection Algorithm = Random Selection\n"); if(replacement_type == 1) fprintf(stdout, "\tReplacement Algorithm = Replace All\n\n"); else fprintf(stdout, "\tReplacement Algorithm = Keep Best\n\n"); // FIX - make this dynamic fprintf(stdout, "\tSeed = %d\n", seed); fprintf(stdout, "\tPercent seeding = %.4lf\n", (1.0 - PERCENT_POP_RANDOM)); }
// *************************************************************************** void CVegetable::generateGroupBiLinear(const CVector &posInWorld, const CVector posInWorldBorder[4], const CVector &surfaceNormal, float area, uint vegetSeed, std::vector<CVector2f> &instances) const { sint i; const float evenDistribFact= 12.25f; // an arbitrary value to have a higher frequency for random. // compute how many instances to generate on borders of the patch // ================== float edgeDensity[4]; for(i=0; i<4; i++) { // Get number of instances generated on edges edgeDensity[i]= area * Density.eval(posInWorldBorder[i]); if(MaxDensity >= 0) edgeDensity[i]= min(edgeDensity[i], area * MaxDensity); edgeDensity[i]= max(0.f, edgeDensity[i]); } // Average on center of the patch for each direction. float edgeDensityCenterX; float edgeDensityCenterY; edgeDensityCenterX= 0.5f * (edgeDensity[0] + edgeDensity[1]); edgeDensityCenterY= 0.5f * (edgeDensity[2] + edgeDensity[3]); // Average for all the patch float nbInstAverage= 0.5f * (edgeDensityCenterX + edgeDensityCenterY); // generate instances on the patch // ================== generateGroupEx(nbInstAverage, posInWorld, surfaceNormal, vegetSeed, instances); // move instances x/y to follow edge repartition // ================== // If on a direction, both edges are 0 density, then must do a special formula bool middleX= edgeDensityCenterX<=1; bool middleY= edgeDensityCenterY<=1; float OOEdgeDCX=0.0; float OOEdgeDCY=0.0; if(!middleX) OOEdgeDCX= 1.0f / edgeDensityCenterX; if(!middleY) OOEdgeDCY= 1.0f / edgeDensityCenterY; // for all instances for(i=0; i<(sint)instances.size(); i++) { float x= instances[i].x; float y= instances[i].y; // a seed for random. CVector randSeed(x*evenDistribFact, y*evenDistribFact, 0); // X change. if(middleX) { // instances are grouped at middle. this is the bijection of easeInEaseOut x= x+x - easeInEaseOut(x); x= x+x - easeInEaseOut(x); instances[i].x= x; } else { // Swap X, randomly. swap more on border // evaluate the density in X direction we have at this point. float densX= edgeDensity[0]*(1-x) + edgeDensity[1]* x ; // If on the side of the lowest density if(densX < edgeDensityCenterX) { // may swap the position float rdSwap= (densX * OOEdgeDCX ); // (densX * OOEdgeDCX) E [0..1[. The more it is near 0, the more is has chance to be swapped. rdSwap+= RandomGenerator.evalOneLevelRandom( randSeed ); if(rdSwap<1) instances[i].x= 1 - instances[i].x; } } // Y change. if(middleY) { // instances are grouped at middle. this is the bijection of easeInEaseOut y= y+y - easeInEaseOut(y); y= y+y - easeInEaseOut(y); instances[i].y= y; } else { // Swap Y, randomly. swap more on border // evaluate the density in Y direction we have at this point. float densY= edgeDensity[2]*(1-y) + edgeDensity[3]* y ; // If on the side of the lowest density if(densY < edgeDensityCenterY) { // may swap the position float rdSwap= (densY * OOEdgeDCY); // (densY * OOEdgeDCY) E [0..1[. The more it is near 0, the more is has chance to be swapped. rdSwap+= RandomGenerator.evalOneLevelRandom( randSeed ); if(rdSwap<1) instances[i].y= 1 - instances[i].y; } } } }