Changed nodeType configuration structure
This commit is contained in:
parent
8aaaf57ed6
commit
0e51082f71
|
@ -121,7 +121,7 @@ class Node:
|
|||
if self.amIproposer:
|
||||
self.bwUplink = shape.bwUplinkProd
|
||||
else:
|
||||
self.bwUplink = shape.nodeTypes[self.nodeClass]['bwUplinks']
|
||||
self.bwUplink = shape.nodeTypes["classes"][self.nodeClass]["def"]['bwUplinks']
|
||||
self.bwUplink *= 1e3 / 8 * config.stepDuration / config.segmentSize
|
||||
|
||||
self.repairOnTheFly = config.evalConf(self, config.repairOnTheFly, shape)
|
||||
|
|
|
@ -19,7 +19,7 @@ class Shape:
|
|||
self.custodyCols = custodyCols
|
||||
self.bwUplinkProd = bwUplinkProd
|
||||
self.nodeTypes = nodeTypes
|
||||
self.nodeClasses = [0] + [_k for _k in nodeTypes.keys() if _k != "group"]
|
||||
self.nodeClasses = [0] + [_k for _k in nodeTypes["classes"].keys()]
|
||||
self.randomSeed = ""
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
@ -45,7 +45,7 @@ class Simulator:
|
|||
self.proposerPublishToC = config.evalConf(self, config.proposerPublishToR, shape)
|
||||
|
||||
def getNodeClass(self, nodeIdx):
|
||||
nodeRatios = [_v['ratio'] for _k, _v in self.shape.nodeTypes.items() if _k != "group"]
|
||||
nodeRatios = [_v['weight'] for _k, _v in self.shape.nodeTypes["classes"].items()]
|
||||
nodeCounts = [int(self.shape.numberNodes * ratio / sum(nodeRatios)) for ratio in nodeRatios]
|
||||
commulativeSum = [sum(nodeCounts[:i+1]) for i in range(len(nodeCounts))]
|
||||
commulativeSum[-1] = self.shape.numberNodes
|
||||
|
@ -135,7 +135,7 @@ class Simulator:
|
|||
|
||||
vs = []
|
||||
nodeClass = self.getNodeClass(i)
|
||||
vpn = self.shape.nodeTypes[nodeClass]['validatorsPerNode']
|
||||
vpn = self.shape.nodeTypes["classes"][nodeClass]["def"]['validatorsPerNode']
|
||||
for v in range(vpn):
|
||||
vs.append(initValidator(self.shape.nbRows, self.shape.custodyRows, self.shape.nbCols, self.shape.custodyCols))
|
||||
val = Node(i, int(not i!=0), nodeClass, amImalicious_value, self.logger, self.shape, self.config, vs)
|
||||
|
|
|
@ -22,7 +22,7 @@ def plotData(conf):
|
|||
for i in range(len(conf["data"])):
|
||||
plt.bar(conf["xdots"], conf["data"][i], label=conf["labels"][i])
|
||||
if conf["type"] == "individual_bar_with_2line":
|
||||
plt.axhline(y = conf["expected_value1"], color='r', linestyle='--', label=conf["line_label1"])
|
||||
plt.axhline(y = conf["expected_value1"], color='w', linestyle='--', label=conf["line_label1"])
|
||||
plt.axhline(y = conf["expected_value2"], color='g', linestyle='--', label=conf["line_label2"])
|
||||
if conf["type"] == "plot_with_1line":
|
||||
plt.axhline(y = conf["expected_value"], color='g', linestyle='--', label=conf["line_label"])
|
||||
|
@ -69,12 +69,11 @@ class Visualizor:
|
|||
theGroup = dict()
|
||||
for nt in self.config.nodeTypesGroup:
|
||||
if nt['group'] == group:
|
||||
for _k, _v in nt.items():
|
||||
if _k != 'group':
|
||||
for _k, _v in nt["classes"].items():
|
||||
theGroup[_k] = {
|
||||
"vpn": _v["validatorsPerNode"],
|
||||
"bw": _v["bwUplinks"],
|
||||
"r": _v["ratio"]
|
||||
"vpn": _v["def"]["validatorsPerNode"],
|
||||
"bw": _v["def"]["bwUplinks"],
|
||||
"w": _v["weight"]
|
||||
}
|
||||
break
|
||||
|
||||
|
@ -82,10 +81,9 @@ class Visualizor:
|
|||
|
||||
def __getNodeRanges(self, shape):
|
||||
nodeClasses, nodeRatios = [], []
|
||||
for _k, _v in shape.nodeTypes.items():
|
||||
if _k != "group":
|
||||
for _k, _v in shape.nodeTypes["classes"].items():
|
||||
nodeClasses.append(_k)
|
||||
nodeRatios.append(_v['ratio'])
|
||||
nodeRatios.append(_v['weight'])
|
||||
nodeCounts = [int(shape.numberNodes * ratio / sum(nodeRatios)) for ratio in nodeRatios]
|
||||
commulativeSum = [sum(nodeCounts[:i+1]) for i in range(len(nodeCounts))]
|
||||
commulativeSum[-1] = shape.numberNodes
|
||||
|
@ -993,7 +991,7 @@ class Visualizor:
|
|||
maxi = max(v)
|
||||
conf["yaxismax"] = maxi
|
||||
x = result.shape.nbCols * result.shape.custodyRows + result.shape.nbRows * result.shape.custodyCols
|
||||
conf["expected_value"] = (result.shape.numberNodes - 1) * x * sum([(_v['r'] * _v['vpn']) for _v in nodeTypes.values()]) / sum([_v['r'] for _v in nodeTypes.values()])
|
||||
conf["expected_value"] = (result.shape.numberNodes - 1) * x * sum([(_v['w'] * _v['vpn']) for _v in nodeTypes.values()]) / sum([_v['w'] for _v in nodeTypes.values()])
|
||||
conf["line_label"] = "Total segments to deliver"
|
||||
plotData(conf)
|
||||
print("Plot %s created." % conf["path"])
|
||||
|
@ -1362,7 +1360,7 @@ class Visualizor:
|
|||
rs = []
|
||||
for result in self.results:
|
||||
attrbs = self.__get_attrbs__(result)
|
||||
rs.append(int(attrbs['r']))
|
||||
rs.append(int(attrbs['w']))
|
||||
|
||||
return max(rs) - min(rs) + 1
|
||||
|
||||
|
|
17
smallConf.py
17
smallConf.py
|
@ -83,9 +83,20 @@ bwUplinksProd = [200]
|
|||
nodeTypesGroup = [
|
||||
{
|
||||
"group": "g1",
|
||||
# nodeClass: node config
|
||||
1: {'validatorsPerNode': 1, 'bwUplinks': 10, 'ratio': 8},
|
||||
2: {'validatorsPerNode': 5, 'bwUplinks': 200, 'ratio': 2}
|
||||
"classes": {
|
||||
1: {
|
||||
"weight": 70,
|
||||
"def": {'validatorsPerNode': 1, 'bwUplinks': 10}
|
||||
},
|
||||
2: {
|
||||
"weight": 20,
|
||||
"def": {'validatorsPerNode': 5, 'bwUplinks': 200}
|
||||
},
|
||||
3: {
|
||||
"weight": 10,
|
||||
"def": {'validatorsPerNode': 10, 'bwUplinks': 500}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue