Added checkempty stage to pipeline
This commit is contained in:
parent
69a0c3ce63
commit
216d3f08ff
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user