-
Notifications
You must be signed in to change notification settings - Fork 2
/
cddio.c
1426 lines (1311 loc) · 38.8 KB
/
cddio.c
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* cddio.c: Basic Input and Output Procedures for cdd.c
written by Komei Fukuda, [email protected]
Version 0.61, December 1, 1997
*/
/* cdd.c : C-Implementation of the double description method for
computing all vertices and extreme rays of the polyhedron
P= {x : b - A x >= 0}.
Please read COPYING (GNU General Public Licence) and
the manual cddman.tex for detail.
*/
#include "setoper.h" /* set operation library header (Ver. March 16,1995 or later) */
#include "cdddef.h"
#include "cdd.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
void SetInputFile(FILE **f, boolean *success)
{
boolean opened=FALSE,stop, quit=FALSE;
int i,dotpos=0, semipos=0;
char ch;
char *tempname;
*success=FALSE;
while (!opened && !quit) {
if (FileInputMode!=Auto){
printf("\n>> Input file (*.ine or *.ext) : ");
scanf("%s",inputfile);
ch=getchar();
}
stop=FALSE;
for (i=0; i<filenamelen && !stop; i++){
ch=inputfile[i];
switch (ch) {
case '.':
dotpos=i+1;
break;
case ';': case ' ': case '\0': case '\n': case '\t':
if (ch==';'){
semipos=i+1;
FileInputMode=SemiAuto;
/* semicolon at the end of the filename
-> output file names will be creeated with defaults. */
}
stop=TRUE;
tempname=(char*)calloc(filenamelen,sizeof ch);
strncpy(tempname, inputfile, i);
strcpy(inputfile,tempname);
break;
}
}
if (dotpos>0){
strncpy(ifilehead, inputfile, dotpos-1);
}else{
strcpy(ifilehead, inputfile);
}
if (debug){
printf("inputfile name: %s\n", inputfile);
printf("inputfile name head: %s\n", ifilehead);
printf("semicolon pos: %d\n", semipos);
}
if ( ( *f = fopen(inputfile, "r") )!= NULL) {
if (DynamicWriteOn) printf("input file %s is open\n", inputfile);
opened=TRUE;
*success=TRUE;
}
else{
printf("The file %s not found\n",inputfile);
if (FileInputMode==Auto) {
quit=TRUE;
}
}
}
}
void SetWriteFile(FILE **f, DataFileType fname, char cflag, char *fscript)
{
boolean quit=FALSE;
char *extension;
DataFileType newname;
switch (cflag) {
case 'o':
switch (Conversion) {
case ExtToIne:
extension=".ine"; break; /* output file for ine data */
case IneToExt: case Projection:
extension=".ext"; break; /* output file for ext data */
case LPmax: case LPmin: case InteriorFind:
extension=".lps"; break; /* output file for LPmax, LPmin, interior_find */
default:
extension=".out";break;
}
break;
case 'a':
if (Conversion==IneToExt)
extension=".ead"; /* adjacency file for ext data */
else
extension=".iad"; /* adjacency file for ine data */
break;
case 'i':
if (Conversion==IneToExt)
extension=".ecd"; /* ext incidence file */
else
extension=".icd"; /* ine incidence file */
break;
case 'l':
extension=".ddl";break;
case 'd':
extension=".dex";break; /* decomposition output */
case 'p':
extension="sub.ine";break;
case 'v':
extension=".solved";break;
default:
extension=".xxx";break;
}
if (FileInputMode==Manual){
while (!quit) {
printf("\n>> %s file name (*%s) : ",fscript, extension);
scanf("%s",fname);
if (fname[0]==';'|| fname[0]<'0'){
quit=TRUE; /* default file name */
}
else if (strcmp(inputfile, fname)!=0){
*f = fopen(fname, "w");
if (DynamicWriteOn) printf("write file %s is open\n",fname);
goto _L99;
}
else {
printf("%s file %s must have a name different from inputfile.\n",fscript,fname);
}
}
}
/* Auto or SemiAuto FileInput */
strcpy(fname,ifilehead);
strcat(fname,extension);
if (strcmp(inputfile, fname)==0) {
strcpy(newname,fname);
strcat(newname,".old");
rename(fname,newname);
if (DynamicWriteOn){
printf("Default output file %s exists.\n",fname);
printf("Caution: The old file %s is renamed to %s!\n",fname,newname);
printf("Create a new file %s.\n",fname);
}
/* strcpy(fname,inputfile);
strcat(fname,extension);
*/
}
*f = fopen(fname, "w");
if (DynamicWriteOn) printf("%s file %s is open\n",fscript,fname);
_L99:;
}
void SetNumberType(char *line)
{
if (strncmp(line, "integer", 7)==0) {
Number = Integer;
return;
}
else if (strncmp(line, "rational", 8)==0) {
Number = Rational;
Error=ImproperInputFormat; /* Rational Input not supported */
return;
}
else if (strncmp(line, "real", 4)==0) {
Number = Integer;
return;
}
else {
Number=Unknown;
Error=ImproperInputFormat;
}
}
void ProcessCommandLine(rowrange m_input, colrange n_input, char *line)
{
colrange j;
long var,msize;
double cost;
if (strncmp(line, "dynout_off", 10)==0) {
DynamicRayWriteOn = FALSE;
return;
}
if (strncmp(line, "stdout_off", 10)==0) {
DynamicRayWriteOn = FALSE;
DynamicWriteOn = FALSE;
return;
}
if (strncmp(line, "logfile_on", 10)==0) {
LogWriteOn = TRUE;
return;
}
if (strncmp(line, "logfile_off", 11)==0) {
LogWriteOn = FALSE;
return;
}
if (strncmp(line, "hull", 4)==0) {
Conversion = ExtToIne;
return;
}
if (strncmp(line, "incidence", 9)==0) {
IncidenceOutput = IncSet;
return;
}
if (strncmp(line, "#incidence", 10)==0) {
IncidenceOutput = IncCardinality;
return;
}
if (strncmp(line, "adjacency", 9)==0) {
AdjacencyOutput = AdjacencyList;
return;
}
if (strncmp(line, "#adjacency", 10)==0) {
AdjacencyOutput = AdjacencyDegree;
fscanf(reading,"%ld", &msize);
set_initialize(&CheckPoints, m_input+1);
for (j=1;j<=msize;j++) {
fscanf(reading,"%ld",&var);
if (var <= m_input+1) set_addelem(CheckPoints,var);
}
return;
}
/* algebraic option is not efficient in most cases and deleted from Version 051 */
/*
if (strncmp(line, "algebraic", 9)==0) {
AdjacencyTest = Algebraic;
return;
}
*/
if (strncmp(line, "nondegenerate", 14)==0) {
NondegAssumed = TRUE;
return;
}
if (strncmp(line, "minindex", 8)==0) {
HyperplaneOrder = MinIndex;
return;
}
if (strncmp(line, "maxindex", 8)==0) {
HyperplaneOrder = MaxIndex;
return;
}
if (strncmp(line, "mincutoff", 9)==0) {
HyperplaneOrder = MinCutoff;
return;
}
if (strncmp(line, "maxcutoff", 9)==0) {
HyperplaneOrder = MaxCutoff;
return;
}
if (strncmp(line, "mixcutoff", 9)==0) {
HyperplaneOrder = MixCutoff;
return;
}
if (strncmp(line, "lexmin", 6)==0) {
HyperplaneOrder = LexMin;
return;
}
if (strncmp(line, "lexmax", 6)==0) {
HyperplaneOrder = LexMax;
return;
}
if (strncmp(line, "random", 6)==0) {
HyperplaneOrder = RandomRow;
fscanf(reading,"%d", &rseed);
if (rseed <= 0) rseed = 1;
return;
}
if (strncmp(line, "lineshell", 9)==0) {
HyperplaneOrder = LineShelling;
return;
}
if (strncmp(line, "initbasis_at_bottom", 19)==0) {
InitBasisAtBottom = TRUE;
return;
}
if (strncmp(line, "verify_input", 12)==0) {
VerifyInput = TRUE;
return;
}
if (strncmp(line, "output_reordered", 16)==0 && !OutputReordered){
printf("* The reordered problem will be generated.\n");
OutputReordered=TRUE;
return;
}
if (strncmp(line, "debug", 5)==0) {
debug = TRUE;
return;
}
if ((strncmp(line, "partial_enum", 12)==0 || strncmp(line, "equality", 8)==0)
&& RestrictedEnumeration==FALSE) {
fscanf(reading,"%ld", &msize);
for (j=1;j<=msize;j++) {
fscanf(reading,"%ld",&var);
EqualityIndex[var]=1;
}
printf("\n");
if (Conversion==Projection) {
printf("Warning: Partial Projection is cancelled because it cannot be compatible with Partial Enumeration.\n");
Conversion=IneToExt;
}
RestrictedEnumeration=TRUE;
return;
}
if (strncmp(line, "strict_ineq", 11)==0 && RelaxedEnumeration==FALSE) {
fscanf(reading,"%ld", &msize);
for (j=1;j<=msize;j++) {
fscanf(reading,"%ld",&var);
EqualityIndex[var]=-1;
}
printf("\n");
if (Conversion==Projection) {
printf("Warning: Partial Projection is cancelled because it cannot be compatible with Partial Enumeration.\n");
Conversion=IneToExt;
}
RelaxedEnumeration=TRUE;
return;
}
if (strncmp(line, "preprojection", 13)==0 && Conversion != Projection) {
set_initialize(&projvars,n_input);
fscanf(reading,"%ld", &projdim);
if (debug) printf("dimension of projection = %ld in variables:\n",projdim);
for (j=1;j<=projdim;j++) {
fscanf(reading,"%ld",&var);
if (debug) printf(" %ld",var);
if (Inequality==NonzeroRHS)
set_addelem(projvars,var+1);
else
set_addelem(projvars,var);
}
Conversion=Projection;
return;
}
if (strncmp(line, "maximize", 8)==0 && Conversion != LPmax) {
if (debug) printf("linear maximization is chosen.\n");
for (j=0;j<n_input;j++) {
fscanf(reading,"%lf",&cost);
LPcost[j]=cost;
if (debug) printf(" cost[%ld] = %.9E\n",j,LPcost[j]);
}
Conversion=LPmax;
if (debug) {
printf("\n");
}
return;
}
if (strncmp(line, "minimize", 8)==0 && Conversion != LPmin) {
if (debug) printf("linear minimization is chosen.\n");
for (j=0;j<n_input;j++) {
fscanf(reading,"%lf",&cost);
LPcost[j]=cost;
if (debug) printf(" cost[%ld] = %.9E\n",j,LPcost[j]);
}
Conversion=LPmin;
if (debug) {
printf("\n");
}
return;
}
if (strncmp(line, "dual_simplex", 12)==0 && LPsolver != DualSimplex) {
if (DynamicWriteOn) printf("Use the dual simplex method.\n");
LPsolver=DualSimplex;
return;
}
if (strncmp(line, "criss-cross", 9)==0 && LPsolver != CrissCross) {
if (DynamicWriteOn) printf("Use the crss-cross method.\n");
LPsolver=CrissCross;
return;
}
if (strncmp(line, "find_interior", 13)==0 && Conversion != InteriorFind) {
printf("Interior finding option is chosen.\n");
Conversion=InteriorFind;
return;
}
if (strncmp(line, "row_decomp", 10)==0 && !RowDecomposition) {
printf("Row decomposition is chosen.\n");
RowDecomposition=TRUE;
return;
}
}
void AmatrixInput(rowrange *m_input, colrange *n_input,
rowrange *m_size, colrange *n_size, Amatrix A, boolean *successful)
{
long i,j;
double value;
long value1,value2;
boolean found=FALSE,decided=FALSE, fileopened, newformat=FALSE;
char command[wordlenmax], numbtype[wordlenmax], stemp[wordlenmax], line[linelenmax];
*successful = FALSE;
SetInputFile(&reading, &fileopened);
if (!fileopened){
Error=FileNotFound;
goto _L99;
}
while (!found)
{
if (fscanf(reading,"%s",command)==EOF) {
Error=ImproperInputFormat;
goto _L99;
}
else {
if (strncmp(command, "V-representation", 16)==0) {
Conversion = ExtToIne; newformat=TRUE;
} else if (strncmp(command, "H-representation", 16)==0){
Conversion =IneToExt; newformat=TRUE;
} else if (strncmp(command, "begin", 5)==0) found=TRUE;
}
}
fscanf(reading, "%ld %ld %s", m_input, n_input, numbtype);
printf("size = %ld x %ld\nNumber Type = %s\n", *m_input, *n_input, numbtype);
SetNumberType(numbtype);
if (Number==Unknown || Number == Rational) {
goto _L99;
}
Inequality=ZeroRHS;
for (i=1; i<= *m_input && !decided; i++) {
fscanf(reading,"%lf", &value);
if (fabs(value) > zero) {
Inequality = NonzeroRHS;
decided=TRUE;
}
for (j=2; j<= *n_input; j++) {
fscanf(reading,"%lf", &value);
}
fgets(line,linelenmax,reading);
if (debug) printf("comments to be skipped: %s\n",line);
if (debug) putchar('\n');
}
if (Inequality==NonzeroRHS) {
printf("Nonhomogeneous system with m = %5ld n = %5ld\n", *m_input, *n_input);
*n_size = *n_input;
}
else {
printf("Homogeneous system with m = %5ld n = %5ld\n", *m_input, *n_input);
*n_size = *n_input-1;
}
if (*n_size > NMAX || *m_input > MMAX) {
Error = DimensionTooLarge;
goto _L99;
}
RestrictedEnumeration = FALSE;
RelaxedEnumeration = FALSE;
EqualityIndex=(long *)calloc(*m_input+2, sizeof *EqualityIndex);
for (i = 0; i <= *m_input+1; i++) EqualityIndex[i]=0;
while (!feof(reading)) {
fscanf(reading,"%s", command);
ProcessCommandLine(*m_input, *n_input, command);
}
fclose(reading);
reading=fopen(inputfile, "r");
found=FALSE;
while (!found)
{
if (!feof(reading)) {
fscanf(reading,"%s",command);
if (strncmp(command, "begin", 5)==0) {
found=TRUE;
}
}
else {
Error=ImproperInputFormat;
goto _L99;
}
}
fscanf(reading, "%ld %ld %s", &value1, &value2, stemp);
for (i = 1; i <= *m_input; i++) {
A[i-1]=(double *) calloc(*n_input, sizeof value);
for (j = 1; j <= *n_input; j++) {
fscanf(reading, "%lf", &value);
if (Inequality==NonzeroRHS)
A[i-1][j - 1] = value;
else if (j>=2) {
A[i-1][j - 2] = value;
}
if (debug) printf("a(%3ld,%5ld) = %10.4f\n",i,j,value);
} /*of j*/
fgets(line,linelenmax,reading);
if (debug) printf("comments to be skipped: %s\n",line);
if (debug) putchar('\n');
} /*of i*/
if (fscanf(reading,"%s",command)==EOF) {
Error=ImproperInputFormat;
goto _L99;
}
else if (strncmp(command, "end", 3)!=0) {
if (debug) printf("'end' missing or illegal extra data: %s\n",command);
Error=ImproperInputFormat;
goto _L99;
}
switch (Conversion) {
case IneToExt:
if (Inequality==NonzeroRHS){
*m_size = *m_input + 1;
A[*m_size-1]=(double *) calloc(*n_input, sizeof value);
for (j = 1; j <= *n_input; j++) { /*artificial row for x_1 >= 0*/
if (j == 1)
A[*m_size - 1][j - 1] = 1.0;
else
A[*m_size - 1][j - 1] = 0.0;
}
} else {
*m_size = *m_input;
}
break;
case ExtToIne:
*m_size = *m_input;
break;
case LPmax: case LPmin:
*m_size = *m_input + 1;
OBJrow=*m_size;
RHScol=1L;
A[*m_size-1]=(double *) calloc(*n_input, sizeof value);
for (j = 1; j <= *n_input; j++) { /*objective row */
A[*m_size - 1][j - 1] = LPcost[j-1];
}
break;
default:
*m_size = *m_input;
}
SetInequalitySets(*m_size, EqualityIndex);
*successful = TRUE;
_L99: ;
if (reading!=NULL) fclose(reading);
}
void WriteRayRecord(FILE *f, colrange n_size, RayRecord *RR)
{
long j;
double scaler;
if (Inequality == ZeroRHS) {
fprintf(f, " %2d", 0);
for (j = 0; j < n_size; j++)
WriteReal(f, RR->Ray[j]);
}
else {
scaler = fabs(RR->Ray[0]);
if (scaler > zero) {
if (RR->Ray[0] > 0) {
if (Conversion == IneToExt) {
fprintf(f, " %2d", 1);
for (j = 1; j < n_size; j++)
WriteReal(f, RR->Ray[j] / scaler);
}
else {
/* hull computation is chosen */
for (j = 0; j < n_size; j++)
WriteReal(f, RR->Ray[j]);
}
}
else {
/* hull computation must have been chosen, since RR->Ray[0] is negative */
for (j = 0; j < n_size; j++)
WriteReal(f, RR->Ray[j]);
}
}
else {
fprintf(f, " %2d", 0);
for (j = 1; j < n_size; j++)
WriteReal(f, RR->Ray[j]);
}
}
if (IncidenceOutput==IncCardinality) {
fprintf(f," : %1ld", set_card(RR->ZeroSet));
}
putc('\n', f);
}
void WriteRayRecord2(FILE *f, colrange n_size, RayRecord *RR)
{
long j;
fprintf(f, " Ray = ");
for (j = 0; j < n_size; j++)
fprintf(f, "%6.2f", RR->Ray[j]);
putchar('\n');
fprintf(f, " ZeroSet =");
set_fwrite(f, RR->ZeroSet);
putc('\n', f);
}
void WriteSubMatrixOfA(FILE *f, rowrange m_size, colrange n_size, Amatrix A,
rowset ChosenRow, colset ChosenCol, InequalityType ineq)
{
long i,j;
fprintf(f, "H-representation\nbegin\n");
if (ineq==ZeroRHS)
fprintf(f, " %ld %ld real\n",m_size, set_card(ChosenCol)+1);
else
fprintf(f, " %ld %ld real\n",m_size, set_card(ChosenCol));
for (i=1; i <= m_size; i++) {
if (set_member(i,ChosenRow)) {
if (ineq==ZeroRHS){ /* If RHS==0, output zero first */
WriteReal(f, 0);
for (j=1; j <= n_size; j++) {
if (set_member(j, ChosenCol)){
WriteReal(f, A[i-1][j-1]);
}
}
}
else {
for (j=1; j <= n_size; j++) {
if (set_member(j, ChosenCol)){
WriteReal(f, A[i-1][j-1]);
}
}
}
fprintf(f,"\n");
}
}
fprintf(f,"end\n");
}
void WriteAmatrix(FILE *f, Amatrix A, long rowmax, long colmax,
InequalityType ineq)
{
long i,j;
fprintf(f, "begin\n");
if (ineq==ZeroRHS)
fprintf(f, " %ld %ld real\n",rowmax, colmax+1);
else
fprintf(f, " %ld %ld real\n",rowmax, colmax);
for (i=1; i <= rowmax; i++) {
if (ineq==ZeroRHS)
WriteReal(f, 0); /* if RHS==0, the column is not explicitely stored */
for (j=1; j <= colmax; j++) {
WriteReal(f, A[i-1][j-1]);
}
fprintf(f,"\n");
}
fprintf(f, "end\n");
}
void WriteAmatrix2(FILE *f, Amatrix A, long rowmax, long colmax,
InequalityType ineq, rowindex OV, rowrange iteration)
{ /* Writing an A matrix with a given ordering and size */
long i,j,imax;
imax=iteration;
if (imax>rowmax) imax=rowmax;
fprintf(f, "begin\n");
if (ineq==ZeroRHS)
fprintf(f, " %ld %ld real\n",imax, colmax+1);
else
fprintf(f, " %ld %ld real\n",imax, colmax);
for (i=1; i <= imax; i++) {
if (ineq==ZeroRHS)
WriteReal(f, 0); /* if RHS==0, the column is not explicitely stored */
for (j=1; j <= colmax; j++) {
WriteReal(f, A[OV[i]-1][j-1]);
}
fprintf(f," #%1ld\n", OV[i]);
}
fprintf(f, "end\n");
}
void WriteBmatrix(FILE *f, colrange n_size, Bmatrix T)
{
colrange j1, j2;
for (j1 = 0; j1 < n_size; j1++) {
for (j2 = 0; j2 < n_size; j2++) {
fprintf(f, "%15.7f ", T[j1][j2]);
} /*of j2*/
putc('\n', f);
} /*of j1*/
putc('\n', f);
}
void WriteReal(FILE *f, double x)
{
long ix1,ix2,ix;
ix1= fabs(x) * 10000. + 0.5;
ix2= (fabs(x) + 0.5);
ix2= ix2*10000;
if ( ix1 == ix2) {
if (x>0) {
ix = x + 0.5;
} else {
ix = -x + 0.5;
ix = -ix;
}
fprintf(f, " %2ld", ix);
} else
fprintf(f, " % .9E", x);
}
void WriteIncidence(FILE *f, rowrange m_size, colrange n_size, RayRecord *RR)
{
rowset cset;
long zcar;
set_initialize(&cset,m_size);
zcar = set_card(RR->ZeroSet);
switch (IncidenceOutput) {
case IncCardinality:
fprintf(f, " : %1ld", zcar);
break;
case IncSet:
if (m_size - zcar >= zcar) {
fprintf(f, " %1ld : ", zcar);
set_fwrite(f, RR->ZeroSet);
} else {
set_diff(cset, GroundSet, RR->ZeroSet);
fprintf(f, " %1ld : ", zcar - m_size);
set_fwrite(f, cset);
}
break;
case IncOff:
break;
}
set_free(cset);
}
void WriteHeading(void)
{
WriteProgramDescription(stdout);
printf("----------------------------------------------\n");
printf(" Enumeration of all vertices and extreme rays\n");
printf(" of a convex polyhedron P={ x : b - A x >= 0}\n");
printf(" Use hull option for convex hull computation!\n");
printf("----------------------------------------------\n");
}
void WriteProgramDescription(FILE *f)
{
fprintf(f, "* cdd: Double Description Method C-Code:%s\n", DDVERSION);
fprintf(f,"* %s\n",COPYRIGHT);
}
void WriteRunningMode(FILE *f)
{
if (Conversion==IneToExt || Conversion==ExtToIne || Conversion==Projection){
switch (HyperplaneOrder) {
case MinIndex:
fprintf(f, "*HyperplaneOrder: MinIndex\n");
break;
case MaxIndex:
fprintf(f, "*HyperplaneOrder: MaxIndex\n");
break;
case MinCutoff:
fprintf(f, "*HyperplaneOrder: MinCutoff\n");
break;
case MaxCutoff:
fprintf(f, "*HyperplaneOrder: MaxCutoff\n");
break;
case MixCutoff:
fprintf(f, "*HyperplaneOrder: MixCutoff\n");
break;
case LexMin:
fprintf(f, "*HyperplaneOrder: LexMin\n");
break;
case LexMax:
fprintf(f, "*HyperplaneOrder: LexMax\n");
break;
case RandomRow:
fprintf(f, "*HyperplaneOrder: Random, Seed = %d\n",rseed);
break;
case LineShelling:
fprintf(f, "*HyperplaneOrder: LineShelling\n");
break;
}
if (NondegAssumed) {
fprintf(f, "*Degeneracy preknowledge for computation: NondegenerateAssumed\n");
}
else {
fprintf(f, "*Degeneracy preknowledge for computation: None (possible degeneracy)\n");
}
}
switch (Conversion) {
case ExtToIne:
fprintf(f, "*Hull computation is chosen.\n");
break;
case IneToExt:
fprintf(f, "*Vertex/Ray enumeration is chosen.\n");
break;
case LPmax:
fprintf(f, "*LP (maximization) is chosen.\n");
break;
case LPmin:
fprintf(f, "*LP (minimization) is chosen.\n");
break;
case Projection:
fprintf(f, "*Preprojection is chosen.\n");
break;
default: break;
}
if (RestrictedEnumeration) {
fprintf(f, "*The equality option is chosen.\n* => Permanently active rows are:");
set_fwrite(f,EqualitySet);
fprintf(f,"\n");
}
if (RelaxedEnumeration) {
fprintf(f, "*The strict_inequality option is chosen.\n* => Permanently nonactive rows are:");
set_fwrite(f,NonequalitySet);
fprintf(f,"\n");
}
}
void WriteRunningMode2(FILE *f, rowrange m_size, colrange n_size)
{
long j;
if (Conversion==IneToExt || Conversion==ExtToIne){
switch (HyperplaneOrder) {
case MinIndex:
fprintf(f, "minindex\n");
break;
case MaxIndex:
fprintf(f, "maxindex\n");
break;
case MinCutoff:
fprintf(f, "mincutoff\n");
break;
case MaxCutoff:
fprintf(f, "maxcutoff\n");
break;
case MixCutoff:
fprintf(f, "mixcutoff\n");
break;
case LexMin:
fprintf(f, "lexmin\n");
break;
case LexMax:
fprintf(f, "lexmax\n");
break;
case RandomRow:
fprintf(f, "random %d\n",rseed);
break;
case LineShelling:
fprintf(f, "lineshelling\n");
break;
}
if (NondegAssumed) {
fprintf(f, "nondegenerate\n");
}
}
switch (Conversion) {
case ExtToIne:
fprintf(f, "hull\n");
break;
case LPmax:
fprintf(f, "maximize\n");
for (j=0; j<n_size; j++) WriteReal(f,LPcost[j]);
fprintf(f,"\n");
break;
case LPmin:
fprintf(f, "minimize\n");
for (j=0; j<n_size; j++) WriteReal(f,LPcost[j]);
fprintf(f,"\n");
break;
case Projection:
fprintf(f, "*Preprojection is chosen.\n");
break;
default: break;
}
if (RestrictedEnumeration) {
fprintf(f, "equality ");
set_fwrite(f,EqualitySet);
fprintf(f,"\n");
}
if (RelaxedEnumeration) {
fprintf(f, "strict_inequality ");
set_fwrite(f,NonequalitySet);
fprintf(f,"\n");
}
}
void WriteRunningMode0(FILE *f)
{
switch (Conversion) {
case ExtToIne:
fprintf(f, "V-representation\n");
break;
case IneToExt: case LPmax: case LPmin: case Projection:
fprintf(f, "H-representation\n");
break;
default: break;
}
}
void WriteCompletionStatus(FILE *f, rowrange m_size, colrange n_size, rowrange iter)
{
if (iter<m_size && CompStatus==AllFound) {
fprintf(f,"*Computation completed at Iteration %4ld.\n", iter);
}
if (CompStatus == RegionEmpty) {
fprintf(f,"*Computation completed at Iteration %4ld because the region found empty.\n", iter);
}
}
void WriteTimes(FILE *f)
{
long ptime,ptime_sec,ptime_minu, ptime_hour;
/* ptime=difftime(endtime,starttime); */ /* This function is ANSI standard, but not available sometime */
ptime=endtime-starttime; /* This is to replace the line above, but it may not give correct time in seconds */
ptime_hour=ptime/3600;
ptime_minu=(ptime-ptime_hour*3600)/60;
ptime_sec=ptime%60;
fprintf(f, "*Computation starts at %s", asctime(localtime(&starttime)));
fprintf(f, "* terminates at %s", asctime(localtime(&endtime)));
fprintf(f, "*Total processor time = %ld seconds\n", ptime);
fprintf(f, "* = %ld hour %ld min %ld sec\n", ptime_hour,ptime_minu,ptime_sec);
}
void WriteAdjacencyDegree(FILE *f, rowrange m_input, colrange n_input,
rowrange m_size, colrange n_size, Amatrix A, rowrange iter)
{
RayRecord *RayPtr1, *RayPtr2;
long pos1, pos2, deg, feasdeg, icd, feasicd;
double totaldeg=0.0, totalfeasdeg=0.0, totalfeasicd=0.0, averfeasicd, averdeg, averfeasdeg;
boolean adj;
switch (Conversion) {
case IneToExt:
fprintf(f,"*Adjacency Degree of output (=vertices/rays)\n");
fprintf(f,"*vertex/ray#, icd#, curr icd#, adj#, feas adj#\n");
break;
case ExtToIne:
fprintf(f,"*Adjacency Degree of output (=inequalities=facets)\n");
fprintf(f,"*facet#, icd#, curr icd#, adj#, feas adj#\n");
break;
default:
break;
}
fprintf(f, "*cdd input file : %s (%4ld x %4ld)\n",
inputfile, m_input, n_input);
fprintf(f, "*At iteration = %ld\n", iter);
fprintf(f,"begin\n");
fprintf(f," %ld\n",RayCount);
if (RayCount==0){
goto _L99;
}
LastRay->Next=NULL;
for (RayPtr1=FirstRay, pos1=1;RayPtr1 != NULL; RayPtr1 = RayPtr1->Next, pos1++){
for (RayPtr2=FirstRay, pos2=1,deg=0,feasdeg=0;RayPtr2 != NULL; RayPtr2 = RayPtr2->Next, pos2++){
if (RayPtr1!=RayPtr2){