Skip to content

Commit

Permalink
Merge pull request #29 from hfoffani/fix-main
Browse files Browse the repository at this point in the history
Fix main
  • Loading branch information
hfoffani authored Jan 20, 2022
2 parents dc728a0 + ad4eaa4 commit e295b33
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 1,186 deletions.
66 changes: 9 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@

ANTLRDIR=/usr/local/opt/antlr
ANTLRLIB=$(ANTLRDIR)/antlr-4.7-complete.jar
ANTLR=$(ANTLRDIR)/bin/antlr4

ANTLRDIR=/usr/local/Cellar/antlr/4.9.3
ANTLRLIB=$(ANTLRDIR)/antlr-4.9.3-complete.jar
ANTLR=$(ANTLRDIR)/bin/antlr
GRUN=$(ANTLRDIR)/bin/grun

# For dotnet
NUNITVERSION=3.6.1
ANTLRNET=Antlr4.Runtime.Standard
ANTLRDLL=Antlr4.Runtime.Standard.4.7.0/lib/net35/Antlr4.Runtime.Standard.dll
DLLSPATH=../pddlnet
CSANTLR=pddlListener.cs pddlBaseListener.cs pddlLexer.cs pddlParser.cs
NUNITLIB=NUnit.$(NUNITVERSION)/lib/net45/nunit.framework.dll
NUNITLITE=NUnitLite.$(NUNITVERSION)/lib/net45/nunitlite.dll
LIBSTEST=-reference:output/$(NUNITLIB),output/$(NUNITLITE),Microsoft.CSharp,pddlnet
MONOBIN=/Library/Frameworks/Mono.framework/Commands
NUGET=$(MONOBIN)/nuget

pyversion ?= 3
ifeq ($(pyversion),3)
PIP=pip
PYTHON=python
ANTLRLANG=-Dlanguage=Python3
else
PIP=pip
PYTHON=python
ANTLRLANG=-Dlanguage=Python2 -encoding utf8
endif
PIP=pip

export CLASSPATH:=.:$(ANTLRLIB)

all: testgrammar parsers
all: testgrammar pytest

parsers: pyparser csparser

testgrammar: pddl.g4
mkdir -p tmp && \
Expand All @@ -40,7 +22,6 @@ testgrammar: pddl.g4
$(GRUN) pddl domain ../examples-pddl/domain-01.pddl && \
$(GRUN) pddl problem ../examples-pddl/problem-01.pddl


pyparser: pddl.g4
mkdir -p pddlpy && \
$(ANTLR) $(ANTLRLANG) -o pddlpy pddl.g4
Expand All @@ -50,44 +31,15 @@ pytest: pyparser pddlpy/pddl.py

pydist: pytest
$(PYTHON) setup.py bdist_wheel
$(PIP) install -e .

pypitest: pydist
$(PYTHON) setup.py register -r pypitest && \
$(PYTHON) setup.py bdist_wheel upload -r pypitest
$(PYTHON) -m twine upload --repository testpypi dist/`ls -t dist | head -1`

pypipublish: pydist
$(PYTHON) setup.py register -r pypi && \
$(PYTHON) setup.py bdist_wheel upload -r pypi
$(PYTHON) -m twine upload dist/`ls -t dist | head -1`

pydemo: pydist
cd examples-python && \
pydemo: pytest
$(PYTHON) demo.py 1 && \
$(PYTHON) demo.py 2 && \
$(PYTHON) demo.py 3

csparser: pddl.g4 pddlnet/pddl.cs
mkdir -p pddlnet && \
$(ANTLR) -Dlanguage=CSharp -package PDDLNET -o pddlnet pddl.g4 && \
(cd pddlnet && \
$(NUGET) install $(ANTLRNET) && \
$(MONOBIN)/mcs -out:pddlnet.dll -reference:$(ANTLRDLL) -t:library pddl.cs $(CSANTLR))

cstest: csparser pddlnet/pddltest.cs
(cd pddlnet && \
mkdir -p output && \
$(NUGET) install NUnitLite -Verbosity quiet -OutputDirectory output && \
$(MONOBIN)/mcs -d:NUNIT $(LIBSTEST) -out:output/pddlnettest.exe -reference:$(ANTLRDLL) -t:exe pddltest.cs && \
cp pddlnet.dll $(ANTLRDLL) output/$(NUNITLIB) output/$(NUNITLITE) output && \
cd output && \
$(MONOBIN)/mono pddlnettest.exe )

csnuget: cstest
(cd pddlnet && \
rm -f pddlnet.dll.*.nupkg && \
$(NUGET) pack pddlnet.dll.nuspec )

csnugetpublish: csnuget
(cd pddlnet && \
$(NUGET) push pddlnet.dll.*.nupkg )

34 changes: 12 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This is enough for the user to focus on the implementation of state-space or pla

The development of this tool was inspired from Univerty of Edinburgh's Artificial Intelligence Planning course by Dr. Gerhard Wickler and Prof. Austin Tate. The terms used in this API (and the API itself) closely resembles the ones proposed by the lecturers.

As of today it supports Python 3 and .NET. While project name is `pddl-lib` to emphasize its language agnosticy each target library has its own name. For Python is `pddlpy`. For .NET the library is `pddlnet.dll`.
As of today it supports Python 3.8 and up.

