Arpit-Bansal commited on
Commit
1e393c3
·
1 Parent(s): 9b70565

fix in implementation and docs

Browse files
Files changed (2) hide show
  1. docs/algorithm_equations.md +18 -6
  2. docs/algorithms.md +8 -6
docs/algorithm_equations.md CHANGED
@@ -54,12 +54,16 @@ where $c_{i,s}$ is the cost coefficient for assigning trainset $i$ to state $s$.
54
  **Chromosome Representation:**
55
  $$\mathbf{x} = [x_1, x_2, \ldots, x_n] \quad x_i \in \{0, 1, 2\}$$
56
 
57
- **Fitness Function:**
58
- $$f(\mathbf{x}) = w_r \sum_{i: x_i=0} r_i + w_b \cdot \frac{1}{1 + \sigma_m^2} - w_v \cdot P(\mathbf{x})$$
 
 
 
59
 
60
  where:
61
  - $\sigma_m^2$: mileage variance
62
  - $P(\mathbf{x})$: penalty for constraint violations
 
63
 
64
  **Selection (Tournament):**
65
  $$P(\text{select } \mathbf{x}_i) = \frac{\mathbb{1}_{f(\mathbf{x}_i) = \max_{j \in K} f(\mathbf{x}_j)}}{1}$$
@@ -121,6 +125,9 @@ where:
121
  **Position Update:**
122
  $$\mathbf{x}_i(t+1) = \mathbf{x}_i(t) + \mathbf{v}_i(t+1)$$
123
 
 
 
 
124
  **Discrete Conversion:**
125
  $$x_i = \begin{cases}
126
  0 & \text{if } \text{sigmoid}(\tilde{x}_i) > \text{threshold}_0 \\
@@ -212,11 +219,16 @@ where:
212
 
213
  ## Balance Score (Mileage Variance Minimization)
214
 
215
- $$B = 1 - \frac{\sigma_m}{\sigma_m^{\max}}$$
 
 
 
 
216
 
217
  where:
218
- $$\sigma_m^2 = \frac{1}{|S|} \sum_{i \in S} (m_i - \bar{m})^2$$
219
 
220
  - $S = \{i : x_i = 0\}$: trainsets in service
221
- - $m_i$: mileage of trainset $i$
222
- - $\bar{m} = \frac{1}{|S|}\sum_{i \in S} m_i$: mean mileage
 
 
54
  **Chromosome Representation:**
55
  $$\mathbf{x} = [x_1, x_2, \ldots, x_n] \quad x_i \in \{0, 1, 2\}$$
56
 
57
+ **Fitness Function (to minimize):**
58
+ $$f(\mathbf{x}) = -w_r \sum_{i: x_i=0} r_i - w_b \cdot \frac{1}{1 + \sigma_m^2} + w_v \cdot P(\mathbf{x})$$
59
+
60
+ **Equivalently (to maximize):**
61
+ $$f'(\mathbf{x}) = w_r \sum_{i: x_i=0} r_i + w_b \cdot \frac{1}{1 + \sigma_m^2} - w_v \cdot P(\mathbf{x})$$
62
 
63
  where:
64
  - $\sigma_m^2$: mileage variance
65
  - $P(\mathbf{x})$: penalty for constraint violations
66
+ - Note: Code uses minimization (negative fitness)
67
 
68
  **Selection (Tournament):**
69
  $$P(\text{select } \mathbf{x}_i) = \frac{\mathbb{1}_{f(\mathbf{x}_i) = \max_{j \in K} f(\mathbf{x}_j)}}{1}$$
 
125
  **Position Update:**
126
  $$\mathbf{x}_i(t+1) = \mathbf{x}_i(t) + \mathbf{v}_i(t+1)$$
127
 
128
+ **Velocity Clamping (optional but recommended):**
129
+ $$\mathbf{v}_i(t+1) = \text{clip}(\mathbf{v}_i(t+1), -v_{\max}, v_{\max})$$
130
+
131
  **Discrete Conversion:**
132
  $$x_i = \begin{cases}
133
  0 & \text{if } \text{sigmoid}(\tilde{x}_i) > \text{threshold}_0 \\
 
219
 
220
  ## Balance Score (Mileage Variance Minimization)
221
 
222
+ **Implementation formula (used in code):**
223
+ $$B = 100 - \min\left(\frac{\sigma_m}{1000}, 100\right)$$
224
+
225
+ **Theoretical normalized formula:**
226
+ $$B_{\text{norm}} = 1 - \frac{\sigma_m}{\sigma_m^{\max}}$$
227
 
228
  where:
229
+ $$\sigma_m = \sqrt{\frac{1}{|S|} \sum_{i \in S} (m_i - \bar{m})^2}$$
230
 
231
  - $S = \{i : x_i = 0\}$: trainsets in service
232
+ - $m_i$: mileage of trainset $i$ (in km)
233
+ - $\bar{m} = \frac{1}{|S|}\sum_{i \in S} m_i$: mean mileage
234
+ - Factor 1000 in implementation scales std dev to reasonable range
docs/algorithms.md CHANGED
@@ -276,13 +276,15 @@ def crossover(parent1, parent2):
276
  return child1, child2
277
  ```
278
 
279
- Example:
280
  ```
281
- Parent1: [0, 0, 1, 2, 0, 1]
282
- Parent2: [1, 2, 0, 0, 1, 2]
283
- ↓ crossover at positions 2-4
284
- Child1: [0, 0, 0, 0, 0, 1]
285
- Child2: [1, 2, 1, 2, 1, 2]
 
 
286
  ```
287
 
288
  #### 6. Mutation
 
276
  return child1, child2
277
  ```
278
 
279
+ Example (crossover points at indices 2 and 4):
280
  ```
281
+ Parent1: [0, 0, | 1, 2, | 0, 1]
282
+ Parent2: [1, 2, | 0, 0, | 1, 2]
283
+
284
+ Swap middle section [2:4]
285
+
286
+ Child1: [0, 0, | 0, 0, | 0, 1] ← P1[0:2] + P2[2:4] + P1[4:6]
287
+ Child2: [1, 2, | 1, 2, | 1, 2] ← P2[0:2] + P1[2:4] + P2[4:6]
288
  ```
289
 
290
  #### 6. Mutation