update pet for rename of pet_scop_collect_* to pet_scop_get_*
[barvinok/uuh.git] / zsolve / solve.c
blob972b630938cf7b52451d6bdf5dc90f3acea0a61e
1 /*
2 4ti2 -- A software package for algebraic, geometric and combinatorial
3 problems on linear spaces.
5 Copyright (C) 2006 4ti2 team.
6 Main author(s): Matthias Walter.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <assert.h>
29 #include "banner.h"
30 #include "opts.h"
31 #include "libzsolve.h"
33 int OVerbose;
34 int OLogging;
35 int OBackup;
36 bool OForce;
37 bool ORightHandSide;
38 bool OResume;
39 bool OHilbert;
40 bool OGraver;
42 int BaseLength;
43 char *BaseName;
45 FILE *LogFile;
47 int readTokenFromFile(FILE *stream, char *tokenchars, char **ptoken, int *pmemory)
49 int c;
50 int len = 0;
52 assert(ptoken);
53 assert(pmemory);
55 if (*ptoken==NULL)
57 *ptoken = (char *)calloc(8, sizeof(char));
58 *pmemory = 1;
60 else
61 (*ptoken)[0] = '\0';
63 while ((c = fgetc(stream))!=EOF)
65 if (strchr(tokenchars, c))
67 if (len+1 >= *pmemory)
69 *pmemory *= 2;
70 *ptoken = (char *)realloc(*ptoken, *pmemory*sizeof(char));
72 (*ptoken)[len++] = c;
73 (*ptoken)[len] = '\0';
75 else if (len>0)
76 return len;
79 return len;
82 void backupEvent(ZSolveContext ctx)
84 FILE *stream;
86 strcat(BaseName, ".backup");
87 stream = fopen(BaseName, "w");
88 BaseName[BaseLength] = '\0';
90 backupZSolveContext(stream, ctx);
92 fclose(stream);
95 // //
97 int main(int argc, char *argv[])
99 FILE *stream = NULL;
100 int i, j, r, count;
101 bool flag;
103 Matrix matrix = NULL;
104 Vector rhs = NULL;
105 VectorArray Lattice = NULL;
106 Vector vector = NULL;
108 LinearSystem initialsystem;
109 ZSolveContext ctx;
111 char *token;
112 int memory;
114 getopts(argc, argv);
116 puts(FORTY_TWO_BANNER);
118 if (OResume)
120 // START OF RESUME SECTION - READ FILES AND CREATE CONTEXT
122 strcat(BaseName, ".backup");
123 stream = fopen(BaseName, "r");
124 BaseName[BaseLength] = '\0';
126 if (stream==NULL)
128 printf("Unable to open backup file %s.backup\n", BaseName);
129 free(BaseName);
130 exit(1);
133 // options
134 if (fscanf(stream, "%d %d %d", &OVerbose, &OLogging, &OBackup)!=3 || OVerbose<0 || OVerbose>3 || OLogging<0 || OLogging>3 || OBackup<0)
136 fclose(stream);
137 printf("Backup file %s.backup does not contain valid data.\n", BaseName);
138 free(BaseName);
139 exit(2);
142 // get context
143 ctx = createZSolveContextFromBackup(stream, zsolveLogCallbackDefault, backupEvent);
144 fclose(stream);
146 // logfile
147 if (OLogging>0)
149 strcat(BaseName, ".log");
150 stream = fopen(BaseName, "a");
151 BaseName[BaseLength] = '\0';
152 if (stream==NULL)
154 printf("Unable to open log file %s.log\n", BaseName);
155 free(BaseName);
156 exit(1);
158 ctx->LogFile = LogFile = stream;
161 // END OF RESUME SECTION
163 else
165 // logfile
166 if (OLogging>0)
168 strcat(BaseName, ".log");
169 stream = fopen(BaseName, "w");
170 BaseName[BaseLength] = '\0';
171 if (stream==NULL)
173 printf("Unable to open log file %s.log\n", BaseName);
174 free(BaseName);
175 exit(1);
177 LogFile = stream;
179 // check for existance of solution files
180 if (!OForce)
182 strcat(BaseName, ".zhom");
183 stream = fopen(BaseName, "r");
184 BaseName[BaseLength] = '\0';
185 if (stream!=NULL)
187 fclose(stream);
188 if (OVerbose>0)
189 printf("%s.hom already exists! Use -f to force calculation.\n", BaseName);
190 if (OLogging>0)
192 fprintf(LogFile, "%s.hom already exists! Use -f to force calculation.\n", BaseName);
193 fclose(LogFile);
195 free(BaseName);
196 exit(1);
198 strcat(BaseName, ".zinhom");
199 stream = fopen(BaseName, "r");
200 BaseName[BaseLength] = '\0';
201 if (stream!=NULL)
203 fclose(stream);
204 if (OVerbose>0)
205 printf("%s.inhom already exists! Use -f to force calculation.\n", BaseName);
206 if (LogFile)
208 fprintf(LogFile, "%s.inhom already exists! Use -f to force calculation.\n", BaseName);
209 fclose(LogFile);
211 free(BaseName);
212 exit(1);
216 // matrix
217 strcat(BaseName, ".mat");
218 stream = fopen(BaseName, "r");
219 BaseName[BaseLength] = '\0';
221 if (stream == NULL)
223 stream = fopen(BaseName, "r");
224 if (stream) {
225 if (OVerbose>0)
226 printf("Matrix file %s.mat not found, falling back to project file %s.\n\n", BaseName, BaseName);
227 if (OLogging>0)
229 fprintf(LogFile, "Matrix file %s.mat not found, falling back to project file %s.\n\n", BaseName, BaseName);
230 fclose(LogFile);
235 if (stream==NULL)
237 strcat(BaseName, ".lat");
238 stream = fopen(BaseName, "r");
239 BaseName[BaseLength] = '\0';
240 if (stream==NULL)
242 // lattice
243 if (OVerbose>0)
244 printf("Neither matrix file %s.mat nor lattice file %s.lat exists!\n", BaseName, BaseName);
245 if (OLogging>0)
247 fprintf(LogFile, "Neither matrix file %s.mat nor lattice file %s.lat exists!\n", BaseName, BaseName);
248 fclose(LogFile);
250 free(BaseName);
251 exit(1);
253 else
255 // START OF LATTICE SECTION - READ FILES AND CREATE CONTEXT
257 Lattice = readVectorArray(stream, false);
258 fclose(stream);
259 if (Lattice == NULL)
261 if (OVerbose>0)
262 printf("Lattice file %s.lat does not contain valid data.\n", BaseName);
263 if (OLogging>0)
265 fprintf(LogFile, "Lattice file %s.lat does not contain valid data.\n", BaseName);
266 fclose(LogFile);
268 free(BaseName);
269 exit(1);
272 // rhs
273 if (ORightHandSide)
275 strcat(BaseName, ".rhs");
276 stream = fopen(BaseName, "r");
277 BaseName[BaseLength] = '\0';
278 if (stream!=NULL)
280 fscanf(stream, "%d", &i);
281 if (i!=1)
283 fclose(stream);
284 printf("Height of RHS must be 1!\n");
285 if (LogFile)
287 fprintf(LogFile, "Height of RHS must be 1!\n");
288 fclose(LogFile);
290 deleteMatrix(matrix);
291 free(BaseName);
292 exit(1);
294 fscanf(stream, "%d", &i);
295 while (i--)
297 if (fscanf(stream, "%d", &j) || j!=0)
299 printf("When reading from %s.lat, RHS file %s.rhs must contain a zero vector.\n", BaseName, BaseName);
300 if (LogFile)
302 fprintf(LogFile, "When reading from %s.lat, RHS file %s.rhs must contain a zero vector.\n", BaseName, BaseName);
303 fclose(LogFile);
305 deleteMatrix(matrix);
306 free(BaseName);
307 exit(1);
313 // variable properties
315 for (i=0; i<Lattice->Variables; i++)
317 Lattice->Properties[i].Column = i;
318 Lattice->Properties[i].Lower = OHilbert ? 0 : -MAXINT;
319 Lattice->Properties[i].Upper = MAXINT;
320 Lattice->Properties[i].Free = (!OGraver && !OHilbert);
323 // read .rel
324 strcat(BaseName, ".rel");
325 stream = fopen(BaseName, "r");
326 BaseName[BaseLength] = '\0';
327 if (stream!=NULL)
329 token = NULL;
330 memory = 0;
331 flag = false;
333 if (fscanf(stream, "%d %d", &r, &j)<2 || r != 1)
335 printf("RELATION file %s.rel must start with the dimensions.\n", BaseName);
336 flag = true;
339 for (i=0; i<j; i++)
341 if (readTokenFromFile(stream, "0123456789=<>", &token, &memory) == 0)
343 printf("RELATION file %s.rel ends unexpectedly.\n", BaseName);
344 flag = true;
346 else if (!strcmp(token, "<") || !strcmp(token, ">"))
348 printf("When reading from %s.lat, inequalities are not allowed.\n", BaseName);
349 flag = true;
351 else if (strcmp(token, "="))
353 printf("Unknown token '%s' in RELATION file %s.rel.\n", token, BaseName);
354 flag = true;
357 free(token);
358 fclose(stream);
360 if (flag)
362 free(BaseName);
363 exit(1);
367 // read .sign
368 strcat(BaseName, ".sign");
369 stream = fopen(BaseName, "r");
370 BaseName[BaseLength] = '\0';
371 if (stream!=NULL)
373 token = NULL;
374 memory = 0;
375 flag = false;
377 if (fscanf(stream, "%d %d", &r, &i)<2 || i != Lattice->Variables || r != 1)
379 printf("SIGN file %s.sign must start with '1 %d'.\n", BaseName, Lattice->Variables);
380 flag = true;
383 for (i=0; i<Lattice->Variables; i++)
385 if (readTokenFromFile(stream, "0123456789-abcdefghijklmnopqrstuvwxyz", &token, &memory) == 0)
387 printf("SIGN file %s.sign ends unexpectedly.\n", BaseName);
388 flag = true;
390 if (!strcmp(token, "0") || !strcmp(token, "free") || !strcmp(token, "f"))
392 Lattice->Properties[i].Upper = MAXINT;
393 Lattice->Properties[i].Lower = -MAXINT;
394 Lattice->Properties[i].Free = true;
396 else if (!strcmp(token, "1") || !strcmp(token, "hil") || !strcmp(token, "h"))
398 Lattice->Properties[i].Upper = MAXINT;
399 Lattice->Properties[i].Lower = 0;
400 Lattice->Properties[i].Free = false;
402 else if (!strcmp(token, "-1") || !strcmp(token, "-hil") || !strcmp(token, "-h"))
404 Lattice->Properties[i].Upper = 0;
405 Lattice->Properties[i].Lower = -MAXINT;
406 Lattice->Properties[i].Free = false;
408 else if (!strcmp(token, "2") || !strcmp(token, "graver") || !strcmp(token, "g"))
410 if (OHilbert)
412 printf("Input Error: Graver components for `hilbert' executable.\nInput Error: Use the `graver' executable instead.\n");
413 flag = true;
415 else
417 Lattice->Properties[i].Upper = MAXINT;
418 Lattice->Properties[i].Lower = -MAXINT;
419 Lattice->Properties[i].Free = false;
422 else
424 printf("Unknown token '%s' in SIGN file %s.sign.\n", token, BaseName);
425 flag = true;
428 free(token);
429 fclose(stream);
431 if (flag)
433 deleteVectorArray(Lattice);
434 free(BaseName);
435 exit(1);
439 // read .ub
440 strcat(BaseName, ".ub");
441 stream = fopen(BaseName, "r");
442 BaseName[BaseLength] = '\0';
443 if (stream!=NULL)
445 token = NULL;
446 memory = 0;
447 flag = false;
449 if (fscanf(stream, "%d %d", &r, &i)<2 || i != Lattice->Variables || r != 1)
451 printf("UPPER BOUNDS file %s.ub must start with '1 %d'.\n", BaseName, Lattice->Variables);
452 flag = true;
455 for (i=0; i<Lattice->Variables; i++)
457 if (readTokenFromFile(stream, "0123456789*-", &token, &memory) == 0)
459 printf("UPPER BOUNDS file %s.ub ends unexpectedly.\n", BaseName);
460 flag = true;
462 if (!strcmp(token, "*"))
463 Lattice->Properties[i].Upper = MAXINT;
464 else if (sscanf(token, "%d", &j) == 1)
466 if (Lattice->Properties[i].Free)
468 printf("Upper bound '%s' cannot be set for free variables.\n", token);
469 flag = true;
471 else if (j>=0)
472 Lattice->Properties[i].Upper = j;
473 else
475 printf("Negative upper bound '%s' in UPPER BOUNDS file %s.ub.\n", token, BaseName);
476 flag = true;
479 else
481 printf("Unknown token '%s' in UPPER BOUNDS file %s.ub.\n", token, BaseName);
482 flag = true;
485 free(token);
486 fclose(stream);
488 if (flag)
490 deleteVectorArray(Lattice);
491 free(BaseName);
492 exit(1);
496 // read .lb
497 strcat(BaseName, ".lb");
498 stream = fopen(BaseName, "r");
499 BaseName[BaseLength] = '\0';
500 if (stream!=NULL)
502 token = NULL;
503 memory = 0;
504 flag = false;
506 if (fscanf(stream, "%d %d", &r, &i)<2 || i != Lattice->Variables || r != 1)
508 printf("LOWER BOUNDS file %s.lb must start with '1 %d'.\n", BaseName, Lattice->Variables);
509 flag = true;
512 for (i=0; i<Lattice->Variables; i++)
514 if (readTokenFromFile(stream, "0123456789*-", &token, &memory) == 0)
516 printf("LOWER BOUNDS file %s.lb ends unexpectedly.\n", BaseName);
517 flag = true;
519 if (!strcmp(token, "*"))
520 Lattice->Properties[i].Lower = -MAXINT;
521 else if (sscanf(token, "%d", &j) == 1)
523 if (Lattice->Properties[i].Free)
525 printf("Lower bound '%s' cannot be set for free variables.\n", token);
526 flag = true;
528 else if (j<=0)
529 Lattice->Properties[i].Lower = j;
530 else
532 printf("Positive lower bound '%s' in LOWER BOUNDS file %s.lb.\n", token, BaseName);
533 flag = true;
536 else
538 printf("Unknown token '%s' in LOWER BOUNDS file %s.lb.\n", token, BaseName);
539 flag = true;
542 free(token);
543 fclose(stream);
545 if (flag)
547 deleteVectorArray(Lattice);
548 free(BaseName);
549 exit(1);
553 ctx = createZSolveContextFromLattice(Lattice, LogFile, OLogging, OVerbose, zsolveLogCallbackDefault, backupEvent);
555 // print lattice
556 if (ctx->Verbosity>0)
558 printf("\nLattice to use:\n\n");
559 printVectorArray(ctx->Lattice, false);
560 printf("\n\n");
562 if (ctx->LogLevel>0)
564 fprintf(ctx->LogFile, "\nLattice to use:\n\n");
565 fprintVectorArray(ctx->LogFile, ctx->Lattice, false);
566 fprintf(ctx->LogFile, "\n\n");
569 // END OF LATTICE SECTION
572 else
574 // START OF SYSTEM SECTION - READ FILES AND CREATE CONTEXT
576 matrix = readMatrix(stream);
577 fclose(stream);
578 if (matrix==NULL)
580 printf("Matrix file %s does not contain valid data.\n", BaseName);
581 if (LogFile)
583 fprintf(LogFile, "Matrix file %s does not contain valid data.\n", BaseName);
584 fclose(LogFile);
586 free(BaseName);
587 exit(1);
590 // rhs
591 if (ORightHandSide)
593 strcat(BaseName, ".rhs");
594 stream = fopen(BaseName, "r");
595 BaseName[BaseLength] = '\0';
596 if (stream!=NULL)
598 if (OGraver || OHilbert)
600 fclose(stream);
601 printf("Input Error: No rhs file is allowed with --graver and --hilbert!\n");
602 printf("Input Error: Please delete %s.rhs and rerun zsolve\n", BaseName);
603 if (LogFile)
605 fprintf(LogFile, "Input Error: No rhs file is allowed with --graver and --hilbert!\n");
606 fprintf(LogFile, "Input Error: Please delete %s.rhs and rerun zsolve\n", BaseName);
607 fclose(LogFile);
609 deleteMatrix(matrix);
610 free(BaseName);
611 exit(1);
614 fscanf(stream, "%d", &i);
615 if (i!=1)
617 fclose(stream);
618 printf("Height of RHS must be 1!\n");
619 if (LogFile)
621 fprintf(LogFile, "Height of RHS must be 1!\n");
622 fclose(LogFile);
624 deleteMatrix(matrix);
625 free(BaseName);
626 exit(1);
628 fscanf(stream, "%d", &i);
629 if (i!=matrix->Height)
631 fclose(stream);
632 printf("Matrix height conflicts with width of rhs!\n");
633 if (LogFile)
635 fprintf(LogFile, "Matrix height conflicts with width of rhs!\n");
636 fclose(LogFile);
638 deleteMatrix(matrix);
639 free(BaseName);
640 exit(1);
642 rhs = readVector(stream, matrix->Height);
643 fclose(stream);
644 if (rhs==NULL)
646 printf("RHS file %s.rhs does not contain valid data.\n", BaseName);
647 if (LogFile)
649 fprintf(LogFile, "RHS file %s.rhs does not contain valid data.\n", BaseName);
650 fclose(LogFile);
652 deleteMatrix(matrix);
653 free(BaseName);
654 exit(1);
659 // fill with zeros
660 if (rhs==NULL)
662 rhs = createVector(matrix->Height);
663 for (i=0; i<matrix->Height; i++)
664 rhs[i] = 0;
667 // create system
668 initialsystem = createLinearSystem();
670 setLinearSystemMatrix(initialsystem, matrix);
671 deleteMatrix(matrix);
673 setLinearSystemRHS(initialsystem, rhs);
674 deleteVector(rhs);
676 // default limits
678 if (OGraver)
679 setLinearSystemLimit(initialsystem, -1, -MAXINT, MAXINT, false);
680 else if (OHilbert)
681 setLinearSystemLimit(initialsystem, -1, 0, MAXINT, false);
682 else
683 setLinearSystemLimit(initialsystem, -1, -MAXINT, MAXINT, true);
685 // default equation type
687 setLinearSystemEquationType(initialsystem, -1, EQUATION_EQUAL, 0);
689 // read .rel
690 strcat(BaseName, ".rel");
691 stream = fopen(BaseName, "r");
692 BaseName[BaseLength] = '\0';
693 if (stream!=NULL)
695 token = NULL;
696 memory = 0;
697 flag = false;
699 if (fscanf(stream, "%d %d", &r, &i)<2 || i != initialsystem->Equations || r != 1)
701 printf("RELATION file %s.rel must start with '1 %d'.\n", BaseName, initialsystem->Equations);
702 flag = true;
705 for (i=0; i<initialsystem->Equations; i++)
707 if (readTokenFromFile(stream, "0123456789=<>", &token, &memory) == 0)
709 printf("RELATION file %s.rel ends unexpectedly.\n", BaseName);
710 flag = true;
712 if (!strcmp(token, "="))
713 setLinearSystemEquationType(initialsystem, i, EQUATION_EQUAL, 0);
714 // BUG: Not a real bug, but maybe misdefinition?? <= is not so hard to type :-)
715 else if (!strcmp(token, "<"))
716 setLinearSystemEquationType(initialsystem, i, EQUATION_LESSEREQUAL, 0);
717 else if (!strcmp(token, ">"))
718 setLinearSystemEquationType(initialsystem, i, EQUATION_GREATEREQUAL, 0);
719 else
721 printf("Unknown token '%s' in RELATION file %s.rel.\n", token, BaseName);
722 flag = true;
725 free(token);
726 fclose(stream);
728 if (flag)
730 deleteLinearSystem(initialsystem);
731 free(BaseName);
732 exit(1);
736 // read .sign
737 strcat(BaseName, ".sign");
738 stream = fopen(BaseName, "r");
739 BaseName[BaseLength] = '\0';
740 if (stream!=NULL)
742 token = NULL;
743 memory = 0;
744 flag = false;
746 if (fscanf(stream, "%d %d", &r, &i)<2 || i != initialsystem->Variables || r != 1)
748 printf("SIGN file %s.sign must start with '1 %d'.\n", BaseName, initialsystem->Variables);
749 flag = true;
752 for (i=0; i<initialsystem->Variables; i++)
754 if (readTokenFromFile(stream, "0123456789-abcdefghijklmnopqrstuvwxyz", &token, &memory) == 0)
756 printf("SIGN file %s.sign ends unexpectedly.\n", BaseName);
757 flag = true;
759 if (!strcmp(token, "0") || !strcmp(token, "free") || !strcmp(token, "f"))
760 setLinearSystemLimit(initialsystem, i, -MAXINT, MAXINT, true);
761 else if (!strcmp(token, "1") || !strcmp(token, "hil") || !strcmp(token, "h"))
762 setLinearSystemLimit(initialsystem, i, 0, MAXINT, false);
763 else if (!strcmp(token, "-1") || !strcmp(token, "-hil") || !strcmp(token, "-h"))
764 setLinearSystemLimit(initialsystem, i, -MAXINT, 0, false);
765 else if (!strcmp(token, "2") || !strcmp(token, "graver") || !strcmp(token, "g"))
767 if (OHilbert)
769 if (!flag)
770 printf("Input Error: Graver components for `hilbert' executable.\nInput Error: Use the `graver' executable instead.\n");
771 flag = true;
773 else
774 setLinearSystemLimit(initialsystem, i, -MAXINT, MAXINT, false);
776 else
778 printf("Unknown token '%s' in SIGN file %s.sign.\n", token, BaseName);
779 flag = true;
782 free(token);
783 fclose(stream);
785 if (flag)
787 deleteLinearSystem(initialsystem);
788 free(BaseName);
789 exit(1);
793 // read .ub
794 strcat(BaseName, ".ub");
795 stream = fopen(BaseName, "r");
796 BaseName[BaseLength] = '\0';
797 if (stream!=NULL)
799 token = NULL;
800 memory = 0;
801 flag = false;
803 if (fscanf(stream, "%d %d", &r, &i)<2 || i != initialsystem->Variables || r != 1)
805 printf("UPPER BOUNDS file %s.ub must start with '1 %d'.\n", BaseName, initialsystem->Variables);
806 flag = true;
809 for (i=0; i<initialsystem->Variables; i++)
811 if (readTokenFromFile(stream, "0123456789*-", &token, &memory) == 0)
813 printf("UPPER BOUNDS file %s.ub ends unexpectedly.\n", BaseName);
814 flag = true;
816 if (!strcmp(token, "*"))
817 setLinearSystemBound(initialsystem, i, 'u', MAXINT);
818 else if (sscanf(token, "%d", &j) == 1)
820 if (initialsystem->VarProperties[i].Free)
822 printf("Upper bound '%s' cannot be set for free variables.\n", token);
823 flag = true;
825 else if (j>=0)
826 setLinearSystemBound(initialsystem, i, 'u', j);
827 else
829 printf("Negative upper bound '%s' in UPPER BOUNDS file %s.ub.\n", token, BaseName);
830 flag = true;
833 else
835 printf("Unknown token '%s' in UPPER BOUNDS file %s.ub.\n", token, BaseName);
836 flag = true;
839 free(token);
840 fclose(stream);
842 if (flag)
844 deleteLinearSystem(initialsystem);
845 free(BaseName);
846 exit(1);
850 // read .lb
851 strcat(BaseName, ".lb");
852 stream = fopen(BaseName, "r");
853 BaseName[BaseLength] = '\0';
854 if (stream!=NULL)
856 token = NULL;
857 memory = 0;
858 flag = false;
860 if (fscanf(stream, "%d %d", &r, &i)<2 || i != initialsystem->Variables || r != 1)
862 printf("LOWER BOUNDS file %s.lb must start with '1 %d'.\n", BaseName, initialsystem->Variables);
863 flag = true;
866 for (i=0; i<initialsystem->Variables; i++)
868 if (readTokenFromFile(stream, "0123456789*-", &token, &memory) == 0)
870 printf("LOWER BOUNDS file %s.lb ends unexpectedly.\n", BaseName);
871 flag = true;
873 if (!strcmp(token, "*"))
874 setLinearSystemBound(initialsystem, i, 'l', -MAXINT);
875 else if (sscanf(token, "%d", &j) == 1)
877 if (initialsystem->VarProperties[i].Free)
879 printf("Lower bound '%s' cannot be set for free variables.\n", token);
880 flag = true;
882 else if (j<=0)
883 setLinearSystemBound(initialsystem, i, 'l', j);
884 else
886 printf("Positive lower bound '%s' in LOWER BOUNDS file %s.lb.\n", token, BaseName);
887 flag = true;
890 else
892 printf("Unknown token '%s' in LOWER BOUNDS file %s.lb.\n", token, BaseName);
893 flag = true;
896 free(token);
897 fclose(stream);
899 if (flag)
901 deleteLinearSystem(initialsystem);
902 free(BaseName);
903 exit(1);
907 ctx = createZSolveContextFromSystem(initialsystem, LogFile, OLogging, OVerbose, zsolveLogCallbackDefault, backupEvent);
909 // END OF SYSTEM SECTION
913 // DEBUG
914 // printVectorArray(ctx->Lattice, true);
916 zsolveSystem(ctx, !OResume);
918 if (OGraver)
920 printf("Writing %d vectors to graver file, with respect to symmetry.\n", ctx->Graver->Size);
921 if (LogFile)
922 fprintf(LogFile, "Writing %d vectors to graver file, with respect to symmetry.\n", ctx->Graver->Size);
924 strcat(BaseName, ".gra");
925 stream = fopen(BaseName, "w");
926 BaseName[BaseLength] = '\0';
927 if (stream)
929 fprintf(stream, "%d %d\n\n", ctx->Graver->Size, ctx->Graver->Variables);
930 fprintVectorArray(stream, ctx->Graver, false);
931 fclose(stream);
934 else if (OHilbert)
936 strcat(BaseName, ".hil");
937 stream = fopen(BaseName, "w");
938 BaseName[BaseLength] = '\0';
939 if (stream)
941 fprintf(stream, "%d %d\n\n", ctx->Homs->Size + ctx->Frees->Size, ctx->Homs->Variables);
942 fprintVectorArray(stream, ctx->Homs, false);
943 fprintf(stream, "\n");
944 fprintVectorArray(stream, ctx->Frees, false);
945 fclose(stream);
948 else
950 strcat(BaseName, ".zinhom");
951 stream = fopen(BaseName, "w");
952 BaseName[BaseLength] = '\0';
953 if (stream)
955 fprintf(stream, "%d %d\n\n", ctx->Inhoms->Size, ctx->Inhoms->Variables);
956 fprintVectorArray(stream, ctx->Inhoms, false);
957 fclose(stream);
960 strcat(BaseName, ".zhom");
961 stream = fopen(BaseName, "w");
962 BaseName[BaseLength] = '\0';
963 if (stream)
965 fprintf(stream, "%d %d\n\n", ctx->Homs->Size, ctx->Homs->Variables);
966 fprintVectorArray(stream, ctx->Homs, false);
967 fclose(stream);
970 if (ctx->Frees->Size>0)
972 strcat(BaseName, ".zfree");
973 stream = fopen(BaseName, "w");
974 BaseName[BaseLength] = '\0';
975 if (stream)
977 fprintf(stream, "%d %d\n\n", ctx->Frees->Size, ctx->Frees->Variables);
978 fprintVectorArray(stream, ctx->Frees, false);
979 fclose(stream);
985 printf("\n4ti2 Total Time: ");
986 printCPUTime(maxd(getCPUTime() - ctx->AllTime, 0.0));
987 printf("\n");
988 if (LogFile) {
989 fprintf(LogFile, "\n4ti2 Total Time: ");
990 fprintCPUTime(LogFile, maxd(getCPUTime() - ctx->AllTime, 0.0));
991 fprintf(LogFile, "\n");
994 deleteZSolveContext(ctx, true);
996 if (BaseName!=NULL)
997 free(BaseName);
999 if (LogFile)
1000 fclose(LogFile);
1002 return EXIT_SUCCESS;
1005 // //