2018-06-18 15:35:05 +00:00
|
|
|
#!/bin/perl
|
|
|
|
|
2018-06-18 14:32:53 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use List::Util qw/shuffle/;
|
|
|
|
|
2018-06-18 15:35:05 +00:00
|
|
|
die "Usage : generate.pl agents_number [floor_number]\nagents number range from 2 to 500\n" if @ARGV == 0;
|
|
|
|
my $total_nb = $ARGV[0];
|
|
|
|
die "Error : stupid amount of agents ($total_nb)\n" if $total_nb < 2;
|
|
|
|
my $visitors_nb = int($total_nb / 2);
|
|
|
|
my $residents_nb = $total_nb - $visitors_nb;
|
|
|
|
my $floor_number = @ARGV > 2 ? $ARGV[1] : 25;
|
|
|
|
|
|
|
|
my $visitors_output_file_name = "visitors.txt";
|
|
|
|
my $residents_output_file_name = "residents.txt";
|
2018-06-18 14:32:53 +00:00
|
|
|
my $visitors_db_filename = "visitors.db";
|
|
|
|
my $residents_db_filename = "residents.db";
|
|
|
|
my @visitors = ();
|
|
|
|
my @residents = ();
|
2018-06-18 15:35:05 +00:00
|
|
|
|
2018-06-18 14:32:53 +00:00
|
|
|
|
|
|
|
open(my $visitors_db_file, $visitors_db_filename) or die "Error : no visitors database found \n";
|
|
|
|
|
|
|
|
open(my $residents_db_file, $residents_db_filename) or die "Error : no residents database found \n";
|
|
|
|
|
|
|
|
while(my $line = <$visitors_db_file>){
|
2018-06-18 15:35:05 +00:00
|
|
|
chomp($line);
|
2018-06-18 14:32:53 +00:00
|
|
|
push(@visitors, $line);
|
|
|
|
}
|
|
|
|
while(my $line = <$residents_db_file>){
|
2018-06-18 15:35:05 +00:00
|
|
|
chomp($line);
|
|
|
|
push(@residents, $line) if(@residents < $residents_nb);
|
2018-06-18 14:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
die "Database is not big enough for $visitors_nb visitors\n" if @visitors < $visitors_nb;
|
|
|
|
die "Database is not big enough for $residents_nb residents" if @residents < $residents_nb;
|
|
|
|
|
|
|
|
@visitors = shuffle(@visitors);
|
|
|
|
@residents = shuffle(@residents);
|
|
|
|
|
2018-06-18 15:35:05 +00:00
|
|
|
open(my $visitors_output_file, '>', $visitors_output_file_name) or die "Error : couldn't create visitors output file.";
|
|
|
|
open(my $residents_output_file, '>', $residents_output_file_name) or die "Error : couldn't create residents output file.";
|
2018-06-18 14:32:53 +00:00
|
|
|
|
2018-06-18 15:35:05 +00:00
|
|
|
|
|
|
|
for(my $i = 0; $i < $visitors_nb; $i += 1){
|
|
|
|
print $visitors_output_file $visitors[$i] . ";" .
|
|
|
|
$residents[rand $residents_nb] . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
for(my $i = 0; $i < $residents_nb; $i += 1){
|
|
|
|
print $residents_output_file $residents[$i] . ";" .
|
|
|
|
(int(rand(25)) + 1) . ";" .
|
|
|
|
(int(rand(25 + 1))) . "\n";
|
2018-06-18 14:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close $visitors_db_file;
|
|
|
|
close $residents_db_file;
|
2018-06-18 15:35:05 +00:00
|
|
|
close $visitors_output_file;
|
|
|
|
close $residents_output_file;
|
2018-06-18 14:32:53 +00:00
|
|
|
|