===== ILP and Hilbert bases =====
==== A first example ====
First we will construct a new rational polytope:
> $p=new Polytope
Note that points in ''%%polymake%%'' are always given in homogenous coordinates. I.e., the point (a,b,c) in R3 is represented as ''%%1 a b c%%'' in ''%%polymake%%''.
Now we can examine some properties of ''%%$p%%''. For instance we can determine the number of facets or whether ''%%$p%%'' is simple:
> print $p->N_FACETS;
6
> print $p->SIMPLE;
true
As you might already have noticed, our polytope is just a 3-dimensional cube. So there would have been an easier way to create it using the client ''%%cube%%'':
> $c = cube(3,0);
(You can check out the details of any function in the [[documentation:latest:polytope|documentation]].)
And we can also verify that the two polytopes are actually equal:
> print equal_polyhedra($p,$c);
true
==== Another example ====
Now let us proceed with a somewhat more interesting example: The convex hull of 20 randomly chosen points on the 2-dimensional sphere.
> $rs = rand_sphere(3,20);
''%%polymake%%'' can of course visualise this polytope:
> $rs->VISUAL;
> $lambda=2;
> $s=new Matrix([[1,0,0,0],[0,$lambda,0,0],[0,0,$lambda,0],[0,0,0,$lambda]]);
> print $s;
1 0 0 0
0 2 0 0
0 0 2 0
0 0 0 2
> $scaled_rs=new Polytope(VERTICES=>($rs->VERTICES * $s), LINEALITY_SPACE=>[]);
''%%polymake%%'' can visualise the polytope together with its lattice points:
> $scaled_rs->VISUAL->LATTICE_COLORED;
> $integer_hull=new Polytope(POINTS=>$scaled_rs->LATTICE_POINTS);
> $integer_hull->VISUAL->LATTICE_COLORED;
> $objective=new LinearProgram(LINEAR_OBJECTIVE=>[0,1,1,1]);
Then we define a new polytope, which is a copy of our old one (''%%$inter_hull%%'') with the LP as an additional property.
> $ilp=new Polytope(VERTICES=>$integer_hull->VERTICES, LP=>$objective);
{{:tutorials:release:4.9:ilp_and_hilbertbases:ilp_min_face.png|ilp_min_face.png}} {{:tutorials:release:4.9:ilp_and_hilbertbases:ilp_max_face.png|ilp_max_face.png}}
And now we can perform some computations:
> print $ilp->LP->MAXIMAL_VALUE;
3
> print $ilp->LP->MAXIMAL_FACE;
{11}
> $ilp->VISUAL->MIN_MAX_FACE;
> print $ilp->VERTICES;
1 -1 -1 -1
1 -1 -1 0
1 -1 0 1
1 -1 1 0
1 -1 1 1
1 0 -1 0
1 0 -1 1
1 0 1 -1
1 1 0 0
1 1 0 1
1 1 1 -1
1 1 1 1
==== Hilbert bases ====
Finally, we can have ''%%polymake%%'' compute and print a Hilbert basis for the cone spanned by ''%%$ilp%%''. Notice that this requires normaliz or 4ti2 to be installed in order to work.
> print $ilp->HILBERT_BASIS;
1 -1 -1 -1
1 -1 -1 0
1 -1 0 0
1 -1 0 1
1 -1 1 0
1 -1 1 1
1 0 -1 0
1 0 -1 1
1 0 0 -1
1 0 0 0
1 0 0 1
1 0 1 -1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 -1
1 1 1 0
1 1 1 1