/** Base BFS algorithm returns "Yes" or "No". */
program

	name bfs_yes_no;
	author "Some clever book :o)";
	version 1.0;


define

	BFSNode extends Node
	attributes
		string name;
		boolean visited;
	;

	BFSEdge extends Edge (BFSNode);

	BFSGraph extends Graph (BFSEdge);


var

	BFSGraph graph;
	BFSNodes start, finish;


function bfs_search_from (BFSNodes nodes) returns boolean;
var
	BFSNodes friends;

do
	nodes set_visited(true);
	if nodes get_intersection_fake(finish) >= 1 then
	    return true;

	friends := graph get_edges() get_edges_source_is(nodes) get_nodes_destination() get_visited_is(false);
	if friends is_empty() then
	    return false;

	return bfs_search_from(friends);
enddo


procedure main();
do
	writeln(get_error_text(graph load_from_file("D:\\Projects\\Rocnikovy projekt\\070427\\graphs\\BGSGraph3.dat")));
	start := graph get_nodes() get_name_is("start");
	finish := graph get_nodes() get_name_is("end");
	if start get_size() < 1 | finish get_size() < 1 then
	    terminate("Chybne urceni zacatku nebo cile hledani!");

    graph get_nodes() set_visited(false);
	if bfs_search_from(start) then
	    terminate("Existuje alespon jedna cesta ze startu do cile.");

	terminate("Mezi zadanymi vrcholy neexistuje zadna cesta.");
enddo