acmpesuecc / acmpesuecc/traffic_simulation

Bug in propagation algorithm for updates

Đang mở
#10 49 bình luận 0 reaction 0 người được giao Xem trên GitHub
BOUNTY:150 hacknight-2025 hacktoberfest
Ngôn ngữ chính
Python
Star
1
Fork
13
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

# 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

---

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.