$start = strtotime("20-09-2012");
$months = 5;
$result = strtotime("+$months months", $start);
echo $result; // 20-02-2013
Tuesday, February 26, 2013
PHP add months to date via "strtotime"
If you need a date calculation via PHP date, you would use "strtotime". For example you have a date and you'll need add months to it.
Thursday, January 24, 2013
Monte Carlo simulation for deployment of a WSN
Monte carlo simulation based on random sampling to acquire numerical results. Steps of method: define a domain of inputs, generate inputs randomly, perform a deterministic computation and associate the results. Here an example of Monte Carlo simulation for deployment of a WSN. Assume a uniform random process governs the deployment of network. Assume disk sensing model. Assume that the deployment is done on 100m by 100m square 2D region. Example program that Monte Carlo simulation to find out the necessary number for 99% sensing coverage as a function of sensing radius.
After 15 times running the program, the simulation result shows the average necessary sensor number for 99% sensing coverage is 586.73.
import random
import math
def sensor_location(n):
coordinates = []
for i in range(n):
x = random.uniform(0,100)
y = random.uniform(0,100)
coordinates.append((x,y))
return coordinates
def coverage_ratio(sample_count,sensor,radius):
count = 0
location = sensor_location(sensor)
for i in range(sample_count):
xi = random.uniform(0,100)
yi = random.uniform(0,100)
sensed = False
for j in location:
d = math.sqrt( math.pow((xi-j[0]),2)+ math.pow((yi-j[1]),2))
if d <= radius:
sensed = True
break
if sensed == False:
count += 1
'''
coverage indicates non-sensed area
'''
coverage = ((count/float(sample_count))*10000)
return 100-(coverage/100)
def simulation(sample, sensor, radius):
print "running for radius = %d" % radius
while True:
ratio = coverage_ratio(sample,sensor,radius)
if ratio >= 99.0:
print "number of required sensor: %d" % sensor
print "coverage: %f" % ratio
break
else:
sensor+=5
return ratio
'''perform simulation for
initial sensor = 10
and r = 5 m
'''
def main():
simulation(10000,10,5)
if __name__ == "__main__":
main()
After 15 times running the program, the simulation result shows the average necessary sensor number for 99% sensing coverage is 586.73.
Subscribe to:
Posts (Atom)