File: central_path_program.pl

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (56 lines) | stat: -rw-r--r-- 2,358 bytes parent folder | download | duplicates (5)
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
# prints a progressbar
# @param Int got : the amount of stuff you have already got
# @param Int total : the total amount of stuff
# @param Int width : the width of the progressbar
# @param Char char : a character which symbolize done stuff
# @param String text : additional text behind the bar.
sub progress_bar {
    my ( $got, $total, $width, $char, $text) = @_;
    local $| = 1;
    printf "|%-${width}s| $got/$total | %-80s \r",
    $char x (($width)*$got/$total). '>', $text;
}

# initialize the central path polytope from 'Long and winding central paths'
# take the defining inequalities from page 18 (arxiv version)
# @param Int r parameter for the number of inequalities and variables
sub fill_inequalities_cpp($) {
    my ($r) = @_;  
 
    my $time;

    # homo. , u_0 , v_0, ... , u_r , v_r 
    my $m = new Matrix<ValuatedRationalFunction<Max, Rational, Rational> >(3*$r+4, 2*$r+3);
    my $t=new UniMonomial<Rational,Rational>(1);
    
    $m->elem(0,0)=$t;    $m->elem(0,1)   =-1; # u_0 =< t
    $m->elem(1,0)=$t*$t; $m->elem(1,2) = -1;  # v_0 =< t^2

    for (my $i=1; $i < $r+1; ++$i) {
	my $s = new UniMonomial<Rational,Rational>(1-1/(2**$i));
	$m->elem(3*$i-1,2*$i-1) = $t; $m->elem(3*$i-1,2*$i+1) = -1;                            # u_i =< t*u_(i-1)
	$m->elem(3*$i,2*$i) = $t;     $m->elem(3*$i,2*$i+1) = -1;                              # u_i =< t*v_(i-1)
	$m->elem(3*$i+1,2*$i+2) = -1; $m->elem(3*$i+1,2*$i-1)= $s; $m->elem(3*$i+1,2*$i) = $s; # v_i =< s*( u_(i-1)+v_(i-1) )
    }
    
    $m->elem(3*$r+2, 2*$r+1) = 1; # u_r >= 0
    $m->elem(3*$r+3, 2*$r+2) = 1; # v_r >= 0

    return new Polytope<ValuatedRationalFunction<Max, Rational, Rational> >(INEQUALITIES=>$m);
}

sub test_example_paper {
    my $cpp1 = fill_inequalities_cpp(1);
    my $F1 = $cpp1->FACETS;
    my $V1 = $cpp1->VERTICES;
    
    my $ts = new UniMonomial<Rational, Rational>(2);
    my $tt = new UniMonomial<Rational, Rational>(3/2);
    my $tr = new UniMonomial<Rational, Rational>(5/2);

    my $ww = new Vector<ValuatedRationalFunction<Max, Rational, Rational>>([1,0,$ts,0,$tt]);
    my $vv = new Vector<ValuatedRationalFunction<Max, Rational, Rational>>([1,0,$ts,0,$tr]);
    print "FACETS:\n$F1\nVERTICES:\n$V1\n\nevaluation of the vertex $ww from the paper:\n",$F1*$ww,"\n\nevaluation of the vertex $vv computed by polymake:\n",$F1*$vv;
}