unit

package
v2.28.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge[EdgeType, VertexType comparable] struct {
	From VertexType
	To   VertexType
	Edge EdgeType
}

Edge is a convenience type for representing an edge in the graph. It encapsulates the from and to vertices and the edge type itself.

type Graph

type Graph[EdgeType, VertexType comparable] struct {
	// contains filtered or unexported fields
}

Graph provides a bidirectional interface over gonum's directed graph implementation. While the underlying gonum graph is directed, we overlay bidirectional semantics by distinguishing between forward and reverse edges. Wanting and being wanted by other units are related but different concepts that have different graph traversal implications when Units update their status.

The graph stores edge types to represent different relationships between units, allowing for domain-specific semantics beyond simple connectivity.

func (*Graph[EdgeType, VertexType]) AddEdge

func (g *Graph[EdgeType, VertexType]) AddEdge(from, to VertexType, edge EdgeType) error

AddEdge adds an edge to the graph. It initializes the graph and metadata on first use, checks for cycles, and adds the edge to the gonum graph.

func (*Graph[EdgeType, VertexType]) GetForwardAdjacentVertices

func (g *Graph[EdgeType, VertexType]) GetForwardAdjacentVertices(from VertexType) []Edge[EdgeType, VertexType]

GetForwardAdjacentVertices returns all the edges that originate from the given vertex.

func (*Graph[EdgeType, VertexType]) GetReverseAdjacentVertices

func (g *Graph[EdgeType, VertexType]) GetReverseAdjacentVertices(to VertexType) []Edge[EdgeType, VertexType]

GetReverseAdjacentVertices returns all the edges that terminate at the given vertex.

func (*Graph[EdgeType, VertexType]) ToDOT

func (g *Graph[EdgeType, VertexType]) ToDOT(name string) (string, error)

ToDOT exports the graph to DOT format for visualization

Jump to

Keyboard shortcuts

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