1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2024-11-23 09:13:22 +00:00

Documentation and minor enhancements of scenario generation script

This commit is contained in:
Aethor 2018-06-18 17:49:15 +02:00
parent 4407c99b77
commit ef4e29f7c2

View File

@ -1,15 +1,28 @@
#!/bin/perl
# --- Documentation ---
# Syntax : ./generate.pl agents_number [floor_number]
# agents_number : can specify a number ranging from 2 to 500 ( upgradable by upgrading database ). number of visitors and residents are evenly splitted.
# floor_number : number of floor in building ( not counting floor 0 ), ranging from 1 to whatever number is too big for perl. By default, number of floor is 25.
# the scripts will generate two files : visitors.txt and residents.txt
# visitors.txt syntax : each line is : visitor_name;resident_name\n
# residents.txt syntax : each line is : resident_name;resident_floor;destination_floor\n
# resident_floor is ranging from 1 to floor_number ( implying residents cant live at floor 0 ), while destination_floor is ranging from 0 to floor_number
# written by Arthur Amalvy
# last modification : 18/06/18
use strict;
use warnings;
use List::Util qw/shuffle/;
die "Usage : generate.pl agents_number [floor_number]\nagents number range from 2 to 500\n" if @ARGV == 0;
die "Usage : generate.pl agents_number [floor_number]\nagents number range from 2 to 500\nfloor number range from 1 to +inf\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 $floor_number = @ARGV > 1 ? $ARGV[1] : 25;
die "Error : stupid floor number ($floor_number)\n" if $floor_number < 1;
my $visitors_output_file_name = "visitors.txt";
my $residents_output_file_name = "residents.txt";
@ -49,8 +62,8 @@ for(my $i = 0; $i < $visitors_nb; $i += 1){
for(my $i = 0; $i < $residents_nb; $i += 1){
print $residents_output_file $residents[$i] . ";" .
(int(rand(25)) + 1) . ";" .
(int(rand(25 + 1))) . "\n";
(int(rand($floor_number)) + 1) . ";" .
(int(rand($floor_number + 1))) . "\n";
}
close $visitors_db_file;