Browse Source

Added checkempty stage to pipeline

development
Rohan Sircar 4 years ago
parent
commit
216d3f08ff
  1. 10
      src/main/scala/HHCSim.scala
  2. 18
      src/main/scala/Main.scala

10
src/main/scala/HHCSim.scala

@ -11,6 +11,7 @@ class HHCSim(
customers: Either[String, IndexedSeq[Customer]]
): String Either Map[Int, IndexedSeq[(Int, Double)]] =
customers
.flatMap(checkEmpty)
.map(Util.formAdjMatrix)
.map(edges => Util.mstUsingPrims(edges))
.map(mst => Util.findCentroids(mst))
@ -28,4 +29,13 @@ class HHCSim(
Util.groupClusters(centroids, clusters, removed)
}
)
def checkEmpty(
customers: IndexedSeq[Customer]
): Either[String, IndexedSeq[Customer]] =
customers.length match {
case 0 => Left("Error input was empty")
case _ => Right(customers)
}
}

18
src/main/scala/Main.scala

@ -14,16 +14,26 @@ object Main {
val customers = Util.getCustomers(bufferedSource)
bufferedSource.close()
val hhc = new HHCSim(epsilonMax = 40, iterations = 10, WLDMax = 10)
val fnl2 = hhc.go(customers)
// customers.map(println(_))
// val edges3 = customers.map(Util.formAdjMatrix)
// val fnl2 = go(customers)
// fnl2 match {
// case Left(value) => println(value)
// case Right(value) => println(value)
// }
fnl2 match {
case Left(value) => println(value)
case Right(groups) =>
groups.foreach(c => {
print(s"${c._1} -> ")
c._2.foreach(e => {
print(f"(${e._1}%d, ${e._2}%.2f), ")
})
println
})
}
// edges3 match {
// case Right(e) =>

Loading…
Cancel
Save