first commit
This commit is contained in:
commit
67c7dd11d5
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
target/
|
||||
.metals
|
||||
.vscode
|
||||
.idea
|
||||
.bloop
|
1
.scalafmt.conf
Normal file
1
.scalafmt.conf
Normal file
@ -0,0 +1 @@
|
||||
version = "2.0.1"
|
19
build.sbt
Normal file
19
build.sbt
Normal file
@ -0,0 +1,19 @@
|
||||
name := "scala-hhc"
|
||||
version := "1.0"
|
||||
scalaVersion := "2.13.1"
|
||||
|
||||
|
||||
resolvers ++= Seq(
|
||||
Resolver.sonatypeRepo("releases"),
|
||||
Resolver.sonatypeRepo("snapshots")
|
||||
)
|
||||
|
||||
|
||||
// https://mvnrepository.com/artifact/org.projectlombok/lombok
|
||||
libraryDependencies += "org.projectlombok" % "lombok" % "1.18.10" % "provided"
|
||||
libraryDependencies ++= Seq(
|
||||
"org.typelevel" %% "cats-core" % "2.0.0",
|
||||
"com.softwaremill.quicklens" %% "quicklens" % "1.4.12",
|
||||
"com.softwaremill.macwire" %% "macros" % "2.3.3",
|
||||
"me.shadaj" %% "scalapy-numpy" % "0.1.0+5-ad550211"
|
||||
)
|
1
project/build.properties
Normal file
1
project/build.properties
Normal file
@ -0,0 +1 @@
|
||||
sbt.version=1.3.5
|
4
project/metals.sbt
Normal file
4
project/metals.sbt
Normal file
@ -0,0 +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")
|
32
src/main/scala/Main.scala
Normal file
32
src/main/scala/Main.scala
Normal file
@ -0,0 +1,32 @@
|
||||
import model.Coord
|
||||
import model.Customer
|
||||
import model.HHCEdge
|
||||
object Main {
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
val coord1 = Coord(3, 4)
|
||||
println(s"Distance from origin = ${coord1.distance}")
|
||||
|
||||
val cust1 = Customer(coord1, 5)
|
||||
val cust2 = Customer(Coord(2, 5), 7)
|
||||
|
||||
println(s"Customer 1 = ${cust1}")
|
||||
println(s"Customer 2 = ${cust2}")
|
||||
|
||||
val cust3 = Customer(Coord(3, 5), 6)
|
||||
val cust4 = Customer(Coord(6, 8), 9)
|
||||
|
||||
val edge1 = HHCEdge(cust1, cust2)
|
||||
val edge2 = HHCEdge(cust3, cust4)
|
||||
|
||||
println(s"Edge 1 = ${edge1}")
|
||||
println(s"Edge 1 weight = ${edge1.weight}")
|
||||
|
||||
val V = Array(cust1, cust2, cust3, cust4)
|
||||
val E = Array(edge1, edge2)
|
||||
|
||||
V.foreach(println(_))
|
||||
E.foreach(println(_))
|
||||
|
||||
}
|
||||
}
|
5
src/main/scala/model/Coord.scala
Normal file
5
src/main/scala/model/Coord.scala
Normal file
@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
case class Coord(latitude: Long, longitude: Long) {
|
||||
lazy val distance = math.sqrt(math.pow(latitude, 2) + math.pow(longitude, 2)) // distance is automatically calculated
|
||||
}
|
3
src/main/scala/model/Customer.scala
Normal file
3
src/main/scala/model/Customer.scala
Normal file
@ -0,0 +1,3 @@
|
||||
package model
|
||||
|
||||
case class Customer(location: Coord, workload: Int)
|
10
src/main/scala/model/HHCEdge.scala
Normal file
10
src/main/scala/model/HHCEdge.scala
Normal file
@ -0,0 +1,10 @@
|
||||
package model
|
||||
|
||||
import scala.math.{sqrt, pow}
|
||||
|
||||
case class HHCEdge(v1: Customer, v2: Customer) {
|
||||
val weight = sqrt( //automatically compute the distance between customers
|
||||
pow(v1.location.latitude - v2.location.latitude, 2) +
|
||||
pow(v1.location.longitude - v2.location.longitude, 2)
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user