本文整理汇总了C++中Automaton类的典型用法代码示例。如果您正苦于以下问题:C++ Automaton类的具体用法?C++ Automaton怎么用?C++ Automaton使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Automaton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ErrorLexicalUnexpectedSymbol
bool State8::transition(Automaton &automaton, Symbol *symbol) {
switch (symbol->getId()) {
/*
* id : E14
*/
case S_VARIABLE:
automaton.addVariableToCurrentDeclarationVar((SymbolVariable *) symbol);
automaton.transition(symbol, new State14());
return true;
/*
* V : E13
*/
case SYMBOL_UNTERMINAL_V:
automaton.transition(symbol, new State13());
return true;
default:
throw ErrorLexicalUnexpectedSymbol(symbol->toString(), symbol->getNumLineDetection(),
symbol->getNumCharDetection());
}
}
示例2: main
int main(int argc, char** argv) {
Automaton automaton;
if(argc == 2) {
InputFromFile ifile(argv[1]);
automaton.setInput(ifile.readFile());
automaton.run();
}
}
示例3: Name
vector<Value*> AssertionSiteInstrumenter::CollectArgs(
Instruction *Before, const Automaton& A,
Module& Mod, IRBuilder<>& Builder) {
// Find named values to be passed to instrumentation.
std::map<string,Value*> ValuesInScope;
for (auto G = Mod.global_begin(); G != Mod.global_end(); G++)
ValuesInScope[G->getName()] = G;
auto *Fn = Before->getParent()->getParent();
for (auto& Arg : Fn->getArgumentList())
ValuesInScope[Arg.getName()] = &Arg;
auto& EntryBlock(*Fn->begin());
for (auto& I : EntryBlock) {
auto *Inst = dyn_cast<AllocaInst>(&I);
if (!Inst)
break;
ValuesInScope[Inst->getName()] = Builder.CreateLoad(Inst);
}
int ArgSize = 0;
for (auto& Arg : A.getAssertion().argument())
if (!Arg.free())
ArgSize = std::max(ArgSize + 1, Arg.index());
vector<Value*> Args(ArgSize, NULL);
for (auto& Arg : A.getAssertion().argument()) {
if (Arg.free())
continue;
string Name(BaseName(Arg));
if (ValuesInScope.find(Name) == ValuesInScope.end()) {
string s;
raw_string_ostream Out(s);
for (auto v : ValuesInScope) {
Out << " \"" << v.first << "\": ";
v.second->getType()->print(Out);
Out << "\n";
}
panic("assertion references non-existent variable '" + BaseName(Arg)
+ "'; was it defined under '#ifdef TESLA'?\n\n"
"Variables in scope are:\n" + Out.str());
}
Args[Arg.index()] =
GetArgumentValue(ValuesInScope[Name], Arg, Builder, true);
}
return Args;
}
示例4: update
void ContactLocalProductPlugin::extraInit(Simulator *simulator){
update(xmlData,true);
Automaton * cellTypePluginAutomaton = potts->getAutomaton();
if (cellTypePluginAutomaton){
ASSERT_OR_THROW("The size of matrix of contact specificity coefficients has must equal max_cell_type_id+1. You must list specificity coefficients between all cel types",
contactSpecificityArray.size() == ((unsigned int)cellTypePluginAutomaton->getMaxTypeId()+1) );
}
}
示例5: Automaton
Automaton* Converter::convert()
{
Automaton* result = new Automaton();
populateStates();
populateTransitions();
for (int i = 0; i < this->totalStates; i++)
{
result->addState(*this->newStates[i]);
}
result->setStartState(this->newStates[1]);
return result;
}
示例6: ErrorLexicalMissingSymbol
bool State37::transition(Automaton &automaton, Symbol *symbol) {
switch (symbol->getId()) {
/*
* R9 : C -> id = val
* ; | R9
* , | R9
*/
case SYMBOL_UNIT_SEMICOLON:
case SYMBOL_UNIT_COMMA:
automaton.reduction(3, new SymbolUnterminal(SYMBOL_UNTERMINAL_C));
return true;
case S_VARIABLE:
throw ErrorLexicalMissingSymbol(symbol->getNumLineDetection(), symbol->getNumCharDetection(),
new SymbolUnit(SYMBOL_UNIT_COMMA));
case S_INSTRUCTION_READ:
case S_INSTRUCTION_WRITE:
case S_DECLARATION_CONST:
case S_DECLARATION_VAR:
case SYMBOL_UNIT_DOLLAR:
throw ErrorLexicalMissingSymbol(symbol->getNumLineDetection(), symbol->getNumCharDetection(),
new SymbolUnit(SYMBOL_UNIT_SEMICOLON));
default:
throw ErrorLexicalUnexpectedSymbol(symbol->toString(), symbol->getNumLineDetection(),
symbol->getNumCharDetection());
}
}
示例7: main
int main() {
string S; getline(cin, S);
int poz = 0;
Automaton T = solve(S, poz, 0);
Automaton V = T.removeEmptyTransitions().makeDeterminist().minimize();
cout << T << "\n";
cout << T.removeEmptyTransitions().makeDeterminist() << "\n";
cout << V << "\n";
while (cin >> S)
if (V.check(S))
cout << "Bun\n";
else
cout << "Rau\n";
}
示例8: ErrorLexicalUnexpectedSymbol
bool State27::transition(Automaton &automaton, Symbol *symbol) {
switch (symbol->getId()) {
/*
* val : E37
*/
case S_NUMBER:
automaton.addConstantValueToCurrentDeclarationConst((SymbolNumber *) symbol);
automaton.transition(symbol, new State37());
return true;
default:
throw ErrorLexicalUnexpectedSymbol(symbol->toString(), symbol->getNumLineDetection(),
symbol->getNumCharDetection());
}
}
示例9: CallUpdateState
void EventTranslator::CallUpdateState(const Automaton& A, uint32_t Symbol) {
std::vector<Value*> Args;
Args.push_back(InstrCtx.TeslaContext(A.getAssertion().context()));
Args.push_back(InstrCtx.ExternalDescription(A));
Args.push_back(ConstantInt::get(InstrCtx.Int32Ty, Symbol));
Args.push_back(Key);
Builder.CreateCall(InstrCtx.UpdateStateFn(), Args);
}
示例10: solve
Automaton solve(string &S, int &position, int level) {
if (level == 0) {
Automaton aux = solve(S, position, 1);
while (position < int(S.size()) and S[position] == '+') {
Automaton next = solve(S, ++position, 1);
aux += next;
}
return aux;
}
if (level == 1) {
Automaton aux = solve(S, position, 2);
while (position < int(S.size()) and S[position] == '|') {
Automaton next = solve(S, ++position, 2);
aux |= next;
}
return aux;
}
if (level == 2) {
Automaton aux = solve(S, position, 3);
while (position < int(S.size()) and S[position] == '*') {
aux.star();
++position;
}
return aux;
}
if (S[position] == '(') {
Automaton aux = solve(S, ++position, 0);
++position;
return aux;
}
Automaton aux(2, dictionary);
aux.setFinal(1);
aux.setStart(0);
aux.addTransition(0, 1, S[position]);
++position;
return aux;
}
示例11: DrawWithMap
void Grid::DrawWithMap(Automaton &a)
{
for (int i=0; i<cellCount; i++)
for(int j=0; j<cellCount; j++) {
statecode cell_state = a(i,j);
statecode ill_state = a.getIllState();
double lcolor[3];
double density = (double) cell_state / ill_state;
std::fill(lcolor, lcolor+3, density);
FillCell(i, j, lcolor);
}
}
示例12: print
void State::print(const Automaton& automaton) const
{
std::cout << "Nom(" << name << ") ";
if (isInitial()) {
std::cout << "[initial] ";
}
if (isFinal()) {
std::cout << "[final] ";
}
std::cout << std::endl;
std::cout << "\t== Transitions" << std::endl;
TransitionSet::const_iterator it;
for (it = outTransitions.begin(); it != outTransitions.end(); ++it) {
std::cout << "\t\tavec(" << it->condition << ") => " << automaton.findStateName(it->target) << std::endl;
}
}
示例13: main
int main (int argc, char *argv[])
{
QCoreApplication app (argc, argv);
bool generate_dot = false;
bool generate_report = false;
bool no_lines = false;
bool debug_info = true;
bool troll_copyright = false;
QString file_name = 0;
QStringList args = app.arguments ();
args.removeFirst ();
foreach (QString arg, args)
{
if (arg == QLatin1String ("-h") || arg == QLatin1String ("--help"))
help_me ();
else if (arg == QLatin1String ("-v") || arg == QLatin1String ("--verbose"))
generate_report = true;
else if (arg == QLatin1String ("--dot"))
generate_dot = true;
else if (arg == QLatin1String ("--no-lines"))
no_lines = true;
else if (arg == QLatin1String ("--no-debug"))
debug_info = false;
else if (arg == QLatin1String ("--troll"))
troll_copyright = true;
else if (file_name.isEmpty ())
file_name = arg;
else
qerr << "*** Warning. Ignore argument `" << arg << "'" << endl;
}
if (file_name.isEmpty ())
{
help_me ();
exit (EXIT_SUCCESS);
}
Grammar grammar;
Recognizer p (&grammar, no_lines);
if (! p.parse (file_name))
exit (EXIT_FAILURE);
if (grammar.rules.isEmpty ())
{
qerr << "*** Fatal. No rules!" << endl;
exit (EXIT_FAILURE);
}
else if (grammar.start == grammar.names.end ())
{
qerr << "*** Fatal. No start symbol!" << endl;
exit (EXIT_FAILURE);
}
grammar.buildExtendedGrammar ();
grammar.buildRuleMap ();
Automaton aut (&grammar);
aut.build ();
CppGenerator gen (p, grammar, aut, generate_report);
gen.setDebugInfo (debug_info);
gen.setTrollCopyright (troll_copyright);
gen ();
if (generate_dot)
{
DotGraph genDotFile (qout);
genDotFile (&aut);
}
else if (generate_report)
{
ParseTable genParseTable (qout);
genParseTable(&aut);
}
return EXIT_SUCCESS;
}
示例14: findSymbolId
Automaton * Automaton::getDeterministic() {
Automaton * b = new Automaton;
std::vector< std::vector< int > > mEmptyTransitions;
std::vector< int > vEmptyIn;
std::vector< int > vEmptyOut;
int i, j, removed;
b->vStates = vStates;
b->vFinal = vFinal;
b->vSymbols = vSymbols;
b->mTransitions = mTransitions;
//creates the mEmptyTransitions table
vEmptyIn.resize(getNStates());
vEmptyOut.resize(getNStates());
mEmptyTransitions.resize(getNStates());
for(i = 0; i < getNStates(); i++)
mEmptyTransitions[i].resize(getNStates());
//initialize mEmptyTransitions
for(i = 0; i < mEmptyTransitions.size(); i++){
vEmptyIn[i] = 0;
vEmptyOut[i] = 0;
for(j = 0; j < mEmptyTransitions[i].size(); j++)
mEmptyTransitions[i][j] = 0;
}
//fills mEmptyTransitons
j = findSymbolId("");
if(j != -1) {
for(int i = 0; i < getNStates(); i++) {
for(std::list<int>::iterator it = mTransitions[i][j].begin(); it != mTransitions[i][j].end(); it++) {
vEmptyIn[*it]++;
vEmptyOut[i]++;
mEmptyTransitions[i][*it]++;
}
}
}
//finds a state 'i' with incoming empty transitions, but no outgoing empty transitions,
//copy its transtions to states 'j' able to reach 'i' and removes these empty transitions
do {
removed = 0;
for(i = 0; i < getNStates(); i++) {
if((vEmptyIn[i] > 0) && (vEmptyOut[i] == 0)) {
for(j = 0; j < getNStates(); j++) {
if(i == j)
continue;
if(mEmptyTransitions[j][i] > 0) {
b->copyOutgoingTransitions(i, j);
b->removeIncomingEmptyTransitions(i);
if(b->vFinal[i] == true)
b->vFinal[j] = true;
mEmptyTransitions[j][i]--;
vEmptyIn[i]--;
vEmptyOut[j]--;
removed++;
}
}
}
}
} while(removed > 0);
//finds a state 'i' that has a non-determinism (two or more outputs for the same symbol),
//creates a state representing all those symbols and change the transition to this one
do {
removed = 0;
for(i = 0; i < b->getNStates(); i++) {
for(j = 0; j < b->getNSymbols(); j++) {
if(b->mTransitions[i][j].size() > 1) {
int newStateId;
std::string newStateName;
bool isFinal;
//fills newStateName and isFinal
newStateName = b->vStates[mTransitions[i][j].front()];
std::list<int>::iterator it = b->mTransitions[i][j].begin();
isFinal = vFinal[*it];
++it;
for(; it != b->mTransitions[i][j].end(); it++) {
newStateName += "_" + b->vStates[*it];
isFinal = isFinal || vFinal[*it];
}
//guarantees the newStateName is unique
while(b->findStateId(newStateName) != -1)
newStateName += '_';
//adds newStateName to b
b->addState(newStateName, isFinal);
newStateId = b->findStateId(newStateName);
//.........这里部分代码省略.........
示例15: update
void ConnectivityGlobalPlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag) {
if (potts->getDisplayUnitsFlag()) {
Unit energyUnit = potts->getEnergyUnit();
CC3DXMLElement * unitsElem = _xmlData->getFirstElement("Units");
if (!unitsElem) { //add Units element
unitsElem = _xmlData->attachElement("Units");
}
if (unitsElem->getFirstElement("PenaltyUnit")) {
unitsElem->getFirstElement("PenaltyUnit")->updateElementValue(energyUnit.toString());
}
else {
CC3DXMLElement * energyElem = unitsElem->attachElement("PenaltyUnit", energyUnit.toString());
}
}
penaltyVec.clear();
Automaton *automaton = potts->getAutomaton();
ASSERT_OR_THROW("CELL TYPE PLUGIN WAS NOT PROPERLY INITIALIZED YET. MAKE SURE THIS IS THE FIRST PLUGIN THAT YOU SET", automaton)
set<unsigned char> cellTypesSet;
map<unsigned char, double> typeIdConnectivityPenaltyMap;
if (_xmlData->getFirstElement("DoNotPrecheckConnectivity")) {
doNotPrecheckConnectivity = true;
}
if (_xmlData->getFirstElement("FastAlgorithm")) {
fast_algorithm = true;
changeEnergyFcnPtr = &ConnectivityGlobalPlugin::changeEnergyFast;
}
CC3DXMLElementList penaltyVecXML = _xmlData->getElements("Penalty");
CC3DXMLElementList connectivityOnVecXML = _xmlData->getElements("ConnectivityOn");
ASSERT_OR_THROW("You cannot use Penalty and ConnectivityOn tags together. Stick to one convention", !(connectivityOnVecXML.size() && penaltyVecXML.size()));
// previous ASSERT_OR_THROW will encure that only one of the subsequent for loops be executed
for (int i = 0; i < penaltyVecXML.size(); ++i) {
typeIdConnectivityPenaltyMap.insert(make_pair(automaton->getTypeId(penaltyVecXML[i]->getAttribute("Type")), penaltyVecXML[i]->getDouble()));
//inserting all the types to the set (duplicate are automatically eleminated) to figure out max value of type Id
cellTypesSet.insert(automaton->getTypeId(penaltyVecXML[i]->getAttribute("Type")));
}
for (int i = 0; i < connectivityOnVecXML.size(); ++i) {
typeIdConnectivityPenaltyMap.insert(make_pair(automaton->getTypeId(connectivityOnVecXML[i]->getAttribute("Type")), 1.0));
//inserting all the types to the set (duplicate are automatically eleminated) to figure out max value of type Id
cellTypesSet.insert(automaton->getTypeId(connectivityOnVecXML[i]->getAttribute("Type")));
}
//Now that we know all the types used in the simulation we will find size of the penaltyVec
vector<unsigned char> cellTypesVector(cellTypesSet.begin(), cellTypesSet.end());//coping set to the vector
int size = 0;
if (cellTypesVector.size()) {
size = *max_element(cellTypesVector.begin(), cellTypesVector.end());
}
maxTypeId = size;
size += 1;//if max element is e.g. 5 then size has to be 6 for an array to be properly allocated
int index;
penaltyVec.assign(size, 0.0);
//inserting connectivity penalty values to penaltyVec;
for (map<unsigned char, double>::iterator mitr = typeIdConnectivityPenaltyMap.begin(); mitr != typeIdConnectivityPenaltyMap.end(); ++mitr) {
penaltyVec[mitr->first] = fabs(mitr->second);
}
cerr << "size=" << size << endl;
for (int i = 0; i < size; ++i) {
cerr << "penaltyVec[" << i << "]=" << penaltyVec[i] << endl;
}
//Here I initialize max neighbor index for direct acces to the list of neighbors
boundaryStrategy = BoundaryStrategy::getInstance();
maxNeighborIndex = 0;
maxNeighborIndex = boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(1);
//.........这里部分代码省略.........