OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Satisfier.cc
Go to the documentation of this file.
1 /*
2  * Satisfier.cc
3  *
4  * Copyright (C) 2015 Linas Vepstas
5  *
6  * Author: Linas Vepstas <linasvepstas@gmail.com> January 2009
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 
27 
28 #include "BindLinkAPI.h"
29 #include "Satisfier.h"
30 
31 using namespace opencog;
32 
33 bool Satisfier::grounding(const std::map<Handle, Handle> &var_soln,
34  const std::map<Handle, Handle> &term_soln)
35 {
36  // PatternMatchEngine::print_solution(var_soln, term_soln);
38 
39  // Look for more groundings.
40  return false;
41 }
42 
43 bool SatisfyingSet::grounding(const std::map<Handle, Handle> &var_soln,
44  const std::map<Handle, Handle> &term_soln)
45 {
46  // PatternMatchEngine::print_solution(var_soln, term_soln);
47 
48  if (1 == _varseq.size())
49  {
50  _satisfying_set.push_back(var_soln.at(_varseq[0]));
51  return false;
52  }
53 
54  // If more than one variable, encapsulate in sequential order,
55  // in a ListLink.
56  HandleSeq vargnds;
57  for (const Handle& hv : _varseq)
58  {
59  vargnds.push_back(var_soln.at(hv));
60  }
61  _satisfying_set.push_back(Handle(createLink(LIST_LINK, vargnds)));
62 
63  // Look for more groundings.
64  return false;
65 }
66 
68 {
70  if (NULL == bl)
71  {
72  // If it is a BindLink (for example), we want to use that ctor
73  // instead of the default ctor.
74  if (classserver().isA(hlink->getType(), SATISFACTION_LINK))
75  bl = createPatternLink(*LinkCast(hlink));
76  else
77  bl = createPatternLink(hlink);
78  }
79 
80  Satisfier sater(as);
81  bl->satisfy(sater);
82 
83  return sater._result;
84 }
85 
87 {
89  if (NULL == bl)
90  {
91  // If it is a BindLink (for example), we want to use that ctor
92  // instead of the default ctor.
93  if (classserver().isA(hlink->getType(), GET_LINK))
94  bl = createPatternLink(*LinkCast(hlink));
95  else
96  bl = createPatternLink(hlink);
97  }
98 
99  SatisfyingSet sater(as);
100  bl->satisfy(sater);
101 
102  return as->add_link(SET_LINK, sater._satisfying_set);
103 }
104 
105 /* ===================== END OF FILE ===================== */
#define createLink
Definition: Link.h:269
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
HandleSeq _satisfying_set
Definition: Satisfier.h:95
static TruthValuePtr TRUE_TV()
Definition: TruthValue.cc:59
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
#define createPatternLink
Definition: PatternLink.h:188
virtual bool grounding(const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)
Definition: Satisfier.cc:43
Type getType() const
Definition: Atom.h:197
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
Definition: ClassServer.cc:159
Handle satisfying_set(AtomSpace *, const Handle &)
Definition: Satisfier.cc:86
TruthValuePtr _result
Definition: Satisfier.h:57
TruthValuePtr satisfaction_link(AtomSpace *, const Handle &)
Definition: Satisfier.cc:67
static LinkPtr LinkCast(const Handle &h)
Definition: Link.h:263
static PatternLinkPtr PatternLinkCast(const Handle &h)
Definition: PatternLink.h:182
std::shared_ptr< PatternLink > PatternLinkPtr
Definition: PatternLink.h:181
Handle add_link(Type t, const HandleSeq &outgoing, bool async=false)
Definition: AtomSpace.cc:175
virtual bool grounding(const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)
Definition: Satisfier.cc:33