bug似乎解决了

This commit is contained in:
AgentLabCn
2025-12-02 10:08:45 +08:00
parent 135b762a29
commit ef93f0cc6a
4 changed files with 165 additions and 149 deletions

View File

@@ -103,7 +103,7 @@ def update_production_line_csv(csv_path: Path, factory_name_cn: str, line_ids: L
_release_lock(lock_path, fd)
def evaluate(factory_code: str, line_ids: List[str], genes: List[float]) -> float:
def evaluate(factory_code: str, factory_name_cn: str, line_ids: List[str], genes: List[float]) -> float:
factory_factors = {}
model = SimulationModel(
factory_factors=factory_factors,
@@ -115,6 +115,13 @@ def evaluate(factory_code: str, line_ids: List[str], genes: List[float]) -> floa
model.line_factor[lid] = float(val)
while model.running:
model.step()
# Prefer per-factory error ratio; fall back to aggregate model.error if missing.
if model.factory_error_df is not None and not model.factory_error_df.empty:
matched = model.factory_error_df[
model.factory_error_df["name"].astype(str).str.strip() == str(factory_name_cn).strip()
]
if not matched.empty and "error_ratio" in matched.columns:
return float(matched.iloc[0]["error_ratio"])
return model.error
@@ -235,7 +242,11 @@ def main():
line_ids = [lid for lid, _, _, _ in seed_lines]
seed_vals = [seed for _, seed, _, _ in seed_lines]
bounds = [(mn, mx) for _, _, mn, mx in seed_lines]
prev_best_error = float(factory_row["最小误差"]) if pd.notna(factory_row["最小误差"]) else float("inf")
prev_best_error = (
float(factory_row[factory_cols["最小误差"]])
if pd.notna(factory_row[factory_cols["最小误差"]])
else float("inf")
)
print(f"[START] 校准工厂 {args.factory} / {factory_name_cn} (产线数={len(line_ids)}, baseline_error={prev_best_error:.6f})")
@@ -248,7 +259,7 @@ def main():
scored = []
for indiv in population:
indiv = apply_bounds(indiv, bounds)
score = evaluate(args.factory, line_ids, indiv)
score = evaluate(args.factory, factory_name_cn, line_ids, indiv)
# print(f"[{args.factory}] Gen {gen+1} try factors={indiv} -> error={score:.6f}")
scored.append((score, indiv))
if score < best_score: