model

package
v0.0.0-...-ec214df Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package model provides model structs for a directed weighted graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID          int
	Username    string
	DisplayName string
	Password    string
	Created     time.Time
	LastUpdated time.Time
}

Account contains all information regarding user accounts.

func (*Account) CreateAccount

func (a *Account) CreateAccount(dbpool *pgxpool.Pool) error

CreateAccount creates and stores a new account to the database.

func (*Account) String

func (a *Account) String() string

type ByTime

type ByTime []*Weight

ByTime is a list of Weights which implements the sort interface.

func (ByTime) Len

func (a ByTime) Len() int

Len returns the ByTime length.

func (ByTime) Less

func (a ByTime) Less(i, j int) bool

Less compares two weight times to each other.

func (ByTime) Swap

func (a ByTime) Swap(i, j int)

Swap changes position of two weights in the ByTime list.

type DijkstraPrio

type DijkstraPrio []*Node

DijkstraPrio is a list of node pointers and implements heap interface

func (DijkstraPrio) Len

func (dp DijkstraPrio) Len() int

Len returns length of DijkstraPrio

func (DijkstraPrio) Less

func (dp DijkstraPrio) Less(i, j int) bool

Less checks which node has shorter minimum path left to end node

func (*DijkstraPrio) Pop

func (dp *DijkstraPrio) Pop() interface{}

Pop returns the node with the shortest minimum path left to end node

func (*DijkstraPrio) Push

func (dp *DijkstraPrio) Push(x interface{})

Push adds a node into DijkstraPrio list to the correct place

func (DijkstraPrio) Swap

func (dp DijkstraPrio) Swap(i, j int)

Swap switches places in the DijkstraPrio list

type Edge

type Edge struct {
	// contains filtered or unexported fields
}

Edge contains pointers to from and to nodes as well as a list of weights.

func CreateEdge

func CreateEdge(from, to *Node) *Edge

CreateEdge takes from and to node pointers and returns a pointer to a new edge.

func (*Edge) AddWeight

func (edge *Edge) AddWeight(weight *Weight)

AddWeight adds a weight to the edge.

func (*Edge) FastestTime

func (edge *Edge) FastestTime() int

FastestTime returns the fastest possible time this edge's weights can provide.

func (*Edge) From

func (edge *Edge) From() *Node

From returns a pointer for the edge's from node.

func (*Edge) To

func (edge *Edge) To() *Node

To returns a pointer for the edge's to node.

func (*Edge) Weights

func (edge *Edge) Weights() []*Weight

Weights returns a list of the edge's weights or a default weight if no weights are set.

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph includes pointers to startNode, endNode and the internal type prioQueue.

func CreateGraph

func CreateGraph(start, end *Node) *Graph

CreateGraph is the constructor for graph taking pointers to startNode and endNode as parameters.

func (*Graph) EndNode

func (graph *Graph) EndNode() *Node

EndNode returns endNode pointer.

func (*Graph) StartNode

func (graph *Graph) StartNode() *Node

StartNode returns startNode pointer.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node stores all information about nodes like neighboring edges, rewards and if it's revisitable.

func CreateNode

func CreateNode(id string, revisit bool) *Node

CreateNode takes id and revisitable as paramteres, returning a pointer to the new node

func (*Node) AddFromEdge

func (node *Node) AddFromEdge(edge *Edge)

AddFromEdge adds an edge which has this node as a from edge.

func (*Node) AddReward

func (node *Node) AddReward(reward *Reward, quantity int)

AddReward sets a node reward with quantity.

func (*Node) AddToEdge

func (node *Node) AddToEdge(edge *Edge)

AddToEdge adds an edge which has this node as a to edge.

func (*Node) FromEdges

func (node *Node) FromEdges() []*Edge

FromEdges returns all edges which has this node as a from node.

func (*Node) ID

func (node *Node) ID() string

ID returns node id.

func (*Node) MinPathLeft

func (node *Node) MinPathLeft() int

MinPathLeft returns minimum path left to end node or math.MaxInt32 if not known.

func (*Node) Revisitable

func (node *Node) Revisitable() bool

Revisitable returns true if the node is revisitable

func (*Node) Rewards

func (node *Node) Rewards() map[*Reward]int

Rewards returns the node rewards as a map with quantity.

func (*Node) SetMinPathLeft

func (node *Node) SetMinPathLeft(mpl int)

SetMinPathLeft sets the minimum path left to end node.

func (*Node) ToEdges

func (node *Node) ToEdges() []*Edge

ToEdges returns all edges which has this node as a to node.

type Path

type Path struct {
	// contains filtered or unexported fields
}

Path holds information about a possible path, including edges, current length and current rewards.

func CreatePath

func CreatePath() *Path

CreatePath is the constructor for path pointer.

func (*Path) AddEdge

func (path *Path) AddEdge(edge *Edge, i int)

AddEdge adds an edge with length and its to node's rewards to the path.

func (*Path) AddRewards

func (path *Path) AddRewards(rewards map[*Reward]int)

AddRewards adds a map of rewards to the path.

func (*Path) Copy

func (path *Path) Copy() *Path

Copy copies a path values into another path.

func (*Path) Edges

func (path *Path) Edges() []*Edge

Edges returns a list of path edges.

func (*Path) IsLongerThan

func (path *Path) IsLongerThan(other *Path) bool

IsLongerThan compares two paths to see which has best potential to be the shortest path.

func (*Path) Length

func (path *Path) Length() int

Length returns the path length.

func (*Path) PossibleRoute

func (path *Path) PossibleRoute(edge *Edge) (isPossible bool, index int)

PossibleRoute checks if an edge makes an eligible route to take for the current path.

func (*Path) Rewards

func (path *Path) Rewards() map[*Reward]int

Rewards returns the path rewards.

type PrioQueue

type PrioQueue []*Path

PrioQueue is a list of Path pointers and implements heap interface.

func (PrioQueue) Len

func (pq PrioQueue) Len() int

Len returns the length of the PriorityQueue.

func (PrioQueue) Less

func (pq PrioQueue) Less(i, j int) bool

Less checks if one path is longer than another path in the PriorityQueue.

func (*PrioQueue) Pop

func (pq *PrioQueue) Pop() interface{}

Pop returns the node with the best potential path for the shortest path.

func (*PrioQueue) Push

func (pq *PrioQueue) Push(x interface{})

Push adds a Path to the correct place in the PriorityQueue.

func (PrioQueue) Swap

func (pq PrioQueue) Swap(i, j int)

Swap switches places of two paths in the PriorityQueue.

type Reward

type Reward struct {
	// contains filtered or unexported fields
}

Reward stores reward id, if it is unique and if can be counted as another reward via inheritance.

func CreateReward

func CreateReward(id string, unique bool, isa *Reward) *Reward

CreateReward constructs a new Reward.

func (*Reward) CanBe

func (r *Reward) CanBe() []*Reward

CanBe returns all references which inherits this reward.

func (*Reward) ID

func (r *Reward) ID() string

ID returns reward id.

func (*Reward) IsA

func (r *Reward) IsA() *Reward

IsA returns reference to inherited reward.

func (*Reward) Unique

func (r *Reward) Unique() bool

Unique returns if the reward is unique.

type Weight

type Weight struct {
	// contains filtered or unexported fields
}

Weight holds the time and possible requirements to traverse an edge.

func CreateWeight

func CreateWeight(time int) *Weight

CreateWeight constructs a weight and returns a pointer to it.

func (*Weight) AddRequirement

func (weight *Weight) AddRequirement(reward *Reward, quantity int)

AddRequirement adds a requirement with a quantity.

func (*Weight) Requirements

func (weight *Weight) Requirements() map[*Reward]int

Requirements returns a map of requirements.

func (*Weight) Time

func (weight *Weight) Time() int

Time returns a time.

Jump to

Keyboard shortcuts

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