OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Target.h
Go to the documentation of this file.
1 /*
2  * Target.h
3  *
4  * Author: William Ma <https://github.com/williampma>
5  *
6  * Copyright (C) 2015 OpenCog Foundation
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License v3 as
10  * published by the Free Software Foundation and including the exceptions
11  * at http://opencog.org/wiki/Licenses
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program; if not, write to:
20  * Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef _OPENCOG_TARGET_H
25 #define _OPENCOG_TARGET_H
26 
28 
29 namespace opencog
30 {
31 
32 typedef std::map<Handle, UnorderedHandleSet> VarMultimap;
33 typedef std::map<Handle, Handle> VarMap;
34 
35 class Target
36 {
37  friend class TargetSet;
38 
39 public:
40 
41  ~Target() {}
42 
43  // Comparison
44  bool operator==(const Target& t) const
45  {
47  }
48  bool operator<(const Target& t) const
49  {
51  }
52 
53  void store_step(const Rule& r, const HandleSeq& premises);
54  void store_varmap(VarMultimap& vm);
55  void store_varmap(VarMap& vm);
56  unsigned int rule_count(const Rule& r);
57 
64 
70  Handle get_handle() const { return _htarget_external; }
71 
78  {
79  return VariableListCast(_vardecl)->get_variables().varseq;
80  }
81 
87  std::set<Handle> get_varset() const
88  {
89  return VariableListCast(_vardecl)->get_variables().varset;
90  }
91 
92  Handle get_vardecl() const { return _vardecl; }
93 
99  const VarMultimap& get_varmap() const { return _varmap; }
100 
101  unsigned int get_selection_count() const { return _selection_count; }
102 
111  float get_weight() { return 1.0f; }
112 
113 private:
114  Target(AtomSpace& as, const Handle& h, const Handle& hvardecl);
115 
118  unsigned int _selection_count;
119 
122 
124 };
125 
126 
128 {
129 public:
130  TargetSet();
131  ~TargetSet();
132 
133  void clear();
134  void emplace(Handle h, Handle hvardecl);
135  unsigned int size();
136  Target& select();
137  Target& get(Handle& h);
138 
139 private:
140  std::map<Handle, Target> _targets_map;
142  unsigned int _total_selection;
143 };
144 
145 }
146 
147 
148 #endif // TARGET_H
unsigned int size()
Definition: Target.cc:161
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
HandleSeq get_varseq() const
Definition: Target.h:77
Handle _vardecl
Definition: Target.h:120
float get_weight()
Definition: Target.h:111
Handle get_vardecl() const
Definition: Target.h:92
void store_varmap(VarMultimap &vm)
Definition: Target.cc:76
void emplace(Handle h, Handle hvardecl)
Definition: Target.cc:150
Handle _htarget_external
Definition: Target.h:116
VarMultimap _varmap
Definition: Target.h:121
unsigned int _selection_count
Definition: Target.h:118
Handle get_handle() const
Definition: Target.h:70
bool operator<(const Target &t) const
Definition: Target.h:48
unsigned int _total_selection
Definition: Target.h:142
void increment_selection_count()
Definition: Target.h:63
std::map< Handle, UnorderedHandleSet > VarMultimap
static VariableListPtr VariableListCast(const Handle &h)
Definition: VariableList.h:95
unsigned int rule_count(const Rule &r)
Definition: Target.cc:107
std::set< Handle > get_varset() const
Definition: Target.h:87
bool operator==(const Target &t) const
Definition: Target.h:44
std::map< Handle, Handle > VarMap
AtomSpace & _as
Definition: Target.h:123
void store_step(const Rule &r, const HandleSeq &premises)
Definition: Target.cc:61
Target(AtomSpace &as, const Handle &h, const Handle &hvardecl)
Definition: Target.cc:40
std::map< Handle, Target > _targets_map
Definition: Target.h:140
unsigned int get_selection_count() const
Definition: Target.h:101
Target & select()
Definition: Target.cc:178
Handle _htarget_internal
Definition: Target.h:117
const VarMultimap & get_varmap() const
Definition: Target.h:99
AtomSpace _history_space
Definition: Target.h:141