The orginal grammar file was authored by Zeyn Saigol from University of Birmingham. I cleaned up it, made it language agnostic and upgraded to ANTLR 4.

Expand Down Expand Up @@ -49,29 +49,29 @@ Using the library is easy.

```
~hernan$ python
Python 3.4.3 (default, Feb 25 2015, 21:28:45)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Python 3.8.0 (default, Nov 20 2019, 14:40:03)
[Clang 11.0.0 (clang-1100.0.33.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import pddlpy
>>> domprob = pddlpy.DomainProblem('domain-03.pddl', 'problem-03.pddl')
>>>
>>> domprob.initialstate()
{('adjacent', 'loc2', 'loc1'), ('unloaded', 'robr'), ('atl', 'robr', 'loc1'), ('unloaded', 'robq'), ('in', 'conta', 'loc1'), ('atl', 'robq', 'loc2'), ('adjacent', 'loc1', 'loc2'), ('in', 'contb', 'loc2')}
{('unloaded', 'robr'), ('adjacent', 'loc2', 'loc1'), ('unloaded', 'robq'), ('in', 'conta', 'loc1'), ('in', 'contb', 'loc2'), ('atl', 'robr', 'loc1'), ('atl', 'robq', 'loc2'), ('adjacent', 'loc1', 'loc2')}
>>>
>>> list( domprob.operators() )
['load', 'unload', 'move']
['move', 'load', 'unload']
>>>
>>> list( domprob.ground_operator('move') )
[<pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>, <pddlpy.pddl.Operator object at 0x10a968438>]
[<pddlpy.pddl.Operator object at 0x1089830a0>, <pddlpy.pddl.Operator object at 0x108983130>, <pddlpy.pddl.Operator object at 0x108983190>, <pddlpy.pddl.Operator object at 0x1089830d0>, <pddlpy.pddl.Operator object at 0x1089831c0>, <pddlpy.pddl.Operator object at 0x1089835b0>, <pddlpy.pddl.Operator object at 0x1089835e0>, <pddlpy.pddl.Operator object at 0x108983610>]
>>>
>>> list( domprob.ground_operator('move') )[0].precondition_pos
{('atl', 'robq', 'loc1'), ('adjacent', 'loc1', 'loc1')}
>>>
{('atl', 'robq', 'loc2'), ('adjacent', 'loc2', 'loc2')}
>>>
```
The pddl files are examples obtained from the course material.

Expand All @@ -84,18 +84,13 @@ There are wonderful material at the the University of Edinburgh:
* [Videos on YouTube](http://bit.ly/aiplanmooc)


### Using the PDDL .NET library ###

The .NET library is available from nuget as `pddlnet.dll`.


### Future development ###

* Implement the `:requirements` directive.
* Add more examples (a simple planner maybe?).
* Add more examples (time durataion, a simple planner maybe?).
* Add API documentation.
* More unit tests.
* Java version (it will be published in Java Central Repository).


### Adavanced ###
Expand All @@ -106,14 +101,12 @@ In case you want to tweak the grammar, add other target languages or modify the

* Install ANTLR version 4.
I used `brew install antlr4` (a Mac). Your mileage may vary depending on your environment.
* Install Python 3 (it works with Python 2 too).
* Install Python 3
For this I also used brew.
* Install antlr4 runtime.
`pip install antlr4-python3-runtime` (or `antlr4-python2-runtime` if building for Python 2)
`pip install antlr4-python3-runtime`
* The package is built using wheel.
`pip install wheel`
* mono development.
* Antlr4.Runtime.Standard.dll

#### Building

Expand All @@ -122,9 +115,6 @@ In case you want to tweak the grammar, add other target languages or modify the
* Run `make` (it includes tests.)
If you are using Python 2 you will need to call `make pyversion=2`.

To build the .NET library you must download the Antlr4.Runtime.Standard.dll from www.antlr4.org and
place it under the pddlnet directory. Currently it works with 4.7.0


### Contribution guidelines ###

Expand Down
24 changes: 16 additions & 8 deletions examples-python/demo.py → demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
#

import sys
from pddlpy import DomainProblem
import pddlpy
import argparse

def main(argv):
demonumber = int(argv[1])
domainfile = "../examples-pddl/domain-0%d.pddl" % demonumber
problemfile = "../examples-pddl/problem-0%d.pddl" % demonumber
domprob = DomainProblem(domainfile, problemfile)
parser = argparse.ArgumentParser(description='Demo PDDLPY.')
parser.add_argument('demonumber', metavar='N', type=int, nargs='+',
help='the number(s) of the demo')

def run_demo(demonumber):
print('===')
print(f'Run DEMO {demonumber}')
domainfile = "./examples-pddl/domain-0%d.pddl" % demonumber
problemfile = "./examples-pddl/problem-0%d.pddl" % demonumber
domprob = pddlpy.DomainProblem(domainfile, problemfile)
print()
print("DOMAIN PROBLEM")
print("objects")
Expand All @@ -47,8 +53,10 @@ def main(argv):
print( "\tpre-", o.precondition_neg )
print( "\teff+", o.effect_pos )
print( "\teff-", o.effect_neg )
print()


if __name__ == '__main__':
main(sys.argv)

args = parser.parse_args()
for n in args.demonumber:
run_demo(n)
Loading

0 comments on commit e295b33

Please sign in to comment.