joker727 Claude Opus 4.8 commited on
Commit
12697c3
Β·
1 Parent(s): 4d5de93

Adjacency wording, connectivity access-graph, uniform walls (client review)

Browse files

Calculation/display only. Adjacency final line clarifies "total possible" is
the max weighted score (not the pair count). Connectivity now exposes and
renders the access graph (nodes=rooms, edges=doorway walls; entry/reachable/
isolated colouring + verdict). Editor hides the green locked-adjacency lines
while the Walls overlay is on so walls look uniform. Generation untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (3) hide show
  1. app.py +48 -6
  2. core/metrics.py +14 -3
  3. floorplan_editor/frontend/index.html +4 -2
app.py CHANGED
@@ -226,6 +226,29 @@ def _pct(v):
226
  return f"{v * 100:.1f}%"
227
 
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  def render_edit_comparison(orig_fp, edited_fp, road_side, selected_vastu=None):
230
  """Score the plan the user edited in the room editor with the SAME finalised
231
  system and compare it, metric by metric, to the original optimised plan.
@@ -333,12 +356,16 @@ def render_evaluation(raw_fp, opt_fp, road_side, selected_vastu=None):
333
  "Each finalised room pair earns its tier value when the two rooms "
334
  "**share a wall** β€” **High +1 Β· Med +0.5 Β· Low +0.2**. Every "
335
  "**Avoid** pair that touches subtracts 1. "
336
- "Score = (total counts βˆ’ avoid penalties) Γ· total possible.")
 
 
 
337
  # only the pairs that are actually present in the plan are judged
338
  arows = [{"Room Pairs": n, "Tier": _atier.get(w, str(w)),
339
  "Status": "Shares wall" if ok else "Doesn't share wall",
340
  "Counts": f"+{w:g}" if ok else "0"}
341
  for n, w, ap, ok in ad["rows"] if ap]
 
342
  arows.append({"Room Pairs": "TOTAL", "Tier": "", "Status": "",
343
  "Counts": f"+{ad['earned']:g}"})
344
  st.dataframe(pd.DataFrame(arows), hide_index=True, width="stretch")
@@ -352,8 +379,11 @@ def render_evaluation(raw_fp, opt_fp, road_side, selected_vastu=None):
352
  width="stretch")
353
  st.markdown(
354
  f"**Final = (counts {ad['earned']:g} βˆ’ avoid "
355
- f"{ad['penalties']:.0f}) Γ· {ad['possible']:g} possible "
356
- f"= {_pct(s['adjacency'])}**")
 
 
 
357
 
358
  with st.expander(f"Constraints β€” {_pct(s['constraints'])}"):
359
  cd = d["constraints"]
@@ -451,9 +481,21 @@ def render_evaluation(raw_fp, opt_fp, road_side, selected_vastu=None):
451
  with st.expander(f"Connectivity β€” {_pct(s['connectivity'])}"):
452
  cn = d["connectivity"]
453
  st.markdown(
454
- "A room is **reachable** when there is a path of real doorways "
455
- "from the entry (staircase) to it. "
456
- "Score = reachable rooms Γ· total rooms.")
 
 
 
 
 
 
 
 
 
 
 
 
457
  unreach = set(cn["unreachable"])
458
  st.dataframe(pd.DataFrame(
459
  [{"Room": pretty_room(r.name),
 
226
  return f"{v * 100:.1f}%"
227
 
228
 
229
+ def fig_connectivity_graph(nodes, edges):
230
+ """Draw the plan's access graph: each room is a node at its centroid, an
231
+ edge joins two rooms that share a doorway-sized wall, and colour shows
232
+ reachability from the entry (green=entry, blue=reachable, red=isolated)."""
233
+ import matplotlib.pyplot as plt
234
+ fig, ax = plt.subplots(figsize=(5, 5))
235
+ for i, j in edges:
236
+ ax.plot([nodes[i][1], nodes[j][1]], [nodes[i][2], nodes[j][2]],
237
+ "-", color="#8899A6", lw=1.2, zorder=1)
238
+ for name, cx, cy, reach, is_entry, _hop in nodes:
239
+ color = "#2E7D32" if is_entry else ("#1E88E5" if reach else "#E53935")
240
+ ax.scatter([cx], [cy], s=560, color=color, edgecolor="white",
241
+ linewidth=1.5, zorder=2)
242
+ ax.text(cx, cy, pretty_room(name).replace(" ", "\n"), ha="center",
243
+ va="center", fontsize=6, color="white", zorder=3)
244
+ ax.set_aspect("equal")
245
+ ax.axis("off")
246
+ ax.set_title("Access graph β€” green = entry Β· blue = reachable Β· "
247
+ "red = isolated", fontsize=8)
248
+ fig.tight_layout()
249
+ return fig
250
+
251
+
252
  def render_edit_comparison(orig_fp, edited_fp, road_side, selected_vastu=None):
253
  """Score the plan the user edited in the room editor with the SAME finalised
254
  system and compare it, metric by metric, to the original optimised plan.
 
356
  "Each finalised room pair earns its tier value when the two rooms "
357
  "**share a wall** β€” **High +1 Β· Med +0.5 Β· Low +0.2**. Every "
358
  "**Avoid** pair that touches subtracts 1. "
359
+ "**Total possible is the MAX SCORE**, not the pair count β€” a High "
360
+ "pair is worth 1.0 but a Low pair only 0.2, so the pairs sum to "
361
+ "less than their number. Score = (total counts βˆ’ avoid penalties) "
362
+ "Γ· total possible.")
363
  # only the pairs that are actually present in the plan are judged
364
  arows = [{"Room Pairs": n, "Tier": _atier.get(w, str(w)),
365
  "Status": "Shares wall" if ok else "Doesn't share wall",
366
  "Counts": f"+{w:g}" if ok else "0"}
367
  for n, w, ap, ok in ad["rows"] if ap]
