diff --git a/DAS/shape.py b/DAS/shape.py index 4723258..93bec3d 100644 --- a/DAS/shape.py +++ b/DAS/shape.py @@ -3,7 +3,7 @@ class Shape: """This class represents a set of parameters for a specific simulation.""" - def __init__(self, blockSizeR, blockSizeC, numberNodes, failureModel, failureRate, class1ratio, chi, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run): + def __init__(self, blockSizeR, blockSizeC, numberNodes, failureModel, failureRate, class1ratio, chiR, chiC, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run): """Initializes the shape with the parameters passed in argument.""" self.run = run self.numberNodes = numberNodes @@ -13,7 +13,8 @@ class Shape: self.failureRate = failureRate self.netDegree = netDegree self.class1ratio = class1ratio - self.chi = chi + self.chiR = chiR + self.chiC = chiC self.vpn1 = vpn1 self.vpn2 = vpn2 self.bwUplinkProd = bwUplinkProd @@ -30,7 +31,8 @@ class Shape: shastr += "-fm-"+str(self.failureModel) shastr += "-fr-"+str(self.failureRate) shastr += "-c1r-"+str(self.class1ratio) - shastr += "-chi-"+str(self.chi) + shastr += "-chir-"+str(self.chiR) + shastr += "-chic-"+str(self.chiC) shastr += "-vpn1-"+str(self.vpn1) shastr += "-vpn2-"+str(self.vpn2) shastr += "-bwupprod-"+str(self.bwUplinkProd) diff --git a/DAS/simulator.py b/DAS/simulator.py index 1925063..f3d881d 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -54,17 +54,20 @@ class Simulator: lightVal = lightNodes * self.shape.vpn1 heavyVal = heavyNodes * self.shape.vpn2 totalValidators = lightVal + heavyVal - totalRows = totalValidators * self.shape.chi + totalRows = totalValidators * self.shape.chiR + totalColumns = totalValidators * self.shape.chiC rows = list(range(self.shape.blockSizeC)) * (int(totalRows/self.shape.blockSizeC)+1) - columns = list(range(self.shape.blockSizeR)) * (int(totalRows/self.shape.blockSizeR)+1) + columns = list(range(self.shape.blockSizeR)) * (int(totalColumns/self.shape.blockSizeR)+1) rows = rows[0:totalRows] columns = columns[0:totalRows] random.shuffle(rows) random.shuffle(columns) - offset = lightVal*self.shape.chi + offsetR = lightVal*self.shape.chiR + offsetC = lightVal*self.shape.chiC self.logger.debug("There is a total of %d nodes, %d light and %d heavy." % (self.shape.numberNodes, lightNodes, heavyNodes), extra=self.format) self.logger.debug("There is a total of %d validators, %d in light nodes and %d in heavy nodes" % (totalValidators, lightVal, heavyVal), extra=self.format) - self.logger.debug("Shuffling a total of %d rows/columns to be assigned (X=%d)" % (len(rows), self.shape.chi), extra=self.format) + self.logger.debug("Shuffling a total of %d rows to be assigned (X=%d)" % (len(rows), self.shape.chiR), extra=self.format) + self.logger.debug("Shuffling a total of %d columns to be assigned (X=%d)" % (len(columns), self.shape.chiC), extra=self.format) self.logger.debug("Shuffled rows: %s" % str(rows), extra=self.format) self.logger.debug("Shuffled columns: %s" % str(columns), extra=self.format) @@ -73,14 +76,18 @@ class Simulator: for i in range(self.shape.numberNodes): if self.config.evenLineDistribution: if i < int(lightVal/self.shape.vpn1): # First start with the light nodes - start = i *self.shape.chi*self.shape.vpn1 - end = (i+1)*self.shape.chi*self.shape.vpn1 + startR = i *self.shape.chiR*self.shape.vpn1 + endR = (i+1)*self.shape.chiR*self.shape.vpn1 + startC = i *self.shape.chiC*self.shape.vpn1 + endC = (i+1)*self.shape.chiC*self.shape.vpn1 else: j = i - int(lightVal/self.shape.vpn1) - start = offset+( j *self.shape.chi*self.shape.vpn2) - end = offset+((j+1)*self.shape.chi*self.shape.vpn2) - r = rows[start:end] - c = columns[start:end] + startR = offsetR+( j *self.shape.chiR*self.shape.vpn2) + endR = offsetR+((j+1)*self.shape.chiR*self.shape.vpn2) + startC = offsetC+( j *self.shape.chiC*self.shape.vpn2) + endC = offsetC+((j+1)*self.shape.chiC*self.shape.vpn2) + r = rows[startR:endR] + c = columns[startC:endC] val = Validator(i, int(not i!=0), self.logger, self.shape, self.config, r, c) self.logger.debug("Node %d has row IDs: %s" % (val.ID, val.rowIDs), extra=self.format) self.logger.debug("Node %d has column IDs: %s" % (val.ID, val.columnIDs), extra=self.format) diff --git a/DAS/validator.py b/DAS/validator.py index e75cb7d..651f4a7 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -42,7 +42,7 @@ class Validator: """It initializes the validator with the logger shape and rows/columns. If rows/columns are specified these are observed, otherwise (default) - chi rows and columns are selected randomly. + chiR rows and chiC columns are selected randomly. """ self.shape = shape @@ -55,12 +55,12 @@ class Validator: self.sendQueue = deque() self.amIproposer = amIproposer self.logger = logger - if self.shape.chi < 1: + if self.shape.chiR < 1 and self.shape.chiC < 1: self.logger.error("Chi has to be greater than 0", extra=self.format) - elif self.shape.chi > self.shape.blockSizeR: - self.logger.error("Chi has to be smaller than %d" % self.shape.blockSizeR, extra=self.format) - elif self.shape.chi > self.shape.blockSizeC: - self.logger.error("Chi has to be smaller than %d" % self.shape.blockSizeC, extra=self.format) + elif self.shape.chiC > self.shape.blockSizeR: + self.logger.error("ChiC has to be smaller than %d" % self.shape.blockSizeR, extra=self.format) + elif self.shape.chiR > self.shape.blockSizeC: + self.logger.error("ChiR has to be smaller than %d" % self.shape.blockSizeC, extra=self.format) else: if amIproposer: self.nodeClass = 0 @@ -74,8 +74,8 @@ class Validator: self.vRowIDs = [] self.vColumnIDs = [] for i in range(self.vpn): - self.vRowIDs.append(set(rows[i*self.shape.chi:(i+1)*self.shape.chi]) if rows else set(random.sample(range(self.shape.blockSizeC), self.shape.chi))) - self.vColumnIDs.append(set(columns[i*self.shape.chi:(i+1)*self.shape.chi]) if columns else set(random.sample(range(self.shape.blockSizeR), self.shape.chi))) + self.vRowIDs.append(set(rows[i*self.shape.chiR:(i+1)*self.shape.chiR]) if rows else set(random.sample(range(self.shape.blockSizeC), self.shape.chiR))) + self.vColumnIDs.append(set(columns[i*self.shape.chiC:(i+1)*self.shape.chiC]) if columns else set(random.sample(range(self.shape.blockSizeR), self.shape.chiC))) self.rowIDs = set.union(*self.vRowIDs) self.columnIDs = set.union(*self.vColumnIDs) self.rowNeighbors = collections.defaultdict(dict)