/* Returns a sample from stable distribution */ double Stable(RndState *S, int param, double alpha, double beta) { double X, theta=M_PI*(Uniform(S)-0.5); // These methods come from John Nolan's book about // stable distributions. They return standardised stable random // numbers in the S(alpha,beta;0) parameterisation if (beta==0) { if (alpha==1) { X=tan(theta); } else { double W=Exponential(S); X=sin(alpha*theta)/cos(theta)*pow(cos((alpha-1)*theta)/(W*cos(theta)),1/alpha-1); } } else { double W=Exponential(S); double zeta=beta*tan(alpha*M_PI/2); if (alpha==1) { double b=2*beta/M_PI; double bt=1+b*theta; X=bt*tan(theta) - b*log(W*cos(theta)/bt); } else { double ath = alpha*theta; double a1th = theta-ath; X = ((sin(ath) + zeta*cos(ath))/cos(theta)) * pow((cos(a1th) + zeta*sin(a1th))/(W*cos(theta)),1/alpha-1); if (param==0) X=X-zeta; } } return X; }
double GetArrival(unsigned int *j) { const double mean[2] = {1/L1, 1/L2}; static double arrival[2] = {START, START}; static int init = 1; double temp; if (init) { SelectStream(0); arrival[0] += Exponential(mean[0]); SelectStream(1); arrival[1] += Exponential(mean[1]); init=0; } if (arrival[0] <= arrival[1]) *j = 0; else *j = 1; temp = arrival[*j]; SelectStream(*j); arrival[*j] += Exponential(mean[*j]); return temp; }
void Behavior3(){ // doba dojeni double time; if (Random()<=0.1) time = Exponential(15); else time = Exponential(8); scheduleAt(Time() + time, SLOT(Krava::Behavior4)); }
long double HyperExponential(long double a, long double m1, long double b, long double m2) /* ========================================================= * Returns ... * NOTE: everything must be > 0.0 * ========================================================= */ { long double r = Random(); long double he = 0.0; if (r < a) he = Exponential(m1); else he = Exponential(m2); return he; }
double GetService(int j, int n) { const double mean[5] = {1/M1CLET, 1/M2CLET, 1/M1CLOUD, 1/M2CLOUD, 1/MSETUP}; SelectStream(j + n + 2); return Exponential(mean[j + n]); }
void FailureProcess::Behavior(void) { Seize(oven_fac, 1); //std::cout << "PORUCHA PECE " << Time << std::endl; refuse_orders = true; Wait(Exponential(FAILURE_WAIT_TIME)); Release(oven_fac); refuse_orders = false; //std::cout << "KONEC PORUCHY PECE " << Time << std::endl; }
/** This function initializes all global generators by @a seed value. @param seed The seed value of all generators. */ void srand(RandomValue seed) { OMNI_MT_CODE(sync::AutoLock guard(g_lock())); g_rand() = Random(seed); g_unif() = Uniform(seed); g_norm() = Normal(seed); g_exp() = Exponential(seed); g_seed() = seed; }
double Erlang(long n, double b) /* ================================================== * Returns an Erlang distributed positive real number. * NOTE: use n > 0 and b > 0.0 * ================================================== */ { long i; double x = 0.0; for (i = 0; i < n; i++) x += Exponential(b); return (x); }
long Poisson(double m) /* ================================================== * Returns a Poisson distributed non-negative integer. * NOTE: use m > 0 * ================================================== */ { double t = 0.0; long x = 0; while (t < m) { t += Exponential(1.0); x++; } return (x - 1); }
//---------------------------------------------- void AirPort::execute() { int id=0; double lambda=5.; long double gen=0; bool active=true; while (active) { switch(phase) { case 0: activate(Exponential(lambda,seed)); active=true; phase=1; break; case 1: int numPass=static_cast<int>(5*Uniform(seed)+8); for(int i=0;i<numPass;i++) { gen=Uniform()+1; if(gen>=1 && gen<1.2) id=1; if(gen>=1.2 && gen<1.4) id=2; if(gen>=1.4&& gen<1.70) id=3; if(gen>=1.7&&gen<2.0) id=4; ap.addPass(new Passsenger(Clock,id)); } active=false; phase=0; break; } } }
void Behavior() { // zivotni cyklus scheduleAt(Time() + Exponential(15*60), SLOT(Krava::Behavior2) ); // 15hod }
static void *foo(void *arg __unused__) { /* actual time */ double _time = cur_time; /* seize the facility */ debug("< Seize(fac) PID: %d >", CURRENT()); Seize(&fac, CURRENT()); /* after succesfull seize, save time into stats */ save_time(fac.stats, cur_time - _time); /* wait for time */ debug("< Wait(fac) PID: %d >", CURRENT()); Wait(Exponential(1.25)); /* release the facility */ debug("< Release(fac) PID: %d >", CURRENT()); Release(&fac); /* terminating the process */ debug("< Quit() PID: %d >", CURRENT()); Quit(); return NULL; } int main(void) { /* Facility initialization */