Skip to content

Commit

Permalink
Merge pull request #36 from pellierd/devel
Browse files Browse the repository at this point in the history
Release PDDL4J 3.6.0
  • Loading branch information
pellierd authored Mar 27, 2018
2 parents 196b027 + 3967a25 commit ce2f2d4
Show file tree
Hide file tree
Showing 52 changed files with 5,262 additions and 965 deletions.
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
##PDDL4J library
## PDDL4J library
[![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.45971.svg)](http://dx.doi.org/10.5281/zenodo.45971)
[![Build Status](http://pddl4j.imag.fr/jenkins/job/pddl4j-base/badge/icon)](http://pddl4j.imag.fr/jenkins/job/pddl4j-base)

###1. Contact
### 1. Contact

- Damien Pellier ([email protected])
- http://lig-membres.imag.fr/pellier/

###2. Description
### 2. Description

PDDL4J is an open source library under LGPL license.

Expand All @@ -31,20 +32,20 @@ standard will have an impact on the entire field, influencing what is seen as
central and what peripheral in the development of planning systems.

The library contains:
* a PDDL 3.1 parser and all the classes need to manipulate its
* A PDDL 3.1 parser and all the classes need to manipulate its
concepts. The parser can be configured to accept only specified requirements of
PDDL language.
* a set of useful pre-processing mechanisms in order to instantiate and
* A set of useful pre-processing mechanisms in order to instantiate and
simply operators into ground actions based on inertia properties.
* a set of already implemented classical heuristics, e.g., h_ff, h_max, etc.
* several examples of planners using PDDL4J.
* A set of already implemented classical heuristics, e.g., h_ff, h_max, etc.
* Several examples of planners using PDDL4J.

###3. How to use the PDDL4J library?
### 3. How to use the PDDL4J library?

The pddl4j library is package with "gradle". If ant is not installed on your computer,
go to https://gradle.org/ and install it.

####3.1 How to build PDDL4J?
#### 3.1 How to build PDDL4J?

Type at the root of the PDDL4J distribution:
> ./gradlew build
Expand All @@ -54,21 +55,21 @@ if you want to build the project with findbug:
The jar "pddl4j-VERSION.jar" is available in the build/libs directory.

####3.3 How to use binary distribution?
#### 3.3 How to use binary distribution?

The pddl4j library can be used as a jar file called "pddl4j-VERSION.jar" in the "libs"
directory of the release. Therefore, include the jar in our classpath and enjoy
it.

####3.4 How to access the documentation?
#### 3.4 How to access the documentation?

All the documentations are contained in the doc directory.

To generate the javadoc just type:
> ./gradlew javadoc

####3.5 How to run existing planner?
#### 3.5 How to run existing planner?

Planners are available in the "planners" package of the distribution. For
instance, this archive contains a simple planner based on A* search strategy
Expand All @@ -81,3 +82,28 @@ Or use the gradle run command:
Note: A set of planning problems is available in the web site of the international
planning competition: http://ipc.icaps-conference.org.

### 4. Changelog

**PDDL4J v3.6.0**

*Planner*
* Adding Fast Forward planner
* Adding Enforced Hill Climbing planner
* Adding depth attibute in Node class
* Converting cost and heuristic in double
* Fix bugs

*Parser*
* Adding parseFromString method (it's is now possible to parse a string containing a pddl domain and/or problem)
* Refactor Parser class and fix bugs

*JUnit tests*
* Adding tests for all the planners, CodedProblem, Encoder, Parser, Plan, etc.
* Refactor and fix bugs

*Global*
* Change AdaptatorJavaJson to JsonAdapter
* Fix logger and standard outputs
* Throws uncatched exceptions
* Fix bugs
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'checkstyle'


group 'fr.uga'
version '3.5.0'
version '3.6.0'
sourceCompatibility = 1.8

repositories {
Expand Down
4 changes: 4 additions & 0 deletions config/findbugs/excludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<Match>
<Class name="fr.uga.pddl4j.parser.Parser" />
<Method name="parse" />
</Match>
<Match>
<Class name="fr.uga.pddl4j.parser.Parser" />
<Method name="parseString" />
</Match>
<Match>
<Class name="fr.uga.pddl4j.util.IntExp" />
Expand Down
1 change: 1 addition & 0 deletions src/main/java/fr/uga/pddl4j/encoding/BitEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ static BitExp encodeGoal(IntExp goal, final Map<IntExp, Integer> map) throws Une
if (goal.getConnective().equals(Connective.FALSE)) {
return null;
}

BitExp newGoal;
BitEncoding.toDNF(goal);
Encoder.codedGoal = new ArrayList<>(goal.getChildren().size());
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/fr/uga/pddl4j/encoding/CodedProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ final void setTypes(final List<String> types) {
}

/**
* TODO to remove: never used.
* Returns the type inferred. Types are inferred when the key work either is used.
*
* @return the inferredDomains
*/
final List<Set<Integer>> getInferredDomains() {
Expand All @@ -186,7 +187,7 @@ final void setInferredDomains(final List<Set<Integer>> inferredDomains) {

/**
* Returns the table of domains for each type of the problem.
* TODO to remove: never used.
*
* @return the table of domains for each type of the problem.
*/
public final List<Set<Integer>> getDomains() {
Expand Down Expand Up @@ -240,7 +241,7 @@ final void setPredicates(final List<String> predicates) {

/**
* Returns the signatures of the predicates defined in the problem.
* TODO to remove: never used.
*
* @return the signatures of the predicates defined in the problem.
*/
public final List<List<Integer>> getPredicatesSignatures() {
Expand Down Expand Up @@ -276,7 +277,7 @@ final void setFunctions(final List<String> functions) {

/**
* Returns the signatures of the functions defined in the problem.
* TODO to remove: never used.
*
* @return the signatures of the functions defined in the problem.
*/
public final List<List<Integer>> getFunctionsSignatures() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Copyright (c) 2016 by Damien Pellier <[email protected]>.
*
* This file is part of PDDL4J library.
*
* PDDL4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PDDL4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PDDL4J. If not, see <http://www.gnu.org/licenses/>
*/

package fr.uga.pddl4j.encoding;

import fr.uga.pddl4j.util.BitExp;
Expand All @@ -18,16 +37,16 @@
import java.util.List;
import java.util.stream.Collectors;


/**
* This class is used to convert Java plan into its JSON representation.
* Its also provide methods to save the JSON String into a file.
*
* @author Samy Ouastani
* @author Cedric Gerard
* @author Damien Pellier
* @version 1.0 - 07.19.2016
*/
public class AdapterPlanJavaJson {
public class JsonAdapter {

/**
* The current coded problem the plan is based on.
Expand All @@ -40,17 +59,18 @@ public class AdapterPlanJavaJson {
private JSONObject jsonPlan;

/**
* Adapter constructor.
* @param codedProblem the pddl4j problem representation
* Create a new adapter.
*
* @param codedProblem the pddl4j problem representation.
*/
public AdapterPlanJavaJson(CodedProblem codedProblem) {
public JsonAdapter(CodedProblem codedProblem) {
this.codedProblem = new CodedProblem(codedProblem);
}

/**
* Save the current jsonPlan into a file.
*
* @param name the name of the saved file
* @param name the name of the saved file.
*/
public void saveInFile(String name) {
if (jsonPlan == null) {
Expand All @@ -59,7 +79,7 @@ public void saveInFile(String name) {
// Creation of the json files
try (Writer writer = new OutputStreamWriter(new FileOutputStream(name), "UTF-8")) {
// Editing the first json file
writer.write(jsonPlan.toJSONString());
writer.write(this.jsonPlan.toJSONString());
} catch (IOException exception) {
exception.printStackTrace();
}
Expand All @@ -68,11 +88,11 @@ public void saveInFile(String name) {
/**
* Return a string of the plan in a json format.
*
* @param plan to convert into json string
* @return the plan in a json string format
* @param plan to convert into json string.
* @return the plan in a json string format.
*/
@SuppressWarnings("unchecked")
public final String toStringJ(final Plan plan) {
public final String toJsonString(final Plan plan) {

JSONObject planJson = new JSONObject();

Expand All @@ -89,12 +109,12 @@ public final String toStringJ(final Plan plan) {
for (int j = 0; j < action.getArity(); j++) {
final int index = action.getValueOfParameter(j);
if (index != -1) {
parameters.add(codedProblem.getConstants().get(index));
parameters.add(this.codedProblem.getConstants().get(index));
}
}

// Preconditions
ArrayList<ArrayList<String>> preconds = this.toStringJ(action.getPreconditions());
ArrayList<ArrayList<String>> preconds = this.toJsonString(action.getPreconditions());
JSONObject precondJson = new JSONObject();

ArrayList<String> positives = preconds.get(0);
Expand All @@ -119,7 +139,7 @@ public final String toStringJ(final Plan plan) {
JSONObject expJsonEffects = new JSONObject();

ArrayList<ArrayList<String>> condExpElementsCondition =
this.toStringJ(condExp.get(k).getCondition());
this.toJsonString(condExp.get(k).getCondition());

JSONArray positivesConditionJson = listToJson(condExpElementsCondition.get(0));
JSONArray negativesConditionJson = listToJson(condExpElementsCondition.get(1));
Expand All @@ -128,7 +148,7 @@ public final String toStringJ(final Plan plan) {
expJsonCondition.put("Positives", positivesConditionJson);
expJsonCondition.put("Negatives", negativesConditionJson);

ArrayList<ArrayList<String>> condExpElementsEffect = this.toStringJ(condExp.get(k).getEffects());
ArrayList<ArrayList<String>> condExpElementsEffect = this.toJsonString(condExp.get(k).getEffects());

JSONArray positivesEffectJson = listToJson(condExpElementsEffect.get(0));
JSONArray negativesEffectJson = listToJson(condExpElementsEffect.get(1));
Expand Down Expand Up @@ -159,35 +179,38 @@ public final String toStringJ(final Plan plan) {
}
}

jsonPlan = planJson;
this.jsonPlan = planJson;
return planJson.toJSONString();
}

/**
* Convert a BitExp into a String collection.
*
* @param exp the BitExp instance to convert
* @return an 2D collection of Strings
* @param exp the BitExp instance to convert.
* @return an 2D collection of Strings.
*/
private ArrayList<ArrayList<String>> toStringJ(BitExp exp) {
return AdapterPlanJavaJson.toStringJ(exp, codedProblem.getConstants(), codedProblem.getTypes(),
codedProblem.getPredicates(), codedProblem.getFunctions(), codedProblem.getRelevantFacts());
private ArrayList<ArrayList<String>> toJsonString(final BitExp exp) {
return JsonAdapter.toJsonString(exp, this.codedProblem.getConstants(), this.codedProblem.getTypes(),
this.codedProblem.getPredicates(), this.codedProblem.getFunctions(), this.codedProblem.getRelevantFacts());
}

/**
* Convert a BitExp into a String collection.
*
* @param exp the BitExp instance to convert
* @param constants the constants of the problem
* @param types the types of the problem
* @param predicates the predicates of the problem
* @param functions the functions of the problem
* @param relevants the facts of the problem
* @return an 2D collection of Strings
* @param exp the BitExp instance to convert.
* @param constants the constants of the problem.
* @param types the types of the problem.
* @param predicates the predicates of the problem.
* @param functions the functions of the problem.
* @param relevants the facts of the problem.
* @return an 2D collection of Strings.
*/
private static ArrayList<ArrayList<String>> toStringJ(BitExp exp, final List<String> constants,
final List<String> types, final List<String> predicates,
final List<String> functions, final List<IntExp> relevants) {
private static ArrayList<ArrayList<String>> toJsonString(final BitExp exp,
final List<String> constants,
final List<String> types,
final List<String> predicates,
final List<String> functions,
final List<IntExp> relevants) {
ArrayList<String> fluentsPos = new ArrayList<>();
ArrayList<String> fluentsNeg = new ArrayList<>();
ArrayList<ArrayList<String>> fluents = new ArrayList<>();
Expand All @@ -208,10 +231,10 @@ private static ArrayList<ArrayList<String>> toStringJ(BitExp exp, final List<Str
}

/**
* Method that transform an ArrayList into a JSONArray.
* Transform an ArrayList into a JSONArray.
*
* @param list an ArrayList that we want to convert into a List.
* @return list the list parameter
* @return list the list parameter.
*/
private static JSONArray listToJson(List<String> list) {
return list.stream().collect(Collectors.toCollection(JSONArray::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ static void simplyOperatorsWithGroundInertia(final List<IntOp> operators, final
*/
static void simplifyGoalWithGroundInertia(final IntExp goal, final Set<IntExp> init) {
PostInstantiation.simplifyWithGroundInertia(goal, false, init);
PostInstantiation.simplify(goal);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/fr/uga/pddl4j/encoding/PreInstantiation.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ static void inferTypesFromInertia(final Set<IntExp> init) {
if (Encoder.tableOfTypedPredicates.get(i).size() == 1
&& Encoder.tableOfInertia.get(i).equals(Inertia.INERTIA)) {
final Set<Integer> newTypeDomain = new LinkedHashSet<>();
for (final IntExp fact : init) {
for (IntExp fact : init) {
if (fact.getConnective().equals(Connective.NOT)) {
fact = fact.getChildren().get(0);
}
if (fact.getPredicate() == i) {
newTypeDomain.add(fact.getArguments()[0]);
}
Expand Down Expand Up @@ -230,7 +233,10 @@ static void createPredicatesTables(final Set<IntExp> init) {
Encoder.predicatesTables.add(pTables);
}

for (final IntExp fact : init) {
for (IntExp fact : init) {
if (fact.getConnective().equals(Connective.NOT)) {
fact = fact.getChildren().get(0);
}
final int arity = Encoder.tableOfTypedPredicates.get(fact.getPredicate()).size();
final List<IntMatrix> pTables = Encoder.predicatesTables.get(fact.getPredicate());
final int[] set = new int[arity];
Expand Down
Loading

0 comments on commit ce2f2d4

Please sign in to comment.