Conversation started Oct 23, 2012 at 13:35.
Oct 23, 2012 13:35
void Graph::DFS_Visit(vertex_struct aVertex)
{
	aVertex.Color = "GRAY";
	mTime = mTime + 1;
	aVertex.Dist = mTime;
	for (list<vertex_struct *>::iterator it = aVertex.Edges.begin(); it != aVertex.Edges.end(); it++)
	{
		if(it->Color.compare("WHITE") == 0)
		{
			it->Pred = &aVertex;
			DFS_Visit(&it);
		}

		aVertex.Color = "BLACK";
		aVertex.Finish = mTime;
		mStack.push(aVertex);
		mTime = mTime + 1;
	}
}
my it is having problems...
expression must have point to class type
ah depth first search :)
Ya!
I just had to write that for Berkeley's AI class
oh really?
What are you using it for anyway? Marking visited vertices with a color?
Oct 23, 2012 13:36
Hmm... maybe I should look into that...
that's the assignment ^^
painful
that's the notes ^^ (Using DAG... towards the bottom)
Yeah I had that in Algorithms class and Probabilistic Graphical Models
@IvoFlipse actually I'm on assignment three, but didn't do so well on assignment two so now I'm redoing it
Darn all these job interviews. I'm glad I'm done with them now
where did you have to interview?
Gray are the vertices you're about to explore?
Oct 23, 2012 13:39
a lot of places... but mainly General Dynamics, Meditronics, Performance Software, and the Local Univ
So I guess you have a DFS function that picks vertices to visit and a function that does the actual following
@IvoFlipse Visited but not fully processed basically... so ya
void Graph::DFS(list<vertex_struct> aGraph)
{

	// Initialize Color and predecessors (leave Pred blank):
	for(list<vertex_struct>::iterator init = aGraph.begin(); init != aGraph.end(); init++)
	{
		init->Color = "WHITE";
		init->Pred = NULL;
	}

	mTime = 0;

	for(list<vertex_struct>::iterator it = aGraph.begin(); it != aGraph.end(); it++)
	{
		if(it->Color.compare("WHITE") == 0)
		{
			DFS_Visit(*it);
		}
	}
}
That's the DFS itself
Yeah, that makes sense
list<vertex_struct *>::iterator it
Is that the right declaration for the iterator?
//Vertex
typedef struct vertex_struct {
	string Name;
	list<vertex_struct *> Edges;
	float Delay;
	string Color;
	vertex_struct *Pred;
	float Dist;
	int Finish;

};
 
Conversation ended Oct 23, 2012 at 13:40.