Skip to content

Commit

Permalink
Merge pull request #50 from pellierd/devel
Browse files Browse the repository at this point in the history
Release PDDL4J 3.7.1
  • Loading branch information
Emmanuel Hermellin committed Jul 3, 2018
2 parents 4fb1214 + 6330ca8 commit 11a1f8b
Show file tree
Hide file tree
Showing 13 changed files with 516 additions and 14 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Planners are available in the "planners" package of the distribution. For
instance, this archive contains a simple planner based on A* search strategy
called HSP. To launch this planner use the following command line:

> java -javaagent:build/libs/pddl4j-3.7.0.jar -server -Xms2048m -Xmx2048m fr.uga.pddl4j.planners.statespace.StateSpacePlannerFactory -o pddl/blocksworld/domain.pddl -f pddl/blocksworld/p15.pddl
> java -javaagent:build/libs/pddl4j-3.7.1.jar -server -Xms2048m -Xmx2048m fr.uga.pddl4j.planners.statespace.StateSpacePlannerFactory -o pddl/blocksworld/domain.pddl -f pddl/blocksworld/p15.pddl
> java -jar build/libs/pddl4j-3.7.0.jar -o pddl/blocksworld/domain.pddl -f pddl/blocksworld/p15.pddl
> java -jar build/libs/pddl4j-3.7.1.jar -o pddl/blocksworld/domain.pddl -f pddl/blocksworld/p15.pddl
Or use the gradle run command:
> gradle run -PArgs=-o,pddl/blocksworld/domain.pddl,-f,pddl/blocksworld/p15.pddl
Expand All @@ -94,6 +94,16 @@ https://doi.org/10.1080/0952813X.2017.1409278
### 5. Changelog

**PDDL4J v3.7.1**

*State space strategy*
* Add Breadth First Search and Depth First Search
* Add associated JUnit tests

*Global*
* Add CLI script to launch PDDL4J
* Patch PDDL4J for Java 10

**PDDL4J v3.7.0**

*Update project tools*
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'findbugs'
apply plugin: 'checkstyle'

group 'fr.uga'
version '3.7.0'
version '3.7.1'
sourceCompatibility = 1.8

repositories {
Expand Down Expand Up @@ -57,7 +57,7 @@ jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version,
'Gradle-Version':'Gradle 4.7',
'Gradle-Version':'Gradle 4.8',
'Built-By': 'Damien Pellier',
'Premain-Class': 'fr.uga.pddl4j.util.MemoryAgent',
'Main-Class': 'fr.uga.pddl4j.planners.statespace.StateSpacePlannerFactory'
Expand All @@ -75,7 +75,7 @@ task run (type: JavaExec, dependsOn: build){

jvmArgs = ["-javaagent:"+project.buildDir.name+"/libs/"+project.name+"-"+project.version+".jar", "-server", "-Xms2048m", "-Xmx2048m"]

description = "Run HSP plannin algorithm"
description = "Run HSP planning algorithm"
main = "fr.uga.pddl4j.planners.statespace.StateSpacePlannerFactory"
classpath = sourceSets.main.runtimeClasspath
}
Expand Down
154 changes: 154 additions & 0 deletions pddl4j.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/bin/bash

pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}

build(){
./gradlew jar
pause
}

solveHSP(){
read -p "Enter domain file [path to the file]: " domainFile
read -p "Enter problem file [path to the file]: " problemFile
read -p "Timeout [int]: " timeOut

show_heuristic

read -p "Choose heuristic [0 - 8]: " heuristic

java -javaagent:build/libs/pddl4j-3.7.1.jar -server -Xms2048m -Xmx2048m fr.uga.pddl4j.planners.statespace.StateSpacePlannerFactory -p 0 -o $domainFile -f $problemFile -t $timeOut -u $heuristic

pause
}

