program

	name Dijkstra;
	description "Algorithm does properly with Oriented-graph not Multi-graph!";


define

	WNode extends Node
	attributes
		string name;
		boolea minimum;
		int way;
	;

	WEdge extends Edge (WNode)
    attributes
	    int weight;
	;

	WGraph extends Graph (WEdge);


var

	WGraph graph;
	WNodes start, finish;
	WNodes node, nodes;


procedure main();
do
	writeln(get_error_text(graph load_from_file("D:\\Projects\\Rocnikovy projekt\\070420\\graphs\\Dijkstra3.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_minimum(false);
	graph get_nodes() set_way(get_max_int());
	start set_way(0);
	start set_minimum(true);

	nodes := start;
	while !finish get_minimum_value() then
	do
	    nodes := graph get_edges() get_edges_source_is(start) get_nodes_destination() get_minimum_is(false);
	    if nodes get_size() == 0 then
	        terminate("Mezi startem a cilem neexistuje zadna cesta!");

		for each node from nodes
		    node set_way(mini(node get_way_value(), start get_way_value() + graph get_edges() get_edges_source_is(start) get_edges_destination_is(node) get_weight_min_value()));

		nodes := graph get_nodes() get_minimum_is(false) get_way_min();
		nodes set_minimum(true);
		start := nodes;
	enddo

	terminate("Delka cesty ze startu do cile je " + int_to_string(finish get_way_value()));
enddo