string PromelaCodeGenerator::generateCode(Flow& automaton, int id, EdgeAnnotationMap edgeAnnotationMap, 
					  bool useTransitionIds, boost::unordered_map<string, int>& transitionIdMap) {
  stringstream ss;
  ss << "/* Process "<<id<<" */" << endl;
  ss << "active proctype Proc"<<id<<"()" << endl;
  ss << "{" << endl;
  ss << "  int state = "<<automaton.getStartLabel().getId()<<";" << endl;
  ss << "  do" << endl;

  set<Label> visited; //TODO: maybe change to hashset
  list<Label> worklist;
  worklist.push_back(automaton.getStartLabel());
  visited.insert(automaton.getStartLabel());
  while (!worklist.empty()) {
    Label label = worklist.front();
    worklist.pop_front();
    ss << "  :: state == "<<label.getId()<<" ->" << endl;
    ss << "    atomic {" << endl;
    ss << "      if" << endl;
    Flow outEdges = automaton.outEdges(label);
    for (Flow::iterator i=outEdges.begin(); i!= outEdges.end(); ++i) {
      ss << "      :: "<<communicationDetails((*i).getAnnotation(), id, edgeAnnotationMap, useTransitionIds, transitionIdMap) << endl;
      ss << "        state = "<<(*i).target().getId()<<";" << endl;
      if (visited.find((*i).target()) == visited.end()) {
	worklist.push_back((*i).target());
        visited.insert((*i).target());
      }
    }
    ss << "      fi" << endl;
    ss << "    }" << endl;
  }

  ss << "  od" << endl;
  ss << "}" << endl;
  return ss.str();
}