Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
howto:data [2010/07/05 09:47] – herr | user_guide:howto:data [2019/01/25 13:32] – ↷ Page moved from user_guide:data to user_guide:howto:data oroehrig | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Save and load data in polymake ====== | ====== Save and load data in polymake ====== | ||
- | In '' | + | In polymake there are different ways to save and load data depending on the type and the format of the data. We distinguish between polymake objects (Polytope, Matroid, |
+ | |||
+ | ===== Handling polymake objects ===== | ||
+ | Let us take this nice example object: | ||
+ | > $p = cube(3); | ||
+ | To store polymake objects use the command | ||
+ | > save($p," | ||
+ | This silently overwrites existing files. | ||
+ | |||
+ | polymake objects that are stored in polymake' | ||
+ | > $p=load(" | ||
+ | If you did not start '' | ||
+ | $p=load(" | ||
+ | TAB completion like in a usual UNIX shell supports you in navigating through the file system. | ||
+ | |||
+ | |||
+ | **Note:** If you load a polymake object and compute new properties, these properties will automatically be added to the original XML-file at the end of the session. You can suppress this with the command | ||
+ | > $p-> | ||
+ | called prior to leaving the session (but after the last computation with $p). | ||
+ | |||
+ | ===== Handling complex data types ===== | ||
+ | |||
+ | Apart from the full objects, you can also persistently store arbitrary data structures like matrices or graphs in XML format via '' | ||
+ | > $s=new Set< | ||
+ | > save_data($s, | ||
+ | The description text is optional; it can be an arbitrary text, even stretching over several lines. | ||
+ | |||
+ | To load such files just type | ||
+ | > $s=load_data(" | ||
+ | ===== Saving visualized objects ===== | ||
+ | Furthermore, | ||
+ | |||
+ | To save the cube visualized via JReality in a new file called '' | ||
+ | < | ||
+ | To save the cube as a TiKz file named '' | ||
+ | < | ||
+ | |||
+ | ===== Handling arbitrary files ===== | ||
+ | |||
+ | Of course, it is also possible to load data from files in other formats. For this purpose use the standard Perl functions for reading and writing. Here is an example:\\ Assume you want to load some points stored in the file points.txt which looks like this: | ||
+ | 1 0 0 0 | ||
+ | 1 1 0 0 | ||
+ | 1 0 1 0 | ||
+ | 1 1 1 0 | ||
+ | 1 0 0 1 | ||
+ | 1 1 0 1 | ||
+ | 1 0 1 1 | ||
+ | 1 1 1 1 | ||
+ | For the sake of the example, let's create this file: | ||
+ | > open(my $f, '> points.txt' | ||
+ | To read this file try the following: | ||
+ | > open(INPUT, "< points.txt" | ||
+ | > while(< | ||
+ | > print $_; | ||
+ | > } | ||
+ | > close(INPUT); | ||
+ | |||
+ | ''< | ||
+ | > open(INPUT, "< points.txt" | ||
+ | > $matrix=new Matrix< | ||
+ | > close(INPUT); | ||
- | * Handling '' | ||
- | * Handling complex data types:\\ It is also possible to store complex data structures in XML format via '' | ||
- | save_data($s," | ||
- | * Handling arbitrary files:\\ Of course, it is also possible to load data from files in other formats. For this purpose use the standard '' | ||
- | 1 1 0 0 | ||
- | 1 0 1 0 | ||
- | 1 1 1 0 | ||
- | 1 0 0 1 | ||
- | 1 1 0 1 | ||
- | 1 0 1 1 | ||
- | 1 1 1 1</ | ||
- | while(< | ||
- | print $_; | ||
- | } | ||
- | close(INPUT); | ||
- | </ | ||
- | open(INPUT, "< points.txt" | ||
- | @points=map{new Vector< | ||
- | close(INPUT); | ||
- | $matrix=new Matrix< | ||
- | </ | ||