#  Copyright (c) 1997-2010
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------
#  $Project: polymake $$Id: upgrade.rules 9592 2010-03-23 00:38:01Z gawrilow $

INCLUDE
   graph::upgrade.rules

#  The aim of all these methods is to convert the obsolete properties read from a plain data file
#  to the corresponding sub-object properties.

object SimplicialComplex {

   # the graph and dual graph related properties

   method upgrade_plain_GRAPH {
      my ($this, $value)=@_;
      $this->take("GRAPH.ADJACENCY", $value);
   }

   method upgrade_plain_DUAL_GRAPH {
      my ($this, $value)=@_;
      $this->take("DUAL_GRAPH.ADJACENCY", $value);
   }
   
   sub parse_graph_with_edge_attributes {
      my ($value, $attr_re)=@_;
      my $adjacency="";
      my @map;
      my $from=0;
      foreach (split /\n/, $value) {
         s{\(\s*(\d+)\s+($attr_re)\s*\)}{
            if ($from>=$1) {
               push @map, $2; $1
            } else {
               ""
            }
         }eg;
         $adjacency.="$_\n";
         ++$from;
      }
      return ($adjacency, \@map);
   }

   method upgrade_plain_MIXED_GRAPH {
      my ($this, $value)=@_;
      my ($adjacency, $weights)=parse_graph_with_edge_attributes($value, qr/\d+(\.\d+)?/);
      $this->take("MIXED_GRAPH.ADJACENCY", $adjacency);
      $this->take("MIXED_GRAPH.EDGE_WEIGHTS", $weights);
   }
   
   method upgrade_plain_VERTEX_DEGREES {
      my ($this, $value)=@_;
      $this->take("GRAPH.NODE_DEGREES", $value);
   }

   method upgrade_plain_CONNECTED {
      my ($this, $value, $boolean_value)=@_;
      $this->take("GRAPH.CONNECTED", $boolean_value);
   }

   method upgrade_plain_DUAL_CONNECTED {
      my ($this, $value, $boolean_value)=@_;
      $this->take("DUAL_GRAPH.CONNECTED", $boolean_value);
   }

   method upgrade_plain_CONNECTIVITY {
      my ($this, $value, $boolean_value)=@_;
      $this->take("GRAPH.CONNECTIVITY", $boolean_value);
   }

   method upgrade_plain_DUAL_CONNECTIVITY {
      my ($this, $value, $boolean_value)=@_;
      $this->take("DUAL_GRAPH.CONNECTIVITY", $boolean_value);
   }

   method upgrade_plain_CONNECTED_COMPONENTS {
      my ($this, $value)=@_;
      $this->take("GRAPH.CONNECTED_COMPONENTS", $value);
   }

   method upgrade_plain_DUAL_CONNECTED_COMPONENTS {
      my ($this, $value)=@_;
      $this->take("DUAL_GRAPH.CONNECTED_COMPONENTS", $value);
   }

   method upgrade_plain_N_CONNECTED_COMPONENTS {
      my ($this, $value)=@_;
      $this->take("GRAPH.N_CONNECTED_COMPONENTS", $value);
   }

   method upgrade_plain_MAX_CLIQUES {
      my ($this, $value)=@_;
      $this->take("GRAPH.MAX_CLIQUES", $value);
   }

   method upgrade_plain_DUAL_MAX_CLIQUES {
      my ($this, $value)=@_;
      $this->take("DUAL_GRAPH.MAX_CLIQUES", $value);
   }

   method upgrade_plain_BIPARTITE {
      my ($this, $value, $boolean_value)=@_;
      $this->take("GRAPH.BIPARTITE", $boolean_value);
   }

   method upgrade_plain_DUAL_BIPARTITE {
      my ($this, $value, $boolean_value)=@_;
      $this->take("DUAL_GRAPH.BIPARTITE", $boolean_value);
   }

   method upgrade_plain_GRAPH_SIGNATURE {
      my ($this, $value)=@_;
      $this->take("GRAPH.SIGNATURE", $value);
   }

   method upgrade_plain_DUAL_GRAPH_SIGNATURE {
      my ($this, $value)=@_;
      $this->take("DUAL_GRAPH.SIGNATURE", $value);
   }

   method upgrade_plain_COLORING {
      my ($this, $value)=@_;
      $this->take("COLORING",$value);
   }
   
   method upgrade_plain_ORIENTATION {
      my ($this, $value)=@_;
      my $o="";
      foreach (split /\ /, $value) {
        if ($_==-1) { $o.="false ";}
	else {$o.="true ";}
      }
      $this->take("ORIENTATION", $o);
   }

   method upgrade_plain_DUAL_COLORING {
      my ($this, $value)=@_;
      $this->take("DUAL_GRAPH.COLORING", $value);
   }

   method upgrade_plain_HASSE_DIAGRAM {
      my ($this, $value)=@_;
      $this->HASSE_DIAGRAM=graph::FaceLattice_from_plain_text($value);
   }

   method upgrade_plain_INTERSECTION_FORM {
      my ($this, $value)=@_;
      $value =~ s/[()]//g;
      $this->take("INTERSECTION_FORM", $value);
   }
 
   method upgrade_plain_BOUNDARY_OF_PSEUDO_MANIFOLD {
      my ($this, $value)=@_;
      $this->take("BOUNDARY.INPUT_FACES", $value);
   }
   
   method upgrade_plain_ODD_SUBCOMPLEX {
      my ($this, $value)=@_;
      $this->take("ODD_SUBCOMPLEX.INPUT_FACES", $value);
   }
   
   method upgrade_plain_VERTICES { }  # discard
}

# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
