|
@ -1,11 +1,14 @@ |
|
|
import model.Customer |
|
|
import model.Customer |
|
|
|
|
|
import scala.util.chaining._ |
|
|
import util._ |
|
|
import util._ |
|
|
|
|
|
import com.typesafe.scalalogging.LazyLogging |
|
|
|
|
|
import scala.collection.mutable |
|
|
class HHCSim( |
|
|
class HHCSim( |
|
|
private val epsilonMax: Int, |
|
|
private val epsilonMax: Int, |
|
|
private val iterations: Int, |
|
|
private val iterations: Int, |
|
|
// private val customers: IndexedSeq[Customer], |
|
|
// private val customers: IndexedSeq[Customer], |
|
|
private val WLDMax: Float |
|
|
private val WLDMax: Float |
|
|
) { |
|
|
|
|
|
|
|
|
) extends LazyLogging { |
|
|
// private val graph: Array[Array[T]] |
|
|
// private val graph: Array[Array[T]] |
|
|
def go( |
|
|
def go( |
|
|
customers: Either[String, IndexedSeq[Customer]] |
|
|
customers: Either[String, IndexedSeq[Customer]] |
|
@ -13,8 +16,14 @@ class HHCSim( |
|
|
customers |
|
|
customers |
|
|
.flatMap(checkEmpty) |
|
|
.flatMap(checkEmpty) |
|
|
.map(Util.formAdjMatrix) |
|
|
.map(Util.formAdjMatrix) |
|
|
|
|
|
.tap(_ => logger.debug("Edge matrix: ")) |
|
|
|
|
|
.tap(logGraph) |
|
|
.map(edges => Util.mstUsingPrims(edges)) |
|
|
.map(edges => Util.mstUsingPrims(edges)) |
|
|
|
|
|
.tap(_ => logger.debug("MST: ")) |
|
|
|
|
|
.tap(logGraph) |
|
|
.map(mst => Util.findCentroids(mst)) |
|
|
.map(mst => Util.findCentroids(mst)) |
|
|
|
|
|
.tap(logCentroids) |
|
|
|
|
|
.tap(logRemovedEdges) |
|
|
.map( |
|
|
.map( |
|
|
e => |
|
|
e => |
|
|
e match { |
|
|
e match { |
|
@ -22,6 +31,7 @@ class HHCSim( |
|
|
Util.findClusters(mst, centroids, removed) |
|
|
Util.findClusters(mst, centroids, removed) |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
.tap(logClusters) |
|
|
.map( |
|
|
.map( |
|
|
e => |
|
|
e => |
|
|
e match { |
|
|
e match { |
|
@ -38,4 +48,51 @@ class HHCSim( |
|
|
case _ => Right(customers) |
|
|
case _ => Right(customers) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def logGraph(it: Either[String, Array[Array[Double]]]): Unit = |
|
|
|
|
|
it.map( |
|
|
|
|
|
mst => { |
|
|
|
|
|
logger.whenDebugEnabled { |
|
|
|
|
|
mst.foreach { e => |
|
|
|
|
|
e.foreach { d => |
|
|
|
|
|
print(f"$d%.2f, ") |
|
|
|
|
|
} |
|
|
|
|
|
println |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def logCentroids( |
|
|
|
|
|
e: Either[ |
|
|
|
|
|
String, |
|
|
|
|
|
(Array[Array[Double]], IndexedSeq[Int], IndexedSeq[(Int, Int, Double)]) |
|
|
|
|
|
] |
|
|
|
|
|
) = e.map(f => logger.debug(s"\nCentroids: \n ${f._2.toString}")) |
|
|
|
|
|
|
|
|
|
|
|
def logRemovedEdges( |
|
|
|
|
|
e: Either[ |
|
|
|
|
|
String, |
|
|
|
|
|
(Array[Array[Double]], IndexedSeq[Int], IndexedSeq[(Int, Int, Double)]) |
|
|
|
|
|
] |
|
|
|
|
|
) = |
|
|
|
|
|
e.map( |
|
|
|
|
|
f => |
|
|
|
|
|
logger.whenDebugEnabled { |
|
|
|
|
|
println(s"Removed Edges: \n${f._3.toString}") |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def logClusters( |
|
|
|
|
|
e: Either[ |
|
|
|
|
|
String, |
|
|
|
|
|
( |
|
|
|
|
|
IndexedSeq[Int], |
|
|
|
|
|
Map[Int, mutable.ArrayBuffer[Int]], |
|
|
|
|
|
IndexedSeq[(Int, Int, Double)] |
|
|
|
|
|
) |
|
|
|
|
|
] |
|
|
|
|
|
) = |
|
|
|
|
|
e.map( |
|
|
|
|
|
f => logger.whenDebugEnabled { println(s"Clusters: \n${f._2.toString}") } |
|
|
|
|
|
) |
|
|
} |
|
|
} |