├── script ├── build.sh └── runtests.sh ├── .gitignore ├── minicppunit ├── MiniCppUnit.h ├── MiniCppUnit.cpp └── runner.cpp ├── examples └── parser │ ├── SConscript │ └── parser.cpp ├── tests ├── SConscript ├── expected │ ├── Log_ins.pddl │ ├── Sched_ins.pddl │ ├── Log_dom.pddl │ ├── Mapana_ins.pddl │ ├── Mapana_dom.pddl │ ├── Elev_dom.pddl │ ├── Sched_dom.pddl │ └── Elev_ins.pddl └── DomainTests.cpp ├── parser ├── ParamCond.cpp ├── GroundFunc.h ├── Equals.h ├── EitherType.h ├── Function.h ├── Not.cpp ├── Function.cpp ├── Lifted.cpp ├── Task.h ├── TypeGround.h ├── Lifted.h ├── Equals.cpp ├── And.cpp ├── Oneof.cpp ├── Condition.h ├── CondIter.h ├── ParamCond.h ├── Exists.h ├── Forall.h ├── Not.h ├── Ground.h ├── Derived.h ├── When.cpp ├── Or.cpp ├── Or.h ├── When.h ├── And.h ├── Oneof.h ├── Exists.cpp ├── Forall.cpp ├── Ground.cpp ├── Derived.cpp ├── TypeGround.cpp ├── GroundFunc.cpp ├── Action.h ├── TokenStruct.h ├── FunctionModifier.cpp ├── TemporalAction.h ├── FunctionModifier.h ├── Expression.cpp ├── Basic.h ├── Action.cpp ├── Type.h ├── Filereader.h ├── Expression.h ├── TemporalAction.cpp ├── Instance.h └── Domain.h ├── domains ├── Log_ins.pddl ├── Sched_ins.pddl ├── Log_dom.pddl ├── Elev_dom.pddl ├── Mapana_ins.pddl ├── Mapana_dom.pddl ├── Sched_dom.pddl └── Elev_ins.pddl ├── .travis.yml ├── SConstruct ├── README.md └── LICENSE /script/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e # halt script on error 3 | 4 | scons 5 | scons test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | build 3 | lib 4 | .sconsign.dblite 5 | valgrind.txt 6 | ins.txt 7 | *.bin 8 | *.o 9 | -------------------------------------------------------------------------------- /minicppunit/MiniCppUnit.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aig-upf/universal-pddl-parser/HEAD/minicppunit/MiniCppUnit.h -------------------------------------------------------------------------------- /minicppunit/MiniCppUnit.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aig-upf/universal-pddl-parser/HEAD/minicppunit/MiniCppUnit.cpp -------------------------------------------------------------------------------- /minicppunit/runner.cpp: -------------------------------------------------------------------------------- 1 | #include "MiniCppUnit.h" 2 | 3 | int main() 4 | { 5 | return TestFixtureFactory::theInstance().runTests() ? 0 : -1; 6 | } 7 | -------------------------------------------------------------------------------- /script/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e # halt script on error 3 | 4 | valgrind -q --leak-check=yes --log-file="valgrind.txt" ./tests/test.bin -------------------------------------------------------------------------------- /examples/parser/SConscript: -------------------------------------------------------------------------------- 1 | 2 | import glob 3 | 4 | Import('extra') 5 | 6 | program = extra.Program( "parser.bin", glob.glob( "./*.cpp" )) 7 | 8 | extra.Alias('parser', program) 9 | -------------------------------------------------------------------------------- /tests/SConscript: -------------------------------------------------------------------------------- 1 | 2 | # Build the testing binaries 3 | 4 | import glob 5 | 6 | Import('extra') 7 | 8 | sources = glob.glob( "./*.cpp" ) 9 | sources += glob.glob( "../minicppunit/*.cpp" ) 10 | 11 | test = extra.Program( "test.bin", sources) 12 | #env.Depends( test, env ) 13 | #extra.Append(LIBPATH=['../lib']) 14 | 15 | extra.Alias( 'test', test ) 16 | -------------------------------------------------------------------------------- /examples/parser/parser.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | 6 | using namespace parser::pddl; 7 | 8 | int main( int argc, char *argv[] ) { 9 | if ( argc < 3 ) { 10 | std::cout << "Usage: ./Domain \n"; 11 | exit( 1 ); 12 | } 13 | 14 | // Read multiagent domain and instance 15 | Domain domain( argv[1] ); 16 | Instance instance( domain, argv[2] ); 17 | 18 | std::cout << domain << std::endl; 19 | std::cout << instance << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /parser/ParamCond.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void ParamCond::printParams( unsigned first, std::ostream & s, TokenStruct< std::string > & ts, const Domain & d ) const { 7 | s << "("; 8 | for ( unsigned i = first; i < params.size(); ++i ) { 9 | std::stringstream ss; 10 | ss << "?" << d.types[params[i]]->getName() << ts.size(); 11 | ts.insert( ss.str() ); 12 | s << " " << ss.str(); 13 | if ( d.typed ) s << " - " << d.types[params[i]]->name; 14 | } 15 | s << " )\n"; 16 | } 17 | 18 | } } // namespaces 19 | -------------------------------------------------------------------------------- /domains/Log_ins.pddl: -------------------------------------------------------------------------------- 1 | (define (problem logistics-4-0) 2 | (:domain logistics) 3 | (:objects 4 | apn1 - airplane 5 | apt1 apt2 - airport 6 | pos2 pos1 - location 7 | cit2 cit1 - city 8 | tru2 tru1 - truck 9 | obj23 obj22 obj21 obj13 obj12 obj11 - package) 10 | 11 | (:init (at apn1 apt2) (at tru1 pos1) (at obj11 pos1) 12 | (at obj12 pos1) (at obj13 pos1) (at tru2 pos2) (at obj21 pos2) (at obj22 pos2) 13 | (at obj23 pos2) (in-city pos1 cit1) (in-city apt1 cit1) (in-city pos2 cit2) 14 | (in-city apt2 cit2)) 15 | 16 | (:goal (and (at obj11 apt1) (at obj23 pos1) (at obj13 apt1) (at obj21 pos1))) 17 | ) -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: cpp 3 | 4 | before_script: 5 | - chmod +x ./script/build.sh 6 | - chmod +x ./script/runtests.sh 7 | 8 | # Build against both compilers 9 | compiler: 10 | # - clang 11 | - gcc 12 | 13 | install: 14 | - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi 15 | 16 | addons: 17 | apt: 18 | sources: 19 | - ubuntu-toolchain-r-test 20 | packages: 21 | - gcc-4.8 22 | - g++-4.8 23 | - clang 24 | - valgrind 25 | 26 | script: ./script/build.sh && ./script/runtests.sh 27 | 28 | sudo: false # route your build to the container-based infrastructure for a faster build 29 | -------------------------------------------------------------------------------- /parser/GroundFunc.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "TypeGround.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | template < typename T > 9 | class GroundFunc : public TypeGround { 10 | 11 | public: 12 | 13 | T value; 14 | 15 | GroundFunc() 16 | : TypeGround(), value( 0 ) {} 17 | 18 | GroundFunc( Lifted * l, const T & val = T( 0 ) ) 19 | : TypeGround( l ), value( val ) {} 20 | 21 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 22 | 23 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 24 | 25 | }; 26 | 27 | } } // namespaces 28 | -------------------------------------------------------------------------------- /parser/Equals.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Ground.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Equals : public Ground { 9 | 10 | public: 11 | 12 | Equals( const IntVec & p = IntVec() ) 13 | : Ground( "=", p ) {} 14 | 15 | Equals( const Equals * e ) 16 | : Ground( "=", e->params ) {} 17 | 18 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 19 | 20 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 21 | 22 | Condition * copy( Domain & d ) { 23 | return new Equals( this ); 24 | } 25 | 26 | }; 27 | 28 | } } // namespaces 29 | -------------------------------------------------------------------------------- /parser/EitherType.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Type.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class EitherType : public Type { 9 | 10 | public: 11 | 12 | EitherType( const std::string & s ) 13 | : Type( s ) {} 14 | 15 | EitherType( const EitherType * t ) 16 | : Type( t ) {} 17 | 18 | std::string getName() const { 19 | std::string out = "EITHER"; 20 | for ( unsigned i = 0; i < subtypes.size(); ++i ) 21 | out += "_" + subtypes[i]->getName(); 22 | return out; 23 | } 24 | 25 | void PDDLPrint( std::ostream & s ) const override {} 26 | 27 | Type * copy() { 28 | return new EitherType( this ); 29 | } 30 | 31 | }; 32 | 33 | } } // namespaces 34 | -------------------------------------------------------------------------------- /parser/Function.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Lifted.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Function : public Lifted { 9 | 10 | public: 11 | 12 | int returnType; 13 | 14 | Function() 15 | : Lifted(), returnType( -1 ) {} 16 | 17 | Function( const std::string & s, int type = -1 ) 18 | : Lifted( s ), returnType( type ) {} 19 | 20 | Function( const ParamCond * c ) 21 | : Lifted( c ), returnType( -1 ) {} 22 | 23 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 24 | 25 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 26 | 27 | }; 28 | 29 | } } // namespaces 30 | -------------------------------------------------------------------------------- /parser/Not.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Not::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( NOT "; 9 | if ( cond ) cond->PDDLPrint( s, 0, ts, d ); 10 | s << " )"; 11 | } 12 | 13 | void Not::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 14 | f.next(); 15 | f.assert_token( "(" ); 16 | 17 | cond = dynamic_cast< Ground * >( d.createCondition( f ) ); 18 | 19 | if ( !cond ) { 20 | f.tokenExit( f.getToken() ); 21 | } 22 | 23 | cond->parse( f, ts, d ); 24 | 25 | f.next(); 26 | f.assert_token( ")" ); 27 | } 28 | 29 | 30 | } } // namespaces 31 | -------------------------------------------------------------------------------- /parser/Function.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Function::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | Lifted::PDDLPrint( s, indent, ts, d ); 8 | if ( returnType >= 0 ) s << " - " << d.types[returnType]->name; 9 | } 10 | 11 | void Function::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 12 | Lifted::parse( f, ts, d ); 13 | 14 | f.next(); 15 | if ( f.getChar() == '-' ) { 16 | f.assert_token( "-" ); 17 | std::string s = f.getToken(); 18 | if ( s != "NUMBER" ) { 19 | f.c -= s.size(); 20 | returnType = d.types.index( f.getToken( d.types ) ); 21 | } 22 | } 23 | } 24 | 25 | } } // namespaces 26 | -------------------------------------------------------------------------------- /tests/expected/Log_ins.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( PROBLEM LOGISTICS-4-0 ) 2 | ( :DOMAIN LOGISTICS ) 3 | ( :OBJECTS 4 | TRU2 TRU1 - TRUCK 5 | APN1 - AIRPLANE 6 | OBJ23 OBJ22 OBJ21 OBJ13 OBJ12 OBJ11 - PACKAGE 7 | APT1 APT2 - AIRPORT 8 | POS2 POS1 - LOCATION 9 | CIT2 CIT1 - CITY 10 | ) 11 | ( :INIT 12 | ( AT APN1 APT2 ) 13 | ( AT TRU1 POS1 ) 14 | ( AT OBJ11 POS1 ) 15 | ( AT OBJ12 POS1 ) 16 | ( AT OBJ13 POS1 ) 17 | ( AT TRU2 POS2 ) 18 | ( AT OBJ21 POS2 ) 19 | ( AT OBJ22 POS2 ) 20 | ( AT OBJ23 POS2 ) 21 | ( IN-CITY POS1 CIT1 ) 22 | ( IN-CITY APT1 CIT1 ) 23 | ( IN-CITY POS2 CIT2 ) 24 | ( IN-CITY APT2 CIT2 ) 25 | ) 26 | ( :GOAL 27 | ( AND 28 | ( AT OBJ11 APT1 ) 29 | ( AT OBJ23 POS1 ) 30 | ( AT OBJ13 APT1 ) 31 | ( AT OBJ21 POS1 ) 32 | ) 33 | ) 34 | ) 35 | -------------------------------------------------------------------------------- /parser/Lifted.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Lifted::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( " << name; 9 | for ( unsigned i = 0; i < params.size(); ++i ) { 10 | if ( ts.size() ) s << ts[i]; 11 | else s << " ?" << d.types[params[i]]->getName() << i; 12 | if ( d.typed ) s << " - " << d.types[params[i]]->name; 13 | } 14 | s << " )"; 15 | } 16 | 17 | void Lifted::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 18 | TokenStruct< std::string > lstruct = f.parseTypedList( true, d.types ); 19 | params = d.convertTypes( lstruct.types ); 20 | } 21 | 22 | 23 | } } // namespaces -------------------------------------------------------------------------------- /parser/Task.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ParamCond.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Task : public ParamCond { 9 | 10 | public: 11 | 12 | Task() {} 13 | 14 | Task( const std::string & s ) 15 | : ParamCond( s ) {} 16 | 17 | Task( const ParamCond * c ) 18 | : ParamCond( c ) {} 19 | 20 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override {} 21 | 22 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) {} 23 | 24 | void addParams( int m, unsigned n ) {} 25 | 26 | Condition * copy( Domain & d ) { 27 | return new Task( this ); 28 | } 29 | 30 | }; 31 | 32 | typedef std::vector< Task * > TaskVec; 33 | 34 | } } // namespaces -------------------------------------------------------------------------------- /parser/TypeGround.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Ground.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class TypeGround : public Ground { 9 | 10 | public: 11 | 12 | TypeGround() 13 | : Ground() {} 14 | 15 | TypeGround( Lifted * l, const IntVec & p = IntVec() ) 16 | : Ground( l, p ) {} 17 | 18 | // TypeGround( const TypeGround * tg ) 19 | // : Ground( tg ) {} 20 | 21 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 22 | 23 | void insert( Domain & d, const StringVec & v ); 24 | 25 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 26 | 27 | }; 28 | 29 | typedef std::vector< TypeGround * > TypeGroundVec; 30 | 31 | } } // namespaces 32 | -------------------------------------------------------------------------------- /parser/Lifted.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ParamCond.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Lifted : public ParamCond { 9 | 10 | public: 11 | 12 | Lifted() {} 13 | 14 | Lifted( const std::string & s ) 15 | : ParamCond( s ) {} 16 | 17 | Lifted( const ParamCond * c ) 18 | : ParamCond( c ) {} 19 | 20 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 21 | 22 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 23 | 24 | void addParams( int m, unsigned n ) {} 25 | 26 | Condition * copy( Domain & d ) { 27 | return new Lifted( this ); 28 | } 29 | 30 | }; 31 | 32 | typedef std::vector< Lifted * > LiftedVec; 33 | 34 | } } // namespaces -------------------------------------------------------------------------------- /parser/Equals.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Equals::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( ="; 9 | for ( unsigned i = 0; i < params.size(); ++i ) 10 | s << " " << ts[params[i]]; 11 | s << " )"; 12 | } 13 | 14 | void Equals::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 15 | f.next(); 16 | params.resize( 2 ); 17 | 18 | for ( unsigned i = 0; i < 2; ++i, f.next() ) { 19 | std::string s = f.getToken(); 20 | int k = ts.index( s ); 21 | if ( k >= 0 ) params[i] = k; 22 | else f.tokenExit( s ); 23 | } 24 | 25 | f.assert_token( ")" ); 26 | } 27 | 28 | 29 | } } // namespaces 30 | -------------------------------------------------------------------------------- /parser/And.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void And::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( AND\n"; 9 | for ( unsigned i = 0; i < conds.size(); ++i ) { 10 | conds[i]->PDDLPrint( s, indent + 1, ts, d ); 11 | s << "\n"; 12 | } 13 | tabindent( s, indent ); 14 | s << ")"; 15 | } 16 | 17 | void And::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 18 | for ( f.next(); f.getChar() != ')'; f.next() ) { 19 | f.assert_token( "(" ); 20 | Condition * condition = d.createCondition( f ); 21 | condition->parse( f, ts, d ); 22 | conds.push_back( condition ); 23 | } 24 | ++f.c; 25 | } 26 | 27 | } } // namespaces 28 | -------------------------------------------------------------------------------- /parser/Oneof.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Oneof::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( ONEOF\n"; 9 | for ( unsigned i = 0; i < conds.size(); ++i ) { 10 | conds[i]->PDDLPrint( s, indent + 1, ts, d ); 11 | s << "\n"; 12 | } 13 | tabindent( s, indent ); 14 | s << ")"; 15 | } 16 | 17 | void Oneof::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 18 | for ( f.next(); f.getChar() != ')'; f.next() ) { 19 | f.assert_token( "(" ); 20 | Condition * condition = d.createCondition( f ); 21 | condition->parse( f, ts, d ); 22 | conds.push_back( condition ); 23 | } 24 | ++f.c; 25 | } 26 | 27 | } } // namespaces 28 | -------------------------------------------------------------------------------- /parser/Condition.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Basic.h" 5 | #include "Filereader.h" 6 | #include "Type.h" 7 | 8 | namespace parser { namespace pddl { 9 | 10 | class Condition { 11 | 12 | public: 13 | 14 | virtual ~Condition() {} 15 | 16 | virtual void print( std::ostream & stream ) const = 0; 17 | 18 | virtual void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const = 0; 19 | 20 | virtual void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) = 0; 21 | 22 | virtual void addParams( int m, unsigned n ) = 0; 23 | 24 | virtual Condition * copy( Domain & d ) = 0; 25 | }; 26 | 27 | inline std::ostream & operator<<( std::ostream & stream, const Condition * c ) { 28 | c->print( stream ); 29 | return stream; 30 | } 31 | 32 | typedef std::vector< Condition * > CondVec; 33 | 34 | } } // namespaces 35 | -------------------------------------------------------------------------------- /parser/CondIter.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | typedef std::list< std::pair< Condition *, unsigned > > CondList; 9 | 10 | class CondIter : public std::iterator< std::input_iterator_tag, Condition * > { 11 | 12 | public: 13 | 14 | CondList condStack; 15 | 16 | CondIter( Condition * c ) { 17 | condStack.push_back( std::make_pair( c, 0 ) ); 18 | (*this)++; 19 | } 20 | 21 | CondIter( const CondIter & ci ) 22 | : condStack( ci.condStack ) {} 23 | 24 | MyIterator & operator++() { 25 | while ( condStack().size() && condStack.last().done() ) 26 | condStack.pop_back(); 27 | 28 | if ( condStack().size() ) { 29 | } 30 | 31 | return *this; 32 | } 33 | 34 | bool hasNext() { 35 | return condStack.size(); 36 | } 37 | 38 | Condition * operator*() { 39 | return condStack.last(); 40 | } 41 | 42 | }; 43 | 44 | } } // namespaces 45 | -------------------------------------------------------------------------------- /parser/ParamCond.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | #include "Basic.h" 6 | 7 | namespace parser { namespace pddl { 8 | 9 | 10 | // This is necessary for ADL 11 | using ::operator<<; 12 | 13 | class ParamCond : public Condition { 14 | 15 | public: 16 | std::string name; 17 | IntVec params; 18 | 19 | ParamCond() {} 20 | 21 | ParamCond( const std::string & s, const IntVec & p = IntVec() ) 22 | : name( s ), params( p ) {} 23 | 24 | ParamCond( const ParamCond * c ) 25 | : name( c->name ), params( c->params ) {} 26 | 27 | std::string c_str() const { 28 | return name; 29 | } 30 | 31 | void print( std::ostream & stream ) const { 32 | stream << name << params << "\n"; 33 | } 34 | 35 | void printParams( unsigned first, std::ostream & s, TokenStruct< std::string > & ts, const Domain & d ) const; 36 | }; 37 | 38 | typedef std::vector< ParamCond * > ParamCondVec; 39 | 40 | } } // namespaces 41 | -------------------------------------------------------------------------------- /parser/Exists.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ParamCond.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Exists : public ParamCond { 9 | 10 | public: 11 | 12 | Condition * cond; 13 | 14 | Exists() 15 | : cond( 0 ) {} 16 | 17 | Exists( const Exists * e, Domain & d ) 18 | : ParamCond( e ), cond( 0 ) { 19 | if ( e->cond ) cond = e->cond->copy( d ); 20 | } 21 | 22 | ~Exists() { 23 | if ( cond ) delete cond; 24 | } 25 | 26 | void print( std::ostream & s ) const { 27 | s << "Exists" << params << ":\n"; 28 | cond->print( s ); 29 | } 30 | 31 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 32 | 33 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 34 | 35 | void addParams( int m, unsigned n ) { 36 | cond->addParams( m, n ); 37 | } 38 | 39 | Condition * copy( Domain & d ) { 40 | return new Exists( this, d ); 41 | } 42 | 43 | }; 44 | 45 | } } // namespaces 46 | -------------------------------------------------------------------------------- /parser/Forall.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ParamCond.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Forall : public ParamCond { 9 | 10 | public: 11 | Condition * cond; 12 | 13 | Forall() 14 | : cond( 0 ) {} 15 | 16 | Forall( const Forall * f, Domain & d ) 17 | : ParamCond( f ), cond( 0 ) { 18 | if ( f->cond ) cond = f->cond->copy( d ); 19 | } 20 | 21 | ~Forall() { 22 | if ( cond ) delete cond; 23 | } 24 | 25 | void print( std::ostream & s ) const { 26 | s << "Forall" << params << ":\n"; 27 | if ( cond ) cond->print( s ); 28 | } 29 | 30 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 31 | 32 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 33 | 34 | void addParams( int m, unsigned n ) { 35 | cond->addParams( m, n ); 36 | } 37 | 38 | Condition * copy( Domain & d ) { 39 | return new Forall( this, d ); 40 | } 41 | 42 | }; 43 | 44 | } } // namespaces -------------------------------------------------------------------------------- /parser/Not.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Ground.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Not : public Condition { 9 | 10 | public: 11 | 12 | Ground * cond; 13 | 14 | Not() 15 | : cond( 0 ) {} 16 | 17 | Not( Ground * g ) 18 | : cond( g ) {} 19 | 20 | Not( const Not * n, Domain & d ) 21 | : cond( 0 ) { 22 | if ( n->cond ) cond = ( Ground * )n->cond->copy( d ); 23 | } 24 | 25 | ~Not() { 26 | if ( cond ) delete cond; 27 | } 28 | 29 | void print( std::ostream & s ) const { 30 | s << "NOT "; 31 | if ( cond ) cond->print( s ); 32 | } 33 | 34 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 35 | 36 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 37 | 38 | void addParams( int m, unsigned n ) { 39 | cond->addParams( m, n ); 40 | } 41 | 42 | Condition * copy( Domain & d ) { 43 | return new Not( this, d ); 44 | } 45 | 46 | }; 47 | 48 | } } // namespaces -------------------------------------------------------------------------------- /parser/Ground.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Lifted.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Ground : public ParamCond { 9 | 10 | public: 11 | 12 | Lifted * lifted; 13 | 14 | Ground() 15 | : ParamCond(), lifted( 0 ) {} 16 | 17 | Ground( const std::string s, const IntVec & p = IntVec() ) 18 | : ParamCond( s, p ), lifted( 0 ) {} 19 | 20 | Ground( Lifted * l, const IntVec & p = IntVec() ) 21 | : ParamCond( l->name, p ), lifted( l ) {} 22 | 23 | Ground( const Ground * g, Domain & d ); 24 | 25 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 26 | 27 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 28 | 29 | void addParams( int m, unsigned n ) { 30 | for ( unsigned i = 0; i < params.size(); ++i ) 31 | if ( params[i] >= m ) params[i] += n; 32 | } 33 | 34 | Condition * copy( Domain & d ) { 35 | return new Ground( this, d ); 36 | } 37 | 38 | }; 39 | 40 | typedef std::vector< Ground * > GroundVec; 41 | 42 | } } // namespaces 43 | -------------------------------------------------------------------------------- /parser/Derived.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Lifted.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Derived : public Lifted { 9 | 10 | public: 11 | 12 | Condition * cond; 13 | Lifted * lifted; 14 | 15 | Derived() 16 | : Lifted(), cond( 0 ), lifted( 0 ) {} 17 | 18 | Derived( const std::string s ) 19 | : Lifted( s ), cond( 0 ), lifted( 0 ) {} 20 | 21 | Derived( const Derived * z, Domain & d ); 22 | 23 | void print( std::ostream & stream ) const { 24 | stream << "Derived "; 25 | ParamCond::print( stream ); 26 | if ( cond ) cond->print( stream ); 27 | } 28 | 29 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 30 | 31 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 32 | 33 | void addParams( int m, unsigned n ) { 34 | for ( unsigned i = 0; i < params.size(); ++i ) 35 | if ( params[i] >= m ) params[i] += n; 36 | } 37 | 38 | Condition * copy( Domain & d ) { 39 | return new Derived( this, d ); 40 | } 41 | 42 | }; 43 | 44 | } } // namespaces 45 | -------------------------------------------------------------------------------- /parser/When.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void When::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( WHEN\n"; 9 | if ( pars ) pars->PDDLPrint( s, indent + 1, ts, d ); 10 | else { 11 | tabindent( s, indent + 1 ); 12 | s << "()"; 13 | } 14 | s << "\n"; 15 | if ( cond ) cond->PDDLPrint( s, indent + 1, ts, d ); 16 | else { 17 | tabindent( s, indent + 1 ); 18 | s << "()"; 19 | } 20 | s << "\n"; 21 | tabindent( s, indent ); 22 | s << ")"; 23 | } 24 | 25 | void When::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 26 | f.next(); 27 | f.assert_token( "(" ); 28 | if ( f.getChar() != ')' ) { 29 | pars = d.createCondition( f ); 30 | pars->parse( f, ts, d ); 31 | } 32 | else ++f.c; 33 | 34 | f.next(); 35 | f.assert_token( "(" ); 36 | if ( f.getChar() != ')' ) { 37 | cond = d.createCondition( f ); 38 | cond->parse( f, ts, d ); 39 | } 40 | else ++f.c; 41 | 42 | f.next(); 43 | f.assert_token( ")" ); 44 | } 45 | 46 | } } // namespaces 47 | -------------------------------------------------------------------------------- /parser/Or.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Or::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( OR\n"; 9 | if ( first ) first->PDDLPrint( s, indent + 1, ts, d ); 10 | else { 11 | tabindent( s, indent + 1 ); 12 | s << "()"; 13 | } 14 | s << "\n"; 15 | if ( second ) second->PDDLPrint( s, indent + 1, ts, d ); 16 | else { 17 | tabindent( s, indent + 1 ); 18 | s << "()"; 19 | } 20 | s << "\n"; 21 | tabindent( s, indent ); 22 | s << ")"; 23 | } 24 | 25 | void Or::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 26 | f.next(); 27 | f.assert_token( "(" ); 28 | if ( f.getChar() != ')' ) { 29 | first = d.createCondition( f ); 30 | first->parse( f, ts, d ); 31 | } 32 | else ++f.c; 33 | 34 | f.next(); 35 | f.assert_token( "(" ); 36 | if ( f.getChar() != ')' ) { 37 | second = d.createCondition( f ); 38 | second->parse( f, ts, d ); 39 | } 40 | else ++f.c; 41 | 42 | f.next(); 43 | f.assert_token( ")" ); 44 | } 45 | 46 | 47 | } } // namespaces 48 | -------------------------------------------------------------------------------- /parser/Or.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Or : public Condition { 9 | 10 | public: 11 | Condition *first, *second; 12 | 13 | Or() 14 | : first( 0 ), second( 0 ) {} 15 | 16 | Or( const Or * o, Domain & d ) 17 | : first( 0 ), second( 0 ) { 18 | if ( o->first ) first = o->first->copy( d ); 19 | if ( o->second ) second = o->second->copy( d ); 20 | } 21 | 22 | ~Or() { 23 | if ( first ) delete first; 24 | if ( second ) delete second; 25 | } 26 | 27 | void print( std::ostream & s ) const { 28 | s << "OR:\n"; 29 | if ( first ) first->print( s ); 30 | if ( second ) second->print( s ); 31 | } 32 | 33 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 34 | 35 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 36 | 37 | void addParams( int m, unsigned n ) { 38 | first->addParams( m, n ); 39 | second->addParams( m, n ); 40 | } 41 | 42 | Condition * copy( Domain & d ) { 43 | return new Or( this, d ); 44 | } 45 | }; 46 | 47 | } } // namespaces -------------------------------------------------------------------------------- /parser/When.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class When : public Condition { 9 | 10 | public: 11 | 12 | Condition *pars, *cond; 13 | 14 | When() 15 | : pars( 0 ), cond( 0 ) {} 16 | 17 | When( const When * w, Domain & d ) 18 | : pars( 0 ), cond( 0 ) { 19 | if ( w->pars ) pars = w->pars->copy( d ); 20 | if ( w->cond ) cond = w->cond->copy( d ); 21 | } 22 | 23 | ~When() { 24 | if ( pars ) delete pars; 25 | if ( cond ) delete cond; 26 | } 27 | 28 | void print( std::ostream & s ) const { 29 | s << "WHEN:\n"; 30 | if ( pars ) pars->print( s ); 31 | if ( cond ) cond->print( s ); 32 | } 33 | 34 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 35 | 36 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 37 | 38 | void addParams( int m, unsigned n ) { 39 | pars->addParams( m, n ); 40 | cond->addParams( m, n ); 41 | } 42 | 43 | Condition * copy( Domain & d ) { 44 | return new When( this, d ); 45 | } 46 | 47 | }; 48 | 49 | } } // namespaces 50 | -------------------------------------------------------------------------------- /parser/And.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class And : public Condition { 9 | 10 | public: 11 | CondVec conds; 12 | 13 | And() = default; 14 | 15 | And( const And * a, Domain & d ) { 16 | for ( unsigned i = 0; i < a->conds.size(); ++i ) 17 | conds.push_back( a->conds[i]->copy( d ) ); 18 | } 19 | 20 | ~And() { 21 | for ( unsigned i = 0; i < conds.size(); ++i ) 22 | delete conds[i]; 23 | } 24 | 25 | void print( std::ostream & s ) const { 26 | for ( unsigned i = 0; i < conds.size(); ++i ) 27 | conds[i]->print( s ); 28 | } 29 | 30 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 31 | 32 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 33 | 34 | void add( Condition * cond ) { 35 | conds.push_back( cond ); 36 | } 37 | 38 | void addParams( int m, unsigned n ) { 39 | for ( unsigned i = 0; i < conds.size(); ++i ) 40 | conds[i]->addParams( m, n ); 41 | } 42 | 43 | Condition * copy( Domain & d ) { 44 | return new And( this, d ); 45 | } 46 | 47 | }; 48 | 49 | } } // namespaces -------------------------------------------------------------------------------- /parser/Oneof.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Oneof : public Condition { 9 | 10 | public: 11 | 12 | CondVec conds; 13 | 14 | Oneof() {} 15 | 16 | Oneof( const Oneof * o, Domain & d ) { 17 | for ( unsigned i = 0; i < o->conds.size(); ++i ) 18 | conds.push_back( o->conds[i]->copy( d ) ); 19 | } 20 | 21 | ~Oneof() { 22 | for ( unsigned i = 0; i < conds.size(); ++i ) 23 | delete conds[i]; 24 | } 25 | 26 | void print( std::ostream & s ) const { 27 | for ( unsigned i = 0; i < conds.size(); ++i ) 28 | conds[i]->print( s ); 29 | } 30 | 31 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 32 | 33 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 34 | 35 | void add( Condition * cond ) { 36 | conds.push_back( cond ); 37 | } 38 | 39 | void addParams( int m, unsigned n ) { 40 | for ( unsigned i = 0; i < conds.size(); ++i ) 41 | conds[i]->addParams( m, n ); 42 | } 43 | 44 | Condition * copy( Domain & d ) { 45 | return new Oneof( this, d ); 46 | } 47 | 48 | }; 49 | 50 | } } // namespaces 51 | -------------------------------------------------------------------------------- /parser/Exists.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Exists::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( EXISTS\n"; 9 | 10 | TokenStruct< std::string > fstruct( ts ); 11 | 12 | tabindent( s, indent + 1 ); 13 | printParams( 0, s, fstruct, d ); 14 | 15 | if ( cond ) cond->PDDLPrint( s, indent + 1, fstruct, d ); 16 | else { 17 | tabindent( s, indent + 1 ); 18 | s << "()"; 19 | } 20 | s << "\n"; 21 | tabindent( s, indent ); 22 | s << ")"; 23 | } 24 | 25 | void Exists::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 26 | f.next(); 27 | f.assert_token( "(" ); 28 | 29 | TokenStruct< std::string > es = f.parseTypedList( true, d.types ); 30 | params = d.convertTypes( es.types ); 31 | 32 | TokenStruct< std::string > estruct( ts ); 33 | estruct.append( es ); 34 | 35 | f.next(); 36 | f.assert_token( "(" ); 37 | if ( f.getChar() != ')' ) { 38 | cond = d.createCondition( f ); 39 | cond->parse( f, estruct, d ); 40 | } 41 | else ++f.c; 42 | 43 | f.next(); 44 | f.assert_token( ")" ); 45 | } 46 | 47 | } } // namespaces 48 | -------------------------------------------------------------------------------- /parser/Forall.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Forall::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( FORALL\n"; 9 | 10 | TokenStruct< std::string > fstruct( ts ); 11 | 12 | tabindent( s, indent + 1 ); 13 | printParams( 0, s, fstruct, d ); 14 | 15 | if ( cond ) cond->PDDLPrint( s, indent + 1, fstruct, d ); 16 | else { 17 | tabindent( s, indent + 1 ); 18 | s << "()"; 19 | } 20 | 21 | s << "\n"; 22 | tabindent( s, indent ); 23 | s << ")"; 24 | } 25 | 26 | void Forall::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 27 | f.next(); 28 | f.assert_token( "(" ); 29 | 30 | TokenStruct< std::string > fs = f.parseTypedList( true, d.types ); 31 | params = d.convertTypes( fs.types ); 32 | 33 | TokenStruct< std::string > fstruct( ts ); 34 | fstruct.append( fs ); 35 | 36 | f.next(); 37 | f.assert_token( "(" ); 38 | if ( f.getChar() != ')' ) { 39 | cond = d.createCondition( f ); 40 | cond->parse( f, fstruct, d ); 41 | } 42 | else ++f.c; 43 | 44 | f.next(); 45 | f.assert_token( ")" ); 46 | } 47 | 48 | } } // namespaces 49 | -------------------------------------------------------------------------------- /parser/Ground.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | Ground::Ground( const Ground * g, Domain & d ) 7 | : ParamCond( g ), lifted( d.preds.get( g->name ) ) {} 8 | 9 | void Ground::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 10 | tabindent( s, indent ); 11 | s << "( " << name; 12 | for ( unsigned i = 0; i < params.size(); ++i ) { 13 | if ( ts.size() && params[i] >= 0 && (unsigned)params[i] < ts.size() ) s << " " << ts[params[i]]; 14 | else if (params[i] >= 0 && (unsigned)params[i] >= ts.size()) s << " ?" << params[i]; 15 | else s << " " << d.types[lifted->params[i]]->object( params[i] ).first; 16 | } 17 | s << " )"; 18 | } 19 | 20 | void Ground::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 21 | f.next(); 22 | params.resize( lifted->params.size() ); 23 | for ( unsigned i = 0; i < lifted->params.size(); ++i, f.next() ) { 24 | std::string s = f.getToken(); 25 | int k = ts.index( s ); 26 | if ( k >= 0 ) params[i] = k; 27 | else { 28 | std::pair< bool, int > p = d.types[lifted->params[i]]->parseConstant( s ); 29 | if ( p.first ) params[i] = p.second; 30 | else f.tokenExit( s ); 31 | } 32 | } 33 | f.assert_token( ")" ); 34 | } 35 | 36 | } } // namespaces 37 | -------------------------------------------------------------------------------- /parser/Derived.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | Derived::Derived( const Derived * z, Domain & d ) 7 | : Lifted( z ), cond( 0 ), lifted( d.preds.get( z->name ) ) { 8 | if ( z->cond ) cond = z->cond->copy( d ); 9 | } 10 | 11 | void Derived::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 12 | s << "( :DERIVED ( " << name; 13 | 14 | TokenStruct< std::string > dstruct( ts ); 15 | 16 | for ( unsigned i = 0; i < params.size(); ++i ) { 17 | std::stringstream ss; 18 | ss << "?" << d.types[params[i]]->getName() << dstruct.size(); 19 | dstruct.insert( ss.str() ); 20 | s << " " << ss.str(); 21 | if ( d.typed ) s << " - " << d.types[params[i]]->name; 22 | } 23 | s << " )\n"; 24 | 25 | if ( cond ) cond->PDDLPrint( s, 1, dstruct, d ); 26 | 27 | s << "\n)\n"; 28 | } 29 | 30 | void Derived::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 31 | f.next(); 32 | f.assert_token( "(" ); 33 | name = f.getToken( d.preds ); 34 | TokenStruct< std::string > dstruct = f.parseTypedList( true, d.types ); 35 | params = d.convertTypes( dstruct.types ); 36 | 37 | f.next(); 38 | f.assert_token( "(" ); 39 | cond = d.createCondition( f ); 40 | cond->parse( f, dstruct, d ); 41 | 42 | f.next(); 43 | f.assert_token( ")" ); 44 | } 45 | 46 | } } // namespaces 47 | -------------------------------------------------------------------------------- /parser/TypeGround.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void TypeGround::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | tabindent( s, indent ); 8 | s << "( " << name; 9 | for ( unsigned i = 0; i < params.size(); ++i ) 10 | s << " " << d.types[lifted->params[i]]->object( params[i] ).first; 11 | s << " )"; 12 | } 13 | 14 | void TypeGround::insert( Domain & d, const StringVec & v ) { 15 | params.resize( lifted->params.size() ); 16 | for ( unsigned i = 0; i < lifted->params.size(); ++i ) { 17 | std::pair< bool, unsigned > p = d.types[lifted->params[i]]->parseObject( v[i] ); 18 | if ( p.first ) params[i] = p.second; 19 | else { 20 | std::pair< bool, int > q = d.types[lifted->params[i]]->parseConstant( v[i] ); 21 | if ( q.first ) params[i] = q.second; 22 | else { 23 | std::cerr << "Unknown object " << v[i] << "\n"; 24 | std::exit( 1 ); 25 | } 26 | } 27 | } 28 | } 29 | 30 | void TypeGround::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 31 | f.next(); 32 | params.resize( lifted->params.size() ); 33 | for ( unsigned i = 0; i < lifted->params.size(); ++i, f.next() ) { 34 | std::string s = f.getToken(); 35 | std::pair< bool, unsigned > p = d.types[lifted->params[i]]->parseObject( s ); 36 | if ( p.first ) params[i] = p.second; 37 | else { 38 | std::pair< bool, int > q = d.types[lifted->params[i]]->parseConstant( s ); 39 | if ( q.first ) params[i] = q.second; 40 | else f.tokenExit( s ); 41 | } 42 | } 43 | f.assert_token( ")" ); 44 | } 45 | 46 | } } // namespaces 47 | -------------------------------------------------------------------------------- /parser/GroundFunc.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | template <> 7 | void GroundFunc::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 8 | tabindent( s, indent ); 9 | s << "( = "; 10 | TypeGround::PDDLPrint( s, 0, ts, d ); 11 | s << " " << ( int )value << " )"; 12 | } 13 | 14 | template <> 15 | void GroundFunc::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 16 | tabindent( s, indent ); 17 | s << "( = "; 18 | TypeGround::PDDLPrint( s, 0, ts, d ); 19 | s << " " << d.types[((Function *)lifted)->returnType]->object( value ) << " )"; 20 | } 21 | 22 | template <> 23 | void GroundFunc::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 24 | TypeGround::parse( f, ts, d ); 25 | 26 | f.next(); 27 | std::string s = f.getToken(); 28 | std::istringstream i( s ); 29 | if ( !( i >> value ) ) f.tokenExit( s ); 30 | 31 | f.next(); 32 | f.assert_token( ")" ); 33 | } 34 | 35 | template <> 36 | void GroundFunc::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 37 | TypeGround::parse( f, ts, d ); 38 | 39 | f.next(); 40 | std::string s = f.getToken(); 41 | std::pair< bool, unsigned > p = d.types[((Function *)lifted)->returnType]->parseObject( s ); 42 | if ( p.first ) value = p.second; 43 | else { 44 | std::pair< bool, int > q = d.types[((Function *)lifted)->returnType]->parseConstant( s ); 45 | if ( q.first ) value = q.second; 46 | else f.tokenExit( s ); 47 | } 48 | 49 | f.next(); 50 | f.assert_token( ")" ); 51 | } 52 | 53 | } } // namespaces 54 | -------------------------------------------------------------------------------- /domains/Sched_ins.pddl: -------------------------------------------------------------------------------- 1 | (define (problem schedule-2-0) 2 | (:domain schedule) 3 | (:objects 4 | TWO 5 | THREE 6 | BLUE 7 | YELLOW 8 | BACK 9 | RED 10 | B0 11 | FRONT 12 | ONE 13 | BLACK 14 | OBLONG 15 | A0 16 | ) 17 | (:init 18 | (idle punch) (idle drill-press) (idle lathe) (idle roller) (idle polisher) 19 | (idle immersion-painter) (idle spray-painter) (idle grinder) (ru unwantedargs) 20 | (SHAPE A0 OBLONG) 21 | (SURFACE-CONDITION A0 SMOOTH) 22 | (PAINTED A0 BLACK) 23 | (HAS-HOLE A0 ONE FRONT) (lasthole A0 ONE FRONT) (linked A0 nowidth noorient ONE FRONT) 24 | (TEMPERATURE A0 COLD) 25 | (SHAPE B0 OBLONG) 26 | (SURFACE-CONDITION B0 SMOOTH) 27 | (PAINTED B0 RED) 28 | (HAS-HOLE B0 ONE FRONT) (lasthole B0 ONE FRONT) (linked B0 nowidth noorient ONE FRONT) 29 | (TEMPERATURE B0 COLD) 30 | (CAN-ORIENT DRILL-PRESS BACK) 31 | (CAN-ORIENT PUNCH BACK) 32 | (CAN-ORIENT DRILL-PRESS FRONT) 33 | (CAN-ORIENT PUNCH FRONT) 34 | (HAS-PAINT IMMERSION-PAINTER YELLOW) 35 | (HAS-PAINT SPRAY-PAINTER YELLOW) 36 | (HAS-PAINT IMMERSION-PAINTER BLUE) 37 | (HAS-PAINT SPRAY-PAINTER BLUE) 38 | (HAS-PAINT IMMERSION-PAINTER BLACK) 39 | (HAS-PAINT SPRAY-PAINTER BLACK) 40 | (HAS-PAINT IMMERSION-PAINTER RED) 41 | (HAS-PAINT SPRAY-PAINTER RED) 42 | (HAS-BIT DRILL-PRESS THREE) 43 | (HAS-BIT PUNCH THREE) 44 | (HAS-BIT DRILL-PRESS TWO) 45 | (HAS-BIT PUNCH TWO) 46 | (HAS-BIT DRILL-PRESS ONE) 47 | (HAS-BIT PUNCH ONE) 48 | (PART B0) (unscheduled B0) 49 | (PART A0) (unscheduled A0) 50 | ) 51 | (:goal (and 52 | (SHAPE B0 CYLINDRICAL) 53 | (SHAPE A0 CYLINDRICAL) 54 | ))) 55 | -------------------------------------------------------------------------------- /tests/expected/Sched_ins.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( PROBLEM SCHEDULE-2-0 ) 2 | ( :DOMAIN SCHEDULE ) 3 | ( :OBJECTS 4 | TWO THREE BLUE YELLOW BACK RED B0 FRONT ONE BLACK OBLONG A0 5 | ) 6 | ( :INIT 7 | ( IDLE PUNCH ) 8 | ( IDLE DRILL-PRESS ) 9 | ( IDLE LATHE ) 10 | ( IDLE ROLLER ) 11 | ( IDLE POLISHER ) 12 | ( IDLE IMMERSION-PAINTER ) 13 | ( IDLE SPRAY-PAINTER ) 14 | ( IDLE GRINDER ) 15 | ( RU UNWANTEDARGS ) 16 | ( SHAPE A0 OBLONG ) 17 | ( SURFACE-CONDITION A0 SMOOTH ) 18 | ( PAINTED A0 BLACK ) 19 | ( HAS-HOLE A0 ONE FRONT ) 20 | ( LASTHOLE A0 ONE FRONT ) 21 | ( LINKED A0 NOWIDTH NOORIENT ONE FRONT ) 22 | ( TEMPERATURE A0 COLD ) 23 | ( SHAPE B0 OBLONG ) 24 | ( SURFACE-CONDITION B0 SMOOTH ) 25 | ( PAINTED B0 RED ) 26 | ( HAS-HOLE B0 ONE FRONT ) 27 | ( LASTHOLE B0 ONE FRONT ) 28 | ( LINKED B0 NOWIDTH NOORIENT ONE FRONT ) 29 | ( TEMPERATURE B0 COLD ) 30 | ( CAN-ORIENT DRILL-PRESS BACK ) 31 | ( CAN-ORIENT PUNCH BACK ) 32 | ( CAN-ORIENT DRILL-PRESS FRONT ) 33 | ( CAN-ORIENT PUNCH FRONT ) 34 | ( HAS-PAINT IMMERSION-PAINTER YELLOW ) 35 | ( HAS-PAINT SPRAY-PAINTER YELLOW ) 36 | ( HAS-PAINT IMMERSION-PAINTER BLUE ) 37 | ( HAS-PAINT SPRAY-PAINTER BLUE ) 38 | ( HAS-PAINT IMMERSION-PAINTER BLACK ) 39 | ( HAS-PAINT SPRAY-PAINTER BLACK ) 40 | ( HAS-PAINT IMMERSION-PAINTER RED ) 41 | ( HAS-PAINT SPRAY-PAINTER RED ) 42 | ( HAS-BIT DRILL-PRESS THREE ) 43 | ( HAS-BIT PUNCH THREE ) 44 | ( HAS-BIT DRILL-PRESS TWO ) 45 | ( HAS-BIT PUNCH TWO ) 46 | ( HAS-BIT DRILL-PRESS ONE ) 47 | ( HAS-BIT PUNCH ONE ) 48 | ( PART B0 ) 49 | ( UNSCHEDULED B0 ) 50 | ( PART A0 ) 51 | ( UNSCHEDULED A0 ) 52 | ) 53 | ( :GOAL 54 | ( AND 55 | ( SHAPE B0 CYLINDRICAL ) 56 | ( SHAPE A0 CYLINDRICAL ) 57 | ) 58 | ) 59 | ) 60 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | import sys 4 | 5 | def which(program): 6 | """ Helper function emulating unix 'which' command """ 7 | for path in os.environ["PATH"].split(os.pathsep): 8 | path = path.strip('"') 9 | exe_file = os.path.join(path, program) 10 | if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK): 11 | return exe_file 12 | return None 13 | 14 | pkgpath = os.environ.get( "PKG_CONFIG_PATH", "" ) 15 | os.environ["PKG_CONFIG_PATH"] = pkgpath 16 | 17 | src_path = "./parser" 18 | 19 | # Read the preferred compiler from the environment - if none specified, choose CLANG if possible 20 | #default_compiler = 'clang++' if which("clang++") else 'g++' 21 | default_compiler = 'g++' 22 | gcc = os.environ.get('CXX', default_compiler) 23 | 24 | 25 | base = Environment(tools=["default"], CXX=gcc) 26 | 27 | include_paths = ['.'] 28 | 29 | base.AppendUnique( 30 | CPPPATH = [ os.path.abspath(p) for p in include_paths ], 31 | CXXFLAGS=[ 32 | "-Wall", 33 | "-pedantic", 34 | "-std=c++11", 35 | "-g" 36 | ] 37 | ) 38 | 39 | 40 | extra = base.Clone() 41 | extra.Append(LIBS=[File(os.path.abspath('./lib/libparser.a'))]) 42 | 43 | # Register the different examples 44 | SConscript('tests/SConscript', exports='extra') 45 | SConscript('examples/parser/SConscript', exports='extra') 46 | 47 | # The compilation of the (static & dynamic) library 48 | build_dirname = 'build' 49 | base.VariantDir(build_dirname, '.') 50 | 51 | sources = glob.glob( src_path + "/*.cpp" ) 52 | build_files = [build_dirname + '/' + src for src in sources] 53 | 54 | shared_lib = base.SharedLibrary('lib/parser', build_files) 55 | static_lib = base.Library('lib/parser', build_files) 56 | 57 | # Build both static and dynamic library 58 | base.Default([static_lib, shared_lib]) 59 | base.AlwaysBuild([static_lib, shared_lib]) 60 | 61 | -------------------------------------------------------------------------------- /parser/Action.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Ground.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Action : public ParamCond { 9 | 10 | public: 11 | 12 | Condition *pre, *eff; 13 | 14 | Action( const std::string & s ) 15 | : ParamCond( s ), pre( 0 ), eff( 0 ) {} 16 | 17 | Action( ParamCond * c ) 18 | : ParamCond( c ), pre( 0 ), eff( 0 ) {} 19 | 20 | Action( const Action * a, Domain & d ) 21 | : ParamCond( a ), pre( 0 ), eff( 0 ) { 22 | if ( a->pre ) pre = a->pre->copy( d ); 23 | if ( a->eff ) eff = a->eff->copy( d ); 24 | } 25 | 26 | virtual ~Action() { 27 | if ( pre ) delete pre; 28 | if ( eff ) delete eff; 29 | } 30 | 31 | void print( std::ostream & s ) const { 32 | s << name << params << "\n"; 33 | s << "Pre: " << pre; 34 | if ( eff ) s << "Eff: " << eff; 35 | } 36 | 37 | virtual double duration() { 38 | return 1; 39 | } 40 | 41 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 42 | 43 | void parseConditions( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 44 | 45 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 46 | 47 | void addParams( int m, unsigned n ) {} 48 | 49 | void addParams( const IntVec & v ) { 50 | if ( pre ) pre->addParams( params.size(), v.size() ); 51 | if ( eff ) eff->addParams( params.size(), v.size() ); 52 | params.insert( params.end(), v.begin(), v.end() ); 53 | } 54 | 55 | Condition * copy( Domain & d ) { 56 | return new Action( this, d ); 57 | } 58 | 59 | CondVec precons(); 60 | 61 | CondVec effects(); 62 | 63 | GroundVec addEffects(); 64 | 65 | GroundVec deleteEffects(); 66 | 67 | protected: 68 | 69 | CondVec getSubconditionsFromCondition( Condition * c ); 70 | 71 | GroundVec getGroundsFromCondition( Condition * c, bool neg ); 72 | }; 73 | 74 | typedef std::vector< Action * > ActionVec; 75 | 76 | } } // namespaces 77 | -------------------------------------------------------------------------------- /parser/TokenStruct.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | T is either a pointer or a string 6 | A token structure stores pointers but does not delete them! 7 | */ 8 | 9 | namespace parser { namespace pddl { 10 | 11 | typedef std::map< std::string, unsigned > TokenMap; 12 | 13 | template 14 | inline std::string getName( const T & t ) { 15 | return t->name; 16 | } 17 | 18 | template <> 19 | inline std::string getName( const std::string & s ) { 20 | return s; 21 | } 22 | 23 | template 24 | class TokenStruct { 25 | 26 | public: 27 | 28 | std::vector< T > tokens; 29 | TokenMap tokenMap; 30 | 31 | // represents the types of a typed list 32 | StringVec types; 33 | 34 | TokenStruct() {} 35 | 36 | TokenStruct( const TokenStruct & ts ) 37 | : tokens( ts.tokens ), tokenMap( ts.tokenMap ), types( ts.types ) {} 38 | 39 | void append( const TokenStruct & ts ) { 40 | for ( unsigned i = 0; i < ts.size(); ++i ) 41 | insert( ts[i] ); 42 | types.insert( types.end(), ts.types.begin(), ts.types.end() ); 43 | } 44 | 45 | unsigned size() const { 46 | return tokens.size(); 47 | } 48 | 49 | T & operator[]( std::size_t i ) { 50 | return tokens[i]; 51 | } 52 | 53 | const T & operator[]( std::size_t i ) const { 54 | return tokens[i]; 55 | } 56 | 57 | void clear() { 58 | for ( unsigned i = 0; i < size(); ++i ) 59 | delete tokens[i]; 60 | 61 | tokens.clear(); 62 | tokenMap.clear(); 63 | } 64 | 65 | unsigned insert( const T & t ) { 66 | TokenMap::iterator i = tokenMap.insert( tokenMap.begin(), std::make_pair( getName( t ), size() ) ); 67 | tokens.push_back( t ); 68 | return i->second; 69 | } 70 | 71 | int index( const std::string & s ) const { 72 | TokenMap::const_iterator i = tokenMap.find( s ); 73 | return i == tokenMap.end() ? -1 : i->second; 74 | } 75 | 76 | T get( const std::string & s ) const { 77 | return tokens[index( s )]; 78 | } 79 | 80 | }; 81 | 82 | } } // namespaces 83 | -------------------------------------------------------------------------------- /parser/FunctionModifier.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | FunctionModifier::FunctionModifier( const std::string& name, int val ) 7 | : name( name ), modifiedGround( 0 ), modifierExpr( new ValueExpression( val ) ) {} 8 | 9 | FunctionModifier::FunctionModifier( const std::string& name, Function * f, const IntVec & p ) 10 | : name( name ), modifiedGround( 0 ), modifierExpr( new FunctionExpression( new Ground( f, p ) ) ) {} 11 | 12 | FunctionModifier::FunctionModifier( const std::string& name, const FunctionModifier * i, Domain & d ) 13 | : name( name ) 14 | { 15 | if ( i->modifiedGround ) { 16 | modifiedGround = dynamic_cast< Ground * >( i->modifiedGround->copy( d ) ); 17 | } 18 | else modifiedGround = 0; 19 | 20 | if ( i->modifierExpr ) { 21 | modifierExpr = dynamic_cast< Expression * >( i->modifierExpr->copy( d ) ); 22 | } 23 | else modifierExpr = 0; 24 | } 25 | 26 | void FunctionModifier::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 27 | tabindent( s, indent ); 28 | s << "( " << name << " "; 29 | 30 | if ( modifiedGround ) { 31 | modifiedGround->PDDLPrint( s, 0, ts, d ); 32 | } 33 | else { 34 | s << "( TOTAL-COST )"; 35 | } 36 | 37 | s << " "; 38 | modifierExpr->PDDLPrint( s, 0, ts, d ); 39 | 40 | s << " )"; 41 | } 42 | 43 | void FunctionModifier::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 44 | f.next(); 45 | 46 | f.assert_token( "(" ); 47 | 48 | std::string increasedFunction = f.getToken(); 49 | if ( increasedFunction == "TOTAL-COST" ) { 50 | f.next(); 51 | f.assert_token( ")" ); 52 | } 53 | else { 54 | modifiedGround = new Ground( d.funcs.get( increasedFunction ) ); 55 | modifiedGround->parse( f, ts, d ); 56 | } 57 | 58 | f.next(); 59 | 60 | modifierExpr = createExpression( f, ts, d ); 61 | 62 | f.next(); 63 | f.assert_token( ")" ); 64 | } 65 | 66 | } } // namespaces 67 | -------------------------------------------------------------------------------- /parser/TemporalAction.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Action.h" 5 | #include "And.h" 6 | #include "Expression.h" 7 | 8 | namespace parser { namespace pddl { 9 | 10 | class Instance; 11 | 12 | class TemporalAction : public Action { 13 | 14 | public: 15 | 16 | Expression * durationExpr; 17 | // pre_s and eff_s inherited from Action 18 | And *pre_o, *pre_e, *eff_e; 19 | 20 | TemporalAction( const std::string & s ) 21 | : Action( s ), durationExpr( 0 ), pre_o( 0 ), pre_e( 0 ), eff_e( 0 ) {} 22 | 23 | ~TemporalAction() { 24 | if ( durationExpr ) delete durationExpr; 25 | if ( pre_o ) delete pre_o; 26 | if ( pre_e ) delete pre_e; 27 | if ( eff_e ) delete eff_e; 28 | } 29 | 30 | void print( std::ostream & s ) const { 31 | s << name << params << "\n"; 32 | s << "Duration: " << durationExpr->info() << "\n"; 33 | s << "Pre_s: " << pre; 34 | s << "Eff_s: " << eff; 35 | s << "Pre_o: " << pre_o; 36 | s << "Pre_e: " << pre_e; 37 | s << "Eff_e: " << eff_e; 38 | } 39 | 40 | double duration() { 41 | if ( durationExpr ) return durationExpr->evaluate(); 42 | else return 0; 43 | } 44 | 45 | Expression * parseDuration( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 46 | 47 | void printCondition( std::ostream & s, const TokenStruct< std::string > & ts, const Domain & d, 48 | const std::string & t, And * a ) const; 49 | 50 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 51 | 52 | void parseCondition( Filereader & f, TokenStruct< std::string > & ts, Domain & d, And * a ); 53 | 54 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 55 | 56 | GroundVec preconsStart(); 57 | 58 | GroundVec preconsOverall(); 59 | 60 | GroundVec preconsEnd(); 61 | 62 | CondVec endEffects(); 63 | 64 | GroundVec addEndEffects(); 65 | 66 | GroundVec deleteEndEffects(); 67 | }; 68 | 69 | } } // namespaces 70 | -------------------------------------------------------------------------------- /domains/Log_dom.pddl: -------------------------------------------------------------------------------- 1 | ;; logistics domain Typed version. 2 | ;; 3 | 4 | (define (domain logistics) 5 | (:requirements :strips :typing) 6 | (:types truck 7 | airplane - vehicle 8 | package 9 | vehicle - physobj 10 | airport 11 | location - place 12 | city 13 | place 14 | physobj - object) 15 | 16 | (:predicates (in-city ?loc - place ?city - city) 17 | (at ?obj - physobj ?loc - place) 18 | (in ?pkg - package ?veh - vehicle)) 19 | 20 | (:action LOAD-TRUCK 21 | :parameters (?pkg - package ?truck - truck ?loc - place) 22 | :precondition (and (at ?truck ?loc) (at ?pkg ?loc)) 23 | :effect (and (not (at ?pkg ?loc)) (in ?pkg ?truck))) 24 | 25 | (:action LOAD-AIRPLANE 26 | :parameters (?pkg - package ?airplane - airplane ?loc - place) 27 | :precondition (and (at ?pkg ?loc) (at ?airplane ?loc)) 28 | :effect (and (not (at ?pkg ?loc)) (in ?pkg ?airplane))) 29 | 30 | (:action UNLOAD-TRUCK 31 | :parameters (?pkg - package ?truck - truck ?loc - place) 32 | :precondition (and (at ?truck ?loc) (in ?pkg ?truck)) 33 | :effect (and (not (in ?pkg ?truck)) (at ?pkg ?loc))) 34 | 35 | (:action UNLOAD-AIRPLANE 36 | :parameters (?pkg - package ?airplane - airplane ?loc - place) 37 | :precondition (and (in ?pkg ?airplane) (at ?airplane ?loc)) 38 | :effect (and (not (in ?pkg ?airplane)) (at ?pkg ?loc))) 39 | 40 | (:action DRIVE-TRUCK 41 | :parameters (?truck - truck ?loc-from - place ?loc-to - place ?city - city) 42 | :precondition 43 | (and (at ?truck ?loc-from) (in-city ?loc-from ?city) (in-city ?loc-to ?city)) 44 | :effect 45 | (and (not (at ?truck ?loc-from)) (at ?truck ?loc-to))) 46 | 47 | (:action FLY-AIRPLANE 48 | :parameters (?airplane - airplane ?loc-from - airport ?loc-to - airport) 49 | :precondition 50 | (at ?airplane ?loc-from) 51 | :effect 52 | (and (not (at ?airplane ?loc-from)) (at ?airplane ?loc-to))) 53 | ) 54 | -------------------------------------------------------------------------------- /tests/DomainTests.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | using namespace parser::pddl; 9 | 10 | class DomainTests : public TestFixture< DomainTests > 11 | { 12 | public: 13 | TEST_FIXTURE( DomainTests ) 14 | { 15 | TEST_CASE( logisticsTest ); 16 | TEST_CASE( scheduleTest ); 17 | TEST_CASE( elevatorTest ); 18 | TEST_CASE( temporalTest ); 19 | } 20 | 21 | template < typename T > 22 | void checkEqual( T & prob, const std::string & file ) { 23 | std::ifstream f(file.c_str()); 24 | if (!f) throw std::runtime_error(std::string("Failed to open file '") + file + "'"); 25 | std::string s, t; 26 | 27 | while(std::getline(f, s)){ 28 | t += s + "\n"; 29 | } 30 | 31 | std::ostringstream ds; 32 | ds << prob; 33 | ASSERT_EQUALS( t, ds.str() ); 34 | std::ofstream of("ins.txt"); 35 | of< total-cost 19 | Expression * modifierExpr; // the expression by which we increment/decrement 20 | 21 | FunctionModifier( const std::string& name, int val = 1 ); 22 | 23 | FunctionModifier( const std::string& name, Function * f, const IntVec & p = IntVec() ); 24 | 25 | FunctionModifier( const std::string& name, const FunctionModifier * i, Domain & d ); 26 | 27 | ~FunctionModifier() { 28 | if ( modifiedGround ) delete modifiedGround; 29 | if ( modifierExpr ) delete modifierExpr; 30 | } 31 | 32 | void print( std::ostream & s ) const { 33 | s << name << " "; 34 | if ( modifiedGround ) modifiedGround->print( s ); 35 | if ( modifierExpr ) modifierExpr->print( s ); 36 | s << "\n"; 37 | } 38 | 39 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 40 | 41 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 42 | 43 | void addParams( int m, unsigned n ) {} 44 | }; 45 | 46 | class Decrease : public FunctionModifier { 47 | 48 | public: 49 | 50 | Decrease( int val = 1 ) : FunctionModifier( "DECREASE", val ) { } 51 | 52 | Decrease( Function * f, const IntVec & p = IntVec() ) : FunctionModifier( "DECREASE", f, p ) { } 53 | 54 | Decrease( const FunctionModifier * i, Domain & d ) : FunctionModifier( "DECREASE", i, d ) { } 55 | 56 | Condition * copy( Domain & d ) { 57 | return new Decrease( this, d ); 58 | } 59 | }; 60 | 61 | class Increase : public FunctionModifier { 62 | 63 | public: 64 | 65 | Increase( int val = 1 ) : FunctionModifier( "INCREASE", val ) { } 66 | 67 | Increase( Function * f, const IntVec & p = IntVec() ) : FunctionModifier( "INCREASE", f, p ) { } 68 | 69 | Increase( const FunctionModifier * i, Domain & d ) : FunctionModifier( "INCREASE", i, d ) { } 70 | 71 | Condition * copy( Domain & d ) { 72 | return new Increase( this, d ); 73 | } 74 | }; 75 | 76 | } } // namespaces 77 | -------------------------------------------------------------------------------- /tests/expected/Log_dom.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( DOMAIN LOGISTICS ) 2 | ( :REQUIREMENTS :STRIPS :TYPING ) 3 | ( :TYPES 4 | VEHICLE - PHYSOBJ 5 | TRUCK - VEHICLE 6 | AIRPLANE - VEHICLE 7 | PHYSOBJ - OBJECT 8 | PACKAGE - PHYSOBJ 9 | PLACE - OBJECT 10 | AIRPORT - PLACE 11 | LOCATION - PLACE 12 | CITY - OBJECT 13 | ) 14 | ( :PREDICATES 15 | ( IN-CITY ?PLACE0 - PLACE ?CITY1 - CITY ) 16 | ( AT ?PHYSOBJ0 - PHYSOBJ ?PLACE1 - PLACE ) 17 | ( IN ?PACKAGE0 - PACKAGE ?VEHICLE1 - VEHICLE ) 18 | ) 19 | ( :ACTION LOAD-TRUCK 20 | :PARAMETERS ( ?PACKAGE0 - PACKAGE ?TRUCK1 - TRUCK ?PLACE2 - PLACE ) 21 | :PRECONDITION 22 | ( AND 23 | ( AT ?TRUCK1 ?PLACE2 ) 24 | ( AT ?PACKAGE0 ?PLACE2 ) 25 | ) 26 | :EFFECT 27 | ( AND 28 | ( NOT ( AT ?PACKAGE0 ?PLACE2 ) ) 29 | ( IN ?PACKAGE0 ?TRUCK1 ) 30 | ) 31 | ) 32 | ( :ACTION LOAD-AIRPLANE 33 | :PARAMETERS ( ?PACKAGE0 - PACKAGE ?AIRPLANE1 - AIRPLANE ?PLACE2 - PLACE ) 34 | :PRECONDITION 35 | ( AND 36 | ( AT ?PACKAGE0 ?PLACE2 ) 37 | ( AT ?AIRPLANE1 ?PLACE2 ) 38 | ) 39 | :EFFECT 40 | ( AND 41 | ( NOT ( AT ?PACKAGE0 ?PLACE2 ) ) 42 | ( IN ?PACKAGE0 ?AIRPLANE1 ) 43 | ) 44 | ) 45 | ( :ACTION UNLOAD-TRUCK 46 | :PARAMETERS ( ?PACKAGE0 - PACKAGE ?TRUCK1 - TRUCK ?PLACE2 - PLACE ) 47 | :PRECONDITION 48 | ( AND 49 | ( AT ?TRUCK1 ?PLACE2 ) 50 | ( IN ?PACKAGE0 ?TRUCK1 ) 51 | ) 52 | :EFFECT 53 | ( AND 54 | ( NOT ( IN ?PACKAGE0 ?TRUCK1 ) ) 55 | ( AT ?PACKAGE0 ?PLACE2 ) 56 | ) 57 | ) 58 | ( :ACTION UNLOAD-AIRPLANE 59 | :PARAMETERS ( ?PACKAGE0 - PACKAGE ?AIRPLANE1 - AIRPLANE ?PLACE2 - PLACE ) 60 | :PRECONDITION 61 | ( AND 62 | ( IN ?PACKAGE0 ?AIRPLANE1 ) 63 | ( AT ?AIRPLANE1 ?PLACE2 ) 64 | ) 65 | :EFFECT 66 | ( AND 67 | ( NOT ( IN ?PACKAGE0 ?AIRPLANE1 ) ) 68 | ( AT ?PACKAGE0 ?PLACE2 ) 69 | ) 70 | ) 71 | ( :ACTION DRIVE-TRUCK 72 | :PARAMETERS ( ?TRUCK0 - TRUCK ?PLACE1 - PLACE ?PLACE2 - PLACE ?CITY3 - CITY ) 73 | :PRECONDITION 74 | ( AND 75 | ( AT ?TRUCK0 ?PLACE1 ) 76 | ( IN-CITY ?PLACE1 ?CITY3 ) 77 | ( IN-CITY ?PLACE2 ?CITY3 ) 78 | ) 79 | :EFFECT 80 | ( AND 81 | ( NOT ( AT ?TRUCK0 ?PLACE1 ) ) 82 | ( AT ?TRUCK0 ?PLACE2 ) 83 | ) 84 | ) 85 | ( :ACTION FLY-AIRPLANE 86 | :PARAMETERS ( ?AIRPLANE0 - AIRPLANE ?AIRPORT1 - AIRPORT ?AIRPORT2 - AIRPORT ) 87 | :PRECONDITION 88 | ( AT ?AIRPLANE0 ?AIRPORT1 ) 89 | :EFFECT 90 | ( AND 91 | ( NOT ( AT ?AIRPLANE0 ?AIRPORT1 ) ) 92 | ( AT ?AIRPLANE0 ?AIRPORT2 ) 93 | ) 94 | ) 95 | ) 96 | -------------------------------------------------------------------------------- /parser/Expression.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Instance.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void FunctionExpression::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | ParamCond * c = d.funcs[d.funcs.index( fun->name )]; 8 | 9 | s << "( " << fun->name; 10 | IntVec v( c->params.size() ); 11 | for ( unsigned i = 0; i < v.size(); ++i ) { 12 | if ( ts.size() && fun->params[i] >= 0 ) s << " " << ts[fun->params[i]]; 13 | else s << " " << d.types[c->params[i]]->object( fun->params[i] ).first; 14 | } 15 | s << " )"; 16 | } 17 | 18 | double FunctionExpression::evaluate( Instance & ins, const StringVec & par ) { 19 | ParamCond * c = ins.d.funcs[ins.d.funcs.index( fun->name )]; 20 | 21 | IntVec v( c->params.size() ); 22 | for ( unsigned i = 0; i < v.size(); ++i ) { 23 | std::pair< bool, unsigned > p = ins.d.types[c->params[i]]->parseObject( par[fun->params[i]] ); 24 | if ( p.first ) v[i] = p.second; 25 | else { 26 | std::pair< bool, int > q = ins.d.types[c->params[i]]->parseConstant( par[fun->params[i]] ); 27 | if ( q.first ) v[i] = q.second; 28 | else return 1; 29 | } 30 | } 31 | 32 | for ( unsigned i = 0; i < ins.init.size(); ++i ) 33 | if ( ins.init[i]->name == c->name && ins.init[i]->params == v ) 34 | return ((GroundFunc *)ins.init[i])->value; 35 | return 1; 36 | } 37 | 38 | Expression * createExpression( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 39 | f.next(); 40 | 41 | if ( f.getChar() == '(' ) { 42 | ++f.c; 43 | f.next(); 44 | std::string s = f.getToken(); 45 | if ( s == "+" || s == "-" || s == "*" || s == "/" ) { 46 | CompositeExpression * ce = new CompositeExpression( s ); 47 | ce->parse( f, ts, d ); 48 | return ce; 49 | } 50 | else { 51 | f.c -= s.size(); 52 | Function * fun = d.funcs.get( f.getToken( d.funcs ) ); 53 | ParamCond * c = new Lifted( fun ); 54 | for ( unsigned i = 0; i < fun->params.size(); ++i ) { 55 | f.next(); 56 | c->params[i] = ts.index( f.getToken( ts ) ); 57 | } 58 | f.next(); 59 | f.assert_token( ")" ); 60 | return new FunctionExpression( c ); 61 | } 62 | } 63 | else if ( f.getChar() == '?' ) { // just support DURATION if starts with ? 64 | f.assert_token( "?DURATION" ); 65 | return new DurationExpression(); 66 | } 67 | else { 68 | double d; 69 | std::string s = f.getToken(); 70 | std::istringstream is( s ); 71 | is >> d; 72 | return new ValueExpression( d ); 73 | } 74 | } 75 | 76 | } } 77 | -------------------------------------------------------------------------------- /domains/Elev_dom.pddl: -------------------------------------------------------------------------------- 1 | (define (domain elevators-sequencedstrips) 2 | (:requirements :typing :action-costs) 3 | (:types elevator - object 4 | slow-elevator fast-elevator - elevator 5 | passenger - object 6 | count - object 7 | ) 8 | 9 | (:predicates 10 | (passenger-at ?person - passenger ?floor - count) 11 | (boarded ?person - passenger ?lift - elevator) 12 | (lift-at ?lift - elevator ?floor - count) 13 | (reachable-floor ?lift - elevator ?floor - count) 14 | (above ?floor1 - count ?floor2 - count) 15 | (passengers ?lift - elevator ?n - count) 16 | (can-hold ?lift - elevator ?n - count) 17 | (next ?n1 - count ?n2 - count) 18 | ) 19 | 20 | (:functions (total-cost) - number 21 | (travel-slow ?f1 - count ?f2 - count) - number 22 | (travel-fast ?f1 - count ?f2 - count) - number 23 | ) 24 | 25 | (:action move-up-slow 26 | :parameters (?lift - slow-elevator ?f1 - count ?f2 - count ) 27 | :precondition (and (lift-at ?lift ?f1) (above ?f1 ?f2 ) (reachable-floor ?lift ?f2) ) 28 | :effect (and (lift-at ?lift ?f2) (not (lift-at ?lift ?f1)) (increase (total-cost) (travel-slow ?f1 ?f2)))) 29 | 30 | (:action move-down-slow 31 | :parameters (?lift - slow-elevator ?f1 - count ?f2 - count ) 32 | :precondition (and (lift-at ?lift ?f1) (above ?f2 ?f1 ) (reachable-floor ?lift ?f2) ) 33 | :effect (and (lift-at ?lift ?f2) (not (lift-at ?lift ?f1)) (increase (total-cost) (travel-slow ?f2 ?f1)))) 34 | 35 | (:action move-up-fast 36 | :parameters (?lift - fast-elevator ?f1 - count ?f2 - count ) 37 | :precondition (and (lift-at ?lift ?f1) (above ?f1 ?f2 ) (reachable-floor ?lift ?f2) ) 38 | :effect (and (lift-at ?lift ?f2) (not (lift-at ?lift ?f1)) (increase (total-cost) (travel-fast ?f1 ?f2)))) 39 | 40 | (:action move-down-fast 41 | :parameters (?lift - fast-elevator ?f1 - count ?f2 - count ) 42 | :precondition (and (lift-at ?lift ?f1) (above ?f2 ?f1 ) (reachable-floor ?lift ?f2) ) 43 | :effect (and (lift-at ?lift ?f2) (not (lift-at ?lift ?f1)) (increase (total-cost) (travel-fast ?f2 ?f1)))) 44 | 45 | (:action board 46 | :parameters (?p - passenger ?lift - elevator ?f - count ?n1 - count ?n2 - count) 47 | :precondition (and (lift-at ?lift ?f) (passenger-at ?p ?f) (passengers ?lift ?n1) (next ?n1 ?n2) (can-hold ?lift ?n2) ) 48 | :effect (and (not (passenger-at ?p ?f)) (boarded ?p ?lift) (not (passengers ?lift ?n1)) (passengers ?lift ?n2) )) 49 | 50 | (:action leave 51 | :parameters (?p - passenger ?lift - elevator ?f - count ?n1 - count ?n2 - count) 52 | :precondition (and (lift-at ?lift ?f) (boarded ?p ?lift) (passengers ?lift ?n1) (next ?n2 ?n1) ) 53 | :effect (and (passenger-at ?p ?f) (not (boarded ?p ?lift)) (not (passengers ?lift ?n1)) (passengers ?lift ?n2) )) 54 | 55 | ) 56 | 57 | -------------------------------------------------------------------------------- /parser/Basic.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) ) 18 | #define MAX( a, b ) ( ( a ) < ( b ) ? ( b ) : ( a ) ) 19 | #define SQR( a ) ( ( a ) * ( a ) ) 20 | 21 | #define PI 3.1415926535897932384 22 | 23 | typedef std::set< int > IntSet; 24 | typedef std::vector< int > IntVec; 25 | typedef std::set< double > DoubleSet; 26 | typedef std::vector< IntSet > SetVec; 27 | typedef std::pair< int, int > IntPair; 28 | typedef std::vector< IntPair > PairVec; 29 | typedef std::map< int, IntSet > SetMap; 30 | typedef std::vector< double > DoubleVec; 31 | typedef std::vector< unsigned > UnsignedVec; 32 | typedef std::vector< std::string > StringVec; 33 | typedef std::pair< double, double > DoublePair; 34 | 35 | // create a vector of integers from lo to (hi-1) 36 | inline IntVec incvec( unsigned lo, unsigned hi ) { 37 | IntVec out; 38 | for ( unsigned i = lo; i < hi; ++i ) 39 | out.push_back( i ); 40 | return out; 41 | } 42 | 43 | // insert all elements of a collection into a stream 44 | template < typename T > 45 | std::ostream & insertAll( std::ostream & stream, const T & begin, const T & end ) { 46 | T i = begin; 47 | stream << "["; 48 | if ( i != end ) stream << *( i++ ); 49 | while ( i != end ) stream << "," << *( i++ ); 50 | return stream << "]"; 51 | } 52 | 53 | // insert a pair into a stream 54 | template < typename T, typename U > 55 | std::ostream & operator<<( std::ostream & stream, const std::pair< T, U > & p ) { 56 | return stream << "(" << p.first << "," << p.second << ")"; 57 | } 58 | 59 | // insert a list into a stream 60 | template < typename T > 61 | std::ostream & operator<<( std::ostream & stream, const std::list< T > & l ) { 62 | return insertAll( stream, l.begin(), l.end() ); 63 | } 64 | 65 | // insert a map into a stream 66 | template < typename T, typename U > 67 | std::ostream & operator<<( std::ostream & stream, const std::map< T, U > & m ) { 68 | return insertAll( stream, m.begin(), m.end() ); 69 | } 70 | 71 | // insert a multiset into a stream 72 | template < typename T > 73 | std::ostream & operator<<( std::ostream & stream, const std::multiset< T > & s ) { 74 | return insertAll( stream, s.begin(), s.end() ); 75 | } 76 | 77 | // insert a set into a stream 78 | template < typename T > 79 | std::ostream & operator<<( std::ostream & stream, const std::set< T > & s ) { 80 | return insertAll( stream, s.begin(), s.end() ); 81 | } 82 | 83 | // insert a vector into a stream 84 | template < typename T > 85 | std::ostream & operator<<( std::ostream & stream, const std::vector< T > &v ) { 86 | return insertAll( stream, v.begin(), v.end() ); 87 | } 88 | 89 | 90 | inline void tabindent( std::ostream & stream, unsigned indent ) { 91 | for ( unsigned i = 0; i < indent; ++i ) 92 | stream << "\t"; 93 | } 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Universal PDDL Parser [![Build Status](https://travis-ci.org/aig-upf/universal-pddl-parser.svg?branch=master)](https://travis-ci.org/aig-upf/universal-pddl-parser) 3 | 4 | An algorithm for parsing any planning problem in PDDL format. 5 | 6 | 1. [Features](#features) 7 | 1. [Project Structure](#project-structure) 8 | 1. [Installation](#installation) 9 | 1. [Related Projects](#related-projects) 10 | 11 | ## Features 12 | 13 | The Universal PDDL Parser provides limited support for creating PDDL domains: 14 | 15 | - creating types 16 | - creating constants 17 | - adding predicates 18 | - adding functions 19 | - adding actions 20 | - adding preconditions and effects of actions 21 | - adding objects 22 | - adding initial and goal states 23 | 24 | However, more complicated constructs (such as `forall` and `when`) currently have to be implemented manually. These classes include a method `PDDLPrint` for printing the resulting domains in PDDL format. 25 | 26 | ## Project Structure 27 | 28 | * `parser` contains the main source code. 29 | * The build script leaves the compiled object file in `build`, the library files in `lib` 30 | * `tests` contains a number of tests 31 | * `script` contains certain scripts useful for automated testing and continuous integration 32 | * `domains` contains some sample domains 33 | 34 | ## Installation 35 | 36 | Firstly, download this project. You can alternatively clone it using the following command: 37 | 38 | ``` 39 | git clone https://github.com/aig-upf/universal-pddl-parser.git 40 | ``` 41 | 42 | Then, open the project folder and compile it using `scons`: 43 | 44 | ``` 45 | cd universal-pddl-parser 46 | scons 47 | ``` 48 | 49 | You can also run `scons tests`, which builds a binary that executes a series of automated tests on actual planning domains. To run the tests binary from the project folder do: 50 | 51 | ``` 52 | ./tests/test.bin 53 | ``` 54 | 55 | Finally, you can also compile a simple program using the Universal PDDL Parser. This program reads a PDDL domain and a PDDL instance, parses them and writes them on screen. You can compile the example using the command `scons examples`. Then, run the example from the project folder as follows: 56 | 57 | ``` 58 | ./examples/parser/parser.bin 59 | ``` 60 | 61 | For example, we can use the program in the Logistics domain: 62 | 63 | ``` 64 | ./examples/parser/parser.bin domains/Log_dom.pddl domains/Log_ins.pddl 65 | ``` 66 | 67 | ## Related Projects 68 | 69 | The [Universal PDDL Parser Multiagent](https://github.com/aig-upf/universal-pddl-parser-multiagent) repository extends the Universal PDDL Parser to allow parsing multiagent domains. Besides, it also provides tools for solving multiagent problems as classical planning problems. 70 | 71 | The [Temporal Planning](https://github.com/aig-upf/temporal-planning) repository contains tools that use the Universal PDDL Parser to parse temporal planning problems expressed using PDDL. 72 | -------------------------------------------------------------------------------- /parser/Action.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Domain.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | void Action::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 7 | s << "( :ACTION " << name << "\n"; 8 | 9 | s << " :PARAMETERS "; 10 | 11 | TokenStruct< std::string > astruct; 12 | 13 | printParams( 0, s, astruct, d ); 14 | 15 | s << " :PRECONDITION\n"; 16 | if ( pre ) pre->PDDLPrint( s, 1, astruct, d ); 17 | else s << "\t()"; 18 | s << "\n"; 19 | 20 | s << " :EFFECT\n"; 21 | if ( eff ) eff->PDDLPrint( s, 1, astruct, d ); 22 | else s << "\t()"; 23 | s << "\n"; 24 | 25 | s << ")\n"; 26 | } 27 | 28 | void Action::parseConditions( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 29 | f.next(); 30 | f.assert_token( ":" ); 31 | std::string s = f.getToken(); 32 | if ( s == "PRECONDITION" ) { 33 | f.next(); 34 | f.assert_token( "(" ); 35 | if ( f.getChar() != ')' ) { 36 | pre = d.createCondition( f ); 37 | pre->parse( f, ts, d ); 38 | } 39 | else ++f.c; 40 | 41 | f.next(); 42 | f.assert_token( ":" ); 43 | s = f.getToken(); 44 | } 45 | if ( s != "EFFECT" ) f.tokenExit( s ); 46 | 47 | f.next(); 48 | f.assert_token( "(" ); 49 | if ( f.getChar() != ')' ) { 50 | eff = d.createCondition( f ); 51 | eff->parse( f, ts, d ); 52 | } 53 | else ++f.c; 54 | f.next(); 55 | f.assert_token( ")" ); 56 | } 57 | 58 | void Action::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 59 | f.next(); 60 | f.assert_token( ":PARAMETERS" ); 61 | f.assert_token( "(" ); 62 | 63 | TokenStruct< std::string > astruct = f.parseTypedList( true, d.types ); 64 | params = d.convertTypes( astruct.types ); 65 | 66 | parseConditions( f, astruct, d ); 67 | } 68 | 69 | CondVec Action::precons() { 70 | return getSubconditionsFromCondition( pre ); 71 | } 72 | 73 | CondVec Action::effects() { 74 | return getSubconditionsFromCondition( eff ); 75 | } 76 | 77 | GroundVec Action::addEffects() { 78 | return getGroundsFromCondition( eff, false ); 79 | } 80 | 81 | GroundVec Action::deleteEffects() { 82 | return getGroundsFromCondition( eff, true ); 83 | } 84 | 85 | CondVec Action::getSubconditionsFromCondition( Condition * c ) { 86 | And * a = dynamic_cast< And * >( c ); 87 | if ( a ) return a->conds; 88 | 89 | CondVec subconds; 90 | if ( c ) subconds.push_back( c ); 91 | return subconds; 92 | } 93 | 94 | GroundVec Action::getGroundsFromCondition( Condition * c, bool neg ) { 95 | GroundVec grounds; 96 | And * a = dynamic_cast< And * >( c ); 97 | for ( unsigned i = 0; a && i < a->conds.size(); ++i ) { 98 | if ( neg ) { 99 | Not * n = dynamic_cast< Not * >( a->conds[i] ); 100 | if ( n ) grounds.push_back( n->cond ); 101 | } 102 | else { 103 | Ground * g = dynamic_cast< Ground * >( a->conds[i] ); 104 | if ( g ) grounds.push_back( g ); 105 | } 106 | } 107 | 108 | if ( neg ) { 109 | Not * n = dynamic_cast< Not * >( c ); 110 | if ( n ) grounds.push_back( n->cond ); 111 | } 112 | else { 113 | Ground * g = dynamic_cast< Ground * >( c ); 114 | if ( g ) grounds.push_back( g ); 115 | } 116 | 117 | return grounds; 118 | } 119 | 120 | } } // namespaces 121 | -------------------------------------------------------------------------------- /domains/Mapana_ins.pddl: -------------------------------------------------------------------------------- 1 | (define (problem citycar-3-3-4) 2 | (:domain mapanalyzer) 3 | (:objects 4 | junction0-0 junction0-1 junction0-2 5 | junction1-0 junction1-1 junction1-2 6 | junction2-0 junction2-1 junction2-2 - junction 7 | car0 car1 car2 car3 - car 8 | garage0 garage1 - garage 9 | road0 road1 road2 road3 road4 - road 10 | ) 11 | (:init 12 | (=(build-time) 5) 13 | (=(remove-time) 3) 14 | (=(arrived-time) 1) 15 | (=(start-time) 1) 16 | (=(speed car0) 14) 17 | (=(speed car1) 7) 18 | (=(speed car2) 10) 19 | (=(speed car3) 4) 20 | (available road0) 21 | (available road1) 22 | (available road2) 23 | (available road3) 24 | (available road4) 25 | (connected junction0-0 junction0-1) 26 | (connected junction0-1 junction0-0) 27 | (=(distance junction0-0 junction0-1) 91) 28 | (=(distance junction0-1 junction0-0) 91) 29 | (connected junction0-1 junction0-2) 30 | (connected junction0-2 junction0-1) 31 | (=(distance junction0-1 junction0-2) 46) 32 | (=(distance junction0-2 junction0-1) 46) 33 | (connected junction1-0 junction1-1) 34 | (connected junction1-1 junction1-0) 35 | (=(distance junction1-0 junction1-1) 69) 36 | (=(distance junction1-1 junction1-0) 69) 37 | (connected junction1-1 junction1-2) 38 | (connected junction1-2 junction1-1) 39 | (=(distance junction1-1 junction1-2) 85) 40 | (=(distance junction1-2 junction1-1) 85) 41 | (connected junction2-0 junction2-1) 42 | (connected junction2-1 junction2-0) 43 | (=(distance junction2-0 junction2-1) 58) 44 | (=(distance junction2-1 junction2-0) 58) 45 | (connected junction2-1 junction2-2) 46 | (connected junction2-2 junction2-1) 47 | (=(distance junction2-1 junction2-2) 70) 48 | (=(distance junction2-2 junction2-1) 70) 49 | (connected junction0-0 junction1-0) 50 | (connected junction1-0 junction0-0) 51 | (=(distance junction0-0 junction1-0) 12) 52 | (=(distance junction1-0 junction0-0) 12) 53 | (connected junction1-0 junction2-0) 54 | (connected junction2-0 junction1-0) 55 | (=(distance junction1-0 junction2-0) 70) 56 | (=(distance junction2-0 junction1-0) 70) 57 | (connected junction0-1 junction1-1) 58 | (connected junction1-1 junction0-1) 59 | (=(distance junction0-1 junction1-1) 91) 60 | (=(distance junction1-1 junction0-1) 91) 61 | (connected junction1-1 junction2-1) 62 | (connected junction2-1 junction1-1) 63 | (=(distance junction1-1 junction2-1) 12) 64 | (=(distance junction2-1 junction1-1) 12) 65 | (connected junction0-2 junction1-2) 66 | (connected junction1-2 junction0-2) 67 | (=(distance junction0-2 junction1-2) 50) 68 | (=(distance junction1-2 junction0-2) 50) 69 | (connected junction1-2 junction2-2) 70 | (connected junction2-2 junction1-2) 71 | (=(distance junction1-2 junction2-2) 24) 72 | (=(distance junction2-2 junction1-2) 24) 73 | (clear junction0-0) 74 | (clear junction0-1) 75 | (clear junction0-2) 76 | (clear junction1-0) 77 | (clear junction1-1) 78 | (clear junction1-2) 79 | (clear junction2-0) 80 | (clear junction2-1) 81 | (clear junction2-2) 82 | (at_garage garage0 junction0-2) 83 | (at_garage garage1 junction0-2) 84 | (starting car0 garage0) 85 | (starting car1 garage1) 86 | (starting car2 garage1) 87 | (starting car3 garage0) 88 | ) 89 | (:goal 90 | (and 91 | (arrived car0 junction2-2) 92 | (arrived car1 junction2-2) 93 | (arrived car2 junction2-1) 94 | (arrived car3 junction2-0) 95 | ) 96 | ) 97 | (:metric minimize (total-time)) 98 | ) 99 | -------------------------------------------------------------------------------- /tests/expected/Mapana_ins.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( PROBLEM CITYCAR-3-3-4 ) 2 | ( :DOMAIN MAPANALYZER ) 3 | ( :OBJECTS 4 | CAR0 CAR1 CAR2 CAR3 - CAR 5 | JUNCTION0-0 JUNCTION0-1 JUNCTION0-2 JUNCTION1-0 JUNCTION1-1 JUNCTION1-2 JUNCTION2-0 JUNCTION2-1 JUNCTION2-2 - JUNCTION 6 | GARAGE0 GARAGE1 - GARAGE 7 | ROAD0 ROAD1 ROAD2 ROAD3 ROAD4 - ROAD 8 | ) 9 | ( :INIT 10 | ( = ( BUILD-TIME ) 5 ) 11 | ( = ( REMOVE-TIME ) 3 ) 12 | ( = ( ARRIVED-TIME ) 1 ) 13 | ( = ( START-TIME ) 1 ) 14 | ( = ( SPEED CAR0 ) 14 ) 15 | ( = ( SPEED CAR1 ) 7 ) 16 | ( = ( SPEED CAR2 ) 10 ) 17 | ( = ( SPEED CAR3 ) 4 ) 18 | ( AVAILABLE ROAD0 ) 19 | ( AVAILABLE ROAD1 ) 20 | ( AVAILABLE ROAD2 ) 21 | ( AVAILABLE ROAD3 ) 22 | ( AVAILABLE ROAD4 ) 23 | ( CONNECTED JUNCTION0-0 JUNCTION0-1 ) 24 | ( CONNECTED JUNCTION0-1 JUNCTION0-0 ) 25 | ( = ( DISTANCE JUNCTION0-0 JUNCTION0-1 ) 91 ) 26 | ( = ( DISTANCE JUNCTION0-1 JUNCTION0-0 ) 91 ) 27 | ( CONNECTED JUNCTION0-1 JUNCTION0-2 ) 28 | ( CONNECTED JUNCTION0-2 JUNCTION0-1 ) 29 | ( = ( DISTANCE JUNCTION0-1 JUNCTION0-2 ) 46 ) 30 | ( = ( DISTANCE JUNCTION0-2 JUNCTION0-1 ) 46 ) 31 | ( CONNECTED JUNCTION1-0 JUNCTION1-1 ) 32 | ( CONNECTED JUNCTION1-1 JUNCTION1-0 ) 33 | ( = ( DISTANCE JUNCTION1-0 JUNCTION1-1 ) 69 ) 34 | ( = ( DISTANCE JUNCTION1-1 JUNCTION1-0 ) 69 ) 35 | ( CONNECTED JUNCTION1-1 JUNCTION1-2 ) 36 | ( CONNECTED JUNCTION1-2 JUNCTION1-1 ) 37 | ( = ( DISTANCE JUNCTION1-1 JUNCTION1-2 ) 85 ) 38 | ( = ( DISTANCE JUNCTION1-2 JUNCTION1-1 ) 85 ) 39 | ( CONNECTED JUNCTION2-0 JUNCTION2-1 ) 40 | ( CONNECTED JUNCTION2-1 JUNCTION2-0 ) 41 | ( = ( DISTANCE JUNCTION2-0 JUNCTION2-1 ) 58 ) 42 | ( = ( DISTANCE JUNCTION2-1 JUNCTION2-0 ) 58 ) 43 | ( CONNECTED JUNCTION2-1 JUNCTION2-2 ) 44 | ( CONNECTED JUNCTION2-2 JUNCTION2-1 ) 45 | ( = ( DISTANCE JUNCTION2-1 JUNCTION2-2 ) 70 ) 46 | ( = ( DISTANCE JUNCTION2-2 JUNCTION2-1 ) 70 ) 47 | ( CONNECTED JUNCTION0-0 JUNCTION1-0 ) 48 | ( CONNECTED JUNCTION1-0 JUNCTION0-0 ) 49 | ( = ( DISTANCE JUNCTION0-0 JUNCTION1-0 ) 12 ) 50 | ( = ( DISTANCE JUNCTION1-0 JUNCTION0-0 ) 12 ) 51 | ( CONNECTED JUNCTION1-0 JUNCTION2-0 ) 52 | ( CONNECTED JUNCTION2-0 JUNCTION1-0 ) 53 | ( = ( DISTANCE JUNCTION1-0 JUNCTION2-0 ) 70 ) 54 | ( = ( DISTANCE JUNCTION2-0 JUNCTION1-0 ) 70 ) 55 | ( CONNECTED JUNCTION0-1 JUNCTION1-1 ) 56 | ( CONNECTED JUNCTION1-1 JUNCTION0-1 ) 57 | ( = ( DISTANCE JUNCTION0-1 JUNCTION1-1 ) 91 ) 58 | ( = ( DISTANCE JUNCTION1-1 JUNCTION0-1 ) 91 ) 59 | ( CONNECTED JUNCTION1-1 JUNCTION2-1 ) 60 | ( CONNECTED JUNCTION2-1 JUNCTION1-1 ) 61 | ( = ( DISTANCE JUNCTION1-1 JUNCTION2-1 ) 12 ) 62 | ( = ( DISTANCE JUNCTION2-1 JUNCTION1-1 ) 12 ) 63 | ( CONNECTED JUNCTION0-2 JUNCTION1-2 ) 64 | ( CONNECTED JUNCTION1-2 JUNCTION0-2 ) 65 | ( = ( DISTANCE JUNCTION0-2 JUNCTION1-2 ) 50 ) 66 | ( = ( DISTANCE JUNCTION1-2 JUNCTION0-2 ) 50 ) 67 | ( CONNECTED JUNCTION1-2 JUNCTION2-2 ) 68 | ( CONNECTED JUNCTION2-2 JUNCTION1-2 ) 69 | ( = ( DISTANCE JUNCTION1-2 JUNCTION2-2 ) 24 ) 70 | ( = ( DISTANCE JUNCTION2-2 JUNCTION1-2 ) 24 ) 71 | ( CLEAR JUNCTION0-0 ) 72 | ( CLEAR JUNCTION0-1 ) 73 | ( CLEAR JUNCTION0-2 ) 74 | ( CLEAR JUNCTION1-0 ) 75 | ( CLEAR JUNCTION1-1 ) 76 | ( CLEAR JUNCTION1-2 ) 77 | ( CLEAR JUNCTION2-0 ) 78 | ( CLEAR JUNCTION2-1 ) 79 | ( CLEAR JUNCTION2-2 ) 80 | ( AT_GARAGE GARAGE0 JUNCTION0-2 ) 81 | ( AT_GARAGE GARAGE1 JUNCTION0-2 ) 82 | ( STARTING CAR0 GARAGE0 ) 83 | ( STARTING CAR1 GARAGE1 ) 84 | ( STARTING CAR2 GARAGE1 ) 85 | ( STARTING CAR3 GARAGE0 ) 86 | ) 87 | ( :GOAL 88 | ( AND 89 | ( ARRIVED CAR0 JUNCTION2-2 ) 90 | ( ARRIVED CAR1 JUNCTION2-2 ) 91 | ( ARRIVED CAR2 JUNCTION2-1 ) 92 | ( ARRIVED CAR3 JUNCTION2-0 ) 93 | ) 94 | ) 95 | ( :METRIC MINIMIZE ( TOTAL-TIME ) ) 96 | ) 97 | -------------------------------------------------------------------------------- /parser/Type.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "TokenStruct.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Type; 9 | 10 | typedef std::vector< Type * > TypeVec; 11 | 12 | class Type { 13 | 14 | public: 15 | 16 | std::string name; 17 | TypeVec subtypes; 18 | Type * supertype; 19 | 20 | TokenStruct< std::string > constants; 21 | TokenStruct< std::string > objects; 22 | 23 | Type() 24 | : supertype( 0 ) {} 25 | 26 | Type( const std::string & s ) 27 | : name( s ), supertype( 0 ) {} 28 | 29 | Type( const Type * t ) 30 | : name( t->name ), supertype( 0 ), constants( t->constants ), objects( t->objects ) {} 31 | 32 | virtual ~Type() { 33 | } 34 | 35 | virtual std::string getName() const { 36 | return name; 37 | } 38 | 39 | void insertSubtype( Type * t ) { 40 | subtypes.push_back( t ); 41 | t->supertype = this; 42 | } 43 | 44 | void copySubtypes( Type * t, const TokenStruct< Type * > & ts ) { 45 | for ( unsigned i = 0; i < t->subtypes.size(); ++i ) 46 | subtypes.push_back( ts.get( t->subtypes[i]->name ) ); 47 | } 48 | 49 | void print( std::ostream & stream ) const { 50 | stream << name; 51 | if ( supertype ) stream << "[" << supertype->name << "]"; 52 | stream << "\n"; 53 | } 54 | 55 | virtual void PDDLPrint( std::ostream & s ) const { 56 | s << "\t" << name; 57 | if ( supertype ) s << " - " << supertype->name; 58 | s << "\n"; 59 | } 60 | 61 | std::pair< bool, int > parseConstant( const std::string & object ) { 62 | int k = 0; 63 | 64 | int i = constants.index( object ); 65 | if ( i < 0 ) k += constants.size(); 66 | else return std::make_pair( true, -1 - i ); 67 | 68 | for ( unsigned i = 0; i < subtypes.size(); ++i ) { 69 | std::pair< bool, int > p = subtypes[i]->parseConstant( object ); 70 | if ( p.first ) return std::make_pair( true, - k + p.second ); 71 | else k += p.second; 72 | } 73 | 74 | return std::make_pair( false, k ); 75 | } 76 | 77 | std::pair< bool, unsigned > parseObject( const std::string & object ) { 78 | unsigned k = 0; 79 | 80 | int i = objects.index( object ); 81 | if ( i < 0 ) k += objects.size(); 82 | else return std::make_pair( true, i ); 83 | 84 | for ( unsigned i = 0; i < subtypes.size(); ++i ) { 85 | std::pair< bool, unsigned > p = subtypes[i]->parseObject( object ); 86 | if ( p.first ) return std::make_pair( true, k + p.second ); 87 | else k += p.second; 88 | } 89 | 90 | return std::make_pair( false, k ); 91 | } 92 | 93 | std::pair< std::string, int > object( int index ) { 94 | if ( index < 0 ) { 95 | if ( -index <= (int)constants.size() ) return std::make_pair( constants[-1 - index], 0 ); 96 | else index += constants.size(); 97 | } 98 | else { 99 | if ( index < (int)objects.size() ) return std::make_pair( objects[index], 0 ); 100 | else index -= objects.size(); 101 | } 102 | 103 | for ( unsigned i = 0; i < subtypes.size(); ++i ) { 104 | std::pair< std::string, int > p = subtypes[i]->object( index ); 105 | if ( p.first.size() ) return p; 106 | else index = p.second; 107 | } 108 | 109 | return std::make_pair( "", index ); 110 | } 111 | 112 | unsigned noObjects() { 113 | unsigned total = objects.size() + constants.size(); 114 | for ( unsigned i = 0; i < subtypes.size(); ++i ) 115 | total += subtypes[i]->noObjects(); 116 | return total; 117 | } 118 | 119 | unsigned noConstants() { 120 | unsigned total = constants.size(); 121 | for ( unsigned i = 0; i < subtypes.size(); ++i ) { 122 | total += subtypes[i]->noConstants(); 123 | } 124 | return total; 125 | } 126 | 127 | virtual Type * copy() { 128 | return new Type( this ); 129 | } 130 | 131 | }; 132 | 133 | inline std::ostream & operator<<( std::ostream & stream, const Type * t ) { 134 | t->print( stream ); 135 | return stream; 136 | } 137 | 138 | } } // namespaces 139 | -------------------------------------------------------------------------------- /tests/expected/Mapana_dom.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( DOMAIN MAPANALYZER ) 2 | ( :REQUIREMENTS :TYPING :DURATIVE-ACTIONS ) 3 | ( :TYPES 4 | VEHICLE - OBJECT 5 | CAR - VEHICLE 6 | JUNCTION - OBJECT 7 | GARAGE - OBJECT 8 | ROAD - OBJECT 9 | ) 10 | ( :PREDICATES 11 | ( CONNECTED ?JUNCTION0 - JUNCTION ?JUNCTION1 - JUNCTION ) 12 | ( AT_JUN ?VEHICLE0 - VEHICLE ?JUNCTION1 - JUNCTION ) 13 | ( STARTING ?VEHICLE0 - VEHICLE ?GARAGE1 - GARAGE ) 14 | ( ARRIVED ?VEHICLE0 - VEHICLE ?JUNCTION1 - JUNCTION ) 15 | ( ROAD_CONNECT ?ROAD0 - ROAD ?JUNCTION1 - JUNCTION ?JUNCTION2 - JUNCTION ) 16 | ( CLEAR ?JUNCTION0 - JUNCTION ) 17 | ( IN_PLACE ?ROAD0 - ROAD ) 18 | ( AVAILABLE ?ROAD0 - ROAD ) 19 | ( AT_GARAGE ?GARAGE0 - GARAGE ?JUNCTION1 - JUNCTION ) 20 | ) 21 | ( :FUNCTIONS 22 | ( DISTANCE ?JUNCTION0 - JUNCTION ?JUNCTION1 - JUNCTION ) 23 | ( BUILD-TIME ) 24 | ( REMOVE-TIME ) 25 | ( SPEED ?VEHICLE0 - VEHICLE ) 26 | ( ARRIVED-TIME ) 27 | ( START-TIME ) 28 | ) 29 | ( :DURATIVE-ACTION MOVE_VEHICLE_ROAD 30 | :PARAMETERS ( ?JUNCTION0 - JUNCTION ?JUNCTION1 - JUNCTION ?VEHICLE2 - VEHICLE ?ROAD3 - ROAD ) 31 | :DURATION ( = ?DURATION ( / ( DISTANCE ?JUNCTION0 ?JUNCTION1 ) ( SPEED ?VEHICLE2 ) ) ) 32 | :CONDITION 33 | ( AND 34 | ( AT START ( AT_JUN ?VEHICLE2 ?JUNCTION0 ) ) 35 | ( AT START ( ROAD_CONNECT ?ROAD3 ?JUNCTION0 ?JUNCTION1 ) ) 36 | ( AT START ( IN_PLACE ?ROAD3 ) ) 37 | ( AT END ( CLEAR ?JUNCTION1 ) ) 38 | ) 39 | :EFFECT 40 | ( AND 41 | ( AT START ( CLEAR ?JUNCTION0 ) ) 42 | ( AT START ( NOT ( AT_JUN ?VEHICLE2 ?JUNCTION0 ) ) ) 43 | ( AT END ( AT_JUN ?VEHICLE2 ?JUNCTION1 ) ) 44 | ) 45 | ) 46 | ( :DURATIVE-ACTION VEHICLE_ARRIVED 47 | :PARAMETERS ( ?JUNCTION0 - JUNCTION ?VEHICLE1 - VEHICLE ) 48 | :DURATION ( = ?DURATION ( ARRIVED-TIME ) ) 49 | :CONDITION 50 | ( AND 51 | ( AT START ( AT_JUN ?VEHICLE1 ?JUNCTION0 ) ) 52 | ) 53 | :EFFECT 54 | ( AND 55 | ( AT END ( CLEAR ?JUNCTION0 ) ) 56 | ( AT END ( ARRIVED ?VEHICLE1 ?JUNCTION0 ) ) 57 | ( AT END ( NOT ( AT_JUN ?VEHICLE1 ?JUNCTION0 ) ) ) 58 | ) 59 | ) 60 | ( :DURATIVE-ACTION VEHICLE_START 61 | :PARAMETERS ( ?JUNCTION0 - JUNCTION ?VEHICLE1 - VEHICLE ?GARAGE2 - GARAGE ) 62 | :DURATION ( = ?DURATION ( START-TIME ) ) 63 | :CONDITION 64 | ( AND 65 | ( AT START ( AT_GARAGE ?GARAGE2 ?JUNCTION0 ) ) 66 | ( AT START ( STARTING ?VEHICLE1 ?GARAGE2 ) ) 67 | ( AT START ( CLEAR ?JUNCTION0 ) ) 68 | ) 69 | :EFFECT 70 | ( AND 71 | ( AT START ( NOT ( STARTING ?VEHICLE1 ?GARAGE2 ) ) ) 72 | ( AT END ( NOT ( CLEAR ?JUNCTION0 ) ) ) 73 | ( AT END ( AT_JUN ?VEHICLE1 ?JUNCTION0 ) ) 74 | ) 75 | ) 76 | ( :DURATIVE-ACTION BUILD_ROAD 77 | :PARAMETERS ( ?JUNCTION0 - JUNCTION ?JUNCTION1 - JUNCTION ?ROAD2 - ROAD ) 78 | :DURATION ( = ?DURATION ( * ( DISTANCE ?JUNCTION0 ?JUNCTION1 ) ( BUILD-TIME ) ) ) 79 | :CONDITION 80 | ( AND 81 | ( AT START ( CLEAR ?JUNCTION1 ) ) 82 | ( AT START ( AVAILABLE ?ROAD2 ) ) 83 | ( AT START ( CONNECTED ?JUNCTION0 ?JUNCTION1 ) ) 84 | ) 85 | :EFFECT 86 | ( AND 87 | ( AT START ( IN_PLACE ?ROAD2 ) ) 88 | ( AT START ( NOT ( AVAILABLE ?ROAD2 ) ) ) 89 | ( AT END ( ROAD_CONNECT ?ROAD2 ?JUNCTION0 ?JUNCTION1 ) ) 90 | ( AT END ( ROAD_CONNECT ?ROAD2 ?JUNCTION1 ?JUNCTION0 ) ) 91 | ) 92 | ) 93 | ( :DURATIVE-ACTION REMOVE_ROAD 94 | :PARAMETERS ( ?JUNCTION0 - JUNCTION ?JUNCTION1 - JUNCTION ?ROAD2 - ROAD ) 95 | :DURATION ( = ?DURATION ( * ( DISTANCE ?JUNCTION0 ?JUNCTION1 ) ( REMOVE-TIME ) ) ) 96 | :CONDITION 97 | ( AND 98 | ( AT START ( ROAD_CONNECT ?ROAD2 ?JUNCTION0 ?JUNCTION1 ) ) 99 | ( AT START ( ROAD_CONNECT ?ROAD2 ?JUNCTION1 ?JUNCTION0 ) ) 100 | ( AT START ( IN_PLACE ?ROAD2 ) ) 101 | ) 102 | :EFFECT 103 | ( AND 104 | ( AT START ( NOT ( ROAD_CONNECT ?ROAD2 ?JUNCTION0 ?JUNCTION1 ) ) ) 105 | ( AT START ( NOT ( ROAD_CONNECT ?ROAD2 ?JUNCTION1 ?JUNCTION0 ) ) ) 106 | ( AT END ( NOT ( IN_PLACE ?ROAD2 ) ) ) 107 | ( AT END ( AVAILABLE ?ROAD2 ) ) 108 | ) 109 | ) 110 | ) 111 | -------------------------------------------------------------------------------- /tests/expected/Elev_dom.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( DOMAIN ELEVATORS-SEQUENCEDSTRIPS ) 2 | ( :REQUIREMENTS :ACTION-COSTS :TYPING ) 3 | ( :TYPES 4 | ELEVATOR - OBJECT 5 | SLOW-ELEVATOR - ELEVATOR 6 | FAST-ELEVATOR - ELEVATOR 7 | PASSENGER - OBJECT 8 | COUNT - OBJECT 9 | ) 10 | ( :PREDICATES 11 | ( PASSENGER-AT ?PASSENGER0 - PASSENGER ?COUNT1 - COUNT ) 12 | ( BOARDED ?PASSENGER0 - PASSENGER ?ELEVATOR1 - ELEVATOR ) 13 | ( LIFT-AT ?ELEVATOR0 - ELEVATOR ?COUNT1 - COUNT ) 14 | ( REACHABLE-FLOOR ?ELEVATOR0 - ELEVATOR ?COUNT1 - COUNT ) 15 | ( ABOVE ?COUNT0 - COUNT ?COUNT1 - COUNT ) 16 | ( PASSENGERS ?ELEVATOR0 - ELEVATOR ?COUNT1 - COUNT ) 17 | ( CAN-HOLD ?ELEVATOR0 - ELEVATOR ?COUNT1 - COUNT ) 18 | ( NEXT ?COUNT0 - COUNT ?COUNT1 - COUNT ) 19 | ) 20 | ( :FUNCTIONS 21 | ( TOTAL-COST ) 22 | ( TRAVEL-SLOW ?COUNT0 - COUNT ?COUNT1 - COUNT ) 23 | ( TRAVEL-FAST ?COUNT0 - COUNT ?COUNT1 - COUNT ) 24 | ) 25 | ( :ACTION MOVE-UP-SLOW 26 | :PARAMETERS ( ?SLOW-ELEVATOR0 - SLOW-ELEVATOR ?COUNT1 - COUNT ?COUNT2 - COUNT ) 27 | :PRECONDITION 28 | ( AND 29 | ( LIFT-AT ?SLOW-ELEVATOR0 ?COUNT1 ) 30 | ( ABOVE ?COUNT1 ?COUNT2 ) 31 | ( REACHABLE-FLOOR ?SLOW-ELEVATOR0 ?COUNT2 ) 32 | ) 33 | :EFFECT 34 | ( AND 35 | ( LIFT-AT ?SLOW-ELEVATOR0 ?COUNT2 ) 36 | ( NOT ( LIFT-AT ?SLOW-ELEVATOR0 ?COUNT1 ) ) 37 | ( INCREASE ( TOTAL-COST ) ( TRAVEL-SLOW ?COUNT1 ?COUNT2 ) ) 38 | ) 39 | ) 40 | ( :ACTION MOVE-DOWN-SLOW 41 | :PARAMETERS ( ?SLOW-ELEVATOR0 - SLOW-ELEVATOR ?COUNT1 - COUNT ?COUNT2 - COUNT ) 42 | :PRECONDITION 43 | ( AND 44 | ( LIFT-AT ?SLOW-ELEVATOR0 ?COUNT1 ) 45 | ( ABOVE ?COUNT2 ?COUNT1 ) 46 | ( REACHABLE-FLOOR ?SLOW-ELEVATOR0 ?COUNT2 ) 47 | ) 48 | :EFFECT 49 | ( AND 50 | ( LIFT-AT ?SLOW-ELEVATOR0 ?COUNT2 ) 51 | ( NOT ( LIFT-AT ?SLOW-ELEVATOR0 ?COUNT1 ) ) 52 | ( INCREASE ( TOTAL-COST ) ( TRAVEL-SLOW ?COUNT2 ?COUNT1 ) ) 53 | ) 54 | ) 55 | ( :ACTION MOVE-UP-FAST 56 | :PARAMETERS ( ?FAST-ELEVATOR0 - FAST-ELEVATOR ?COUNT1 - COUNT ?COUNT2 - COUNT ) 57 | :PRECONDITION 58 | ( AND 59 | ( LIFT-AT ?FAST-ELEVATOR0 ?COUNT1 ) 60 | ( ABOVE ?COUNT1 ?COUNT2 ) 61 | ( REACHABLE-FLOOR ?FAST-ELEVATOR0 ?COUNT2 ) 62 | ) 63 | :EFFECT 64 | ( AND 65 | ( LIFT-AT ?FAST-ELEVATOR0 ?COUNT2 ) 66 | ( NOT ( LIFT-AT ?FAST-ELEVATOR0 ?COUNT1 ) ) 67 | ( INCREASE ( TOTAL-COST ) ( TRAVEL-FAST ?COUNT1 ?COUNT2 ) ) 68 | ) 69 | ) 70 | ( :ACTION MOVE-DOWN-FAST 71 | :PARAMETERS ( ?FAST-ELEVATOR0 - FAST-ELEVATOR ?COUNT1 - COUNT ?COUNT2 - COUNT ) 72 | :PRECONDITION 73 | ( AND 74 | ( LIFT-AT ?FAST-ELEVATOR0 ?COUNT1 ) 75 | ( ABOVE ?COUNT2 ?COUNT1 ) 76 | ( REACHABLE-FLOOR ?FAST-ELEVATOR0 ?COUNT2 ) 77 | ) 78 | :EFFECT 79 | ( AND 80 | ( LIFT-AT ?FAST-ELEVATOR0 ?COUNT2 ) 81 | ( NOT ( LIFT-AT ?FAST-ELEVATOR0 ?COUNT1 ) ) 82 | ( INCREASE ( TOTAL-COST ) ( TRAVEL-FAST ?COUNT2 ?COUNT1 ) ) 83 | ) 84 | ) 85 | ( :ACTION BOARD 86 | :PARAMETERS ( ?PASSENGER0 - PASSENGER ?ELEVATOR1 - ELEVATOR ?COUNT2 - COUNT ?COUNT3 - COUNT ?COUNT4 - COUNT ) 87 | :PRECONDITION 88 | ( AND 89 | ( LIFT-AT ?ELEVATOR1 ?COUNT2 ) 90 | ( PASSENGER-AT ?PASSENGER0 ?COUNT2 ) 91 | ( PASSENGERS ?ELEVATOR1 ?COUNT3 ) 92 | ( NEXT ?COUNT3 ?COUNT4 ) 93 | ( CAN-HOLD ?ELEVATOR1 ?COUNT4 ) 94 | ) 95 | :EFFECT 96 | ( AND 97 | ( NOT ( PASSENGER-AT ?PASSENGER0 ?COUNT2 ) ) 98 | ( BOARDED ?PASSENGER0 ?ELEVATOR1 ) 99 | ( NOT ( PASSENGERS ?ELEVATOR1 ?COUNT3 ) ) 100 | ( PASSENGERS ?ELEVATOR1 ?COUNT4 ) 101 | ) 102 | ) 103 | ( :ACTION LEAVE 104 | :PARAMETERS ( ?PASSENGER0 - PASSENGER ?ELEVATOR1 - ELEVATOR ?COUNT2 - COUNT ?COUNT3 - COUNT ?COUNT4 - COUNT ) 105 | :PRECONDITION 106 | ( AND 107 | ( LIFT-AT ?ELEVATOR1 ?COUNT2 ) 108 | ( BOARDED ?PASSENGER0 ?ELEVATOR1 ) 109 | ( PASSENGERS ?ELEVATOR1 ?COUNT3 ) 110 | ( NEXT ?COUNT4 ?COUNT3 ) 111 | ) 112 | :EFFECT 113 | ( AND 114 | ( PASSENGER-AT ?PASSENGER0 ?COUNT2 ) 115 | ( NOT ( BOARDED ?PASSENGER0 ?ELEVATOR1 ) ) 116 | ( NOT ( PASSENGERS ?ELEVATOR1 ?COUNT3 ) ) 117 | ( PASSENGERS ?ELEVATOR1 ?COUNT4 ) 118 | ) 119 | ) 120 | ) 121 | -------------------------------------------------------------------------------- /domains/Mapana_dom.pddl: -------------------------------------------------------------------------------- 1 | (define (domain mapanalyzer) 2 | (:requirements :typing :durative-actions) 3 | (:types 4 | car - vehicle 5 | junction 6 | garage 7 | road 8 | ) 9 | 10 | (:predicates 11 | (connected ?x - junction ?y - junction ) ;; junctions in diagonal (on the map) 12 | (at_jun ?c - vehicle ?x - junction) ;; a car is at the junction 13 | (starting ?c - vehicle ?x - garage) ;; a car is in its initial position 14 | (arrived ?c - vehicle ?x - junction) ;; a car arrived at destination 15 | (road_connect ?r1 - road ?xy - junction ?xy2 - junction) ;; there is a road that connects 2 junctions 16 | (clear ?xy - junction ) ;; the junction is clear, no vehicles 17 | (in_place ?x - road);; the road has been put in place 18 | (available ?x - road);; the road has been put in place 19 | (at_garage ?g - garage ?xy - junction ) ;; position of the starting garage 20 | 21 | ) 22 | (:functions 23 | (distance ?initial - junction ?final - junction) 24 | (build-time) 25 | (remove-time) 26 | (speed ?v - vehicle) 27 | (arrived-time) 28 | (start-time) 29 | ) 30 | 31 | ;; move the vehicle: no limit on the number of vehicles on the road, but the junction must be clear at the end 32 | (:durative-action move_vehicle_road 33 | :parameters (?xy_initial - junction ?xy_final - junction ?machine - vehicle ?r1 - road) 34 | :duration (= ?duration (/ (distance ?xy_initial ?xy_final) (speed ?machine))) 35 | :condition (and 36 | (at start (at_jun ?machine ?xy_initial)) 37 | (at start (road_connect ?r1 ?xy_initial ?xy_final)) 38 | (at start (in_place ?r1)) 39 | (at end (clear ?xy_final)) 40 | ) 41 | :effect (and 42 | (at start (clear ?xy_initial)) 43 | (at end (at_jun ?machine ?xy_final)) 44 | (at start (not (at_jun ?machine ?xy_initial))) 45 | ) 46 | ) 47 | 48 | 49 | ;; vehicle at the final position. They are removed from the network and position is cleared. 50 | (:durative-action vehicle_arrived 51 | :parameters (?xy_final - junction ?machine - vehicle ) 52 | :duration (= ?duration (arrived-time)) 53 | :condition (and 54 | (at start (at_jun ?machine ?xy_final)) 55 | ) 56 | :effect (and 57 | (at end (clear ?xy_final)) 58 | (at end (arrived ?machine ?xy_final)) 59 | (at end (not (at_jun ?machine ?xy_final))) 60 | ) 61 | ) 62 | 63 | ;; vehicle moved from the initial garage in the network. 64 | (:durative-action vehicle_start 65 | :parameters (?xy_final - junction ?machine - vehicle ?g - garage) 66 | :duration (= ?duration (start-time)) 67 | :condition (and 68 | (at start (at_garage ?g ?xy_final)) 69 | (at start (starting ?machine ?g)) 70 | (at start (clear ?xy_final)) 71 | ) 72 | :effect (and 73 | (at end (not (clear ?xy_final))) 74 | (at end (at_jun ?machine ?xy_final)) 75 | (at start (not (starting ?machine ?g))) 76 | ) 77 | ) 78 | 79 | ;; build road 80 | (:durative-action build_road 81 | :parameters (?xy_initial - junction ?xy_final - junction ?r1 - road) 82 | :duration (= ?duration (* (distance ?xy_initial ?xy_final) (build-time))) 83 | :condition (and 84 | (at start (clear ?xy_final)) 85 | (at start (available ?r1)) 86 | (at start (connected ?xy_initial ?xy_final)) 87 | ) 88 | :effect (and 89 | (at end (road_connect ?r1 ?xy_initial ?xy_final)) 90 | (at end (road_connect ?r1 ?xy_final ?xy_initial)) 91 | (at start (in_place ?r1)) 92 | (at start (not (available ?r1))) 93 | ) 94 | ) 95 | 96 | ;; remove a road 97 | (:durative-action remove_road 98 | :parameters (?xy_initial - junction ?xy_final - junction ?r1 - road) 99 | :duration (= ?duration (* (distance ?xy_initial ?xy_final) (remove-time))) 100 | :condition (and 101 | (at start (road_connect ?r1 ?xy_initial ?xy_final)) 102 | (at start (road_connect ?r1 ?xy_final ?xy_initial)) 103 | (at start (in_place ?r1)) 104 | ) 105 | :effect (and 106 | (at end (not (in_place ?r1))) 107 | (at end (available ?r1)) 108 | (at start (not (road_connect ?r1 ?xy_initial ?xy_final))) 109 | (at start (not (road_connect ?r1 ?xy_final ?xy_initial))) 110 | ) 111 | ) 112 | 113 | 114 | 115 | 116 | ) 117 | -------------------------------------------------------------------------------- /parser/Filereader.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #include "TokenStruct.h" 8 | #include "Type.h" 9 | 10 | namespace parser { namespace pddl { 11 | 12 | class Domain; 13 | 14 | class ExpectedToken : public std::runtime_error { 15 | public: 16 | ExpectedToken(const std::string& token) : std::runtime_error(token + " expected") {} 17 | }; 18 | 19 | class UnknownToken : public std::runtime_error { 20 | public: 21 | UnknownToken(const std::string& token) : std::runtime_error(token + " does not name a known token") {} 22 | }; 23 | 24 | class UnexpectedEOF : public std::runtime_error { 25 | public: 26 | UnexpectedEOF() : std::runtime_error("Unexpected EOF found") {} 27 | }; 28 | 29 | class Filereader { 30 | 31 | public: 32 | 33 | std::string s; // current line of file 34 | std::ifstream f; // file input stream 35 | unsigned r, c; // current row and column of file 36 | 37 | Filereader( const std::string & file ) : f( file.c_str() ), r( 1 ), c( 0 ) { 38 | if (!f) throw std::runtime_error(std::string("Failed to open file '") + file + "'"); 39 | std::getline( f, s ); 40 | next(); 41 | } 42 | 43 | ~Filereader() { 44 | f.close(); 45 | } 46 | 47 | // characters to be ignored 48 | bool ignore( char c ) { 49 | return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f'; 50 | } 51 | 52 | // parenthesis 53 | bool paren( char c ) { 54 | return c == '(' || c == ')' || c == '{' || c == '}'; 55 | } 56 | 57 | // current character 58 | char getChar() { 59 | return s[c]; 60 | } 61 | 62 | // print line and column 63 | void printLine() { 64 | std::cout << "Line " << r << ", column " << c+1 << ": "; 65 | } 66 | 67 | void tokenExit( const std::string & t ) { 68 | c -= t.size(); 69 | printLine(); 70 | throw UnknownToken(t); 71 | } 72 | 73 | // get next non-ignored character 74 | void next() { 75 | for ( ; c < s.size() && ignore( s[c] ); ++c ); 76 | while ( c == s.size() || s[c] == ';' ) { 77 | ++r; 78 | c = 0; 79 | if ( f.eof() ) { 80 | printLine(); 81 | throw UnexpectedEOF(); 82 | } 83 | std::getline( f, s ); 84 | for ( ; c < s.size() && ignore( s[c] ); ++c ); 85 | } 86 | } 87 | 88 | // get token converted to uppercase 89 | std::string getToken() { 90 | std::ostringstream os; 91 | while ( c < s.size() && !ignore( s[c] ) && !paren( s[c] ) && s[c] != ',' ) 92 | os << ( 97 <= s[c] && s[c] <= 122 ? (char)( s[c++] - 32 ) : s[c++] ); 93 | return os.str(); 94 | } 95 | 96 | // get token converted to uppercase 97 | // check that the token exists 98 | template < typename T > 99 | std::string getToken( const TokenStruct< T > & ts ) { 100 | std::string t = getToken(); 101 | if ( ts.index( t ) < 0 ) 102 | tokenExit( t ); 103 | return t; 104 | } 105 | 106 | // assert syntax 107 | void assert_token( const std::string & t ) { 108 | unsigned b = 0; 109 | for ( unsigned k = 0; c + k < s.size() && k < t.size(); ++k ) 110 | b += s[c + k] == t[k] || 111 | ( 97 <= s[c + k] && s[c + k] <= 122 && s[c + k] == t[k] + 32 ); 112 | if ( b < t.size() ) { 113 | printLine(); 114 | throw ExpectedToken(t); 115 | } 116 | c += t.size(); 117 | next(); 118 | } 119 | 120 | // parse the name of a domain or instance 121 | std::string parseName( const std::string & u ) { 122 | std::string out; 123 | std::string t[5] = { "(", "DEFINE", "(", u, ")" }; 124 | for ( unsigned i = 0; i < 5; ++i ) { 125 | assert_token( t[i] ); 126 | if ( i == 3 ) { 127 | out = getToken(); 128 | next(); 129 | } 130 | } 131 | return out; 132 | } 133 | 134 | 135 | // parse a typed list 136 | // if check is true, checks that types exist 137 | TokenStruct< std::string > parseTypedList( bool check, const TokenStruct< Type * > & ts = TokenStruct< Type * >(), const std::string & lt = "" ) { 138 | unsigned k = 0; 139 | TokenStruct< std::string > out; 140 | for ( next(); getChar() != ')' && lt.find( getChar() ) == std::string::npos; next() ) { 141 | if ( getChar() == '-' ) { 142 | assert_token( "-" ); 143 | 144 | std::string t; 145 | // check if the type is "EITHER" 146 | if ( getChar() == '(' ) { 147 | assert_token( "(" ); 148 | assert_token( "EITHER" ); 149 | 150 | t = "( EITHER"; 151 | for ( ; getChar() != ')'; next() ) { 152 | if ( check ) t += " " + getToken( ts ); 153 | else t += " " + getToken(); 154 | } 155 | t += " )"; 156 | ++c; 157 | } 158 | else if ( check ) t = getToken( ts ); 159 | else t = getToken(); 160 | 161 | out.types.insert( out.types.end(), out.size() - k, t ); 162 | k = out.size(); 163 | } 164 | else if ( getChar() == '(' ) { 165 | assert_token( "(" ); 166 | assert_token( ":PRIVATE" ); 167 | getToken(); 168 | out.append( parseTypedList( check, ts ) ); 169 | } 170 | else out.insert( getToken() ); 171 | } 172 | if ( k < out.size() ) out.types.insert( out.types.end(), out.size() - k, check ? "OBJECT" : "" ); 173 | ++c; 174 | 175 | return out; 176 | } 177 | 178 | }; 179 | 180 | } } // namespaces 181 | 182 | -------------------------------------------------------------------------------- /parser/Expression.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Condition.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Instance; 9 | 10 | class Expression : public Condition { 11 | 12 | public: 13 | 14 | virtual ~Expression() {} 15 | virtual std::string info() const = 0; 16 | virtual double evaluate() = 0; 17 | virtual double evaluate( Instance & ins, const StringVec & par ) = 0; 18 | virtual IntSet params() = 0; 19 | 20 | // inherit 21 | virtual void print( std::ostream & stream ) const { 22 | stream << info(); 23 | } 24 | 25 | virtual void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) {} 26 | virtual void addParams( int m, unsigned n ) {} 27 | }; 28 | 29 | Expression * createExpression( Filereader & f, TokenStruct< std::string > & ts, Domain & d ); 30 | 31 | class CompositeExpression : public Expression { 32 | 33 | public: 34 | 35 | std::string op; 36 | Expression * left; 37 | Expression * right; 38 | 39 | CompositeExpression( const std::string& c ) : op( c ) {} 40 | 41 | CompositeExpression( const std::string& c, Expression * l, Expression * r ) : op( c ), left( l ), right( r ) {} 42 | 43 | ~CompositeExpression() { 44 | delete left; 45 | delete right; 46 | } 47 | 48 | void parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 49 | f.next(); 50 | left = createExpression( f, ts, d ); 51 | right = createExpression( f, ts, d ); 52 | f.next(); 53 | f.assert_token( ")" ); 54 | } 55 | 56 | std::string info() const { 57 | std::ostringstream os; 58 | os << "(" << op << " " << left->info() << " " << right->info() << ")"; 59 | return os.str(); 60 | } 61 | 62 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override { 63 | s << "( " << op << " "; 64 | left->PDDLPrint( s, indent, ts, d ); 65 | s << " "; 66 | right->PDDLPrint( s, indent, ts, d ); 67 | s << " )"; 68 | } 69 | 70 | double compute( double x, double y ) { 71 | double res = 0; 72 | 73 | if ( op == "+" ) res = x + y; 74 | else if ( op == "-" ) res = x - y; 75 | else if ( op == "*" ) res = x * y; 76 | else if ( op == "/" ) res = ( y == 0 ? 0 : x / y ); 77 | 78 | return res; 79 | } 80 | 81 | double evaluate() { 82 | return compute( left->evaluate(), right->evaluate() ); 83 | } 84 | 85 | double evaluate( Instance & ins, const StringVec & par ) { 86 | return compute( left->evaluate( ins, par ), right->evaluate( ins, par ) ); 87 | } 88 | 89 | IntSet params() { 90 | IntSet lpars = left->params(); 91 | IntSet rpars = right->params(); 92 | lpars.insert( rpars.begin(), rpars.end() ); 93 | return lpars; 94 | } 95 | 96 | Condition * copy( Domain & d ) { 97 | Expression * cleft = dynamic_cast< Expression * >( left->copy( d ) ); 98 | Expression * cright = dynamic_cast< Expression * >( right->copy( d ) ); 99 | return new CompositeExpression( op, cleft, cright ); 100 | } 101 | }; 102 | 103 | class FunctionExpression : public Expression { 104 | 105 | public: 106 | 107 | ParamCond * fun; 108 | 109 | FunctionExpression( ParamCond * c ) : fun( c ) {} 110 | 111 | ~FunctionExpression() { 112 | delete fun; 113 | } 114 | 115 | std::string info() const { 116 | std::ostringstream os; 117 | os << "(" << fun->name << fun->params << ")"; 118 | return os.str(); 119 | } 120 | 121 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override; 122 | 123 | double evaluate() { return 1; } 124 | 125 | double evaluate( Instance & ins, const StringVec & par ); 126 | 127 | IntSet params() { 128 | return IntSet( fun->params.begin(), fun->params.end() ); 129 | } 130 | 131 | Condition * copy( Domain & d ) { 132 | return new FunctionExpression( dynamic_cast< ParamCond * >( fun->copy( d ) ) ); 133 | } 134 | }; 135 | 136 | class ValueExpression : public Expression { 137 | 138 | public: 139 | 140 | double value; 141 | 142 | ValueExpression( double v ) : value( v ) {} 143 | 144 | std::string info() const { 145 | std::ostringstream os; 146 | os << value; 147 | return os.str(); 148 | } 149 | 150 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override { 151 | s << std::fixed << value; 152 | } 153 | 154 | double evaluate() { return value; } 155 | 156 | double evaluate( Instance & ins, const StringVec & par ) { 157 | return value; 158 | } 159 | 160 | IntSet params() { 161 | return IntSet(); 162 | } 163 | 164 | Condition * copy( Domain & d ) { 165 | return new ValueExpression( value ); 166 | } 167 | }; 168 | 169 | class DurationExpression : public Expression { 170 | 171 | void PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const override { 172 | s << "?DURATION"; 173 | } 174 | 175 | std::string info() const { 176 | return "?DURATION"; 177 | } 178 | 179 | double evaluate() { 180 | return -1; 181 | } 182 | 183 | double evaluate( Instance & ins, const StringVec & par ) { 184 | return evaluate(); 185 | } 186 | 187 | IntSet params() { 188 | return IntSet(); 189 | } 190 | 191 | Condition * copy( Domain & d ) { 192 | return new DurationExpression(); 193 | } 194 | }; 195 | 196 | } } // namespaces 197 | -------------------------------------------------------------------------------- /parser/TemporalAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Instance.h" 3 | 4 | namespace parser { namespace pddl { 5 | 6 | Expression * TemporalAction::parseDuration( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 7 | return createExpression( f, ts, d ); 8 | } 9 | 10 | void TemporalAction::printCondition( std::ostream & s, const TokenStruct< std::string > & ts, const Domain & d, 11 | const std::string & t, And * a ) const { 12 | for ( unsigned i = 0; a && i < a->conds.size(); ++i ) { 13 | s << "\t\t( " << t << " "; 14 | a->conds[i]->PDDLPrint( s, 0, ts, d ); 15 | s << " )\n"; 16 | } 17 | } 18 | 19 | void TemporalAction::PDDLPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, const Domain & d ) const { 20 | s << "( :DURATIVE-ACTION " << name << "\n"; 21 | 22 | s << " :PARAMETERS "; 23 | 24 | TokenStruct< std::string > astruct; 25 | 26 | printParams( 0, s, astruct, d ); 27 | 28 | s << " :DURATION ( = ?DURATION "; 29 | if ( durationExpr ) durationExpr->PDDLPrint( s, 0, astruct, d ); 30 | else s << "1"; 31 | s << " )\n"; 32 | 33 | s << " :CONDITION\n"; 34 | s << "\t( AND\n"; 35 | printCondition( s, astruct, d, "AT START", (And *)pre ); 36 | printCondition( s, astruct, d, "OVER ALL", pre_o ); 37 | printCondition( s, astruct, d, "AT END", pre_e ); 38 | s << "\t)\n"; 39 | 40 | s << " :EFFECT\n"; 41 | s << "\t( AND\n"; 42 | printCondition( s, astruct, d, "AT START", (And *)eff ); 43 | printCondition( s, astruct, d, "AT END", eff_e ); 44 | s << "\t)\n"; 45 | 46 | s << ")\n"; 47 | } 48 | 49 | void TemporalAction::parseCondition( Filereader & f, TokenStruct< std::string > & ts, Domain & d, And * a ) { 50 | f.next(); 51 | f.assert_token( "(" ); 52 | Condition * c = d.createCondition( f ); 53 | c->parse( f, ts, d ); 54 | a->conds.push_back( c ); 55 | } 56 | 57 | void TemporalAction::parse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) { 58 | f.next(); 59 | f.assert_token( ":PARAMETERS" ); 60 | f.assert_token( "(" ); 61 | 62 | TokenStruct< std::string > astruct = f.parseTypedList( true, d.types ); 63 | params = d.convertTypes( astruct.types ); 64 | 65 | f.next(); 66 | f.assert_token( ":DURATION" ); 67 | f.assert_token( "(" ); 68 | f.assert_token( "=" ); 69 | f.assert_token( "?DURATION" ); 70 | durationExpr = parseDuration( f, astruct, d ); 71 | f.next(); 72 | f.assert_token( ")" ); 73 | 74 | f.next(); 75 | f.assert_token( ":" ); 76 | std::string s = f.getToken(); 77 | if ( s == "CONDITION" ) { 78 | pre = new And; 79 | pre_o = new And; 80 | pre_e = new And; 81 | f.next(); 82 | f.assert_token( "(" ); 83 | if ( f.getChar() != ')' ) { 84 | s = f.getToken(); 85 | if ( s == "AND" ) { 86 | for ( f.next(); f.getChar() != ')'; f.next() ) { 87 | f.assert_token( "(" ); 88 | s = f.getToken(); 89 | f.next(); 90 | std::string t = f.getToken(); 91 | 92 | if ( s == "AT" && t == "START" ) 93 | parseCondition( f, astruct, d, (And *)pre ); 94 | else if ( s == "OVER" && t == "ALL" ) 95 | parseCondition( f, astruct, d, pre_o ); 96 | else if ( s == "AT" && t == "END" ) 97 | parseCondition( f, astruct, d, pre_e ); 98 | else f.tokenExit( s + " " + t ); 99 | 100 | f.next(); 101 | f.assert_token( ")" ); 102 | } 103 | ++f.c; 104 | } 105 | else { 106 | f.next(); 107 | std::string t = f.getToken(); 108 | 109 | if ( s == "AT" && t == "START" ) 110 | parseCondition( f, astruct, d, (And *)pre ); 111 | else if ( s == "OVER" && t == "ALL" ) 112 | parseCondition( f, astruct, d, pre_o ); 113 | else if ( s == "AT" && t == "END" ) 114 | parseCondition( f, astruct, d, pre_e ); 115 | else f.tokenExit( s + " " + t ); 116 | 117 | f.next(); 118 | f.assert_token( ")" ); 119 | } 120 | } 121 | else ++f.c; 122 | 123 | f.next(); 124 | f.assert_token( ":" ); 125 | s = f.getToken(); 126 | } 127 | if ( s != "EFFECT" ) f.tokenExit( s ); 128 | 129 | f.next(); 130 | f.assert_token( "(" ); 131 | if ( f.getChar() != ')' ) { 132 | eff = new And; 133 | eff_e = new And; 134 | 135 | s = f.getToken(); 136 | if ( s == "AND" ) { 137 | for ( f.next(); f.getChar() != ')'; f.next() ) { 138 | f.assert_token( "(" ); 139 | s = f.getToken(); 140 | f.next(); 141 | std::string t = f.getToken(); 142 | 143 | if ( s == "AT" && t == "START" ) 144 | parseCondition( f, astruct, d, (And *)eff ); 145 | else if ( s == "AT" && t == "END" ) 146 | parseCondition( f, astruct, d, eff_e ); 147 | else f.tokenExit( s + " " + t ); 148 | 149 | f.next(); 150 | f.assert_token( ")" ); 151 | } 152 | ++f.c; 153 | } 154 | else { 155 | f.next(); 156 | std::string t = f.getToken(); 157 | 158 | if ( s == "AT" && t == "START" ) 159 | parseCondition( f, astruct, d, (And *)eff ); 160 | else if ( s == "AT" && t == "END" ) 161 | parseCondition( f, astruct, d, eff_e ); 162 | else f.tokenExit( s + " " + t ); 163 | 164 | f.next(); 165 | f.assert_token( ")" ); 166 | } 167 | } 168 | else ++f.c; 169 | 170 | f.next(); 171 | f.assert_token( ")" ); 172 | } 173 | 174 | GroundVec TemporalAction::preconsStart() { 175 | return getGroundsFromCondition( pre, false ); 176 | } 177 | 178 | GroundVec TemporalAction::preconsOverall() { 179 | return getGroundsFromCondition( pre_o, false ); 180 | } 181 | 182 | GroundVec TemporalAction::preconsEnd() { 183 | return getGroundsFromCondition( pre_e, false ); 184 | } 185 | 186 | CondVec TemporalAction::endEffects() { 187 | return getSubconditionsFromCondition( eff_e ); 188 | } 189 | 190 | GroundVec TemporalAction::addEndEffects() { 191 | return getGroundsFromCondition( eff_e, false ); 192 | } 193 | 194 | GroundVec TemporalAction::deleteEndEffects() { 195 | return getGroundsFromCondition( eff_e, true ); 196 | } 197 | 198 | } } // namespaces 199 | -------------------------------------------------------------------------------- /domains/Sched_dom.pddl: -------------------------------------------------------------------------------- 1 | (define (domain schedule) 2 | (:requirements :strips) 3 | 4 | (:constants cold hot cylindrical polisher roller lathe grinder punch drill-press 5 | spray-painter immersion-painter polished rough smooth 6 | nowidth noorient undefined nopaint unwantedargs) 7 | 8 | (:predicates (part ?obj) 9 | (temperature ?obj ?temp) 10 | (busy ?machine) (idle ?machine) 11 | (scheduled ?obj ?task) (unscheduled ?obj) 12 | (surface-condition ?obj ?surface-cond) 13 | (shape ?obj ?shape) 14 | (painted ?obj ?colour) 15 | (has-hole ?obj ?width ?orientation) 16 | (has-bit ?machine ?width) 17 | (can-orient ?machine ?orientation) 18 | (has-paint ?machine ?colour) 19 | (lasthole ?x ?y ?z) (linked ?x ?y ?z ?a ?b) (ru ?r)) 20 | 21 | (:action do-polish 22 | :parameters (?x ?r ?oldsurface) 23 | :precondition (and (ru ?r) (part ?x) 24 | (idle polisher) 25 | (unscheduled ?x) 26 | (temperature ?x cold) 27 | (surface-condition ?x ?oldsurface)) 28 | :effect (and (busy polisher) (not (idle polisher)) 29 | (scheduled ?x polisher) (not (unscheduled ?x)) 30 | (surface-condition ?x polished) 31 | (not (surface-condition ?x ?oldsurface)))) 32 | 33 | 34 | (:action do-roll 35 | :parameters (?x ?r ?oldsurface ?oldtemp ?oldshape ?oldpaint) 36 | :precondition (and (ru ?r) (part ?x) 37 | (idle roller) 38 | (unscheduled ?x) 39 | (surface-condition ?x ?oldsurface) 40 | (temperature ?x ?oldtemp) 41 | (shape ?x ?oldshape) 42 | (painted ?x ?oldpaint) 43 | (lasthole ?x nowidth noorient)) 44 | :effect (and 45 | (busy roller) (not (idle roller)) 46 | (scheduled ?x roller) (not (unscheduled ?x)) 47 | (temperature ?x hot) (not (temperature ?x ?oldtemp)) 48 | (shape ?x cylindrical) (not (shape ?x ?oldshape)) 49 | (not (painted ?x ?oldpaint)) (painted ?x nopaint) 50 | (surface-condition ?x rough) (not (surface-condition ?x ?oldsurface)) 51 | )) 52 | 53 | (:action do-lathe 54 | :parameters (?x ?r ?oldshape ?oldpaint ?oldsurface) 55 | :precondition (and (ru ?r) (part ?x) 56 | (idle lathe) 57 | (unscheduled ?x) 58 | (painted ?x ?oldpaint) 59 | (shape ?x ?oldshape) 60 | (surface-condition ?x ?oldsurface)) 61 | :effect (and 62 | (busy lathe) (not (idle lathe)) 63 | (scheduled ?x lathe) (not (unscheduled ?x)) 64 | (surface-condition ?x rough) 65 | (shape ?x cylindrical) (not (shape ?x ?oldshape)) 66 | (not (surface-condition ?x ?oldsurface)) 67 | (painted ?x nopaint) (not (painted ?x ?oldpaint)) 68 | )) 69 | 70 | (:action do-grind 71 | :parameters (?x ?r ?oldpaint ?oldsurface) 72 | :precondition (and (ru ?r) (part ?x) 73 | (idle grinder) 74 | (unscheduled ?x) 75 | (surface-condition ?x ?oldsurface) 76 | (painted ?x ?oldpaint)) 77 | :effect (and 78 | (busy GRINDER) (not (idle grinder)) 79 | (scheduled ?x grinder) (not (unscheduled ?x)) 80 | (surface-condition ?x smooth) (not (surface-condition ?x ?oldsurface)) 81 | (painted ?x nopaint) (not (painted ?x ?oldpaint)))) 82 | 83 | (:action do-punch 84 | :parameters (?x ?width ?orient ?r ?oldsurface ?oldwidth ?oldorient) 85 | :precondition (and (ru ?r) 86 | (part ?x) 87 | (has-bit punch ?width) 88 | (can-orient punch ?orient) 89 | (temperature ?x cold) 90 | (idle punch) 91 | (unscheduled ?x) 92 | (surface-condition ?x ?oldsurface) 93 | ; DON'T REALLY NEED THIS (not (has-hole ?x ?width ?orient)) 94 | (lasthole ?x ?oldwidth ?oldorient)) 95 | :effect (and 96 | (busy punch) (not (idle punch)) 97 | (scheduled ?x punch) (not (unscheduled ?x)) 98 | (has-hole ?x ?width ?orient) 99 | (lasthole ?x ?width ?orient) 100 | (linked ?x ?oldwidth ?oldorient ?width ?orient) (not (lasthole ?x ?oldwidth ?oldorient)) 101 | (surface-condition ?x rough) (not (surface-condition ?x ?oldsurface)))) 102 | 103 | (:action do-drill-press 104 | :parameters (?x ?width ?orient ?r ?oldwidth ?oldorient) 105 | :precondition (and (ru ?r) 106 | (part ?x) 107 | (has-bit drill-press ?width) 108 | (can-orient drill-press ?orient) 109 | (temperature ?x cold) 110 | (idle drill-press) 111 | (unscheduled ?x) 112 | ; DON'T REALLY NEED THIS (not (has-hole ?x ?width ?orient)) 113 | (lasthole ?x ?oldwidth ?oldorient) 114 | ) 115 | :effect (and 116 | (busy drill-press) (not (idle drill-press)) 117 | (scheduled ?x drill-press) (not (unscheduled ?x)) 118 | (lasthole ?x ?width ?orient) 119 | (linked ?x ?oldwidth ?oldorient ?width ?orient) (not (lasthole ?x ?oldwidth ?oldorient)) 120 | (has-hole ?x ?width ?orient))) 121 | 122 | (:action do-spray-paint 123 | :parameters (?x ?newpaint ?r ?oldpaint ?oldsurface) 124 | :precondition (and 125 | (part ?x) (ru ?r) 126 | (has-paint spray-painter ?newpaint) 127 | (idle spray-painter) 128 | (unscheduled ?x) 129 | (temperature ?x cold) 130 | (painted ?x ?oldpaint) 131 | (surface-condition ?x ?oldsurface)) 132 | :effect (and 133 | (busy spray-painter) (not (idle spray-painter)) 134 | (scheduled ?x spray-painter) (not (unscheduled ?x)) 135 | (painted ?x ?newpaint) (not (painted ?x ?oldpaint)) 136 | (surface-condition ?x undefined) (not (surface-condition ?x ?oldsurface)) 137 | )) 138 | 139 | (:action do-immersion-paint 140 | :parameters (?x ?newpaint ?r ?oldpaint) 141 | :precondition (and 142 | (part ?x) (ru ?r) 143 | (has-paint immersion-painter ?newpaint) 144 | (idle immersion-painter) 145 | (unscheduled ?x) 146 | (painted ?x ?oldpaint)) 147 | :effect (and 148 | (busy immersion-painter) (not (idle immersion-painter)) 149 | (scheduled ?x immersion-painter) (not (unscheduled ?x)) 150 | (painted ?x ?newpaint) (not (painted ?x ?oldpaint)) 151 | )) 152 | 153 | (:action do-time-step 154 | :parameters (?r ?x ?t) 155 | :precondition (and (ru ?r) (busy ?t) (scheduled ?x ?t)) 156 | :effect (and 157 | (not (busy ?t)) (idle ?t) (not (scheduled ?x ?t)) 158 | (unscheduled ?x))) 159 | (:action delete-strip-holes 160 | :parameters (?x ?width ?orient ?oldwidth ?oldorient) 161 | :precondition (and (linked ?x ?oldwidth ?oldorient ?width ?orient) 162 | (lasthole ?x ?width ?orient) (has-hole ?x ?width ?orient)) 163 | :effect (and (not (linked ?x ?oldwidth ?oldorient ?width ?orient)) 164 | (not (lasthole ?x ?width ?orient)) (not (has-hole ?x ?width ?orient)) 165 | (lasthole ?x ?oldwidth ?oldorient)))) 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /domains/Elev_ins.pddl: -------------------------------------------------------------------------------- 1 | (define (problem elevators-sequencedstrips-p16_14_1) 2 | (:domain elevators-sequencedstrips) 3 | 4 | (:objects 5 | n0 n1 n2 n3 n4 n5 n6 n7 n8 n9 n10 n11 n12 n13 n14 n15 n16 - count 6 | p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 - passenger 7 | fast0 fast1 - fast-elevator 8 | slow0-0 slow1-0 - slow-elevator 9 | ) 10 | 11 | (:init 12 | (next n0 n1) (next n1 n2) (next n2 n3) (next n3 n4) (next n4 n5) (next n5 n6) (next n6 n7) (next n7 n8) (next n8 n9) (next n9 n10) (next n10 n11) (next n11 n12) (next n12 n13) (next n13 n14) (next n14 n15) (next n15 n16) 13 | 14 | (above n0 n1) (above n0 n2) (above n0 n3) (above n0 n4) (above n0 n5) (above n0 n6) (above n0 n7) (above n0 n8) (above n0 n9) (above n0 n10) (above n0 n11) (above n0 n12) (above n0 n13) (above n0 n14) (above n0 n15) (above n0 n16) 15 | (above n1 n2) (above n1 n3) (above n1 n4) (above n1 n5) (above n1 n6) (above n1 n7) (above n1 n8) (above n1 n9) (above n1 n10) (above n1 n11) (above n1 n12) (above n1 n13) (above n1 n14) (above n1 n15) (above n1 n16) 16 | (above n2 n3) (above n2 n4) (above n2 n5) (above n2 n6) (above n2 n7) (above n2 n8) (above n2 n9) (above n2 n10) (above n2 n11) (above n2 n12) (above n2 n13) (above n2 n14) (above n2 n15) (above n2 n16) 17 | (above n3 n4) (above n3 n5) (above n3 n6) (above n3 n7) (above n3 n8) (above n3 n9) (above n3 n10) (above n3 n11) (above n3 n12) (above n3 n13) (above n3 n14) (above n3 n15) (above n3 n16) 18 | (above n4 n5) (above n4 n6) (above n4 n7) (above n4 n8) (above n4 n9) (above n4 n10) (above n4 n11) (above n4 n12) (above n4 n13) (above n4 n14) (above n4 n15) (above n4 n16) 19 | (above n5 n6) (above n5 n7) (above n5 n8) (above n5 n9) (above n5 n10) (above n5 n11) (above n5 n12) (above n5 n13) (above n5 n14) (above n5 n15) (above n5 n16) 20 | (above n6 n7) (above n6 n8) (above n6 n9) (above n6 n10) (above n6 n11) (above n6 n12) (above n6 n13) (above n6 n14) (above n6 n15) (above n6 n16) 21 | (above n7 n8) (above n7 n9) (above n7 n10) (above n7 n11) (above n7 n12) (above n7 n13) (above n7 n14) (above n7 n15) (above n7 n16) 22 | (above n8 n9) (above n8 n10) (above n8 n11) (above n8 n12) (above n8 n13) (above n8 n14) (above n8 n15) (above n8 n16) 23 | (above n9 n10) (above n9 n11) (above n9 n12) (above n9 n13) (above n9 n14) (above n9 n15) (above n9 n16) 24 | (above n10 n11) (above n10 n12) (above n10 n13) (above n10 n14) (above n10 n15) (above n10 n16) 25 | (above n11 n12) (above n11 n13) (above n11 n14) (above n11 n15) (above n11 n16) 26 | (above n12 n13) (above n12 n14) (above n12 n15) (above n12 n16) 27 | (above n13 n14) (above n13 n15) (above n13 n16) 28 | (above n14 n15) (above n14 n16) 29 | (above n15 n16) 30 | 31 | (lift-at fast0 n8) 32 | (passengers fast0 n0) 33 | (can-hold fast0 n1) (can-hold fast0 n2) (can-hold fast0 n3) (can-hold fast0 n4) 34 | (reachable-floor fast0 n0)(reachable-floor fast0 n4)(reachable-floor fast0 n8)(reachable-floor fast0 n12)(reachable-floor fast0 n16) 35 | 36 | (lift-at fast1 n12) 37 | (passengers fast1 n0) 38 | (can-hold fast1 n1) (can-hold fast1 n2) (can-hold fast1 n3) (can-hold fast1 n4) 39 | (reachable-floor fast1 n0)(reachable-floor fast1 n4)(reachable-floor fast1 n8)(reachable-floor fast1 n12)(reachable-floor fast1 n16) 40 | 41 | (lift-at slow0-0 n2) 42 | (passengers slow0-0 n0) 43 | (can-hold slow0-0 n1) (can-hold slow0-0 n2) (can-hold slow0-0 n3) 44 | (reachable-floor slow0-0 n0)(reachable-floor slow0-0 n1)(reachable-floor slow0-0 n2)(reachable-floor slow0-0 n3)(reachable-floor slow0-0 n4)(reachable-floor slow0-0 n5)(reachable-floor slow0-0 n6)(reachable-floor slow0-0 n7)(reachable-floor slow0-0 n8) 45 | 46 | (lift-at slow1-0 n12) 47 | (passengers slow1-0 n0) 48 | (can-hold slow1-0 n1) (can-hold slow1-0 n2) (can-hold slow1-0 n3) 49 | (reachable-floor slow1-0 n8)(reachable-floor slow1-0 n9)(reachable-floor slow1-0 n10)(reachable-floor slow1-0 n11)(reachable-floor slow1-0 n12)(reachable-floor slow1-0 n13)(reachable-floor slow1-0 n14)(reachable-floor slow1-0 n15)(reachable-floor slow1-0 n16) 50 | 51 | (passenger-at p0 n13) 52 | (passenger-at p1 n10) 53 | (passenger-at p2 n13) 54 | (passenger-at p3 n0) 55 | (passenger-at p4 n9) 56 | (passenger-at p5 n12) 57 | (passenger-at p6 n8) 58 | (passenger-at p7 n3) 59 | (passenger-at p8 n5) 60 | (passenger-at p9 n2) 61 | (passenger-at p10 n4) 62 | (passenger-at p11 n11) 63 | (passenger-at p12 n13) 64 | (passenger-at p13 n7) 65 | 66 | (= (travel-slow n0 n1) 6) (= (travel-slow n0 n2) 7) (= (travel-slow n0 n3) 8) (= (travel-slow n0 n4) 9) (= (travel-slow n0 n5) 10) (= (travel-slow n0 n6) 11) (= (travel-slow n0 n7) 12) (= (travel-slow n0 n8) 13) (= (travel-slow n1 n2) 6) (= (travel-slow n1 n3) 7) (= (travel-slow n1 n4) 8) (= (travel-slow n1 n5) 9) (= (travel-slow n1 n6) 10) (= (travel-slow n1 n7) 11) (= (travel-slow n1 n8) 12) (= (travel-slow n2 n3) 6) (= (travel-slow n2 n4) 7) (= (travel-slow n2 n5) 8) (= (travel-slow n2 n6) 9) (= (travel-slow n2 n7) 10) (= (travel-slow n2 n8) 11) (= (travel-slow n3 n4) 6) (= (travel-slow n3 n5) 7) (= (travel-slow n3 n6) 8) (= (travel-slow n3 n7) 9) (= (travel-slow n3 n8) 10) (= (travel-slow n4 n5) 6) (= (travel-slow n4 n6) 7) (= (travel-slow n4 n7) 8) (= (travel-slow n4 n8) 9) (= (travel-slow n5 n6) 6) (= (travel-slow n5 n7) 7) (= (travel-slow n5 n8) 8) (= (travel-slow n6 n7) 6) (= (travel-slow n6 n8) 7) (= (travel-slow n7 n8) 6) 67 | 68 | (= (travel-slow n8 n9) 6) (= (travel-slow n8 n10) 7) (= (travel-slow n8 n11) 8) (= (travel-slow n8 n12) 9) (= (travel-slow n8 n13) 10) (= (travel-slow n8 n14) 11) (= (travel-slow n8 n15) 12) (= (travel-slow n8 n16) 13) (= (travel-slow n9 n10) 6) (= (travel-slow n9 n11) 7) (= (travel-slow n9 n12) 8) (= (travel-slow n9 n13) 9) (= (travel-slow n9 n14) 10) (= (travel-slow n9 n15) 11) (= (travel-slow n9 n16) 12) (= (travel-slow n10 n11) 6) (= (travel-slow n10 n12) 7) (= (travel-slow n10 n13) 8) (= (travel-slow n10 n14) 9) (= (travel-slow n10 n15) 10) (= (travel-slow n10 n16) 11) (= (travel-slow n11 n12) 6) (= (travel-slow n11 n13) 7) (= (travel-slow n11 n14) 8) (= (travel-slow n11 n15) 9) (= (travel-slow n11 n16) 10) (= (travel-slow n12 n13) 6) (= (travel-slow n12 n14) 7) (= (travel-slow n12 n15) 8) (= (travel-slow n12 n16) 9) (= (travel-slow n13 n14) 6) (= (travel-slow n13 n15) 7) (= (travel-slow n13 n16) 8) (= (travel-slow n14 n15) 6) (= (travel-slow n14 n16) 7) (= (travel-slow n15 n16) 6) 69 | 70 | 71 | (= (travel-fast n0 n4) 13) (= (travel-fast n0 n8) 25) (= (travel-fast n0 n12) 37) (= (travel-fast n0 n16) 49) 72 | 73 | (= (travel-fast n4 n8) 13) (= (travel-fast n4 n12) 25) (= (travel-fast n4 n16) 37) 74 | 75 | (= (travel-fast n8 n12) 13) (= (travel-fast n8 n16) 25) 76 | 77 | (= (travel-fast n12 n16) 13) 78 | 79 | (= (total-cost) 0) 80 | 81 | ) 82 | 83 | (:goal 84 | (and 85 | (passenger-at p0 n8) 86 | (passenger-at p1 n15) 87 | (passenger-at p2 n6) 88 | (passenger-at p3 n14) 89 | (passenger-at p4 n5) 90 | (passenger-at p5 n2) 91 | (passenger-at p6 n14) 92 | (passenger-at p7 n4) 93 | (passenger-at p8 n10) 94 | (passenger-at p9 n9) 95 | (passenger-at p10 n12) 96 | (passenger-at p11 n13) 97 | (passenger-at p12 n5) 98 | (passenger-at p13 n6) 99 | )) 100 | 101 | (:metric minimize (total-cost)) 102 | 103 | ) 104 | -------------------------------------------------------------------------------- /parser/Instance.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Domain.h" 5 | 6 | namespace parser { namespace pddl { 7 | 8 | class Instance { 9 | public: 10 | Domain &d; 11 | std::string name; 12 | GroundVec init, goal; // initial and goal states 13 | 14 | bool metric; 15 | 16 | Instance( Domain & dom ) : d( dom ), metric( false ) {} 17 | 18 | Instance( Domain & dom, const std::string & s ) : Instance(dom) 19 | { 20 | parse(s); 21 | } 22 | 23 | virtual ~Instance() { 24 | for ( unsigned i = 0; i < init.size(); ++i ) 25 | delete init[i]; 26 | for ( unsigned i = 0; i < goal.size(); ++i ) 27 | delete goal[i]; 28 | } 29 | 30 | void parse( const std::string &s) { 31 | Filereader f( s ); 32 | name = f.parseName( "PROBLEM" ); 33 | 34 | if ( DOMAIN_DEBUG ) std::cout << name << "\n"; 35 | 36 | for ( ; f.getChar() != ')'; f.next() ) { 37 | f.assert_token( "(" ); 38 | f.assert_token( ":" ); 39 | std::string t = f.getToken(); 40 | 41 | if ( DOMAIN_DEBUG ) std::cout << t << "\n"; 42 | 43 | if ( t == "DOMAIN" ) parseDomain( f ); 44 | else if ( t == "OBJECTS" ) parseObjects( f ); 45 | else if ( t == "INIT" ) parseInit( f ); 46 | else if ( t == "GOAL" ) parseGoal( f ); 47 | else if ( t == "METRIC" ) parseMetric( f ); 48 | else f.tokenExit( t ); 49 | } 50 | } 51 | 52 | 53 | 54 | void parseDomain( Filereader & f ) { 55 | f.next(); 56 | f.assert_token( d.name ); 57 | f.assert_token( ")" ); 58 | } 59 | 60 | void parseObjects( Filereader & f ) { 61 | TokenStruct< std::string > ts = f.parseTypedList( true, d.types ); 62 | 63 | for ( unsigned i = 0; i < ts.size(); ++i ) { 64 | Type * type = d.getType( ts.types[i] ); 65 | std::pair< bool, unsigned > pair = type->parseObject( ts[i] ); 66 | if ( pair.first == false ) 67 | type->objects.insert( ts[i] ); 68 | } 69 | 70 | for ( unsigned i = 0; DOMAIN_DEBUG && i < d.types.size(); ++i ) { 71 | std::cout << " "; 72 | if ( d.typed ) std::cout << " " << d.types[i] << ":"; 73 | for ( unsigned j = 0; j < d.types[i]->objects.size(); ++j ) 74 | std::cout << " " << d.types[i]->objects[j]; 75 | std::cout << "\n"; 76 | } 77 | } 78 | 79 | 80 | virtual void parseGround( Filereader & f, GroundVec & v ) { 81 | TypeGround * c = 0; 82 | if ( f.getChar() == '=') { 83 | f.assert_token( "=" ); 84 | f.assert_token( "(" ); 85 | 86 | std::string s = f.getToken(); 87 | int i = d.funcs.index( s ); 88 | if ( i < 0 ) f.tokenExit( s ); 89 | 90 | if ( d.funcs[i]->returnType < 0 ) c = new GroundFunc< double >( d.funcs[i] ); 91 | else c = new GroundFunc< int >( d.funcs[i] ); 92 | } 93 | else c = new TypeGround( d.preds.get( f.getToken( d.preds ) ) ); 94 | c->parse( f, d.types[0]->constants, d ); 95 | v.push_back( c ); 96 | } 97 | 98 | void parseInit( Filereader & f ) { 99 | for ( f.next(); f.getChar() != ')'; f.next() ) { 100 | f.assert_token( "(" ); 101 | parseGround( f, init ); 102 | } 103 | ++f.c; 104 | 105 | for ( unsigned i = 0; DOMAIN_DEBUG && i < init.size(); ++i ) 106 | std::cout << " " << init[i]; 107 | } 108 | 109 | virtual void parseGoal( Filereader & f ) { 110 | f.next(); 111 | f.assert_token( "(" ); 112 | 113 | std::string s = f.getToken(); 114 | if ( s == "AND" ) { 115 | for ( f.next(); f.getChar() != ')'; f.next() ) { 116 | f.assert_token( "(" ); 117 | parseGround( f, goal ); 118 | } 119 | ++f.c; 120 | f.next(); 121 | } 122 | else { 123 | f.c -= s.size(); 124 | parseGround( f, goal ); 125 | } 126 | f.assert_token( ")" ); 127 | 128 | for ( unsigned i = 0; DOMAIN_DEBUG && i < goal.size(); ++i ) std::cout << " " << goal[i]; 129 | } 130 | 131 | // for the moment only parse total-cost/total-time 132 | void parseMetric( Filereader & f ) { 133 | if ( !d.temp && !d.costs ) { 134 | std::cerr << "METRIC only defined for temporal actions or actions with costs!\n"; 135 | std::exit( 1 ); 136 | } 137 | 138 | metric = true; 139 | 140 | f.next(); 141 | f.assert_token( "MINIMIZE" ); 142 | f.assert_token( "(" ); 143 | if ( d.temp ) f.assert_token( "TOTAL-TIME" ); 144 | else f.assert_token( "TOTAL-COST" ); 145 | f.assert_token( ")" ); 146 | f.assert_token( ")" ); 147 | } 148 | 149 | // add an object of a certain type 150 | void addObject( const std::string & name, const std::string & type ) { 151 | d.getType( type )->objects.insert( name ); 152 | } 153 | 154 | // add a predicate fluent to the initial state 155 | void addInit( const std::string & name, const StringVec & v = StringVec() ) { 156 | TypeGround * tg = new TypeGround( d.preds.get( name ) ); 157 | tg->insert( d, v ); 158 | init.push_back( tg ); 159 | } 160 | 161 | // add a function value to the initial state 162 | void addInit( const std::string & name, int value, const StringVec & v = StringVec() ) { 163 | GroundFunc< int > * gf = new GroundFunc< int >( d.funcs.get( name ), value ); 164 | gf->insert( d, v ); 165 | init.push_back( gf ); 166 | } 167 | 168 | // add a function value to the initial state 169 | void addInit( const std::string & name, double value, const StringVec & v = StringVec() ) { 170 | GroundFunc< double > * gf = new GroundFunc< double >( d.funcs.get( name ), value ); 171 | gf->insert( d, v ); 172 | init.push_back( gf ); 173 | } 174 | 175 | // add a fluent (predicate or function) to the initial state 176 | void addInit( TypeGround * g, const StringVec & v = StringVec() ) { 177 | TypeGround * tg = 0; 178 | GroundFunc< int > * f1 = dynamic_cast< GroundFunc< int > * >( g ); 179 | GroundFunc< double > * f2 = dynamic_cast< GroundFunc< double > * >( g ); 180 | if ( f1 ) tg = new GroundFunc< int >( d.funcs.get( g->name ), f1->value ); 181 | else if ( f2 ) tg = new GroundFunc< double >( d.funcs.get( g->name ), f2->value ); 182 | else tg = new TypeGround( d.preds.get( g->name ) ); 183 | tg->insert( d, v ); 184 | init.push_back( tg ); 185 | } 186 | 187 | // add a fluent to the goal state 188 | void addGoal( const std::string & name, const StringVec & v = StringVec() ) { 189 | TypeGround * tg = new TypeGround( d.preds.get( name ) ); 190 | tg->insert( d, v ); 191 | goal.push_back( tg ); 192 | } 193 | 194 | friend std::ostream& operator<<(std::ostream &os, const Instance& o) { return o.print(os); } 195 | virtual std::ostream& print(std::ostream& stream) const { 196 | stream << "( DEFINE ( PROBLEM " << name << " )\n"; 197 | stream << "( :DOMAIN " << d.name << " )\n"; 198 | 199 | stream << "( :OBJECTS\n"; 200 | for ( unsigned i = 0; i < d.types.size(); ++i ) 201 | if ( d.types[i]->objects.size() ) { 202 | stream << "\t"; 203 | for ( unsigned j = 0; j < d.types[i]->objects.size(); ++j ) 204 | stream << d.types[i]->objects[j] << " "; 205 | if ( d.typed ) stream << "- " << d.types[i]->name; 206 | stream << "\n"; 207 | } 208 | stream << ")\n"; 209 | 210 | stream << "( :INIT\n"; 211 | for ( unsigned i = 0; i < init.size(); ++i ) { 212 | ( (TypeGround*)init[i])->PDDLPrint( stream, 1, TokenStruct< std::string >(), d ); 213 | stream << "\n"; 214 | } 215 | stream << ")\n"; 216 | 217 | stream << "( :GOAL\n"; 218 | stream << "\t( AND\n"; 219 | for ( unsigned i = 0; i < goal.size(); ++i ) { 220 | ( (TypeGround*)goal[i])->PDDLPrint( stream, 2, TokenStruct< std::string >(), d ); 221 | stream << "\n"; 222 | } 223 | stream << "\t)\n"; 224 | stream << ")\n"; 225 | 226 | if ( metric ) { 227 | stream << "( :METRIC MINIMIZE ( TOTAL-"; 228 | if ( d.temp ) stream << "TIME"; 229 | else stream << "COST"; 230 | stream << " ) )\n"; 231 | } 232 | 233 | stream << ")\n"; 234 | return stream; 235 | } 236 | 237 | }; 238 | 239 | } } // namespaces 240 | -------------------------------------------------------------------------------- /tests/expected/Sched_dom.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( DOMAIN SCHEDULE ) 2 | ( :REQUIREMENTS :STRIPS ) 3 | ( :CONSTANTS 4 | COLD HOT CYLINDRICAL POLISHER ROLLER LATHE GRINDER PUNCH DRILL-PRESS SPRAY-PAINTER IMMERSION-PAINTER POLISHED ROUGH SMOOTH NOWIDTH NOORIENT UNDEFINED NOPAINT UNWANTEDARGS 5 | ) 6 | ( :PREDICATES 7 | ( PART ?OBJECT0 ) 8 | ( TEMPERATURE ?OBJECT0 ?OBJECT1 ) 9 | ( BUSY ?OBJECT0 ) 10 | ( IDLE ?OBJECT0 ) 11 | ( SCHEDULED ?OBJECT0 ?OBJECT1 ) 12 | ( UNSCHEDULED ?OBJECT0 ) 13 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT1 ) 14 | ( SHAPE ?OBJECT0 ?OBJECT1 ) 15 | ( PAINTED ?OBJECT0 ?OBJECT1 ) 16 | ( HAS-HOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 17 | ( HAS-BIT ?OBJECT0 ?OBJECT1 ) 18 | ( CAN-ORIENT ?OBJECT0 ?OBJECT1 ) 19 | ( HAS-PAINT ?OBJECT0 ?OBJECT1 ) 20 | ( LASTHOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 21 | ( LINKED ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ) 22 | ( RU ?OBJECT0 ) 23 | ) 24 | ( :ACTION DO-POLISH 25 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 26 | :PRECONDITION 27 | ( AND 28 | ( RU ?OBJECT1 ) 29 | ( PART ?OBJECT0 ) 30 | ( IDLE POLISHER ) 31 | ( UNSCHEDULED ?OBJECT0 ) 32 | ( TEMPERATURE ?OBJECT0 COLD ) 33 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT2 ) 34 | ) 35 | :EFFECT 36 | ( AND 37 | ( BUSY POLISHER ) 38 | ( NOT ( IDLE POLISHER ) ) 39 | ( SCHEDULED ?OBJECT0 POLISHER ) 40 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 41 | ( SURFACE-CONDITION ?OBJECT0 POLISHED ) 42 | ( NOT ( SURFACE-CONDITION ?OBJECT0 ?OBJECT2 ) ) 43 | ) 44 | ) 45 | ( :ACTION DO-ROLL 46 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ?OBJECT5 ) 47 | :PRECONDITION 48 | ( AND 49 | ( RU ?OBJECT1 ) 50 | ( PART ?OBJECT0 ) 51 | ( IDLE ROLLER ) 52 | ( UNSCHEDULED ?OBJECT0 ) 53 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT2 ) 54 | ( TEMPERATURE ?OBJECT0 ?OBJECT3 ) 55 | ( SHAPE ?OBJECT0 ?OBJECT4 ) 56 | ( PAINTED ?OBJECT0 ?OBJECT5 ) 57 | ( LASTHOLE ?OBJECT0 NOWIDTH NOORIENT ) 58 | ) 59 | :EFFECT 60 | ( AND 61 | ( BUSY ROLLER ) 62 | ( NOT ( IDLE ROLLER ) ) 63 | ( SCHEDULED ?OBJECT0 ROLLER ) 64 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 65 | ( TEMPERATURE ?OBJECT0 HOT ) 66 | ( NOT ( TEMPERATURE ?OBJECT0 ?OBJECT3 ) ) 67 | ( SHAPE ?OBJECT0 CYLINDRICAL ) 68 | ( NOT ( SHAPE ?OBJECT0 ?OBJECT4 ) ) 69 | ( NOT ( PAINTED ?OBJECT0 ?OBJECT5 ) ) 70 | ( PAINTED ?OBJECT0 NOPAINT ) 71 | ( SURFACE-CONDITION ?OBJECT0 ROUGH ) 72 | ( NOT ( SURFACE-CONDITION ?OBJECT0 ?OBJECT2 ) ) 73 | ) 74 | ) 75 | ( :ACTION DO-LATHE 76 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ) 77 | :PRECONDITION 78 | ( AND 79 | ( RU ?OBJECT1 ) 80 | ( PART ?OBJECT0 ) 81 | ( IDLE LATHE ) 82 | ( UNSCHEDULED ?OBJECT0 ) 83 | ( PAINTED ?OBJECT0 ?OBJECT3 ) 84 | ( SHAPE ?OBJECT0 ?OBJECT2 ) 85 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT4 ) 86 | ) 87 | :EFFECT 88 | ( AND 89 | ( BUSY LATHE ) 90 | ( NOT ( IDLE LATHE ) ) 91 | ( SCHEDULED ?OBJECT0 LATHE ) 92 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 93 | ( SURFACE-CONDITION ?OBJECT0 ROUGH ) 94 | ( SHAPE ?OBJECT0 CYLINDRICAL ) 95 | ( NOT ( SHAPE ?OBJECT0 ?OBJECT2 ) ) 96 | ( NOT ( SURFACE-CONDITION ?OBJECT0 ?OBJECT4 ) ) 97 | ( PAINTED ?OBJECT0 NOPAINT ) 98 | ( NOT ( PAINTED ?OBJECT0 ?OBJECT3 ) ) 99 | ) 100 | ) 101 | ( :ACTION DO-GRIND 102 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ) 103 | :PRECONDITION 104 | ( AND 105 | ( RU ?OBJECT1 ) 106 | ( PART ?OBJECT0 ) 107 | ( IDLE GRINDER ) 108 | ( UNSCHEDULED ?OBJECT0 ) 109 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT3 ) 110 | ( PAINTED ?OBJECT0 ?OBJECT2 ) 111 | ) 112 | :EFFECT 113 | ( AND 114 | ( BUSY GRINDER ) 115 | ( NOT ( IDLE GRINDER ) ) 116 | ( SCHEDULED ?OBJECT0 GRINDER ) 117 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 118 | ( SURFACE-CONDITION ?OBJECT0 SMOOTH ) 119 | ( NOT ( SURFACE-CONDITION ?OBJECT0 ?OBJECT3 ) ) 120 | ( PAINTED ?OBJECT0 NOPAINT ) 121 | ( NOT ( PAINTED ?OBJECT0 ?OBJECT2 ) ) 122 | ) 123 | ) 124 | ( :ACTION DO-PUNCH 125 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ?OBJECT5 ?OBJECT6 ) 126 | :PRECONDITION 127 | ( AND 128 | ( RU ?OBJECT3 ) 129 | ( PART ?OBJECT0 ) 130 | ( HAS-BIT PUNCH ?OBJECT1 ) 131 | ( CAN-ORIENT PUNCH ?OBJECT2 ) 132 | ( TEMPERATURE ?OBJECT0 COLD ) 133 | ( IDLE PUNCH ) 134 | ( UNSCHEDULED ?OBJECT0 ) 135 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT4 ) 136 | ( LASTHOLE ?OBJECT0 ?OBJECT5 ?OBJECT6 ) 137 | ) 138 | :EFFECT 139 | ( AND 140 | ( BUSY PUNCH ) 141 | ( NOT ( IDLE PUNCH ) ) 142 | ( SCHEDULED ?OBJECT0 PUNCH ) 143 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 144 | ( HAS-HOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 145 | ( LASTHOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 146 | ( LINKED ?OBJECT0 ?OBJECT5 ?OBJECT6 ?OBJECT1 ?OBJECT2 ) 147 | ( NOT ( LASTHOLE ?OBJECT0 ?OBJECT5 ?OBJECT6 ) ) 148 | ( SURFACE-CONDITION ?OBJECT0 ROUGH ) 149 | ( NOT ( SURFACE-CONDITION ?OBJECT0 ?OBJECT4 ) ) 150 | ) 151 | ) 152 | ( :ACTION DO-DRILL-PRESS 153 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ?OBJECT5 ) 154 | :PRECONDITION 155 | ( AND 156 | ( RU ?OBJECT3 ) 157 | ( PART ?OBJECT0 ) 158 | ( HAS-BIT DRILL-PRESS ?OBJECT1 ) 159 | ( CAN-ORIENT DRILL-PRESS ?OBJECT2 ) 160 | ( TEMPERATURE ?OBJECT0 COLD ) 161 | ( IDLE DRILL-PRESS ) 162 | ( UNSCHEDULED ?OBJECT0 ) 163 | ( LASTHOLE ?OBJECT0 ?OBJECT4 ?OBJECT5 ) 164 | ) 165 | :EFFECT 166 | ( AND 167 | ( BUSY DRILL-PRESS ) 168 | ( NOT ( IDLE DRILL-PRESS ) ) 169 | ( SCHEDULED ?OBJECT0 DRILL-PRESS ) 170 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 171 | ( LASTHOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 172 | ( LINKED ?OBJECT0 ?OBJECT4 ?OBJECT5 ?OBJECT1 ?OBJECT2 ) 173 | ( NOT ( LASTHOLE ?OBJECT0 ?OBJECT4 ?OBJECT5 ) ) 174 | ( HAS-HOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 175 | ) 176 | ) 177 | ( :ACTION DO-SPRAY-PAINT 178 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ) 179 | :PRECONDITION 180 | ( AND 181 | ( PART ?OBJECT0 ) 182 | ( RU ?OBJECT2 ) 183 | ( HAS-PAINT SPRAY-PAINTER ?OBJECT1 ) 184 | ( IDLE SPRAY-PAINTER ) 185 | ( UNSCHEDULED ?OBJECT0 ) 186 | ( TEMPERATURE ?OBJECT0 COLD ) 187 | ( PAINTED ?OBJECT0 ?OBJECT3 ) 188 | ( SURFACE-CONDITION ?OBJECT0 ?OBJECT4 ) 189 | ) 190 | :EFFECT 191 | ( AND 192 | ( BUSY SPRAY-PAINTER ) 193 | ( NOT ( IDLE SPRAY-PAINTER ) ) 194 | ( SCHEDULED ?OBJECT0 SPRAY-PAINTER ) 195 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 196 | ( PAINTED ?OBJECT0 ?OBJECT1 ) 197 | ( NOT ( PAINTED ?OBJECT0 ?OBJECT3 ) ) 198 | ( SURFACE-CONDITION ?OBJECT0 UNDEFINED ) 199 | ( NOT ( SURFACE-CONDITION ?OBJECT0 ?OBJECT4 ) ) 200 | ) 201 | ) 202 | ( :ACTION DO-IMMERSION-PAINT 203 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ) 204 | :PRECONDITION 205 | ( AND 206 | ( PART ?OBJECT0 ) 207 | ( RU ?OBJECT2 ) 208 | ( HAS-PAINT IMMERSION-PAINTER ?OBJECT1 ) 209 | ( IDLE IMMERSION-PAINTER ) 210 | ( UNSCHEDULED ?OBJECT0 ) 211 | ( PAINTED ?OBJECT0 ?OBJECT3 ) 212 | ) 213 | :EFFECT 214 | ( AND 215 | ( BUSY IMMERSION-PAINTER ) 216 | ( NOT ( IDLE IMMERSION-PAINTER ) ) 217 | ( SCHEDULED ?OBJECT0 IMMERSION-PAINTER ) 218 | ( NOT ( UNSCHEDULED ?OBJECT0 ) ) 219 | ( PAINTED ?OBJECT0 ?OBJECT1 ) 220 | ( NOT ( PAINTED ?OBJECT0 ?OBJECT3 ) ) 221 | ) 222 | ) 223 | ( :ACTION DO-TIME-STEP 224 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 225 | :PRECONDITION 226 | ( AND 227 | ( RU ?OBJECT0 ) 228 | ( BUSY ?OBJECT2 ) 229 | ( SCHEDULED ?OBJECT1 ?OBJECT2 ) 230 | ) 231 | :EFFECT 232 | ( AND 233 | ( NOT ( BUSY ?OBJECT2 ) ) 234 | ( IDLE ?OBJECT2 ) 235 | ( NOT ( SCHEDULED ?OBJECT1 ?OBJECT2 ) ) 236 | ( UNSCHEDULED ?OBJECT1 ) 237 | ) 238 | ) 239 | ( :ACTION DELETE-STRIP-HOLES 240 | :PARAMETERS ( ?OBJECT0 ?OBJECT1 ?OBJECT2 ?OBJECT3 ?OBJECT4 ) 241 | :PRECONDITION 242 | ( AND 243 | ( LINKED ?OBJECT0 ?OBJECT3 ?OBJECT4 ?OBJECT1 ?OBJECT2 ) 244 | ( LASTHOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 245 | ( HAS-HOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) 246 | ) 247 | :EFFECT 248 | ( AND 249 | ( NOT ( LINKED ?OBJECT0 ?OBJECT3 ?OBJECT4 ?OBJECT1 ?OBJECT2 ) ) 250 | ( NOT ( LASTHOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) ) 251 | ( NOT ( HAS-HOLE ?OBJECT0 ?OBJECT1 ?OBJECT2 ) ) 252 | ( LASTHOLE ?OBJECT0 ?OBJECT3 ?OBJECT4 ) 253 | ) 254 | ) 255 | ) 256 | -------------------------------------------------------------------------------- /tests/expected/Elev_ins.pddl: -------------------------------------------------------------------------------- 1 | ( DEFINE ( PROBLEM ELEVATORS-SEQUENCEDSTRIPS-P16_14_1 ) 2 | ( :DOMAIN ELEVATORS-SEQUENCEDSTRIPS ) 3 | ( :OBJECTS 4 | SLOW0-0 SLOW1-0 - SLOW-ELEVATOR 5 | FAST0 FAST1 - FAST-ELEVATOR 6 | P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 - PASSENGER 7 | N0 N1 N2 N3 N4 N5 N6 N7 N8 N9 N10 N11 N12 N13 N14 N15 N16 - COUNT 8 | ) 9 | ( :INIT 10 | ( NEXT N0 N1 ) 11 | ( NEXT N1 N2 ) 12 | ( NEXT N2 N3 ) 13 | ( NEXT N3 N4 ) 14 | ( NEXT N4 N5 ) 15 | ( NEXT N5 N6 ) 16 | ( NEXT N6 N7 ) 17 | ( NEXT N7 N8 ) 18 | ( NEXT N8 N9 ) 19 | ( NEXT N9 N10 ) 20 | ( NEXT N10 N11 ) 21 | ( NEXT N11 N12 ) 22 | ( NEXT N12 N13 ) 23 | ( NEXT N13 N14 ) 24 | ( NEXT N14 N15 ) 25 | ( NEXT N15 N16 ) 26 | ( ABOVE N0 N1 ) 27 | ( ABOVE N0 N2 ) 28 | ( ABOVE N0 N3 ) 29 | ( ABOVE N0 N4 ) 30 | ( ABOVE N0 N5 ) 31 | ( ABOVE N0 N6 ) 32 | ( ABOVE N0 N7 ) 33 | ( ABOVE N0 N8 ) 34 | ( ABOVE N0 N9 ) 35 | ( ABOVE N0 N10 ) 36 | ( ABOVE N0 N11 ) 37 | ( ABOVE N0 N12 ) 38 | ( ABOVE N0 N13 ) 39 | ( ABOVE N0 N14 ) 40 | ( ABOVE N0 N15 ) 41 | ( ABOVE N0 N16 ) 42 | ( ABOVE N1 N2 ) 43 | ( ABOVE N1 N3 ) 44 | ( ABOVE N1 N4 ) 45 | ( ABOVE N1 N5 ) 46 | ( ABOVE N1 N6 ) 47 | ( ABOVE N1 N7 ) 48 | ( ABOVE N1 N8 ) 49 | ( ABOVE N1 N9 ) 50 | ( ABOVE N1 N10 ) 51 | ( ABOVE N1 N11 ) 52 | ( ABOVE N1 N12 ) 53 | ( ABOVE N1 N13 ) 54 | ( ABOVE N1 N14 ) 55 | ( ABOVE N1 N15 ) 56 | ( ABOVE N1 N16 ) 57 | ( ABOVE N2 N3 ) 58 | ( ABOVE N2 N4 ) 59 | ( ABOVE N2 N5 ) 60 | ( ABOVE N2 N6 ) 61 | ( ABOVE N2 N7 ) 62 | ( ABOVE N2 N8 ) 63 | ( ABOVE N2 N9 ) 64 | ( ABOVE N2 N10 ) 65 | ( ABOVE N2 N11 ) 66 | ( ABOVE N2 N12 ) 67 | ( ABOVE N2 N13 ) 68 | ( ABOVE N2 N14 ) 69 | ( ABOVE N2 N15 ) 70 | ( ABOVE N2 N16 ) 71 | ( ABOVE N3 N4 ) 72 | ( ABOVE N3 N5 ) 73 | ( ABOVE N3 N6 ) 74 | ( ABOVE N3 N7 ) 75 | ( ABOVE N3 N8 ) 76 | ( ABOVE N3 N9 ) 77 | ( ABOVE N3 N10 ) 78 | ( ABOVE N3 N11 ) 79 | ( ABOVE N3 N12 ) 80 | ( ABOVE N3 N13 ) 81 | ( ABOVE N3 N14 ) 82 | ( ABOVE N3 N15 ) 83 | ( ABOVE N3 N16 ) 84 | ( ABOVE N4 N5 ) 85 | ( ABOVE N4 N6 ) 86 | ( ABOVE N4 N7 ) 87 | ( ABOVE N4 N8 ) 88 | ( ABOVE N4 N9 ) 89 | ( ABOVE N4 N10 ) 90 | ( ABOVE N4 N11 ) 91 | ( ABOVE N4 N12 ) 92 | ( ABOVE N4 N13 ) 93 | ( ABOVE N4 N14 ) 94 | ( ABOVE N4 N15 ) 95 | ( ABOVE N4 N16 ) 96 | ( ABOVE N5 N6 ) 97 | ( ABOVE N5 N7 ) 98 | ( ABOVE N5 N8 ) 99 | ( ABOVE N5 N9 ) 100 | ( ABOVE N5 N10 ) 101 | ( ABOVE N5 N11 ) 102 | ( ABOVE N5 N12 ) 103 | ( ABOVE N5 N13 ) 104 | ( ABOVE N5 N14 ) 105 | ( ABOVE N5 N15 ) 106 | ( ABOVE N5 N16 ) 107 | ( ABOVE N6 N7 ) 108 | ( ABOVE N6 N8 ) 109 | ( ABOVE N6 N9 ) 110 | ( ABOVE N6 N10 ) 111 | ( ABOVE N6 N11 ) 112 | ( ABOVE N6 N12 ) 113 | ( ABOVE N6 N13 ) 114 | ( ABOVE N6 N14 ) 115 | ( ABOVE N6 N15 ) 116 | ( ABOVE N6 N16 ) 117 | ( ABOVE N7 N8 ) 118 | ( ABOVE N7 N9 ) 119 | ( ABOVE N7 N10 ) 120 | ( ABOVE N7 N11 ) 121 | ( ABOVE N7 N12 ) 122 | ( ABOVE N7 N13 ) 123 | ( ABOVE N7 N14 ) 124 | ( ABOVE N7 N15 ) 125 | ( ABOVE N7 N16 ) 126 | ( ABOVE N8 N9 ) 127 | ( ABOVE N8 N10 ) 128 | ( ABOVE N8 N11 ) 129 | ( ABOVE N8 N12 ) 130 | ( ABOVE N8 N13 ) 131 | ( ABOVE N8 N14 ) 132 | ( ABOVE N8 N15 ) 133 | ( ABOVE N8 N16 ) 134 | ( ABOVE N9 N10 ) 135 | ( ABOVE N9 N11 ) 136 | ( ABOVE N9 N12 ) 137 | ( ABOVE N9 N13 ) 138 | ( ABOVE N9 N14 ) 139 | ( ABOVE N9 N15 ) 140 | ( ABOVE N9 N16 ) 141 | ( ABOVE N10 N11 ) 142 | ( ABOVE N10 N12 ) 143 | ( ABOVE N10 N13 ) 144 | ( ABOVE N10 N14 ) 145 | ( ABOVE N10 N15 ) 146 | ( ABOVE N10 N16 ) 147 | ( ABOVE N11 N12 ) 148 | ( ABOVE N11 N13 ) 149 | ( ABOVE N11 N14 ) 150 | ( ABOVE N11 N15 ) 151 | ( ABOVE N11 N16 ) 152 | ( ABOVE N12 N13 ) 153 | ( ABOVE N12 N14 ) 154 | ( ABOVE N12 N15 ) 155 | ( ABOVE N12 N16 ) 156 | ( ABOVE N13 N14 ) 157 | ( ABOVE N13 N15 ) 158 | ( ABOVE N13 N16 ) 159 | ( ABOVE N14 N15 ) 160 | ( ABOVE N14 N16 ) 161 | ( ABOVE N15 N16 ) 162 | ( LIFT-AT FAST0 N8 ) 163 | ( PASSENGERS FAST0 N0 ) 164 | ( CAN-HOLD FAST0 N1 ) 165 | ( CAN-HOLD FAST0 N2 ) 166 | ( CAN-HOLD FAST0 N3 ) 167 | ( CAN-HOLD FAST0 N4 ) 168 | ( REACHABLE-FLOOR FAST0 N0 ) 169 | ( REACHABLE-FLOOR FAST0 N4 ) 170 | ( REACHABLE-FLOOR FAST0 N8 ) 171 | ( REACHABLE-FLOOR FAST0 N12 ) 172 | ( REACHABLE-FLOOR FAST0 N16 ) 173 | ( LIFT-AT FAST1 N12 ) 174 | ( PASSENGERS FAST1 N0 ) 175 | ( CAN-HOLD FAST1 N1 ) 176 | ( CAN-HOLD FAST1 N2 ) 177 | ( CAN-HOLD FAST1 N3 ) 178 | ( CAN-HOLD FAST1 N4 ) 179 | ( REACHABLE-FLOOR FAST1 N0 ) 180 | ( REACHABLE-FLOOR FAST1 N4 ) 181 | ( REACHABLE-FLOOR FAST1 N8 ) 182 | ( REACHABLE-FLOOR FAST1 N12 ) 183 | ( REACHABLE-FLOOR FAST1 N16 ) 184 | ( LIFT-AT SLOW0-0 N2 ) 185 | ( PASSENGERS SLOW0-0 N0 ) 186 | ( CAN-HOLD SLOW0-0 N1 ) 187 | ( CAN-HOLD SLOW0-0 N2 ) 188 | ( CAN-HOLD SLOW0-0 N3 ) 189 | ( REACHABLE-FLOOR SLOW0-0 N0 ) 190 | ( REACHABLE-FLOOR SLOW0-0 N1 ) 191 | ( REACHABLE-FLOOR SLOW0-0 N2 ) 192 | ( REACHABLE-FLOOR SLOW0-0 N3 ) 193 | ( REACHABLE-FLOOR SLOW0-0 N4 ) 194 | ( REACHABLE-FLOOR SLOW0-0 N5 ) 195 | ( REACHABLE-FLOOR SLOW0-0 N6 ) 196 | ( REACHABLE-FLOOR SLOW0-0 N7 ) 197 | ( REACHABLE-FLOOR SLOW0-0 N8 ) 198 | ( LIFT-AT SLOW1-0 N12 ) 199 | ( PASSENGERS SLOW1-0 N0 ) 200 | ( CAN-HOLD SLOW1-0 N1 ) 201 | ( CAN-HOLD SLOW1-0 N2 ) 202 | ( CAN-HOLD SLOW1-0 N3 ) 203 | ( REACHABLE-FLOOR SLOW1-0 N8 ) 204 | ( REACHABLE-FLOOR SLOW1-0 N9 ) 205 | ( REACHABLE-FLOOR SLOW1-0 N10 ) 206 | ( REACHABLE-FLOOR SLOW1-0 N11 ) 207 | ( REACHABLE-FLOOR SLOW1-0 N12 ) 208 | ( REACHABLE-FLOOR SLOW1-0 N13 ) 209 | ( REACHABLE-FLOOR SLOW1-0 N14 ) 210 | ( REACHABLE-FLOOR SLOW1-0 N15 ) 211 | ( REACHABLE-FLOOR SLOW1-0 N16 ) 212 | ( PASSENGER-AT P0 N13 ) 213 | ( PASSENGER-AT P1 N10 ) 214 | ( PASSENGER-AT P2 N13 ) 215 | ( PASSENGER-AT P3 N0 ) 216 | ( PASSENGER-AT P4 N9 ) 217 | ( PASSENGER-AT P5 N12 ) 218 | ( PASSENGER-AT P6 N8 ) 219 | ( PASSENGER-AT P7 N3 ) 220 | ( PASSENGER-AT P8 N5 ) 221 | ( PASSENGER-AT P9 N2 ) 222 | ( PASSENGER-AT P10 N4 ) 223 | ( PASSENGER-AT P11 N11 ) 224 | ( PASSENGER-AT P12 N13 ) 225 | ( PASSENGER-AT P13 N7 ) 226 | ( = ( TRAVEL-SLOW N0 N1 ) 6 ) 227 | ( = ( TRAVEL-SLOW N0 N2 ) 7 ) 228 | ( = ( TRAVEL-SLOW N0 N3 ) 8 ) 229 | ( = ( TRAVEL-SLOW N0 N4 ) 9 ) 230 | ( = ( TRAVEL-SLOW N0 N5 ) 10 ) 231 | ( = ( TRAVEL-SLOW N0 N6 ) 11 ) 232 | ( = ( TRAVEL-SLOW N0 N7 ) 12 ) 233 | ( = ( TRAVEL-SLOW N0 N8 ) 13 ) 234 | ( = ( TRAVEL-SLOW N1 N2 ) 6 ) 235 | ( = ( TRAVEL-SLOW N1 N3 ) 7 ) 236 | ( = ( TRAVEL-SLOW N1 N4 ) 8 ) 237 | ( = ( TRAVEL-SLOW N1 N5 ) 9 ) 238 | ( = ( TRAVEL-SLOW N1 N6 ) 10 ) 239 | ( = ( TRAVEL-SLOW N1 N7 ) 11 ) 240 | ( = ( TRAVEL-SLOW N1 N8 ) 12 ) 241 | ( = ( TRAVEL-SLOW N2 N3 ) 6 ) 242 | ( = ( TRAVEL-SLOW N2 N4 ) 7 ) 243 | ( = ( TRAVEL-SLOW N2 N5 ) 8 ) 244 | ( = ( TRAVEL-SLOW N2 N6 ) 9 ) 245 | ( = ( TRAVEL-SLOW N2 N7 ) 10 ) 246 | ( = ( TRAVEL-SLOW N2 N8 ) 11 ) 247 | ( = ( TRAVEL-SLOW N3 N4 ) 6 ) 248 | ( = ( TRAVEL-SLOW N3 N5 ) 7 ) 249 | ( = ( TRAVEL-SLOW N3 N6 ) 8 ) 250 | ( = ( TRAVEL-SLOW N3 N7 ) 9 ) 251 | ( = ( TRAVEL-SLOW N3 N8 ) 10 ) 252 | ( = ( TRAVEL-SLOW N4 N5 ) 6 ) 253 | ( = ( TRAVEL-SLOW N4 N6 ) 7 ) 254 | ( = ( TRAVEL-SLOW N4 N7 ) 8 ) 255 | ( = ( TRAVEL-SLOW N4 N8 ) 9 ) 256 | ( = ( TRAVEL-SLOW N5 N6 ) 6 ) 257 | ( = ( TRAVEL-SLOW N5 N7 ) 7 ) 258 | ( = ( TRAVEL-SLOW N5 N8 ) 8 ) 259 | ( = ( TRAVEL-SLOW N6 N7 ) 6 ) 260 | ( = ( TRAVEL-SLOW N6 N8 ) 7 ) 261 | ( = ( TRAVEL-SLOW N7 N8 ) 6 ) 262 | ( = ( TRAVEL-SLOW N8 N9 ) 6 ) 263 | ( = ( TRAVEL-SLOW N8 N10 ) 7 ) 264 | ( = ( TRAVEL-SLOW N8 N11 ) 8 ) 265 | ( = ( TRAVEL-SLOW N8 N12 ) 9 ) 266 | ( = ( TRAVEL-SLOW N8 N13 ) 10 ) 267 | ( = ( TRAVEL-SLOW N8 N14 ) 11 ) 268 | ( = ( TRAVEL-SLOW N8 N15 ) 12 ) 269 | ( = ( TRAVEL-SLOW N8 N16 ) 13 ) 270 | ( = ( TRAVEL-SLOW N9 N10 ) 6 ) 271 | ( = ( TRAVEL-SLOW N9 N11 ) 7 ) 272 | ( = ( TRAVEL-SLOW N9 N12 ) 8 ) 273 | ( = ( TRAVEL-SLOW N9 N13 ) 9 ) 274 | ( = ( TRAVEL-SLOW N9 N14 ) 10 ) 275 | ( = ( TRAVEL-SLOW N9 N15 ) 11 ) 276 | ( = ( TRAVEL-SLOW N9 N16 ) 12 ) 277 | ( = ( TRAVEL-SLOW N10 N11 ) 6 ) 278 | ( = ( TRAVEL-SLOW N10 N12 ) 7 ) 279 | ( = ( TRAVEL-SLOW N10 N13 ) 8 ) 280 | ( = ( TRAVEL-SLOW N10 N14 ) 9 ) 281 | ( = ( TRAVEL-SLOW N10 N15 ) 10 ) 282 | ( = ( TRAVEL-SLOW N10 N16 ) 11 ) 283 | ( = ( TRAVEL-SLOW N11 N12 ) 6 ) 284 | ( = ( TRAVEL-SLOW N11 N13 ) 7 ) 285 | ( = ( TRAVEL-SLOW N11 N14 ) 8 ) 286 | ( = ( TRAVEL-SLOW N11 N15 ) 9 ) 287 | ( = ( TRAVEL-SLOW N11 N16 ) 10 ) 288 | ( = ( TRAVEL-SLOW N12 N13 ) 6 ) 289 | ( = ( TRAVEL-SLOW N12 N14 ) 7 ) 290 | ( = ( TRAVEL-SLOW N12 N15 ) 8 ) 291 | ( = ( TRAVEL-SLOW N12 N16 ) 9 ) 292 | ( = ( TRAVEL-SLOW N13 N14 ) 6 ) 293 | ( = ( TRAVEL-SLOW N13 N15 ) 7 ) 294 | ( = ( TRAVEL-SLOW N13 N16 ) 8 ) 295 | ( = ( TRAVEL-SLOW N14 N15 ) 6 ) 296 | ( = ( TRAVEL-SLOW N14 N16 ) 7 ) 297 | ( = ( TRAVEL-SLOW N15 N16 ) 6 ) 298 | ( = ( TRAVEL-FAST N0 N4 ) 13 ) 299 | ( = ( TRAVEL-FAST N0 N8 ) 25 ) 300 | ( = ( TRAVEL-FAST N0 N12 ) 37 ) 301 | ( = ( TRAVEL-FAST N0 N16 ) 49 ) 302 | ( = ( TRAVEL-FAST N4 N8 ) 13 ) 303 | ( = ( TRAVEL-FAST N4 N12 ) 25 ) 304 | ( = ( TRAVEL-FAST N4 N16 ) 37 ) 305 | ( = ( TRAVEL-FAST N8 N12 ) 13 ) 306 | ( = ( TRAVEL-FAST N8 N16 ) 25 ) 307 | ( = ( TRAVEL-FAST N12 N16 ) 13 ) 308 | ( = ( TOTAL-COST ) 0 ) 309 | ) 310 | ( :GOAL 311 | ( AND 312 | ( PASSENGER-AT P0 N8 ) 313 | ( PASSENGER-AT P1 N15 ) 314 | ( PASSENGER-AT P2 N6 ) 315 | ( PASSENGER-AT P3 N14 ) 316 | ( PASSENGER-AT P4 N5 ) 317 | ( PASSENGER-AT P5 N2 ) 318 | ( PASSENGER-AT P6 N14 ) 319 | ( PASSENGER-AT P7 N4 ) 320 | ( PASSENGER-AT P8 N10 ) 321 | ( PASSENGER-AT P9 N9 ) 322 | ( PASSENGER-AT P10 N12 ) 323 | ( PASSENGER-AT P11 N13 ) 324 | ( PASSENGER-AT P12 N5 ) 325 | ( PASSENGER-AT P13 N6 ) 326 | ) 327 | ) 328 | ( :METRIC MINIMIZE ( TOTAL-COST ) ) 329 | ) 330 | -------------------------------------------------------------------------------- /parser/Domain.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Task.h" 5 | #include "TemporalAction.h" 6 | #include "And.h" 7 | #include "Derived.h" 8 | #include "Equals.h" 9 | #include "Exists.h" 10 | #include "Forall.h" 11 | #include "Function.h" 12 | #include "GroundFunc.h" 13 | #include "FunctionModifier.h" 14 | 15 | #include "Not.h" 16 | #include "Oneof.h" 17 | #include "Or.h" 18 | #include "EitherType.h" 19 | #include "When.h" 20 | 21 | #define DOMAIN_DEBUG false 22 | 23 | namespace parser { namespace pddl { 24 | 25 | class Domain { 26 | public: 27 | 28 | std::string name; // name of domain 29 | 30 | bool equality; // whether domain supports equality 31 | bool strips, adl, condeffects; // whether domain is STRIPS, ADL and/or has conditional effects 32 | bool typed, cons, costs; // whether domain is typed, has constants, has costs 33 | bool temp, nondet, neg, disj; // whether domain is temporal, is non-deterministic, has negative precons, has disjunctive preconditions 34 | bool universal; // whether domain has universal precons 35 | bool fluents; // whether domains contains fluents 36 | bool derivedpred; // whether domain contains derived predicates 37 | 38 | TokenStruct< Type * > types; // types 39 | TokenStruct< Lifted * > preds; // predicates 40 | TokenStruct< Function * > funcs; // functions 41 | TokenStruct< Action * > actions; // actions 42 | TokenStruct< Derived * > derived; // derived predicates 43 | TokenStruct< Task * > tasks; // tasks 44 | 45 | Domain() 46 | : equality( false ), strips( false ), adl( false ), condeffects( false ) 47 | , typed( false ), cons( false ), costs( false ), temp( false ) 48 | , nondet( false ), neg( false ), disj( false ), universal( false ) 49 | , fluents( false ), derivedpred( false ) 50 | { 51 | types.insert( new Type( "OBJECT" ) ); // Type 0 is always "OBJECT", whether the domain is typed or not 52 | } 53 | 54 | Domain( const std::string & s ) : Domain() 55 | { 56 | parse( s ); 57 | } 58 | 59 | virtual ~Domain() { 60 | for ( unsigned i = 0; i < types.size(); ++i ) 61 | delete types[i]; 62 | for ( unsigned i = 0; i < preds.size(); ++i ) 63 | delete preds[i]; 64 | for ( unsigned i = 0; i < funcs.size(); ++i ) 65 | delete funcs[i]; 66 | for ( unsigned i = 0; i < actions.size(); ++i ) 67 | delete actions[i]; 68 | for ( unsigned i = 0; i < derived.size(); ++i ) 69 | delete derived[i]; 70 | for ( unsigned i = 0; i < tasks.size(); ++i ) 71 | delete tasks[i]; 72 | } 73 | 74 | virtual void parse( const std::string & s ) { 75 | Filereader f( s ); 76 | name = f.parseName( "DOMAIN" ); 77 | 78 | if ( DOMAIN_DEBUG ) std::cout << name << "\n"; 79 | 80 | for ( ; f.getChar() != ')'; f.next() ) { 81 | f.assert_token( "(" ); 82 | f.assert_token( ":" ); 83 | std::string t = f.getToken(); 84 | 85 | if ( DOMAIN_DEBUG ) std::cout << t << "\n"; 86 | 87 | if (!parseBlock(t, f)) { 88 | f.tokenExit( t ); 89 | } 90 | } 91 | } 92 | 93 | //! Returns a boolean indicating whether the block was correctly parsed 94 | virtual bool parseBlock(const std::string& t, Filereader& f) { 95 | if ( t == "REQUIREMENTS" ) parseRequirements( f ); 96 | else if ( t == "TYPES" ) parseTypes( f ); 97 | else if ( t == "CONSTANTS" ) parseConstants( f ); 98 | else if ( t == "PREDICATES" ) parsePredicates( f ); 99 | else if ( t == "FUNCTIONS" ) parseFunctions( f ); 100 | else if ( t == "ACTION" ) parseAction( f ); 101 | else if ( t == "DURATIVE-ACTION" ) parseDurativeAction( f ); 102 | else if ( t == "DERIVED" ) parseDerived( f ); 103 | // else if ( t == "AXIOM" ) parseAxiom( f ); 104 | else return false; // Unknown block type 105 | 106 | return true; 107 | } 108 | 109 | 110 | void parseRequirements( Filereader & f ) { 111 | for ( f.next(); f.getChar() != ')'; f.next() ) { 112 | f.assert_token( ":" ); 113 | std::string s = f.getToken(); 114 | 115 | if ( DOMAIN_DEBUG ) std::cout << " " << s << "\n"; 116 | 117 | if (!parseRequirement(s)) { 118 | f.tokenExit( s ); 119 | } 120 | } 121 | 122 | ++f.c; 123 | } 124 | 125 | //! Returns a boolean indicating whether the requirement was correctly parsed 126 | virtual bool parseRequirement( const std::string& s ) { 127 | if ( s == "STRIPS" ) strips = true; 128 | else if ( s == "ADL" ) adl = true; 129 | else if ( s == "NEGATIVE-PRECONDITIONS" ) neg = true; 130 | else if ( s == "CONDITIONAL-EFFECTS" ) condeffects = true; 131 | else if ( s == "TYPING" ) typed = true; 132 | else if ( s == "ACTION-COSTS" ) costs = true; 133 | else if ( s == "EQUALITY" ) equality = true; 134 | else if ( s == "DURATIVE-ACTIONS" ) temp = true; 135 | else if ( s == "NON-DETERMINISTIC" ) nondet = true; 136 | else if ( s == "UNIVERSAL-PRECONDITIONS" ) universal = true; 137 | else if ( s == "FLUENTS" ) fluents = true; 138 | else if ( s == "DISJUNCTIVE-PRECONDITIONS" ) disj = true; 139 | else if ( s == "DERIVED-PREDICATES" ) derivedpred = true; 140 | else return false; // Unknown requirement 141 | 142 | return true; 143 | } 144 | 145 | // get the type corresponding to a string 146 | Type * getType( std::string s ) { 147 | int i = types.index( s ); 148 | if ( i < 0 ) { 149 | if ( s[0] == '(' ) { 150 | i = types.insert( new EitherType( s ) ); 151 | for ( unsigned k = 9; s[k] != ')'; ) { 152 | unsigned e = s.find( ' ', k ); 153 | types[i]->subtypes.push_back( getType( s.substr( k, e - k ) ) ); 154 | k = e + 1; 155 | } 156 | } 157 | else i = types.insert( new Type( s ) ); 158 | } 159 | return types[i]; 160 | } 161 | 162 | // convert a vector of type names to integers 163 | IntVec convertTypes( const StringVec & v ) { 164 | IntVec out; 165 | for ( unsigned i = 0; i < v.size(); ++i ) 166 | out.push_back( types.index( getType( v[i] )->name ) ); 167 | return out; 168 | } 169 | 170 | void parseTypes( Filereader & f ) { 171 | if ( !typed ) { 172 | std::cout << "Requirement :TYPING needed to define types\n"; 173 | exit( 1 ); 174 | } 175 | 176 | // if this makes it in, probably need to define new subclass of Type 177 | // if ( costs ) insert( new Type( "NUMBER" ), tmap, types ); 178 | 179 | // Parse the typed list 180 | TokenStruct< std::string > ts = f.parseTypedList( false ); 181 | 182 | // bit of a hack to avoid OBJECT being the supertype 183 | if ( ts.index( "OBJECT" ) >= 0 ) { 184 | types[0]->name = "SUPERTYPE"; 185 | types.tokenMap.clear(); 186 | types.tokenMap["SUPERTYPE"] = 0; 187 | } 188 | 189 | // Relate subtypes and supertypes 190 | for ( unsigned i = 0; i < ts.size(); ++i ) { 191 | if ( ts.types[i].size() ) 192 | getType( ts.types[i] )->insertSubtype( getType( ts[i] ) ); 193 | else getType( ts[i] ); 194 | } 195 | 196 | // By default, the supertype of a type is "OBJECT" 197 | for ( unsigned i = 1; i < types.size(); ++i ) 198 | if ( types[i]->supertype == 0 ) 199 | types[0]->insertSubtype( types[i] ); 200 | 201 | for ( unsigned i = 0; DOMAIN_DEBUG && i < types.size(); ++i ) 202 | std::cout << " " << types[i]; 203 | } 204 | 205 | void parseConstants( Filereader & f ) { 206 | if ( typed && !types.size() ) { 207 | std::cout << "Types needed before defining constants\n"; 208 | exit( 1 ); 209 | } 210 | 211 | cons = true; 212 | 213 | TokenStruct< std::string > ts = f.parseTypedList( true, types ); 214 | 215 | for ( unsigned i = 0; i < ts.size(); ++i ) 216 | getType( ts.types[i] )->constants.insert( ts[i] ); 217 | 218 | for ( unsigned i = 0; DOMAIN_DEBUG && i < types.size(); ++i ) { 219 | std::cout << " "; 220 | if ( typed ) std::cout << " " << types[i] << ":"; 221 | for ( unsigned j = 0; j < types[i]->constants.size(); ++j ) 222 | std::cout << " " << types[i]->constants[j]; 223 | std::cout << "\n"; 224 | } 225 | } 226 | 227 | void parsePredicates( Filereader & f ) { 228 | if ( typed && !types.size() ) { 229 | std::cout << "Types needed before defining predicates\n"; 230 | exit(1); 231 | } 232 | 233 | for ( f.next(); f.getChar() != ')'; f.next() ) { 234 | f.assert_token( "(" ); 235 | if ( f.getChar() == ':' ) { 236 | // Needed to support MA-PDDL 237 | f.assert_token( ":PRIVATE" ); 238 | f.parseTypedList( true, types, "(" ); 239 | 240 | // CURRENT HACK: TOTALLY IGNORE PRIVATE !!! 241 | --f.c; 242 | parsePredicates( f ); 243 | } 244 | else { 245 | Lifted * c = new Lifted( f.getToken() ); 246 | c->parse( f, types[0]->constants, *this ); 247 | 248 | if ( DOMAIN_DEBUG ) std::cout << " " << c; 249 | preds.insert( c ); 250 | } 251 | } 252 | ++f.c; 253 | } 254 | 255 | void parseFunctions( Filereader & f ) { 256 | if ( typed && !types.size() ) { 257 | std::cout << "Types needed before defining functions\n"; 258 | exit(1); 259 | } 260 | 261 | for ( f.next(); f.getChar() != ')'; f.next() ) { 262 | f.assert_token( "(" ); 263 | Function * c = new Function( f.getToken() ); 264 | c->parse( f, types[0]->constants, *this ); 265 | 266 | if ( DOMAIN_DEBUG ) std::cout << " " << c; 267 | funcs.insert( c ); 268 | } 269 | ++f.c; 270 | } 271 | 272 | virtual void parseAction( Filereader & f ) { 273 | if ( !preds.size() ) { 274 | std::cout << "Predicates needed before defining actions\n"; 275 | exit(1); 276 | } 277 | 278 | f.next(); 279 | Action * a = new Action( f.getToken() ); 280 | a->parse( f, types[0]->constants, *this ); 281 | 282 | if ( DOMAIN_DEBUG ) std::cout << a << "\n"; 283 | actions.insert( a ); 284 | } 285 | 286 | void parseDerived( Filereader & f ) { 287 | if ( !preds.size() ) { 288 | std::cout << "Predicates needed before defining derived predicates\n"; 289 | exit(1); 290 | } 291 | 292 | f.next(); 293 | Derived * d = new Derived; 294 | d->parse( f, types[0]->constants, *this ); 295 | 296 | if ( DOMAIN_DEBUG ) std::cout << d << "\n"; 297 | derived.insert( d ); 298 | } 299 | 300 | void parseDurativeAction( Filereader & f ) { 301 | if ( !preds.size() ) { 302 | std::cout << "Predicates needed before defining actions\n"; 303 | exit(1); 304 | } 305 | 306 | f.next(); 307 | Action * a = new TemporalAction( f.getToken() ); 308 | a->parse( f, types[0]->constants, *this ); 309 | 310 | if ( DOMAIN_DEBUG ) std::cout << a << "\n"; 311 | actions.insert( a ); 312 | } 313 | 314 | 315 | // Return a copy of the type structure, with newly allocated types 316 | // This will also copy all constants and objects! 317 | TokenStruct< Type * > copyTypes() { 318 | TokenStruct< Type * > out; 319 | for ( unsigned i = 0; i < types.size(); ++i ) 320 | out.insert( types[i]->copy() ); 321 | 322 | for ( unsigned i = 1; i < types.size(); ++i ) { 323 | if ( types[i]->supertype ) 324 | out[out.index( types[i]->supertype->name )]->insertSubtype( out[i] ); 325 | else 326 | out[i]->copySubtypes( types[i], out ); 327 | } 328 | 329 | return out; 330 | } 331 | 332 | // Set the types to "otherTypes" 333 | void setTypes( const TokenStruct< Type * > & otherTypes ) { 334 | for ( unsigned i = 0; i < types.size(); ++i ) 335 | delete types[i]; 336 | types = otherTypes; 337 | } 338 | 339 | // Create a type with a given supertype (default is "OBJECT") 340 | void createType( const std::string & name, const std::string & parent = "OBJECT" ) { 341 | Type * type = new Type( name ); 342 | types.insert( type ); 343 | types.get( parent )->insertSubtype( type ); 344 | } 345 | 346 | // Create a constant of a given type 347 | void createConstant( const std::string & name, const std::string & type ) { 348 | types.get( type )->constants.insert( name ); 349 | } 350 | 351 | // Create a predicate with the given name and parameter types 352 | Lifted * createPredicate( const std::string & name, const StringVec & params = StringVec() ) { 353 | Lifted * pred = new Lifted( name ); 354 | for ( unsigned i = 0; i < params.size(); ++i ) 355 | pred->params.push_back( types.index( params[i] ) ); 356 | preds.insert( pred ); 357 | return pred; 358 | } 359 | 360 | // Create a function with the given name and parameter types 361 | Lifted * createFunction( const std::string & name, int type, const StringVec & params = StringVec() ) { 362 | Function * func = new Function( name, type ); 363 | for ( unsigned i = 0; i < params.size(); ++i ) 364 | func->params.push_back( types.index( params[i] ) ); 365 | funcs.insert( func ); 366 | return func; 367 | } 368 | 369 | // Create an action with the given name and parameter types 370 | Action * createAction( const std::string & name, const StringVec & params = StringVec() ) { 371 | Action * action = new Action( name ); 372 | for ( unsigned i = 0; i < params.size(); ++i ) 373 | action->params.push_back( types.index( params[i] ) ); 374 | action->pre = new And; 375 | action->eff = new And; 376 | actions.insert( action ); 377 | return action; 378 | } 379 | 380 | // Set the precondition of an action to "cond", converting to "And" 381 | void setPre( const std::string & act, Condition * cond ) { 382 | Action * action = actions.get( act ); 383 | 384 | And * old = dynamic_cast< And * >( cond ); 385 | if ( old == 0 ) { 386 | action->pre = new And; 387 | if ( cond ) dynamic_cast< And * >( action->pre )->add( cond->copy( *this ) ); 388 | } 389 | else action->pre = old->copy( *this ); 390 | } 391 | 392 | // Add a precondition to the action with name "act" 393 | void addPre( bool neg, const std::string & act, const std::string & pred, const IntVec & params = IntVec() ) { 394 | Action * action = actions.get( act ); 395 | if ( action->pre == 0 ) action->pre = new And; 396 | And * a = dynamic_cast< And * >( action->pre ); 397 | if ( neg ) a->add( new Not( ground( pred, params ) ) ); 398 | else a->add( ground( pred, params ) ); 399 | } 400 | 401 | // Add an "OR" precondition to the action with name "act" 402 | void addOrPre( const std::string & act, const std::string & pred1, const std::string & pred2, 403 | const IntVec & params1 = IntVec(), const IntVec & params2 = IntVec() ) { 404 | Or * o = new Or; 405 | o->first = ground( pred1, params1 ); 406 | o->second = ground( pred2, params2 ); 407 | Action * action = actions.get( act ); 408 | And * a = dynamic_cast< And * >( action->pre ); 409 | a->add( o ); 410 | } 411 | 412 | // Set the precondition of an action to "cond", converting to "And" 413 | void setEff( const std::string & act, Condition * cond ) { 414 | Action * action = actions.get( act ); 415 | 416 | And * old = dynamic_cast< And * >( cond ); 417 | if ( old == 0 ) { 418 | action->eff = new And; 419 | if ( cond ) dynamic_cast< And * >( action->eff )->add( cond->copy( *this ) ); 420 | } 421 | else action->eff = old->copy( *this ); 422 | } 423 | 424 | // Add an effect to the action with name "act" 425 | void addEff( bool neg, const std::string & act, const std::string & pred, const IntVec & params = IntVec() ) { 426 | Action * action = actions.get( act ); 427 | if ( action->eff == 0 ) action->eff = new And; 428 | And * a = dynamic_cast< And * >( action->eff ); 429 | if ( neg ) a->add( new Not( ground( pred, params ) ) ); 430 | else a->add( ground( pred, params ) ); 431 | } 432 | 433 | // Add a cost to the action with name "act", in the form of an integer 434 | void addCost( const std::string & act, int cost ) { 435 | Action * action = actions.get( act ); 436 | if ( action->eff == 0 ) action->eff = new And; 437 | And * a = dynamic_cast< And * >( action->eff ); 438 | a->add( new Increase( cost ) ); 439 | } 440 | 441 | // Add a cost to the action with name "act", in the form of a function 442 | void addCost( const std::string & act, const std::string & func, const IntVec & params = IntVec() ) { 443 | Action * action = actions.get( act ); 444 | if ( action->eff == 0 ) action->eff = new And; 445 | And * a = dynamic_cast< And * >( action->eff ); 446 | a->add( new Increase( funcs.get( func ), params ) ); 447 | } 448 | 449 | void addFunctionModifier( const std::string & act, FunctionModifier * fm ) { 450 | Action * action = actions.get( act ); 451 | if ( action->eff == 0 ) action->eff = new And; 452 | And * a = dynamic_cast< And * >( action->eff ); 453 | a->add( fm ); 454 | } 455 | 456 | // Create a ground condition with the given name 457 | Ground * ground( const std::string & name, const IntVec & params = IntVec() ) { 458 | if ( preds.index( name ) < 0 ) { 459 | std::cout << "Creating a ground condition " << name << params; 460 | std::cout << " failed since the predicate " << name << " does not exist!\n"; 461 | std::exit( 1 ); 462 | } 463 | return new Ground( preds[preds.index( name )], params ); 464 | } 465 | 466 | // Return the list of type names corresponding to a parameter list 467 | StringVec typeList( ParamCond * c ) { 468 | StringVec out; 469 | for ( unsigned i = 0; i < c->params.size(); ++i ) 470 | out.push_back( types[c->params[i]]->name ); 471 | return out; 472 | } 473 | 474 | // Return the list of object names corresponding to a ground fluent 475 | StringVec objectList( Ground * g ) { 476 | StringVec out; 477 | for ( unsigned i = 0; i < g->params.size(); ++i ) 478 | out.push_back( types[g->lifted->params[i]]->object( g->params[i] ).first ); 479 | return out; 480 | } 481 | 482 | // Add parameters to an action 483 | void addParams( const std::string & name, const StringVec & v ) { 484 | actions.get( name )->addParams( convertTypes( v ) ); 485 | } 486 | 487 | // Assert that one type is a subtype of another 488 | bool assertSubtype( int t1, int t2 ) { 489 | for ( Type * type = types[t1]; type != 0; type = type->supertype ) 490 | if ( type->name == types[t2]->name ) return 1; 491 | return 0; 492 | } 493 | 494 | // return the index of a constant for a given type 495 | int constantIndex( const std::string & name, const std::string & type ) { 496 | return types.get( type )->parseConstant( name ).second; 497 | } 498 | 499 | //! Prints a PDDL representation of the object to the given stream. 500 | friend std::ostream& operator<<(std::ostream &os, const Domain& o) { return o.print(os); } 501 | virtual std::ostream& print(std::ostream& os) const { 502 | os << "( DEFINE ( DOMAIN " << name << " )\n"; 503 | print_requirements(os); 504 | 505 | if ( typed ) { 506 | os << "( :TYPES\n"; 507 | for ( unsigned i = 1; i < types.size(); ++i ) 508 | types[i]->PDDLPrint( os ); 509 | os << ")\n"; 510 | } 511 | 512 | if ( cons ) { 513 | os << "( :CONSTANTS\n"; 514 | for ( unsigned i = 0; i < types.size(); ++i ) 515 | if ( types[i]->constants.size() ) { 516 | os << "\t"; 517 | for ( unsigned j = 0; j < types[i]->constants.size(); ++j ) 518 | os << types[i]->constants[j] << " "; 519 | if ( typed ) 520 | os << "- " << types[i]->name; 521 | os << "\n"; 522 | } 523 | os << ")\n"; 524 | } 525 | 526 | os << "( :PREDICATES\n"; 527 | for ( unsigned i = 0; i < preds.size(); ++i ) { 528 | preds[i]->PDDLPrint( os, 1, TokenStruct< std::string >(), *this ); 529 | os << "\n"; 530 | } 531 | os << ")\n"; 532 | 533 | if ( funcs.size() ) { 534 | os << "( :FUNCTIONS\n"; 535 | for ( unsigned i = 0; i < funcs.size(); ++i ) { 536 | funcs[i]->PDDLPrint( os, 1, TokenStruct< std::string >(), *this ); 537 | os << "\n"; 538 | } 539 | os << ")\n"; 540 | } 541 | 542 | for ( unsigned i = 0; i < actions.size(); ++i ) 543 | actions[i]->PDDLPrint( os, 0, TokenStruct< std::string >(), *this ); 544 | 545 | for ( unsigned i = 0; i < derived.size(); ++i ) 546 | derived[i]->PDDLPrint( os, 0, TokenStruct< std::string >(), *this ); 547 | 548 | print_addtional_blocks(os); 549 | 550 | os << ")\n"; 551 | return os; 552 | } 553 | 554 | virtual std::ostream& print_requirements(std::ostream& os) const { 555 | os << "( :REQUIREMENTS"; 556 | if ( equality ) os << " :EQUALITY"; 557 | if ( strips ) os << " :STRIPS"; 558 | if ( costs ) os << " :ACTION-COSTS"; 559 | if ( adl ) os << " :ADL"; 560 | if ( neg ) os << " :NEGATIVE-PRECONDITIONS"; 561 | if ( condeffects ) os << " :CONDITIONAL-EFFECTS"; 562 | if ( typed ) os << " :TYPING"; 563 | if ( temp ) os << " :DURATIVE-ACTIONS"; 564 | if ( nondet ) os << " :NON-DETERMINISTIC"; 565 | if ( universal ) os << " :UNIVERSAL-PRECONDITIONS"; 566 | if ( fluents ) os << " :FLUENTS"; 567 | if ( disj ) os << " :DISJUNCTIVE-PRECONDITIONS"; 568 | if ( derivedpred ) os << " :DERIVED-PREDICATES"; 569 | os << " )\n"; 570 | return os; 571 | } 572 | 573 | virtual std::ostream& print_addtional_blocks(std::ostream& os) const { return os; } 574 | 575 | virtual Condition * createCondition( Filereader & f ) { 576 | std::string s = f.getToken(); 577 | 578 | if ( s == "=" ) return new Equals; 579 | if ( s == "AND" ) return new And; 580 | if ( s == "EXISTS" ) return new Exists; 581 | if ( s == "FORALL" ) return new Forall; 582 | if ( s == "INCREASE" ) return new Increase; 583 | if ( s == "DECREASE" ) return new Decrease; 584 | if ( s == "NOT" ) return new Not; 585 | if ( s == "ONEOF" ) return new Oneof; 586 | if ( s == "OR" ) return new Or; 587 | if ( s == "WHEN" ) return new When; 588 | if ( s == ">=" || s == ">" || s == "<=" || s == "<" ) return new CompositeExpression( s ); 589 | 590 | int i = preds.index( s ); 591 | if ( i >= 0 ) return new Ground( preds[i] ); 592 | 593 | f.tokenExit( s ); 594 | 595 | return 0; 596 | } 597 | }; 598 | 599 | } } // namespaces 600 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------