passagemath-gap-pkg-cddinterface 10.6.35__cp314-cp314t-musllinux_1_2_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. gap/pkg/cddinterface/LICENSE +344 -0
  2. gap/pkg/cddinterface/PackageInfo.g +103 -0
  3. gap/pkg/cddinterface/README.md +129 -0
  4. gap/pkg/cddinterface/ToDo.txt +2 -0
  5. gap/pkg/cddinterface/bin/aarch64-unknown-linux-musl-default64-kv10/CddInterface.so +0 -0
  6. gap/pkg/cddinterface/etc/download.sh +86 -0
  7. gap/pkg/cddinterface/examples/30x30.g +5 -0
  8. gap/pkg/cddinterface/examples/FourierProjection.g +83 -0
  9. gap/pkg/cddinterface/examples/comparing_polyhedrons.g +32 -0
  10. gap/pkg/cddinterface/examples/demo.g +65 -0
  11. gap/pkg/cddinterface/examples/example1.g +115 -0
  12. gap/pkg/cddinterface/examples/intersection.g +35 -0
  13. gap/pkg/cddinterface/examples/linear_programs.g +64 -0
  14. gap/pkg/cddinterface/examples/minkuwski.g +35 -0
  15. gap/pkg/cddinterface/examples/new.g +5 -0
  16. gap/pkg/cddinterface/examples/new2.g +8 -0
  17. gap/pkg/cddinterface/gap/Julia.gd +3 -0
  18. gap/pkg/cddinterface/gap/Julia.gi +15 -0
  19. gap/pkg/cddinterface/gap/polyhedra.gd +268 -0
  20. gap/pkg/cddinterface/gap/polyhedra.gi +871 -0
  21. gap/pkg/cddinterface/gap/tools.gd +12 -0
  22. gap/pkg/cddinterface/gap/tools.gi +472 -0
  23. gap/pkg/cddinterface/init.g +17 -0
  24. gap/pkg/cddinterface/install.sh +64 -0
  25. gap/pkg/cddinterface/makedoc.g +19 -0
  26. gap/pkg/cddinterface/read.g +12 -0
  27. gap/pkg/cddinterface/tst/01.tst +37 -0
  28. gap/pkg/cddinterface/tst/02.tst +36 -0
  29. gap/pkg/cddinterface/tst/03.tst +50 -0
  30. gap/pkg/cddinterface/tst/04.tst +51 -0
  31. gap/pkg/cddinterface/tst/05.tst +41 -0
  32. gap/pkg/cddinterface/tst/06.tst +44 -0
  33. gap/pkg/cddinterface/tst/07.tst +46 -0
  34. gap/pkg/cddinterface/tst/08.tst +66 -0
  35. gap/pkg/cddinterface/tst/09.tst +28 -0
  36. gap/pkg/cddinterface/tst/10.tst +56 -0
  37. gap/pkg/cddinterface/tst/11.tst +70 -0
  38. gap/pkg/cddinterface/tst/etest_1.tst +6 -0
  39. gap/pkg/cddinterface/tst/etest_2.tst +33 -0
  40. gap/pkg/cddinterface/tst/testall.g +10 -0
  41. passagemath_gap_pkg_cddinterface-10.6.35.dist-info/METADATA +93 -0
  42. passagemath_gap_pkg_cddinterface-10.6.35.dist-info/METADATA.bak +94 -0
  43. passagemath_gap_pkg_cddinterface-10.6.35.dist-info/RECORD +50 -0
  44. passagemath_gap_pkg_cddinterface-10.6.35.dist-info/WHEEL +5 -0
  45. passagemath_gap_pkg_cddinterface-10.6.35.dist-info/top_level.txt +1 -0
  46. passagemath_gap_pkg_cddinterface.libs/libcddgmp-ecb88865.so.0.1.3 +0 -0
  47. passagemath_gap_pkg_cddinterface.libs/libgmp-28992bcb.so.10.5.0 +0 -0
  48. sage/all__sagemath_gap_pkg_cddinterface.py +1 -0
  49. sage/libs/all__sagemath_gap_pkg_cddinterface.py +1 -0
  50. sage/libs/gap_pkg_cddinterface.cpython-314t-aarch64-linux-musl.so +0 -0
