-
Notifications
You must be signed in to change notification settings - Fork 0
/
go2opl
executable file
·139 lines (108 loc) · 3.36 KB
/
go2opl
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
#!/usr/bin/perl -W
use strict qw(vars subs);
use Getopt::Long;
use POSIX;
use Pod::Usage;
############################################################
#################### read command line options #######################
############################################################
my $verbose, my $help, my $man;
# read command line options
my $status=GetOptions(
#misc options
"verbose!" => \$verbose,
'help' => \$help,
'man' => \$man
# #generator options
# "jobs=i" => sub {
# die("The number of jobs is already defined.\n") if defined $nJobs;
# $nJobs = $_[1];
# die("The number of jobs must be strictly positive.\n") if defined $nJobs <= 0;
# },
# "machines=i" => sub {
# die("The number of machines is already defined.\n") if defined $mMachines;
# $mMachines = $_[1];
# die("The number of machines must be strictly positive.\n") if defined $mMachines <= 0;
# },
# "step!" => \$stepMode
);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
$status == 1 or pod2usage(2);
############################################################
#################### Main script ################################
############################################################
sub nextLine {
my $IN = shift;
my $OUT = shift;
while (<$IN>) {
if (s/^\s*#\s*/\/\//) {
print $OUT $_;
}
else
{
chomp;
return $_ ;
}
}
die "unable to read next line";
}
foreach my $infile (@ARGV)
{
my $outfile=$infile;
$outfile=~ s/(\.[^\.]+)$/-opl$1/;
open IN, "<$infile" or die "unable to open $infile: $!";
open OUT, ">$outfile" or die "unable to open $outfile: $!";
my $nbJobs = &nextLine(\*IN, \*OUT);
print OUT "NbJobs=$nbJobs;\n";
my $line = &nextLine(\*IN, \*OUT);
print OUT "MachineCapacity=$line;\n";
print OUT "//<duration, size, weight, due-date>\nJobData = [\n";
for (my $i=1; $i<=$nbJobs;$i++) {
$line = &nextLine(\*IN, \*OUT);
$line =~s/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/<$1, $2, $3, $4>/;
print OUT $line;
print OUT "," if ($i<$nbJobs);
print OUT "\n";
}
print OUT "];\n";
while (<IN>) {
if (s/^\s*#\s*/\/\//) {
print OUT $_;
}
elsif (! /^\s*$/)
{
chomp;
die "Invalid file format: $infile \n>> $_\n";
}
}
close IN or die "unable to close $infile: $!";
close OUT or die "unable to close $outfile: $!";
print "Generate $outfile [OK]\n" if $verbose;
}
############################################################
#################### Pod documentation ############################
############################################################
__END__
=pod
=head1 NAME
go2opl - convert each instance FILE to OPL format.
=head1 SYNOPSIS
go2opl [options] -- FILE...
=head1 OPTIONS
=over 8
=item B<-verbose>
Activate verbose mode.
=item B<-help>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=head1 REPORT BUGS
Report bugs to <arnaud (dot) malapert (at) unice (dot) fr>.
=head1 COPYRIGHT
Copyright (C) 2011 Arnaud Malapert. This program is free software: you
can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
=cut