Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/**
* Analytical Preview - Shows Jackson's theorem calculations BEFORE simulation
*/
import { useEffect, useState } from 'react';
import {
Box,
Typography,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Alert,
AlertTitle,
CircularProgress,
Divider,
} from '@mui/material';
import {
CheckCircle as CheckCircleIcon,
Warning as WarningIcon,
Error as ErrorIcon,
Assessment as AssessmentIcon,
} from '@mui/icons-material';
import { useSimulationStore } from '../../store/simulationStore';
import { formatTime, formatRate } from '../../utils/timeFormat';
import api from '../../services/api';
import type { NetworkAnalytics } from '../../types/simulation';
export default function AnalyticalPreview() {
const { config, timeUnit } = useSimulationStore();
const [analytics, setAnalytics] = useState<NetworkAnalytics | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!config) {
setAnalytics(null);
return;
}
const fetchAnalytics = async () => {
try {
setLoading(true);
setError(null);
const result = await api.analyzeWithJackson(config);
setAnalytics(result);
} catch (err) {
setError(err instanceof Error ? err.message : 'Erreur de calcul analytique');
} finally {
setLoading(false);
}
};
fetchAnalytics();
}, [config]);
if (!config) {
return null;
}
if (loading) {
return (
<Paper sx={{ p: 3 }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<CircularProgress size={24} />
<Typography>Calcul analytique en cours...</Typography>
</Box>
</Paper>
);
}
if (error) {
return (
<Paper sx={{ p: 3 }}>
<Alert severity="error">
<AlertTitle>Erreur</AlertTitle>
{error}
</Alert>
</Paper>
);
}
if (!analytics) {
return null;
}
return (
<Paper sx={{ p: 3 }}>
<Typography variant="h6" gutterBottom sx={{ fontWeight: 600, mb: 2, display: 'flex', alignItems: 'center', gap: 1 }}>
<AssessmentIcon /> Analyse Théorique (Théorème de Jackson)
</Typography>
{/* Stability Alert */}
<Alert
severity={analytics.is_stable ? 'success' : 'error'}
icon={analytics.is_stable ? <CheckCircleIcon /> : <ErrorIcon />}
sx={{ mb: 3 }}
>
<AlertTitle>
{analytics.is_stable ? 'Système Stable' : 'Système Instable'}
</AlertTitle>
{analytics.instability_reason && (
<Typography variant="body2">{analytics.instability_reason}</Typography>
)}
</Alert>
{/* Global Metrics */}
<Box sx={{ mb: 3 }}>
<Typography variant="subtitle2" fontWeight={600} gutterBottom>
Métriques Globales du Réseau
</Typography>
<Box sx={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 2, mt: 1 }}>
<Paper variant="outlined" sx={{ p: 2, bgcolor: 'primary.50' }}>
<Typography variant="caption" color="text.secondary">
Nombre moyen de clients (L)
</Typography>
<Typography variant="h5" fontWeight={600}>
{analytics.total_average_customers.toFixed(4)}
</Typography>
<Typography variant="caption" color="text.secondary">
clients dans le système
</Typography>
</Paper>
<Paper variant="outlined" sx={{ p: 2, bgcolor: 'primary.50' }}>
<Typography variant="caption" color="text.secondary">
Temps moyen (W)
</Typography>
<Typography variant="h5" fontWeight={600}>
{formatTime(analytics.total_average_time, timeUnit)}
</Typography>
<Typography variant="caption" color="text.secondary">
temps dans le système
</Typography>
</Paper>
</Box>
</Box>
<Divider sx={{ my: 3 }} />
{/* Coordinator Details */}
<Box sx={{ mb: 3 }}>
<Typography variant="subtitle2" fontWeight={600} gutterBottom sx={{ color: 'primary.main' }}>
🔵 COORDINATEUR
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow sx={{ bgcolor: 'grey.100' }}>
<TableCell sx={{ fontWeight: 600 }}>Paramètre</TableCell>
<TableCell sx={{ fontWeight: 600 }}>Symbole</TableCell>
<TableCell align="right" sx={{ fontWeight: 600 }}>Valeur</TableCell>
<TableCell sx={{ fontWeight: 600 }}>Description</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow sx={{ bgcolor: 'info.50' }}>
<TableCell>Arrivée externe</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>λ</Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatRate(config.arrival_rate, timeUnit)}
</Typography>
</TableCell>
<TableCell>Taux d'arrivée externe (Poisson)</TableCell>
</TableRow>
<TableRow>
<TableCell>Probabilité de sortie</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>p</Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{config.coordinator_exit_probability.toFixed(3)}
</Typography>
</TableCell>
<TableCell>Clients sortant après le coordinateur</TableCell>
</TableRow>
<TableRow sx={{ bgcolor: 'warning.50' }}>
<TableCell>Taux effectif coordinateur</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>γ<sub>0</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatRate(analytics.coordinator.arrival_rate, timeUnit)}
</Typography>
</TableCell>
<TableCell>λ / p (externe + retours des serveurs)</TableCell>
</TableRow>
<TableRow>
<TableCell>Taux de service</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>μ<sub>c</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatRate(analytics.coordinator.service_rate, timeUnit)}
</Typography>
</TableCell>
<TableCell>Capacité de service du coordinateur</TableCell>
</TableRow>
<TableRow sx={{ bgcolor: 'warning.50' }}>
<TableCell>Utilisation</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>ρ<sub>c</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace" fontWeight={600}>
{analytics.coordinator.utilization.toFixed(4)}
</Typography>
</TableCell>
<TableCell>
{analytics.coordinator.utilization < 1 ? (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<CheckCircleIcon fontSize="small" color="success" />
<Typography variant="caption">Stable (ρ < 1)</Typography>
</Box>
) : (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<WarningIcon fontSize="small" color="error" />
<Typography variant="caption">Instable (ρ ≥ 1)</Typography>
</Box>
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Nombre moyen clients</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>L<sub>c</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{(analytics.coordinator.average_customers ?? 0).toFixed(4)}
</Typography>
</TableCell>
<TableCell>Clients dans le coordinateur (file + service)</TableCell>
</TableRow>
<TableRow>
<TableCell>Temps moyen système</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>W<sub>c</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatTime(analytics.coordinator.average_time ?? 0, timeUnit)}
</Typography>
</TableCell>
<TableCell>Attente + Service</TableCell>
</TableRow>
<TableRow>
<TableCell>Temps d'attente</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>W<sub>q,c</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatTime(analytics.coordinator.average_wait_time ?? 0, timeUnit)}
</Typography>
</TableCell>
<TableCell>Temps dans la file seulement</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</Box>
{/* Servers Details */}
{Object.entries(analytics.servers).map(([serverId, serverAnalytics], index) => (
<Box key={serverId} sx={{ mb: 3 }}>
<Typography variant="subtitle2" fontWeight={600} gutterBottom sx={{ color: 'secondary.main' }}>
🟢 SERVEUR {index + 1}
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow sx={{ bgcolor: 'grey.100' }}>
<TableCell sx={{ fontWeight: 600 }}>Paramètre</TableCell>
<TableCell sx={{ fontWeight: 600 }}>Symbole</TableCell>
<TableCell align="right" sx={{ fontWeight: 600 }}>Valeur</TableCell>
<TableCell sx={{ fontWeight: 600 }}>Description</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Taux d'arrivée</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>λ<sub>{index + 1}</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatRate(serverAnalytics.arrival_rate, timeUnit)}
</Typography>
</TableCell>
<TableCell>Depuis coordinateur: γ<sub>0</sub> × q<sub>{index + 1}</sub> = (λ / p) × q<sub>{index + 1}</sub></TableCell>
</TableRow>
<TableRow>
<TableCell>Taux de service</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>μ<sub>{index + 1}</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatRate(serverAnalytics.service_rate, timeUnit)}
</Typography>
</TableCell>
<TableCell>Capacité de service du serveur</TableCell>
</TableRow>
<TableRow sx={{ bgcolor: 'warning.50' }}>
<TableCell>Utilisation</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>ρ<sub>{index + 1}</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace" fontWeight={600}>
{serverAnalytics.utilization.toFixed(4)}
</Typography>
</TableCell>
<TableCell>
{serverAnalytics.utilization < 1 ? (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<CheckCircleIcon fontSize="small" color="success" />
<Typography variant="caption">Stable (ρ < 1)</Typography>
</Box>
) : (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
<WarningIcon fontSize="small" color="error" />
<Typography variant="caption">Instable (ρ ≥ 1)</Typography>
</Box>
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Nombre moyen clients</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>L<sub>{index + 1}</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{(serverAnalytics.average_customers ?? 0).toFixed(4)}
</Typography>
</TableCell>
<TableCell>Clients dans le serveur (file + service)</TableCell>
</TableRow>
<TableRow>
<TableCell>Temps moyen système</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>W<sub>{index + 1}</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatTime(serverAnalytics.average_time ?? 0, timeUnit)}
</Typography>
</TableCell>
<TableCell>Attente + Service</TableCell>
</TableRow>
<TableRow>
<TableCell>Temps d'attente</TableCell>
<TableCell>
<Typography fontFamily="monospace" fontWeight={600}>W<sub>q,{index + 1}</sub></Typography>
</TableCell>
<TableCell align="right">
<Typography fontFamily="monospace">
{formatTime(serverAnalytics.average_wait_time ?? 0, timeUnit)}
</Typography>
</TableCell>
<TableCell>Temps dans la file seulement</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</Box>
))}
{/* Formulas Reference */}
<Box sx={{ mt: 3, p: 2, bgcolor: 'info.50', borderRadius: 1 }}>
<Typography variant="caption" fontWeight={600} gutterBottom display="block">
📐 Formules utilisées (Théorème de Jackson):
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace" sx={{ mb: 1, fontWeight: 600 }}>
Équations de trafic (avec boucle de retour):
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace">
• γ<sub>0</sub> = λ + Σγ<sub>i</sub> (coordinateur reçoit externe + retours)
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace">
• γ<sub>i</sub> = q<sub>i</sub> × γ<sub>0</sub> (routage vers serveur i)
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace" sx={{ mb: 1, fontWeight: 600, mt: 1 }}>
Solution: γ<sub>0</sub> = λ / p, γ<sub>i</sub> = (λ / p) × q<sub>i</sub>
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace" sx={{ mb: 1, fontWeight: 600 }}>
Métriques par file M/M/1:
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace">
• ρ = λ/μ (Utilisation)
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace">
• L = ρ/(1-ρ) (Nombre moyen de clients)
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace">
• W = 1/(μ-λ) (Temps moyen dans le système)
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace">
• W<sub>q</sub> = W - 1/μ (Temps d'attente)
</Typography>
<Typography variant="caption" component="div" fontFamily="monospace" sx={{ mt: 1 }}>
• L<sub>total</sub> = Σ L<sub>i</sub> (Loi de Little globale)
</Typography>
</Box>
</Paper>
);
}