19 #include<boost/date_time/posix_time/posix_time.hpp> 21 #include<utils/CmdInterface.hh> 42 string description=
"Usage: abstract --help |\n\t [file.des_comp] [ [--events | --notevents] evt1 evt2 ....] [--output result.des_comp] [--verbose trace.log] [--state-abstractions filename]\n\n\t Compute the model resulting from the abstraction of evt1, evt2 on the standard output\n\tunless the optional output file is setup.\n\tAccept model from standard input\n\tThe option --state-abstractions allows to write in a file the resulting state abstractions";
65 void readParameters(
int argc,
char * argv[],
string & modelFile,
string & outputFile,
66 string & logFile,
string & stateAbstractionFile,
67 unordered_set<Event> & abstractedEvents);
71 int main(
int argc,
char * argv[])
76 string stateAbstractionFile;
77 unordered_set<Event> abstractedEvents;
80 logFile,stateAbstractionFile,
84 ptime time1(microsec_clock::universal_time());
89 log<LgProcess>(
"start importing model from the input stream at %1%")% time1;
93 log<LgProcess>(
"start importing model '%2%' at %1%")% time1 % modelFile;
103 component.importDesCompModel(modelFile);
105 ptime time2(microsec_clock::universal_time());
108 log<LgProcess>(
"end importing model at %1% (duration: %2%ms)")
109 % time2 % (time2-time1);
110 if(modelFile.empty())
112 log<LgProcess>(
"start abstracting model from the input stream on the events %1%")
113 %
toStream(abstractedEvents.begin(),abstractedEvents.end());
117 log<LgProcess>(
"start abstracting model '%1%' on the events %2%") % modelFile %
toStream(abstractedEvents.begin(),abstractedEvents.end());
121 set<Event> projectedEvents;
126 evtIt != component.eventEnd(); ++evtIt)
128 if(abstractedEvents.find(*evtIt) == abstractedEvents.end())
130 projectedEvents.insert(*evtIt);
137 projectedEvents.insert(abstractedEvents.begin(),abstractedEvents.end());
139 if(stateAbstractionFile.empty())
141 abstraction.project(&component,projectedEvents);
145 typedef unordered_map<Diades::Automata::State,unordered_set<Diades::Automata::State> > Dict;
147 abstraction.project(&component,projectedEvents,dictionary);
148 ofstream file(stateAbstractionFile.c_str());
149 for(Dict::const_iterator it = dictionary.begin();
150 it != dictionary.end();
153 file << it->first <<
" { ";
154 for(unordered_set<Diades::Automata::State>::const_iterator it2 = it->second.begin();
155 it2 != it->second.end();
164 abstraction.setName(component.name());
165 ptime time3(microsec_clock::universal_time());
168 log<LgProcess>(
"end abstracting model at %1% (duration: %2%ms)")
169 % time3 % (time3-time2);
171 if(outputFile.empty())
173 log<LgProcess>(
"saving model to the standard output");
177 log<LgProcess>(
"saving model to '%1%'") % outputFile;
180 if(!outputFile.empty())
182 ofstream file(outputFile.c_str());
183 abstraction.exportDesCompModel(file);
187 abstraction.exportDesCompModel(cout);
191 log<LgProcess>(
"successful.");
192 ofstream logs(logFile.c_str());
198 log<LgProcess>(
"abstract has failed, sorry for any inconvenience: %1%")
207 void readParameters(
int argc,
char * argv[],
string & modelFile,
string & outputFile,
208 string & logFile,
string & stateAbstractionFile, unordered_set<Event> & abstractedEvents)
218 while( index < argc )
221 if(getOption<Option>(argv[index],
options,currentOption))
223 if(
isSet[currentOption])
225 printError(
"The option '" +
options[currentOption] +
"' occurs at least twice.");
229 isSet[currentOption] =
true;
231 switch(currentOption)
236 getParameter<string>(argc,argv,index,stateAbstractionFile);
237 if(stateAbstractionFile.empty())
251 getParameter<string>(argc,argv,index,outputFile);
252 if(outputFile.empty())
261 getParameter<string>(argc,argv,index,logFile);
274 set< string > eventLabels;
277 for(
const string & label: eventLabels)
279 abstractedEvents.insert(EventFactory::factory()->getEvent(label));
289 set< string > eventLabels;
292 for(
const string & label: eventLabels)
294 abstractedEvents.insert(EventFactory::factory()->getEvent(label));
302 vector<string>::const_iterator it =
306 printError(
"Unrecognized file extension in file name: " +
string(argv[index]));
313 modelFile = string(argv[index]);
InputIterator getFileExtension(const std::basic_string< CharType, CharTraits > &fileName, InputIterator begin, InputIterator end)
int main(int argc, char *argv[])
void readParameters(int argc, char *argv[], string &modelFile, string &outputFile, string &logFile, string &stateAbstractionFile, unordered_set< Event > &abstractedEvents)
unsigned numberOfFileExtensions
vector< string > options(numberOfOptions)
An observable Component defined as a automaton.
virtual bool importDesCompModel(const string &filename)
void saveLog(Logger logger, ostream &os)
Diades::Utils::ToStream< InputIterator, Diades::Utils::AlwaysTrue< typename InputIterator::reference > > toStream(InputIterator first, InputIterator last)
void printError(string parameter, string message)
set< Event >::const_iterator EventIterator
Log log(Logger logger, const string &msg)
vector< string > fileExtensions(numberOfFileExtensions)
vector< bool > isSet(numberOfOptions, false)
void printUsage(const po::options_description &desc)