Skip to content

Commit

Permalink
update new algorithm (exp3s) and the distribution of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
tuyen.ta committed Apr 25, 2019
1 parent 3256d73 commit a79337e
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 193 deletions.
14 changes: 9 additions & 5 deletions iot_mab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def main(args):
nrBS = int(args.nrBS)
initial = str(args.initial)
radius = int(args.radius)
distribution = list(map(float, args.distribution.split()))
avgSendTime = int(args.AvgSendTime)
horTime = int(args.horizonTime)
packetLength = int(args.packetLength)
Expand All @@ -17,20 +18,23 @@ def main(args):
captureEffect = bool(args.captureEffect)
interSFInterference = bool(args.interSFInterference)
info_mode = str(args.infoMode)
algo = str(args.Algo)
exp_name = str(args.exp_name)
logdir = str(args.logdir)

# print simulation parameters
print("\n=================================================")
print_params(nrNodes, nrIntNodes, nrBS, initial, radius, avgSendTime, horTime, packetLength,
sfSet, freqSet, powSet, captureEffect, interSFInterference, info_mode)
print_params(nrNodes, nrIntNodes, nrBS, initial, radius, distribution, avgSendTime, horTime, packetLength,
sfSet, freqSet, powSet, captureEffect, interSFInterference, info_mode, algo)

assert initial in ["UNIFORM", "RANDOM"], "Initial mode must be UNIFORM, RANDOM."
assert info_mode in ["NO", "PARTIAL", "FULL"], "Initial mode must be NO, PARTIAL, or FULL."

assert algo in ["exp3", "exp3s"], "Learning algorithm must be exp3 or exp3s."


# running simulation
bsDict, nodeDict = sim(nrNodes, nrIntNodes, nrBS, initial, radius, avgSendTime, horTime,
packetLength, sfSet, freqSet, powSet, captureEffect, interSFInterference, info_mode, logdir, exp_name)
bsDict, nodeDict = sim(nrNodes, nrIntNodes, nrBS, initial, radius, distribution, avgSendTime, horTime,
packetLength, sfSet, freqSet, powSet, captureEffect, interSFInterference, info_mode, algo, logdir, exp_name)

return bsDict, nodeDict

Expand Down
6 changes: 4 additions & 2 deletions lora/bsFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from os.path import join
from .loratools import airtime, dBmTomW
# Transmit
def transmitPacket(env, node, bsDict, logDistParams):
def transmitPacket(env, node, bsDict, logDistParams, algo):
""" Transmit a packet from node to all BSs in the list.
Parameters
----------
Expand All @@ -26,6 +26,8 @@ def transmitPacket(env, node, bsDict, logDistParams):
list of BSs.
logDistParams: list
channel params
algo: string
learning algorithm
Returns
-------
"""
Expand Down Expand Up @@ -86,7 +88,7 @@ def transmitPacket(env, node, bsDict, logDistParams):
if not node.ack[0].isCollision:
node.packetsSuccessful += 1
node.transmitTime += node.packets[0].rectime
node.updateProb()
node.updateProb(algo)
#print("Probability of action from node " +str(node.nodeid)+ " at (t+1)= {}".format(int(1+env.now/(6*60*1000))))
#print(node.prob)
#print(node.weight)
Expand Down
42 changes: 29 additions & 13 deletions lora/loratools.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def placeRandomly(number, locArray, xRange, yRange):


def placeRandomlyInRange(number, nrIntNodes, locArray, xRange, yRange, refLoc, bestValue,
radius, transmitParams, maxPtx):
radius, transmitParams, maxPtx, distribution, distMatrix):
""" Place node randomly in a range
Parameters
----------
Expand All @@ -326,23 +326,39 @@ def placeRandomlyInRange(number, nrIntNodes, locArray, xRange, yRange, refLoc, b
Transmission params
maxPtx: float
Maximum transmission value
distribution: list
Distribution of nodes
distMatrix: matrix
Matrix of distance sperated by SF and BW
Returns
-------
locArray: array
Location array.
"""
for n in range(number):
while True:
# This could technically turn into an infinite loop but that shouldn't ever practically happen.
# add check here later
x = random.uniform(xRange[0], xRange[1])
y = random.uniform(yRange[0], yRange[1])
rdd, packetLength, preambleLength, syncLength, headerEnable, crc = transmitParams
bestDist, bestSF, bestBW = bestValue

if np.any(np.sum(np.square(refLoc[:,1:3] - np.array([x,y]).reshape(1,2)), axis=1) <= radius**2):
locArray[n,:] = [n, x, y, bestSF, rdd, bestBW, packetLength, preambleLength, syncLength, headerEnable, crc, maxPtx, 0, 0]
break
temp = 0
for idx in range(len(distribution)):
number_nodes = int(number * distribution[idx])
for n in range(number_nodes):
while True:
# This could technically turn into an infinite loop but that shouldn't ever practically happen.
# add check here later
x = random.uniform(xRange[0], xRange[1])
y = random.uniform(yRange[0], yRange[1])
#print(x, y)
rdd, packetLength, preambleLength, syncLength, headerEnable, crc = transmitParams
bestDist, bestSF, bestBW = bestValue
if idx == 0:
if np.any(np.sum(np.square(refLoc[:,1:3] - np.array([x,y]).reshape(1,2)), axis=1) <= radius**2):
if np.any(np.sum(np.square(refLoc[:,1:3] - np.array([x,y]).reshape(1,2)), axis=1) <= distMatrix[idx]**2):
locArray[n+temp,:] = [n+temp, x, y, bestSF, rdd, bestBW, packetLength, preambleLength, syncLength, headerEnable, crc, maxPtx, 0, 0]
break
else:
if np.any(np.sum(np.square(refLoc[:,1:3] - np.array([x,y]).reshape(1,2)), axis=1) <= radius**2):
if np.any(np.sum(np.square(refLoc[:,1:3] - np.array([x,y]).reshape(1,2)), axis=1) <= distMatrix[idx]**2):
if np.any(np.sum(np.square(refLoc[:,1:3] - np.array([x,y]).reshape(1,2)), axis=1) >= distMatrix[idx-1]**2):
locArray[n+temp,:] = [n+temp, x, y, bestSF, rdd, bestBW, packetLength, preambleLength, syncLength, headerEnable, crc, maxPtx, 0, 0]
break
temp += number_nodes

def airtime(phyParams):
""" Computes the airtime of a packet in second.
Expand Down
Loading

0 comments on commit a79337e

Please sign in to comment.