3. rafcontpp.logic package

3.1. Submodules

3.2. rafcontpp.logic.domain_generator module

class rafcontpp.logic.domain_generator.DomainGenerator(datastore)[source]

Bases: object

The DomainGenerator uses the data provided by the datastore to generate a domain.pddl file for the planner.

Parameters:datastore – A Datastore containing: pddl facts representation, pddl action map, file save directory.
_DomainGenerator__get_actions(pddl_actions)

Takes a list of PddlActionRepresentations, and returns a pddl conform action section.

Parameters:pddl_actions – A list of PddlActionRepresentations.
Returns:String: A pddl conform action section.
_DomainGenerator__get_comment_section()

This method generated a header comment for the domain, containing the version, the time, date and the ‘author’.

Returns:String: A domain header comment, already containing the pddl comment indicator character ‘;’.
_DomainGenerator__get_head(domain_name)

Takes a domain name, and returns the head of a pddl domain, e.g. “(define (domain test_domain)”.

Parameters:domain_name – The name of the domain.
Returns:String: The head of a pddl domain.
_DomainGenerator__get_predicates(predicates)

Takes a list of predicates as string, and returns a pddl confrom predicates section.

Parameters:predicate_section – A list of predicates as strings.
Returns:String: A pddl conform predicates section.
_DomainGenerator__get_requirements(requirements)

Takes the requirements list and returns it as string in a pddl-format.

Parameters:requirements – A list with all requirments
Returns:String: Requirments in a pddl-conform format.
_DomainGenerator__get_types(merged_types)

Takes a type tree and returns a string representation usable in a pddl-domain.

Parameters:merged_types – A type tree containing all (relevant) types.
Returns:String: A type section usable in pddl.
_DomainGenerator__merge_predicates(pddl_actions)

mergePredicates takes all predicates mentioned in the PddlActionRepresentations, and removes dublicates.

Parameters:pddl_actions – A list of PddlActionRepresentations.
Returns:([String],[(String,[(String,int)])]): A tuple with a list of predicates and a list of predicates as tuple without dublicates.
_DomainGenerator__merge_requirements(pddl_actions)

mergeRequirements takes the requirements of the used pddl-actions, and removes dublicates.

Parameters:pddl_actions – A list with PddlActionRepresentations
Returns:[String]: All pddl-requirements without dublicates.
generate_domain()[source]

generateDomain generates a domain and returns its path.

Returns:String: The path of the generated domain file.

3.3. rafcontpp.logic.mapper module

class rafcontpp.logic.mapper.Mapper(datastore)[source]

Bases: object

The Mapper maps pddl actions and rafcon states together.

Parameters:datastore – A datastore containing state pools.
generate_action_state_map()[source]

generates a map, with pddl action names as key, and RAFCON States as Values. Writes the map into the datastore.

Returns:void
generate_available_actions()[source]

Takes the action_state_map, and extracts the keys, in order to get a list of all available PDDL Actions. If no action_state_map exists, it calls generate_action_state_map() first. It writes the list with available actions into the datastore.

Returns:void
generate_state_action_map()[source]

Generates a map with RAFCON States as Keys and PDDL Action names as values. If no action_state_map exists, it calls generate action_state_map. It’s writing the map into the datastore.

Returns:void

3.4. rafcontpp.logic.pddl_action_loader module

class rafcontpp.logic.pddl_action_loader.PddlActionLoader(datastore)[source]

Bases: object

This class reads and parses PDDL actions from RAFCON states, into the PDDLActionRepresentation.

Parameters:datastore – A datastore containing state pools, the state action map, and available actions.
load_pddl_actions()[source]

load_pddl_actions reads the actions from the states and parses them into PddlActionRepresentations. Then it sets the pddl action map in datastore.

Returns:void
parse_predicate_string(pred_string)[source]

Construct predicate array from predicate string.

Parameters:pred_string – A string containing all predicates of the action.
Returns:[String]: An array containing all predicates of the action.
parse_requirement_string(requ_string)[source]

Reveives an requirements string and parses it into a requirement array.

Parameters:requ_string – A string containing requirements.
Returns:[String]: An array containing requirements. An empty array if requ_string is None or empty.
parse_type_string(type_string)[source]

parse_type_string reveives a type string of fromat type1,type2 or type1 type2 and parses it into an array containing the types.

Parameters:type_string – A type string of format type1,type2 or type1 type2.
Returns:[String]: An array containing the types contained in the string, or an empty array if string is None or empty.

3.5. rafcontpp.logic.pddl_action_parser module

class rafcontpp.logic.pddl_action_parser.PddlActionParser(action_string)[source]

Bases: object

PddlActionParser is able to parse an pddl action string e.g. a usual pddl action into a PddlActionRepresentation by extracting predicates, types, variables and the action name.

Parameters:action_string – A pddl action string
_PddlActionParser__clean_comments(action_string)

Takes the action string and removes all comments.

Returns:String: The action string without comments.
_PddlActionParser__create_var_type_dict()

create_var_type_dict creates a dictionary, which contains all variables with their type, defined in the action.

Returns:{String:String}: A dictionary containing variable : type pairs.
_PddlActionParser__is_built_in_pred(name)

Checks if the Predicate is a PDDL built-in predicate.

Parameters:name – The name of a predicate.
Returns:Boolean: True if the predicate is a PDDL built-in predicate, false otherwise.
_PddlActionParser__parse_and_generalize_predicates()

This method extracts all applied pradicates from the action, then it generalizes them. e.g. add types to the variables and remove dublicats. applied predicate example: (at ?a ?b) generalized predicate example: (at ?a - Location ?b - Robot)

Returns:[String]: A list with all parsed predicates.
parse_action()[source]

parse_action takes the given action string, and parses it into a PddlActionRepresenation, raises ValueError, if the action string is none or empty.

Returns:PddlActionRepresentation: A PddlActionRepresentation of the pddl action.
parse_action_name()[source]

parse_action_name reads the action form the given action and returns it.

Returns:String: The name of the action.
parse_parameters()[source]

parse_parameters parses the parameters out of an pddl action string.

Returns:[String]: A list with parameter names, without ‘?’

3.6. rafcontpp.logic.pddl_facts_parser module

class rafcontpp.logic.pddl_facts_parser.PddlFactsParser(facts_string)[source]

Bases: object

The facts file parser will later be used to parse a raw facts file into a pddl facts file representation.

Parameters:facts_string – The facts file content as string.
_PddlFactsParser__clean_comments(facts_string)

Takes the facts string and removes all comments.

Returns:String: The facts string without comments.
parse_domain_name()[source]

parse_domain_name parses the domain name out of the given facts file.

Returns:String: The domain name.
parse_objects()[source]

Parse object parses the Objects present in the facts file, and returns a map of all objects with their type, in format: object: type

Returns:{String:String}: A map of format: key: Object, value: type.
parse_problem_name()[source]

parse_problem_name parses the problem name out of the given facts file.

Returns:String: The problem name.

3.7. rafcontpp.logic.pddl_requirement_finder module

class rafcontpp.logic.pddl_requirement_finder.PddlRequirementFinder(action_string)[source]

Bases: object

The PddlRequirementFiner, tries to figure out requirments from a given action definition. It’s doing this according to PDDL 2.1. It’s not completed yet.

Parameters:action_string – An string, containing a pddl action.
action_expansions()[source]
adl()[source]
conditional_effects()[source]

This requirement allows for “when”, and “forall” in the effects of an action.

Returns:Boolean: True, if “forall” or “when” is present in the effects of an action. False otherwise.
dag_expansions()[source]
disjunctive_preconditions()[source]

Allows the key words “imply” and “or” in the preconditions.

Returns:Boolean: True if the key words “or”, or “imply” are part of the preconditions. False otherwise.
domain_axioms()[source]
equality()[source]

Equality allows for a built-in predicate named “=”. :return: Boolean: True, if “=” is present in the action. False otherwise.

existential_preconditions()[source]

Allows for the “exists” keyword.

Returns:Boolean: True, if “exists” is present in the preconditions. False otherwise.
expression_evaluation()[source]
fluents()[source]
foreach_expansions()[source]
negative_preconditions()[source]

Negative preconditions allows for the “NOT” keyword in the preconditions.

Returns:Boolean: True if preconditions contain a ‘NOT’, False otherwise.
quantified_preconditions()[source]

This is the abbreviation of the requirement set, consisting of existential, and universal-preconditions.

Returns:Boolean: True, if existential and universal-preconditions are met. False otherwise.
strips()[source]

Returns always True, since “If a domain stipulates no requirements, it is assumed to declare a requirement for :strips” (PDDL2.1: An Extension to PDDL for Expressing Temporal Planning Domains, Fox and Long, 12/2003)

Returns:Boolean: Returns always True.
typing()[source]

returns true, if the action is typed.

Returns:Boolean: True if the action is typed, False otherwise.
universal_preconditions()[source]

this requirement allows forall-loops inside of the preconditions.

Returns:Boolean: True, if forall loop is present in the preconditions. False otherwise.

3.8. rafcontpp.logic.predicate_merger module

class rafcontpp.logic.predicate_merger.PredicateMerger(datastore)[source]

Bases: object

This class merges predicates with the same identifier, but different types of the same branch together.

Parameters:datastore – A datastore containing available types.
_PredicateMerger__name_index = 0
_PredicateMerger__parse_predicate(predicate_string)

parse_predicate gets a predicate string and parses it into a useful tuple of (predicate_Name,[(type_name,occurance)]).

Parameters:predicate_string – A predicate as string e.g (LOCATED ?VEH - VEHICLE ?OBJ ?sObj ?thirdObj - PHYSOBJ).
Returns:(String,[(String,int)]): A parsed predicate as tuple e.g. (‘LOCATED’,[(VEHICLE,1),(PHYSOBJ,3)]).
_PredicateMerger__reduce_predicate_list(predicate_list)

reduce_predicate_list gets a list of predicates, with the same name but different types, and reduces them to one predicate, with the most open types.

Parameters:predicate_list – A list of predicates with the same name, format: (‘LOCATED’,[(VEHICLE,1),(PHYSOBJ,3)])
Returns:(String,[(String,int)]): One predicate tuple, containing the most general types. of format (‘LOCATED’,[(VEHICLE,1),(PHYSOBJ,3)])
_PredicateMerger__tuple_to_predicate_string(predicate_tuple)

Receives a predicate tuple and returns it as predicate string.

Parameters:predicate_tuple – A tuple in format (PREDICATE_NAME,[(TYPE,NUM_VARIABLES)])
Returns:String: A predicate string e.g (PREDICATENAME ?0 ?1 - Type).
merge_predicates(predicates)[source]

Merge predicates merges all predicates, sets all available predicates in datastore and returns all merged predicates as strings.

Parameters:predicates – A list [string] with predicates.
Returns:([String],[(String,[(String,int)])]): A tuple (list [string] with merged predicates, and a list [of format (‘LOCATED’,[(VEHICLE,1),(PHYSOBJ,3)])] all available predicates)

3.9. rafcontpp.logic.state_machine_generator module

class rafcontpp.logic.state_machine_generator.StateMachineGenerator(datastore)[source]

Bases: object

The StateMachineGenerator takes the plan from the datastore and molds a state machine out of it.

Parameters:datastore – A datastore containing: the target state, the state machine save directory, the action state map,

the pddl action map, the facts representation, the runtime data path, the plan, the state pools, and the state machine name.

_StateMachineGenerator__clear_state(state)

Clear_state receives a hierarchy state, and removes all child states.

Parameters:state – A hierarchy state
Returns:Boolean: True if clearing was successful, False otherwhise.
_StateMachineGenerator__generate_core_machine(target_state)

Takes a root state, and generates the state machine into it.

Parameters:target_state – The root state

:return:(HierarchyState,[State]): The root state containing the state machine, and the state order list, is a list of all states in the sm in right order. Can return (None,[]) if process was interrupted.

_StateMachineGenerator__generate_independent_state_machine(target_state=None)

generate_independent_state_machine generates a new state machine. It optinally receives a target_state, which is then treated as root state for the new state machine. If the target state is not valid, a new root state is used.

Parameters:target_state – A potential target state, optional.
Returns:StateMachine: The generated state machine.
_StateMachineGenerator__generate_state_machine_into_state(target_state)

generate_state_machine_into_state receives a target state, copies that state, generates a state machine into the copy, and then substitutes the original state with the copy.

Parameters:target_state – The target state to generate the state machine into a copy of it.
Returns:(Boolean, HierarchyState): True if successful, False otherwise. May return a state which should

be used as root state for a new independent state machine, or None.

_StateMachineGenerator__get_actual_sm_name()

Looks if a state machine name is present in the datastore, if no name is present it uses the problem name followed by _state_machine.

Returns:String: The actual state machine name.
_StateMachineGenerator__get_runtime_data_init_state(data_init_file_path, use_as_ref)

Creates an execution state, containing the, or a reference to the runtime data, as well as the code needed to write it into a dictionary in the global variables.

Parameters:
  • data_init_file_path – The path of a file containing a json dict.
  • use_as_ref – True if the path should be included as reference, False if the dictionary itself should be included.
Returns:

ExecutionState: An Execution state, that will update the rtpp_data dict in the global variables.

_StateMachineGenerator__is_valid_target_state(target_state)

is_valid_target_state receives a potential target state, and checks if it is valid. e.g. if its a hierarchy state, if its None, if permission is granted.

Parameters:target_state – A state to validate
Returns:(Boolean, String): True if state is valid, and an error message, in case it’s not.
_StateMachineGenerator__load_state(wanted_state)

load_state gets a state and loads it from the libraries.

Parameters:wanted_state – A state that should be loaded.
Returns:LibraryState: The loaded state
_StateMachineGenerator__open_state_machine(state_machine, state_machine_path)

Reveives a state machine and opens it in rafcon. If an old version is still open, it closes it first.

Parameters:
  • state_machine – The name of the state machine
  • state_machine_path – The path of the state machine.
Returns:

void

generate_state_machine()[source]

generate_state_machine generates a state machine, fills the data ports and opens the state machine in rafcon, if it’s a new one.

Returns:void

3.10. rafcontpp.logic.state_machine_layouter module

class rafcontpp.logic.state_machine_layouter.StateMachineLayouter[source]

Bases: object

StateMachineLayouter gets a state machine, and layouts it in a particular way.

_StateMachineLayouter__get_num_rows(num_states, width=16.0, height=9.0)

Get num rows, receives the number of states, a width and a height. it uses the width and the height to calculate a ratio, to be able to calculate the number of rows to use the given space optimal.

Parameters:
  • num_states – The number of the states used.
  • width – The width of the available space. if this or height <= 0 automatically set to 16.
  • height – The height of the available space if this or heigt <= 0 automatically set to 9.
Returns:

double: The number of rows optimal in the state machine.

_StateMachineLayouter__get_state_dimensions(canvas_width, canvas_height, col_count, row_count)

get_state_dimensions reveives a fixed canvas width and height, a col and a row count and calcualtes a possible state size. adds an additional x_gap.

Parameters:
  • canvas_width
  • canvas_height
Returns:

(double,double,double,double). (state_width, state_height, x_gap, y_gap)

_StateMachineLayouter__get_target_state_dimensions(canvas_width, canvas_height)

get_target_state_dimensions receives a desired canvas width and height, and returns the overall rootstate size, and the border width.

Parameters:
  • canvas_width – The width of the canvas.
  • canvas_height – The height of the canvas.
Returns:

(double, double, double): (width, height, border_width).

layout_state_machine(state_machine, target_state, fixed_size, state_order)[source]

This function will format the state machine in a merlon like format.

Parameters:
  • state_machine – A state machine to layout.
  • target_state – The “root state” all content in the state will be formated, it needs to be tube like.
  • fixed_size – True if the size of the root state is fixed.
  • state_order – The order of the states in the machine.
Returns:

void

3.11. rafcontpp.logic.type_merger module

class rafcontpp.logic.type_merger.TypeMerger(datastore)[source]

Bases: object

Parameters:datastore – A datastore containing: A pddl action map and the path of the type database.
_TypeMerger__dict_to_upper(dict)
Receives a dict of string:string and returns it in upper case.
Parameters:dict – A string:string dict
Returns:{String:String}: A new dict in upper case.
merge_types()[source]

Merge types uses the typetree data structure, to create a type tree, with types needed in the actions.

Returns:TypeTree: A type tree containing all (relevant) types.

3.12. Module contents