int main() { freopen("t.in", "w", stdout); scanf("%d%d%d", &n, &m, &seed); srand(seed); printf("%d %d\n", n, m); for ( int i = 0; i < n; i ++ ) printf("%d %d\n", randVal(), randVal()); }
//Fabricate some test faces (random subset of points) void makeFaces(int *facesA,int *facesB) { for (int f=0;f<nFaces;f++) { int *fa=&facesA[f*nPer]; int *fb=&facesB[f*nPer]; bool doSkip=true; for (int i=0;i<nPer;i++) { int na=randNo(aPoints); bool repeat=true; //Did we hit a repeated point? do { repeat=false; for (int j=0;j<i;j++) if (na==fa[j]) { //It's a repetition-- try again na=randNo(aPoints); repeat=true; break; } } while (repeat); if (doSkip && randVal(1.0)<0.1) { fa[i]=fb[i]=-1; //Skip this node doSkip=false; } else { fa[i]=na; fb[i]=na+a2bPoints; } } } }
/// <summary> /// Perform learning (weight adjustments) for all units on the topological map /// </summary> void Ttopmap::learn() { int x; int y,i; float d; float value; float max; //store the current input image on the winning unit if (WinnerX>-1) { max = (float)(RadiusExcite * RadiusExcite); for (x = (WinnerX - RadiusExcite);x<=(WinnerX + RadiusExcite);x++) { for (y = (WinnerY - RadiusExcite);y<=(WinnerY + RadiusExcite);y++) { if ((x >= 0) && (x < map_width) && (y >= 0) && (y < map_height)) { d = Dist(x, y) / (2 * max); if (d < 1) { value = randVal(d); adjustWeights(x, y, value); if (!((x == WinnerX) && (y == WinnerY))) { for (i=0;i<10;i++) classificationMulti[x][y][i] = classificationMulti[x][y][i] + (int)((classificationMulti[WinnerX][WinnerY][i] - classificationMulti[x][y][i]) * (1 - d) * learningRate); } } } } } for (x=0;x<inputs_width;x++) for (y=0;y<inputs_height;y++) image[WinnerX][WinnerY][x][y] = inputs[x][y]; } //update the threshold based upon the average similarity Threshold = (Threshold + (average_similarity*10)) / 2; }
int main( int argc, char *argv[] ) { int db_timeout = 60000; bool end = false; int ans; //parametry uruchomienia struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; while( end==false ) { int option_index = 0; int ch=getopt_long(argc, argv, "hv", long_options, &option_index); if (ch == -1) break; switch(ch) { case 'h': print_usage(argv[0]); end = true; break; case 'v': print_version(argv[0]); end = true; break; MIN: std::cerr << "Unknown option ` " << char(ch) << " '" << std::endl; exit(1); break; } } //parametry uruchomienia -- koniec globalConfigDb=new sqlite3cc::conn(); globalConfigDb->open( std::getenv("ICD_CONFIG_DB") ); globalConfigDb->busy_timeout( db_timeout ); globalConfig=new icd::config( *globalConfigDb ); //#define FLUSH_DELAY 180 sleep( randVal()*20.0+10 ); system( "icd-transfer-data" );//first sync int timeOfNextTransfer; // int timeOfNextFlush; int timeNow; int delayNow=0; while( 1==1 ) { sleep( 30 );//sleep to avoid running loop twice in one second timeNow=time(NULL); // timeOfNextFlush=timeNow; // timeOfNextFlush/=FLUSH_DELAY; // timeOfNextFlush+=1; // timeOfNextFlush*=FLUSH_DELAY; // timeOfNextFlush+=5;//rounded to 3 min, + 5 secs if( delayNow!=getDelay() ) {//delay changed by user or transfer delayNow=getDelay(); timeOfNextTransfer=timeNow; timeOfNextTransfer/=delayNow; timeOfNextTransfer+=1; timeOfNextTransfer*=delayNow; if( delayNow > 300 ) {//rand of no more than 5 minutes timeOfNextTransfer+=(int)((double)randVal()*(double)0.1*300.0); } else { timeOfNextTransfer+=(int)((double)randVal()*(double)0.1*(double)delayNow); } timeOfNextTransfer+=30; } // if( timeOfNextTransfer<=timeOfNextFlush ) {//transfer will be faster than flush if( timeOfNextTransfer-timeNow > 0 ) { sleep( timeOfNextTransfer-timeNow ); } // system( "icd-flush-db" ); system( "icd-transfer-data" ); delayNow=0;//force get delay and calculate new time // } else {//only flush // if( timeOfNextFlush-timeNow > 0 ) { // sleep( timeOfNextFlush-timeNow ); // } // system( "icd-flush-db" ); // } }//end while( 1==1 ) return 0; }
void DEMGenerator::fractalRecurse(int left, int right, int top, int bottom) { if ((right - left) < 2) { return; } int midPointH = (left + right) / 2; int midPointV = (top + bottom) / 2; if (this->grid[top][midPointH] == -1.0f) this->grid[top][midPointH] = (this->grid[top][left] + this->grid[top][right]) / 2; if (this->grid[bottom][midPointH] == -1.0f) this->grid[bottom][midPointH] = (this->grid[bottom][left] + this->grid[bottom][right]) / 2; if (this->grid[midPointV][left] == -1.0f) this->grid[midPointV][left] = (this->grid[top][left] + this->grid[bottom][left]) / 2; if (this->grid[midPointV][right] == -1.0f) this->grid[midPointV][right] = (this->grid[top][right] + this->grid[bottom][right]) / 2; if (this->grid[midPointV][midPointH] == -1.0f) this->grid[midPointV][midPointH] = (this->grid[top][left] + this->grid[top][right] + this->grid[bottom][left] + this->grid[bottom][right]) / 4 + randVal(left - right + 1); fractalRecurse(left, midPointH, midPointV, bottom); fractalRecurse(left, midPointH, top, midPointV); fractalRecurse(midPointH, right, top, midPointV); fractalRecurse(midPointH, right, midPointV, bottom); }
//Return random integer on [0,max) int randNo(int max) { return (int)(randVal(max-0.000001)); }
CkVector3d randVec(const CkVector3d &scale) { return CkVector3d(randVal(scale.x),randVal(scale.y),randVal(scale.z)); }