generation

package
v0.0.0-...-a69e935 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0, MIT Imports: 4 Imported by: 10

Documentation

Overview

Package generation provides builders to easily build groups, entities and their resource and affinity requirements and placement orderings. All builders have methods to set each specific field of the type being build and a generate method which will then create an instance of the type from the specifications given to the builder.

Building a group can look like this:

random := rand.New(rand.NewSource(42))
// Create a template for the group name
nameTemplate := labels.NewLabelTemplate("schemadock$id$-$dc$")
// Create the builder
builder := NewGroupBuilder().
	Name(nameTemplate)
// Bind values to the names in the template, this makes reusing the builder to generate groups with different
// names easy.
nameTemplate.
	Bind("id", "42").
	Bind("dc", "dc1")
// Generate a group with name "schemadock42-dc1"
group := builder.Generate(random, time.Now())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constant

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

Constant represents a constant distribution which always returns the same value, though the value to return can be changed using the new value method.

func NewConstant

func NewConstant(value float64) *Constant

NewConstant creates a new constant distribution.

func (*Constant) CurrentValue

func (constant *Constant) CurrentValue() float64

CurrentValue returns the current value of the constant distribution.

func (*Constant) NewValue

func (constant *Constant) NewValue(value float64)

NewValue changes the value of the constant distribution to a new constant value.

func (*Constant) Value

func (constant *Constant) Value(random Random, gtime time.Duration) float64

Value returns the currently set constant value.

type Discrete

type Discrete struct {
	ValuesToProbabilities map[float64]func(gtime time.Duration) float64
}

Discrete represents a discrete distribution with varying probabilities for each value throughout time.

func NewDiscrete

func NewDiscrete(valueToWeight map[float64]float64) *Discrete

NewDiscrete creates a new discrete distribution which returns each value with a probability distributed that corresponds to the weight of the value.

func NewUniformDiscrete

func NewUniformDiscrete(values ...float64) *Discrete

NewUniformDiscrete creates a new Discrete which returns a set of values with a uniform probability distribution throughout time.

func (*Discrete) Value

func (discrete *Discrete) Value(random Random, gtime time.Duration) float64

Value returns a random value from a discrete distribution that varies throughout time.

type Distribution

type Distribution interface {
	Value(random Random, gtime time.Duration) float64
}

Distribution represents a probability distribution which can change according to time but always returns the same value for the same point in time.

type Gaussian

type Gaussian struct {
	Mean              func(gtime time.Duration) float64
	StandardDeviation func(gtime time.Duration) float64
}

Gaussian represents a gaussian distribution with varying mean and standard deviation throughout time.

func NewConstantGaussian

func NewConstantGaussian(mean, deviation float64) *Gaussian

NewConstantGaussian creates a new GaussianDistribution with constant mean and standard deviation.

func (*Gaussian) Value

func (gaussian *Gaussian) Value(random Random, gtime time.Duration) float64

Value returns a random value from a gaussian with a mean and standard deviation that varies throughout time.

type Random

type Random interface {
	// Uniform returns a value in the range [0;1[.
	Uniform(gtime time.Duration) float64

	// Norm returns a normal distributed value in the range [-math.MaxFloat64, +math.MaxFloat64] with mean 0.0 and
	// stddev 1.0.
	Norm(gtime time.Duration) float64

	// Exp returns a exponentially distributed value in the range [0, +math.MaxFloat64] with an exponential distribution
	// whose rate parameter (lambda) is 1 and whose mean is 1/lambda (1).
	Exp(gtime time.Duration) float64

	// Perm returns permutation of the numbers 0, 1, ..., n-1.
	Perm(gtime time.Duration, n int) []int
}

Random is source of randomness that varies throughout time, but will always return the same value for the same instance in time.

func NewRandom

func NewRandom(seed int64) Random

NewRandom returns a new source of randomness with the given seed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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