Skip to content

Commit

Permalink
Add some example
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico Scala committed Oct 9, 2024
1 parent 3ba5fe8 commit fc12ae3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
40 changes: 40 additions & 0 deletions unified_planning/test/examples/processes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from unified_planning.shortcuts import *
from unified_planning.model.action import Process
from unified_planning.io import PDDLReader, PDDLWriter


on = Fluent("on")
d = Fluent("d", RealType())

a = InstantaneousAction("turn_on")
a.add_precondition(Not(on))
a.add_effect(on, True)

evt = Event("turn_off_automatically")
evt.add_precondition(GE(d, 200))
evt.add_effect(on, False)

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

problem = Problem("1D Movement")
problem.add_fluent(on)
problem.add_fluent(d)
problem.add_action(a)
problem.add_action(b)
problem.add_action(evt)
problem.set_initial_value(on, False)
problem.set_initial_value(d, 0)
problem.add_goal(GE(d, 10))

z = Fluent("z", BoolType())
pr = Process("Name")
pr.add_precondition(z)

with OneshotPlanner(problem_kind=problem.kind) as planner:
result = planner.solve(problem)
if result.status in unified_planning.engines.results.POSITIVE_OUTCOMES:
print(f"{planner.name} found this plan: {result.plan}")
else:
print("No plan found.")
30 changes: 30 additions & 0 deletions unified_planning/test/test_processes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021-2023 AIPlan4EU project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from random import shuffle
import unified_planning
from unified_planning.shortcuts import *
from unified_planning.test import unittest_TestCase


class TestProcesses(unittest_TestCase):
def setUp(self):
unittest_TestCase.setUp(self)

def test_state(self):
x = Fluent("x", BoolType())
pr = Process("Name")
pr.add_precondition(x)

self.assertNotEqual({x}, pr.preconditions)

0 comments on commit fc12ae3

Please sign in to comment.