I have this structure based multimap and a vector for this structure:
typedef std::multimap<char, int> tr;
vector <tr> transitions;
I want to fill the array with values like:
0 0 a
0 1 a
1 1 b
1 2 c
1 3 c
which represent the transitions of an automaton, and i use a vector of std::multimap for the transitions. This assumes that each state corresponds to an integer. How I could do this?. I try:
for (j=0; j<numberTransitions;j++){
cin>> stateOrigin>>stateDestination>>transitionCharacter;
transitionsStates.insert(pair<char, int>(transitionCharacter, stateDestination));
transitions.push_back (transitionsStates);
}
But I’m not sure if it’s correct. Any suggestions?
You never use stateOrigin, so I’m pretty sure it’s wrong (unless I’ve completely misunderstood your intent). I think what you want is more like this:
To drive the state machine, you’d use something like this:
Also note that with C++11 you probably want to use
std::unordered_mapinstead, unless you need efficient access to all the triggers for a given state.