solveFF(){
read -p "Enter domain file [path to the file]: " domainFile
read -p "Enter problem file [path to the file]: " problemFile
read -p "Timeout [int]: " timeOut

show_heuristic

read -p "Choose heuristic [0 - 8]: " heuristic

java -javaagent:build/libs/pddl4j-3.7.1.jar -server -Xms2048m -Xmx2048m fr.uga.pddl4j.planners.statespace.StateSpacePlannerFactory -p 1 -o $domainFile -f $problemFile -t $timeOut -u $heuristic

pause
}

about() {
show_title
echo ""
echo "PDDL4J is an open source library under LGPL license."
echo ""
echo "The purpose of PDDL4J is to facilitate the development of JAVA tools for Automated Planning based on PDDL language (Planning Domain Description Language). Automated planning and scheduling, in the relevant literature often denoted as simply planning, is a branch of artificial intelligence that concerns the realization of strategies or action sequences, typically for execution by intelligent agents, autonomous robots and unmanned vehicles."
echo ""
echo "PDDL was originally developed by Drew McDermott and the 1998 planning competition committee. It was inspired by the need to encourage the empirical comparison of planning systems and the exchange of planning benchmarks within the community. Its development improved the communication of research results and triggered an explosion in performance, expressivity and robustness of planning systems."
echo ""
echo "PDDL has become a de facto standard language for describing planning domains, not only for the competition but more widely, as it offers an opportunity to carry out empirical evaluation of planning systems on a growing collection of generally adopted standard benchmark domains. The emergence of a language standard will have an impact on the entire field, influencing what is seen as central and what peripheral in the development of planning systems."
pause
}

clean() {
./gradlew clean
pause
}

show_title() {
clear
echo " _____ ____ ____ __ ___ __ "
echo "| _ | \| \| | | | |__| |"
echo "| __| | | | | |__|_ | | |"
echo "|__| |____/|____/|_____| |_|_____|"
}

show_status() {
echo "|"
echo "| PDDL4J `awk '/^version/' build.gradle`"
if [ -d build/libs ]; then
echo -e "| PDDL4J status [\e[92mBuilt\e[39m]"
echo "|"
echo " ----------"
else
echo -e "| PDDL4J status [\e[91mNot built\e[39m]"
echo "|"
echo " ----------"
fi
}

show_menus_l() {
echo "| 0. Build jar"
echo "| ..."
echo "| 4. About"
echo "| 5. Exit"
echo " ----------"
}

read_options_l(){
local choice
read -p "Enter choice [0 - 5] : " choice
case $choice in
0) build ;;
4) about ;;
5) exit 0;;
*) echo "Error..." && sleep 1
esac
}

show_menus() {
echo "| 0. Build jar"
echo "| 1. Solve with HSP"
echo "| 2. Solve with FF"
echo "| 3. Clean"
echo "| 4. About"
echo "| 5. Exit"
echo " ----------"
}

show_heuristic() {
echo "0. ff heuristic"
echo "1. sum heuristic"
echo "2. sum mutex heuristic"
echo "3. djusted sum heuristic"
echo "4. adjusted sum 2 heuristic"
echo "5. adjusted sum 2M heuristic"
echo "6. combo heuristic"
echo "7. max heuristic"
echo "8. set-level heuristic"
}

read_options(){
local choice
read -p "Enter choice [0 - 5] : " choice
case $choice in
0) build ;;
1) solveHSP ;;
2) solveFF ;;
3) clean ;;
4) about ;;
5) exit 0;;
*) echo "Error..." && sleep 1
esac
}

# ----------------------------------------------
# Trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP

# -----------------------------------
# Main logic - infinite loop
# ------------------------------------
while true
do
show_title
show_status
if [ -d build/libs ]; then
show_menus
read_options
else
show_menus_l
read_options_l
fi
done
7 changes: 4 additions & 3 deletions src/main/java/fr/uga/pddl4j/encoding/JsonAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.stream.Collectors;

