-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Enrico Scala
committed
Oct 9, 2024
1 parent
3ba5fe8
commit fc12ae3
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |