www.pudn.com > ghs1.2.rar > distributor.cpp
/* * Copyright (c) 2000-2003 Illinois Institute of Technology. * All rights reserved. * * This file is part of the GHS software package. For license * information, see the LICENSE file in the top level directory of the * GHS source distribution. * * Released Date: August 18 2005 * This is the GHS I release by the * SCS Group, * http://www.cs.iit.edu/~scs * Department of Computer Science, * Illinois Institute of Technology. * * This release has been tested under SUN OS 5.9. * * Supervisor * ---------- * Illiniois Institute of Technology: * -Dr. Xian-He Sun * * Author(s) * ----------------- * Illinois Institute of Technology: * -Ming Wu * -Xian-He Sun * */ #include#include #include #include #include #include #include "distributor.h" using namespace std; /* Drand: choose a rand floating-point number between zero and one (including both), * based on a 31-bit rand integer */ void Distributor::SetUp(int value) { srand(value); } double Distributor::Drand () { return (double) (1.0*rand()) / (RAND_MAX + 1.0); } /* CHOOSE FROM LOG UNIFORM : low and high are the exponents of the * range; i.e. low = 0 and high = 3 would have a range from 1 second * to exp(3) seconds */ double Distributor::ChooseFromLogUniform(double low, double high) { double x = Drand () * (high - low) + low; return exp(x); } double Distributor::ChooseFromSerial(double maxValue) { double x; int l = 0; while (l == 0) { x = Drand(); if ( (2.0 / x) < maxValue ) l = 1; } return (2.0 / x); } /* CHOOSE LIFETIME : log uniform distribution between tmin and tmax */ double Distributor::ChooseLifeTime(double maxValue) { return ChooseFromSerial(maxValue); } void Distributor::GenerateRaLifeTime(vector &lifeTime, double maxvalue, int procNum) { for (int i = 0; i < procNum; i++) { lifeTime.push_back(Drand() * maxvalue); } } void Distributor::GenerateSeLifeTime(vector &lifeTime, double maxvalue, int procNum) { for (int i = 0; i < procNum; i++) { lifeTime.push_back( ChooseLifeTime(maxvalue) ); } } // generate process time following the Exponential distribution void Distributor::GenerateExLifeTime(vector &lifeTime, double serv, int procNum) { for (int i = 0; i < procNum; i++) { lifeTime.push_back( -1 * (1.0 / serv) * log(Drand()) ); } } // generate process time following the Log Normal distribution void Distributor::GenerateLNLifeTime(vector &lifeTime, double miu, double std, int procNum) { int valid = 0; double u1, u2, u3, x, y; for (int i = 0; i < procNum; i++) { valid = 0; while (valid == 0) { u1 = Drand(); u2 = Drand(); x = -1.0 * log(u1); if (u2 <= exp(-1.0 * pow((x - 1), 2.0) / 2.0)) valid = 1; } u3 = Drand(); if (u3 > 0.5) y = x; else y = -1.0 * x; lifeTime.push_back( exp(miu + std * y) ); } } // generate process time following the Erlang distribution void Distributor::GenerateErLifeTime(vector &lifeTime, double scaleP, int shapeP, int procNum) { double tmpproduct = 1.0; for (int i = 0; i < procNum; i++) { for (int k = 0; k < shapeP; k++) tmpproduct *= Drand(); lifeTime.push_back( -1 * scaleP * log(tmpproduct) ); tmpproduct = 1.0; } } // generate process time following the Gamma distribution void Distributor::GenerateGaLifeTime(vector &lifeTime, double scaleP, double shapeP, int procNum) { int shapeInt; int valid = 0; double tmpProduct = 1.0, u1, u2, xb, yb, x, y; for (int i = 0; i < procNum; i++) { shapeInt = (int) shapeP; if (shapeP == shapeInt) { for (int k = 0; k < shapeP; k++) tmpProduct *= Drand(); lifeTime.push_back( -1 * scaleP * log(tmpProduct) ); tmpProduct = 1.0; } else if (shapeP < 1) { valid = 0; while ( valid == 0) { u1 = Drand(); u2 = Drand(); xb = pow(u1, (1/shapeP)); yb = pow(u2, (1/(1 - shapeP))); if ( (xb + yb) <= 1) valid = 1; } x = xb / (xb + yb); y = -1 * log(Drand()); lifeTime.push_back( scaleP * x * y ); } else { tmpProduct = 1.0; for (int k = 0; k < shapeP; k++) tmpProduct *= Drand(); lifeTime.push_back( -1 * scaleP * log(tmpProduct) ); shapeP = shapeP - shapeInt; valid = 0; while ( valid == 0) { u1 = Drand(); u2 = Drand(); xb = pow(u1, (1.0 / shapeP)); yb = pow(u2, (1.0/(1 - shapeP))); if ( (xb + yb) <= 1) valid = 1; } x = xb / (xb + yb); y = -1 * log(Drand()); lifeTime[i] += scaleP * x * y; } } } // generate process time following the Truncated Normal distribution void Distributor::GenerateTNLifeTime(vector &lifeTime, double serv, int procNum) { for (int i = 0; i < procNum; i++) { lifeTime.push_back( -1 * (1.0 / serv) * log(Drand()) ); } } void Distributor::GenerateInterarri(vector &interArri, double arri, int procNum) { int l= 0; for (int i = 0; i < procNum; i++) { l = 0; while (l == 0) { interArri.push_back( (-1) * (1.0 / arri) * log(Drand()) ); if (interArri[i] < 1000000) l=1; } } }