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
//Search given some nodes, and a SearchOptions instance, returns the optimal strategy and quorum system in respect of the optimization target and constraints. | |
func Search(nodes []Expr, option SearchOptions) (SearchResult, error) { | |
return performQuorumSearch(nodes, initializeSearchOptions(option)) | |
} | |
func performQuorumSearch(nodes []Expr, opts ...func(options *SearchOptions) error) (SearchResult, error) { | |
sb := &SearchOptions{} | |
// ... (write initializations with default values)... | |
for _, op := range opts { |
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
// Strategy defines a strategy related to a QuorumSystem. | |
type Strategy struct { | |
Qs QuorumSystem | |
SigmaR Sigma | |
SigmaW Sigma | |
nodeToReadProbability map[Node]Probability | |
nodeToWriteProbability map[Node]Probability | |
} | |
// Sigma defines the probabilities of a specific Strategy. Each Expr (quorum) has a probability of being choose associated. |
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
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... |
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
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... |
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
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... |
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
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... | |
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
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 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 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 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. |