1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# 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.
#-------------------------------------------------------------------------------
# The aim of all these methods is to convert the obsolete properties read from a plain data file
# to the corresponding sub-object properties.
sub translate_plain_file_type : method {
(undef, my $legacy_type)=@_;
( $legacy_type && do {
$legacy_type =~ s/^(Rational|Float)Polytope$/Polytope<$1>/;
eval("typeof $legacy_type")
}, typeof Polytope<Rational> )
}
object Polytope {
# 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);
}
method upgrade_plain_N_EDGES {
my ($this, $value)=@_;
$this->take("GRAPH.N_EDGES", $value);
}
method upgrade_plain_N_RIDGES {
my ($this, $value)=@_;
$this->take("DUAL_GRAPH.N_EDGES", $value);
}
method upgrade_plain_VERTEX_DEGREES {
my ($this, $value)=@_;
$this->take("GRAPH.NODE_DEGREES", $value);
}
method upgrade_plain_FACET_DEGREES {
my ($this, $value)=@_;
$this->take("DUAL_GRAPH.NODE_DEGREES", $value);
}
method upgrade_plain_DIAMETER {
my ($this, $value)=@_;
$this->take("GRAPH.DIAMETER", $value);
}
method upgrade_plain_DUAL_DIAMETER {
my ($this, $value)=@_;
$this->take("DUAL_GRAPH.DIAMETER", $value);
}
method upgrade_plain_TRIANGLE_FREE {
my ($this, $value, $boolean_value)=@_;
$this->take("GRAPH.TRIANGLE_FREE", $boolean_value);
}
method upgrade_plain_DUAL_TRIANGLE_FREE {
my ($this, $value, $boolean_value)=@_;
$this->take("DUAL_GRAPH.TRIANGLE_FREE", $boolean_value);
}
method upgrade_plain_EVEN {
my ($this, $value, $boolean_value)=@_;
$this->take("GRAPH.BIPARTITE", $boolean_value);
}
method upgrade_plain_DUAL_EVEN {
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_CONNECTIVITY {
my ($this, $value)=@_;
$this->take("GRAPH.CONNECTIVITY", $value);
}
method upgrade_plain_DUAL_CONNECTIVITY {
my ($this, $value)=@_;
$this->take("DUAL_GRAPH.CONNECTIVITY", $value);
}
method upgrade_plain_HASSE_DIAGRAM {
my ($this, $value)=@_;
$this->HASSE_DIAGRAM=graph::FaceLattice_from_plain_text($value);
}
method upgrade_plain_BOUNDED_COMPLEX {
my ($this, $value)=@_;
$this->BOUNDED_COMPLEX->HASSE_DIAGRAM=graph::FaceLattice_from_plain_text($value);
}
# Triangulations
method upgrade_plain_TRIANGULATION {
my ($this, $value)=@_;
$this->take("TRIANGULATION.FACETS", $value);
}
method upgrade_plain_TRIANGULATION_BOUNDARY {
my ($this, $value)=@_;
my $tb_new;
foreach (split /\n/, $value) {
s/\{\{/\{/;
s/\}\}/\}/;
s/\}\s\{/\}\n\{/g;
$tb_new.=$_;
}
$this->take("TRIANGULATION.BOUNDARY.FACETS",$tb_new);
my $tb=new Array<Set<Int>>($value);
my $n_facets=scalar(@$tb);
my $tb_f_triag=new Array<Set<Int>>($n_facets);
my $n_simplices=0;
for (my $i=0; $i<$n_facets;++$i) {
my $ns_f=$tb->[$i]->size;
$tb_f_triag->[$i]=sequence($n_simplices,$ns_f);
$n_simplices+=$ns_f;
}
print $tb_f_triag;
$this->TRIANGULATION->BOUNDARY->FACET_TRIANGULATIONS=$tb_f_triag;
}
# Schlegel diagrams
method upgrade_plain_SCHLEGEL_PARAMS {
my ($this, $value)=@_;
my ($facet, $zoom, $facet_point, $inner_point)= $value =~ /\A\s* (\d+) \s+ (\S+) \s* ^(.*)$ \n ^(.*)$/xm;
$this->SCHLEGEL_DIAGRAM(FACET=>$facet, ZOOM=>$zoom, FACET_POINT=>$facet_point, INNER_POINT=>$inner_point);
}
method upgrade_plain_SCHLEGEL_TRANSFORM {
my ($this, $value)=@_;
$this->take("SCHLEGEL_DIAGRAM.TRANSFORM", $value);
}
method upgrade_plain_SCHLEGEL_VIEWPOINT {
my ($this, $value)=@_;
$this->take("SCHLEGEL_DIAGRAM.VIEWPOINT", $value);
}
method upgrade_plain_SCHLEGEL_VERTICES {
my ($this, $value)=@_;
$this->take("SCHLEGEL_DIAGRAM.VERTICES", $value);
}
# LP related properties
method upgrade_plain_LINEAR_OBJECTIVE {
my ($this, $value)=@_;
$this->take("LP.LINEAR_OBJECTIVE", $value);
}
method upgrade_plain_ABSTRACT_OBJECTIVE {
my ($this, $value)=@_;
$this->take("LP.ABSTRACT_OBJECTIVE", $value);
}
method upgrade_plain_MAXIMAL_FACE {
my ($this, $value)=@_;
$this->take("LP.MAXIMAL_FACE", $value);
}
method upgrade_plain_MINIMAL_FACE {
my ($this, $value)=@_;
$this->take("LP.MINIMAL_FACE", $value);
}
method upgrade_plain_MAXIMAL_VERTEX {
my ($this, $value)=@_;
$this->take("LP.MAXIMAL_VERTEX", $value);
}
method upgrade_plain_MINIMAL_VERTEX {
my ($this, $value)=@_;
$this->take("LP.MINIMAL_VERTEX", $value);
}
method upgrade_plain_MAXIMAL_VALUE {
my ($this, $value)=@_;
if ($value !~ $Core::PropertyValue::UNDEF_re) {
$this->take("LP.MAXIMAL_VALUE", $value);
}
}
method upgrade_plain_MINIMAL_VALUE {
my ($this, $value)=@_;
if ($value !~ $Core::PropertyValue::UNDEF_re) {
$this->take("LP.MINIMAL_VALUE", $value);
}
}
method upgrade_plain_DIRECTED_GRAPH {
my ($this, $value)=@_;
$this->take("LP.DIRECTED_GRAPH.ADJACENCY", $value);
}
method upgrade_plain_VERTEX_OUT_DEGREES {
my ($this, $value)=@_;
$this->take("LP.DIRECTED_GRAPH.NODE_OUT_DEGREES", $value);
}
method upgrade_plain_VERTEX_IN_DEGREES {
my ($this, $value)=@_;
$this->take("LP.DIRECTED_GRAPH.NODE_IN_DEGREES", $value);
}
method upgrade_plain_VERTEX_COLORS { } # discard it
method upgrade_plain_RANDOM_EDGE_EPL {
my ($this, $value)=@_;
$this->take("LP.RANDOM_EDGE_EPL", $value);
}
method upgrade_plain_VARIABLE_NAMES {
my ($this, $value)=@_;
$this->take("COORDINATE_LABELS", $value);
}
# attributed graphs are converted to graphs with property maps
method upgrade_plain_BOUNDED_GRAPH {
my ($this, $value)=@_;
my $n;
# we dare not use rules on an object being built up
unless (defined ($n=$this->lookup("N_VERTICES"))) {
if (defined (my $v=$this->lookup("VERTICES"))) {
$n=$v->rows;
} elsif (defined ($v=$this->lookup("VERTICES_IN_FACETS"))) {
$n=$v->cols;
} elsif (defined (my $G=$this->lookup("GRAPH.ADJACENCY"))) {
$n=$G->nodes;
} else {
return;
}
}
my $BG=new GraphAdjacency($n);
my @renumber= map { /^\s*\(\s*(\d+)/ } split /\n/, $value;
my $from=0;
foreach (split /\n/, $value) {
my ($edges)=/\{(.*)\}/;
foreach my $to ($edges =~ /\d+/g) {
if ($from>=$to) {
$BG->edge($renumber[$from], $renumber[$to]);
}
}
++$from;
}
$from=0;
foreach (@renumber) {
while ($from<$_) {
$BG->delete_node($from);
++$from;
}
++$from;
}
while ($from<$n) {
$BG->delete_node($from++);
}
$this->take("BOUNDED_COMPLEX.GRAPH.ADJACENCY", $BG);
1
}
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_EDGE_COLORED_BOUNDED_GRAPH {
my ($this, $value)=@_;
my ($adjacency, $colors)=parse_graph_with_edge_attributes($value, qr/\d+/);
if ($this->lookup("BOUNDED_COMPLEX.GRAPH.ADJACENCY") || upgrade_plain_BOUNDED_GRAPH($this,$adjacency)) {
$this->take("BOUNDED_COMPLEX.GRAPH.EDGE_COLORS", $colors);
}
}
method upgrade_plain_EDGE_DIRECTIONS_GRAPH {
my ($this, $value)=@_;
my ($adjacency, $dirs)=parse_graph_with_edge_attributes($value, qr/<.*?>/);
$this->lookup("GRAPH.ADJACENCY") || upgrade_plain_GRAPH($this,$adjacency);
tr/<>/ / for @$dirs;
$this->take("GRAPH.EDGE_DIRECTIONS", $dirs);
}
method upgrade_plain_EDGE_DIRECTED_BOUNDED_GRAPH {
my ($this, $value)=@_;
my ($adjacency, $dirs)=parse_graph_with_edge_attributes($value, qr/<.*?>/);
if ($this->lookup("BOUNDED_COMPLEX.GRAPH.ADJACENCY") || upgrade_plain_BOUNDED_GRAPH($this,$adjacency)) {
tr/<>/ / for @$dirs;
$this->take("BOUNDED_COMPLEX.GRAPH.EDGE_DIRECTIONS", $dirs);
}
}
# new object types introduced
method cast_if_seen_SUM_PRODUCT_GRAPH { "PropagatedPolytope" }
method cast_if_seen_VORONOI_BOUNDING_BOX { "VoronoiPolyhedron" }
method cast_if_seen_VORONOI_GRAPH { "VoronoiPolyhedron" }
method cast_if_seen_DELAUNAY_GRAPH { "VoronoiPolyhedron" }
method cast_if_seen_NN_GRAPH { "VoronoiPolyhedron" }
method cast_if_seen_NN_CRUST_GRAPH { "VoronoiPolyhedron" }
sub convert_to_PointConfiguration {
my $this=shift;
if (defined (my $pts=$this->lookup("POINTS"))) {
my $pc=new PointConfiguration;
$pc->take("POINTS", $pts);
$this->remove("POINTS");
[ $pc, "CONVEX_HULL" ]
} else {
undef
}
}
method cast_if_seen_TRIANGULATION_INT {
if (defined $_[0]->lookup("VERTICES")) {
# do nothing
undef;
} else {
&convert_to_PointConfiguration;
}
}
method cast_if_seen_CHIROTOPE_INT {
&convert_to_PointConfiguration;
}
# properties with changed semantics
method upgrade_plain_H_VECTOR {
my ($this, $value)=@_;
if ($this->lookup("SIMPLICIAL")) {
$this->take("H_VECTOR",$value);
} elsif ($this->lookup("SIMPLE")) {
$this->take("DUAL_H_VECTOR",$value);
} # if neither SIMPLE nor SIMPLICIAL known, discard this section
}
# obsolete properties
method upgrade_plain_TRIANGULATION_SIGNS { } # discard
method upgrade_plain_TRIANGULATION_INT_SIGNS { } # discard
method upgrade_plain_REVERSE_TRANSFORMATION {
my ($this, $value)=@_;
$this->attach("REVERSE_TRANSFORMATION", new Matrix<Scalar>($value));
}
# dimensions renamed after the switch to cones
method upgrade_plain_AMBIENT_DIM {
my ($this, $value)=@_;
$this->take("CONE_AMBIENT_DIM", $value+1);
}
method upgrade_plain_DIM {
my ($this, $value)=@_;
my $as_dim;
if(defined($this->lookup("POINTS | VERTICES | INEQUALITIES | FACETS | EQUATIONS | AFFINE_HULL"))){
$as_dim="CONE_DIM"; #POLYTOPE_AMBIENT_DIM was wrong! Should have been POLYTOPE_DIM!
$value++;
} else {
$as_dim="COMBINATORIAL_DIM";
}
$this->take($as_dim, $value);
}
method upgrade_plain_AFFINE_HULL {
my ($this, $value)=@_;
if (length($value)) {
$this->take("AFFINE_HULL", $value);
}
}
}
object PropagatedPolytope {
method upgrade_plain_SUM_PRODUCT_GRAPH {
my ($this, $value)=@_;
my (@adjacency, @trans);
foreach (split /\n/, $value) {
while (s/\((\d+) \s+ <? ([^>)]+) >?\s*\)/$1/x) {
push @trans, $2;
}
push @adjacency, $_;
}
$this->take("SUM_PRODUCT_GRAPH.ADJACENCY", \@adjacency);
$this->take("SUM_PRODUCT_GRAPH.TRANSLATIONS", \@trans);
}
}
object VoronoiPolyhedron {
method upgrade_plain_DELAUNAY_GRAPH {
my ($this, $value)=@_;
$this->take("DELAUNAY_GRAPH.ADJACENCY", $value);
}
method upgrade_plain_VORONOI_GRAPH {
my ($this, $value)=@_;
convert_graph_with_coords($this, $value, "VORONOI_GRAPH");
}
method upgrade_plain_VORONOI_BOUNDING_BOX {
my ($this, $value)=@_;
$this->take("VORONOI_GRAPH.BOUNDING_BOX", $value);
}
method upgrade_plain_NN_GRAPH {
my ($this, $value)=@_;
$this->take("NN_GRAPH.ADJACENCY", $value);
}
method upgrade_plain_NN_CRUST_GRAPH {
my ($this, $value)=@_;
$this->take("NN_CRUST_GRAPH.ADJACENCY", $value);
}
sub convert_graph_with_coords {
my ($this, $value, $prop_name)=@_;
my (@adjacency, @coords);
while (/^\s*\(\s*<? (.*?) >?\s* (\{.*?\})/xm) {
push @coords, $1;
push @adjacency, $2;
}
$this->take("$prop_name.ADJACENCY", \@adjacency);
$this->take("$prop_name.COORDINATES", \@coords);
}
}
object PointConfiguration {
method upgrade_plain_TRIANGULATION_INT {
my ($this, $value)=@_;
$this->take("TRIANGULATION", $value);
}
method upgrade_plain_CHIROTOPE_INT {
my ($this, $value)=@_;
$this->take("CHIROTOPE", $value);
}
}
# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
|