refactor dumbRandomScheduler
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
3095e440c6
commit
e611b5143c
|
@ -385,6 +385,8 @@ class Validator:
|
||||||
|
|
||||||
def runDumbRandomScheduler(self, tries = 100):
|
def runDumbRandomScheduler(self, tries = 100):
|
||||||
# dumb random scheduler picking segments at random and trying to send it
|
# dumb random scheduler picking segments at random and trying to send it
|
||||||
|
|
||||||
|
def nextSegment():
|
||||||
t = tries
|
t = tries
|
||||||
while t:
|
while t:
|
||||||
if self.rowIDs:
|
if self.rowIDs:
|
||||||
|
@ -392,21 +394,25 @@ class Validator:
|
||||||
cID = random.randrange(0, self.shape.blockSize)
|
cID = random.randrange(0, self.shape.blockSize)
|
||||||
if self.block.getSegment(rID, cID) :
|
if self.block.getSegment(rID, cID) :
|
||||||
neigh = random.choice(list(self.rowNeighbors[rID].values()))
|
neigh = random.choice(list(self.rowNeighbors[rID].values()))
|
||||||
if self.checkSendSegmentToNeigh(rID, cID, neigh):
|
if self.checkSegmentToNeigh(rID, cID, neigh):
|
||||||
|
yield(rID, cID, neigh)
|
||||||
t = tries
|
t = tries
|
||||||
if self.statsTxInSlot >= self.bwUplink:
|
|
||||||
return
|
|
||||||
if self.columnIDs:
|
if self.columnIDs:
|
||||||
cID = random.choice(self.columnIDs)
|
cID = random.choice(self.columnIDs)
|
||||||
rID = random.randrange(0, self.shape.blockSize)
|
rID = random.randrange(0, self.shape.blockSize)
|
||||||
if self.block.getSegment(rID, cID) :
|
if self.block.getSegment(rID, cID) :
|
||||||
neigh = random.choice(list(self.columnNeighbors[cID].values()))
|
neigh = random.choice(list(self.columnNeighbors[cID].values()))
|
||||||
if self.checkSendSegmentToNeigh(rID, cID, neigh):
|
if self.checkSegmentToNeigh(rID, cID, neigh):
|
||||||
|
yield(rID, cID, neigh)
|
||||||
t = tries
|
t = tries
|
||||||
t -= 1
|
t -= 1
|
||||||
|
|
||||||
|
for rid, cid, neigh in nextSegment():
|
||||||
|
# segments are checked just before yield, so we can send directly
|
||||||
|
self.sendSegmentToNeigh(rid, cid, neigh)
|
||||||
|
|
||||||
if self.statsTxInSlot >= self.bwUplink:
|
if self.statsTxInSlot >= self.bwUplink:
|
||||||
return
|
return
|
||||||
return
|
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
""" Send as much as we can in the timeslot, limited by bwUplink
|
""" Send as much as we can in the timeslot, limited by bwUplink
|
||||||
|
|
Loading…
Reference in New Issue