ga

package
v0.0.0-...-73d8155 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(a City, b City) float64

Types

type City

type City struct {
	X, Y float64
}

City is a location in the world

type GA

type GA struct {
	World        World
	MutationRate float64
	Population   int
	Journies     []Journey
}

func NewGA

func NewGA(w World, population int, mutationRate float64) GA

func (*GA) Iterate

func (ga *GA) Iterate()

type Journey

type Journey struct {
	Cities []City
	Trips  []Trip
	Length float64
}

Journey is the total journey

func (*Journey) Eval

func (j *Journey) Eval()

func (*Journey) Mutate

func (jo *Journey) Mutate(n int)

func (*Journey) MutateTrips

func (jo *Journey) MutateTrips()

func (Journey) Plot

func (j Journey) Plot(fname string) (err error)

type Trip

type Trip struct {
	Dests []int
}

Trip can be one city or two cities in a specific order

type World

type World struct {
	Cities []City
	Trips  []Trip
}

World is the list of all the cities and the possible trips

func NewWorld

func NewWorld(cities []City, trips []Trip) (w World)

func (World) FindBest

func (w World) FindBest() (best Journey)

func (World) RandomJourney

func (w World) RandomJourney() (j Journey)

Jump to

Keyboard shortcuts

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