/**
* This class is used to convert Java plan into its JSON representation.
Expand Down Expand Up @@ -241,8 +240,10 @@ private static ArrayList<ArrayList<String>> toJsonString(final BitExp exp,
* @param list an ArrayList that we want to convert into a List.
* @return list the list parameter.
*/
@SuppressWarnings("unchecked")
private static JSONArray listToJson(List<String> list) {
return list.stream().collect(Collectors.toCollection(JSONArray::new));
final JSONArray array = new JSONArray();
array.addAll(list);
return array;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ public AbstractStateSpaceStrategy() {
resetNodesStatistics();
}

/**
* Create a new search strategy.
*
* @param timeout the time out of the planner.
*/
public AbstractStateSpaceStrategy(int timeout) {
super();
this.heuristic = StateSpacePlanner.DEFAULT_HEURISTIC;
this.weight = StateSpacePlanner.DEFAULT_WEIGHT;
this.timeout = timeout;
this.searchingTime = 0;
this.memoryUsed = 0;
resetNodesStatistics();
}

/**
* Create a new search strategy.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2016 by Damien Pellier <Damien.Pellier@imag.fr>.
*
* 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.planners.statespace.search.strategy;

import fr.uga.pddl4j.encoding.CodedProblem;
import fr.uga.pddl4j.util.BitOp;
import fr.uga.pddl4j.util.BitState;
import fr.uga.pddl4j.util.MemoryAgent;

import java.util.LinkedList;
import java.util.Objects;

/**
* This class implements Breadth First Search strategy.
*
* @author E. Hermellin
* @version 1.0 - 22.06.2018
*/
public final class BreadthFirstSearch extends AbstractStateSpaceStrategy {

/**
* The serial id of the class.
*/
private static final long serialVersionUID = 1L;

/**
* Creates a new Greedy best First Search search strategy with default parameters.
*/
public BreadthFirstSearch() {
super();
}

/**
* Creates a new Greedy best First Search search strategy.
*
* @param timeout the time out of the planner.
*/
public BreadthFirstSearch(int timeout) {
super(timeout);
}

/**
* The greedy best first search algorithm. Solves the planning problem and returns the first solution plan found.
* This method must be completed.
*
* @param codedProblem the problem to be solved. The problem cannot be null.
* @return a solution plan or null if it does not exist.
*/
public Node search(final CodedProblem codedProblem) {
Objects.requireNonNull(codedProblem);
final long begin = System.currentTimeMillis();

final LinkedList<Node> closeSet = new LinkedList<>();
final LinkedList<Node> openSet = new LinkedList<>();
final int timeout = getTimeout();

BitState init = new BitState(codedProblem.getInit());
Node root = new Node(init, null, 0, 0, 0);
root.setDepth(0);
openSet.add(root);

this.resetNodesStatistics();
Node solution = null;
long searchingTime = 0;
while (!openSet.isEmpty() && solution == null && searchingTime < timeout) {
// Pop the first node in the pending list open
final Node current = openSet.pollFirst();

if (current.satisfy(codedProblem.getGoal())) {
solution = current;
} else {
closeSet.add(current);
int index = 0;
for (BitOp op : codedProblem.getOperators()) {

// Test if a specified operator is applicable in the current state
if (op.isApplicable(current)) {
final BitState nextState = new BitState(current);
nextState.or(op.getCondEffects().get(0).getEffects().getPositive());
nextState.andNot(op.getCondEffects().get(0).getEffects().getNegative());

// Apply the effect of the applicable operator
final Node successor = new Node(nextState);
this.setCreatedNodes(this.getCreatedNodes() + 1);
successor.setCost(current.getCost() + op.getCost());
successor.setHeuristic(0);
successor.setParent(current);
successor.setOperator(index);
successor.setDepth(current.getDepth() + 1);

if (!closeSet.contains(successor) && !openSet.contains(successor)) {
openSet.addLast(successor);
}
}
index++;
}
}
// Take time to compute the searching time
long end = System.currentTimeMillis();
searchingTime = end - begin;
}

this.setExploredNodes(closeSet.size());
this.setPendingNodes(openSet.size());
this.setMemoryUsed(MemoryAgent.getDeepSizeOf(closeSet) + MemoryAgent.getDeepSizeOf(openSet));
this.setSearchingTime(searchingTime);

return solution;
}
}

0 comments on commit 11a1f8b

Please sign in to comment.