using Plots


include("read_xml.jl")
include("clustering.jl")
include("distances_hour.jl")
include("write_xlsx.jl")
include("write_xml.jl")


# Read client dataset as input
nodes = read_xml("inputs/R101_25.xml")

# Apply clustering algorithm to generate provider nodes
nodes = clusterise(nodes, 3)

# Extract client and provider nodes based on their type
clients = [node for node in nodes if node.type == "client"]
providers = [node for node in nodes if node.type == "provider"]

# Then, generate the corresponding time distance matrix
D_MN = calc_D_MN(providers, clients, 15.0)
D_NN = calc_D_NN(clients, 15.0)

# Write the generated data to XLSX file
write_xlsx("outputs/R101_25.xlsx", providers, clients, D_MN, D_NN)

# Write the generated data (including provider nodes) to XML for VRP-REP mapper
write_xml("outputs/R101_25.xml", nodes, "Solomon 1987 — Set R1", "R101_25")


# Plot generated nodes
cxs = [client.cx for client in clients]
cys = [client.cy for client in clients]
pxs = [provider.cx for provider in providers]
pys = [provider.cy for provider in providers]
plot(pxs, pys, seriestype = :scatter, label="Providers")
plot!(cxs, cys, seriestype = :scatter, label="Clients")
