func readOptimalRoute(optimalRouteFileName string, numberExpected int) []string { pointLines := make(chan string) lineHandler := tspOptimalRouteFileHeader go func() { for line := range File.EachLine(optimalRouteFileName) { lineHandler = lineHandler(line, pointLines) } close(pointLines) }() pointIds := make([]string, numberExpected) i := 0 for pointLine := range pointLines { x, err := strconv.Atoi(pointLine) if err != nil { panic(err) } pointIds[i] = genericGeneSet[x : x+1] i++ } return pointIds }
func loadResources(routeFileName string) ([]resource, int, map[resource]int) { parts := make(chan part) lineHandler := ukpResourceFileHeader go func() { for line := range File.EachLine(routeFileName) { lineHandler = lineHandler(line, parts) } close(parts) }() resources := make([]resource, 0, 10) solution := make(map[resource]int) maxWeight := -1 for part := range parts { switch { case part.partType == constraintPart: maxWeight = parseConstraint(part.line) case part.partType == resourcePart: resources = append(resources, parseResource(part.line, len(resources))) case part.partType == solutionPart: resourceId, count := parseSolutionResource(part.line) solution[resources[resourceId-1]] = count } } return resources, maxWeight, solution }
func readPoints(routeFileName string) map[string]Point { pointLines := make(chan string) lineHandler := tspRouteFileHeader go func() { for line := range File.EachLine(routeFileName) { lineHandler = lineHandler(line, pointLines) } close(pointLines) }() points := make(map[string]Point) for pointLine := range pointLines { parts := strings.Split(pointLine, " ") geneIndex, err := strconv.Atoi(parts[0]) if err != nil { panic(err) } x, err := strconv.Atoi(parts[1]) if err != nil { panic(err) } y, err := strconv.Atoi(parts[2]) if err != nil { panic(err) } point := Point{col: x, row: y} geneId := genericGeneSet[geneIndex : geneIndex+1] points[geneId] = point } return points }