Fawkes API  Fawkes Development Version
stn.h
1 
2 /***************************************************************************
3  * stn.h - stn-generator
4  *
5  * Created: Sat May 6 20:16:21 2017
6  * Copyright 2017 Matthias Loebach
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef PLUGINS_STN_H_
23 #define PLUGINS_STN_H_
24 
25 #include "domain_action.h"
26 #include "stn_action.h"
27 
28 #include <aspect/logging.h>
29 #include <graphviz/gvc.h>
30 #include <mongo/client/dbclient.h>
31 #include <pddl_parser/pddl_ast.h>
32 
33 #include <algorithm>
34 #include <iterator>
35 #include <string>
36 #include <vector>
37 
38 namespace fawkes {
39 namespace stn {
40 
41 class Stn
42 {
43 public:
44  Stn(fawkes::Logger *logger);
45  Stn(fawkes::Logger *logger, const std::string &classic_dom_path);
46  virtual ~Stn();
47 
48  void add_plan_action(const std::string &name, const std::string &params);
49  void set_initial_state(const StnAction &action);
50  void read_initial_state(const std::string &pddl_problem_string);
51  void set_pddl_domain(const std::string &pddl_domain_string);
52  void generate();
53  void drawGraph();
54  std::vector<mongo::BSONObj> get_bson();
55 
56 private:
57  struct plan_action
58  {
59  std::string name;
60  std::string params;
61  };
62 
63  fawkes::Logger *logger_;
64  bool gen_classic_dom_ = false;
65  std::string classic_dom_path_;
66  StnAction initial_state_;
67 
68  std::vector<DomainAction> domain_actions_;
69  std::vector<plan_action> plan_actions_;
70  std::vector<StnAction> stn_actions_;
71 
72  std::vector<std::pair<StnAction, StnAction>> cond_edges_;
73  std::vector<std::pair<StnAction, StnAction>> temp_edges_;
74 
75  enum LogLevel { WARN, INFO, DEBUG };
76  void log_warn(const std::string &s);
77  void log_info(const std::string &s);
78  void log_debug(const std::string &s);
79  void log(const std::string &s, Stn::LogLevel log_leve);
80  StnAction findActionById(size_t id);
81  void add_domain_action(const DomainAction &action);
82  void build_pred_list(pddl_parser::Expression e, std::vector<Predicate> *preconds, bool condition);
83  void build_breakup_list(pddl_parser::Expression e, std::vector<std::string> *breakups);
84  void generate_classic_pddl_domain(pddl_parser::Domain *dom, const std::string &classic_dom_path);
85  void output_pred_list(pddl_parser::Expression e, std::ofstream &out);
86 };
87 
88 } // namespace stn
89 } // namespace fawkes
90 
91 #endif
void read_initial_state(const std::string &pddl_problem_string)
Read the initial state from the given PDDL problem.
Definition: stn.cpp:93
A Simple Temporal Network.
Definition: stn.h:41
Fawkes library namespace.
void generate()
Regenerate the STN.
Definition: stn.cpp:208
virtual ~Stn()
Destructor.
Definition: stn.cpp:55
Stn(fawkes::Logger *logger)
Constructor.
Definition: stn.cpp:40
void set_initial_state(const StnAction &action)
Set the initial state.
Definition: stn.cpp:84
void add_plan_action(const std::string &name, const std::string &params)
Add a (grounded action).
Definition: stn.cpp:73
void set_pddl_domain(const std::string &pddl_domain_string)
Set the domain of the STN to the given PDDL domain.
Definition: stn.cpp:126
A representation of an action used by the STN generator.
Definition: domain_action.h:39
std::vector< mongo::BSONObj > get_bson()
Get a BSON representation of the STN.
Definition: stn.cpp:360
void drawGraph()
Render a graph representation of the STN.
Definition: stn.cpp:302
An action representation within an STN.
Definition: stn_action.h:40
A structured representation of a PDDL domain.
Definition: pddl_ast.h:98
Interface for logging.
Definition: logger.h:41