dijkstra/cmd/resolve.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"antoine-roux.ml/projects/go/dijkstra/internal"
2020-12-20 15:18:34 +00:00
stringset "antoine-roux.ml/projects/go/stringset/pkg"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
)
func main() {
filename := flag.String("i", "-", "Input file use to generate graph")
flag.Parse()
src, err := ioutil.ReadFile(*filename)
if err != nil {
log.Fatalln(err)
}
file, diags := hclsyntax.ParseConfig(src, *filename, hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
log.Fatalf("config parse: %s", fmt.Errorf("%w", diags))
}
graph := &internal.Graph{}
diags = gohcl.DecodeBody(file.Body, nil, graph)
if diags.HasErrors() {
log.Fatalf("config parse: %s", fmt.Errorf("%w", diags))
}
2020-12-20 15:18:34 +00:00
graph.InitDefaultValue()
/*
fmt.Printf("%#v\n", *graph)
for _, p := range graph.Nodes {
fmt.Printf("%+v\n", p)
}
*/
start, err := graph.GetStartingNode()
fmt.Printf("%#v\n", start)
2020-12-20 15:18:34 +00:00
ss := stringset.New(start)
ss.ToString()
fmt.Printf("neighbourNode of start %+v : \n", start)
neig := graph.GetNeighbour(start)
for _, n := range neig {
fmt.Printf("%+v\n", n)
2020-12-20 15:18:34 +00:00
g.UpdateNodeValue(start, n)
}
fmt.Println("level 2 neighbour")
neig_level2 := graph.GetNeighbourForList(neig)
for _, n := range neig_level2 {
fmt.Printf("%+v\n", n)
}
}