route

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RefreshTracks

func RefreshTracks(o *entities.Player, parallel int) map[uint]*Model

RefreshTracks set minimum distance trace on specified rail.

func RefreshTransports

func RefreshTransports(l *entities.RailLine, parallel int) map[uint]*Model

RefreshTransports set minimum distance route on specified rail line.

Types

type Digest

type Digest struct {
	ModelType entities.ModelType
	ID        uint
	Value     float64
}

Digest directs resource of model

type Edge

type Edge struct {
	Digest
	FromNode *Node
	ToNode   *Node
}

Edge is wrapper of Step for routing.

func NewEdge

func NewEdge(base entities.Connectable, from *Node, to *Node) *Edge

NewEdge creates new instance.

func (*Edge) Cost

func (e *Edge) Cost() float64

Cost returns value.

func (*Edge) Export

func (e *Edge) Export(from *Node, to *Node) *Edge

Export creates new instance which has specified Node.

func (*Edge) String

func (e *Edge) String() string

type Model

type Model struct {
	GoalIDs []uint
	Nodes   map[entities.ModelType]map[uint]*Node
	Edges   map[entities.ModelType]map[uint]*Edge
}

Model has minimux distance route information to specific Node.

func NewModel

func NewModel(origin ...*Model) *Model

NewModel creates instance or copies original if it is specified.

func Scan

func Scan(ctx context.Context, model *entities.Model) (*Model, bool)

Scan extracts Step for Human informations.

func (*Model) AddGoalID

func (m *Model) AddGoalID(id uint)

AddGoalID adds id as goal.

func (*Model) Export

func (m *Model) Export() *Model

Export copies Nodes and Edges having same id.

func (*Model) ExportWith

func (m *Model) ExportWith(t entities.ModelType, id uint) (*Model, *Node)

ExportWith copies Nodes and Edges, then returns corresponding Node to specified goal.

func (*Model) FindOrCreateEdge

func (m *Model) FindOrCreateEdge(origin entities.Connectable) *Edge

FindOrCreateEdge returns corresponding Edge. If such Edge doesn't exist, create and return new Edge.

func (*Model) FindOrCreateNode

func (m *Model) FindOrCreateNode(origin entities.Entity) *Node

FindOrCreateNode returns corresponding Node. If such Node doesn't exist, create and return new Node.

func (*Model) Fix

func (m *Model) Fix()

Fix discards no more using data.

func (*Model) NumEdges

func (m *Model) NumEdges() int

NumEdges returns the number of Edges.

func (*Model) NumNodes

func (m *Model) NumNodes() int

NumNodes returns the number of Nodes.

func (*Model) String

func (m *Model) String() string

type Node

type Node struct {
	Digest
	Via     *Node
	ViaEdge *Edge
	Out     []*Edge
	In      []*Edge
}

Node is digest of Relayable, Transportable for routing. The chain of Node represents one route.

func NewNode

func NewNode(obj entities.Entity) *Node

NewNode returns instance

func (*Node) Export

func (n *Node) Export() *Node

Export create new instance which has same id of it.

func (*Node) Fix

func (n *Node) Fix()

Fix sets ViaEdge and discards no more need slice

func (*Node) RawRoute

func (n *Node) RawRoute() string

func (*Node) Route

func (n *Node) Route() string

func (*Node) SameAs

func (n *Node) SameAs(oth entities.Entity) bool

SameAs check both directs same resource

func (*Node) String

func (n *Node) String() string

func (*Node) WalkThrough

func (n *Node) WalkThrough()

WalkThrough set distance towrards self to Value of connected Nodes. Initial cost of connected Node must be max float64 value.

type NodeQueue

type NodeQueue []*Node

NodeQueue is open list for searching

func (NodeQueue) Len

func (q NodeQueue) Len() int

func (NodeQueue) Less

func (q NodeQueue) Less(i, j int) bool

func (NodeQueue) Swap

func (q NodeQueue) Swap(i, j int)

type Payload

type Payload struct {
	Route     map[uint]*Model
	Processed int
	Total     int
}

Payload is collection of Model.

func Search(ctx context.Context, t entities.ModelType, parallel int, model *Model) (*Payload, bool)

Search calculates minimum distance of route for specified goal.

func (*Payload) Import

func (p *Payload) Import(oth *Payload)

Import accepts result of calcuration.

func (*Payload) IsOK

func (p *Payload) IsOK() bool

IsOK returns whether all Model was built or not.

type Searcher

type Searcher struct {
	Name   string
	Target entities.ModelType
	Tasks  []uint
	Model  *Model
	Ch     chan *Payload
}

Searcher has minimum distance route for specified goal.

func (*Searcher) Search

func (s *Searcher) Search(ctx context.Context, wg *sync.WaitGroup)

Search calculates minimum distance of route.

Jump to

Keyboard shortcuts

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