-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.hs
35 lines (31 loc) · 1.22 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Algebra.Point
import Data.List
import Algebra.Group
import System.IO
import Text.Printf
-- Input and output files
inputFileK = "./k.txt"
inputFilePoints = "./entrada.txt"
outputFileGroups = "./saida.txt"
outputFileRes = "./result.txt"
-- Function that formats output for proper display
-- Parameters:
-- groups: [Group] -> List of groups to be displayed
-- Result:
-- [Char] -> String to be outputted
formatOuput :: [Group] -> [Char]
formatOuput groups = formatted
where
ids = reverse $ map (map (identifier)) (map (points) groups)
sorted = map (sort) ids
formatted = concat . map (\x -> (concat . intersperse ", " $ (map (show) x)) ++ "\n\n") $ sorted
main = do putStrLn "Main called"
readK <- readFile inputFileK
readP <- readFile inputFilePoints
let dataset = map (map (read::String->Double)) (map (words) (lines readP))
let k = read readK :: Int
let centroids = findCentroidsFromDataset dataset k
let finalGroups = groupPoints (convertDataset dataset) centroids
writeFile outputFileRes $ printf "%.4f" (getTotalSSE finalGroups)
writeFile outputFileGroups $ formatOuput $ finalGroups
return()