api

package
v0.0.0-...-b2d8a4d Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const TIMEOUT = 2

Variables

This section is empty.

Functions

func Call

func Call(rpcname string, args interface{}, reply interface{}) error

send an RPC request to the master, wait for the response. usually returns true. returns false if something goes wrong.

func CreateShapesFactory

func CreateShapesFactory(ctx *TaskContext) func(rng *rand.Rand) eaopt.Genome

returns a closure with a reference to the context that can be used to generate a random shapes object

func CreateShapesFactoryFromPopulation

func CreateShapesFactoryFromPopulation(
	ctx *TaskContext,
	initialPopulation eaopt.Individuals,
) func(rng *rand.Rand) eaopt.Genome

func GetCreateShapeFunc

func GetCreateShapeFunc(shapeType string) func(opt ShapeOptions, rng *rand.Rand) Shape

get the correct creation function based on the given shape type

func GetShapesFactory

func GetShapesFactory(
	ctx *TaskContext,
	initialPopulation eaopt.Individuals,
) func(rng *rand.Rand) eaopt.Genome

func Register

func Register()

func Update

func Update(args TaskState) error

Types

type Circle

type Circle struct {
	Color    color.RGBA
	Position util.Vector
	Radius   float64
}

//////////////////////////////////////////////////////////////////////////// CIRCLE ////////////////////////////////////////////////////////////////////////////

func (Circle) Draw

func (c Circle) Draw(dc *gg.Context, offset util.Vector)

type JSONIndividual

type JSONIndividual struct {
	Genome  JSONShapes `json:"genome"`
	Fitness float64    `json:"fitness"`
	ID      string     `json:"ID"`
}

type JSONShapes

type JSONShapes struct {
	Bounds util.Vector `json:"bounds"`
	Type   string      `json:"type"`

	Circles   []Circle   `json:"circles"`
	Polygons  []Polygon  `json:"polygon"`
	Triangles []Triangle `json:"triangle"`
}

*

  • Since Shapes contains pointers, custom json marshalling is needed.
  • This file contains the JSON-encodable versions of Shapes and eaopt.Individual,
  • and handles the logic associated with them.

func (JSONShapes) ToShapes

func (j JSONShapes) ToShapes() Shapes

convert a decoded json shapes intance to a Shapes instance

type Job

type Job struct {
	Complete       bool      `json:"complete"`
	CompletedAt    time.Time `json:"completedAt"`
	CrossRate      float64   `json:"crossRate"`
	DetectEdges    bool      `json:"detectEdges"`
	ID             int       `json:"ID"`
	MutationRate   float64   `json:"mutationRate"`
	NumColors      int       `json:"numColors"`
	NumGenerations uint      `json:"numGenerations"`
	NumShapes      int       `json:"numShapes"`
	OverDraw       int       `json:"overDraw"`
	PaletteType    string    `json:"paletteType"`
	PoolSize       uint      `json:"poolSize"`
	PopSize        uint      `json:"popSize"`
	Quantization   int       `json:"quantization"`
	ShapeSize      uint      `json:"shapeSize"`
	ShapeType      string    `json:"shapeType"`
	ShapesPerSlice int       `json:"shapesPerSlice"`
	StartedAt      time.Time `json:"startedAt"`
	TargetImage    string    `json:"targetImage"`
}

type Line

type Line struct {
	Color    color.RGBA
	Position []util.Vector
	Width    float64
}

//////////////////////////////////////////////////////////////////////////// LINE ////////////////////////////////////////////////////////////////////////////

func (Line) Draw

func (l Line) Draw(dc *gg.Context, offset util.Vector)

type MasterSnapshot

type MasterSnapshot struct {
	Job         Job               `json:"job"`
	TargetImage string            `json:"targetImage"`
	Tasks       map[int]TaskState `json:"tasks"`
}

type Output

type Output struct {
	Fitness float64
	Output  image.Image
}

type Polygon

type Polygon struct {
	Color    color.RGBA
	Position util.Vector
	Radius   float64
	Rotation float64
	Sides    int
}

//////////////////////////////////////////////////////////////////////////// POLYGON ////////////////////////////////////////////////////////////////////////////

func (Polygon) Draw

func (p Polygon) Draw(dc *gg.Context, offset util.Vector)

type Shape

type Shape interface {
	Draw(dc *gg.Context, offset util.Vector)
}

func CreateCircle

func CreateCircle(opt ShapeOptions, rng *rand.Rand) Shape

func CreateLine

func CreateLine(opt ShapeOptions, rng *rand.Rand) Shape

func CreatePolygon

