Saving Polytope Vertices to CSV or TXT

Questions and problems about using polymake go here.
selman.ipek
Posts: 5
Joined: 25 Oct 2021, 12:47

Saving Polytope Vertices to CSV or TXT

Postby selman.ipek » 25 Oct 2021, 13:20

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.

User avatar
joswig
Main Author
Posts: 279
Joined: 24 Dec 2010, 11:10

Re: Saving Polytope Vertices to CSV or TXT

Postby joswig » 25 Oct 2021, 17:44

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.


Return to “Helpdesk”