"docs/vscode:/vscode.git/clone" did not exist on "9c161d1d040e83c65b934b5a1312c17899e9b565"
gexpand.pl 1.1 KB
Newer Older
lisj's avatar
lisj committed
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
#!/usr/bin/perl -w

die "Usage $0 <gfile> <ncopies>\n" unless @ARGV == 2;

$filein  = shift(@ARGV);
$ncopies = shift(@ARGV);

open(FPIN, "<$filein") or die "Could not open $filein. $!\n";

$_ = <FPIN>;
chomp($_);
($nvtxs, $nedges) = split(' ', $_);

#print "nvtxs: $nvtxs, nedges: $nedges\n";

$u = 1;
while (<FPIN>) {
  chomp($_);
  @edges = split(' ', $_);

  # put the within layer edges
  foreach $v (@edges) {
    next if $v < $u;
    for ($i=0; $i<$ncopies; $i++) {
      printf("%d %d\n", $i*$nvtxs+$u-1, $i*$nvtxs+$v-1);
      printf("%d %d\n", $i*$nvtxs+$v-1, $i*$nvtxs+$u-1);
    }
  }

  # put the vertex across layer edges
  for ($i=0; $i<$ncopies-1; $i++) {
    printf("%d %d\n", $i*$nvtxs+$u-1, ($i+1)*$nvtxs+$u-1);
    printf("%d %d\n", ($i+1)*$nvtxs+$u-1, $i*$nvtxs+$u-1);
  }

  # put the adjacent across layer edges
  for ($i=0; $i<$ncopies-1; $i++) {
    $j=0;
    foreach $v (@edges) {
      $j++;
      next if (($j+$i)%2 == 0);
      printf("%d %d\n", $i*$nvtxs+$u-1, ($i+1)*$nvtxs+$v-1);
      printf("%d %d\n", ($i+1)*$nvtxs+$v-1, $i*$nvtxs+$u-1);
    }
  }

  goto DONE;

DONE:
  $u++;
}

close(FPIN);