@@ -0,0 +1,871 @@
1
+ #############################################################################
2
+ ##
3
+ ## polyhedra.gi CddInterface package Kamal Saleh
4
+ ##
5
+ ## Copyright 2019 Mathematics Faculty, Siegen University, Germany
6
+ ##
7
+ ## Fans for NConvex package.
8
+ ##
9
+ #############################################################################
10
+
11
+ #
12
+ # Gap Interface to Cdd package.
13
+ #
14
+ # Implementations
15
+ #
16
+
17
+ #############################
18
+ ##
19
+ ## Representations
20
+ ##
21
+ #############################
22
+
23
+ DeclareRepresentation( "IsCddPolyhedronRep",
24
+ IsCddPolyhedron and IsAttributeStoringRep,
25
+ [ ] );
26
+
27
+ DeclareRepresentation( "IsCddLinearProgramRep",
28
+ IsCddLinearProgram and IsAttributeStoringRep,
29
+ [ ] );
30
+
31
+ ##################################
32
+ ##
33
+ ## Family and Type
34
+ ##
35
+ ##################################
36
+
37
+ BindGlobal( "CddObjectsFamily",
38
+ NewFamily( "CddObjectsFamily", IsObject ) );
39
+
40
+ BindGlobal( "TheTypeCddPolyhedron",
41
+ NewType( CddObjectsFamily,
42
+ IsCddPolyhedronRep ) );
43
+
44
+ BindGlobal( "TheTypeCddLinearProgram",
45
+ NewType( CddObjectsFamily,
46
+ IsCddLinearProgramRep ) );
47
+
48
+ ##################################
49
+ ##
50
+ ## Constructors
51
+ ##
52
+ ##################################
53
+
54
+ ###
55
+ InstallGlobalFunction( Cdd_PolyhedronByInequalities,
56
+ # "constructor for polyhedron by inequalities",
57
+ # [IsMatrix, IsString],
58
+ function( arg )
59
+ local poly, i, temp, matrix, dim;
60
+
61
+ if Length( arg ) = 0 then
62
+
63
+ Error( "Wronge input: Please provide some input!" );
64
+
65
+ elif Length( arg ) = 1 and IsList( arg[ 1 ] ) then
66
+
67
+ return Cdd_PolyhedronByInequalities( arg[ 1 ], [ ] );
68
+
69
+ elif Length( arg ) = 2 and IsList( arg[ 1 ] ) and IsList( arg[ 2 ] ) then
70
+
71
+ if IsEmpty( arg[ 1 ] ) or ForAny( arg[ 1 ], IsEmpty ) then
72
+
73
+ Error( "Wronge input: Please remove the empty lists from the input!" );
74
+
75
+ fi;
76
+
77
+ if not IsMatrix( arg[ 1 ] ) then
78
+
79
+ Error( "Wronge input: The first argument should be a Gap matrix!" );
80
+
81
+ fi;
82
+
83
+ if not ForAll( arg[ 2 ], i -> i in [ 1 .. NrRows( arg[ 1 ] ) ] ) then
84
+
85
+ Error( "Wronge input for linearity" );
86
+
87
+ fi;
88
+
89
+ dim := Length( arg[ 1 ][ 1 ] ) - 1;
90
+
91
+ matrix := Filtered( arg[ 1 ], row -> not IsZero( row ) );
92
+
93
+ if IsEmpty( matrix ) then
94
+
95
+ matrix := [ Concatenation( [ 1 ], ListWithIdenticalEntries( dim, 0 ) ) ];
96
+
97
+ fi;
98
+
99
+ temp := GiveInequalitiesAndEqualities( matrix, arg[ 2 ] );
100
+
101
+ poly := rec( matrix := matrix,
102
+ inequalities := temp[ 1 ],
103
+ equalities := temp[ 2 ],
104
+ linearity := arg[ 2 ],
105
+ number_type := "rational",
106
+ rep_type := "H-rep" );
107
+
108
+ ObjectifyWithAttributes( poly, TheTypeCddPolyhedron );
109
+
110
+ return poly;
111
+
112
+ fi;
113
+
114
+ end );
115
+
116
+ ###
117
+ InstallGlobalFunction( Cdd_PolyhedronByGenerators,
118
+ # "Constructor for polyhedron by generators",
119
+ function( arg )
120
+ local poly, i, matrix, temp, dim;
121
+
122
+ if Length( arg )= 0 then
123
+
124
+ Error( "Wronge input" );
125
+
126
+ elif Length( arg ) = 1 and IsList( arg[1] ) then
127
+
128
+ return Cdd_PolyhedronByGenerators( arg[ 1 ], [ ] );
129
+
130
+ elif Length( arg ) = 2 and IsList( arg[ 1 ] ) and IsList( arg[ 2 ] ) then
131
+
132
+ if IsEmpty( arg[ 1 ] ) or ForAny( arg[ 1 ], IsEmpty ) then
133
+
134
+ poly := rec( generating_vertices := [ ],
135
+ generating_rays := [ ],
136
+ matrix:= arg[ 1 ],
137
+ number_type := "rational",
138
+ rep_type := "V-rep" );
139
+
140
+ ObjectifyWithAttributes( poly, TheTypeCddPolyhedron );
141
+
142
+ return poly;
143
+
144
+ fi;
145
+
146
+ if not IsMatrix( arg[ 1 ] ) then
147
+
148
+ Error( "Wronge input: The first argument should be a Gap matrix!" );
149
+
150
+ fi;
151
+
152
+ if not ForAll( arg[ 1 ], row -> row[ 1 ] in [ 0, 1 ] ) then
153
+
154
+ Error( "Wronge input: Please see the documentation!" );
155
+
156
+ fi;
157
+
158
+ if not ForAll( arg[ 2 ], i -> i in [ 1 .. NrRows( arg[ 1 ] ) ] ) then
159
+
160
+ Error( "Wronge input for linearity" );
161
+
162
+ fi;
163
+
164
+ dim := Length( arg[ 1 ][ 1 ] ) - 1;
165
+
166
+ matrix := Filtered( arg[ 1 ], row -> not IsZero( row ) );
167
+
168
+ if IsEmpty( matrix ) then
169
+
170
+ Error( "Wronge input: Please make sure the input has sensable direction vectors!" );
171
+
172
+ fi;
173
+
174
+ temp := GiveGeneratingVerticesAndGeneratingRays( arg[ 1 ], arg[ 2 ] );
175
+
176
+ poly := rec( generating_vertices := temp[ 1 ],
177
+ generating_rays := temp[ 2 ],
178
+ matrix :=arg[ 1 ],
179
+ linearity := arg[ 2 ],
180
+ number_type := "rational",
181
+ rep_type := "V-rep" );
182
+
183
+ ObjectifyWithAttributes( poly, TheTypeCddPolyhedron );
184
+
185
+ return poly;
186
+
187
+ fi;
188
+
189
+ end );
190
+
191
+
192
+ InstallMethod( Cdd_LinearProgram,
193
+ "creating linear program",
194
+ [ IsCddPolyhedron, IsString, IsList ],
195
+ function( poly, obj, rowvec )
196
+ local r;
197
+
198
+ if obj <> "max" and obj <> "min" then
199
+
200
+ Error( "The second argument should be either 'max' or 'min' " );
201
+
202
+ fi;
203
+
204
+ r := rec( polyhedron:= poly , objective := obj, rowvector := rowvec );
205
+
206
+ ObjectifyWithAttributes( r, TheTypeCddLinearProgram );
207
+
208
+ return r;
209
+
210
+ end );
211
+
212
+
213
+ ##################################
214
+ ##
215
+ ## Attributes and Properties
216
+ ##
217
+ ##################################
218
+
219
+ # The dimension, dim(P ), of a polyhedron P is the maximum number of affinely
220
+ # independent points in P minus 1.
221
+ #
222
+ InstallMethod( Cdd_Dimension,
223
+ " returns the dimension of the polyhedron",
224
+ [ IsCddPolyhedron ],
225
+ function( poly )
226
+
227
+ if Cdd_IsEmpty( poly ) then
228
+
229
+ return -1;
230
+
231
+ else
232
+
233
+ return CddInterface_DimAndInteriorPoint( CDD_POLYHEDRON_TO_LIST( poly ) )[ 1 ];
234
+
235
+ fi;
236
+
237
+ end );
238
+
239
+ InstallMethod( Cdd_Inequalities,
240
+ " return the list of inequalities of a polyhedron",
241
+ [ IsCddPolyhedron ],
242
+ function( poly )
243
+
244
+ return Set( Cdd_Canonicalize( Cdd_H_Rep( poly ) )!.inequalities );
245
+
246
+ end );
247
+
248
+ InstallMethod( Cdd_Equalities,
249
+ " return the list of equalities of a poylhedra",
250
+ [ IsCddPolyhedron ],
251
+ function( poly )
252
+
253
+ return Set(Cdd_Canonicalize( Cdd_H_Rep( poly ) )!.equalities );
254
+
255
+ end );
256
+
257
+
258
+ InstallMethod( Cdd_GeneratingVertices,
259
+ " return the list of generating vertices",
260
+ [ IsCddPolyhedron ],
261
+ function( poly )
262
+
263
+ return Set( Cdd_Canonicalize( Cdd_V_Rep( poly ) )!.generating_vertices );
264
+
265
+ end );
266
+
267
+ InstallMethod( Cdd_GeneratingRays,
268
+ " return the list of generating vertices",
269
+ [ IsCddPolyhedron ],
270
+ function( poly )
271
+
272
+ return Set( Cdd_Canonicalize( Cdd_V_Rep( poly ) )!.generating_rays );
273
+
274
+ end );
275
+
276
+ ###
277
+ InstallMethod( Cdd_AmbientSpaceDimension,
278
+ "finding the dimension of the ambient space",
279
+ [ IsCddPolyhedron ],
280
+ function( poly )
281
+
282
+ return Length( Cdd_H_Rep( poly )!.matrix[1] )-1;
283
+
284
+ end );
285
+
286
+ ####
287
+ ###
288
+ InstallMethod( Cdd_IsEmpty,
289
+ "finding if the polyhedron empty is or not",
290
+ [ IsCddPolyhedron ],
291
+ function( poly )
292
+
293
+ return Length( Cdd_V_Rep( poly )!.matrix ) = 0;
294
+
295
+ end );
296
+
297
+
298
+ InstallMethod( Cdd_IsCone,
299
+ "finding if the polyhedron is a cone or not",
300
+ [ IsCddPolyhedron ],
301
+ function( poly )
302
+
303
+ return Length( Cdd_GeneratingVertices( poly ) ) = 0;
304
+
305
+ end );
306
+
307
+
308
+ InstallMethod( Cdd_IsPointed,
309
+ "finding if the polyhedron is pointed or not",
310
+ [ IsCddPolyhedron ],
311
+ function( poly )
312
+
313
+ return Length( Cdd_V_Rep( poly )!.linearity )= 0;
314
+
315
+ end );
316
+
317
+ ##################################
318
+ ##
319
+ ## Operations
320
+ ##
321
+ ##################################
322
+
323
+
324
+ InstallMethod( Cdd_Canonicalize,
325
+ [ IsCddPolyhedron],
326
+ function( poly )
327
+ local temp, temp_poly, i, L1, L2, L, H;
328
+
329
+ if poly!.rep_type= "V-rep" and poly!.matrix = [] then
330
+
331
+ return poly;
332
+
333
+ fi;
334
+
335
+ return CallFuncList( LIST_TO_CDD_POLYHEDRON, CddInterface_Canonicalize( CDD_POLYHEDRON_TO_LIST( poly ) ) );
336
+
337
+ end );
338
+
339
+ InstallMethod( Cdd_V_Rep,
340
+ [ IsCddPolyhedron ],
341
+ function( poly )
342
+ local L, p, Q, L2;
343
+
344
+ if poly!.rep_type = "V-rep" then
345
+
346
+ return Cdd_Canonicalize( poly );
347
+
348
+ else
349
+
350
+ return CallFuncList( LIST_TO_CDD_POLYHEDRON, CddInterface_Compute_V_rep( CDD_POLYHEDRON_TO_LIST( poly ) ) );
351
+
352
+ fi;
353
+
354
+ end );
355
+
356
+ InstallMethod( Cdd_H_Rep,
357
+ [ IsCddPolyhedron ],
358
+ function( poly )
359
+ local L, H, p, L2;
360
+
361
+ if poly!.rep_type = "H-rep" then
362
+
363
+ return Cdd_Canonicalize( poly );
364
+
365
+ else
366
+
367
+ if poly!.rep_type = "V-rep" and poly!.matrix = [] then
368
+
369
+ return Cdd_PolyhedronByInequalities( [ [ 0, 1 ], [ -1, -1 ] ] );
370
+
371
+ fi;
372
+
373
+ return CallFuncList( LIST_TO_CDD_POLYHEDRON, CddInterface_Compute_H_rep( CDD_POLYHEDRON_TO_LIST( poly ) ) );
374
+
375
+ fi;
376
+
377
+ end );
378
+
379
+
380
+ InstallMethod( Cdd_SolveLinearProgram,
381
+ [IsCddLinearProgram],
382
+
383
+ function( lp )
384
+ local temp;
385
+
386
+ temp := LinearProgramToList( lp );
387
+
388
+ return CddInterface_LpSolution( temp );
389
+
390
+ end );
391
+
392
+ ###
393
+ InstallMethod( Cdd_FacesWithFixedDimensionOp,
394
+ [ IsCddPolyhedron, IsInt ],
395
+ function( poly, d )
396
+ local M, L;
397
+
398
+ if poly!.rep_type = "V-rep" then
399
+
400
+ Error( "The input should be in H-rep " );
401
+
402
+ fi;
403
+
404
+ M := CDD_POLYHEDRON_TO_LIST( poly );
405
+
406
+ L := CddInterface_FacesWithDimensionAndInteriorPoints( M, d );
407
+
408
+ L := CanonicalizeListOfFacesAndInteriorPoints( L );
409
+
410
+ L := Filtered( L, l -> l[ 1 ] = d );
411
+
412
+ return List( L, l -> l[ 2 ] );
413
+
414
+ end );
415
+
416
+ ###
417
+ InstallMethod( Cdd_Faces,
418
+ [ IsCddPolyhedron],
419
+ function( poly )
420
+ local M, L;
421
+
422
+ if poly!.rep_type = "V-rep" then
423
+
424
+ Error( "The input should be in H-rep " );
425
+
426
+ fi;
427
+
428
+ M := CDD_POLYHEDRON_TO_LIST( poly );
429
+
430
+ L := CddInterface_FacesWithDimensionAndInteriorPoints( M, 0 );
431
+
432
+ L := CanonicalizeListOfFacesAndInteriorPoints( L );
433
+
434
+ return List( L, l -> l{ [ 1, 2 ] } );
435
+
436
+ end );
437
+
438
+ ###
439
+ InstallMethod( Cdd_Facets,
440
+ [ IsCddPolyhedron ],
441
+ function( poly )
442
+ local d;
443
+
444
+ d := Cdd_Dimension( poly );
445
+
446
+ return Cdd_FacesWithFixedDimension( poly, d - 1 );
447
+
448
+ end );
449
+
450
+ InstallMethod( Cdd_Lines,
451
+ [ IsCddPolyhedron ],
452
+
453
+ function( poly )
454
+
455
+ return Cdd_FacesWithFixedDimension( poly, 1 );
456
+
457
+ end );
458
+
459
+ ###
460
+ InstallMethod( Cdd_Vertices,
461
+ [ IsCddPolyhedron ],
462
+
463
+ function( poly )
464
+
465
+ return Cdd_FacesWithFixedDimension( poly, 0 );
466
+
467
+ end );
468
+
469
+ ###
470
+ InstallMethod( Cdd_FacesWithInteriorPoints,
471
+ [ IsCddPolyhedron ],
472
+
473
+ function( poly )
474
+ local M, L;
475
+
476
+ if poly!.rep_type = "V-rep" then
477
+
478
+ Error( "The input should be in H-rep " );
479
+
480
+ fi;
481
+
482
+ M := CDD_POLYHEDRON_TO_LIST( poly );
483
+
484
+ L := CddInterface_FacesWithDimensionAndInteriorPoints( M, 0 );
485
+
486
+ return CanonicalizeListOfFacesAndInteriorPoints( L );
487
+
488
+ end );
489
+
490
+ ###
491
+ InstallMethod( Cdd_FacesWithFixedDimensionAndInteriorPointsOp,
492
+ [ IsCddPolyhedron, IsInt ],
493
+
494
+ function( poly, d )
495
+ local M, L;
496
+
497
+ if poly!.rep_type = "V-rep" then
498
+
499
+ Error( "The input should be in H-rep " );
500
+
501
+ fi;
502
+
503
+ M := CDD_POLYHEDRON_TO_LIST( poly );
504
+
505
+ L := CddInterface_FacesWithDimensionAndInteriorPoints( M, 0 );
506
+
507
+ L := CanonicalizeListOfFacesAndInteriorPoints( L );
508
+
509
+ L := Filtered( L, l -> l[ 1 ] = d );
510
+
511
+ return List( L, l -> l{ [ 2, 3 ] } );
512
+
513
+ end );
514
+
515
+ ####
516
+ InstallMethod( Cdd_ExtendLinearity,
517
+ [ IsCddPolyhedron, IsList],
518
+
519
+ function( poly, lin )
520
+ local temp, temp2, L, P;
521
+
522
+ if poly!.rep_type = "V-rep" then
523
+
524
+ Error( "The polyhedron should be in H-rep");
525
+
526
+ fi;
527
+
528
+ temp := StructuralCopy( poly!.linearity );
529
+
530
+ Append( temp, lin );
531
+
532
+ temp := List( Set( temp ) );
533
+
534
+ if temp = [ ] then
535
+
536
+ P := Cdd_PolyhedronByInequalities( poly!.matrix );
537
+
538
+ else
539
+
540
+ P := Cdd_PolyhedronByInequalities( poly!.matrix, temp );
541
+
542
+ fi;
543
+
544
+ return P;
545
+
546
+ end );
547
+
548
+
549
+ InstallMethod( Cdd_InteriorPoint,
550
+ [ IsCddPolyhedron ],
551
+
552
+ function( poly )
553
+ local dim_and_interior;
554
+
555
+ dim_and_interior:= CddInterface_DimAndInteriorPoint( CDD_POLYHEDRON_TO_LIST( poly ) );
556
+
557
+ if dim_and_interior[ 1 ] = -1 then
558
+
559
+ return fail ;
560
+
561
+ else
562
+
563
+ Remove( dim_and_interior, 1 );
564
+
565
+ return ShallowCopy( dim_and_interior );
566
+
567
+ fi;
568
+
569
+ end );
570
+
571
+
572
+ InstallMethod( Cdd_FourierProjection,
573
+ [ IsCddPolyhedron, IsInt ],
574
+
575
+ function( poly, n )
576
+ local f,temp_poly, temp, i,j,row_range, col_range, extra_row;
577
+
578
+ if Cdd_IsEmpty( poly ) then
579
+
580
+ return poly;
581
+
582
+ fi;
583
+
584
+ temp_poly := GetRidOfLinearity( Cdd_H_Rep( StructuralCopy( poly ) ) );
585
+
586
+ col_range := Length( temp_poly!.matrix[1] );
587
+
588
+ row_range := Length( temp_poly!.matrix );
589
+
590
+ temp := temp_poly!.matrix;
591
+
592
+ if n >= col_range then
593
+
594
+ for j in [ 1 .. row_range ] do
595
+
596
+ for i in [ col_range, n ] do
597
+
598
+ Add( temp[ j ], 0 );
599
+
600
+ od;
601
+
602
+ od;
603
+
604
+ else
605
+
606
+ for i in [ 1 .. row_range ] do
607
+
608
+ Add( temp[ i ], temp[ i, n + 1 ] );
609
+
610
+ Remove( temp[ i ], n + 1 );
611
+
612
+ od;
613
+
614
+ temp_poly := Cdd_Canonicalize(
615
+ CallFuncList(
616
+ LIST_TO_CDD_POLYHEDRON,
617
+ CddInterface_FourierElimination( CDD_POLYHEDRON_TO_LIST( Cdd_PolyhedronByInequalities( temp ) ) )
618
+ )
619
+ );
620
+
621
+ temp := temp_poly!.matrix;
622
+
623
+ row_range := Length( temp );
624
+
625
+ for i in [ 1 .. row_range ] do
626
+
627
+ Add( temp[ i ], 0, n + 1 );
628
+
629
+ od;
630
+
631
+ f := function( t )
632
+ if t <> n+1 then
633
+ return 0;
634
+ else
635
+ return 1;
636
+ fi;
637
+ end;
638
+
639
+ extra_row := List( [ 1 .. col_range ], f );
640
+
641
+ Add( temp, extra_row );
642
+
643
+ Add( temp_poly!.linearity, row_range + 1 );
644
+
645
+ fi;
646
+
647
+ return temp_poly;
648
+
649
+ end );
650
+
651
+ #################################
652
+ #
653
+ # Operations on two polyhedrons
654
+ #
655
+ #################################
656
+
657
+ InstallMethod( \+,
658
+ [ IsCddPolyhedron, IsCddPolyhedron ],
659
+ function( poly1, poly2 )
660
+ local col_range, g_vertices1, g_vertices2, g_rays1, g_rays2, new_generating_rays, new_generating_vertices, i,j, matrix, u ;
661
+
662
+ if Cdd_AmbientSpaceDimension( poly1) <> Cdd_AmbientSpaceDimension( poly1) then
663
+
664
+ Error( "The polyhedrons are not in the same space" );
665
+
666
+ fi;
667
+
668
+ col_range := Cdd_AmbientSpaceDimension( poly1 );
669
+
670
+ g_vertices1 := ShallowCopy ( Cdd_GeneratingVertices( poly1 ) );
671
+
672
+ if g_vertices1 = [ ] then
673
+
674
+ g_vertices1 := [ List( [ 1 .. col_range ], i -> 0 ) ];
675
+
676
+ fi;
677
+
678
+ g_vertices2 := ShallowCopy( Cdd_GeneratingVertices( poly2 ) );
679
+
680
+ if g_vertices2 = [ ] then
681
+
682
+ g_vertices2 := [ List( [ 1 .. col_range ], i -> 0 ) ];
683
+
684
+ fi;
685
+
686
+ new_generating_vertices := [ ];
687
+
688
+ for i in g_vertices1 do
689
+
690
+ for j in g_vertices2 do
691
+
692
+ Add( new_generating_vertices, i + j );
693
+
694
+ od;
695
+
696
+ od;
697
+
698
+ matrix := [ ];
699
+
700
+ for i in new_generating_vertices do
701
+
702
+ u := ShallowCopy( i );
703
+
704
+ Add( u, 1, 1 );
705
+
706
+ Add( matrix, u );
707
+
708
+ od;
709
+
710
+ g_rays1 := Cdd_GeneratingRays( poly1 );
711
+
712
+ g_rays2 := Cdd_GeneratingRays( poly2 );
713
+
714
+ new_generating_rays := Union( g_rays1 ,g_rays2 );
715
+
716
+ for i in new_generating_rays do
717
+
718
+ u := ShallowCopy( i );
719
+
720
+ Add( u, 0, 1 );
721
+
722
+ Add( matrix, u );
723
+
724
+ od;
725
+
726
+ return Cdd_H_Rep( Cdd_PolyhedronByGenerators( matrix ) );
727
+
728
+ end );
729
+
730
+ ##
731
+ InstallMethod( \=,
732
+ [ IsCddPolyhedron, IsCddPolyhedron ],
733
+ function( poly1, poly2 )
734
+ local generating_vertices1, generating_vertices2, generating_rays1, generating_rays2;
735
+
736
+ generating_vertices1 := Set(Cdd_GeneratingVertices( poly1 ) );
737
+
738
+ generating_vertices2 := Set(Cdd_GeneratingVertices( poly2 ) );
739
+
740
+ generating_rays1 := Set( Cdd_GeneratingRays( poly1 ) );
741
+
742
+ generating_rays2 := Set( Cdd_GeneratingRays( poly2 ) );
743
+
744
+ return generating_vertices1=generating_vertices2 and generating_rays1= generating_rays2;
745
+
746
+ end );
747
+
748
+ ##
749
+ InstallMethod( Cdd_Intersection,
750
+ [ IsCddPolyhedron, IsCddPolyhedron ],
751
+
752
+ function( poly1, poly2 )
753
+ local poly1_h, poly2_h, new_matrix, new_linearity, i, poly1_rowrange, poly2_rowrange;
754
+
755
+ poly1_h := Cdd_H_Rep( poly1 );
756
+
757
+ poly2_h := Cdd_H_Rep( poly2 );
758
+
759
+ new_matrix := StructuralCopy( poly1_h!.matrix );
760
+
761
+ new_linearity := StructuralCopy( poly1_h!.linearity );
762
+
763
+ poly1_rowrange := Length( poly1_h!.matrix );
764
+
765
+ poly2_rowrange := Length( poly2_h!.matrix );
766
+
767
+ for i in [ 1 .. poly2_rowrange ] do
768
+
769
+ Add( new_matrix, poly2_h!.matrix[ i ] );
770
+
771
+ if i in poly2_h!.linearity then
772
+
773
+ Add( new_linearity, i+poly1_rowrange );
774
+
775
+ fi;
776
+
777
+ od;
778
+
779
+ if Length( new_linearity ) = 0 then
780
+
781
+ return Cdd_Canonicalize( Cdd_PolyhedronByInequalities( new_matrix ) );
782
+
783
+ else
784
+
785
+ return Cdd_Canonicalize( Cdd_PolyhedronByInequalities( new_matrix, new_linearity ) );
786
+
787
+ fi;
788
+
789
+ end );
790
+ ##
791
+ InstallMethod( Cdd_IsContained,
792
+ [ IsCddPolyhedron, IsCddPolyhedron ],
793
+
794
+ function( poly1, poly2 )
795
+ local temp;
796
+
797
+ temp := Cdd_Intersection( poly1, poly2 );
798
+
799
+ return temp = poly1;
800
+
801
+ end );
802
+
803
+ ##################################
804
+ ##
805
+ ## Display Methods
806
+ ##
807
+ ##################################
808
+
809
+ ###
810
+ InstallMethod( ViewObj,
811
+ [ IsCddPolyhedron ],
812
+ function( poly )
813
+
814
+ Print( "<Polyhedron given by its ", poly!.rep_type, "resentation>" );
815
+
816
+ end );
817
+
818
+ ###
819
+ InstallMethod( ViewObj,
820
+ [ IsCddLinearProgram ],
821
+
822
+ function( poly )
823
+
824
+ Print( "<Linear program>" );
825
+
826
+ end );
827
+
828
+ ###
829
+ InstallMethod( Display,
830
+ [ IsCddPolyhedron ],
831
+ function( poly )
832
+
833
+ if poly!.rep_type = "V-rep" and poly!.matrix = [] then
834
+
835
+ Print( "The empty polyhedron" );
836
+
837
+ else
838
+
839
+ Print( poly!.rep_type, "resentation \n" );
840
+
841
+ if Length( poly!.linearity) <> 0 then
842
+
843
+ Print( "linearity ", Length( poly!.linearity ), ", ", poly!.linearity, "\n");
844
+
845
+ fi;
846
+
847
+ Print( "begin \n" );
848
+
849
+ Print( " ", Length( poly!.matrix ), " X ", Length( poly!.matrix[ 1 ] ), " ", poly!.number_type, "\n" );
850
+
851
+ PTM( poly!.matrix );
852
+
853
+ Print( "end\n" );
854
+
855
+ fi;
856
+
857
+ end );
858
+
859
+ ###
860
+ InstallMethod( Display,
861
+ [ IsCddLinearProgram ],
862
+ function( poly )
863
+
864
+ Print( "Linear program given by: \n" );
865
+
866
+ Display( poly!.polyhedron );
867
+
868
+ Print( poly!.objective, " ", poly!.rowvector );
869
+
870
+ end );
871
+