← Documentation
ADS-IDAC Engine 5.0.0
KBConcept.cpp
Go to the documentation of this file.
1// KBConcept.cpp: implementation of the KBConcept class.
2//
4
5#include <iostream>
6#include <fstream>
7#include <algorithm>
8#include <math.h>
9
10#include "KBConcept.h"
11#include "../Scheduler/Scheduler.h"
12#include "../Global/TermConversions.h"
13#include "ConceptBasicUnit.h"
14#include "ConceptComposedUnit.h"
15#include "InstantiationBase.h"
16#include "../Crew/OperatorDM.h"
17#include "../Crew/OperatorAT.h"
18#include "../Global/SimulationContext.h"
19
20using namespace std;
21
22
24// Construction/Destruction
26
28{
29 m_decrease_pt = NULL;
30 m_increase_pt = NULL;
31 m_stable_pt = NULL;
32
33 m_ON_pt = NULL;
34 m_OFF_pt = NULL;
35
36 m_bigger_pt = NULL;
37 m_smaller_pt = NULL;
38 m_equal_pt = NULL;
39
40 m_turn_on_pt = NULL;
41 m_turn_off_pt = NULL;
42
43 m_open_bigger_pt = NULL;
44 m_close_smaller_pt = NULL;
45
46}
47
49{
50
51/*
52 vector<ConceptBasicUnit *> m_BasicConcept_list;
53 vector<ConceptBasicUnit *> m_BasicConcept_updated_list;
54 vector<ConceptComposedUnit *> m_ComposedConcept_list;
55 vector<ConceptComposedUnit *> m_ComposedConcept_updated_list;
56*/
57 this->m_BasicConcept_list.clear();
58 this->m_ComposedConcept_list.clear();
59 this->m_BasicConcept_updated_list.clear();
61
62/* delete this->m_stable_pt;
63 delete this->m_smaller_pt;
64 delete this->m_bigger_pt;
65 delete this->m_equal_pt;
66 delete this->m_close_smaller_pt;
67 delete this->m_open_bigger_pt;
68 delete this->m_OFF_pt;
69 delete this->m_ON_pt;
70 delete this->m_turn_off_pt;
71 delete this->m_turn_on_pt;
72 delete this->m_decrease_pt;
73 delete this->m_increase_pt;
74*/
75
76
77}
78
80{
81
82// to be modified
83 string directory, str, str1, str2, str_ID, file_name;
84 string err_mes;
85 bool found_file;
86 ifstream fin;
87 ConceptBasicUnit *ConceptBasicUnit_pt;
88 ConceptBasicUnit *ConceptBasicUnit_pt1;
89 ConceptComposedUnit *ConceptComposedUnit_pt;
90 ConceptComposedUnit *ConceptComposedUnit_pt2;
91 int i, j, n_Unit, n_type, n_member;
92
93 //get the input file directory
94 if (this->m_operator == sim::Operator::ODM)
95 {file_name = g_sim.SScheduler.getODMDirectory();
96 file_name += "RM/";
97 file_name += "KB_ODM_Concept_Base.txt";}
98 else if (this->m_operator == sim::Operator::OAT)
99 {file_name = g_sim.SScheduler.getOATDirectory();
100 file_name += "RM/";
101 file_name += "KB_OAT_Concept_Base.txt";}
102 else
103 {
104 err_mes = "could not identify the operator in KBConcept::ReadKBConceptInfoFromInputFile()";
105 this->ErrorMessage(err_mes);
106 return;
107 }
108 fin.open(file_name.c_str(), ios::in);
109 if(!fin.is_open()){//the file contains the list of Calculation Aid cannot be found
110 err_mes = "File: " + file_name + " cound not be found";
111 this->ErrorMessage(err_mes);
112 return;
113 }
114 else{
115
116 //start to read information from the input file
117 found_file = true;
118 fin >> str >> n_Unit; //read the basic concept unit
119 for (i = 0; i < n_Unit; i++){
120 fin >> str1 >> str2 >> n_type;
122 ConceptBasicUnit_pt1 = checkExistanceOfConceptBasicUnit(str1);
123 if (ConceptBasicUnit_pt1 != NULL)
124 {
125 err_mes = str1 + " already existed";
126 this->ErrorMessage(err_mes);
127 return;}
128 else
129 {
130 auto basic_owned = std::make_unique<ConceptBasicUnit>();
131 basic_owned->m_ID = str1;
132 basic_owned->m_content = str2;
133 basic_owned->m_concept_type = n_type;
134 m_BasicConcept_list.push_back(std::move(basic_owned));
135 }
136 }
137
138 //read the composed concept unit
139 fin >> str >> n_Unit;
140 //add comparison
141 if(str.compare("No_of_Composed_Concept") != 0)
142 {
143 err_mes = "format error at No_of_Composed_Concept";
144 this->ErrorMessage(err_mes);
145 }
146 for (i = 0; i < n_Unit; i++)
147 {
148 //Check whether there is a same ID existing
149 fin >> str_ID;
150 ConceptBasicUnit_pt = this->checkExistanceOfConceptBasicUnit(str_ID);
151 ConceptComposedUnit_pt = this->checkExistanceOfConceptComposedUnit(str_ID);
152 if ((ConceptBasicUnit_pt != NULL) || (ConceptComposedUnit_pt != NULL))
153 {
154 err_mes = str_ID + " Already Existed " + "Error location: KBConcept::ReadKBConceptInfoFromInputFile";
155 this->ErrorMessage(err_mes);
156 return;
157 }
158 auto composed_owned = std::make_unique<ConceptComposedUnit>();
159 ConceptComposedUnit_pt = composed_owned.get();
160 ConceptComposedUnit_pt->m_ID = str_ID;
161
162 // caution: it can be either a basic concept ID or a composed concept ID
163 fin >> str;
164 ConceptComposedUnit_pt->m_CoreID_pt = this->FindConceptByID(str);
165 if(ConceptComposedUnit_pt->m_CoreID_pt == NULL)
166 {
167 err_mes = "Core concept of " + str_ID + ":" + str + " does not exist";
168 this->ErrorMessage(err_mes);
169 return;
170 }
171
172 //More specification concept added
173 fin >> n_member;
174 for (j = 0; j < n_member; j++){
175 fin >> str;
176 ConceptBasicUnit_pt = this->checkExistanceOfConceptBasicUnit(str);
177 if(ConceptBasicUnit_pt != 0)
178 {
179 ConceptComposedUnit_pt->m_Spec_array.push_back((IDElement*)ConceptBasicUnit_pt);
180 }
181 else
182 {
183 ConceptComposedUnit_pt2 = this->checkExistanceOfConceptComposedUnit(str);
184 if (ConceptComposedUnit_pt2 == NULL)
185 {
186 err_mes = "specification concept of " + str_ID + ":" + str + " does not exist";
187 this->ErrorMessage(err_mes);
188 return;
189 }
190 else{
191 ConceptComposedUnit_pt->m_Spec_array.push_back((IDElement*)ConceptComposedUnit_pt2);
192 }
193 }
194 }
195 this->m_ComposedConcept_list.push_back(std::move(composed_owned));
196 }
197 fin.close();
198 }
199}
200
202{
203 for (auto &e : m_BasicConcept_list)
204 {
205 if (e->m_ID == _ID)
206 return e.get();
207 }
208 return nullptr;
209}
210
212{
213 for (auto &e : m_ComposedConcept_list)
214 {
215 if (e->m_ID == _ID)
216 return e.get();
217 }
218 return nullptr;
219}
220
222{
223 if (this->m_increase_pt == 0)
224 {
225 this->m_increase_pt = this->FindConceptByID("increase");
226 }
227 if(this->m_increase_pt ==0)
228 {}//add error message
229 return this->m_increase_pt;
230}
231
233{
234 if (this->m_decrease_pt == 0)
235 {
236 this->m_decrease_pt = this->FindConceptByID("decrease");
237 }
238 if(this->m_decrease_pt ==0)
239 {}//add error message
240 return this->m_decrease_pt;
241}
242
244{
245 //if(r5pars_.timesno > 9)
246 //{this->ErrorMessage("test");}
247 if (this->m_stable_pt == NULL)
248 {
249 this->m_stable_pt = this->FindConceptByID("stable");
250 }
251 if(this->m_stable_pt == NULL)
252 {
253 this->ErrorMessage("this->m_stable_pt == NULL");
254 }//add error message
255 return this->m_stable_pt;
256}
257
259{
260 for (auto &e : this->m_BasicConcept_list)
261 {
262 if (e->m_ID == _ID)
263 return static_cast<IDElement *>(e.get());
264 }
265
266 for (auto &e : this->m_ComposedConcept_list)
267 {
268 if (e->m_ID == _ID)
269 return static_cast<IDElement *>(e.get());
270 }
271 return nullptr;
272}
273
275{
276 if (this->m_turn_on_pt == 0)
277 {
278 this->m_turn_on_pt = this->FindConceptByID("turn_on");
279 }
280 if(this->m_turn_on_pt ==0)
281 {}//add error message
282 return this->m_turn_on_pt;
283
284}
286{
287 if (this->m_turn_off_pt == 0)
288 {
289 this->m_turn_off_pt = this->FindConceptByID("turn_off");
290 }
291 if(this->m_turn_off_pt ==0)
292 {}//add error message
293 return this->m_turn_off_pt;
294
295}
296
298{
299 if (this->m_ON_pt == NULL)
300 {
301 this->m_ON_pt = this->FindConceptByID("ON");
302 }
303 if(this->m_ON_pt ==NULL)
304 {}//add error message
305 return this->m_ON_pt;
306}
307
309{
310 if (this->m_OFF_pt == 0)
311 {
312 this->m_OFF_pt = this->FindConceptByID("OFF");
313 }
314 if(this->m_OFF_pt ==0)
315 {}//add error message
316 return this->m_OFF_pt;
317}
318
320{
321 if (this->m_open_bigger_pt == 0)
322 {
323 this->m_open_bigger_pt = this->FindConceptByID("open_bigger");
324 }
325 if(this->m_open_bigger_pt ==0)
326 {}//add error message
327 return this->m_open_bigger_pt;
328}
329
331{
332 if (this->m_close_smaller_pt == 0)
333 {
334 this->m_close_smaller_pt = this->FindConceptByID("close_smaller");
335 }
336 if(this->m_close_smaller_pt ==0)
337 {}//add error message
338 return this->m_close_smaller_pt;
339}
340
342{
343 if (this->m_bigger_pt == 0)
344 {
345 this->m_bigger_pt = this->FindConceptByID(">");
346 }
347 if(this->m_bigger_pt ==0)
348 {}//add error message
349 return this->m_bigger_pt;
350}
351
353{
354 if (this->m_smaller_pt == 0)
355 {
356 this->m_smaller_pt = this->FindConceptByID("<");
357 }
358 if(this->m_smaller_pt ==0)
359 {}//add error message
360 return this->m_smaller_pt;
361}
362
364{
365 if (this->m_equal_pt == 0)
366 {
367 this->m_equal_pt = this->FindConceptByID("=");
368 }
369 if(this->m_equal_pt ==0)
370 {}//add error message
371 return this->m_equal_pt;
372}
373
374
375
377{
378 //to be added
379 vector<IDElement *> antonym_list;
380 return antonym_list;
381}
382
384{
385 //to be added
386 bool IsAntonyms=true;
387 return IsAntonyms;
388}
389
391{
392 string directory, str, str1, file_name, ID_str1, ID_str2;
393 string err_mes;
394 ifstream fin;
395 ConceptBasicUnit *ConceptB_pt1;
396 ConceptBasicUnit *ConceptB_pt2;
397 ConceptComposedUnit *ConceptC_pt1;
398 ConceptComposedUnit *ConceptC_pt2;
399 vector<string> antonym_group;
400 vector<string>::iterator str_itr1, str_itr2;
401 int i, j, n_Unit, n1;
402
403 //get the input file directory
404 if (this->m_operator == sim::Operator::ODM)
405 {file_name = g_sim.SScheduler.getODMDirectory();
406 file_name += "RM//";
407 file_name += "KB_ODM_Antonym_Base.txt";}
408 else if (this->m_operator == sim::Operator::OAT)
409 {file_name = g_sim.SScheduler.getOATDirectory();
410 file_name += "RM//";
411 file_name += "KB_OAT_Antonym_Base.txt";}
412 else
413 {
414 err_mes = "could not identify the operator in KBConcept::ReadAntonymBaseFromInputFile()";
415 this->ErrorMessage(err_mes);
416 return;
417 }
418 fin.open(file_name.c_str(), ios::in);
419 if(!fin.is_open()){//the file contains the list of Calculation Aid cannot be found
420 err_mes = "file: " + file_name + " cound not be found";
421 this->ErrorMessage(err_mes);
422 return;
423 }
424 else
425 {
426 //start to read the Antonym Base
427 fin >> str >> n_Unit;
428 for(i = 0; i<n_Unit; i++)
429 {
430 fin >> n1;
431 //read all the IDs in this group into a vector
432 antonym_group.clear();
433 for(j = 0; j < n1; j++)
434 {
435 fin >> str;
436 antonym_group.push_back(str);
437 }
438
439 for(str_itr1 = antonym_group.begin(); str_itr1 != antonym_group.end(); str_itr1++)
440 {
441 ID_str1 = *str_itr1;
442 ConceptB_pt1 = this->checkExistanceOfConceptBasicUnit(ID_str1);
443 if(ConceptB_pt1 == NULL)
444 {
445 err_mes = "Could not find" + ID_str1 + "Location: KBConcept::ReadAntonymBaseFromInputFile()";
446 this->ErrorMessage(err_mes);
447 }
448 //add the antonym list to each word
449 for(str_itr2 = antonym_group.begin(); str_itr2 != antonym_group.end(); str_itr2++)
450 {
451 ID_str2 = *str_itr2;
452 ConceptB_pt2 = this->checkExistanceOfConceptBasicUnit(ID_str2);
453 if(ConceptB_pt2 == NULL)
454 {
455 err_mes = "Could not find" + ID_str2 + "Location: KBConcept::ReadAntonymBaseFromInputFile()";
456 this->ErrorMessage(err_mes);
457 }
458 if(ID_str1 != ID_str2)
459 {
460 ConceptB_pt1->m_antonym_list.push_back((IDElement*)ConceptB_pt2);
461 }
462 }// end of for(str_itr2
463 }//end of for(str_itr1
464 }
465 }
466 fin.close();
467}
468
470{
471 ConceptBasicUnit * B_pt;
472 ConceptComposedUnit * C_pt;
473 double ratio;
474 float n;
475 for (auto B_itr = this->m_BasicConcept_updated_list.begin(); B_itr!=this->m_BasicConcept_updated_list.end(); B_itr++)
476 {
477 B_pt = *B_itr;
478 for (auto &e : this->m_ComposedConcept_list)
479 {
480 C_pt = e.get();
481 if(C_pt->CheckWhetherContainThisConceptDirectly((IDElement *)B_pt) == true)
482 {
483 n = 1 + C_pt->m_Spec_array.size();
484 ratio = pow(B_pt->m_change_ratio, float(1/n));
485 C_pt->ChangeActivationByRatio(ratio);
486 if(this->CheckExistingInConceptComposedUnitUpdateList(C_pt) == false)
487 {this->m_ComposedConcept_updated_list.push_back(C_pt);}
488 }
489 }
490 }
491
492}
493
494//DEL void KBConcept::PropagateActivationFromComposedConceptToBasicConcept()
495//DEL {
496//DEL
497//DEL }
498
500{
501 for (auto &e : this->m_BasicConcept_list)
502 {
503 e->ActivationDecay(_lamda);
504 }
505
506 for (auto &e : this->m_ComposedConcept_list)
507 {
508 e->ActivationDecay(_lamda);
509 }
510}
511
513{
514 //known limitation of this subroutine: if a->b, a->c, b->c, activation propagating from c might be double counted.
515 ConceptComposedUnit * C_pt1;
516 ConceptComposedUnit * C_pt2;
517 float ratio;
518 float n;
519 auto C_itr1 = this->m_ComposedConcept_updated_list.begin();
520 while(C_itr1 != this->m_ComposedConcept_updated_list.end())
521 {
522 C_pt1 = *C_itr1;
523 for (auto &e : this->m_ComposedConcept_list)
524 {
525 C_pt2 = e.get();
526 if(C_pt2->CheckWhetherContainThisConceptDirectly((IDElement *)C_pt1) == true)
527 {
528 //update the activation of C_pt2
529 n = 1 + C_pt2->m_Spec_array.size();
530 ratio = pow(C_pt1->m_change_ratio, float(1/n));
531 C_pt2->ChangeActivationByRatio(ratio);
532 if(this->CheckExistingInConceptComposedUnitUpdateList(C_pt2) == false)
533 {this->m_ComposedConcept_updated_list.push_back(C_pt2);}
534 }
535 }
536 //finish propagation from C_pt1
537 C_itr1= this->m_ComposedConcept_updated_list.begin();
538 (*C_itr1)->ResetChangeRatio();
539 this->m_ComposedConcept_updated_list.erase(C_itr1);
540 }
541}
542
544{
545 ConceptComposedUnit * C_pt;
546 IDElement * ID_pt;
547 vector<ConceptComposedUnit *>::iterator C_itr;
548 vector<IDElement *>::iterator ID_itr;
549 float n;
550 double ratio1, ratio2;
551
552 //for(C_itr = this->m_ComposedConcept_updated_list.begin(); C_itr != this->m_ComposedConcept_updated_list.end(); C_itr++)
553 while(this->m_ComposedConcept_updated_list.size() != 0)
554 {
555 C_itr = this->m_ComposedConcept_updated_list.begin();
556 C_pt = *C_itr;
557 n = 1 +C_pt->m_Spec_array.size();
558 ratio1 = C_pt->m_change_ratio;
559 ratio2 = pow(ratio1, float(1/n));
560 ID_pt = C_pt->m_CoreID_pt;
561 this->ChangeActivationByConceptID(ID_pt, ratio2);
562 for(ID_itr = C_pt->m_Spec_array.begin(); ID_itr != C_pt->m_Spec_array.end(); ID_itr++)
563 {
564 ID_pt = *ID_itr;
565 this->ChangeActivationByConceptID(ID_pt, ratio2);
566 }
567 C_itr = this->m_ComposedConcept_updated_list.begin();
568 (*C_itr)->ResetChangeRatio();
569 this->m_ComposedConcept_updated_list.erase(C_itr);
570 //C_itr--;
571 }
572}
573
575{
576 vector<ConceptBasicUnit *>::iterator B_itr;
577 bool exist = false;
578 for(B_itr = this->m_BasicConcept_updated_list.begin(); B_itr!= this->m_BasicConcept_updated_list.end() && exist == false; B_itr++)
579 {
580 if((*B_itr) == _B_pt)
581 {exist = true;}
582 }
583 return exist;
584}
585
587{
588 vector<ConceptComposedUnit *>::iterator C_itr;
589 bool exist = false;
590
591 for(C_itr = this->m_ComposedConcept_updated_list.begin(); C_itr != this->m_ComposedConcept_updated_list.end() && exist == false;C_itr++)
592 {
593 if((*C_itr) == _C_pt)
594 {exist = true;}
595 }
596 return exist;
597
598}
599
601{
602 ConceptBasicUnit * B_pt;
603 ConceptComposedUnit * C_pt;
604 IDElement * ID_pt;
605
606 switch (_ID_pt->m_ID_Type)
607 {
608 case 1:
609 B_pt = (ConceptBasicUnit *)_ID_pt;
610 B_pt->ChangeActivationByRatio(_ratio);
611 if(this->CheckExistingInConceptBasicUnitUpdateList(B_pt) == false)
612 {this->m_BasicConcept_updated_list.push_back(B_pt);}
613 break;
614 case 2:
615 C_pt = (ConceptComposedUnit *)_ID_pt;
616 C_pt->ChangeActivationByRatio(_ratio);
617 if(this->CheckExistingInConceptComposedUnitUpdateList(C_pt) == false)
618 {this->m_ComposedConcept_updated_list.push_back(C_pt);}
619 break;
620 default:
621 //error message
622 break;
623 }
624}
625
627{
628 // clean update list of basic concept
629 vector<ConceptBasicUnit *>::iterator B_itr;
630 B_itr = this->m_BasicConcept_updated_list.begin();
631 while( B_itr != this->m_BasicConcept_updated_list.end())
632 {
633 this->m_BasicConcept_updated_list.erase(B_itr);
634 }
635}
636
638{
639 //clean update list of composed concept
640 vector<ConceptComposedUnit *>::iterator C_itr;
641 C_itr = this->m_ComposedConcept_updated_list.begin();
642 while( C_itr != this->m_ComposedConcept_updated_list.end())
643 {
644 this->m_ComposedConcept_updated_list.erase(C_itr);
645 }
646}
647
649{
650 //reset activation change of basic concept
651 for (auto &e : this->m_BasicConcept_list)
652 {
653 e->m_change_ratio = 1;
654 }
655}
656
658{
659 //reset activation change of composed concept
660 for (auto &e : this->m_ComposedConcept_list)
661 {
662 e->m_change_ratio = 1;
663 }
664}
665
667{
672}
673
675{
676 //find out those composed concepts with activation_change bigger than 1 and push them to the list
677 this->m_ComposedConcept_updated_list.clear();
678 for (auto &e : this->m_ComposedConcept_list)
679 {
680 if(e->m_activation != e->m_old_activation)
681 {
682 e->UpdateChangeRatio();
683 this->m_ComposedConcept_updated_list.push_back(e.get());
684 }
685 }
686}
687
689{
690 cout << r5pars_.timesno << " " << str << " in KBConcept.cpp" << '\n';
691 ofstream fout("err messages.txt", ios::app);
692 fout << r5pars_.timesno << " " << str << '\n';
693 fout.close();
694 //r5pars_.terminateall = true;
695}
696
698{
699 IDElement * ID_pt = NULL;
700 ID_pt = this->checkExistanceOfConceptBasicUnit(str_ID);
701 if(ID_pt == NULL)
702 {
703 ID_pt = this->checkExistanceOfConceptComposedUnit(str_ID);
704 }
705 return ID_pt;
706}
707
709{
710 //Save the Basic concept base first
711 IDElement * ID_pt;
712 ConceptBasicUnit * BC_pt;
713 ConceptComposedUnit * CC_pt;
714 KBConceptBaseDataSetUnit * data_pt;
715
716
717 this->m_operator = _CB_pt->m_operator;
718 if(this->m_BasicConcept_list.size() != 0)
719 {
720 this->ErrorMessage("The Basic Concept List is not empty and not ready for the copy action!");
721 }
722 for (auto &e : _CB_pt->m_BasicConcept_list)
723 {
724 auto bc_owned = std::make_unique<ConceptBasicUnit>();
725 bc_owned->CopyConceptBasicUnitToRestartInfo(e.get());
726 this->m_BasicConcept_list.push_back(std::move(bc_owned));
727 }
728
729 //Save the Composed Concept Base
730
731 if(this->m_ComposedConcept_list.size() != 0)
732 {
733 this->ErrorMessage("The Composit Concept List is not empty and not ready for the copy action!");
734 }
735 for (auto &e : _CB_pt->m_ComposedConcept_list)
736 {
737 //to be continued
738 auto cc_owned = std::make_unique<ConceptComposedUnit>();
739 cc_owned->CopyInfoFromAnotherConceptComposedUnit(e.get());
740 this->m_ComposedConcept_list.push_back(std::move(cc_owned));
741 }
742
743 //copy the dataset
744 if(this->m_data_array.size() != 0)
745 {
746 this->ErrorMessage("The data array is not empty at the begining!");
747 }
748
749 for (auto &e : this->m_data_array)
750 {
751 auto data_owned = std::make_unique<KBConceptBaseDataSetUnit>();
752 data_owned->CopyFromAnotherKBConceptBaseDataSetUnit(e.get());
753 }
754}
755
756//DEL void KBConcept::MakeConnectionAmongConceptBasicConcept()
757//DEL {
758//DEL //to be added
759//DEL }
760
762{
763 vector<string >::iterator ID_itr;
764 IDElement * ID_pt;
765 ConceptBasicUnit * BC_pt;
766 ConceptComposedUnit * CC_pt;
767 ReasonMachine * RM_pt;
768
769 RM_pt = (ReasonMachine *)_RM_pt;
770
771 for (auto &e : this->m_BasicConcept_list)
772 {
773 BC_pt = e.get();
774 if(BC_pt->m_antonym_list.size() != 0)
775 {
776 this->ErrorMessage("Problem with reconstructing the antonym pointers");
777 }
778 for(ID_itr = BC_pt->m_antonym_ID_list.begin(); ID_itr != BC_pt->m_antonym_ID_list.end(); ID_itr++)
779 {
780 ID_pt = this->CheckExistanceOfConcept(*ID_itr);
781 if(ID_pt == NULL)
782 {
783 this->ErrorMessage("could not find the antonym concept " + (*ID_itr));
784 }
785 else
786 {
787 BC_pt->m_antonym_list.push_back(ID_pt);
788 }
789 }
790 }
791 //establish the pointers in the ConceptComposedUnit
792 for (auto &e : this->m_ComposedConcept_list)
793 {
794 CC_pt = e.get();
795 //establish the core concept pointer
796 ID_pt = this->CheckExistanceOfConcept(CC_pt->m_ID_core);
797 if(ID_pt == NULL)
798 {
799 this->ErrorMessage("Could not find the core concept "+ CC_pt->m_ID_core + " of " + CC_pt->m_ID);
800 }
801 else
802 {
803 CC_pt->m_CoreID_pt = ID_pt;
804 }
805 //establish the specification concept pointers;
806 for(ID_itr = CC_pt->m_ID_spec_list.begin(); ID_itr != CC_pt->m_ID_spec_list.end(); ID_itr++)
807 {
808 ID_pt = this->CheckExistanceOfConcept(*ID_itr);
809 if(ID_pt == NULL)
810 {
811 this->ErrorMessage("could not find the antonym concept " + (*ID_itr));
812 }
813 else
814 {
815 CC_pt->m_Spec_array.push_back(ID_pt);
816 }
817 }
818 //establish antonym pointers
819 if(CC_pt->m_antonym_list.size() != 0)
820 {
821 this->ErrorMessage("Problem with reconstructing the antonym pointers");
822 }
823 for(ID_itr = CC_pt->m_ID_antonym_list.begin(); ID_itr != CC_pt->m_ID_antonym_list.end(); ID_itr++)
824 {
825 ID_pt = this->CheckExistanceOfConcept(*ID_itr);
826 if(ID_pt == NULL)
827 {
828 this->ErrorMessage("could not find the antonym concept " + (*ID_itr));
829 }
830 else
831 {
832 CC_pt->m_antonym_list.push_back(ID_pt);
833 }
834 }
835 //add the indefinite concept pointer
836 if(CC_pt->m_ID_indefinite.compare("") != 0)
837 {
838 ID_pt = this->CheckExistanceOfConcept(CC_pt->m_ID_indefinite);
839 if(ID_pt == NULL)
840 {
841 this->ErrorMessage("Could not find the indefinite concept " + CC_pt->m_ID_indefinite + " for " + CC_pt->m_ID);
842 }
843 else
844 {
845 CC_pt->m_Indefinite_Concept_ID_pt = ID_pt;
846 }
847 }
848 //add the label pointer
849 if(CC_pt->m_ID_lable.compare("") != 0)
850 {
851 CC_pt->m_label_ID_pt = (IDElement *)(RM_pt->m_IB->CheckExistanceOfLabelGroupByName(CC_pt->m_ID_lable));
852 if(CC_pt->m_label_ID_pt == NULL)
853 {
854 this->ErrorMessage("Could not find the corresponding label for the concept " + CC_pt->m_ID);
855 }
856 }
857 }
858
859}
860
862{
863 for (auto &e : this->m_ComposedConcept_list)
864 {
865 e->ConvertPointerConnectionToStringForm();
866 }
867
868}
869
871{
872 vector<string>::iterator str_itr;
873 ConceptBasicUnit * cb_pt;
874 ConceptComposedUnit * cc_pt;
875 ReasonMachine * RM_pt;
876 if(this->m_operator == sim::Operator::ODM)
877 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
878 else if(this->m_operator == sim::Operator::OAT)
879 {RM_pt = g_sim.Action_Taker.m_RM.get();}
880
881 IDElement * ID_pt;
882
883 for (auto &e : this->m_BasicConcept_list)
884 {
885 cb_pt = e.get();
886 for(str_itr = cb_pt->m_antonym_ID_list.begin(); str_itr != cb_pt->m_antonym_ID_list.end(); str_itr++)
887 {
888 ID_pt = this->FindConceptByID(*str_itr);
889 if(ID_pt == NULL)
890 {this->ErrorMessage("could not find BasicConceptUnit " + *str_itr);return;}
891 cb_pt->m_antonym_list.push_back(ID_pt);
892 }
893 }
894/*
895 IDElement * m_CoreID_pt;
896 IDElement * m_label_ID_pt;
897 IDElement * m_Indefinite_Concept_ID_pt;
898
899 string m_ID_core;
900 string m_ID_indefinite;
901 string m_ID_lable;
902
903 vector<IDElement *> m_Spec_array;
904 vector<IDElement *> m_antonym_list;
905
906 vector<string> m_ID_spec_list;
907 vector<string> m_ID_antonym_list;
908*/
909 for (auto &e : this->m_ComposedConcept_list)
910 {
911 cc_pt = e.get();
912 cc_pt->m_CoreID_pt = this->FindConceptByID(cc_pt->m_ID_core);
913 if(cc_pt->m_CoreID_pt == NULL)
914 {this->ErrorMessage("could not find the core concept " + cc_pt->m_ID_core);return;}
915
916 if(cc_pt->m_ID_indefinite.compare("") != 0)
917 {
919 if(cc_pt->m_Indefinite_Concept_ID_pt == NULL)
920 {this->ErrorMessage("could not find the indefinite concept " + cc_pt->m_ID_indefinite);return;}
921 }
922
923 if(cc_pt->m_ID_lable.compare("") != 0)
924 {
925 cc_pt->m_label_ID_pt = (IDElement *)(this->FindConceptByID(cc_pt->m_ID_lable));
926 if(cc_pt->m_label_ID_pt == NULL)
927 {this->ErrorMessage("could not find the label " + cc_pt->m_ID_lable);return;}
928 }
929
930 for(str_itr = cc_pt->m_ID_antonym_list.begin(); str_itr != cc_pt->m_ID_antonym_list.end(); str_itr++)
931 {
932 ID_pt = this->FindConceptByID(*str_itr);
933 if(ID_pt == NULL)
934 {this->ErrorMessage("could not find the antonym concept " + *str_itr);return;}
935 cc_pt->m_antonym_list.push_back(ID_pt);
936 }
937
938 for(str_itr = cc_pt->m_ID_spec_list.begin(); str_itr != cc_pt->m_ID_spec_list.end(); str_itr++)
939 {
940 ID_pt = this->FindConceptByID(*str_itr);
941 if(ID_pt == NULL)
942 {this->ErrorMessage("could not find the defining concept " + *str_itr);return;}
943 cc_pt->m_Spec_array.push_back(ID_pt);
944 }
945
946 }
947}
948
950{
951 ReasonMachine * RM_pt;
952 if(this->m_operator == sim::Operator::ODM)
953 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
954 else if(this->m_operator == sim::Operator::OAT)
955 {RM_pt = g_sim.Action_Taker.m_RM.get();}
956
957 auto data_owned = std::make_unique<KBConceptBaseDataSetUnit>();
958 KBConceptBaseDataSetUnit * data_unit = data_owned.get();
959
960 //add concept activation level
961 data_unit->m_data_time = r5pars_.timesno;
962 for (auto &e : this->m_BasicConcept_list)
963 {
964 data_unit->m_value_list.push_back(e->m_activation);
965 }
966 for (auto &e : this->m_ComposedConcept_list)
967 {
968 data_unit->m_value_list.push_back(e->m_activation);
969 }
970 //add sentence activation level
971
972 this->m_data_array.push_back(std::move(data_owned));
973 for (auto &s : RM_pt->m_Semantic_list)
974 {
975 data_unit->m_value_list.push_back(s->m_activation);
976 data_unit->m_value_list.push_back(s->m_activation_baseline);
977 }
978
979}
980
982{
983 vector<float>::iterator fl_itr;
984
985 ReasonMachine * RM_pt;
986 if(this->m_operator == sim::Operator::ODM)
987 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
988 else if(this->m_operator == sim::Operator::OAT)
989 {RM_pt = g_sim.Action_Taker.m_RM.get();}
990
991 ofstream fout(_path.c_str(), ios::out);
992 fout << this->m_BasicConcept_list.size() + this->m_ComposedConcept_list.size() + 2*RM_pt->m_Semantic_list.size() + 1 << '\t';
993 fout << this->m_data_array.size() + 1 << '\n';
994
995 fout << "Time" << '\t';
996 for (auto &e : this->m_BasicConcept_list)
997 {
998 fout << e->m_ID << '\t';
999 }
1000
1001 for (auto &e : this->m_ComposedConcept_list)
1002 {
1003 fout << e->m_ID << '\t';
1004 }
1005
1006 for (auto &s : RM_pt->m_Semantic_list)
1007 {
1008 fout << s->m_ID << '\t';
1009 fout << s->m_ID + ": base_line" << '\t';
1010 }
1011
1012 fout << '\n';
1013
1014 for (auto &e : this->m_data_array)
1015 {
1016 fout << e->m_data_time << '\t';
1017 for(fl_itr = e->m_value_list.begin(); fl_itr != e->m_value_list.end(); fl_itr++)
1018 {
1019 fout << (*fl_itr) << '\t';
1020 }
1021 fout << '\n';
1022 }
1023
1024 fout.close();
1025
1026/* for(info_itr = this->m_investigation_history.begin(); info_itr != this->m_investigation_history.end(); info_itr++)
1027 {
1028 fout << (*info_itr)->m_interval_start << '\t';
1029 fout << (*info_itr)->m_interval_end << '\t';
1030 for(str_itr = (*info_itr)->m_thought_line_list.begin(); str_itr != (*info_itr)->m_thought_line_list.end(); str_itr++)
1031 {
1032 fout << (*str_itr) << '\t';
1033 }
1034 fout << '\n';
1035 }
1036
1037 */
1038}
1039
1041{
1042 for (auto &e : this->m_BasicConcept_list)
1043 {
1044 e->m_old_activation = e->m_activation;
1045 }
1046
1047 for (auto &e : this->m_ComposedConcept_list)
1048 {
1049 e->m_old_activation = e->m_activation;
1050 }
1051}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
document e
double m_change_ratio
Definition: Activation.h:19
void ChangeActivationByRatio(float)
Definition: Activation.cpp:55
std::vector< std::string > m_antonym_ID_list
std::vector< IDElement * > m_antonym_list
IDElement * m_Indefinite_Concept_ID_pt
std::vector< IDElement * > m_Spec_array
bool CheckWhetherContainThisConceptDirectly(IDElement *)
std::vector< std::string > m_ID_antonym_list
std::vector< IDElement * > m_antonym_list
std::vector< std::string > m_ID_spec_list
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
std::vector< float > m_value_list
void ActivationDecayOfConcept(double)
Definition: KBConcept.cpp:499
IDElement * getONpt()
Definition: KBConcept.cpp:297
std::vector< ConceptBasicUnit * > m_BasicConcept_updated_list
Definition: KBConcept.h:80
std::vector< IDElement * > getAntonymList(IDElement *)
Definition: KBConcept.cpp:376
void CleanConceptBasicUnitUpdateList()
Definition: KBConcept.cpp:626
IDElement * m_increase_pt
Definition: KBConcept.h:78
bool CheckExistingInConceptBasicUnitUpdateList(ConceptBasicUnit *)
Definition: KBConcept.cpp:574
void SetActivationChangeOfConceptComposedUnitsBackToOne()
Definition: KBConcept.cpp:657
IDElement * m_bigger_pt
Definition: KBConcept.h:69
int m_operator
Definition: KBConcept.h:66
void PropagateActivationFromBasicConceptToComposedConcept()
Definition: KBConcept.cpp:469
IDElement * getTurnOffPt()
Definition: KBConcept.cpp:285
std::vector< ConceptComposedUnit * > m_ComposedConcept_updated_list
Definition: KBConcept.h:82
void ReconstructThePointerLinks(void *)
Definition: KBConcept.cpp:761
void ReadKBConceptInfoFromInputFile()
Definition: KBConcept.cpp:79
void CopyStaticKBConceptFromAnother(KBConcept *)
Definition: KBConcept.cpp:708
void ConvertConnectionToStringForm()
Definition: KBConcept.cpp:861
IDElement * getDecreasePt()
Definition: KBConcept.cpp:232
std::vector< std::unique_ptr< ConceptComposedUnit > > m_ComposedConcept_list
Definition: KBConcept.h:81
virtual ~KBConcept()
Definition: KBConcept.cpp:48
void SetAllConceptActivationChangeBackToOneAndCleanTheUpdateList()
Definition: KBConcept.cpp:666
IDElement * m_close_smaller_pt
Definition: KBConcept.h:71
bool CheckExistingInConceptComposedUnitUpdateList(ConceptComposedUnit *)
Definition: KBConcept.cpp:586
bool checkWhetherAntonyms(IDElement *, IDElement *)
Definition: KBConcept.cpp:383
IDElement * m_turn_off_pt
Definition: KBConcept.h:75
void PropagateActivationAmongConceptsTopDown()
Definition: KBConcept.cpp:543
void SaveActivationToOldActivationVariable()
Definition: KBConcept.cpp:1040
void CleanConceptComposedUnitUpdateList()
Definition: KBConcept.cpp:637
ConceptComposedUnit * checkExistanceOfConceptComposedUnit(std::string)
Definition: KBConcept.cpp:211
IDElement * getTurnOnPt()
Definition: KBConcept.cpp:274
IDElement * m_ON_pt
Definition: KBConcept.h:74
IDElement * getOpenBiggerPt()
Definition: KBConcept.cpp:319
void BuidConnectionsWithinKBConcept()
Definition: KBConcept.cpp:870
IDElement * getOFFpt()
Definition: KBConcept.cpp:308
IDElement * m_decrease_pt
Definition: KBConcept.h:77
IDElement * FindConceptByID(std::string)
Definition: KBConcept.cpp:258
IDElement * m_OFF_pt
Definition: KBConcept.h:73
void AddDataSetOfTheConceptBase()
Definition: KBConcept.cpp:949
ConceptBasicUnit * checkExistanceOfConceptBasicUnit(std::string)
Definition: KBConcept.cpp:201
void SetActivationChangeOfConceptBasicUnitsBackToOne()
Definition: KBConcept.cpp:648
IDElement * m_smaller_pt
Definition: KBConcept.h:68
IDElement * getIncreasePt()
Definition: KBConcept.cpp:221
IDElement * m_open_bigger_pt
Definition: KBConcept.h:72
IDElement * getEqualPt()
Definition: KBConcept.cpp:363
void ReadAntonymBaseFromInputFile()
Definition: KBConcept.cpp:390
void PropagateActivationAmongComposedConceptBottomUp()
Definition: KBConcept.cpp:512
IDElement * m_turn_on_pt
Definition: KBConcept.h:76
IDElement * m_equal_pt
Definition: KBConcept.h:70
IDElement * getBiggerPt()
Definition: KBConcept.cpp:341
void ChangeActivationByConceptID(IDElement *, double)
Definition: KBConcept.cpp:600
IDElement * getCloseSmallerPt()
Definition: KBConcept.cpp:330
void SaveConceptActivationIntoOutputFile(std::string)
Definition: KBConcept.cpp:981
IDElement * getStablePt()
Definition: KBConcept.cpp:243
void FillTheConceptCompsedUnitUpdateList()
Definition: KBConcept.cpp:674
IDElement * CheckExistanceOfConcept(std::string)
Definition: KBConcept.cpp:697
std::vector< std::unique_ptr< KBConceptBaseDataSetUnit > > m_data_array
Definition: KBConcept.h:63
std::vector< std::unique_ptr< ConceptBasicUnit > > m_BasicConcept_list
Definition: KBConcept.h:79
void ErrorMessage(std::string)
Definition: KBConcept.cpp:688
IDElement * getSmallerPt()
Definition: KBConcept.cpp:352
IDElement * m_stable_pt
Definition: KBConcept.h:67
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
std::vector< std::unique_ptr< SentenceUnit > > m_Semantic_list
std::unique_ptr< InstantiationBase > m_IB
std::string getOATDirectory()
Definition: Scheduler.cpp:622
std::string getODMDirectory()
Definition: Scheduler.cpp:619
struct @0 r5pars_
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
Scheduler SScheduler
Simulation scheduling, parses CLI options.
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.