Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Last active December 10, 2021 12:15
Show Gist options
  • Save samueleresca/7f1ee46ca07f34d196e38cff614a8735 to your computer and use it in GitHub Desktop.
Save samueleresca/7f1ee46ca07f34d196e38cff614a8735 to your computer and use it in GitHub Desktop.
func (qs QuorumSystem) loadOptimalStrategy(
optimize OptimizeType,
readQuorums []ExprSet,
writeQuorums []ExprSet,
readFraction DistributionValues,
loadLimit *float64,
networkLimit *float64,
latencyLimit *float64) (*Strategy, error) {
...
buildLoadDef := func(loadLimit *float64, fr float64) (lpDefinition, error) {
def := newDefinitionWithVarsAndConstraints(readQuorumVars, writeQuorumVars)
// l def
def.Vars = append(def.Vars, 1.0)
def.Constraints = append(def.Constraints, [2]float64{ninf, pinf})
// Load formula
for n := range qs.GetNodes() {
tmp := make([]float64, len(def.Vars))
if _, ok := xToReadQuorumVars[n]; ok {
vs := xToReadQuorumVars[n]
for _, v := range vs {
tmp[v.Index] += fr * v.Value / float64(*qs.GetNodeByName(n.Name).ReadCapacity)
}
}
if _, ok := xToWriteQuorumVars[n]; ok {
vs := xToWriteQuorumVars[n]
for _, v := range vs {
tmp[v.Index] += (1 - fr) * v.Value / float64(*qs.GetNodeByName(n.Name).WriteCapacity)
}
}
def.Objectives = append(def.Objectives, tmp)
}
return def, nil
}
...
return &newStrategy, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment