acmpesuecc / acmpesuecc/traffic_simulation
Bug in propagation algorithm for updates
- Vorherrschende Sprache
- Python
- Sterne
- 1
- Forks
- 13
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
# Bounty Points: 150
## Branch Instructions
push changes to a new *'propogation'* branch
***
**Explanation:**
* **`num_of_cars()`** function incorrectly calculates car redistribution
* Only counts incoming cars from **one edge** instead of all incoming edges
* **Logic error:** uses `cars_initial[node]` when should use **source node count**
* Distribution ratios applied incorrectly
* Causes **negative car counts** and **simulation errors**
---
### Current buggy code:
```python
def num_of_cars(node):
t = 0
for i in distances:
if i[1] == node:
for j in distribution:
if j == i[0]:
for k in distribution[j]:
if k[0] == node:
t += (cars_initial[node]) * k[1] # BUG: wrong node
t -= (distribution[node][0][1]) * (cars_initial[node])
cars_initial[node] = t
return t
```
### Possible fix/approach:
* For each edge (`source -> target`) where `target == node`:
* Add `cars_initial[source] * distribution[source][target_ratio]`
* Calculate outgoing cars separately
* Formula: **`new_count = current + incoming - outgoing`**
* Ensure **non-negative** car counts
* Fix global state mutation issue
---
### Correct logic (Example):
```python
incoming = sum(cars_initial[src] * ratio
for edge in distances if edge[1] == node
for src, ratio in get_incoming_ratio(edge[0], node))
outgoing = sum(cars_initial[node] * ratio
for dest, ratio in distribution[node] if dest != node)
```
### Maintainer notes:
* **Critical bug** affecting entire simulation accuracy
* Test with simple **2-3 node graphs** first
* Verify **car conservation** (total cars should remain constant)
* Check distribution ratios sum to **1.0**
---
### Resources:
* Traffic flow conservation principles
* Graph theory: flow networks
---
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.