P1: add data and agents.md
This commit is contained in:
42
AGENTS.md
Normal file
42
AGENTS.md
Normal 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/`).
|
||||||
|
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 246 KiB |
@@ -8,6 +8,7 @@ k_min为实数:如2.7表示70%站点最低2次,30%站点最低3次
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import matplotlib
|
import matplotlib
|
||||||
@@ -28,6 +29,7 @@ ALPHA = 0.5
|
|||||||
BETA = 0.2
|
BETA = 0.2
|
||||||
N_SIMS = 2000
|
N_SIMS = 2000
|
||||||
RANDOM_SEED = 42
|
RANDOM_SEED = 42
|
||||||
|
OUTPUT_DIR = "data"
|
||||||
|
|
||||||
|
|
||||||
def gini_coefficient(values):
|
def gini_coefficient(values):
|
||||||
@@ -393,7 +395,8 @@ def plot_results(results):
|
|||||||
axes[3, 1].axis('off')
|
axes[3, 1].axis('off')
|
||||||
|
|
||||||
plt.tight_layout()
|
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)
|
plt.close(fig)
|
||||||
|
|
||||||
return selected_k, selected_eff
|
return selected_k, selected_eff
|
||||||
@@ -443,9 +446,10 @@ def main():
|
|||||||
print(f" 访问次数: [{df_opt['AllocatedVisits'].min()}, {df_opt['AllocatedVisits'].max()}]")
|
print(f" 访问次数: [{df_opt['AllocatedVisits'].min()}, {df_opt['AllocatedVisits'].max()}]")
|
||||||
|
|
||||||
# 6. 保存
|
# 6. 保存
|
||||||
results.to_csv('kmin_effectiveness_data.csv', index=False)
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||||
sites_out.to_csv("kmin_effectiveness_sites.csv", index=False)
|
results.to_csv(os.path.join(OUTPUT_DIR, 'kmin_effectiveness_data.csv'), index=False)
|
||||||
print("\n已保存: kmin_effectiveness.png, kmin_effectiveness_data.csv, kmin_effectiveness_sites.csv")
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user