Skip to content

Commit

Permalink
Use floats for edge weight
Browse files Browse the repository at this point in the history
  • Loading branch information
aThorp96 committed Feb 23, 2019
1 parent e859776 commit c24ad91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Hamiltonian struct {

// The optimitality of the solution
// The lower the number the shorter the path
fitness int
fitness float64
}

func main() {
Expand Down Expand Up @@ -89,7 +89,7 @@ func Gentior(filepath string, populationSize, generations int, bias float64, qui
fmt.Println()
fmt.Println("-------------------- Results -------------------- ")
fmt.Printf("Shortest path:\t%d\n\n", population[0].fitness)
fmt.Printf("Sholution: %v\n", population[0].path)
fmt.Printf("Solution: %v\n", population[0].path)
fmt.Println("------------------------------------------------- ")
}

Expand Down Expand Up @@ -122,8 +122,8 @@ func ConnectedGentior(filepath string, populationSize, generations int, bias flo
fmt.Println()
fmt.Println("---------------------- Results ---------------------- ")
fmt.Printf("Population: \t%d\t\tGenerations: \t%d\n", populationSize, generations)
fmt.Printf("Shortest path:\t%d\t\tTime: %v\n\n", population[0].fitness, elapsed)
fmt.Printf("Sholution: %v\n", population[0].path)
fmt.Printf("Shortest path:\t%.2f\tTime: %v\n\n", population[0].fitness, elapsed)
fmt.Printf("Solution: %v\n", population[0].path)
fmt.Println("----------------------------------------------------- ")
}

Expand Down Expand Up @@ -560,8 +560,8 @@ func dfs(current int, goal int, visited []bool, depth int, soFar []int, g *Undir

// A fitness evaluator
// Returns the sum weight of the walk
func fitness(g *Undirected, walk []int) int {
length := 0
func fitness(g *Undirected, walk []int) float64 {
length := 0.0
for i := 0; i < len(walk); i++ {
n := (i + 1) % len(walk)
length += g.Weight(walk[i], walk[n])
Expand Down
4 changes: 2 additions & 2 deletions tools/tsp2wdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# of each end of the edge, followed by the distance spanned by the edge.
# Finally, the EOF indicator is the footer "-1 -1 -1"

filename = "./xqf131.tsp"
filename = "./data/att48/att48.tsp"
edgeFile = open(filename)

outFilename = "./xqf131.wdat"
outFilename = "./data/att48/att48.wdat"
outFile = open(outFilename, "w")

string = ""
Expand Down

0 comments on commit c24ad91

Please sign in to comment.