Documentation
¶
Index ¶
- Constants
- func Call(rpcname string, args interface{}, reply interface{}) error
- func CreateShapesFactory(ctx *TaskContext) func(rng *rand.Rand) eaopt.Genome
- func CreateShapesFactoryFromPopulation(ctx *TaskContext, initialPopulation eaopt.Individuals) func(rng *rand.Rand) eaopt.Genome
- func GetCreateShapeFunc(shapeType string) func(opt ShapeOptions, rng *rand.Rand) Shape
- func GetShapesFactory(ctx *TaskContext, initialPopulation eaopt.Individuals) func(rng *rand.Rand) eaopt.Genome
- func Register()
- func Update(args TaskState) error
- type Circle
- type JSONIndividual
- type JSONShapes
- type Job
- type Line
- type MasterSnapshot
- type Output
- type Polygon
- type Shape
- type ShapeOptions
- type Shapes
- func (s Shapes) Append(q eaopt.Slice) eaopt.Slice
- func (s Shapes) At(i int) interface{}
- func (s Shapes) Clone() eaopt.Genome
- func (s Shapes) CloneForSending() eaopt.Genome
- func (s Shapes) Copy() eaopt.Slice
- func (s Shapes) Crossover(g eaopt.Genome, rng *rand.Rand)
- func (s Shapes) Draw(dc *gg.Context, offset util.Vector)
- func (s Shapes) Evaluate() (float64, error)
- func (s Shapes) Len() int
- func (s Shapes) Mutate(rng *rand.Rand)
- func (s Shapes) Replace(q eaopt.Slice)
- func (s Shapes) Set(i int, v interface{})
- func (s Shapes) Slice(a, b int) eaopt.Slice
- func (s Shapes) Split(k int) (eaopt.Slice, eaopt.Slice)
- func (s Shapes) Swap(i, j int)
- func (s Shapes) ToJSON() JSONShapes
- type Task
- type TaskContext
- type TaskState
- type Triangle
Constants ¶
const TIMEOUT = 2
Variables ¶
This section is empty.
Functions ¶
func Call ¶
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
Types ¶
type Circle ¶
//////////////////////////////////////////////////////////////////////////// CIRCLE ////////////////////////////////////////////////////////////////////////////
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 ¶
//////////////////////////////////////////////////////////////////////////// LINE ////////////////////////////////////////////////////////////////////////////
type MasterSnapshot ¶
type Polygon ¶
type Polygon struct {
Color color.RGBA
Position util.Vector
Radius float64
Rotation float64
Sides int
}
//////////////////////////////////////////////////////////////////////////// POLYGON ////////////////////////////////////////////////////////////////////////////
type Shape ¶
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 Shapes ¶
type Shapes struct {
Bounds util.Vector
Context *TaskContext
Members []Shape
Type string
}
*
- REMEMBER to update JSONShapes in json.go
func (Shapes) Clone ¶
create a new shapes instance with the same data copy all the data without pointers
func (Shapes) CloneForSending ¶
creates a copy of the instance without context
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) MarshalJSON ¶
func (*Task) UnmarshalJSON ¶
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"`
}