Skip to content

Commit

Permalink
introduce type for objects representing number
Browse files Browse the repository at this point in the history
one aspect mentioned in #7
  • Loading branch information
tobiaswjohn committed Aug 15, 2024
1 parent b37b597 commit 3f3ea29
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/suave/suave_problem_created.pddl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
(:domain suave)

(:objects
f_generate_search_path f_follow_pipeline f_maintain_motion fd_spiral_low fd_spiral_medium fd_spiral_high fd_all_thrusters fd_recover_thrusters fd_follow_pipeline 0.25_decimal 0.5_decimal 0.75_decimal 1.0_decimal 1.25_decimal 2.25_decimal 3.25_decimal <_string battery_level c_thruster_1 c_thruster_2 c_thruster_3 c_thruster_4 c_thruster_5 c_thruster_6 energy obs_water_visibility performance qa_inspect_efficiency_high qa_motion_efficiency_degraded qa_motion_efficiency_normal qa_search_efficiency_high qa_search_efficiency_low qa_search_efficiency_medium qa_water_visibility_high qa_water_visibility_low qa_water_visibility_medium safety - object
f_generate_search_path f_follow_pipeline f_maintain_motion fd_spiral_low fd_spiral_medium fd_spiral_high fd_all_thrusters fd_recover_thrusters fd_follow_pipeline <_string battery_level c_thruster_1 c_thruster_2 c_thruster_3 c_thruster_4 c_thruster_5 c_thruster_6 energy obs_water_visibility performance qa_inspect_efficiency_high qa_motion_efficiency_degraded qa_motion_efficiency_normal qa_search_efficiency_high qa_search_efficiency_low qa_search_efficiency_medium qa_water_visibility_high qa_water_visibility_low qa_water_visibility_medium safety - object
a_search_pipeline a_inspect_pipeline - action
pipeline - pipeline
bluerov - robot
0.25_decimal 0.5_decimal 0.75_decimal 1.0_decimal 1.25_decimal 2.25_decimal 3.25_decimal - number
)

(:init
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/no/uio/tobiajoh/owl/OwlNumber.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package no.uio.tobiajoh.owl

// owl constant, representing a number
class OwlNumber(val number: Double, name: String) : OwlAssertionConstant(name) {
class OwlNumber(private val number: Double, name: String) : OwlAssertionConstant(name) {

companion object {
// the type that is used for numbers in pddl files
const val PDDLTYPE = "number"
}

// operator to compare two numbers
// note: only indicates, which number is larger, not by how much
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/no/uio/tobiajoh/pddl/PDDLInjector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class PDDLInjector(val addNumComparisons: Boolean = false) {

sP.addInitialAssertions(assertions)

sP.addObjects(objects)
sP.addObjects(objects.minus(numbers))
sP.addNumbers(numbers)

sP.outputToFile(newProblem)

Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/no/uio/tobiajoh/pddl/SplitProgram.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.uio.tobiajoh.pddl

import no.uio.tobiajoh.owl.OwlAssertion
import no.uio.tobiajoh.owl.OwlAssertionConstant
import no.uio.tobiajoh.owl.OwlNumber
import java.io.File


Expand Down Expand Up @@ -93,6 +94,14 @@ class SplitProgram(val problem : File) {
}
}

fun addNumbers(newNumbers: Set<OwlNumber>) {
val sortedNumbers = newNumbers.map { it.toString() }.sorted()
sortedNumbers.forEach { n ->
if (!objects.containsKey(n))
objects[n] = OwlNumber.PDDLTYPE
}
}

fun outputToFile(outFile: File) {
outFile.printWriter().use { out ->
out.println("(define (problem ${problemName})")
Expand Down

0 comments on commit 3f3ea29

Please sign in to comment.