You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

  1. package main
  2. import (
  3. "io/ioutil"
  4. "strconv"
  5. "strings"
  6. )
  7. func readDataset(path string, lineSeparation string, valueSeparation string) [][][]int {
  8. var dataset [][][]int
  9. b, err := ioutil.ReadFile(path)
  10. check(err)
  11. str := string(b)
  12. str = strings.Replace(str, "\r", "", -1)
  13. lines := strings.Split(str, lineSeparation)
  14. for _, v1 := range lines {
  15. params := strings.Split(v1, valueSeparation)
  16. var datasetLine [][]int
  17. var datasetLineEntry []int
  18. var lastLineValue []int
  19. for k2, v2 := range params {
  20. value, err := strconv.Atoi(v2)
  21. check(err)
  22. if k2 < len(params)-1 {
  23. datasetLineEntry = append(datasetLineEntry, value)
  24. } else {
  25. lastLineValue = append(lastLineValue, value)
  26. }
  27. }
  28. datasetLine = append(datasetLine, datasetLineEntry)
  29. datasetLine = append(datasetLine, lastLineValue)
  30. dataset = append(dataset, datasetLine)
  31. }
  32. return dataset
  33. }
  34. func readInputs(path string, lineSeparation string, valueSeparation string) [][]int {
  35. var dataset [][]int
  36. b, err := ioutil.ReadFile(path)
  37. check(err)
  38. str := string(b)
  39. str = strings.Replace(str, "\r", "", -1)
  40. lines := strings.Split(str, lineSeparation)
  41. for _, v1 := range lines {
  42. params := strings.Split(v1, valueSeparation)
  43. //var datasetLine [][]int
  44. var datasetLineEntry []int
  45. for _, v2 := range params {
  46. value, err := strconv.Atoi(v2)
  47. check(err)
  48. datasetLineEntry = append(datasetLineEntry, value)
  49. }
  50. //datasetLine = append(datasetLine, datasetLineEntry)
  51. dataset = append(dataset, datasetLineEntry)
  52. }
  53. return dataset
  54. }