maze

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

The maze solving experiments based on NEAT methodology with Novelty Search and Fitness based optimization

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// The current location
	Location Point
	// The heading direction in degrees
	Heading float64
	// The speed of agent
	Speed float64
	// The angular velocity
	AngularVelocity float64
	// The radius of agent body
	Radius float64
	// The maximal range of range finder sensors
	RangeFinderRange float64

	// The angles of range finder sensors
	RangeFinderAngles []float64
	// The beginning angles for radar sensors
	RadarAngles1 []float64
	// The ending angles for radar sensors
	RadarAngles2 []float64

	// stores radar outputs
	Radar []float64
	// stores rangefinder outputs
	RangeFinders []float64
}

The class for the maze navigator agent

func NewAgent

func NewAgent() Agent

Creates new Agent with default settings

type AgentRecord

type AgentRecord struct {
	// The ID of agent
	AgentID int
	// The agent position at the end of simulation
	X, Y float64
	// The agent fitness
	Fitness float64
	// The flag to indicate whether agent reached maze exit
	GotExit bool
	// The population generation when agent data was collected
	Generation int
	// The novelty value associated
	Novelty float64

	// The ID of species to whom individual belongs
	SpeciesID int
	// The age of species to whom individual belongs at time of recording
	SpeciesAge int
}

The record holding info about individual maze agent performance at the end of simulation

type Environment

type Environment struct {
	// The maze navigating agent
	Hero Agent
	// The maze line segments
	Lines []Line
	// The maze exit - goal
	MazeExit Point

	// The flag to indicate if exit was found
	ExitFound bool

	// The number of time steps to be executed during maze solving simulation
	TimeSteps int
	// The sample step size to determine when to collect subsequent samples during simulation
	SampleSize int

	// The range around maze exit point to test if agent coordinates is within to be considered as solved successfully (5.0 is good enough)
	ExitFoundRange float64
	// contains filtered or unexported fields
}

The maze environment class

func ReadEnvironment

func ReadEnvironment(ir io.Reader) (*Environment, error)

Reads maze environment from reader

func (*Environment) AgentDistanceToExit

func (e *Environment) AgentDistanceToExit() float64

used for fitness calculations based on distance of maze Agent to the target maze exit

func (*Environment) ApplyOutputs

func (e *Environment) ApplyOutputs(o1, o2 float64) error

transform neural net outputs into angular velocity and speed

func (*Environment) GetInputs

func (e *Environment) GetInputs() ([]float64, error)

create neural net inputs from maze agent sensors

func (*Environment) String

func (e *Environment) String() string

Stringer

func (*Environment) Update

func (e *Environment) Update() error

Do one time step of the simulation

type Line

type Line struct {
	A, B Point
}

The simple line segment class, used for maze walls

func NewLine

func NewLine(a, b Point) Line

To create new line

func ReadLine

func ReadLine(lr io.Reader) (*Line, error)

Reads line from specified reader

func (Line) Distance

func (l Line) Distance(p Point) float64

To find distance between line segment and the point

func (Line) Intersection

func (l Line) Intersection(line Line) (bool, Point)

Returns point of intersection between two line segments if it exists

func (Line) Length

func (l Line) Length() float64

The line segment length

func (Line) Midpoint

func (l Line) Midpoint() Point

To find midpoint of the line segment

type MazeNoveltySearchEvaluator

type MazeNoveltySearchEvaluator struct {
	// The output path to store execution results
	OutputPath string
	// The maze seed environment
	Environment *Environment

	// The target number of species to be maintained
	NumSpeciesTarget int
	// The species compatibility threshold adjustment frequency
	CompatAdjustFreq int
}

The maze solving experiment with Novelty Search optimization of NEAT algorithm

func (MazeNoveltySearchEvaluator) GenerationEvaluate

func (e MazeNoveltySearchEvaluator) GenerationEvaluate(pop *genetics.Population, epoch *experiments.Generation, context *neat.NeatContext) (err error)

This method evaluates one epoch for given population and prints results into output directory if any.

func (MazeNoveltySearchEvaluator) TrialRunStarted

func (e MazeNoveltySearchEvaluator) TrialRunStarted(trial *experiments.Trial)

Invoked before new trial run started

type MazeObjectiveEvaluator

type MazeObjectiveEvaluator struct {
	// The output path to store execution results
	OutputPath string
	// The maze seed environment
	Environment *Environment

	// The target number of species to be maintained
	NumSpeciesTarget int
	// The species compatibility threshold adjustment frequency
	CompatAdjustFreq int
}

The maze solving experiment with objective fitness-based optimization of NEAT algorithm

func (MazeObjectiveEvaluator) GenerationEvaluate

func (e MazeObjectiveEvaluator) GenerationEvaluate(pop *genetics.Population, epoch *experiments.Generation, context *neat.NeatContext) (err error)

This method evaluates one epoch for given population and prints results into output directory if any.

func (MazeObjectiveEvaluator) TrialRunStarted

func (e MazeObjectiveEvaluator) TrialRunStarted(trial *experiments.Trial)

Invoked before new trial run started

type Point

type Point struct {
	X, Y float64
}

The simple point class

func ReadPoint

func ReadPoint(lr io.Reader) (*Point, error)

Reads Point from specified reader

func (Point) Angle

func (p Point) Angle() float64

To determine angle in degrees of vector defined by (0,0)->This Point. The angle is from 0 to 360 degrees anti clockwise.

func (Point) Distance

func (p Point) Distance(point Point) float64

To find distance between this point and another point

func (*Point) Rotate

func (p *Point) Rotate(angle float64, point Point)

To rotate this point around another point with given angle in degrees

type RecordStore

type RecordStore struct {
	// The array of agent records
	Records []AgentRecord
	// The array of the solver agent path points
	SolverPathPoints []Point
}

The maze agent records storage

func (*RecordStore) Read

func (s *RecordStore) Read(r io.Reader) error

Reads record store data from provided reader

func (*RecordStore) Write

func (s *RecordStore) Write(w io.Writer) error

Writes record store to the provided writer

Jump to

Keyboard shortcuts

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