with graph; with ada.text_io; with ada.integer_text_io; procedure Graph_Driver2 is Max_Cities : constant := 25; type City is (atlanta, boston, chicago, dallas, great_falls, houston, ithaca, jacksonville, kansas_city, lexington, minneapolis, new_york, oswego, philadelphia, quogue, talahassee, utica, venice, washington, yonkers); subtype Distance is natural; package City_IO is new ada.text_io.enumeration_io (city); function cityName(location : in city) return City is begin return location; end cityName; package Routes is new graph( vertex_type => city, key_type => city, weight_type => distance, key_of => cityName, "=" => "="); myGraph : Routes.Graph_Type(Max_Cities); leg : Routes.Edge_Type; myCity: city; myweight : distance; neighbors : Routes.Key_Queue.Queue_Type(Max_Size => Max_Cities); -- from page 738 begin Routes.Clear(Graph => myGraph); -- initialize graph to have no nodes and no edges in it Routes.Add_Vertex(Graph => myGraph, Vertex => atlanta); for i in city'succ(atlanta)..city'last loop Routes.Add_Vertex (Graph => myGraph, Vertex => i); -- add vertex leg := (from => i, to => city'pred(i)); -- specify direction of edge Routes.Add_Edge (Graph => myGraph, Edge => leg, weight => 10*city'pos(i)); -- add edge leg := (from => city'pred(i), to => i); Routes.Add_Edge (Graph => myGraph, Edge => leg, weight => 10*city'pos(i)); -- add edge Routes.retrieve (Graph => myGraph, Key => i, Vertex => myCity); -- existence test city_io.put (myCity,15); myWeight := Routes.Weight_of(Graph => myGraph, Edge => leg); -- retrieve distance ada.integer_text_io.put (myWeight,5); ada.text_io.new_line; end loop; for i in city'first .. city'pred(city'last) loop Routes.get_Adjacent_Vertices (Graph => myGraph, Key => i, Adj_keys => neighbors); while not Neighbors.empty loop neighbors.dequeue (myCity); city_io.put (myCity,15); end loop; ada.text_io.new_line; end loop; end graph_Driver2;