Skip to content

Commit

Permalink
Added the translator from PDDLSharp into this project
Browse files Browse the repository at this point in the history
  • Loading branch information
kris701 committed May 11, 2024
1 parent a0832da commit 0878afc
Show file tree
Hide file tree
Showing 27 changed files with 1,510 additions and 17 deletions.
2 changes: 1 addition & 1 deletion FlashPlanner.CLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using CommandLine;
using CommandLine.Text;
using FlashPlanner.Translator;
using PDDLSharp.CodeGenerators.FastDownward.Plans;
using PDDLSharp.ErrorListeners;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Domain;
using PDDLSharp.Models.PDDL.Problem;
using PDDLSharp.Parsers.PDDL;
using PDDLSharp.Translators;

namespace FlashPlanner.CLI
{
Expand Down
5 changes: 3 additions & 2 deletions FlashPlanner.Tests/BasePlannerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PDDLSharp.ErrorListeners;
using FlashPlanner.Translator;
using PDDLSharp.ErrorListeners;
using PDDLSharp.Models;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Domain;
Expand Down Expand Up @@ -33,7 +34,7 @@ internal static SASDecl GetSASDecl(string domain, string problem)
parser.ParseAs<ProblemDecl>(new FileInfo(problem))
);

ITranslator<PDDLDecl, SASDecl> translator = new PDDLToSASTranslator();
var translator = new PDDLToSASTranslator();
var decl = translator.Translate(pddlDecl);

_declCache.Add(domain + problem, decl);
Expand Down
6 changes: 3 additions & 3 deletions FlashPlanner.Tests/FlashPlanner.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PlanVal" Version="1.0.2" />
<PackageReference Include="PlanVal" Version="1.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion FlashPlanner.Tests/Heuristics/hWeightedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using PDDLSharp;
using PDDLSharp.Models.PDDL.Domain;
using PDDLSharp.Models.SAS;
using PDDLSharp.Toolkit;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using PDDLSharp.Models.FastDownward.Plans;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Toolkit;
using PlanVal;
using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion FlashPlanner.Tests/Search/BlackBox/GreedyBFSTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using PDDLSharp.Models.FastDownward.Plans;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Toolkit;
using PlanVal;
using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion FlashPlanner.Tests/Search/Classical/GreedyBFSDHETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using PDDLSharp.Models.FastDownward.Plans;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Toolkit;
using PlanVal;
using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion FlashPlanner.Tests/Search/Classical/GreedyBFSPOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using FlashPlanner.Tests.Search.Classical;
using PDDLSharp;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Toolkit;
using PlanVal;
using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion FlashPlanner.Tests/Search/Classical/GreedyBFSTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using PDDLSharp.Models.FastDownward.Plans;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Toolkit;
using PlanVal;
using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion FlashPlanner.Tests/Search/Classical/GreedyBFSUARTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using FlashPlanner.Tests.Search.Classical;
using PDDLSharp;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Toolkit;
using PlanVal;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using FlashPlanner.Translator.Components;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Domain;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Models.PDDL.Problem;
using PDDLSharp.Translators.Grounders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PDDLSharp.Translators.Tests.Tools
{
[TestClass]
public class ConditionalDeconstructorTests
{
public static IEnumerable<object[]> DeconstructWhen_Valid()
{
yield return new object[] {
new ActionDecl(
"act",
new ParameterExp(),
new PredicateExp("a"),
new WhenExp(new PredicateExp("b"), new PredicateExp("c"))
),
2
};
yield return new object[] {
new ActionDecl(
"act",
new ParameterExp(),
new PredicateExp("a"),
new AndExp(new List<IExp>(){
new WhenExp(new PredicateExp("b"), new PredicateExp("c")),
new WhenExp(new PredicateExp("d"), new PredicateExp("e"))
})
),
4
};
yield return new object[] {
new ActionDecl(
"act",
new ParameterExp(),
new PredicateExp("a"),
new AndExp(new List<IExp>(){
new WhenExp(new PredicateExp("b"), new PredicateExp("c")),
new WhenExp(new PredicateExp("d"), new PredicateExp("e")),
new WhenExp(new PredicateExp("f"), new PredicateExp("g"))
})
),
8
};
}

[TestMethod]
[DynamicData(nameof(DeconstructWhen_Valid), DynamicDataSourceType.Method)]
public void Can_DeconstructWhen(ActionDecl input, int expectedPermutations)
{
// ARRANGE
var deconstructor = new ConditionalDeconstructor();

// ACT
var result = deconstructor.DecontructConditionals(input);

// ASSERT
Assert.AreEqual(expectedPermutations, result.Count);
}
}
}
102 changes: 102 additions & 0 deletions FlashPlanner.Tests/Translator/Components/ExistsDeconstructorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using FlashPlanner.Translator.Components;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Domain;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Models.PDDL.Problem;
using PDDLSharp.Translators.Grounders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PDDLSharp.Translators.Tests.Tools
{
[TestClass]
public class ExistsDeconstructorTests
{
public static IEnumerable<object[]> DeconstructExists_Valid()
{
yield return new object[] {
new AndExp(new List<IExp>(){
new ExistsExp(
new ParameterExp(new List<NameExp>(){ new NameExp("?a") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("?a") }))
}),
new AndExp(new List<IExp>(){
new OrExp(new List<IExp>()
{
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2") })
})
}),
new List<NameExp>(){
new NameExp("obj1"),
new NameExp("obj2"),
}
};

yield return new object[] {
new AndExp(new List<IExp>(){
new ExistsExp(
new ParameterExp(new List<NameExp>(){ new NameExp("?a") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("?a") }))
}),
new AndExp(new List<IExp>(){
new OrExp(new List<IExp>()
{
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj3") }),
})
}),
new List<NameExp>(){
new NameExp("obj1"),
new NameExp("obj2"),
new NameExp("obj3"),
}
};

yield return new object[] {
new AndExp(new List<IExp>(){
new ExistsExp(
new ParameterExp(new List<NameExp>(){ new NameExp("?a"), new NameExp("?b") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("?a"), new NameExp("?b") }))
}),
new AndExp(new List<IExp>(){
new OrExp(new List<IExp>()
{
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1"), new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1"), new NameExp("obj2") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2"), new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2"), new NameExp("obj2") }),
})
}),
new List<NameExp>(){
new NameExp("obj1"),
new NameExp("obj2"),
}
};
}

