2016-06-10 17:40:32 +02:00
# include <plasp/pddl/TranslatorASP.h>
2016-06-13 02:48:16 +02:00
# include <boost/assert.hpp>
2016-11-29 06:03:05 +01:00
# include <plasp/output/Formatting.h>
# include <plasp/output/TranslatorException.h>
2016-06-12 23:38:44 +02:00
# include <plasp/pddl/expressions/And.h>
# include <plasp/pddl/expressions/Not.h>
2016-06-13 02:38:56 +02:00
# include <plasp/pddl/expressions/Predicate.h>
2016-12-08 00:52:09 +01:00
# include <plasp/pddl/translation/Precondition.h>
2016-12-08 01:27:38 +01:00
# include <plasp/pddl/translation/Predicate.h>
2016-12-08 00:52:09 +01:00
# include <plasp/pddl/translation/Primitives.h>
2016-12-08 01:05:39 +01:00
# include <plasp/pddl/translation/Variables.h>
2016-06-10 17:40:32 +02:00
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TranslatorASP
//
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-11-29 06:03:05 +01:00
TranslatorASP : : TranslatorASP ( Description & description , output : : ColorStream & outputStream )
2016-06-12 22:31:18 +02:00
: m_description ( description ) ,
2016-06-14 16:14:39 +02:00
m_outputStream ( outputStream )
2016-06-10 17:40:32 +02:00
{
2016-09-02 16:39:42 +02:00
m_description . normalize ( ) ;
2016-06-10 17:40:32 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-12 22:31:18 +02:00
void TranslatorASP : : translate ( ) const
2016-06-10 17:40:32 +02:00
{
2016-06-12 22:31:18 +02:00
translateDomain ( ) ;
2016-06-10 17:40:32 +02:00
if ( m_description . containsProblem ( ) )
2016-06-12 22:25:12 +02:00
{
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-12 22:31:18 +02:00
translateProblem ( ) ;
2016-06-12 22:25:12 +02:00
}
2016-06-10 17:40:32 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-12 22:31:18 +02:00
void TranslatorASP : : translateDomain ( ) const
2016-06-10 17:40:32 +02:00
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading1 ( " domain " ) ;
2016-06-10 17:40:32 +02:00
const auto & domain = m_description . domain ( ) ;
// Types
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-14 13:53:09 +02:00
translateTypes ( ) ;
2016-06-10 17:52:19 +02:00
// Constants
2016-06-12 22:19:24 +02:00
if ( ! domain . constants ( ) . empty ( ) )
{
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-14 13:21:41 +02:00
translateConstants ( " constants " , domain . constants ( ) ) ;
2016-06-12 22:19:24 +02:00
}
2016-06-12 22:25:12 +02:00
// Predicates
if ( ! domain . predicates ( ) . empty ( ) )
{
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-12 22:39:04 +02:00
translatePredicates ( ) ;
}
2016-06-12 22:47:39 +02:00
2016-12-07 01:56:06 +01:00
// Derived predicates
if ( ! domain . derivedPredicates ( ) . empty ( ) )
{
m_outputStream < < std : : endl ;
translateDerivedPredicates ( ) ;
}
2016-06-12 22:47:39 +02:00
// Actions
if ( ! domain . actions ( ) . empty ( ) )
{
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-12 22:47:39 +02:00
translateActions ( ) ;
}
2016-06-12 22:39:04 +02:00
}
2016-06-12 22:25:12 +02:00
2016-06-12 22:39:04 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-12 22:25:12 +02:00
2016-06-12 22:39:04 +02:00
void TranslatorASP : : translateTypes ( ) const
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading2 ( " types " ) ;
2016-06-14 16:38:41 +02:00
m_outputStream < < std : : endl ;
2016-06-12 22:25:12 +02:00
2016-06-12 22:39:04 +02:00
const auto & types = m_description . domain ( ) . types ( ) ;
2016-06-12 22:25:12 +02:00
2016-06-14 13:53:09 +02:00
if ( types . empty ( ) )
{
2016-08-13 02:32:27 +02:00
m_outputStream
2016-11-29 06:03:05 +01:00
< < output : : Function ( " type " ) < < " ( "
< < output : : Keyword ( " type " ) < < " ( " < < output : : String ( " object " ) < < " )). " < < std : : endl ;
2016-08-13 02:32:27 +02:00
2016-06-14 13:53:09 +02:00
return ;
}
2016-12-08 01:05:39 +01:00
for ( const auto & type : types )
{
m_outputStream
< < output : : Function ( " type " ) < < " ( "
< < output : : Keyword ( " type " ) < < " ( "
< < output : : String ( type - > name ( ) . c_str ( ) )
< < " )). " < < std : : endl ;
2016-06-12 22:25:12 +02:00
2016-12-08 01:05:39 +01:00
const auto & parentTypes = type - > parentTypes ( ) ;
2016-06-12 22:25:12 +02:00
2016-12-08 01:05:39 +01:00
std : : for_each ( parentTypes . cbegin ( ) , parentTypes . cend ( ) ,
[ & ] ( const auto & parentType )
{
m_outputStream
< < output : : Function ( " inherits " ) < < " ( " < < output : : Keyword ( " type " )
< < " ( " < < output : : String ( type - > name ( ) . c_str ( ) ) < < " ), " < < output : : Keyword ( " type " )
< < " ( " < < output : : String ( parentType - > name ( ) . c_str ( ) ) < < " )). " < < std : : endl ;
} ) ;
}
2016-08-16 18:35:55 +02:00
m_outputStream
< < std : : endl
2016-11-29 06:03:05 +01:00
< < output : : Function ( " has " ) < < " ( "
< < output : : Variable ( " X " ) < < " , "
< < output : : Keyword ( " type " ) < < " ( " < < output : : Variable ( " T2 " ) < < " )) :- "
< < output : : Function ( " has " ) < < " ( "
< < output : : Variable ( " X " ) < < " , "
< < output : : Keyword ( " type " ) < < " ( " < < output : : Variable ( " T1 " ) < < " )), "
< < output : : Function ( " inherits " ) < < " ( "
< < output : : Keyword ( " type " ) < < " ( " < < output : : Variable ( " T1 " ) < < " ), "
< < output : : Keyword ( " type " ) < < " ( " < < output : : Variable ( " T2 " ) < < " )). "
2016-08-16 18:35:55 +02:00
< < std : : endl ;
2016-06-12 22:39:04 +02:00
}
2016-06-12 22:25:12 +02:00
2016-06-12 22:39:04 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-12 22:25:12 +02:00
2016-06-12 22:39:04 +02:00
void TranslatorASP : : translatePredicates ( ) const
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading2 ( " variables " ) ;
2016-06-12 22:39:04 +02:00
const auto & predicates = m_description . domain ( ) . predicates ( ) ;
2016-12-08 01:05:39 +01:00
for ( const auto & predicate : predicates )
{
2016-12-08 01:27:38 +01:00
m_outputStream < < std : : endl < < output : : Function ( " variable " ) < < " ( " ;
2016-06-13 02:38:56 +02:00
2016-12-08 01:27:38 +01:00
translation : : printPredicateName ( m_outputStream , * predicate ) ;
2016-08-13 02:48:30 +02:00
2016-12-08 01:27:38 +01:00
m_outputStream < < " ) " ;
2016-06-13 02:38:56 +02:00
2016-12-08 01:05:39 +01:00
translation : : translateVariablesForRuleBody ( m_outputStream , predicate - > parameters ( ) ) ;
2016-12-07 01:56:06 +01:00
2016-12-08 01:05:39 +01:00
m_outputStream < < " . " ;
}
2016-12-07 01:56:06 +01:00
m_outputStream
< < std : : endl < < std : : endl
< < output : : Function ( " boolean " ) < < " ( " < < output : : Boolean ( " true " ) < < " ). " < < std : : endl
< < output : : Function ( " boolean " ) < < " ( " < < output : : Boolean ( " false " ) < < " ). " < < std : : endl
< < std : : endl
< < output : : Function ( " contains " ) < < " ( "
< < output : : Keyword ( " variable " ) < < " ( " < < output : : Variable ( " X " ) < < " ), "
< < output : : Keyword ( " value " ) < < " ( " < < output : : Variable ( " X " ) < < " , " < < output : : Variable ( " B " ) < < " )) :- "
< < output : : Function ( " variable " ) < < " ( " < < output : : Keyword ( " variable " ) < < " ( " < < output : : Variable ( " X " ) < < " )), "
< < output : : Function ( " boolean " ) < < " ( " < < output : : Variable ( " B " ) < < " ). "
< < std : : endl ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void TranslatorASP : : translateDerivedPredicates ( ) const
{
m_outputStream < < output : : Heading2 ( " derived predicates " ) ;
const auto & derivedPredicates = m_description . domain ( ) . derivedPredicates ( ) ;
2016-12-08 00:52:09 +01:00
for ( const auto & derivedPredicate : derivedPredicates )
{
2016-12-08 01:27:38 +01:00
const auto printObjectName =
[ & ] ( auto & outputStream )
2016-12-07 01:56:06 +01:00
{
2016-12-08 01:27:38 +01:00
translation : : printDerivedPredicateName ( outputStream , * derivedPredicate ) ;
2016-12-08 00:52:09 +01:00
} ;
2016-12-07 01:56:06 +01:00
2016-12-08 00:52:09 +01:00
m_outputStream < < std : : endl < < output : : Function ( " derivedVariable " ) < < " ( " ;
2016-12-07 01:56:06 +01:00
2016-12-08 01:27:38 +01:00
printObjectName ( m_outputStream ) ;
2016-12-07 01:56:06 +01:00
2016-12-08 00:52:09 +01:00
m_outputStream < < " ) " ;
2016-06-12 22:39:04 +02:00
2016-12-08 01:05:39 +01:00
translation : : translateVariablesForRuleBody ( m_outputStream , derivedPredicate - > parameters ( ) ) ;
2016-08-18 00:00:50 +02:00
2016-12-08 00:52:09 +01:00
m_outputStream < < " . " ;
2016-12-08 01:27:38 +01:00
translation : : translatePreconditionDisjunction ( m_outputStream , " derivedVariable " , printObjectName , derivedPredicate - > preconditions ( ) ) ;
2016-12-08 00:52:09 +01:00
m_outputStream < < std : : endl ;
}
m_outputStream
< < std : : endl
< < output : : Function ( " contains " ) < < " ( "
< < output : : Keyword ( " derivedVariable " ) < < " ( " < < output : : Variable ( " X " ) < < " ), "
< < output : : Keyword ( " value " ) < < " ( " < < output : : Variable ( " X " ) < < " , " < < output : : Variable ( " B " ) < < " )) :- "
2016-12-08 00:54:13 +01:00
< < output : : Function ( " derivedVariable " ) < < " ( " < < output : : Keyword ( " derivedVariable " ) < < " ( " < < output : : Variable ( " X " ) < < " )), "
2016-12-08 00:52:09 +01:00
< < output : : Function ( " boolean " ) < < " ( " < < output : : Variable ( " B " ) < < " ). "
< < std : : endl ;
2016-06-12 22:47:39 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void TranslatorASP : : translateActions ( ) const
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading2 ( " actions " ) ;
2016-06-12 22:47:39 +02:00
const auto & actions = m_description . domain ( ) . actions ( ) ;
2016-06-13 02:38:56 +02:00
const auto printActionName =
[ & ] ( const auto & action )
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Keyword ( " action " ) < < " ( " ;
2016-06-13 02:38:56 +02:00
2016-08-16 18:35:55 +02:00
if ( action . parameters ( ) . empty ( ) )
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : String ( action . name ( ) . c_str ( ) ) < < " ) " ;
2016-06-13 02:38:56 +02:00
2016-08-16 18:35:55 +02:00
return ;
}
2016-11-29 06:03:05 +01:00
m_outputStream < < " ( " < < output : : String ( action . name ( ) . c_str ( ) ) ;
2016-12-08 01:05:39 +01:00
translation : : translateVariablesForRuleHead ( m_outputStream , action . parameters ( ) ) ;
2016-08-16 18:35:55 +02:00
m_outputStream < < " )) " ;
2016-06-13 02:38:56 +02:00
} ;
2016-12-07 02:11:54 +01:00
for ( const auto & action : actions )
{
const auto translateExpression =
[ & ] ( const auto & ruleHead , const auto & literal , bool enumerateEffects = false )
{
m_outputStream < < std : : endl < < output : : Function ( ruleHead ) < < " ( " ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
printActionName ( * action ) ;
2016-08-13 03:17:48 +02:00
2016-12-07 02:11:54 +01:00
// TODO: implement conditional effects
if ( enumerateEffects )
m_outputStream < < " , " < < output : : Keyword ( " effect " ) < < " ( " < < output : : Reserved ( " unconditional " ) < < " ) " ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < " , " ;
2016-06-13 02:38:56 +02:00
2016-12-08 00:52:09 +01:00
translation : : translateLiteral ( m_outputStream , literal ) ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < " ) :- " < < output : : Function ( " action " ) < < " ( " ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
printActionName ( * action ) ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < " ). " ;
} ;
2016-06-13 03:19:24 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < std : : endl ;
2016-06-13 03:19:24 +02:00
2016-12-07 02:11:54 +01:00
// Name
m_outputStream < < output : : Function ( " action " ) < < " ( " ;
printActionName ( * action ) ;
m_outputStream < < " ) " ;
2016-06-13 03:19:24 +02:00
2016-12-08 01:05:39 +01:00
translation : : translateVariablesForRuleBody ( m_outputStream , action - > parameters ( ) ) ;
2016-06-13 03:19:24 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < " . " ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
// Precondition
if ( action - > precondition ( ) )
{
const auto & precondition = * action - > precondition ( ) ;
2016-06-13 02:38:56 +02:00
2016-12-07 02:11:54 +01:00
switch ( precondition . expressionType ( ) )
2016-06-13 02:41:23 +02:00
{
2016-12-07 02:11:54 +01:00
case Expression : : Type : : And :
2016-06-13 02:41:23 +02:00
{
2016-12-07 02:29:48 +01:00
const auto & andExpression = precondition . as < expressions : : And > ( ) ;
2016-06-13 02:41:23 +02:00
std : : for_each ( andExpression . arguments ( ) . cbegin ( ) , andExpression . arguments ( ) . cend ( ) ,
2016-09-04 18:48:46 +02:00
[ & ] ( const auto argument )
2016-06-13 02:41:23 +02:00
{
2016-12-07 02:11:54 +01:00
translateExpression ( " precondition " , * argument ) ;
2016-06-13 02:41:23 +02:00
} ) ;
2016-12-07 02:11:54 +01:00
break ;
}
case Expression : : Type : : Predicate :
case Expression : : Type : : Not :
case Expression : : Type : : DerivedPredicate :
{
translateExpression ( " precondition " , precondition ) ;
break ;
2016-06-13 02:41:23 +02:00
}
2016-12-07 02:11:54 +01:00
default :
throw output : : TranslatorException ( " only “and” expressions and (negated) predicates supported as action preconditions currently ( " + std : : to_string ( ( int ) precondition . expressionType ( ) ) + " ) " ) ;
2016-06-13 02:41:23 +02:00
}
2016-12-07 02:11:54 +01:00
}
2016-06-13 02:41:23 +02:00
2016-12-07 02:11:54 +01:00
// Effect
if ( action - > effect ( ) )
{
const auto & effect = * action - > effect ( ) ;
if ( effect . is < expressions : : Predicate > ( ) | | effect . is < expressions : : Not > ( ) )
{
translateExpression ( " postcondition " , effect , true ) ;
}
// Assuming a conjunction
else
{
if ( effect . expressionType ( ) ! = Expression : : Type : : And )
throw output : : TranslatorException ( " only “and” expressions and (negated) predicates supported as action effects currently " ) ;
2016-12-07 02:29:48 +01:00
const auto & andExpression = effect . as < expressions : : And > ( ) ;
2016-12-07 02:11:54 +01:00
std : : for_each ( andExpression . arguments ( ) . cbegin ( ) , andExpression . arguments ( ) . cend ( ) ,
[ & ] ( const auto argument )
{
translateExpression ( " postcondition " , * argument , true ) ;
} ) ;
}
}
m_outputStream < < std : : endl ;
}
2016-06-12 22:55:35 +02:00
}
2016-06-12 22:47:39 +02:00
2016-06-12 22:55:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-12 22:47:39 +02:00
2016-06-14 16:38:41 +02:00
void TranslatorASP : : translateConstants ( const std : : string & heading , const expressions : : Constants & constants ) const
2016-06-14 13:21:41 +02:00
{
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading2 ( heading . c_str ( ) ) ;
2016-06-14 13:21:41 +02:00
2016-12-08 01:05:39 +01:00
for ( const auto & constant : constants )
2016-06-12 22:55:35 +02:00
{
2016-12-08 01:05:39 +01:00
m_outputStream < < std : : endl
< < output : : Function ( " constant " ) < < " ( "
< < output : : Keyword ( " constant " ) < < " ( "
< < output : : String ( constant - > name ( ) . c_str ( ) )
< < " )). " < < std : : endl ;
2016-06-14 13:21:41 +02:00
2016-12-08 01:05:39 +01:00
const auto type = constant - > type ( ) ;
2016-06-12 22:55:35 +02:00
2016-12-08 01:05:39 +01:00
if ( type ! = nullptr )
2016-06-13 16:37:35 +02:00
{
2016-12-08 01:05:39 +01:00
m_outputStream < < output : : Function ( " has " ) < < " ( "
< < output : : Keyword ( " constant " ) < < " ( " < < output : : String ( constant - > name ( ) . c_str ( ) ) < < " ), "
< < output : : Keyword ( " type " ) < < " ( " < < output : : String ( type - > name ( ) . c_str ( ) ) < < " )). " < < std : : endl ;
2016-06-13 16:37:35 +02:00
}
2016-06-14 13:21:41 +02:00
else
2016-06-14 16:38:41 +02:00
{
2016-12-08 01:05:39 +01:00
m_outputStream < < output : : Function ( " has " ) < < " ( "
< < output : : Keyword ( " constant " ) < < " ( " < < output : : String ( constant - > name ( ) . c_str ( ) ) < < " ), "
< < output : : Keyword ( " type " ) < < " ( " < < output : : String ( " object " ) < < " )). " < < std : : endl ;
2016-06-14 16:38:41 +02:00
}
2016-06-12 22:55:35 +02:00
}
2016-06-10 17:40:32 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-12 22:31:18 +02:00
void TranslatorASP : : translateProblem ( ) const
2016-06-10 17:40:32 +02:00
{
2016-06-13 03:19:24 +02:00
BOOST_ASSERT ( m_description . containsProblem ( ) ) ;
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading1 ( " problem " ) ;
2016-06-13 02:48:16 +02:00
const auto & problem = m_description . problem ( ) ;
// Objects
if ( ! problem . objects ( ) . empty ( ) )
{
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-14 13:21:41 +02:00
translateConstants ( " objects " , problem . objects ( ) ) ;
2016-06-13 02:48:16 +02:00
}
2016-06-13 02:59:43 +02:00
// Initial State
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-13 02:59:43 +02:00
translateInitialState ( ) ;
2016-06-13 03:19:24 +02:00
// Goal
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-13 03:19:24 +02:00
translateGoal ( ) ;
2016-06-13 02:48:16 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-13 02:59:43 +02:00
void TranslatorASP : : translateInitialState ( ) const
{
2016-06-13 03:19:24 +02:00
BOOST_ASSERT ( m_description . containsProblem ( ) ) ;
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading2 ( " initial state " ) ;
2016-06-13 02:59:43 +02:00
const auto & initialStateFacts = m_description . problem ( ) . initialState ( ) . facts ( ) ;
2016-12-07 02:11:54 +01:00
for ( const auto & fact : initialStateFacts )
{
m_outputStream < < std : : endl < < output : : Function ( " initialState " ) < < " ( " ;
2016-06-13 02:59:43 +02:00
2016-12-07 02:11:54 +01:00
// Translate single predicate
if ( fact - > is < expressions : : Predicate > ( ) )
{
2016-12-07 02:29:48 +01:00
const auto & predicate = fact - > as < expressions : : Predicate > ( ) ;
2016-08-13 03:22:25 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < output : : Keyword ( " variable " ) < < " ( " ;
2016-12-08 00:52:09 +01:00
translation : : translatePredicate ( m_outputStream , predicate ) ;
2016-12-07 02:11:54 +01:00
m_outputStream < < " ), " < < output : : Keyword ( " value " ) < < " ( " ;
2016-12-08 00:52:09 +01:00
translation : : translatePredicate ( m_outputStream , predicate ) ;
2016-12-07 02:11:54 +01:00
m_outputStream < < " , " < < output : : Boolean ( " true " ) < < " ) " ;
}
// Assuming that "not" expression may only contain a predicate
else if ( fact - > is < expressions : : Not > ( ) )
{
2016-12-07 02:29:48 +01:00
const auto & notExpression = fact - > as < expressions : : Not > ( ) ;
2016-06-13 02:59:43 +02:00
2016-12-07 02:11:54 +01:00
if ( notExpression . argument ( ) - > expressionType ( ) ! = Expression : : Type : : Predicate )
throw output : : TranslatorException ( " only negations of simple predicates supported in initial state currently " ) ;
}
else
throw output : : TranslatorException ( " only predicates and their negations supported in initial state currently " ) ;
2016-06-13 02:59:43 +02:00
2016-12-07 02:11:54 +01:00
m_outputStream < < " ). " ;
}
2016-06-13 02:59:43 +02:00
2016-08-17 19:02:51 +02:00
m_outputStream
< < std : : endl < < std : : endl
2016-11-29 06:03:05 +01:00
< < output : : Function ( " initialState " ) < < " ( "
< < output : : Keyword ( " variable " ) < < " ( " < < output : : Variable ( " X " ) < < " ), "
< < output : : Keyword ( " value " ) < < " ( " < < output : : Variable ( " X " ) < < " , " < < output : : Boolean ( " false " ) < < " )) :- "
< < output : : Function ( " variable " ) < < " ( " < < output : : Keyword ( " variable " ) < < " ( " < < output : : Variable ( " X " ) < < " )), "
< < output : : Keyword ( " not " ) < < " "
< < output : : Function ( " initialState " ) < < " ( "
< < output : : Keyword ( " variable " ) < < " ( " < < output : : Variable ( " X " ) < < " ), "
< < output : : Keyword ( " value " ) < < " ( " < < output : : Variable ( " X " ) < < " , " < < output : : Boolean ( " true " ) < < " )). "
2016-08-17 19:02:51 +02:00
< < std : : endl ;
2016-06-13 02:59:43 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-13 03:19:24 +02:00
void TranslatorASP : : translateGoal ( ) const
{
BOOST_ASSERT ( m_description . containsProblem ( ) ) ;
2016-11-29 06:03:05 +01:00
m_outputStream < < output : : Heading2 ( " goal " ) ;
2016-06-13 03:19:24 +02:00
const auto & goal = m_description . problem ( ) . goal ( ) ;
2016-12-07 02:11:54 +01:00
if ( goal . is < expressions : : Predicate > ( ) | | goal . is < expressions : : Not > ( ) )
2016-06-13 03:19:24 +02:00
{
2016-11-29 06:03:05 +01:00
m_outputStream < < std : : endl < < output : : Function ( " goal " ) < < " ( " ;
2016-06-13 03:19:24 +02:00
2016-12-08 00:52:09 +01:00
translation : : translateLiteral ( m_outputStream , goal ) ;
2016-06-13 03:19:24 +02:00
2016-06-14 16:14:39 +02:00
m_outputStream < < " ). " ;
2016-06-13 03:19:24 +02:00
}
2016-12-07 02:11:54 +01:00
else if ( goal . is < expressions : : And > ( ) )
2016-06-13 03:19:24 +02:00
{
2016-12-07 02:29:48 +01:00
const auto & andExpression = goal . as < expressions : : And > ( ) ;
2016-06-13 03:19:24 +02:00
std : : for_each ( andExpression . arguments ( ) . cbegin ( ) , andExpression . arguments ( ) . cend ( ) ,
2016-09-04 18:48:46 +02:00
[ & ] ( const auto argument )
2016-06-13 03:19:24 +02:00
{
2016-11-29 06:03:05 +01:00
m_outputStream < < std : : endl < < output : : Function ( " goal " ) < < " ( " ;
2016-06-13 03:19:24 +02:00
2016-12-08 00:52:09 +01:00
translation : : translateLiteral ( m_outputStream , * argument ) ;
2016-06-13 03:19:24 +02:00
2016-06-14 16:14:39 +02:00
m_outputStream < < " ). " ;
2016-06-13 03:19:24 +02:00
} ) ;
}
else
2016-11-29 06:03:05 +01:00
throw output : : TranslatorException ( " only single predicates, their negations, and conjunctions are currently supported in the goal " ) ;
2016-06-13 03:19:24 +02:00
2016-06-14 16:14:39 +02:00
m_outputStream < < std : : endl ;
2016-06-13 03:19:24 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-10 17:40:32 +02:00
}
}