CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
#include "polymake_fan.h"
2
3
Obj REAL_FAN_BY_CONES_SAVE( Polymake_Data* data, Obj cones ){
4
5
if( ! IS_PLIST( cones ) ){
6
ErrorMayQuit( "not a plain list", 0, 0);
7
return NULL;
8
}
9
10
int numberofcones = LEN_PLIST( cones );
11
Obj akt;
12
Obj elem;
13
Obj numb;
14
int numberofrays = 0;
15
data->main_polymake_session->set_application("fan");
16
17
for(int i=1;i<=numberofcones;i++){
18
akt = ELM_PLIST( cones, i );
19
#ifdef MORE_TESTS
20
if( !IS_PLIST( akt ) ){
21
ErrorMayQuit( "one cone is not a plain list", 0, 0);
22
return NULL;
23
}
24
#endif
25
numberofrays += LEN_PLIST( akt );
26
27
}
28
int dimension = LEN_PLIST( ELM_PLIST( ELM_PLIST( cones, 1 ), 1 ) );
29
pm::Array< pm::Set <pm::Integer> > incMatr(numberofcones,pm::Set<pm::Integer>());
30
pm::Integer* ratarray = new pm::Integer[ (numberofrays+1)*dimension ];
31
int raycounter = 1;
32
for(int i = 0; i < dimension; i++ )
33
ratarray[i] = 0;
34
for(int i = 1; i <= numberofcones; i++){
35
akt = ELM_PLIST( cones, i );
36
for( int j = 1; j <= LEN_PLIST( akt ); j++){
37
elem = ELM_PLIST( akt, j );
38
for( int k = 1; k <= LEN_PLIST( elem ); k++){
39
numb = ELM_PLIST( elem, k );
40
41
#ifdef MORE_TESTS
42
if( ! IS_INTOBJ( numb ) ){
43
ErrorMayQuit( "some entries are not integers", 0, 0);
44
return NULL;
45
}
46
#endif
47
48
ratarray[ raycounter*dimension+(k-1) ] = INT_INTOBJ( numb );
49
50
}
51
(incMatr[i-1]).collect(raycounter);
52
raycounter++;
53
}
54
}
55
pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>((numberofrays+1),dimension,ratarray);
56
perlobj q;
57
CallPolymakeFunction("check_fan",*matr,incMatr) >> q;
58
data->polymake_objects->insert( object_pair(data->new_polymake_object_number, &q ) );
59
elem = INTOBJ_INT( data->new_polymake_object_number );
60
data->new_polymake_object_number++;
61
return elem;
62
}
63
64
65
66
Obj REAL_FAN_BY_CONES( Polymake_Data* data, Obj cones ){
67
68
if( ! IS_PLIST( cones ) ){
69
ErrorMayQuit( "not a plain list", 0, 0);
70
return NULL;
71
}
72
73
int numberofcones = LEN_PLIST( cones );
74
Obj akt;
75
Obj elem;
76
Obj numb;
77
int numberofrays = 0;
78
data->main_polymake_session->set_application("fan");
79
80
for(int i=1;i<=numberofcones;i++){
81
akt = ELM_PLIST( cones, i );
82
#ifdef MORE_TESTS
83
if( !IS_PLIST( akt ) ){
84
ErrorMayQuit( "one cone is not a plain list", 0, 0);
85
return NULL;
86
}
87
#endif
88
numberofrays += LEN_PLIST( akt );
89
90
}
91
92
int dimension = LEN_PLIST( ELM_PLIST( ELM_PLIST( cones, 1 ), 1 ) );
93
pm::Array< pm::Set<pm::Integer> >* incMatr;
94
incMatr = new pm::Array< pm::Set<pm::Integer> >(numberofcones,pm::Set<pm::Integer>());
95
pm::Integer* ratarray;
96
ratarray = new pm::Integer[ (numberofrays+1)*dimension ];
97
int raycounter = 1;
98
for(int i = 0; i < dimension; i++ )
99
ratarray[i] = 0;
100
for(int i = 1; i <= numberofcones; i++){
101
akt = ELM_PLIST( cones, i );
102
for( int j = 1; j <= LEN_PLIST( akt ); j++){
103
elem = ELM_PLIST( akt, j );
104
for( int k = 1; k <= LEN_PLIST( elem ); k++){
105
numb = ELM_PLIST( elem, k );
106
107
#ifdef MORE_TESTS
108
if( ! IS_INTOBJ( numb ) ){
109
delete [] ratarray;
110
delete incMatr;
111
ErrorMayQuit( "some entries are not integers", 0, 0);
112
return NULL;
113
}
114
#endif
115
116
ratarray[ raycounter*dimension+(k-1) ] = INT_INTOBJ( numb );
117
118
}
119
((*incMatr)[i-1]).collect(raycounter);
120
raycounter++;
121
}
122
}
123
pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>((numberofrays+1),dimension,ratarray);
124
perlobj* q = new perlobj("PolyhedralFan<Rational>");
125
q->take("INPUT_RAYS") << *matr;
126
q->take("INPUT_CONES") << *incMatr;
127
elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );
128
POLYMAKEOBJ_SET_PERLOBJ( elem, q);
129
delete [] ratarray;
130
delete incMatr;
131
delete matr;
132
return elem;
133
}
134
135
136
137
Obj REAL_FAN_BY_RAYS_AND_CONES( Polymake_Data* data, Obj rays, Obj cones ){
138
139
if( ! IS_PLIST( cones ) || ! IS_PLIST( rays ) ){
140
ErrorMayQuit( "not a plain list", 0, 0);
141
return NULL;
142
}
143
144
int numberofrays = LEN_PLIST( rays );
145
Obj akt;
146
Obj elem;
147
Obj numb;
148
data->main_polymake_session->set_application("fan");
149
int dimension = LEN_PLIST( ELM_PLIST( rays, 1 ) );
150
pm::Integer* ratarray;
151
ratarray = new pm::Integer[ numberofrays*dimension ];
152
for(int i=0;i<numberofrays;i++){
153
akt = ELM_PLIST( rays, i+1 );
154
#ifdef MORE_TESTS
155
if( !IS_PLIST( akt ) || LEN_PLIST( akt ) != dimension ){
156
delete [] ratarray;
157
ErrorMayQuit( "one ray is not a plain list", 0, 0);
158
return NULL;
159
}
160
#endif
161
for(int j = 0; j<dimension; j++){
162
numb = ELM_PLIST( akt, j+1 );
163
#ifdef MORE_TESTS
164
if( ! IS_INTOBJ( numb ) ){
165
delete [] ratarray;
166
ErrorMayQuit( "some entries are not integers", 0, 0);
167
return NULL;
168
}
169
#endif
170
ratarray[(i*dimension)+j] = INT_INTOBJ( numb );
171
}
172
}
173
int numberofcones = LEN_PLIST( cones );
174
pm::Array< pm::Set<pm::Integer> >* incMatr;
175
incMatr = new pm::Array< pm::Set<pm::Integer> >(numberofcones,pm::Set<pm::Integer>());
176
for(int i=0;i<numberofcones;i++){
177
akt = ELM_PLIST( cones, i+1 );
178
#ifdef MORE_TESTS
179
if( !IS_PLIST( akt ) ){
180
delete [] ratarray;
181
delete incMatr;
182
ErrorMayQuit( "one cone is not a plain list", 0, 0);
183
return NULL;
184
}
185
#endif
186
for(int j = 0; j < LEN_PLIST( akt ) ; j++){
187
numb = ELM_PLIST( akt, j+1 );
188
#ifdef MORE_TESTS
189
if( ! IS_INTOBJ( numb ) ){
190
delete [] ratarray;
191
delete incMatr;
192
ErrorMayQuit( "some entries are not integers", 0, 0);
193
return NULL;
194
}
195
#endif
196
((*incMatr)[i]).collect( INT_INTOBJ( numb ) - 1 );
197
}
198
}
199
200
pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>(numberofrays,dimension,ratarray);
201
perlobj* q = new perlobj("PolyhedralFan<Rational>");
202
q->take("INPUT_RAYS") << *matr;
203
q->take("INPUT_CONES") << *incMatr;
204
elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );
205
POLYMAKEOBJ_SET_PERLOBJ( elem, q);
206
delete [] ratarray;
207
delete matr;
208
delete incMatr;
209
return elem;
210
}
211
212
// TODO: F
213
Obj REAL_FAN_BY_RAYS_AND_CONES_UNSAVE( Polymake_Data* data, Obj rays, Obj cones ){
214
215
if( ! IS_PLIST( cones ) || ! IS_PLIST( rays ) ){
216
ErrorMayQuit( "not a plain list", 0, 0);
217
return NULL;
218
}
219
220
int numberofrays = LEN_PLIST( rays );
221
Obj akt;
222
Obj elem;
223
Obj numb;
224
data->main_polymake_session->set_application("fan");
225
int dimension = LEN_PLIST( ELM_PLIST( rays, 1 ) );
226
pm::Integer* ratarray;
227
ratarray = new pm::Integer[ numberofrays*dimension ];
228
for(int i=0;i<numberofrays;i++){
229
akt = ELM_PLIST( rays, i+1 );
230
#ifdef MORE_TESTS
231
if( !IS_PLIST( akt ) || LEN_PLIST( akt ) != dimension ){
232
delete [] ratarray;
233
ErrorMayQuit( "one ray is not a plain list", 0, 0);
234
return NULL;
235
}
236
#endif
237
for(int j = 0; j<dimension; j++){
238
numb = ELM_PLIST( akt, j+1 );
239
#ifdef MORE_TESTS
240
if( ! IS_INTOBJ( numb ) ){
241
delete [] ratarray;
242
ErrorMayQuit( "some entries are not integers", 0, 0);
243
return NULL;
244
}
245
#endif
246
ratarray[(i*dimension)+j] = INT_INTOBJ( numb );
247
}
248
}
249
int numberofcones = LEN_PLIST( cones );
250
pm::IncidenceMatrix< >* incMatr;
251
incMatr = new pm::IncidenceMatrix<>(numberofcones,numberofrays);
252
for(int i=0;i<numberofcones;i++){
253
akt = ELM_PLIST( cones, i+1 );
254
#ifdef MORE_TESTS
255
if( !IS_PLIST( akt ) ){
256
delete [] ratarray;
257
delete incMatr;
258
ErrorMayQuit( "one cone is not a plain list", 0, 0);
259
return NULL;
260
}
261
#endif
262
for(int j = 0; j < LEN_PLIST( akt ) ; j++){
263
numb = ELM_PLIST( akt, j+1 );
264
#ifdef MORE_TESTS
265
if( ! IS_INTOBJ( numb ) ){
266
delete [] ratarray;
267
delete incMatr;
268
ErrorMayQuit( "some entries are not integers", 0, 0);
269
return NULL;
270
}
271
#endif
272
((*incMatr)[i])+= INT_INTOBJ( numb ) - 1;
273
}
274
}
275
276
pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>(numberofrays,dimension,ratarray);
277
perlobj* q = new perlobj("PolyhedralFan<Rational>");
278
q->take("RAYS") << *matr;
279
q->take("MAXIMAL_CONES") << *incMatr;
280
elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );
281
POLYMAKEOBJ_SET_PERLOBJ( elem, q);
282
delete [] ratarray;
283
delete matr;
284
delete incMatr;
285
return elem;
286
}
287
288
289
290
Obj REAL_RAYS_IN_MAXCONES_OF_FAN( Polymake_Data* data, Obj fan ){
291
292
#ifdef MORE_TESTS
293
if(! IS_POLYMAKE_FAN(fan) ){
294
ErrorMayQuit(" parameter is not a fan.",0,0);
295
return NULL;
296
}
297
#endif
298
299
perlobj* coneobj = PERLOBJ_POLYMAKEOBJ( fan );
300
data->main_polymake_session->set_application_of(*coneobj);
301
pm::IncidenceMatrix<pm::NonSymmetric> matr;
302
try
303
{
304
pm::IncidenceMatrix<pm::NonSymmetric> matr_temp = coneobj->give("MAXIMAL_CONES");
305
matr = matr_temp;
306
}
307
308
POLYMAKE_GAP_CATCH
309
310
Obj RETLI = NEW_PLIST( T_PLIST , matr.rows());
311
UInt matr_rows = matr.rows();
312
SET_LEN_PLIST( RETLI , matr_rows );
313
Obj LIZeil;
314
UInt matr_cols = matr.cols();
315
for(int i = 0;i<matr.rows();i++){
316
LIZeil = NEW_PLIST( T_PLIST, matr.cols());
317
SET_LEN_PLIST( LIZeil , matr_cols );
318
for(int j = 0;j<matr.cols();j++){
319
SET_ELM_PLIST(LIZeil,j+1,INTOBJ_INT(matr(i,j)));
320
}
321
SET_ELM_PLIST(RETLI,i+1,LIZeil);
322
CHANGED_BAG(RETLI);
323
}
324
return RETLI;
325
326
}
327
328
329
330
Obj REAL_NORMALFAN_OF_POLYTOPE( Polymake_Data* data, Obj polytope ){
331
332
#ifdef MORE_TESTS
333
if(! IS_POLYMAKE_POLYTOPE(polytope) ){
334
ErrorMayQuit(" parameter is not a polytope.",0,0);
335
return NULL;
336
}
337
#endif
338
339
perlobj* coneobj = PERLOBJ_POLYMAKEOBJ( polytope );
340
data->main_polymake_session->set_application("fan");
341
perlobj p;
342
try{
343
CallPolymakeFunction("normal_fan",*coneobj) >> p;
344
}
345
346
POLYMAKE_GAP_CATCH
347
348
perlobj* q = new perlobj(p);
349
//data->polymake_objects->insert( object_pair(data->new_polymake_object_number, &p ) );
350
Obj elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );
351
POLYMAKEOBJ_SET_PERLOBJ( elem, q );
352
return elem;
353
}
354
355
356
Obj REAL_STELLAR_SUBDIVISION( Polymake_Data* data, Obj ray, Obj fan ){
357
358
#ifdef MORE_TESTS
359
if( (! IS_POLYMAKE_CONE(ray)) || (! IS_POLYMAKE_FAN(fan)) ){
360
ErrorMayQuit(" parameter is not a fan or a cone.",0,0);
361
return NULL;
362
}
363
#endif
364
perlobj* rayobject = PERLOBJ_POLYMAKEOBJ( ray );
365
perlobj* fanobject = PERLOBJ_POLYMAKEOBJ( fan );
366
data->main_polymake_session->set_application("fan");
367
perlobj p;
368
try{
369
CallPolymakeFunction("stellar_subdivision",*rayobject,*fanobject) >> p;
370
}
371
372
POLYMAKE_GAP_CATCH
373
374
perlobj* q = new perlobj(p);
375
Obj elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_FAN );
376
POLYMAKEOBJ_SET_PERLOBJ( elem, q );
377
return elem;
378
}
379
380
381
Obj REAL_RAYS_OF_FAN( Polymake_Data* data, Obj fan){
382
383
#ifdef MORE_TESTS
384
if( ( ! IS_POLYMAKE_FAN(fan) ) ){
385
ErrorMayQuit(" parameter is not a cone or fan.",0,0);
386
return NULL;
387
}
388
#endif
389
390
perlobj* coneobj = PERLOBJ_POLYMAKEOBJ( fan );
391
data->main_polymake_session->set_application_of(*coneobj);
392
pm::Matrix<pm::Rational> matr;
393
try{
394
pm::Matrix<pm::Rational> matr_temp = coneobj->give("RAYS");
395
matr = matr_temp;
396
}
397
398
POLYMAKE_GAP_CATCH
399
400
Obj RETLI = NEW_PLIST( T_PLIST , matr.rows());
401
UInt matr_rows = matr.rows();
402
SET_LEN_PLIST( RETLI , matr_rows );
403
Obj LIZeil;
404
UInt matr_cols = matr.cols();
405
polymake::common::primitive( matr );
406
for(int i = 0;i<matr.rows();i++){
407
LIZeil = NEW_PLIST( T_PLIST, matr.cols());
408
SET_LEN_PLIST( LIZeil , matr_cols );
409
for(int j = 0;j<matr.cols();j++){
410
SET_ELM_PLIST(LIZeil,j+1,INTOBJ_INT( (matr(i,j)).to_int() ));
411
}
412
SET_ELM_PLIST(RETLI,i+1,LIZeil);
413
CHANGED_BAG(RETLI);
414
}
415
return RETLI;
416
}
417
418
419
Obj REAL_F_VECTOR( Polymake_Data* data, Obj fan){
420
421
#ifdef MORE_TESTS
422
if( ( ! IS_POLYMAKE_FAN(fan) ) ){
423
ErrorMayQuit(" parameter is not a cone or fan.",0,0);
424
return NULL;
425
}
426
#endif
427
428
perlobj* fanobj = PERLOBJ_POLYMAKEOBJ( fan );
429
data->main_polymake_session->set_application_of(*fanobj);
430
pm::Vector<pm::Integer> matr;
431
try{
432
pm::Vector<pm::Integer> matr_temp = fanobj->give("F_VECTOR");
433
matr = matr_temp;
434
}
435
436
POLYMAKE_GAP_CATCH
437
438
UInt matr_rows = matr.size();
439
Obj RETLI = NEW_PLIST( T_PLIST , matr.size() );
440
SET_LEN_PLIST( RETLI , matr_rows );
441
for(int i = 0;i<matr.size(); i++){
442
SET_ELM_PLIST(RETLI,i+1,INTOBJ_INT( (matr[i]).to_int() ));
443
CHANGED_BAG(RETLI);
444
}
445
return RETLI;
446
}
447