P1: add data and agents.md

This commit is contained in:
2026-01-17 18:46:16 +08:00
parent ead7e9a9dd
commit d68dc8cde0
5 changed files with 50 additions and 4 deletions

42
AGENTS.md Normal file
View File

@@ -0,0 +1,42 @@
# Repository Guidelines
## Project Structure & Module Organization
- `*.py`: Standalone analysis/optimization scripts (run directly with Python).
- `kmin_effectiveness.py`: k-min vs effectiveness/fairness analysis; writes artifacts to `data/`.
- `fairness_optimization.py`, `analyze_visits.py`, `plot_sites.py`: additional analyses/plots.
- `prob/`: Problem statement and source dataset (e.g., `prob/MFP Regular Sites 2019.xlsx`).
- `latex-template/`: Report template and compilation assets.
- `data/` (generated): Output CSV/PNG artifacts produced by scripts.
## Build, Test, and Development Commands
This repo is script-driven (no package build step).
- Run k-min analysis: `python3 kmin_effectiveness.py`
- Outputs: `data/kmin_effectiveness.png`, `data/kmin_effectiveness_data.csv`, `data/kmin_effectiveness_sites.csv`
- Run visit analysis: `python3 analyze_visits.py` (generates plots in the workspace)
- Run site map: `python3 plot_sites.py`
- Quick syntax check: `python3 -m py_compile kmin_effectiveness.py`
Dependencies commonly used: `numpy`, `pandas`, `matplotlib`, plus Excel readers like `openpyxl`.
## Coding Style & Naming Conventions
- Python: 4-space indentation; keep scripts runnable as `python3 <script>.py`.
- Prefer descriptive names (`k_min`, `total_demand`) and Chinese comments/docstrings where already used.
- Output files should be written under `data/` and named predictably (e.g., `kmin_effectiveness_*.csv/png`).
## Testing Guidelines
There is no formal test suite currently. When changing math/metrics:
- Add a small deterministic check (e.g., `py_compile`, or seed-controlled simulation runs).
- Prefer reproducible randomness via explicit seeds (see `RANDOM_SEED` in `kmin_effectiveness.py`).
## Commit & Pull Request Guidelines
Commit history uses short subjects, sometimes with prefixes (e.g., `P1:` / `add:`). Follow this pattern:
- Keep messages concise and action-oriented (e.g., `P1: add gini plot`).
- PRs should include: what changed, which script(s) to run, and expected outputs (file names under `data/`).

View File

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 246 KiB

View File

@@ -8,6 +8,7 @@ k_min为实数如2.7表示70%站点最低2次30%站点最低3次
import numpy as np
import pandas as pd
import math
import os
try:
import matplotlib
@@ -28,6 +29,7 @@ ALPHA = 0.5
BETA = 0.2
N_SIMS = 2000
RANDOM_SEED = 42
OUTPUT_DIR = "data"
def gini_coefficient(values):
@@ -393,7 +395,8 @@ def plot_results(results):
axes[3, 1].axis('off')
plt.tight_layout()
plt.savefig('kmin_effectiveness.png', dpi=150)
os.makedirs(OUTPUT_DIR, exist_ok=True)
plt.savefig(os.path.join(OUTPUT_DIR, 'kmin_effectiveness.png'), dpi=150)
plt.close(fig)
return selected_k, selected_eff
@@ -443,9 +446,10 @@ def main():
print(f" 访问次数: [{df_opt['AllocatedVisits'].min()}, {df_opt['AllocatedVisits'].max()}]")
# 6. 保存
results.to_csv('kmin_effectiveness_data.csv', index=False)
sites_out.to_csv("kmin_effectiveness_sites.csv", index=False)
print("\n已保存: kmin_effectiveness.png, kmin_effectiveness_data.csv, kmin_effectiveness_sites.csv")
os.makedirs(OUTPUT_DIR, exist_ok=True)
results.to_csv(os.path.join(OUTPUT_DIR, 'kmin_effectiveness_data.csv'), index=False)
sites_out.to_csv(os.path.join(OUTPUT_DIR, "kmin_effectiveness_sites.csv"), index=False)
print("\n已保存到 data/: kmin_effectiveness.png, kmin_effectiveness_data.csv, kmin_effectiveness_sites.csv")
if __name__ == '__main__':