Skip to content

Commit

Permalink
fix(interpreted functions): work in progress - test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Sep 18, 2024
1 parent e3565ff commit f50081e
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 50 deletions.
16 changes: 4 additions & 12 deletions unified_planning/model/walkers/simplifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,19 @@ def walk_interpreted_function_exp( # code here is not clean but should work
newlist.append(v)
constantval = expression.interpreted_function().function(*newlist)
if expression.interpreted_function().return_type.is_bool_type():
constantval = self.manager.Bool(
(expression.interpreted_function().function(*newlist))
)
constantval = self.manager.Bool((constantval))

elif expression.interpreted_function().return_type.is_int_type():

constantval = self.manager.Int(
(expression.interpreted_function().function(*newlist))
)
constantval = self.manager.Int((constantval))
elif expression.interpreted_function().return_type.is_real_type():

constantval = self.manager.Real(
(expression.interpreted_function().function(*newlist))
)
constantval = self.manager.Real((constantval))
elif (
expression.interpreted_function().return_type.is_user_type()
): # not sure this works and idk how to check

constantval = self.manager.ObjectExp(
(expression.interpreted_function().function(*newlist))
)
constantval = self.manager.ObjectExp((constantval))
else:
return new_exp
return constantval
Expand Down
38 changes: 0 additions & 38 deletions unified_planning/test/examples/minimals.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,42 +551,4 @@ def get_example_problems():
],
)

# interpreted functions in durations

problem = Problem("interpreted_functions_in_durations")

def callableFun(
israining, basetime
): # if it rains you will take longer to walk home
r = basetime
if israining:
r = basetime * 1.4
return r

signature = OrderedDict()
signature["israining"] = BoolType()
signature["basetime"] = IntType()
funx = InterpretedFunction("funx", RealType(), signature, callableFun)
athome = Fluent("athome")
rain = Fluent("rain")
normaltime = Fluent("normaltime", IntType(0, 20))
gohome = DurativeAction("gohome")
gohome.add_condition(StartTiming(), Not(athome))
gohome.add_effect(EndTiming(), athome, True)
gohome.set_fixed_duration(funx(rain, normaltime))
problem = Problem("IF_in_durations")
problem.add_fluent(athome)
problem.add_fluent(rain)
problem.add_fluent(normaltime)
problem.add_action(gohome)
problem.set_initial_value(athome, False)
problem.set_initial_value(rain, True)
problem.set_initial_value(normaltime, 10)
problem.add_goal(athome)

problems["interpreted_functions_in_durations"] = TestCase(
problem=problem,
solvable=True,
) # solvable=True, valid_plans=[up.plans.SequentialPlan([gohome])]

return problems
21 changes: 21 additions & 0 deletions unified_planning/test/test_anytime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

import os

import pytest
import unified_planning as up
from unified_planning.shortcuts import *
from unified_planning.model.problem_kind import (
Expand All @@ -37,6 +39,25 @@ class TestAnytimePlanning(unittest_TestCase):
simple_numeric_kind.union(quality_metrics_kind),
up.engines.AnytimeGuarantee.INCREASING_QUALITY,
)
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="takes a alot of time to test")#this fails now even without adding if problems to minimals
def test_counters(self):
reader = PDDLReader()
domain_filename = os.path.join(PDDL_DOMAINS_PATH, "counters", "domain.pddl")
Expand Down
78 changes: 78 additions & 0 deletions unified_planning/test/test_htn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import os
import tempfile

import pytest

import unified_planning as up
from unified_planning.io import PDDLReader, PDDLWriter
from unified_planning.model.htn import TaskNetwork, Task
Expand All @@ -32,6 +34,25 @@ def setUp(self):
unittest_TestCase.setUp(self)
self.problems = get_example_problems()

# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="takes a alot of time to test")
def test_htn_problem_creation(self):
problems = examples.hierarchical.get_example_problems()
problem = problems["htn-go"].problem
Expand Down Expand Up @@ -62,6 +83,25 @@ def test_htn_problem_creation(self):
in self.problems["htn-go-temporal"].problem.kind.features
)

# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="takes a alot of time to test")
def test_ordering(self):
"""Checks that we detect the right orderings in task networks"""

Expand Down Expand Up @@ -127,6 +167,25 @@ def assert_temporal(tn):
tn.add_constraint(c)
assert_temporal(tn)

# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="takes a alot of time to test")
def test_hddl_parsing(self):
"""Tests that all HDDL benchmarks are successfully parsed."""
hddl_dir = os.path.join(FILE_PATH, "hddl")
Expand Down Expand Up @@ -157,6 +216,25 @@ def test_hddl_parsing(self):
or name in TO_instances
)

# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="takes a alot of time to test")
def test_hddl_writing(self):
"""Tests that all HDDL benchmarks can be written to HDDL and reparsed."""
hddl_dir = os.path.join(FILE_PATH, "hddl")
Expand Down
59 changes: 59 additions & 0 deletions unified_planning/test/test_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from typing import Callable
import warnings

import pytest
import unified_planning as up
from unified_planning.shortcuts import *
from unified_planning.model.problem_kind import (
Expand Down Expand Up @@ -95,6 +97,25 @@ def test_basic_parameters(self):
self.assertTrue(val_res)

@skipIfEngineNotAvailable("tamer")
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="this one causes deadlock!!! - point 4")
def test_basic_parallel(self):
problem = self.problems["basic"].problem
a = problem.action("a")
Expand Down Expand Up @@ -150,6 +171,25 @@ def test_basic_oversubscription(self):
self.assertEqual(len(plan.actions[0].actual_parameters), 0)

@skipIfEngineNotAvailable("tamer")
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="this one causes deadlock!!! - case 4 - ?")
def test_basic_oversubscription_parallel(self):
problem = self.problems["basic_oversubscription"].problem
a = problem.action("a")
Expand All @@ -169,6 +209,25 @@ def test_basic_oversubscription_parallel(self):
self.assertEqual(len(plan.actions[0].actual_parameters), 0)

@skipIfEngineNotAvailable("tamer")
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# the following skip MUST BE REMOVED
# @pytest.mark.skip(reason="this one causes deadlock!!! - point 15")
def test_timed_connected_locations_parallel(self):
problem = self.problems["timed_connected_locations"].problem
move = problem.action("move")
Expand Down

0 comments on commit f50081e

Please sign in to comment.