|
803 | 803 | " edge_labels[(node, connection)] = distance" |
804 | 804 | ] |
805 | 805 | }, |
806 | | - { |
807 | | - "cell_type": "code", |
808 | | - "execution_count": 7, |
809 | | - "metadata": { |
810 | | - "collapsed": true |
811 | | - }, |
812 | | - "outputs": [], |
813 | | - "source": [ |
814 | | - "# initialise a graph\n", |
815 | | - "G = nx.Graph()\n", |
816 | | - "\n", |
817 | | - "# use this while labeling nodes in the map\n", |
818 | | - "node_labels = dict()\n", |
819 | | - "# use this to modify colors of nodes while exploring the graph.\n", |
820 | | - "# This is the only dict we send to `show_map(node_colors)` while drawing the map\n", |
821 | | - "node_colors = dict()\n", |
822 | | - "\n", |
823 | | - "for n, p in romania_locations.items():\n", |
824 | | - " # add nodes from romania_locations\n", |
825 | | - " G.add_node(n)\n", |
826 | | - " # add nodes to node_labels\n", |
827 | | - " node_labels[n] = n\n", |
828 | | - " # node_colors to color nodes while exploring romania map\n", |
829 | | - " node_colors[n] = \"white\"\n", |
830 | | - "\n", |
831 | | - "# we'll save the initial node colors to a dict to use later\n", |
832 | | - "initial_node_colors = dict(node_colors)\n", |
833 | | - " \n", |
834 | | - "# positions for node labels\n", |
835 | | - "node_label_pos = { k:[v[0],v[1]-10] for k,v in romania_locations.items() }\n", |
836 | | - "\n", |
837 | | - "# use this while labeling edges\n", |
838 | | - "edge_labels = dict()\n", |
839 | | - "\n", |
840 | | - "# add edges between cities in romania map - UndirectedGraph defined in search.py\n", |
841 | | - "for node in romania_map.nodes():\n", |
842 | | - " connections = romania_map.get(node)\n", |
843 | | - " for connection in connections.keys():\n", |
844 | | - " distance = connections[connection]\n", |
845 | | - "\n", |
846 | | - " # add edges to the graph\n", |
847 | | - " G.add_edge(node, connection)\n", |
848 | | - " # add distances to edge_labels\n", |
849 | | - " edge_labels[(node, connection)] = distance" |
850 | | - ] |
851 | | - }, |
852 | 806 | { |
853 | 807 | "cell_type": "markdown", |
854 | 808 | "metadata": {}, |
|
0 commit comments