Skip to content

Instantly share code, notes, and snippets.

@FrankRuns
Created December 22, 2024 12:16
Show Gist options
  • Save FrankRuns/5946b3a8638a50142643c3376358545b to your computer and use it in GitHub Desktop.
Save FrankRuns/5946b3a8638a50142643c3376358545b to your computer and use it in GitHub Desktop.
You have a CSV file called `locations.csv` with columns: name, longitude, latitude, type (including 'Customer' rows), DCs, and plants.
I want you to:
1. Filter the data to only include rows where `type == 'Customer'`.
2. Generate synthetic one-period demand for these customers:
- Normal scenario: Draw from a normal distribution (mean=100, std=20), clip negatives at 0.
- Lognormal scenario: Draw from a lognormal distribution (mean=4.5, sigma=0.5).
3. Compute a local density factor:
- Convert lat/lon to radians.
- Use a BallTree with haversine distance to count the number of other customers within 100km.
- Compute density factor = (neighbors+1)/(average_neighbors+1).
4. Apply this density factor to both normal and lognormal demands, producing four scenarios:
- Normal Base
- Normal Density-Scaled
- Lognormal Base
- Lognormal Density-Scaled
5. Create four separate Folium maps (one per scenario), each saved as an HTML file.
- Markers represent customer locations.
- Marker size is smaller, scaled by demand (smaller than before).
- Initial map zoom is 4.
- Color markers based on demand volume (Low: <80 green, Medium: 80-120 orange, High: >=120 red).
6. Arrange all four Folium maps side-by-side in a 2x2 grid in a single Jupyter cell using iframes and a simple HTML block (no ipywidgets).
7. Finally, create histograms of each demand scenario (Normal Base, Normal Density-Scaled, Lognormal Base, Lognormal Density-Scaled).
Please provide a single Python code cell that executes all the above steps and displays both the maps and the histograms in a Jupyter notebook environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment