-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextract_plan.pl
85 lines (65 loc) · 1.5 KB
/
extract_plan.pl
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
# Find the solution number.
open FILE, "result" or die $!;
@lines = <FILE>;
close FILE;
open OUT, ">slimm_result_tmp" or die $!;
sub GetNextSolutionNr {
my ($line_nr) = @_;
print "GetNextSolutionNr: $line_nr\n";
# Search for the given plan number.
for ($i = $line_nr; $i > -1; $i--) {
if ($lines[$i] =~ m/\*\*\* Current plan:/) {
if ($lines[$i + 1] =~ m/Plan: \[(\d+)\]/) {
return $1;
}
}
}
return 0;
}
sub ExtractPlan {
my ($plan_number, $line_nr) = @_;
@tmp = ();
print "ExtractPlan: $plan_number $line_nr\n";
# Search for the given plan number.
for ($i = $line_nr; $i > -1; $i--) {
$line = $lines[$i];
if ($line =~ m/Plan: \[$plan_number\]/) {
for (; $i < $#lines; $i++) {
$line = $lines[$i];
#print OUT "$line";
push(@tmp, $line);
if ($line =~ m/Orderings.*/) {
# Print everything backwards.
for ($j = $#tmp; $j > -1; $j--) {
print OUT $tmp[$j];
}
return $i;
}
}
}
}
return 0;
}
# Start reading the file and search for the line 'Sulution!'
for ($i = $#lines; $i > -1; $i--) {
$line = $lines[$i];
if ($line =~ m/Solution\! Plan: \[(\d+)\]/)
{
$solution_number = $1;
while ((my $line_nr = &ExtractPlan($solution_number, $i)) != 0) {
$solution_number = &GetNextSolutionNr($line_nr);
}
last;
}
}
# Reverse the file.
close OUT;
open OUTM, "<slimm_result_tmp" or die $!;
@lines = reverse <OUTM>;
close OUTM;
open OUTR, ">slimm_result" or die $!;
foreach $line (@lines) {
print OUTR $line;
}
close OUTR;
print "Done";