add isl_multi_aff_to_polylib
[barvinok.git] / zsolve / varproperties.c
blob36a36d6cb842365e430339595dd89e75eb614e6a
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 "varproperties.h"
25 #include <assert.h>
26 #include <stdlib.h>
28 // //
30 VariableProperties createVariableProperties(int size)
32 VariableProperties var;
33 int i;
35 assert(size>0);
37 var = (VariableProperties)malloc(size*sizeof(variableproperty_t));
39 if (var==NULL)
41 fprintf(stderr, "Fatal Error (%s/%d): Could not allocate memory for VariableProperties!\n", __FILE__, __LINE__);
42 exit(1);
45 for (i=0; i<size; i++)
47 var[i].Free = true;
48 var[i].Upper = MAXINT;
49 var[i].Lower = -MAXINT;
50 var[i].Column = i;
53 return var;
56 // //
58 void deleteVariableProperties(VariableProperties var)
60 if (var)
61 free(var);
64 // //
66 bool checkVariableSymmetry(VariableProperties var, int id)
68 assert(var);
69 assert(id>=0);
71 return var[id].Lower+var[id].Upper==0;
74 // //
76 bool checkVariableFree(VariableProperties var, int id)
78 assert(var);
79 assert(id>=0);
81 return var[id].Free;
84 // //
86 bool checkVariableBounds(VariableProperties var, int id, int num)
88 assert(var);
89 assert(id>=0);
91 return var[id].Lower<=num && num<=var[id].Upper;
94 // //
96 void swapVariableProperties(VariableProperties var, int a, int b)
98 variableproperty_t v;
100 assert(a>=0);
101 assert(b>=0);
103 v = var[a];
104 var[a] = var[b];
105 var[b] = v;
108 // //
110 void fprintVariableProperties(FILE *stream, VariableProperties var, int size)
112 int i;
114 for (i=0; i<size; i++)
115 fprintf(stream, "%d %d %d %d\n", var[i].Column, var[i].Lower, var[i].Upper, var[i].Free);
118 // //
120 void readVariableProperties(FILE *stream, VariableProperties var, int size)
122 int i;
124 assert(stream);
125 assert(var);
127 for (i=0; i<size; i++)
128 fscanf(stream, "%d %d %d %d", &(var[i].Column), &(var[i].Lower), &(var[i].Upper), &(var[i].Free));
131 // //