Skip to content

Commit

Permalink
new test case in processes examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Dec 5, 2024
1 parent 7bd6be1 commit 5238ea5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
58 changes: 52 additions & 6 deletions unified_planning/test/examples/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ def get_example_problems():
evt.add_precondition(GE(d, 200))
evt.add_effect(on, False)

evt.clear_effects()
evt.add_effect(on, False)

b = Process("moving")
b.add_precondition(on)
b.add_derivative(d, 1)

b.clear_effects()
b.add_derivative(d, 1)

problem = Problem("1d_Movement")
problem.add_fluent(on)
problem.add_fluent(d)
Expand All @@ -47,4 +41,56 @@ def get_example_problems():
invalid_plans=[],
)
problems["1d_movement"] = test_problem

problem = Problem("boiling_water")
boiler_on = Fluent("boiler_on")
temperature = Fluent("temperature", RealType())
water_level = Fluent("water_level", RealType())
chimney_vent_open = Fluent("chimney_vent_open")

turn_on_boiler = InstantaneousAction("turn_on_boiler")
turn_on_boiler.add_precondition(Not(boiler_on))
turn_on_boiler.add_effect(boiler_on, True)

water_heating = Process("water_heating")
water_heating.add_precondition(And(boiler_on, LE(temperature, 100)))
water_heating.add_derivative(temperature, 1)

water_boiling = Process("water_boiling")
water_boiling.add_precondition(And(boiler_on, GE(temperature, 100)))
water_boiling.add_derivative(water_level, -1)

open_chimney_vent_auto = Event("open_chimney_vent_auto")
open_chimney_vent_auto.add_precondition(
And(Not(chimney_vent_open), GE(temperature, 100))
)
open_chimney_vent_auto.add_effect(chimney_vent_open, True)

turn_off_boiler_auto = Event("turn_off_boiler_auto")
turn_off_boiler_auto.add_precondition(And(LE(water_level, 0), boiler_on))
turn_off_boiler_auto.add_effect(boiler_on, False)

problem.add_fluent(boiler_on)
problem.set_initial_value(boiler_on, False)
problem.add_fluent(chimney_vent_open)
problem.set_initial_value(chimney_vent_open, False)
problem.add_fluent(temperature)
problem.set_initial_value(temperature, 20)
problem.add_fluent(water_level)
problem.set_initial_value(water_level, 10)
problem.add_action(turn_on_boiler)
problem.add_process(water_heating)
problem.add_process(water_boiling)
problem.add_event(open_chimney_vent_auto)
problem.add_event(turn_off_boiler_auto)
problem.add_goal(And(Not(boiler_on), And(chimney_vent_open, LE(water_level, 2))))

test_problem = TestCase(
problem=problem,
solvable=True,
valid_plans=[],
invalid_plans=[],
)
problems["boiling_water"] = test_problem

return problems
1 change: 1 addition & 0 deletions unified_planning/test/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def test_simple_numeric_planning_kind(self):
"sched:resource_set",
"sched:jobshop-ft06-operators",
"1d_Movement",
"boiling_water",
]
for example in self.problems.values():
problem = example.problem
Expand Down

0 comments on commit 5238ea5

Please sign in to comment.