Skip to content

Instantly share code, notes, and snippets.

@FrankRuns
Created December 14, 2024 13:50
Show Gist options
  • Save FrankRuns/b809433ea938780d6365674d271b6b71 to your computer and use it in GitHub Desktop.
Save FrankRuns/b809433ea938780d6365674d271b6b71 to your computer and use it in GitHub Desktop.
Write a Python script to generate synthetic supply chain data with the following rules:
Here is the detailed description based on the supply chain network:
Distribution Centers (DCs)
Washington, DC:
Located in the northeastern United States near major population centers.
Likely serves as a key hub for East Coast distribution.
Dallas, TX:
Positioned centrally in the southern United States.
Serves as a critical distribution point for central and southern regions.
Los Angeles (LA), CA:
Located in the southwest, close to major ports for imports.
Functions as a gateway for West Coast distribution and international shipments.
Plants
Phoenix, AZ (Plant):
Situated in the southwestern region.
Likely focuses on production for the western states and areas near major ports for outbound shipments.
Charlotte, NC (Plant):
Located in the southeastern United States.
Positioned strategically to supply East Coast markets and southern regions efficiently.
Customers
Based on DC locations, generate synthetic customer locations that make sense for a CPG manufacturer. Most demand will be relatively close to DCs, but there will also be sporadic demand across the country (that is serviced via LTL providers). For the customer generation process, use a Gaussian (normal) distribution instead of uniform random deltas to create more natural and realistic clusters around each hub. Additionally, consider adjusting the standard deviation based on each hub's strategic importance and incorporating population-based weighting to reflect actual demand patterns.
The script should: Explicitly fetch the GeoJSON file of U.S. state boundaries from the URL: https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json. Use the following code to load it into geopandas: python Copy code import requests from io import StringIO import geopandas as gpd url = "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json" response = requests.get(url) us_states = gpd.read_file(StringIO(response.text)) Filter out Alaska and Hawaii, and combine the remaining states into a single geometry for the contiguous U.S. Use this geometry to generate valid land-based points for plants, DCs, and customers: Plants should be evenly spaced across the U.S. DCs should be placed near predefined transportation hubs. Visualize the data on an interactive Folium map, with distinct colors for plants (red plant icon), DCs (blue logistics icon), and customers (green dot).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment