2. Add extra monitors.—LJ Staff
3. Analyse water level and precipitation data.—Keith Nunn
4. Analysis of remote sensing imagery.—Micha Silver
7. As the basis for FOSS conferences.—moose
#!/usr/bin/env python # Copyright (C) 2010-11-13 by Antonio081014 import random import numpy import matplotlib.pyplot LinkRate = 10000000 #kbps; pkgSize = 4000 #bits; simTimes = 10 #Number of simulations; longda = numpy.arange(1000, 2001, 100) pkgNum = 2000 servTime = 1. * pkgSize / LinkRate M = servTime def getArrivalTime(lnda): r = random.random() return -numpy.log(r) / lnda; def performance(rate): startTime = 0. deptTime = servTime totalTime = servTime for i in range(1, pkgNum): startTime += getArrivalTime(rate) if deptTime - startTime <= 0.: deptTime = startTime + servTime totalTime += servTime else: totalTime += deptTime + servTime - startTime; deptTime += servTime return 1. * totalTime / pkgNum def simulate(): ret = numpy.zeros((simTimes, longda.shape[0]), 'float') for count in range(simTimes): for r in range(longda.shape[0]): rate = longda[r] ret[count][r] = performance(rate); return (ret)*1000. def getTheory(lnda): ld = numpy.zeros(lnda.shape[0], 'float') for i in range(lnda.shape[0]): d = lnda[i] temp = (2.*M - d*(M**2))/(2.*(1.-d*M)); ld[i] = temp return ld*1000. def plotSimulate(record): m = record.shape[0] n = record.shape[1] sum = numpy.sum(record, axis=0); temp = numpy.arange(n)*100 + 1000 matplotlib.pyplot.plot(temp, sum/m, 'g', label='Simulated Average Response Time'); matplotlib.pyplot.plot(temp, getTheory(longda), 'r', label='Theoretical Average Response Time'); for i in range(n): for j in range(m): matplotlib.pyplot.plot(i*100+1000, record[j][i], 'r*'); matplotlib.pyplot.legend(); matplotlib.pyplot.xlabel('Arrival Rate (packages per second)'); matplotlib.pyplot.ylabel('Response Time (ms)'); matplotlib.pyplot.title('Simulated Response Time for an M/D/1 Queue'); if __name__ == '__main__': record = simulate(); # print record matplotlib.pyplot.ion() matplotlib.pyplot.figure() plotSimulate(record); matplotlib.pyplot.savefig('SimulationT.png')
#!/usr/bin/env python # Copyright (C) 2010-11-13 by Antonio081014 # Single arrival rate specified import random import numpy import matplotlib.pyplot LinkRate = 10000000 #kbps; pkgSize = 4000 #bits; simTimes = 10 #Number of simulations; longda = numpy.array([2000, 3000]) pkgNum = 1000 servTime = 1. * pkgSize / LinkRate M = servTime def getArrivalTime(lnda): r = random.random() return -numpy.log(r) / lnda; def performance(rate): start = numpy.zeros((pkgNum), 'float'); dept = numpy.zeros((pkgNum), 'float'); startTime = 0. deptTime = servTime totalTime = servTime start[0] = startTime dept[0] = deptTime for i in range(1, pkgNum): startTime += getArrivalTime(rate) if deptTime - startTime <= 0.: deptTime = startTime + servTime totalTime += servTime else: totalTime += deptTime + servTime - startTime; deptTime += servTime start[i] = startTime dept[i] = deptTime return start*1000., dept*1000. def simCount(rate): start,dept = performance(rate) count = numpy.zeros((pkgNum)); for i in range(pkgNum): for j in dept[:i]: if j > start[i]: count[i]+=1 return count def plotSimulate(rate): record = simCount(rate); m = record.shape[0] temp = numpy.arange(m) matplotlib.pyplot.plot(temp, record, 'r*', label='The situation of filled queue before next package\'s arrival'); matplotlib.pyplot.legend(); matplotlib.pyplot.xlabel('Package Number'); matplotlib.pyplot.ylabel('Number of package in the queue when its comming'); matplotlib.pyplot.title('The sistuation of filled queue before next package\'s arrival when arrival rate is ' + str(rate)); if __name__ == '__main__': matplotlib.pyplot.ion() matplotlib.pyplot.figure() plotSimulate(longda[0]); matplotlib.pyplot.savefig('Rate01.png') matplotlib.pyplot.figure() plotSimulate(longda[1]); matplotlib.pyplot.savefig('Rate02.png')