fpc

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2021 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVoteAlreadyOngoing is returned if a vote is already going on for the given ID.
	ErrVoteAlreadyOngoing = errors.New("a vote is already ongoing for the given ID")
	// ErrNoOpinionGiversAvailable is returned if a round cannot be performed as no opinion gives are available.
	ErrNoOpinionGiversAvailable = errors.New("can't perform round as no opinion givers are available")
)

Functions

func RandUniformThreshold

func RandUniformThreshold(rand float64, thresholdLowerBound float64, thresholdUpperBound float64) float64

RandUniformThreshold returns random threshold between the given lower/upper bound values.

Types

type FPC

type FPC struct {
	// contains filtered or unexported fields
}

FPC is a DRNGRoundBasedVoter which uses the Opinion of other entities in order to finalize an Opinion.

func New

func New(opinionGiverFunc opinion.OpinionGiverFunc, paras ...*Parameters) *FPC

New creates a new FPC instance.

func (*FPC) Events

func (f *FPC) Events() vote.Events

Events returns the events which happen on a vote.

func (*FPC) IntermediateOpinion

func (f *FPC) IntermediateOpinion(id string) (opinion.Opinion, error)

IntermediateOpinion returns the last formed opinion. If the vote is not found for the specified ID, it returns with error ErrVotingNotFound.

func (*FPC) Round

func (f *FPC) Round(rand float64) error

Round enqueues new items, sets opinions on active vote contexts, finalizes them and then queries for opinions.

func (*FPC) Vote

func (f *FPC) Vote(id string, objectType vote.ObjectType, initOpn opinion.Opinion) error

Vote sets an initial opinion on the vote context and enqueues the vote context.

type Parameters

type Parameters struct {
	// The lower bound liked percentage threshold at the first round. Also called 'a'.
	FirstRoundLowerBoundThreshold float64
	// The upper bound liked percentage threshold at the first round. Also called 'b'.
	FirstRoundUpperBoundThreshold float64
	// The lower bound liked percentage threshold used after the first round.
	SubsequentRoundsLowerBoundThreshold float64
	// The upper bound liked percentage threshold used after the first round.
	SubsequentRoundsUpperBoundThreshold float64
	// The amount of opinions to query on each round for a given vote context. Also called 'k'.
	QuerySampleSize int
	// The amount of rounds a vote context's opinion needs to stay the same to be considered final. Also called 'l'.
	FinalizationThreshold int
	// The amount of rounds for which to ignore any finalization checks for. Also called 'm'.
	CoolingOffPeriod int
	// The max amount of rounds to execute per vote context before aborting them.
	MaxRoundsPerVoteContext int
	// The max amount of time a query is allowed to take.
	QueryTimeout time.Duration
}

Parameters define the parameters of an FPC instance.

func DefaultParameters

func DefaultParameters() *Parameters

DefaultParameters returns the default parameters used in FPC.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL