commit 3a721ac0b48874541c3343309d39a667df1a2c7f Author: Nigel Barink Date: Sun Mar 28 20:25:57 2021 +0100 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b59815 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/**/* diff --git a/City.go b/City.go new file mode 100644 index 0000000..40acf8d --- /dev/null +++ b/City.go @@ -0,0 +1,8 @@ +package main + +type City struct { + Name string + Area int + Population int + Mayor Person +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..67eb09f --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +build: + go build -o bin/build/pathFinder *.go +run: + go run *.go diff --git a/Person.go b/Person.go new file mode 100644 index 0000000..7334342 --- /dev/null +++ b/Person.go @@ -0,0 +1,8 @@ +package main + +type Person struct { + FirstName string + LastName string + Age int + JobTitle string +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..37a421f --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Pathfinding + + + + +## Which algorithms ? +Dijkstra & A* + + +## What type of graph I am using ? +Directed graph + + +## Why use Golang? + + +I have wanted to play around with golang for a while but didn't have a good project for it. My hopes are to play with the ___ side by running the algorithm in ___ + diff --git a/directedGraph.go b/directedGraph.go new file mode 100644 index 0000000..f7a811b --- /dev/null +++ b/directedGraph.go @@ -0,0 +1,23 @@ +package main + +const SIZE_GRAPH int = 10 + +type DirectedGraph struct { + count int + nodes [SIZE_GRAPH]Node + Head *Node +} + +func (self *DirectedGraph) AddNode(node *Node) { + + if self.count > SIZE_GRAPH { + panic("Graph has gotten too big") + } + + if self.Head == nil && self.count == 0 { + self.Head = node + } + + self.nodes[self.count] = *node + self.count++ +} diff --git a/edge.go b/edge.go new file mode 100644 index 0000000..7128c01 --- /dev/null +++ b/edge.go @@ -0,0 +1,9 @@ +package main + +type Edge struct { + To *Node +} + +func (self *Edge) Cost() int { + return (self.To.Data.Population / 100) +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..62e1811 --- /dev/null +++ b/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" +) + +func main() { + + MyGraph := DirectedGraph{} + + // Instantiate Nodes + FirstNode := Node{Data: City{Name: "Amsterdam", Population: 821_752}} + SecondNode := Node{Data: City{Name: "Dublin", Population: 544_107}} + thirdNode := Node{Data: City{Name: "Berlin", Population: 3_645_000}} + fourthNode := Node{Data: City{Name: "Paris", Population: 2_161_000}} + + // Setup relations + FirstNode.Edges[0] = Edge{To: &thirdNode} + SecondNode.Edges[0] = Edge{To: &thirdNode} + FirstNode.Edges[1] = Edge{To: &SecondNode} + thirdNode.Edges[0] = Edge{To: &fourthNode} + + // Add Nodes to graph + MyGraph.AddNode(&FirstNode) + MyGraph.AddNode(&SecondNode) + MyGraph.AddNode(&thirdNode) + MyGraph.AddNode(&fourthNode) + + fmt.Println("Whats inside the graph") + for index, node := range MyGraph.nodes { + if (node == Node{}) { + continue + } + fmt.Printf("%d %s\t(Pops: %d)\n", index, node.Data.Name, node.Data.Population) + for _, edge := range node.Edges { + if (edge == Edge{}) { + continue + } + + fmt.Printf( + "\t- Has a connection to %s\t(Travel Cost: %d)\n", + edge.To.Data.Name, + edge.Cost()) + } + fmt.Println() + } + +} diff --git a/node.go b/node.go new file mode 100644 index 0000000..fe3260a --- /dev/null +++ b/node.go @@ -0,0 +1,8 @@ +package main + +const MAX_EDGES int = 3 + +type Node struct { + Data City + Edges [MAX_EDGES]Edge +}