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
Last revisionBoth sides next revision
tutorial:data [2012/08/07 14:43] – [Handling polymake objects] paffenholzuser_guide:tutorials:data [2019/02/11 16:43] – ↷ Links adapted because of a move operation oroehrig
Line 4: Line 4:
  
 ===== Handling polymake objects ===== ===== Handling polymake objects =====
 +Let us take this nice example object:
 +  > $p = cube(3);
 +To store polymake objects use the command
 +  > save($p,"myPolyObject.poly");
 +This silently overwrites existing files.
 +  
 polymake objects that are stored in polymake's own XML file format can be loaded via polymake objects that are stored in polymake's own XML file format can be loaded via
-  $p=load("myPolyObject.poly"); +  $p=load("myPolyObject.poly"); 
-If you did not start ''polymake'' in the directory containing your object, it is necessary to add the relative path, e.g.+If you did not start ''polymake'' in the directory containing your object, it is necessary to add the relative or absolute path, e.g.
   $p=load("MyFolder/myPolyObject.poly");   $p=load("MyFolder/myPolyObject.poly");
-To store polymake objects use the command +TAB completion like in a usual UNIX shell supports you in navigating through the file system. 
-  save($p,"myPolyObject.poly");+ 
 **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  **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->dont_save; +  $p->dont_save; 
-called prior to leaving the session (but after the last compuation with $p).+called prior to leaving the session (but after the last computation with $p).
  
 +
 +If you want to store a collection of objects into a single file, there is an [[..:howto:tarballs|extra tutorial]] for you.
 ===== Handling complex data types ===== ===== Handling complex data types =====
  
-It is also possible to store complex data structures in XML format via ''save_data'', e.g. +Apart from the full objects, you can also persistently store arbitrary data structures like matrices or graphs in XML format via ''save_data'', e.g. 
-  $s=new Set<Int>(1,2,3,4); +  $s=new Set<Int>(1,2,3,4); 
-  save_data($s,"mySet.poly");+  save_data($s, "mySet.poly", "My very own set."); 
 +The description text is optional; it can be an arbitrary text, even stretching over several lines. 
 To load such files just type To load such files just type
-  $s=load_data("mySet.poly");+  $s=load_data("mySet.poly"); 
 +===== Saving visualized objects ===== 
 +Furthermore, most visualization methods provide an option to save the visualized object in a suitable format. Consult the [[user_guide:intro_tutorial#getting_help|F1 help]] for information on the file format and further options. 
 + 
 +To save the cube visualized via JReality in a new file called ''mycube.bsh'', do this: 
 +<code>jreality(cube(3)->VISUAL,File=>"mycube");</code> 
 +To save the cube as a TiKz file named ''mycube.tikz'' that you can e.g. import in a LaTeX document, do this instead: 
 +<code>tikz(cube(3)->VISUAL,File=>"mycube");</code>
  
 ===== Handling arbitrary files ===== ===== Handling arbitrary files =====
Line 33: Line 51:
   1 0 1 1   1 0 1 1
   1 1 1 1   1 1 1 1
 +For the sake of the example, let's create this file:
 +  > open(my $f, '> points.txt'); print $f "1 0 0 0\n1 1 0 0\n1 0 1 0\n1 1 1 0\n1 0 0 1\n1 1 0 1\n1 0 1 1\n1 1 1 1\n"; close $f;
 To read this file try the following: To read this file try the following:
-  open(INPUT, "< points.txt"); +  open(INPUT, "< points.txt"); 
-  while(<INPUT>){ +  while(<INPUT>){ 
-    print $_; +  >   print $_; 
-  } +  
-  close(INPUT);+  close(INPUT);
  
 ''<INPUT>'' is a perl input iterator reading the file line by line.  Variable ''$_'' refers to the current line within this loop; it has a plain string value.\\ A reasonable task could be to store the points from the file as a matrix.  This can be done immediately, because the matrix constructor called with a list of values interprets each value as a matrix line: ''<INPUT>'' is a perl input iterator reading the file line by line.  Variable ''$_'' refers to the current line within this loop; it has a plain string value.\\ A reasonable task could be to store the points from the file as a matrix.  This can be done immediately, because the matrix constructor called with a list of values interprets each value as a matrix line:
-  open(INPUT, "< points.txt"); +  open(INPUT, "< points.txt"); 
-  $matrix=new Matrix<Rational>(<INPUT>); +  $matrix=new Matrix<Rational>(<INPUT>); 
-  close(INPUT);+  close(INPUT);
  
  
  
  • user_guide/tutorials/data.txt
  • Last modified: 2019/02/11 16:43
  • by oroehrig