feat: Update visualization metrics and enhance product tracking funct…#30
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the MPVRP-CC solution visualizer to parse richer per-segment solution metadata (product states, depot loads, and station deliveries) and use that data to improve exchange/delivery calculations and depot inventory tracking.
Changes:
- Extend
.datsolution parsing to capture product state lines and segment-level metadata (delivery/load quantities). - Update exchange counting and station/depot product accounting to use parsed product states instead of heuristics.
- Add a new sample solution
.datfile; adjust a metric label in the UI; update.gitignorefor a backup file.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
pages/visualisation.html |
Updates the displayed metric label (but currently mismatches the JS metric source). |
pages/static/js/visualisation.js |
Adds parsing and normalization for product lines + segment metadata; updates exchange/delivery and depot inventory logic to use these fields. |
data/solutions/Sol_MPVRP_S_005_s7_d1_p3.dat |
Adds a sample solution file that includes route delivery quantities and product state lines. |
.gitignore |
Ignores a specific backup Python file path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Extract quantity from brackets [qty] (depot load) | ||
| const bracketMatch = raw.match(/\[(\d+(?:\.\d+)?)\]/); | ||
| const loadQty = bracketMatch ? parseFloat(bracketMatch[1]) : 0; | ||
| // Extract quantity from parentheses (station delivery in route line) | ||
| const parenMatch = raw.match(/\(([-+]?\d*\.?\d+)\)/); | ||
| const deliveryQty = parenMatch ? parseFloat(parenMatch[1]) : 0; |
There was a problem hiding this comment.
deliveryQty is defaulted to 0 when no parentheses are present, which makes it impossible to distinguish “no explicit delivery quantity provided” from an explicit “(0)” in the route. This later causes station deliveries to fall back to demand/visits even when the solution explicitly encodes a 0 delivery. Consider storing deliveryQty as null/undefined when no parentheses are present (or keep a separate hasDeliveryQty flag) so downstream logic can respect explicit zeros.
| const explicitDelivery = Number(segMeta.deliveryQty || 0); | ||
| const deliveryQty = explicitDelivery > 0 |
There was a problem hiding this comment.
explicitDelivery > 0 treats an explicit “(0)” delivery the same as “no explicit delivery provided”, which will over-report deliveries by falling back to demand/visits. Use a sentinel (e.g., null) or an explicit flag from parsing so that explicit zeros result in a 0 delivery rather than triggering the fallback.
| const explicitDelivery = Number(segMeta.deliveryQty || 0); | |
| const deliveryQty = explicitDelivery > 0 | |
| let explicitDelivery = null; | |
| if (segMeta.deliveryQty !== undefined && segMeta.deliveryQty !== null && segMeta.deliveryQty !== '') { | |
| const parsedDelivery = Number(segMeta.deliveryQty); | |
| if (!Number.isNaN(parsedDelivery)) { | |
| explicitDelivery = parsedDelivery; | |
| } | |
| } | |
| const deliveryQty = explicitDelivery !== null |
| <div class="metric"> | ||
| <span class="metric-value" id="stat-routing">0.00</span> | ||
| <span class="metric-label">Routing Cost</span> | ||
| <span class="metric-label">Changes Cost</span> |
There was a problem hiding this comment.
The label was changed to “Changes Cost”, but stat-routing is still populated from metrics.routing_cost in visualisation.js. Please align the label/element id with the metric being displayed (either restore “Routing Cost” or update the JS + metric naming so this field truly shows the changes cost).
| <span class="metric-label">Changes Cost</span> | |
| <span class="metric-label">Routing Cost</span> |
…ionality