Last active
April 29, 2021 21:12
-
-
Save samueleresca/800044104b218afda46951e804be23fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/main/quoracle/quorum_system.py#L541 | |
''' | |
#... | |
def load(problem: pulp.LpProblem, | |
read_fraction: Dict[float, float]) -> pulp.LpAffineExpression: | |
return sum(p * fr_load(problem, fr) | |
for (fr, p) in read_fraction.items()) | |
def fr_load(problem: pulp.LpProblem, fr: float) -> pulp.LpAffineExpression: | |
l = pulp.LpVariable(f'l_{fr}', 0, 1) | |
for node in self.nodes(): | |
x = node.x | |
x_load: pulp.LpAffineExpression = 0 | |
if x in x_to_read_quorum_vars: | |
vs = x_to_read_quorum_vars[x] | |
x_load += fr * sum(vs) / self.node(x).read_capacity | |
if x in x_to_write_quorum_vars: | |
vs = x_to_write_quorum_vars[x] | |
x_load += (1 - fr) * sum(vs) / self.node(x).write_capacity | |
problem += (x_load <= l, f'{x}{fr}') | |
return l | |
# Form the linear program. | |
problem = pulp.LpProblem("optimal_strategy", pulp.LpMinimize) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment