-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenNodesPositions.py
More file actions
62 lines (43 loc) · 1.95 KB
/
genNodesPositions.py
File metadata and controls
62 lines (43 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import argparse
import numpy as np
import scipy.stats
import scipy.spatial.distance as ssd
def generateHPPP(X, Y, n):
#Intensity (i.e., mean density) of the Poisson process
lambda0 = (1. * n) / (X * Y)
#We did not yet find the array of points
findNP = False
while (findNP == False):
#Simulate Poisson Point Process
numberOfPoints = scipy.stats.poisson(lambda0*(X * Y)).rvs() #Poisson number of points
if (numberOfPoints == n):
#X coordinates of Poisson points
xx = X*scipy.stats.uniform.rvs(0,1,((numberOfPoints,1)))
#Y coordinates of Poisson points
yy = Y*scipy.stats.uniform.rvs(0,1,((numberOfPoints,1)))
#Generate the list of the points from X and Y arrays
points = np.column_stack((np.array(xx),np.array(yy)))
#Compute the distances between all pairs of points and store it into a matrix
distances = ssd.cdist(points,points)
#Flat that matrix
distances = distances.flatten()
#Keep only the non zero values
distances = distances[np.nonzero(distances)]
findNP = True
return points
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-x", "--xaxis", help="Area size horizontally in meters.")
parser.add_argument("-y", "--yaxis", help="Area size vertically in meters.")
parser.add_argument("-n", "--nodes", help="Number of nodes.")
args = parser.parse_args()
result = generateHPPP(float(args.xaxis), float(args.yaxis), int(args.nodes))
fileName = 'nodesPositions.csv'
with open(fileName,'a') as resultsFile:
resultsFile.write('Node ID;X;Y\n')
for index in range(len(result)):
with open(fileName,'a') as resultsFile:
resultsFile.write('{};{};{}\n'.format(index, float(result[index][0]), float(result[index][1])))
resultsFile.close()
if __name__ == '__main__':
main()