Page 1 of 1

Saving Polytope Vertices to CSV or TXT

Posted: 25 Oct 2021, 13:20
by selman.ipek
Hi All, My first time posting here and new user to polymake. In general, what I would like to do is to create a polytope in polymake (e.g., Bell polytopes, No-Signaling polytopes, etc.) for physics research. I will be using inequalities and equalities in the polytope function and I am hoping to save the array of vertices for further study. I did a search but could not (surprisingly) find any threads with this information.

A simple example of what I might want to do is the following:

From the command line in macOS, in the polymake module:

> $p = cube(3);

> print($p->VERTICES);

> save_data($p->VERTICES, "my_vertices.txt");

Any help would be appreciated.

Re: Saving Polytope Vertices to CSV or TXT

Posted: 25 Oct 2021, 17:44
by joswig
Your command sequence

Code: Select all

> $p = cube(3); > print($p->VERTICES); > save_data($p->VERTICES, "my_vertices.txt");
is perfectly OK; the result is a JSON file (format defined by polymake) which contains just one matrix plus a bit of metadata.

If you want the matrix (coefficients separated by blanks) directly, then this is a standard perl question:

Code: Select all

> open OUT, ">myfile.txt"; print OUT $p->VERTICES; close OUT;
The JSON is often superior since it contains version information and such; so future versions of polymake will be able to load it back, even if we will have made some changes to the file format/layout.