Graphs from the World Map¶
The methods defined here appear in sage.graphs.graph_generators
.
- sage.graphs.generators.world_map.AfricaMap(continental=False, year=2018)[source]¶
Return African states as a graph of common border.
“African state” here is defined as an independent state having the capital city in Africa. The graph has an edge between those countries that have common land border.
INPUT:
continental
– boolean (default:False
); whether to only return states in the continental Africa or all African statesyear
– integer (default: 2018); reserved for future use
EXAMPLES:
sage: Africa = graphs.AfricaMap(); Africa Africa Map: Graph on 54 vertices sage: sorted(Africa.neighbors('Libya')) ['Algeria', 'Chad', 'Egypt', 'Niger', 'Sudan', 'Tunisia'] sage: cont_Africa = graphs.AfricaMap(continental=True) sage: cont_Africa.order() 48 sage: 'Madagaskar' in cont_Africa False
>>> from sage.all import * >>> Africa = graphs.AfricaMap(); Africa Africa Map: Graph on 54 vertices >>> sorted(Africa.neighbors('Libya')) ['Algeria', 'Chad', 'Egypt', 'Niger', 'Sudan', 'Tunisia'] >>> cont_Africa = graphs.AfricaMap(continental=True) >>> cont_Africa.order() 48 >>> 'Madagaskar' in cont_Africa False
- sage.graphs.generators.world_map.EuropeMap(continental=False, year=2018)[source]¶
Return European states as a graph of common border.
“European state” here is defined as an independent state having the capital city in Europe. The graph has an edge between those countries that have common land border.
INPUT:
continental
– boolean (default:False
); whether to only return states in the continental Europe or all European statesyear
– integer (default: 2018); reserved for future use
EXAMPLES:
sage: Europe = graphs.EuropeMap(); Europe Europe Map: Graph on 44 vertices sage: Europe.neighbors('Ireland') ['United Kingdom'] sage: cont_Europe = graphs.EuropeMap(continental=True) sage: cont_Europe.order() 40 sage: 'Iceland' in cont_Europe False
>>> from sage.all import * >>> Europe = graphs.EuropeMap(); Europe Europe Map: Graph on 44 vertices >>> Europe.neighbors('Ireland') ['United Kingdom'] >>> cont_Europe = graphs.EuropeMap(continental=True) >>> cont_Europe.order() 40 >>> 'Iceland' in cont_Europe False
- sage.graphs.generators.world_map.USAMap(continental=False)[source]¶
Return states of USA as a graph of common border.
The graph has an edge between those states that have common land border line or point. Hence for example Colorado and Arizona are marked as neighbors, but Michigan and Minnesota are not.
INPUT:
continental
– boolean (default:False
); whether to exclude Alaska and Hawaii
EXAMPLES:
How many states are neighbor’s neighbor for Pennsylvania:
sage: USA = graphs.USAMap() sage: distance = USA.shortest_path_lengths('Pennsylvania') sage: len([n2 for n2, d in distance.items() if d == 2]) 7
>>> from sage.all import * >>> USA = graphs.USAMap() >>> distance = USA.shortest_path_lengths('Pennsylvania') >>> len([n2 for n2, d in distance.items() if d == Integer(2)]) 7
Diameter for continental USA:
sage: USAcont = graphs.USAMap(continental=True) sage: USAcont.diameter() 11
>>> from sage.all import * >>> USAcont = graphs.USAMap(continental=True) >>> USAcont.diameter() 11
- sage.graphs.generators.world_map.WorldMap()[source]¶
Return the Graph of all the countries, in which two countries are adjacent in the graph if they have a common boundary.
This graph has been built from the data available in The CIA World Factbook [CIA] (2009-08-21).
The returned graph
G
has a memberG.gps_coordinates
equal to a dictionary containing the GPS coordinates of each country’s capital city.EXAMPLES:
sage: g = graphs.WorldMap() sage: g.has_edge("France", "Italy") True sage: g.gps_coordinates["Bolivia"] [[17, 'S'], [65, 'W']] sage: g.connected_component_containing_vertex('Ireland', sort=True) ['Ireland', 'United Kingdom']
>>> from sage.all import * >>> g = graphs.WorldMap() >>> g.has_edge("France", "Italy") True >>> g.gps_coordinates["Bolivia"] [[17, 'S'], [65, 'W']] >>> g.connected_component_containing_vertex('Ireland', sort=True) ['Ireland', 'United Kingdom']