Ejemplo n.º 1
0
QList<ListDigraph::Node> ProcessModel::reachableFrom(const QList<ListDigraph::Node>& s) {
	ListDigraph::NodeMap<bool > nodevisited(graph, false);
	QList<ListDigraph::Node> res;
	QQueue<ListDigraph::Node> q;
	ListDigraph::Node curnode;
	ListDigraph::Node targetnode;

	q.reserve(countNodes(graph));
	res.reserve(countNodes(graph));

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != INVALID) {
			q.append(s[i]);
		}
	}

	while (!q.empty()) {
		curnode = q.dequeue();

		if (!nodevisited[curnode]) {
			nodevisited[curnode] = true;
			res.append(curnode);

			// Check the successors
			for (ListDigraph::OutArcIt oait(graph, curnode); oait != INVALID; ++oait) {
				targetnode = graph.target(oait);
				if (!nodevisited[targetnode]) {
					q.enqueue(targetnode);
				}
			}
		}

	}

	return res;
}