# Copyright (c) 1997-2006 # Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany) # http://www.math.tu-berlin.de/polymake, mailto:polymake@math.tu-berlin.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: visual.rules 7487 2006-12-06 15:16:09Z gawrilow $ package Visual::Color; # graph edges: black custom $graph="0 0 0"; require VisualGraph; require VisualLattice; ############################################################################### # # Home-maid 3-d spring embedder with variations # package Visual::GraphEmbedding; # Tuning parameters for the graph embedder. # Almost all are multiplicative factors; the comments describe # the effect of INCREASING of the corresponding parameter. custom %graph_parameters=( # scale => 1, # the average edge length increases inertion => 0.1, # the computations might converge more slowly, but more steadily # viscosity => 1, # improves the convergence at the risk of being stuck at a bad local minimum # 'max-iterations' => 10000, # The iteration limit. Not multiplicative! balance => 10, # the non-neighbor nodes are more spread away from each other ); # Additional tuning parameters for the interactive spring embedder. custom %interactive_parameters=( 'eps' => 1e-4 # the movement to be accepted as "no movement" ); @ISA=qw( Visual::Embedding ); sub compute { unbless($_[0]); my ($obj, $graph_section) = splice @{$_[0]}, 0, 2; my %params=(%graph_parameters, @{$_[0]}); client("spring_embedder", $obj, $graph_section, $_[0], map { ("-$_", (defined($params{$_}) ? ($params{$_}) : ())) } keys %params); $_[0]; } sub get_n_vertices { my ($self)=@_; my ($obj, $graph)=@$self[0,1]; # see the command line in compute() if (is_object($graph) and my $meth=$graph->can("get_number_nodes")) { &$meth($graph); } elsif (is_array($graph) || !ref($graph) && defined ($graph=$obj->lookup($graph))) { scalar @$graph; } else { 0; } } package Visual::HDEmbedding; @ISA=qw( Visual::Embedding ); sub compute { unbless($_[0]); my ($obj, $lattice_section, $label_width_section) = splice @{$_[0]}, 0, 3; my %params=@{$_[0]}; client("hd_embedder", $obj, $lattice_section, $_[0], $label_width_section, map { ("-$_", (defined($params{$_}) ? ($params{$_}) : ())) } keys %params); $_[0]; } package default; # Object, SECTION, optional parameters ... => Visual::GraphEmbedding function spring_embedding_3d { new Visual::GraphEmbedding(@_); } # Object, SECTION, optional parameters ... => Visual::HDEmbedding function hd_embedding { new Visual::HDEmbedding(@_); } function dim(Visual::GraphEmbedding) { 3 } function dim(Visual::HDEmbedding) { 2 } function enforce_static(Visual::Graph) { enforce_static_coord($_[0], "Vertices"); } # Local Variables: # mode: perl # c-basic-offset:3 # End: