6#include <boost/serialization/export.hpp>
7#include "../Global/SimulationContext.h"
8#include <boost/archive/binary_oarchive.hpp>
9#include <boost/archive/binary_iarchive.hpp>
10BOOST_CLASS_EXPORT_IMPLEMENT(
KB)
44 bool got_operator =
true;
51 file_name +=
"KB_ODM_HardWired_Diagnosis.txt";
54 file_name +=
"KB_OCT_HardWired_Diagnosis.txt";
57 file_name +=
"KB_OAT_HardWired_Diagnosis.txt";
59 ofstream fout(
"err messages.txt", ios::app);
60 cout <<
"KB::readHardWiredDiagnosis: " << _operator <<
" is not one of the three operators." << endl;
61 fout <<
r5pars_.timesno <<
" KB::readHardWiredDiagnosis: " << _operator <<
" is not one of the three operators.\n";
70 ifstream fin(file_name.c_str(), ios::in);
72 cout <<
"File: " << file_name <<
" cound not be found" << endl;
73 ofstream fout(
"err messages.txt", ios::app);
74 fout <<
r5pars_.timesno <<
" File: " << file_name <<
" cound not be found\n";
80 fin >> str >> n_diagnosis;
81 for (i = 0; i < n_diagnosis; i++) {
82 auto hwu_pt = make_unique<KBHardWiredUnit>();
83 hwu_pt->readInfoFromFile(fin);
89 mental_belief_itr++) {
91 auto mental_belief_sp = make_shared<ExpectedMentalBelief>();
92 mental_belief_sp->setInfoName(mental_belief_itr->get()->getInfoName());
93 mental_belief_sp->setStateOfActivation(
sim::None);
104 string str, file_name;
106 bool got_operator =
true;
110 file_name +=
"KB_ODM_Bias_Factors.txt";
113 file_name +=
"KB_OCT_Bias_Factors.txt";
116 file_name +=
"KB_OAT_Bias_Factors.txt";
118 ofstream fout(
"err messages.txt", ios::app);
119 cout <<
"KB::readIndicatorBiasFactors: " << _operator <<
" is not one of the three operators." << endl;
120 fout <<
r5pars_.timesno <<
" KB::readIndicatorBiasFactors: " << _operator
121 <<
" is not one of the three operators.\n";
126 got_operator =
false;
129 ifstream fin(file_name.c_str(), ios::in);
130 if (!fin.is_open()) {
131 cout <<
"File: " << file_name <<
" cound not be found" << endl;
132 ofstream fout(
"err messages.txt", ios::app);
133 fout <<
r5pars_.timesno <<
" File: " << file_name <<
" cound not be found\n";
139 fin >> str >> n_bias_factors;
140 for (
int i = 0; i < n_bias_factors; i++) {
141 auto bf_pt = make_unique<KBBiasFactorUnit>();
142 bf_pt->readKBBiasFactorUnit(fin);
154 int number_of_functions, function_id;
155 bool instruction_finished =
false;
156 bool got_operator =
true;
165 file_name +=
"KB_ODM_System_Decomposition.txt";
168 file_name +=
"KB_OCT_System_Decomposition.txt";
171 file_name +=
"KB_OAT_System_Decomposition.txt";
173 ofstream fout(
"err messages.txt", ios::app);
174 cout <<
"KB::readSystemDecompositionKB: " << _operator <<
" is not one of the three operators." << endl;
175 fout <<
r5pars_.timesno <<
" KB::readSystemDecompositionKB: " << _operator
176 <<
" is not one of the three operators.\n";
181 got_operator =
false;
185 ifstream fin(file_name.c_str(), ios::in);
186 if (!fin.is_open()) {
187 cout <<
"File: " << file_name <<
" cound not be found" << endl;
188 ofstream fout(
"err messages.txt", ios::app);
189 fout <<
r5pars_.timesno <<
" File: " << file_name <<
" cound not be found\n";
195 while (!instruction_finished) {
199 if (i >= 2) instruction_finished =
true;
202 fin >> str >> number_of_functions;
203 for (
int i = 0; i < number_of_functions; i++) {
204 fin >> str >> function_id;
210 auto sdu_upt = make_unique<KBSystemDecompositionUnit>();
211 sdu_upt->setInfoName(str);
212 sdu_upt->readInfoFromFileIntegrated(fin);
220 sdu_pt = sdu_itr->get();
227 hw_ptr->checkForControl(_name, _value);
232 hw_ptr->checkForMentalBelief(_name, _state);
237 hw_ptr->checkForProcedureActivity(_name, _state);
242 hw_ptr->checkForAlarmState(_alarm_name, _alarm_state);
247 hw_ptr->checkForComponentState(_comp_name, _comp_state);
252 hw_ptr->checkForSupportSystemState(_ss_name, _ss_state);
257 hw_ptr->checkForParameterValue(_par_name, _par_value, _operator);
262 hw_ptr->checkForParameterTrend(_par_name, _par_trend);
267 auto hwd_pt = make_unique<KBHardWiredUnit>();
268 hwd_pt->copyKBHardWiredUnit(*src);
272 auto bf_pt = make_unique<KBBiasFactorUnit>();
273 bf_pt->copyKBBiasFactorUnit(*src);
277 auto sd_pt = make_unique<KBSystemDecompositionUnit>();
278 sd_pt->copyKBSystemDecompositionUnit(*src);
279 auto* raw = sd_pt.get();
289 auto hwd_pt = make_unique<KBHardWiredUnit>();
290 hwd_pt->copyKBHardWiredUnit(*src);
294 auto bf_pt = make_unique<KBBiasFactorUnit>();
295 bf_pt->copyKBBiasFactorUnit(*src);
299 auto sd_pt = make_unique<KBSystemDecompositionUnit>();
300 sd_pt->copyKBSystemDecompositionUnit(*src);
301 auto* raw = sd_pt.get();
320 str += hwu->getInfoName();
326 fout <<
"\tConfidence_%";
331 hwd->calculateConfidenceLevel();
336 string procedure_name =
"NONE";
339 if ((*hwd_itr)->getInfoName() == _diagnosis) {
341 procedure_name = (*hwd_itr)->getProcedureName();
346 ofstream fout(
"err messages.txt", ios::app);
347 cout <<
"KB::getProcedureNameOfHWDiagnosis: could not find Diagnosis: " << _diagnosis
348 <<
" from Hard Wired Diagnosis list" << endl;
349 fout <<
r5pars_.timesno <<
" KB::getProcedureNameOfHWDiagnosis: could not find Diagnosis: " << _diagnosis
350 <<
" from Hard Wired Diagnosis list\n";
356 return procedure_name;
360 string step_name =
"NONE";
363 if ((*hwd_itr)->getInfoName() == _diagnosis) {
365 step_name = (*hwd_itr)->getStepName();
370 ofstream fout(
"err messages.txt", ios::app);
371 cout <<
"KB::getProcedureNameOfHWDiagnosis: could not find Diagnosis: " << _diagnosis
372 <<
" from Hard Wired Diagnosis list" << endl;
373 fout <<
r5pars_.timesno <<
" KB::getProcedureNameOfHWDiagnosis: could not find Diagnosis: " << _diagnosis
374 <<
" from Hard Wired Diagnosis list\n";
384 map<int, string>::iterator sfm_itr;
385 string function =
"NONE";
388 function = sfm_itr->second;
390 ofstream fout(
"err messages.txt", ios::app);
391 cout <<
"KB::getAssociatedFunctionalDecompositionName: could not find function: " << _function_id
392 <<
" in System Decomposition" << endl;
393 fout <<
r5pars_.timesno <<
" KB::getAssociatedFunctionalDecompositionName: could not find function: "
394 << _function_id <<
" in System Decomposition\n";
405 if ((*hwd_itr)->getInfoName() == _diagnosis) {
407 diagnosis_ptr = hwd_itr->get();
412 ofstream fout(
"err messages.txt", ios::app);
413 cout <<
r5pars_.timesno <<
" KB::getPtrToHardWiredDiagnosis: could not find Diagnosis: " << _diagnosis
414 <<
" from Hard Wired Diagnosis list" << endl;
415 fout <<
r5pars_.timesno <<
" KB::getPtrToHardWiredDiagnosis: could not find Diagnosis: " << _diagnosis
416 <<
" from Hard Wired Diagnosis list\n";
419 return diagnosis_ptr;
424 double confidence = 0.0;
427 if ((*hwd_itr)->getInfoName() == _diagnosis) {
429 confidence = (*hwd_itr)->getConfidenceLevel();
434 ofstream fout(
"err messages.txt", ios::app);
435 cout <<
"KB::getConfidenceLevelOfHWDiagnosis: could not find Diagnosis: " << _diagnosis
436 <<
" from Hard Wired Diagnosis list" << endl;
437 fout <<
r5pars_.timesno <<
" KB::getConfidenceLevelOfHWDiagnosis: could not find Diagnosis: " << _diagnosis
438 <<
" from Hard Wired Diagnosis list\n";
445 map<int, string>::iterator sfm_itr;
448 fout <<
"KB\n" << num <<
'\n';
449 for (i = 0; i < num; i++) {
453 fout <<
"IndicatorBiasFactors " << num <<
'\n';
454 for (i = 0; i < num; i++) {
458 fout <<
"SystemDecomposition " << num <<
'\n';
459 for (i = 0; i < num; i++) {
464 fout << sfm_itr->first <<
' ' << sfm_itr->second <<
'\n';
468 int i, num, function_id;
469 string str, function;
472 ofstream fout(
"err messages.txt", ios::app);
473 cout <<
"KB::retrieveKBFromFile File retrieval error in previous function" << endl;
474 fout <<
r5pars_.timesno <<
" KB::retrieveKBFromFile File retrieval error in previous function\n";
481 for (i = 0; i < num; i++) {
482 auto hwd_pt = make_unique<KBHardWiredUnit>();
483 hwd_pt->retrieveKBHardWiredUnitFromFile(fin);
487 if (str !=
"IndicatorBiasFactors") {
488 ofstream fout(
"err messages.txt", ios::app);
489 cout <<
"KB::retrieveKBFromFile File retrieval error in KBHardWiredUnit" << endl;
490 fout <<
r5pars_.timesno <<
" KB::retrieveKBFromFile File retrieval error in KBHardWiredUnit\n";
497 for (i = 0; i < num; i++) {
498 auto bf_pt = make_unique<KBBiasFactorUnit>();
499 bf_pt->retrieveKBBiasFactorUnitFromFile(fin);
503 if (str !=
"SystemDecomposition") {
504 ofstream fout(
"err messages.txt", ios::app);
505 cout <<
"KB::retrieveKBFromFile File retrieval errir in KBHardWiredUnit" << endl;
506 fout <<
r5pars_.timesno <<
" KB::retrieveKBFromFile File retrieval errir in KBHardWiredUnit\n";
513 for (i = 0; i < num; i++) {
514 auto sd_pt = make_unique<KBSystemDecompositionUnit>();
515 sd_pt->retrieveKBSystemDecompositionUnitFromFile(fin);
523 for (i = 0; i < num; i++) {
524 fin >> function_id >> function;
531#include <boost/archive/binary_oarchive.hpp>
532#include <boost/archive/binary_iarchive.hpp>
538 ar << n_hw << n_bias;
544 uint32_t n_hw = 0, n_bias = 0;
545 ar >> n_hw >> n_bias;
547 throw std::runtime_error(
"KB state overlay: unit counts mismatch against the seeded KB");
Knowledge Base — long-term knowledge about plant systems, components, and procedures.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
std::vector< std::shared_ptr< ExpectedMentalBelief > > mental_belief
std::string getInfoName()
void readHardWiredDiagnosis(int, InfoChunk &)
void outputHardWiredDiagnosisLabelToFile(std::string, std::ofstream &)
void KBcheckHardWiredMatchForControl(std::string, double)
void initiationForSimulation(int, InfoChunk &)
void readSystemDecompositionKB(int)
void KBcheckHardWiredMatchForProcedureActivity(std::string, int)
void retrieveKBFromFile(std::ifstream &)
std::map< std::string, KBSystemDecompositionUnit * > system_decomposition_map
std::string getAssociatedFunctionalDecompositionName(int)
std::map< int, std::string > system_function_map
void copyKBForRestart(KB &)
void KBcheckHardWiredMatchForParameterTrend(std::string, int)
void state_load(boost::archive::binary_iarchive &ar)
KBHardWiredUnit * getPtrToHardWiredDiagnosis(std::string)
void KBcheckHardWiredMatchForAlarmState(std::string, int)
void saveKBToFile(std::ofstream &)
void KBcheckHardWiredMatchForParameterValue(std::string, double, int)
std::vector< std::unique_ptr< KBBiasFactorUnit > > indicator_bias_factors
std::string getStepNameOfHWDiagnosis(std::string)
void KBcalculateHardWiredConfidence()
void state_save(boost::archive::binary_oarchive &ar) const
void KBcheckHardWiredMatchForComponentState(std::string, int)
void outputHardWiredDiagnosisUnitToFile(std::ofstream &)
std::string getProcedureNameOfHWDiagnosis(std::string)
void KBcheckHardWiredMatchForSupportSystemState(std::string, int)
std::vector< std::unique_ptr< KBHardWiredUnit > > hard_wired_diagnosis
double getConfidenceLevelOfHWDiagnosis(std::string)
std::vector< std::unique_ptr< KBSystemDecompositionUnit > > system_decomposition
void KBcheckHardWiredMatchForMentalBelief(std::string, int)
void readIndicatorBiasFactors(int)
std::string getOATDirectory()
std::string getOCTDirectory()
std::string getODMDirectory()
Scheduler SScheduler
Simulation scheduling, parses CLI options.
BranchRecord Branch_center
Dynamic event tree state.