6 #include<boost/date_time/posix_time/posix_time.hpp> 7 #include<boost/archive/text_oarchive.hpp> 9 #include<utils/CmdInterface.hh> 16 #include<io/xml/automata/Simulation.hh> 42 string description=
"Usage:\t dd-run --algorithms ALG1 [ALG2...] --faults evt1 [evt2 ...] file1.des_comp [file2.des_comp file3.des_comp... sync.rules] scenario.xml\n\t Diagnose the sequence of observations given in the scenarios with the set of available algorithms. Write the diagnostic history in\n\t a file 'histALG.archv' for each algorithm ALG and the perfect diagnosis in 'perfect_history.archv'.\n\t The implemented algorithms are: FBFS, FDFS, FGFS, AFBFS.";
54 vector< EventOccurrence > & simulation,
55 vector< EventOccurrence > & observations);
58 list<string> & modelFiles,
60 unordered_set<Event> & faults,
62 string & scenarioFile);
67 int main(
int argc,
char ** argv)
70 list<string> modelFiles;
72 unordered_set<Event> faults;
76 readParameters(argc,argv,modelFiles,algos,faults,ruleFile,scenarioFile);
79 vector<ObservableComponent *> components;
80 vector<ObservableComponent::CRef> comps;
81 ParametrizedSynchronisation::ComponentVector vectorComp;
82 for(
const string & filename : modelFiles)
85 components.back()->importDesCompModel(filename);
86 vectorComp.push_back(components.back());
87 comps.push_back(cref(*components.back()));
96 set<Event> synchronisedEvents;
102 cit != sit->endOfSupport();
105 synchronisedEvents.insert(sit->getAssociatedEvent(cit));
110 vector< EventOccurrence > observations;
111 vector< EventOccurrence > simulation;
114 std::cout <<
"Scenario:" << std::endl;
117 std::cout <<
"(" << evo.first <<
"," << evo.second <<
") ";
119 std::cout << std::endl;
124 list<Diagnosis> results;
125 string histFile =
"hist.archv";
126 for(
const string & algo: algos)
131 cout <<
"FBFS starting.." << endl;
133 std::ofstream ofs1(
"FBFS" + histFile);
134 boost::archive::text_oarchive oa1(ofs1);
136 results.push_back(d1.
history().getDiagnosis(d1.
history().lastTimePoint()));
141 cout <<
"FDFS starting.." << endl;
143 std::ofstream ofs2(
"FDFS" + histFile);
144 boost::archive::text_oarchive oa2(ofs2);
146 results.push_back(d2.
history().getDiagnosis(d2.
history().lastTimePoint()));
151 cout <<
"FGFS starting.." << endl;
153 std::ofstream ofs3(
"FGFS" + histFile);
154 boost::archive::text_oarchive oa3(ofs3);
156 results.push_back(d3.
history().getDiagnosis(d3.
history().lastTimePoint()));
160 cout <<
"pre-ABFS starting" << endl;
162 typedef unordered_map<Diades::Automata::State,unordered_set<Diades::Automata::State> > Dict;
163 vector<Dict> dictionary;
164 vector<ObservableComponent *> absComponents;
165 vector<ObservableComponent::CRef> abscomps;
166 ParametrizedSynchronisation::ComponentVector vectorAbsComp;
170 set<Event> projectedEvents;
171 for(ObservableComponent::EventIterator evtIt = comp.eventBegin();
172 evtIt != comp.eventEnd();
175 if(synchronisedEvents.find(*evtIt) != synchronisedEvents.end())
177 projectedEvents.insert(*evtIt);
179 if(comp.mask().isObservable(*evtIt))
181 projectedEvents.insert(*evtIt);
183 if(faults.find(*evtIt) != faults.end())
185 projectedEvents.insert(*evtIt);
188 dictionary.push_back(Dict());
189 absComponents.back()->project(&comp,projectedEvents,dictionary.back());
190 absComponents.back()->setName(comp.name());
191 abscomps.push_back(cref(*absComponents.back()));
192 vectorAbsComp.push_back(absComponents.back());
196 if(!ruleFile.empty())
201 cout <<
"AFBFS starting.." << endl;
203 cout <<
"Done" << endl;
204 std::ofstream ofs4(
"AFBFS" + histFile);
205 boost::archive::text_oarchive oa4(ofs4);
206 typedef unordered_map<Diades::Automata::Candidate::StateId,unordered_set<Diades::Automata::Candidate::StateId> > DictId;
207 vector<DictId> dictionaryId(dictionary.size());
208 for(
unsigned i = 0; i < dictionary.size(); ++i)
210 for(Dict::const_iterator it1 = dictionary[i].begin();
211 it1 != dictionary[i].end();
214 for(unordered_set<Diades::Automata::State>::const_iterator it2 = it1->second.begin();
215 it2 != it1->second.end();
218 dictionaryId[i][it1->first.id()].insert(it2->id());
224 results.push_back(nonAbsHist.getDiagnosis(d4.
history().lastTimePoint()));
228 list<Diagnosis>::const_iterator rit = results.begin();
229 for(set<string>::const_iterator it = algos.begin();
233 set<string>::const_iterator it2 = it;
234 list<Diagnosis>::const_iterator rit2 = rit;
237 for(; it2 != algos.end(); ++it2)
239 cout << *it <<
"/" << *it2 <<
" ? " << (*rit == *rit2 ) << endl;
251 list<string> & modelFiles,
253 unordered_set<Event> & faults,
254 string & ruleFile,
string & scenarioFile)
256 list<string>::size_type nbModel = 0;
262 while( index < argc )
265 if(getOption<Option>(argv[index],
options,currentOption))
267 if(
isSet[currentOption])
269 printError(
"The option '" +
options[currentOption] +
"' occurs at least twice.");
273 isSet[currentOption] =
true;
275 switch(currentOption)
280 set<string> faultstring;
283 if(faultstring.empty())
285 printError(
"No parameter after the option " + options[currentOption]);
289 for(
const string & s : faultstring)
291 faults.insert(EventFactory::factory()->getEvent(s));
304 printError(
"No parameter after the option " + options[currentOption]);
312 vector<string>::const_iterator it =
316 printError(
"Unrecognized file extension in file name: " +
string(argv[index]));
325 if(find(modelFiles.begin(),modelFiles.end(),string(argv[index])) == modelFiles.end())
328 modelFiles.push_back(
string(argv[index]));
334 if(!ruleFile.empty())
336 printError(
"The dreamap command does not accept two synchronisation files at the same time.");
338 ruleFile = string(argv[index]);
343 if(!scenarioFile.empty())
345 printError(
"The dreamap command does not accept two scenarios at the same time.");
347 scenarioFile = string(argv[index]);
358 if(scenarioFile.empty())
362 if((nbModel > 1) && (ruleFile.empty()))
366 if((nbModel == 1) && (!ruleFile.empty()))
368 printError(
"Only one component found so no rule file is needed.");
370 if(modelFiles.empty())
380 vector< EventOccurrence > & simulation,
381 vector< EventOccurrence > & observations)
383 list<EventOccurrence> tmp1;
384 list<EventOccurrence> tmp2;
386 back_insert_iterator< list< EventOccurrence > > simIt(tmp1);
387 back_insert_iterator< list< EventOccurrence > > obsIt(tmp2);
390 Diades::Io::Xml::loadXmlSimulation(filename, simIt,obsIt);
394 printError(
"The function readScenario has caught an exception when loading the file " + filename +
": \n" + e.what());
399 simulation.push_back(evo);
404 observations.push_back(evo);
vector< string > fileExtensions(numberOfFileExtensions)
InputIterator getFileExtension(const std::basic_string< CharType, CharTraits > &fileName, InputIterator begin, InputIterator end)
pair< time_duration, Event > EventOccurrence
unsigned initialiseSeed()
ComposableModelSearch< Diades::Utils::GFS< NextTransitions, TargetDiagState, list< DiagState >, list< DiagState >, VisitedDiagState, IsCandidate, IncorrectPath > > FGFS
const History & history() const
bool loadSynchronisationRules(const ParametrizedSynchronisation::ComponentVector &models, const string &filename, ParametrizedSynchronisation &sync)
pair< time_duration, Event > EventOccurrence
SynchronisationIterator beginOfSynchronisedEvents() const
Definition of a fault diagnosis problem in a discrete-event system.
An observable Component defined as a automaton.
DdAutFsm::EventPropertyId Event
unsigned numberOfFileExtensions
Random generation utilities.
Definition of a fault diagnosis problem in a discrete-event system.
SynchronisationIterator endOfSynchronisedEvents() const
void readScenario(const string &filename, vector< EventOccurrence > &simulation, vector< EventOccurrence > &observations)
int main(int argc, char **argv)
ComposableModelSearch< Diades::Utils::DFS< NextTransitions, TargetDiagState, list< DiagState >, list< DiagState >, VisitedDiagState, IsCandidate, IncorrectPath > > FDFS
void initialiseRandomGenerator(unsigned int seed)
void printError(string parameter, string message)
vector< string > options(numberOfOptions)
ComposableModelSearch< Diades::Utils::BFS< NextTransitions, TargetDiagState, list< DiagState >, list< DiagState >, VisitedDiagState, IsCandidate, IncorrectPath > > FBFS
void readParameters(int argc, char *argv[], list< string > &modelFiles, set< string > &algos, unordered_set< Event > &faults, string &ruleFiles, string &scenarioFile)
vector< bool > isSet(numberOfOptions, false)
void printUsage(const po::options_description &desc)