368
+ njudged = sum(1 for _n, _w, ap, _ok in ad["rows"] if ap)
369
  arows.append({"Room Pairs": "TOTAL", "Tier": "", "Status": "",
370
  "Counts": f"+{ad['earned']:g}"})
371
  st.dataframe(pd.DataFrame(arows), hide_index=True, width="stretch")
 
379
  width="stretch")
380
  st.markdown(
381
  f"**Final = (counts {ad['earned']:g} βˆ’ avoid "
382
+ f"{ad['penalties']:.0f}) Γ· {ad['possible']:g} max score "
383
+ f"= {_pct(s['adjacency'])}** \n"
384
+ f"*{njudged} pairs judged Β· max score {ad['possible']:g} = their "
385
+ f"tier values summed (High 1.0 Β· Med 0.5 Β· Low 0.2), not the pair "
386
+ f"count.*")
387
 
388
  with st.expander(f"Constraints β€” {_pct(s['constraints'])}"):
389
  cd = d["constraints"]
 
481
  with st.expander(f"Connectivity β€” {_pct(s['connectivity'])}"):
482
  cn = d["connectivity"]
483
  st.markdown(
484
+ "The plan is read as a **graph**: every room is a node, two rooms "
485
+ "are joined by an edge when they share a doorway-sized wall, and a "
486
+ "room is **reachable** when a path of doorways links it to the "
487
+ "entry (staircase). The graph shows at a glance whether every room "
488
+ "is connected β€” not just how many. Score = reachable Γ· total rooms.")
489
+ if cn.get("nodes"):
490
+ fig_cg = fig_connectivity_graph(cn["nodes"], cn["edges"])
491
+ st.pyplot(fig_cg, use_container_width=True)
492
+ import matplotlib.pyplot as _plt
493
+ _plt.close(fig_cg)
494
+ iso = cn["unreachable"]
495
+ st.markdown(
496
+ "**βœ… All rooms are reachable from the entry.**" if not iso else
497
+ "**⚠ Not fully connected β€” isolated: " +
498
+ ", ".join(pretty_room(x) for x in iso) + "**")
499
  unreach = set(cn["unreachable"])
500
  st.dataframe(pd.DataFrame(
501
  [{"Room": pretty_room(r.name),
core/metrics.py CHANGED
@@ -506,15 +506,26 @@ def room_size_accuracy(fp, road_side: str = "S"):
506
  # ── 7. Connectivity ──────────────────────────────────────────────────────────
507
 
508
  def connectivity(fp):
509
- """Fraction of rooms reachable from the entry through real doorways."""
 
 
 
 
510
  if not fp.rooms:
511
- return 1.0, {"unreachable": []}
512
  depth = _hop_depths(fp)
513
  reachable = len(depth)
514
  unreachable = [r.name for r in fp.rooms if id(r) not in depth]
 
 
 
 
 
 
 
515
  return reachable / len(fp.rooms), {
516
  "reachable": reachable, "total": len(fp.rooms),
517
- "unreachable": unreachable}
518
 
519
 
520
  # ── 8. Room Aspect Ratio ─────────────────────────────────────────────────────
 
506
  # ── 7. Connectivity ──────────────────────────────────────────────────────────
507
 
508
  def connectivity(fp):
509
+ """Fraction of rooms reachable from the entry through real doorways, plus
510
+ the full access GRAPH: every room is a node, two rooms are joined by an edge
511
+ when they share enough wall for a doorway, and reachability is a BFS from the
512
+ entry. This lets the plan be read as a graph β€” you can see at a glance
513
+ whether every room is connected, not just count how many are."""
514
  if not fp.rooms:
515
+ return 1.0, {"unreachable": [], "nodes": [], "edges": [], "hops": {}}
516
  depth = _hop_depths(fp)
517
  reachable = len(depth)
518
  unreachable = [r.name for r in fp.rooms if id(r) not in depth]
519
+ entry = _entry_room(fp)
520
+ # nodes: (name, centroid x, centroid y, reachable?, is-entry?, hop depth)
521
+ nodes = [(r.name, r.cx, r.cy, id(r) in depth, r is entry,
522
+ depth.get(id(r), -1)) for r in fp.rooms]
523
+ edges = [(i, j) for i in range(len(fp.rooms))
524
+ for j in range(i + 1, len(fp.rooms))
525
+ if _connected(fp.rooms[i], fp.rooms[j])]
526
  return reachable / len(fp.rooms), {
527
  "reachable": reachable, "total": len(fp.rooms),
528
+ "unreachable": unreachable, "nodes": nodes, "edges": edges}
529
 
530
 
531
  # ── 8. Room Aspect Ratio ─────────────────────────────────────────────────────
floorplan_editor/frontend/index.html CHANGED
@@ -252,8 +252,10 @@ function draw() {
252
  // eats half its thickness from each room; toggled by the Walls button
253
  if (showWalls) drawWalls();
254
 
255
- // Locked-adjacency walls (bright green on shared walls)
256
- drawLockedLinks();
 
 
257
 
258
  // Handles for the selected room
259
  if (selIdx>=0 && selIdx<rooms.length) {
 
252
  // eats half its thickness from each room; toggled by the Walls button
253
  if (showWalls) drawWalls();
254
 
255
+ // Locked-adjacency indicator (bright green on shared walls). Hidden while the
256
+ // Walls overlay is on, so walls read as ONE uniform material throughout
257
+ // rather than a green/black mix.
258
+ if (!showWalls) drawLockedLinks();
259
 
260
  // Handles for the selected room
261
  if (selIdx>=0 && selIdx<rooms.length) {