📄 run-simulations.pl
字号:
if( !defined $randomize ) { foreach my $val (@args) { $val = &check_dependent( $argname, $val, $args_so_far ); if( !&check_conditions( $argname, $val, $args_so_far ) ) { next; } my $arg_string = $args_so_far . "$argname=$val "; if( $arg_iter == $#argnames+1 ) { # it's the last argument, so just run the test &run_command( $arg_string ); } else { # recurse again &run_sim( $arg_string, $arg_iter ); } } } else { # pick a random value and recurse my $val = $args[int(rand($#args+1))]; if( !defined $val ) { die( "value not defined" ) }; $val = &check_dependent( $argname, $val, $args_so_far ); if( &check_conditions( $argname, $val, $args_so_far ) ) { my $arg_string = $args_so_far . "$argname=$val "; if( $arg_iter == $#argnames+1 ) { # it's the last argument, so just run the test if( &run_command( $arg_string ) ) { $randomize--; } } else { # recurse again &run_sim( $arg_string, $arg_iter ); } } }}sub check_conditions { my $arg = shift; my $val = shift; my $arg_string = shift; if( defined $conditions{$arg} ) { my @conds = split( /\s+/, $conditions{$arg} ); foreach my $cond (@conds) { if( $cond =~ /^\<(\w*)$/ ) { my $oarg = $1; if( $arg_string =~ /$oarg\=(\d*)/ ) { if( $val >= $1 ) { return 0; } } else { die( "condition doesn't match: $cond, $arg_string" ); } } elsif( $cond =~ /^\<\=(\w*)$/ ) { my $oarg = $1; if( $arg_string =~ /$oarg=(\d*)/ ) { if( $val > $1 ) { return 0; } } else { die( "condition doesn't match: $cond, $arg_string" ); } } elsif( $cond =~ /^\>(\w*)$/ ) { my $oarg = $1; if( $arg_string =~ /$oarg=(\d*)/ ) { if( $val <= $1 ) { return 0; } } else { die( "condition doesn't match: $cond, $arg_string" ); } } } } return 1;}sub check_dependent { my $arg = shift; my $val = shift; my $arg_string = shift; if( defined $dependent{$arg} ) { my $dep = $dependent{$arg}; if( $dep =~ /^\=(\w*)$/ ) { my $oarg = $1; if( $arg_string =~ /$oarg\=(\d*)/ ) { return $1; } else { die( "dep doesn't match: $dep, $arg_string" ); } } elsif( $dep =~ /^\+(\w*)$/ ) { my $oarg = $1; if( $arg_string =~ /$oarg=(\d*)/ ) { return $1 + $val; } else { die( "dep doesn't match: $dep, $arg_string" ); } } elsif( $dep =~ /^\*(\w*)$/ ) { my $oarg = $1; if( $arg_string =~ /$oarg=(\d*)/ ) { return $1*$val; } else { die( "dep doesn't match: $dep, $arg_string" ); } } else { die( "unrecognized dep: $dep" ); } } return $val;}sub run_command { my $arg_string = shift; my @splitargs = split( /\s+/, $arg_string ); my $label = ""; my $i = 0; my %labelhash = (); foreach my $a (@splitargs) { my @val = split( /=/, $a ); if( $val[0] eq "topology" ) { $label .= $val[1]; $topology =~ s/(\d+)([^\d]*)$/$val[1]$2/; } else { $label .= $val[1]; } $labelhash{$val[0]} = $val[1]; if( $i != $#splitargs ) { $label .= "-"; } $i++; } # if no command line arguments are specified for event stuff, see # if the protocol file had these params my $lomean = $lookupmean; my $limean = $lifemean; my $dmean = $deathmean; my $paret = $pareto; my $unifor = $uniform; my $alph = $alpha; my $bet = $beta; my $etime = $exittime; my $stime = $stattime; my $randseed = $seed; if( !defined $options{"lookupmean"} && defined $labelhash{"lookupmean"}) { $lomean = $labelhash{"lookupmean"}; } if( !defined $options{"lifemean"} && defined $labelhash{"lifemean"}) { $limean = $labelhash{"lifemean"}; } if( !defined $options{"deathmean"} && defined $labelhash{"deathmean"}) { $dmean = $labelhash{"deathmean"}; } if( !defined $options{"exittime"} && defined $labelhash{"exittime"}) { $etime = $labelhash{"exittime"}; } if( !defined $options{"stattime"} && defined $labelhash{"stattime"}) { $stime = $labelhash{"stattime"}; } if( !defined $options{"seed"} && defined $labelhash{"seed"}) { $randseed = $labelhash{"seed"}; } elsif( !defined $options{"seed"} ) { $randseed = int 1000000 * rand(); } if (!defined $options{"paret"} & defined $labelhash{"pareto"}) { $paret = $labelhash{"pareto"}; } if (!defined $options{"uniform"} & defined $labelhash{"uniform"}) { $unifor = $labelhash{"uniform"}; } if (!defined $options{"alpha"} & defined $labelhash{"alpha"}) { $alph = $labelhash{"alpha"}; } if (!defined $options{"beta"} & defined $labelhash{"beta"}) { $bet = $labelhash{"beta"}; } if ($unifor) { $paret = 0; } &write_events_file( $lomean, $limean, $dmean, $paret, $unifor, $alph, $bet, $etime, $stime ); my $protfile = "$logdir/run-simulations-tmp-prot$$"; open( PF, ">$protfile" ) or die( "Couldn't write to $protfile" ); print PF "$protocol $arg_string initstate=1\n"; close( PF ); # now run it my $logfile = "$logdir/$protocol-$label.log"; if( -f $logfile ) { return 0; } open( LOG, ">$logfile" ) or die( "Couldn't open $logfile" ); print LOG "# lookupmean=$lomean lifemean=$limean " . "deathmean=$dmean file=$churnfile exit=$etime stat=$stime\n"; print LOG "# topology=$topology seed=$randseed\n"; close( LOG ); #print "$p2psim_cmd $protfile $topology $eventfile >> $logfile"; my $before = time(); my $failexit = 0; print "# $arg_string randseed $randseed > $logfile \n"; $failexit = system( "$p2psim_cmd -e $randseed $protfile $topology " . "$eventfile >> $logfile 2>> $logfile" ); if (($failexit) && (!$dontdie)) { die( "$p2psim_cmd $protfile $topology $eventfile failed" ); } my $complete_time = time() - $before; print "# completed in $complete_time seconds\n"; unlink( $protfile ); return 1;}sub write_events_file { my $lookupmean = shift; my $lifemean = shift; my $deathmean = shift; my $pareto = shift; my $uniform = shift; my $alpha = shift; my $beta = shift; my $exittime = shift; my $stattime = shift; # now write the events file to use open( EF, ">$eventfile" ) or die( "Couldn't write to $eventfile" ); my $eg_type = "ChurnEventGenerator"; if( $churnfile ne "" ) { $eg_type = "ChurnFileEventGenerator"; } my $datakeys = 0; if (defined $options{"datakey"}) { $datakeys = $options{"datakey"}; } my $ipkeys = 0; if (defined $options{"ipkey"}) { $ipkeys = $options{"ipkey"}; }elsif( $protocol eq "Kademlia" or $protocol eq "Kelips") { $ipkeys = 1; } die "ipkeys and datakeys are mutually exclusive\n" if ($ipkeys and $datakeys); print EF "generator $eg_type ipkeys=$ipkeys datakeys=$datakeys " . "lifemean=$lifemean deathmean=$deathmean lookupmean=$lookupmean pareto=$pareto alpha=$alpha beta=$beta uniform=$uniform " . "exittime=$exittime stattime=$stattime"; if( $churnfile ne "" ) { print EF "file=$churnfile"; } print EF "\n"; if( $withobserver ) { print EF "observer $observer initnodes=1 oracle=1\n"; } close( EF );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -