int rsmp(Rnd_Smp* pvl) { /*----------------------------------------------------*/ /* pvl: Number and probabilities of parameter values */ /*----------------------------------------------------*/ int i; /* The i-th offset parameter value will be the choice */ float c; /* Cumulative probabilites across parameter values */ float r; /* A uniform random number on the interval 0 - 1 */ int idum = 1; /* for(i=0;i<pvl->n;i++) printf("%.4f ",pvl->p[i]); printf("pvl->p\n"); */ /* r=drand48(); c=0.; */ r = Rand01(&idum); c = 0.0; /* printf("r: %.4f\n",r); */ for(i=0; i<pvl->n; i++) { c=c+pvl->p[i]; /* printf("c: %.4f\n",c); */ if(c>=r) return(i); } return(i-1); }
int roulette(ANT * ant){ WAY * way = ant->way; int nextNode; int num = ant->way->num; int S[N - num]; int sizeOfS = N - num; double sum; for(int i = 0; i < sizeOfS; i++){ int column = getColumn(ant, i); sum += pow(way->tau[i], alpha) * pow(eta(ant, num + 1, column), beta); } double ball = sum * Rand01(); sum = 0; for(itn i = 0; i < sizeOfS; i++){ sum += pow(way->tau[i], alpha) * pow(eta(ant, num + 1, column), beta); if(sum > ball){ nextNode = i; break; } } return nextNode; }
int roulette(ANT * ant){ int nextNode; int S[N*N];//next nodes this ant can choose int sizeOfS;//sizeof S double sum; double *currentTau = tau[ant->x][ant->y*N + ant->z]; double ball;//roulette ball sizeOfS = 0; for(int i = 0; i < N*N; i++){ if(!ant->BD[i / N][i % N]){ S[sizeOfS] = i; sizeOfS++; } } sum = 0; for(int i = 0; i < sizeOfS; i++){ sum += pow(currentTau[S[i]] , alpha) + pow(eta(ant, S[i]) , beta); } ball = sum * Rand01(); sum = 0; for(int i = 0; i < sizeOfS; i++){ sum += pow(currentTau[S[i]] , alpha) + pow(eta(ant, S[i]) , beta); if(sum > ball) { nextNode = S[i]; break; } } return nextNode; }
int firstRoulette(){ int nextNode; int S[N*N];//next nodes this ant can choose int sizeOfS;//sizeof S double sum; double * currentTau = tau0; double ball;//roulette ball sizeOfS = N*N; for(int i = 0; i < N*N; i++){ S[i] = i; } sum = 0; for(int i = 0; i < sizeOfS; i++){ sum += pow(currentTau[S[i]] , alpha) + 1; } ball = sum * Rand01(); sum = 0; for(int i = 0; i < sizeOfS; i++){ sum += pow(currentTau[S[i]] , alpha) + 1; if(sum > ball) { nextNode = S[i]; break; } } return nextNode; }
void InitializeApplication(NET* Net) { INT n,i,j; for (i=0; i<Y; i++) { for (j=0; j<X; j++) { /* Input [i*X+j] = (RandomEqualINT(LO, 100*HI)%2); */ Input [i*X+j] = Rand01(); } } f = fopen("Queen.txt", "w"); }
bool DielectricMaterial::Scatter( const Ray& ray, const HitRecord& record, Vector3& attenuation, Ray& scattered ) const { attenuation = Vector3( 1.f, 1.f, 1.f ); const float dirDotNormal = ray.Direction().Dot( record.normal ); Vector3 outwardNormal; float niOverNt; float cosine; if ( dirDotNormal > 0.f ) { outwardNormal = -record.normal; niOverNt = refractionIndex; //cosine = refractionIndex * dirDotNormal / ray.Direction().Length(); cosine = dirDotNormal / ray.Direction().Length(); cosine = std::sqrt( 1.f - refractionIndex * refractionIndex * ( 1.f - cosine * cosine ) ); } else { outwardNormal = record.normal; niOverNt = 1.f / refractionIndex; cosine = -dirDotNormal / ray.Direction().Length(); } const Vector3 reflected = Reflect( ray.Direction(), record.normal ); float reflectProbability; Vector3 refracted; if ( Refract( ray.Direction(), outwardNormal, niOverNt, refracted ) ) { reflectProbability = Schlick( cosine, refractionIndex ); } else { reflectProbability = 1.f; } if ( Rand01() < reflectProbability ) { scattered = Ray( record.point, reflected ); } else { scattered = Ray( record.point, refracted ); } return true; }
REAL RandomEqualREAL() { return((Rand01()-0.5)*2); }
void Renderer::CreateRandomAVPLs(std::vector<Avpl>& avpls, int numAVPLs) { for(int i = 0; i < numAVPLs; ++i) { const glm::vec3 position = glm::vec3(500 * Rand01(), 500 * Rand01(), 100 * Rand01()); const glm::vec3 normal = glm::vec3(Rand01(), Rand01(), Rand01()); const glm::vec3 L = glm::vec3(Rand01(), Rand01(), Rand01()); const glm::vec3 A = glm::vec3(Rand01(), Rand01(), Rand01()); const glm::vec3 w = glm::vec3(Rand01(), Rand01(), Rand01()); Avpl a(position, normal, L, A, w, 0, 0); avpls.push_back(a); } }