This file contains hidden or 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
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... |
This file contains hidden or 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
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... | |
This file contains hidden or 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
problemDefinition := lpDefinition { | |
Vars: []float64 {1.0, 1.0, 1.0}, // dice A , dice B, dice C | |
Constraints: [][2]float64{ | |
{1, 6}, // Index 0: dice A | |
{1, 6}, // Index 1: dice B | |
{1, 6}, // Index 2: dice C | |
}, | |
Objectives: [][]float64{ | |
// LB A B C UB | |
{1.0, 1.0, -1.0, 0.0, math.Inf(1)}, // 1 ≤ a - b ≤ ∞ | Dice A cannot be equal to dice B |
This file contains hidden or 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
// lpDefinition defines a linear programming expression with its own Vars, Constraints, Objectives. | |
type lpDefinition struct { | |
Vars []float64 | |
Constraints [][2]float64 | |
Objectives [][]float64 | |
} |
This file contains hidden or 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
// NewQuorumSystemWithReads defines a new quorum system given a read Expr, the write Expr is derived using DualOperator.Dual operation. | |
func NewQuorumSystemWithReads(reads Expr) QuorumSystem { | |
qs, _ := NewQuorumSystem(reads, reads.Dual()) | |
qs.nameToNode = nameToNode{} | |
for node := range qs.GetNodes() { | |
qs.nameToNode[node.Name] = node | |
} |
This file contains hidden or 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
// OptimizeType describes an optimization type | |
type OptimizeType string | |
const ( | |
Load OptimizeType = "Load" | |
Network OptimizeType = "Network" | |
Latency OptimizeType = "Latency" | |
) | |
// StrategyOptions describes the quorum system strategy options. |
This file contains hidden or 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
// QuorumSystem describes a read-write quorum system. | |
type QuorumSystem struct { | |
// reads describes the read-quorum. | |
reads Expr | |
// writes describes the write-quorum. | |
writes Expr | |
// nameToNode keeps track the name of a node to a GetNodeByName. | |
nameToNode nameToNode | |
} |
This file contains hidden or 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
// ExprOperator that wraps the Add and Multiply methods needed to build a quorum from a set of Node. | |
type ExprOperator interface { | |
// Add method aggregate a Node to an Expr with a logical Or (a ∨ b) | |
// returns the resulting Or operation. | |
Add(expr Expr) Or | |
// Multiply method aggregate a Node to an Expr with a logical And (a ∧ b) | |
// returns the resulting And operation. | |
Multiply(expr Expr) And | |
} |
This file contains hidden or 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
def search(nodes: List[Node[T]], | |
read_fraction: Optional[Distribution] = None, | |
write_fraction: Optional[Distribution] = None, | |
optimize: str = LOAD, | |
resilience: int = 0, | |
load_limit: Optional[float] = None, | |
network_limit: Optional[float] = None, | |
latency_limit: Optional[datetime.timedelta] = None, | |
f: int = 0, | |
timeout: datetime.timedelta = datetime.timedelta(seconds=0)) \ |
This file contains hidden or 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/d83a811a905a51fc13ebc00ddac036d559463380/quoracle/quorum_system.py#L276 | |
""" | |
def _f_resilient_quorums(self, | |
f: int, | |
xs: List[T], | |
e: Expr) -> Iterator[Set[T]]: | |
""" | |
Consider a set X of elements in xs. We say X is f-resilient if, despite |