Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Last active April 29, 2021 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueleresca/800044104b218afda46951e804be23fd to your computer and use it in GitHub Desktop.
Save samueleresca/800044104b218afda46951e804be23fd to your computer and use it in GitHub Desktop.
'''
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