@@ -283,6 +283,11 @@ <h5 class="step-title">Topology generation</h5>
283
283
</ select >
284
284
< input type ="number " class ="form-control " id ="predefined-topology-nodes "
285
285
placeholder ="Number of nodes " min ="1 " value ="3 " oninput ="greaterthan0(this) " style ="display: inline; width: 40% ">
286
+ < div id ="random-topology-options " style ="display: none; margin-top: 10px; ">
287
+ < label for ="random-probability "> Edge Probability:</ label >
288
+ < input type ="number " class ="form-control " id ="random-probability "
289
+ placeholder ="Probability (0-1) " min ="0 " max ="1 " step ="0.1 " value ="0.5 " style ="display: inline; width: 40% ">
290
+ </ div >
286
291
</ div >
287
292
</ div >
288
293
< div class ="form-group row container-shadow tiny grey ">
@@ -2355,6 +2360,7 @@ <h5 class="step-title">Schema of deployment</h5>
2355
2360
2356
2361
2357
2362
if ( $ ( "#predefined-topology-select" ) . val ( ) === 'Fully' ) {
2363
+ $ ( "#random-topology-options" ) . hide ( ) ;
2358
2364
// Update gData: create a link between each node
2359
2365
for ( var i = 0 ; i < gData . nodes . length ; i ++ ) {
2360
2366
for ( var j = 0 ; j < gData . nodes . length ; j ++ ) {
@@ -2366,6 +2372,7 @@ <h5 class="step-title">Schema of deployment</h5>
2366
2372
}
2367
2373
// If networkTopology is changed to Ring, gData is updated to a ring graph
2368
2374
else if ( $ ( "#predefined-topology-select" ) . val ( ) === 'Ring' ) {
2375
+ $ ( "#random-topology-options" ) . hide ( ) ;
2369
2376
// Update gData: create a link between each node and its two neighbors
2370
2377
for ( var i = 0 ; i < gData . nodes . length ; i ++ ) {
2371
2378
gData . links . push ( { source : i , target : ( i + 1 ) % gData . nodes . length } ) ;
@@ -2374,19 +2381,24 @@ <h5 class="step-title">Schema of deployment</h5>
2374
2381
}
2375
2382
// If networkTopology is changed to Star, gData is updated to a star graph
2376
2383
else if ( $ ( "#predefined-topology-select" ) . val ( ) === 'Star' ) {
2384
+ $ ( "#random-topology-options" ) . hide ( ) ;
2377
2385
// Update gData: create a link between each node and the central node
2378
2386
for ( var i = 0 ; i < gData . nodes . length ; i ++ ) {
2379
2387
gData . links . push ( { source : i , target : 0 } ) ;
2380
2388
}
2381
2389
} else if ( $ ( "#predefined-topology-select" ) . val ( ) === 'Random' ) {
2382
- // Update gData: create a link between each node and a random node
2383
- for ( var i = 0 ; i < gData . nodes . length ; i ++ ) {
2384
- var randomNode = Math . floor ( Math . random ( ) * gData . nodes . length ) ;
2385
- while ( randomNode === i ) {
2386
- randomNode = Math . floor ( Math . random ( ) * gData . nodes . length ) ;
2387
- }
2388
- gData . links . push ( { source : i , target : randomNode } ) ;
2389
- }
2390
+ // Show probability input
2391
+ $ ( "#random-topology-options" ) . show ( ) ;
2392
+ const probability = parseFloat ( $ ( "#random-probability" ) . val ( ) ) ;
2393
+
2394
+ // Clear existing links
2395
+ gData . links = [ ] ;
2396
+
2397
+ // Generate random links using Erdős-Rényi model
2398
+ gData . links = generateRandomLinks ( gData . nodes , probability ) ;
2399
+ } else {
2400
+ // Hide probability input
2401
+ $ ( "#random-topology-options" ) . hide ( ) ;
2390
2402
}
2391
2403
2392
2404
if ( document . getElementById ( "predefined-topology-nodes" ) . value > 10 ) {
0 commit comments