← Documentation
ADS-IDAC Engine 5.0.0
TimeConstrainedModule.cpp
Go to the documentation of this file.
1// TimeConstrainedModule.cpp: implementation of the TimeConstrainedModule class.
2//
4
6#include "../Procedure/ExpectedMentalBelief.h"
7#include <boost/serialization/export.hpp>
8#include "../Global/SimulationContext.h"
9#include <boost/archive/binary_oarchive.hpp>
10#include <boost/archive/binary_iarchive.hpp>
11BOOST_CLASS_EXPORT_IMPLEMENT(TimeConstrainedModule)
12using namespace std;
13
14
16// Construction/Destruction
18
20{
22 Last_Update_Time = 0.0;
24}
25
27{
29}
30
32{
35 Last_Update_Time = 0.0;
37}
39 int goal;
40 ExpectedMentalBelief *emb_ptr = 0;
41 bool reactor_tripped = false;
42 goal = _perceived_info->getCurrentGoal();
43 //
44 // Check status of reactor (on line or tripped)
45 emb_ptr = _perceived_info->checkExistanceOfMentalBelief("Reactor_Tripped");
46 if (emb_ptr != 0 )
47 {
48 if (emb_ptr->getStateOfActivation() == sim::State::Succeed) {
49 reactor_tripped = true;
50 }
51 }
52 //
53 for(auto& item : Time_Constrained_Parameter_Array){
54 item->updateRawData(Time_Lapse_for_Update, _perceived_info);
55 item->CalculateTimeToThreshold();
56 item->CalculateTimeConstrainedUnitPIFValue(goal, reactor_tripped, this->getTimeLapseForUpdate());
57 }
58}
59
61{
62 double TCL_unit_value;
63 double new_TCL_value = 0.0;
65 {
66 Last_Update_Time = r5pars_.timesno;
67 this->updateRawDataAndCalculateTimeToThreshold(_perceived_info);
68 for(auto& item : Time_Constrained_Parameter_Array)
69 {
70 TCL_unit_value = item->getTimeConstrainedUnitPIFValue();
71 new_TCL_value = fmax(new_TCL_value,TCL_unit_value);
72 }
73 Time_Constrained_PIF_Value = new_TCL_value;
74 }
75
76}
77
79 string limiting_parameter = "NONE";
80 double max_PIF = 0.0;
81 for (auto& item : Time_Constrained_Parameter_Array){
82 if(item->getTimeConstrainedUnitPIFValue() > max_PIF) {
83 max_PIF = item->getTimeConstrainedUnitPIFValue();
84 limiting_parameter = item->getCorrespondingIndicatorName();
85 }
86 }
87 if (limiting_parameter == "NONE") {
88 max_PIF = 0.0;
89 }
90 return limiting_parameter;
91}
92
98{
99 for(auto& src : _Time_Constrained_Data.Time_Constrained_Parameter_Array)
100 {
101 auto time_constrained_unit_pt = make_unique<TimeConstrainedUnit>();
102 time_constrained_unit_pt->copyTimeConstrainedUnit(*src);
103 Time_Constrained_Parameter_Array.push_back(std::move(time_constrained_unit_pt));
104 }
106 Last_Update_Time = _Time_Constrained_Data.getLastUpdateTime();
107 Time_Lapse_for_Update = _Time_Constrained_Data.getTimeLapseForUpdate();
108}
109
113{
114 // Module used to output column headers to key parameter file
115 int i;
116 // Data Label for Control Panel Based Time Constrained Load
117 fout << '\t'<<str<<"Time_Constrained_PIF_Value";
118 for(i = 0; i < Time_Constrained_Parameter_Array.size(); i++)
119 {
120 fout << '\t' << str << Time_Constrained_Parameter_Array.at(i)->getTimeConstrainedUnitName() << "(Value)"
121 << '\t' << str << Time_Constrained_Parameter_Array.at(i)->getTimeConstrainedUnitName() << "(Rate)"
122 << '\t' << str << Time_Constrained_Parameter_Array.at(i)->getTimeConstrainedUnitName() << "(Normal)"
123 << '\t' << str << Time_Constrained_Parameter_Array.at(i)->getTimeConstrainedUnitName() << "(Accident)";
124 }
125
126}
128{
129 int i;
130 fout << "\t Range:_0-10";
131 for(i = 0; i < Time_Constrained_Parameter_Array.size(); i++){
132 fout << "\t --" << "\t --" << "\tMinutes to Threshold" << "\tMinutes to Threshold";
133 }
134
135}
137{
138 int i;
139 int num_time_constrained_parameters, num_history_data_points;
140 double lower_threshold, upper_threshold, decay_tau, buildup_tau;
141 TimeConstrainedUnit *time_constrained_array_ptr;
142 num_history_data_points = 10;
143 string str;
144 ifstream fin(_file_name.c_str(), ios::in);
145 if(!fin.is_open()){
146 cout << "File: " << _file_name << " cound not be found" << endl;
147 ofstream fout("err messages.txt", ios::app);
148 fout << r5pars_.timesno << " File: " << _file_name << " cound not be found\n";
149 fout.close();
150 }
151 else {
152 fin >> str >> num_time_constrained_parameters
153 >> str >> Time_Lapse_for_Update;
154 fin >> str >> lower_threshold;
155 fin >> str >> upper_threshold;
156 fin >> str >> decay_tau;
157 fin >> str >> buildup_tau;
158 for (i = 0; i < num_time_constrained_parameters; i++){
159 auto time_constrained_array_ptr = make_unique<TimeConstrainedUnit>();
160 time_constrained_array_ptr->readInfoFromFile(fin);
161 time_constrained_array_ptr->setLowerTimeThreshold(lower_threshold);
162 time_constrained_array_ptr->setUpperTimeThreshold(upper_threshold);
163 time_constrained_array_ptr->setDecayTau(decay_tau);
164 time_constrained_array_ptr->setBuildupTau(buildup_tau);
165// for (int j=0; j< num_history_data_points; j++)
166// {
167// time_constrained_array_ptr->time_constrained_parameter_history.push_back(time_constrained_array_ptr->getInitialParameterValue());
168// time_constrained_array_ptr->time_constrained_time_history.push_back(r5pars_.timesno + (double) (j - (num_history_data_points+1)) * Time_Lapse_for_Update);
169// }
170 Time_Constrained_Parameter_Array.push_back(std::move(time_constrained_array_ptr));
171 }
172 fin.close();
174 }
175}
176
178 fout << this->Time_Constrained_PIF_Value << ' '
179 << this->Last_Update_Time << ' '
180 << this->Time_Lapse_for_Update << ' '
181 << '\n';
182 fout << Time_Constrained_Parameter_Array.size() << '\n';
183 for(auto& item : Time_Constrained_Parameter_Array){
184 item->saveTimeConstrainedUnitToFile(fout);
185 }
186}
188 int i, num_obj;
192 fin >> num_obj;
193 for(i = 0; i < num_obj;i++){
194 auto TimeConstrainedUnit_pt = make_unique<TimeConstrainedUnit>();
195 TimeConstrainedUnit_pt->retrieveTimeConstrainedUnitFromFile(fin);
196 this->Time_Constrained_Parameter_Array.push_back(std::move(TimeConstrainedUnit_pt));
197 }
198}
int getCurrentGoal()
Definition: InfoChunk.cpp:82
ExpectedMentalBelief * checkExistanceOfMentalBelief(std::string)
Definition: InfoChunk.cpp:934
void outputTimeConstrainedLabelToFile(std::string, std::ofstream &)
void retrieveTimeConstrainedModuleFromFile(std::ifstream &)
void copyTimeConstrainedData(TimeConstrainedModule &)
void initiationForSimulation(std::string)
void operatorUpdateTimeConstrainedValuesWithGoal(InfoChunk *)
void outputTimeConstrainedUnitsToFile(std::ofstream &)
std::vector< std::unique_ptr< TimeConstrainedUnit > > Time_Constrained_Parameter_Array
void saveTimeConstrainedModuleToFile(std::ofstream &)
void updateRawDataAndCalculateTimeToThreshold(InfoChunk *)
std::string determineLimitingTimeConstrainedParameter()
void setLowerTimeThreshold(double)
void setUpperTimeThreshold(double)
void readInfoFromFile(std::ifstream &)
struct @0 r5pars_
constexpr int Succeed
Definition: SimConstants.h:104