Commit ed706b98 authored by Arthur Bit-Monnot's avatar Arthur Bit-Monnot

[planning] Add a plan validation step.

parent 0ce40ee3
......@@ -188,7 +188,8 @@ lazy val pddlPlanner = project
)
.settings(
libraryDependencies ++= Seq(
"com.github.scopt" %% "scopt" % "3.7.0"
"com.github.scopt" %% "scopt" % "3.7.0",
"com.lihaoyi" %% "ammonite-ops" % "1.1.0"
))
resolvers += Resolver.sonatypeRepo("releases")
......
......@@ -61,6 +61,7 @@ object deps {
val scopt = ivy"com.github.scopt::scopt:3.7.0"
val debox = ivy"org.spire-math::debox:0.8.0"
val pddl4j = ivy"fr.uga:pddl4j:3.6.0"
val ammoniteOps = ivy"com.lihaoyi::ammonite-ops:1.1.0"
val utest = ivy"com.lihaoyi::utest:0.6.4"
val scalatest = ivy"org.scalatest::scalatest:3.0.5"
......@@ -113,7 +114,7 @@ object planning extends EmptyModule {
}
object planner extends Module {
def moduleDeps = Seq(planning.pddl.parser, planning.planner)
def ivyDeps = Agg(scopt)
def ivyDeps = Agg(scopt, ammoniteOps)
def mainClass = Some("dahu.planning.pddl.planner.Main")
}
}
......
......@@ -33,6 +33,9 @@ object Main extends App {
opt[Int]("timeout")
.action((t, c) => c.copy(maxRuntime = t.seconds))
opt[Int]("discretization")
.action((i, c) => c.copy(discretization = i))
arg[File]("XXX.dom.pddl").optional().action {
case (f, c) => c.copy(domainFile = Some(f))
}
......@@ -72,12 +75,12 @@ object Main extends App {
parser.parse(domain, problem) match {
case Success(model) =>
Planner.solveIncremental(model, config.maxInstances, Deadline.now + config.maxRuntime) match {
case Some(Plan(operators)) =>
case Some(plan) =>
println("\n== Solution ==")
operators
.map(PddlOperator(_))
.sortBy(_.start)
.foreach(println)
val sol = PddlPlan(plan)
println(sol.format)
println("Validating")
Validator.validate(domain, problem, sol)
case None =>
println("\nFAIL")
}
......@@ -88,21 +91,3 @@ object Main extends App {
None
}
}
case class PddlOperator(name: String, args: Vec[String], start: Double, duration: Double) {
override def toString: String = s"$start: ($name ${args.mkString(", ")}) [$duration]"
}
object PddlOperator {
def toPddlTime(t: Int)(implicit predef: PddlPredef): Double = t.toDouble / predef.discretization.toDouble
def apply(gen: Operator[cats.Id])(implicit predef: PddlPredef): PddlOperator = gen match {
case Operator(name, args, start, end, true) =>
new PddlOperator(
name,
Vec(args.map(_.toString): _*),
toPddlTime(start),
toPddlTime(end - start))
}
}
package dahu.planning.pddl.planner
import dahu.planning.pddl.parser.PddlPredef
import dahu.planning.planner.Operator
import dahu.utils.Vec
case class PddlOperator(name: String, args: Vec[String], start: Double, duration: Double) {
override def toString: String = s"$start: ($name ${args.mkString(", ")}) [$duration]"
}
object PddlOperator {
def toPddlTime(t: Int)(implicit predef: PddlPredef): Double = t.toDouble / predef.discretization.toDouble
def apply(gen: Operator[cats.Id])(implicit predef: PddlPredef): PddlOperator = gen match {
case Operator(name, args, start, end, true) =>
new PddlOperator(
name,
Vec(args.map(_.toString): _*),
toPddlTime(start),
toPddlTime(end - start))
}
}
package dahu.planning.pddl.planner
import dahu.planning.pddl.parser.PddlPredef
import dahu.planning.planner.Plan
case class PddlPlan(operators: Seq[PddlOperator]) {
def format: String =
operators
.sortBy(_.start)
.mkString("\n")
}
object PddlPlan {
def apply(genPlan: Plan)(implicit predef: PddlPredef): PddlPlan = {
PddlPlan(
genPlan.operators
.map(PddlOperator(_))
.sortBy(_.start))
}
}
package dahu.planning.pddl.planner
import java.io.File
import ammonite.ops._
import dahu.planning.pddl.parser.PddlPredef
object Validator {
def validate(domain: File, problem: File, plan: PddlPlan)(implicit predef: PddlPredef): Boolean = {
val tolerance: Double = 1.0 / predef.discretization.toDouble
val out = File.createTempFile("plan", "")
write.over(Path(out), plan.format)
val ret = %%('validate, "-t", tolerance, "-v", domain.getAbsolutePath, problem.getAbsolutePath, out.getAbsolutePath)(pwd)
println(ret)
true
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment