OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-generate commits / 1e1c213

Avoid nameing collision with base AtomSpace
1e1c2131326fc6cf779e1aacd70a0abf0e8f24cf
by Linas Vepstas <linasvepstas@gmail.com> · 2023-01-02T19:11:26.000Z

Changed files (5) +236 -236

opencog/generate/CMakeLists.txt +9 -9
……@@ -1,14 +1,14 @@
11
22
33ADD_LIBRARY(generate SHARED
4 Aggregate
5 BasicParameters
6 CollectStyle
7 Dictionary
8 Frame
9 LinkStyle
10 RandomCallback
11 SimpleCallback
4 Aggregate.cc
5 BasicParameters.cc
6 CollectStyle.cc
7 Dictionary.cc
8 LinkStyle.cc
9 Odometer.cc
10 RandomCallback.cc
11 SimpleCallback.cc
1212)
1313
1414TARGET_LINK_LIBRARIES(generate
……@@ -25,9 +25,9 @@ INSTALL(FILES
2525 BasicParameters.h
2626 CollectStyle.h
2727 Dictionary.h
28 Frame.h
2928 GenerateCallback.h
3029 LinkStyle.h
30 Odometer.h
3131 RandomCallback.h
3232 RandomParameters.h
3333 SimpleCallback.h
opencog/generate/Frame.cc +0 -135
……@@ -1,135 +0,0 @@
1/*
2 * opencog/generate/Frame.cc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License v3 as
6 * published by the Free Software Foundation and including the exceptions
7 * at http://opencog.org/wiki/Licenses
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program; if not, write to:
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <stdio.h>
21
22#include <opencog/atoms/base/Handle.h>
23#include <opencog/atoms/base/Link.h>
24#include <opencog/atomspace/AtomSpace.h>
25
26#include "Frame.h"
27
28using namespace opencog;
29
30void Frame::clear(void)
31{
32 _open_points.clear();
33 _open_sections.clear();
34 _linkage.clear();
35 _nodo = -1;
36 _wheel = -1;
37}
38
39void Odometer::clear(void)
40{
41 _sections.clear();
42 _from_index.clear();
43 _to_connectors.clear();
44 _size = 0;
45 _step = -1;
46 _frame_depth = 0;
47}
48
49// =================================================================
50// Debug printing utilities.
51// Current printing format makes assumptions about connectors
52// which will be invalid, in general. XXX FIMXE, someday.
53
54void Frame::print_section(const Handle& section)
55{
56 logger().fine(" %s:",
57 section->getOutgoingAtom(0)->get_name().c_str());
58 const HandleSeq& conseq = section->getOutgoingAtom(1)->getOutgoingSet();
59 for (const Handle& con : conseq)
60 {
61 if (CONNECTOR == con->get_type())
62 logger().fine(" %s%s",
63 con->getOutgoingAtom(0)->get_name().c_str(),
64 con->getOutgoingAtom(1)->get_name().c_str());
65 else
66 logger().fine(" %s - %s - %s",
67 con->getOutgoingAtom(1)->getOutgoingAtom(0)->get_name().c_str(),
68 con->getOutgoingAtom(0)->get_name().c_str(),
69 con->getOutgoingAtom(1)->getOutgoingAtom(1)->get_name().c_str());
70 }
71}
72
73void Frame::print(void) const
74{
75 logger().fine("Frame:");
76 std::string pts;
77 for (const Handle& pt : _open_points)
78 pts += pt->get_name() + ", ";
79 logger().fine(" pts: %s", pts.c_str());
80
81 logger().fine(" Open:");
82 for (const Handle& open : _open_sections)
83 print_section(open);
84
85 logger().fine(" Closed:");
86 for (const Handle& lkg : _linkage)
87 print_section(lkg);
88}
89
90// =================================================================
91
92void Odometer::print_wheel(const Frame& frm, size_t i) const
93{
94 bool sect_open = true;
95 const Handle& fm_sect = _sections[i];
96 if (frm._open_sections.find(fm_sect) == frm._open_sections.end())
97 sect_open = false;
98
99 const Handle& disj = fm_sect->getOutgoingAtom(1);
100 const Handle& fm_con = disj->getOutgoingAtom(_from_index[i]);
101
102 bool conn_open = (fm_con->get_type() == CONNECTOR);
103 if (conn_open)
104 logger().fine(" wheel %lu: %s : %s\t: %s -> %s (sect %s; conn %s)",
105 i,
106 _sections[i]->getOutgoingAtom(0)->get_name().c_str(),
107 fm_con->getOutgoingAtom(0)->get_name().c_str(),
108 fm_con->getOutgoingAtom(1)->get_name().c_str(),
109 _to_connectors[i]->getOutgoingAtom(1)->get_name().c_str(),
110 sect_open ? "open" : "closed",
111 conn_open ? "open" : "closed"
112 );
113 else
114 {
115 const Handle& lnkset = fm_con->getOutgoingAtom(1);
116 logger().fine(" wheel %lu: %s : %s\t: %s -> %s (sect %s; conn %s)",
117 i,
118 _sections[i]->getOutgoingAtom(0)->get_name().c_str(),
119 fm_con->getOutgoingAtom(0)->get_name().c_str(),
120 lnkset->getOutgoingAtom(0)->get_name().c_str(),
121 lnkset->getOutgoingAtom(1)->get_name().c_str(),
122 sect_open ? "open" : "closed",
123 conn_open ? "open" : "closed"
124 );
125 }
126}
127
128void Odometer::print_odometer(const Frame& frm) const
129{
130 logger().fine("Odometer State: length %lu", _size);
131 for (size_t i=0; i<_size; i++)
132 print_wheel(frm, i);
133}
134
135// ========================== END OF FILE ==========================
opencog/generate/Frame.h +0 -92
……@@ -1,92 +0,0 @@
1/*
2 * opencog/generate/Frame.h
3 *
4 * Copyright (C) 2020 Linas Vepstas <linasvepstas@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License v3 as
8 * published by the Free Software Foundation and including the exceptions
9 * at http://opencog.org/wiki/Licenses
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program; if not, write to:
18 * Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#ifndef _OPENCOG_FRAME_H
23#define _OPENCOG_FRAME_H
24
25#include <opencog/atomspace/AtomSpace.h>
26
27namespace opencog
28{
29/** \addtogroup grp_generate
30 * @{
31 */
32
33/// Current traversal state
34struct Frame
35{
36 /// Points that are unconnected
37 HandleSet _open_points;
38
39 /// Sections with unconnected connectors.
40 HandleSet _open_sections;
41
42 /// Completed links.
43 HandleSet _linkage;
44
45 /// The depth of the odometer stack, and the odometer wheel
46 /// that this frame is isolating. State earlier than this is
47 /// in earlier frames, and later state is in later frames.
48 size_t _nodo;
49 size_t _wheel;
50
51 void clear(void);
52 void print(void) const;
53
54 static void print_section(const Handle&);
55};
56
57/// Odometer for breadth-wise aggregation
58struct Odometer
59{
60 /// Size of odometer. All vectors below are of this size.
61 size_t _size;
62
63 /// Ordered list of from-sections which have unconnected connectors
64 // that are being explored as a part of this odometer.
65 /// from-connectors.
66 HandleSeq _sections;
67
68 /// Index into the corresponding section, pointing at the open
69 /// connector (the "from-connector").
70 std::vector<size_t> _from_index;
71
72 /// List of valid connectors that each from-connector can mate to.
73 /// (That can be legally joined to a from-connector) Note there
74 /// may be multiple to-connectors for each from-connector.
75 HandleSeq _to_connectors;
76
77 /// The next wheel to be stepped. This is an index into the
78 /// above sequences.
79 size_t _step;
80
81 /// The correspoding frame-stack depth, when this odo was created.
82 size_t _frame_depth;
83
84 void clear(void);
85 void print_odometer(const Frame&) const;
86 void print_wheel(const Frame&, size_t) const;
87};
88
89/** @}*/
90} // namespace opencog
91
92#endif // _OPENCOG_FRAME_H
opencog/generate/Odometer.cc +135 -0
……@@ -0,0 +1,135 @@
1/*
2 * opencog/generate/Odometer.cc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License v3 as
6 * published by the Free Software Foundation and including the exceptions
7 * at http://opencog.org/wiki/Licenses
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program; if not, write to:
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <stdio.h>
21
22#include <opencog/atoms/base/Handle.h>
23#include <opencog/atoms/base/Link.h>
24#include <opencog/atomspace/AtomSpace.h>
25
26#include "Odometer.h"
27
28using namespace opencog;
29
30void OdoFrame::clear(void)
31{
32 _open_points.clear();
33 _open_sections.clear();
34 _linkage.clear();
35 _nodo = -1;
36 _wheel = -1;
37}
38
39void Odometer::clear(void)
40{
41 _sections.clear();
42 _from_index.clear();
43 _to_connectors.clear();
44 _size = 0;
45 _step = -1;
46 _frame_depth = 0;
47}
48
49// =================================================================
50// Debug printing utilities.
51// Current printing format makes assumptions about connectors
52// which will be invalid, in general. XXX FIMXE, someday.
53
54void OdoFrame::print_section(const Handle& section)
55{
56 logger().fine(" %s:",
57 section->getOutgoingAtom(0)->get_name().c_str());
58 const HandleSeq& conseq = section->getOutgoingAtom(1)->getOutgoingSet();
59 for (const Handle& con : conseq)
60 {
61 if (CONNECTOR == con->get_type())
62 logger().fine(" %s%s",
63 con->getOutgoingAtom(0)->get_name().c_str(),
64 con->getOutgoingAtom(1)->get_name().c_str());
65 else
66 logger().fine(" %s - %s - %s",
67 con->getOutgoingAtom(1)->getOutgoingAtom(0)->get_name().c_str(),
68 con->getOutgoingAtom(0)->get_name().c_str(),
69 con->getOutgoingAtom(1)->getOutgoingAtom(1)->get_name().c_str());
70 }
71}
72
73void OdoFrame::print(void) const
74{
75 logger().fine("OdoFrame:");
76 std::string pts;
77 for (const Handle& pt : _open_points)
78 pts += pt->get_name() + ", ";
79 logger().fine(" pts: %s", pts.c_str());
80
81 logger().fine(" Open:");
82 for (const Handle& open : _open_sections)
83 print_section(open);
84
85 logger().fine(" Closed:");
86 for (const Handle& lkg : _linkage)
87 print_section(lkg);
88}
89
90// =================================================================
91
92void Odometer::print_wheel(const OdoFrame& frm, size_t i) const
93{
94 bool sect_open = true;
95 const Handle& fm_sect = _sections[i];
96 if (frm._open_sections.find(fm_sect) == frm._open_sections.end())
97 sect_open = false;
98
99 const Handle& disj = fm_sect->getOutgoingAtom(1);
100 const Handle& fm_con = disj->getOutgoingAtom(_from_index[i]);
101
102 bool conn_open = (fm_con->get_type() == CONNECTOR);
103 if (conn_open)
104 logger().fine(" wheel %lu: %s : %s\t: %s -> %s (sect %s; conn %s)",
105 i,
106 _sections[i]->getOutgoingAtom(0)->get_name().c_str(),
107 fm_con->getOutgoingAtom(0)->get_name().c_str(),
108 fm_con->getOutgoingAtom(1)->get_name().c_str(),
109 _to_connectors[i]->getOutgoingAtom(1)->get_name().c_str(),
110 sect_open ? "open" : "closed",
111 conn_open ? "open" : "closed"
112 );
113 else
114 {
115 const Handle& lnkset = fm_con->getOutgoingAtom(1);
116 logger().fine(" wheel %lu: %s : %s\t: %s -> %s (sect %s; conn %s)",
117 i,
118 _sections[i]->getOutgoingAtom(0)->get_name().c_str(),
119 fm_con->getOutgoingAtom(0)->get_name().c_str(),
120 lnkset->getOutgoingAtom(0)->get_name().c_str(),
121 lnkset->getOutgoingAtom(1)->get_name().c_str(),
122 sect_open ? "open" : "closed",
123 conn_open ? "open" : "closed"
124 );
125 }
126}
127
128void Odometer::print_odometer(const OdoFrame& frm) const
129{
130 logger().fine("Odometer State: length %lu", _size);
131 for (size_t i=0; i<_size; i++)
132 print_wheel(frm, i);
133}
134
135// ========================== END OF FILE ==========================
opencog/generate/Odometer.h +92 -0
……@@ -0,0 +1,92 @@
1/*
2 * opencog/generate/Odometer.h
3 *
4 * Copyright (C) 2020 Linas Vepstas <linasvepstas@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License v3 as
8 * published by the Free Software Foundation and including the exceptions
9 * at http://opencog.org/wiki/Licenses
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program; if not, write to:
18 * Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#ifndef _OPENCOG_ODOMETER_H
23#define _OPENCOG_ODOMETER_H
24
25#include <opencog/atomspace/AtomSpace.h>
26
27namespace opencog
28{
29/** \addtogroup grp_generate
30 * @{
31 */
32
33/// Current traversal state
34struct OdoFrame
35{
36 /// Points that are unconnected
37 HandleSet _open_points;
38
39 /// Sections with unconnected connectors.
40 HandleSet _open_sections;
41
42 /// Completed links.
43 HandleSet _linkage;
44
45 /// The depth of the odometer stack, and the odometer wheel
46 /// that this frame is isolating. State earlier than this is
47 /// in earlier frames, and later state is in later frames.
48 size_t _nodo;
49 size_t _wheel;
50
51 void clear(void);
52 void print(void) const;
53
54 static void print_section(const Handle&);
55};
56
57/// Odometer for breadth-wise aggregation
58struct Odometer
59{
60 /// Size of odometer. All vectors below are of this size.
61 size_t _size;
62
63 /// Ordered list of from-sections which have unconnected connectors
64 // that are being explored as a part of this odometer.
65 /// from-connectors.
66 HandleSeq _sections;
67
68 /// Index into the corresponding section, pointing at the open
69 /// connector (the "from-connector").
70 std::vector<size_t> _from_index;
71
72 /// List of valid connectors that each from-connector can mate to.
73 /// (That can be legally joined to a from-connector) Note there
74 /// may be multiple to-connectors for each from-connector.
75 HandleSeq _to_connectors;
76
77 /// The next wheel to be stepped. This is an index into the
78 /// above sequences.
79 size_t _step;
80
81 /// The correspoding frame-stack depth, when this odo was created.
82 size_t _frame_depth;
83
84 void clear(void);
85 void print_odometer(const OdoFrame&) const;
86 void print_wheel(const OdoFrame&, size_t) const;
87};
88
89/** @}*/
90} // namespace opencog
91
92#endif // _OPENCOG_ODOMETER_H