AERA
group.inline.cpp
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2018-2025 Jeff Thompson
7 //_/_/ Copyright (c) 2018-2025 Kristinn R. Thorisson
8 //_/_/ Copyright (c) 2018-2025 Icelandic Institute for Intelligent Machines
9 //_/_/ http://www.iiim.is
10 //_/_/
11 //_/_/ Copyright (c) 2010-2012 Eric Nivel
12 //_/_/ Center for Analysis and Design of Intelligent Agents
13 //_/_/ Reykjavik University, Menntavegur 1, 102 Reykjavik, Iceland
14 //_/_/ http://cadia.ru.is
15 //_/_/
16 //_/_/ Part of this software was developed by Eric Nivel
17 //_/_/ in the HUMANOBS EU research project, which included
18 //_/_/ the following parties:
19 //_/_/
20 //_/_/ Autonomous Systems Laboratory
21 //_/_/ Technical University of Madrid, Spain
22 //_/_/ http://www.aslab.org/
23 //_/_/
24 //_/_/ Communicative Machines
25 //_/_/ Edinburgh, United Kingdom
26 //_/_/ http://www.cmlabs.com/
27 //_/_/
28 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
29 //_/_/ University of Lugano and SUPSI, Switzerland
30 //_/_/ http://www.idsia.ch/
31 //_/_/
32 //_/_/ Institute of Cognitive Sciences and Technologies
33 //_/_/ Consiglio Nazionale delle Ricerche, Italy
34 //_/_/ http://www.istc.cnr.it/
35 //_/_/
36 //_/_/ Dipartimento di Ingegneria Informatica
37 //_/_/ University of Palermo, Italy
38 //_/_/ http://diid.unipa.it/roboticslab/
39 //_/_/
40 //_/_/
41 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
42 //_/_/
43 //_/_/ Redistribution and use in source and binary forms, with or without
44 //_/_/ modification, is permitted provided that the following conditions
45 //_/_/ are met:
46 //_/_/ - Redistributions of source code must retain the above copyright
47 //_/_/ and collaboration notice, this list of conditions and the
48 //_/_/ following disclaimer.
49 //_/_/ - Redistributions in binary form must reproduce the above copyright
50 //_/_/ notice, this list of conditions and the following disclaimer
51 //_/_/ in the documentation and/or other materials provided with
52 //_/_/ the distribution.
53 //_/_/
54 //_/_/ - Neither the name of its copyright holders nor the names of its
55 //_/_/ contributors may be used to endorse or promote products
56 //_/_/ derived from this software without specific prior
57 //_/_/ written permission.
58 //_/_/
59 //_/_/ - CADIA Clause: The license granted in and to the software
60 //_/_/ under this agreement is a limited-use license.
61 //_/_/ The software may not be used in furtherance of:
62 //_/_/ (i) intentionally causing bodily injury or severe emotional
63 //_/_/ distress to any person;
64 //_/_/ (ii) invading the personal privacy or violating the human
65 //_/_/ rights of any person; or
66 //_/_/ (iii) committing or preparing for any act of war.
67 //_/_/
68 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
69 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
70 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
71 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
73 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
74 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
75 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
76 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
78 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
79 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
81 //_/_/ OF SUCH DAMAGE.
82 //_/_/
83 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
84 
85 namespace r_exec {
86 
87 inline Group::Group(r_code::Mem *m) : LObject(m), CriticalSection() {
88 
89  reset_ctrl_values();
90  reset_stats();
91  reset_decay_values();
92 }
93 
94 inline Group::Group(r_code::SysObject *source) : LObject(source), CriticalSection() {
95 
96  reset_ctrl_values();
97  reset_stats();
98  reset_decay_values();
99 }
100 
101 inline Group::~Group() {
102 
103  invalidate();
104 }
105 
106 inline bool Group::invalidate() {
107 
108  if (LObject::invalidate())
109  return true;
110 
111  // unregister from all groups it views.
112  std::unordered_map<uint32, P<View> >::const_iterator gv;
113  for (gv = group_views_.begin(); gv != group_views_.end(); ++gv) {
114 
115  ((Group *)gv->second->object_)->enter();
116  ((Group *)gv->second->object_)->viewing_groups_.erase(this);
117  ((Group *)gv->second->object_)->leave();
118  }
119  /* We keep the group intact: the only thing is now the group will not be updated anymore.
120  // remove all views that are hosted by this group.
121  FOR_ALL_VIEWS_BEGIN(this,v)
122 
123  v->second->object->acq_views();
124  v->second->object->views_.erase(v->second); // delete view from object's views.
125  v->second->object->rel_views();
126 
127  FOR_ALL_VIEWS_END
128 
129  notification_views_.clear();
130  ipgm_views_.clear();
131  anti_ipgm_views_.clear();
132  input_less_ipgm_views_.clear();
133  other_views_.clear();
134  group_views_.clear();
135  */
136  return false;
137 }
138 
139 inline uint32 Group::get_upr() const {
140 
141  return (uint32)code(GRP_UPR).asFloat();
142 }
143 
144 inline float32 Group::get_sln_thr() const {
145 
146  return code(GRP_SLN_THR).asFloat();
147 }
148 
149 inline float32 Group::get_act_thr() const {
150 
151  return code(GRP_ACT_THR).asFloat();
152 }
153 
154 inline float32 Group::get_vis_thr() const {
155 
156  return code(GRP_VIS_THR).asFloat();
157 }
158 
159 inline float32 Group::get_c_sln_thr() const {
160 
161  return code(GRP_C_SLN_THR).asFloat();
162 }
163 
164 inline float32 Group::get_c_act_thr() const {
165 
166  return code(GRP_C_ACT_THR).asFloat();
167 }
168 
169 inline float32 Group::get_c_sln() const {
170 
171  return code(GRP_C_SLN).asFloat();
172 }
173 
174 inline float32 Group::get_c_act() const {
175 
176  return code(GRP_C_ACT).asFloat();
177 }
178 
179 inline void Group::mod_sln_thr(float32 value) {
180 
181  ++sln_thr_changes_;
182  acc_sln_thr_ += value;
183 }
184 
185 inline void Group::set_sln_thr(float32 value) {
186 
187  ++sln_thr_changes_;
188  acc_sln_thr_ += value - get_sln_thr();
189 }
190 
191 inline void Group::mod_act_thr(float32 value) {
192 
193  ++act_thr_changes_;
194  acc_act_thr_ += value;
195 }
196 
197 inline void Group::set_act_thr(float32 value) {
198 
199  ++act_thr_changes_;
200  acc_act_thr_ += value - get_act_thr();
201 }
202 
203 inline void Group::mod_vis_thr(float32 value) {
204 
205  ++vis_thr_changes_;
206  acc_vis_thr_ += value;
207 }
208 
209 inline void Group::set_vis_thr(float32 value) {
210 
211  ++vis_thr_changes_;
212  acc_vis_thr_ += value - get_vis_thr();
213 }
214 
215 inline void Group::mod_c_sln(float32 value) {
216 
217  ++c_sln_changes_;
218  acc_c_sln_ += value;
219 }
220 
221 inline void Group::set_c_sln(float32 value) {
222 
223  ++c_sln_changes_;
224  acc_c_sln_ += value - get_c_sln();
225 }
226 
227 inline void Group::mod_c_act(float32 value) {
228 
229  ++c_act_changes_;
230  acc_c_act_ += value;
231 }
232 
233 inline void Group::set_c_act(float32 value) {
234 
235  ++c_act_changes_;
236  acc_c_act_ += value - get_c_act();
237 }
238 
239 inline void Group::mod_c_sln_thr(float32 value) {
240 
241  ++c_sln_thr_changes_;
242  acc_c_sln_thr_ += value;
243 }
244 
245 inline void Group::set_c_sln_thr(float32 value) {
246 
247  ++c_sln_thr_changes_;
248  acc_c_sln_thr_ += value - get_c_sln_thr();
249 }
250 
251 inline void Group::mod_c_act_thr(float32 value) {
252 
253  ++c_act_thr_changes_;
254  acc_c_act_thr_ += value;
255 }
256 
257 inline void Group::set_c_act_thr(float32 value) {
258 
259  ++c_act_thr_changes_;
260  acc_c_act_thr_ += value - get_c_act_thr();
261 }
262 
263 inline float32 Group::get_sln_chg_thr() {
264 
265  return code(GRP_SLN_CHG_THR).asFloat();
266 }
267 
268 inline float32 Group::get_sln_chg_prd() {
269 
270  return code(GRP_SLN_CHG_PRD).asFloat();
271 }
272 
273 inline float32 Group::get_act_chg_thr() {
274 
275  return code(GRP_ACT_CHG_THR).asFloat();
276 }
277 
278 inline float32 Group::get_act_chg_prd() {
279 
280  return code(GRP_ACT_CHG_PRD).asFloat();
281 }
282 
283 inline float32 Group::get_avg_sln() {
284 
285  return code(GRP_AVG_SLN).asFloat();
286 }
287 
288 inline float32 Group::get_high_sln() {
289 
290  return code(GRP_HIGH_SLN).asFloat();
291 }
292 
293 inline float32 Group::get_low_sln() {
294 
295  return code(GRP_LOW_SLN).asFloat();
296 }
297 
298 inline float32 Group::get_avg_act() {
299 
300  return code(GRP_AVG_ACT).asFloat();
301 }
302 
303 inline float32 Group::get_high_act() {
304 
305  return code(GRP_HIGH_ACT).asFloat();
306 }
307 
308 inline float32 Group::get_low_act() {
309 
310  return code(GRP_LOW_ACT).asFloat();
311 }
312 
313 inline float32 Group::get_high_sln_thr() {
314 
315  return code(GRP_HIGH_SLN_THR).asFloat();
316 }
317 
318 inline float32 Group::get_low_sln_thr() {
319 
320  return code(GRP_LOW_SLN_THR).asFloat();
321 }
322 
323 inline float32 Group::get_sln_ntf_prd() {
324 
325  return code(GRP_SLN_NTF_PRD).asFloat();
326 }
327 
328 inline float32 Group::get_high_act_thr() {
329 
330  return code(GRP_HIGH_ACT_THR).asFloat();
331 }
332 
333 inline float32 Group::get_low_act_thr() {
334 
335  return code(GRP_LOW_ACT_THR).asFloat();
336 }
337 
338 inline float32 Group::get_act_ntf_prd() {
339 
340  return code(GRP_ACT_NTF_PRD).asFloat();
341 }
342 
343 inline float32 Group::get_low_res_thr() {
344 
345  return code(GRP_LOW_RES_THR).asFloat();
346 }
347 
348 inline float32 Group::get_ntf_new() {
349 
350  return code(GRP_NTF_NEW).asFloat();
351 }
352 
353 inline uint16 Group::get_ntf_grp_count() {
354 
355  return code(code(GRP_NTF_GRPS).asIndex()).getAtomCount();
356 }
357 
358 inline Group *Group::get_ntf_grp(uint16 i) {
359 
360  if (code(code(GRP_NTF_GRPS).asIndex() + i).readsAsNil())
361  return this;
362 
363  uint16 index = code(code(GRP_NTF_GRPS).asIndex() + i).asIndex();
364  return (Group *)get_reference(index);
365 }
366 
367 inline void Group::_mod_0_positive(uint16 member_index, float32 value) {
368 
369  float32 v = code(member_index).asFloat() + value;
370  if (v < 0)
371  v = 0;
372  code(member_index) = Atom::Float(v);
373 }
374 
375 inline void Group::_mod_0_plus1(uint16 member_index, float32 value) {
376 
377  float32 v = code(member_index).asFloat() + value;
378  if (v < 0)
379  v = 0;
380  else if (v > 1)
381  v = 1;
382  code(member_index) = Atom::Float(v);
383 }
384 
385 inline void Group::_mod_minus1_plus1(uint16 member_index, float32 value) {
386 
387  float32 v = code(member_index).asFloat() + value;
388  if (v < -1)
389  v = -1;
390  else if (v > 1)
391  v = 1;
392  code(member_index) = Atom::Float(v);
393 }
394 
395 inline void Group::_set_0_positive(uint16 member_index, float32 value) {
396 
397  if (value < 0)
398  code(member_index) = Atom::Float(0);
399  else
400  code(member_index) = Atom::Float(value);
401 }
402 
403 inline void Group::_set_0_plus1(uint16 member_index, float32 value) {
404 
405  if (value < 0)
406  code(member_index) = Atom::Float(0);
407  else if (value > 1)
408  code(member_index) = Atom::Float(1);
409  else
410  code(member_index) = Atom::Float(value);
411 }
412 
413 inline void Group::_set_minus1_plus1(uint16 member_index, float32 value) {
414 
415  if (value < -1)
416  code(member_index) = Atom::Float(-1);
417  else if (value > 1)
418  code(member_index) = Atom::Float(1);
419  else
420  code(member_index) = Atom::Float(value);
421 }
422 
423 inline void Group::_set_0_1(uint16 member_index, float32 value) {
424 
425  if (value == 0 || value == 1)
426  code(member_index) = Atom::Float(value);
427 }
428 
429 inline void Group::mod(uint16 member_index, float32 value) {
430 
431  switch (member_index) {
432  case GRP_UPR:
433  case GRP_DCY_PRD:
434  case GRP_SLN_CHG_PRD:
435  case GRP_ACT_CHG_PRD:
436  case GRP_SLN_NTF_PRD:
437  case GRP_ACT_NTF_PRD:
438  _mod_0_positive(member_index, value);
439  return;
440  case GRP_SLN_THR:
441  mod_sln_thr(value);
442  return;
443  case GRP_ACT_THR:
444  mod_act_thr(value);
445  return;
446  case GRP_VIS_THR:
447  mod_vis_thr(value);
448  return;
449  case GRP_C_SLN:
450  mod_c_sln(value);
451  return;
452  case GRP_C_SLN_THR:
453  mod_c_sln_thr(value);
454  return;
455  case GRP_C_ACT:
456  mod_c_act(value);
457  return;
458  case GRP_C_ACT_THR:
459  mod_c_act_thr(value);
460  return;
461  case GRP_DCY_PER:
462  _mod_minus1_plus1(member_index, value);
463  return;
464  case GRP_SLN_CHG_THR:
465  case GRP_ACT_CHG_THR:
466  case GRP_HIGH_SLN_THR:
467  case GRP_LOW_SLN_THR:
468  case GRP_HIGH_ACT_THR:
469  case GRP_LOW_ACT_THR:
470  case GRP_LOW_RES_THR:
471  _mod_0_plus1(member_index, value);
472  return;
473  }
474 }
475 
476 inline void Group::set(uint16 member_index, float32 value) {
477 
478  switch (member_index) {
479  case GRP_UPR:
480  case GRP_DCY_PRD:
481  case GRP_SLN_CHG_PRD:
482  case GRP_ACT_CHG_PRD:
483  case GRP_SLN_NTF_PRD:
484  case GRP_ACT_NTF_PRD:
485  _set_0_positive(member_index, value);
486  return;
487  case GRP_SLN_THR:
488  set_sln_thr(value);
489  return;
490  case GRP_ACT_THR:
491  set_act_thr(value);
492  return;
493  case GRP_VIS_THR:
494  set_vis_thr(value);
495  return;
496  case GRP_C_SLN:
497  set_c_sln(value);
498  return;
499  case GRP_C_SLN_THR:
500  set_c_sln_thr(value);
501  return;
502  case GRP_C_ACT:
503  set_c_act(value);
504  return;
505  case GRP_C_ACT_THR:
506  set_c_act_thr(value);
507  return;
508  case GRP_DCY_PER:
509  _set_minus1_plus1(member_index, value);
510  return;
511  case GRP_SLN_CHG_THR:
512  case GRP_ACT_CHG_THR:
513  case GRP_HIGH_SLN_THR:
514  case GRP_LOW_SLN_THR:
515  case GRP_HIGH_ACT_THR:
516  case GRP_LOW_ACT_THR:
517  case GRP_LOW_RES_THR:
518  _set_0_plus1(member_index, value);
519  return;
520  case GRP_NTF_NEW:
521  case GRP_DCY_TGT:
522  case GRP_DCY_AUTO:
523  _set_0_1(member_index, value);
524  return;
525  }
526 }
527 }
r_code::SysObject
Definition: r_code/object.h:136
r_code::Mem
Definition: r_code/object.h:420