func CreatePolygon(opt ShapeOptions, rng *rand.Rand) Shape

func CreateTriangle

func CreateTriangle(opt ShapeOptions, rng *rand.Rand) Shape

type ShapeOptions

type ShapeOptions struct {
	Bounds       util.Vector
	MutationRate float64
	Palette      []color.RGBA
	PaletteType  string
	Quantization int
	Size         float64
	TargetImage  image.Image
}

type Shapes

type Shapes struct {
	Bounds  util.Vector
	Context *TaskContext
	Members []Shape
	Type    string
}

*

  • REMEMBER to update JSONShapes in json.go

func (Shapes) Append

func (s Shapes) Append(q eaopt.Slice) eaopt.Slice

func (Shapes) At

func (s Shapes) At(i int) interface{}

func (Shapes) Clone

func (s Shapes) Clone() eaopt.Genome

create a new shapes instance with the same data copy all the data without pointers

func (Shapes) CloneForSending

func (s Shapes) CloneForSending() eaopt.Genome

creates a copy of the instance without context

func (Shapes) Copy

func (s Shapes) Copy() eaopt.Slice

func (Shapes) Crossover

func (s Shapes) Crossover(g eaopt.Genome, rng *rand.Rand)

randomly swap shapes between two populations

func (Shapes) Draw

func (s Shapes) Draw(dc *gg.Context, offset util.Vector)

draw the shapes to the given draw context

func (Shapes) Evaluate

func (s Shapes) Evaluate() (float64, error)

evaluates the fitness of the shapes instance

func (Shapes) Len

func (s Shapes) Len() int

func (Shapes) Mutate

func (s Shapes) Mutate(rng *rand.Rand)

randomly replace members of the population with a new random shape

func (Shapes) Replace

func (s Shapes) Replace(q eaopt.Slice)

func (Shapes) Set

func (s Shapes) Set(i int, v interface{})

func (Shapes) Slice

func (s Shapes) Slice(a, b int) eaopt.Slice

func (Shapes) Split

func (s Shapes) Split(k int) (eaopt.Slice, eaopt.Slice)

func (Shapes) Swap

func (s Shapes) Swap(i, j int)

func (Shapes) ToJSON

func (s Shapes) ToJSON() JSONShapes

convert a Shapes instance to a json encodable version

type Task

type Task struct {
	BestFit            eaopt.Individual  `json:"-"`
	Dimensions         util.Vector       `json:"dimensions"`
	Edges              string            `json:"edges"`
	Generation         uint              `json:"generation"`
	ID                 int               `json:"ID"`
	Job                Job               `json:"job"`
	Output             string            `json:"output"`
	Population         eaopt.Individuals `json:"-"`
	Position           util.Vector       `json:"position"`
	ScaledQuantization int               `json:"quantization"`
	ShapeType          string            `json:"shapeType"`
	TargetImage        string            `json:"targetImage"`
}

func (Task) Key

func (t Task) Key() string

func (*Task) MarshalJSON

func (t *Task) MarshalJSON() ([]byte, error)

func (*Task) UnmarshalJSON

func (t *Task) UnmarshalJSON(data []byte) error

func (Task) UpdateMaster

func (t Task) UpdateMaster(worker uint32, thread int, status string) error

type TaskContext

type TaskContext struct {
	BestFit     Output
	Edges       image.Image
	GenOffset   uint
	Mu          sync.Mutex
	Palette     []color.RGBA
	TargetImage util.Image
	Task        Task
}

func (*TaskContext) EnrichTask

func (ctx *TaskContext) EnrichTask(ga *eaopt.GA) (Task, error)

type TaskState

type TaskState struct {
	Attempt     int       `json:"attempt"`
	Complete    bool      `json:"complete"`
	CompletedAt time.Time `json:"completedAt"`
	Fitness     float64   `json:"fitness"`
	Generation  uint      `json:"generation"`
	ID          int       `json:"ID"`
	JobID       int       `json:"jobID"`
	LastUpdate  time.Time `json:"lastUpdate"`
	StartedAt   time.Time `json:"startedAt"`
	Status      string    `json:"status"`
	Thread      int       `json:"thread"`
	WorkerID    uint32    `json:"workerID"`
}

type Triangle

type Triangle struct {
	Color    color.RGBA
	Vertices []util.Vector
}

//////////////////////////////////////////////////////////////////////////// TRIANGLE ////////////////////////////////////////////////////////////////////////////

func (Triangle) Draw

func (t Triangle) Draw(dc *gg.Context, offset util.Vector)

Jump to

Keyboard shortcuts

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