[TestMethod]
[DynamicData(nameof(DeconstructExists_Valid), DynamicDataSourceType.Method)]
public void Can_DeconstructExists(INode input, INode expected, List<NameExp> objects)
{
// ARRANGE
(input as AndExp).Children[0].Parent = input;
(expected as AndExp).Children[0].Parent = expected;
var decl = new PDDLDecl(new DomainDecl(), new ProblemDecl());
decl.Problem.Objects = new ObjectsDecl();
decl.Problem.Objects.Objs = objects;
var grounder = new ParametizedGrounder(decl);
var deconstructor = new ExistsDeconstructor(grounder);

// ACT
var result = deconstructor.DeconstructExists(input);

// ASSERT
Assert.AreEqual(expected, result);
}
}
}
102 changes: 102 additions & 0 deletions FlashPlanner.Tests/Translator/Components/ForAllDeconstructorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using FlashPlanner.Translator.Components;
using PDDLSharp.Models.PDDL;
using PDDLSharp.Models.PDDL.Domain;
using PDDLSharp.Models.PDDL.Expressions;
using PDDLSharp.Models.PDDL.Problem;
using PDDLSharp.Translators.Grounders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PDDLSharp.Translators.Tests.Tools
{
[TestClass]
public class ForAllDeconstructorTests
{
public static IEnumerable<object[]> DeconstrucForAllData_Valid()
{
yield return new object[] {
new AndExp(new List<IExp>(){
new ForAllExp(
new ParameterExp(new List<NameExp>(){ new NameExp("?a") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("?a") }))
}),
new AndExp(new List<IExp>(){
new AndExp(new List<IExp>()
{
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2") })
})
}),
new List<NameExp>(){
new NameExp("obj1"),
new NameExp("obj2"),
}
};

yield return new object[] {
new AndExp(new List<IExp>(){
new ForAllExp(
new ParameterExp(new List<NameExp>(){ new NameExp("?a") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("?a") }))
}),
new AndExp(new List<IExp>(){
new AndExp(new List<IExp>()
{
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj3") }),
})
}),
new List<NameExp>(){
new NameExp("obj1"),
new NameExp("obj2"),
new NameExp("obj3"),
}
};

yield return new object[] {
new AndExp(new List<IExp>(){
new ForAllExp(
new ParameterExp(new List<NameExp>(){ new NameExp("?a"), new NameExp("?b") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("?a"), new NameExp("?b") }))
}),
new AndExp(new List<IExp>(){
new AndExp(new List<IExp>()
{
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1"), new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj1"), new NameExp("obj2") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2"), new NameExp("obj1") }),
new PredicateExp("pred", new List<NameExp>(){ new NameExp("obj2"), new NameExp("obj2") }),
})
}),
new List<NameExp>(){
new NameExp("obj1"),
new NameExp("obj2"),
}
};
}

[TestMethod]
[DynamicData(nameof(DeconstrucForAllData_Valid), DynamicDataSourceType.Method)]
public void Can_DeconstructForAll(INode input, INode expected, List<NameExp> objects)
{
// ARRANGE
(input as AndExp).Children[0].Parent = input;
(expected as AndExp).Children[0].Parent = expected;
var decl = new PDDLDecl(new DomainDecl(), new ProblemDecl());
decl.Problem.Objects = new ObjectsDecl();
decl.Problem.Objects.Objs = objects;
var grounder = new ParametizedGrounder(decl);
var deconstructor = new ForAllDeconstructor(grounder);

// ACT
var result = deconstructor.DeconstructForAlls(input);

// ASSERT
Assert.AreEqual(expected, result);
}
}
}
Loading

0 comments on commit 0878afc

Please sign in to comment.