diff --git a/src/main/scala/HHCSim.scala b/src/main/scala/HHCSim.scala index 17911c1..3632c9a 100644 --- a/src/main/scala/HHCSim.scala +++ b/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) + } + } diff --git a/src/main/scala/Main.scala b/src/main/scala/Main.scala index e24e002..f8f9376 100644 --- a/src/main/scala/Main.scala +++ b/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) =>