added logging
This commit is contained in:
parent
216d3f08ff
commit
0c39eed5d9
@ -11,5 +11,8 @@ libraryDependencies ++= Seq(
|
||||
"org.typelevel" %% "cats-core" % "2.0.0",
|
||||
"com.softwaremill.quicklens" %% "quicklens" % "1.4.12",
|
||||
"com.softwaremill.macwire" %% "macros" % "2.3.3",
|
||||
"org.rogach" %% "scallop" % "3.4.0"
|
||||
"org.rogach" %% "scallop" % "3.4.0",
|
||||
"ch.qos.logback" % "logback-classic" % "1.2.3",
|
||||
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
|
||||
"com.github.valskalla" %% "odin-core" % "0.7.0"
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
// DO NOT EDIT! This file is auto-generated.
|
||||
// This file enables sbt-bloop to create bloop config files.
|
||||
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1-105-118a551b")
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1-190-ef7d8dba")
|
||||
|
@ -1,11 +1,14 @@
|
||||
import model.Customer
|
||||
import scala.util.chaining._
|
||||
import util._
|
||||
import com.typesafe.scalalogging.LazyLogging
|
||||
import scala.collection.mutable
|
||||
class HHCSim(
|
||||
private val epsilonMax: Int,
|
||||
private val iterations: Int,
|
||||
// private val customers: IndexedSeq[Customer],
|
||||
private val WLDMax: Float
|
||||
) {
|
||||
) extends LazyLogging {
|
||||
// private val graph: Array[Array[T]]
|
||||
def go(
|
||||
customers: Either[String, IndexedSeq[Customer]]
|
||||
@ -13,8 +16,14 @@ class HHCSim(
|
||||
customers
|
||||
.flatMap(checkEmpty)
|
||||
.map(Util.formAdjMatrix)
|
||||
.tap(_ => logger.debug("Edge matrix: "))
|
||||
.tap(logGraph)
|
||||
.map(edges => Util.mstUsingPrims(edges))
|
||||
.tap(_ => logger.debug("MST: "))
|
||||
.tap(logGraph)
|
||||
.map(mst => Util.findCentroids(mst))
|
||||
.tap(logCentroids)
|
||||
.tap(logRemovedEdges)
|
||||
.map(
|
||||
e =>
|
||||
e match {
|
||||
@ -22,6 +31,7 @@ class HHCSim(
|
||||
Util.findClusters(mst, centroids, removed)
|
||||
}
|
||||
)
|
||||
.tap(logClusters)
|
||||
.map(
|
||||
e =>
|
||||
e match {
|
||||
@ -38,4 +48,51 @@ class HHCSim(
|
||||
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}") }
|
||||
)
|
||||
}
|
||||
|
@ -5,12 +5,13 @@ import scala.collection.mutable.ArrayBuffer
|
||||
import util.Util
|
||||
import config.Conf
|
||||
import java.io.File
|
||||
import scala.io.Source
|
||||
object Main {
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
val conf = new Conf(args.toIndexedSeq)
|
||||
|
||||
val bufferedSource = io.Source.fromFile(conf.infile())
|
||||
val bufferedSource = Source.fromFile(conf.infile())
|
||||
|
||||
val customers = Util.getCustomers(bufferedSource)
|
||||
bufferedSource.close()
|
||||
|
@ -7,8 +7,10 @@ import scala.collection.mutable
|
||||
import model.Customer
|
||||
import scala.io.BufferedSource
|
||||
import scala.reflect.ClassTag
|
||||
import com.typesafe.scalalogging.Logger
|
||||
import com.typesafe.scalalogging.LazyLogging
|
||||
|
||||
object Util {
|
||||
object Util extends LazyLogging {
|
||||
private val r = 6471.00 // km
|
||||
|
||||
def toRad(num: Double): Double = {
|
||||
|
Loading…
Reference in New Issue
Block a user