graph

package
v0.0.0-...-3660825 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coords

type Coords struct {
	X float64
	Y float64
}

Coords : Holds X/Y 2d coordinates

func (*Coords) DistanceTo

func (c *Coords) DistanceTo(other *Coords) float64

DistanceTo : Calculates the distance between two coordinates

type Edge

type Edge struct {
	First      *Vertex
	Second     *Vertex
	Pheromones float64
	Weight     float64
}

Edge : represents an edge on the graph

func (*Edge) GetOppositeEnd

func (e *Edge) GetOppositeEnd(v *Vertex) *Vertex

GetOppositeEnd : Return the opposite end vertex if both are connected returns nil otherwise

func (*Edge) Hash

func (e *Edge) Hash() float64

Hash : Identifying hash of the edge

type Graph

type Graph struct {
	Name     string
	Vertices map[float64]*Vertex
	Edges    map[float64]*Edge
	// contains filtered or unexported fields
}

Graph : Represents an non oriented graph with vertices and edges

func (*Graph) AddEdge

func (g *Graph) AddEdge(v1, v2 *Vertex) *Edge

AddEdge : Add an edge between the two vertices

func (*Graph) AddVertex

func (g *Graph) AddVertex(v *Vertex)

AddVertex : Add a vertex to the graph

func (*Graph) GetEdgeBetweenVertices

func (g *Graph) GetEdgeBetweenVertices(v1, v2 *Vertex) *Edge

GetEdgeBetweenVertices : return the edge between the given vertices, or nil if it's not present

func (*Graph) GetEdgesCount

func (g *Graph) GetEdgesCount() int

GetEdgesCount : total number of edges in the graph

func (*Graph) GetEdgesForVertex

func (g *Graph) GetEdgesForVertex(v *Vertex) []*Edge

GetEdgesForVertex : returns the edges connected to the vertex

func (*Graph) GetRandomVertex

func (g *Graph) GetRandomVertex() *Vertex

GetRandomVertex : return a random vertex from the vertices of the graph

func (*Graph) GetVerticesCount

func (g *Graph) GetVerticesCount() int

GetVerticesCount : total number of vertices in the graph

func (*Graph) IsEmpty

func (g *Graph) IsEmpty() bool

IsEmpty : Returns true if the graph has no Vertices, returns false otherwise

type Vertex

type Vertex struct {
	Name     string
	Position Coords
}

Vertex represents a node element in a graph

func (*Vertex) Hash

func (v *Vertex) Hash() float64

Hash : hashcode for the vertex based on its coordinates

func (*Vertex) String

func (v *Vertex) String() string

String : returns a string representation of the vertex

Jump to

Keyboard shortcuts

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