-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcyclic_chain_polytopes
executable file
·94 lines (85 loc) · 1.69 KB
/
cyclic_chain_polytopes
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
#!/opt/homebrew/bin/perl
use strict;
use warnings;
use feature qw(say);
print "type anything to star the interactive shell";
while (<STDIN>) {
say "What is n?";
my $n = <STDIN>;
chomp $n;
last if $n eq '';
say "What are the (maximal) chains?";
my @arr;
my $count = 0;
while (my $line=<>) {
chomp($line);
last if $line eq '';
push(@arr, [split(',',$line)]);
}
sub chains_to_polytope1 {
my @chains = @_;
my @arr = map [(0) x ($n+1)], 1..@chains+2*$n;
for (my $i = 0; $i < $n; $i++) {
$arr[$i][$i+1] = 1;
$arr[$i+$n][0] = 1;
$arr[$i+$n][$i+1] = -1;
}
my $count = 2*$n;
foreach my $c (@chains) {
foreach my $entry (@$c) {
$arr[$count][0] = 1;
$arr[$count][$entry] = -1;
}
$count++;
}
return @arr;
}
sub right_circ_des {
my @Y = @_;
my $size = @Y;
my $a = $Y[0];
my $b = 0;
my $cdesr = 0;
for (my $i = 1; $i < $size; $i++) {
if (($i == $size-1) & ($Y[$i] > $Y[0])) {
$cdesr++;
last;
}
$b = $Y[$i];
if ($a > $b) {
$cdesr++;
}
$a = $b;
}
return $cdesr;
}
#sub chains_to_polytope2 {
# my @chains = @_;
# my @arr = map [(0) x ($n+1)], 1..@chains+2*$n;
# for (my $i = 0; $i < $n; $i++) {
# $arr[$i][$i+1] = 1;
# $arr[$i+$n][0] = 1;
# $arr[$i+$n][$i+1] = -1;
# }
# my $count = 2*$n;
# foreach my $c (@chains) {
# $arr[$count][0] = right_circ_des(@$c);
# foreach my $entry (@$c) {
# $arr[$count][$entry] = -1;
# }
# $count++;
# }
# return @arr;
#}
sub print_matrix {
my @arr = @_;
for my $row (@arr) {
say('['.join(',', @$row).'],');
}
}
say "Flow polytope / Stanley's chain polytope construction:";
print_matrix(chains_to_polytope1(@arr));
# say "dual to Lauren's construction:";
# print_matrix(chains_to_polytope2(@arr));
}
1;