user_guide:tutorials:data

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howto:data [2010/07/05 09:47] herruser_guide:tutorials:data [2019/02/11 16:43] (current) – restored. oroehrig
Line 1: Line 1:
-====== Save and load data in polymake ======  +{{page>.:latest:@FILEID@}}
- +
-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,...), complex data types (Set, Matrix, Array<Vector<Rational>,...), and data from files in arbitrary formats. +
- +
-  * Handling ''polymake'' objects:\\ ''polymake'' objects that are stored in ''polymake'''s own XML file format can be loaded via <code>$p=load("myPolyObject.poly");</code> If you did not start ''polymake'' in the directory containing your object, it is necessary to add the relative path, e.g. <code>$p=load("MyFolder/myPolyObject.poly");</code>To store ''polymake'' objects use the command <code>save($p,"myPolyObject.poly");</code>**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. +
-  * Handling complex data types:\\ It is also possible to store complex data structures in XML format via ''save_data'', e.g.<code>$s=new Set<Int>(1,2,3,4); +
-save_data($s,"mySet.poly");</code>To load such files just type<code>$s=load_data("mySet.poly");</code> +
-  * 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:<code>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</code>To read this file try the following:<code>open(INPUT, "< points.txt"); +
-while(<INPUT>){ +
- print $_; +
-+
-close(INPUT); +
-</code> ''<INPUT>'' is a perl array containing all the lines of the file. Via ''$_'' you have access to the current line, which is interpreted as a string.\\ A reasonable task could be to store the points from the file as a matrix in a variable. To this end we transform each line into a ''Vector<Rational>'' and gather all the vectors in an array using the perl function ''map''. Then we construct a matrix from this array:<code> +
-open(INPUT, "< points.txt"); +
-@points=map{new Vector<Rational>($_)<INPUT>; +
-close(INPUT); +
-$matrix=new Matrix<Rational>(@points); +
-</code>+
  
  
  • user_guide/tutorials/data.1278323276.txt.gz
  • Last modified: 2014/01/03 15:45
  • (external edit)