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
|
/* cone.cpp -- Linked list of cones
Copyright 2002-2004 Jesus A. De Loera, David Haws, Raymond
Hemmecke, Peter Huggins, Jeremy Tauzer, Ruriko Yoshida
Copyright 2006 Matthias Koeppe
This file is part of LattE.
LattE is free software; you can redistribute it and/or modify it
under the terms of the version 2 of the GNU General Public License
as published by the Free Software Foundation.
LattE is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with LattE; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdlib.h>
#include "ramon.h"
listCone::listCone(): vertex(NULL), rays(NULL), subspace_generators(NULL),
facets(NULL), equalities(NULL), latticePoints(NULL), rest(NULL)
{
}
/* ----------------------------------------------------------------- */
int lengthListVector(const listVector* LIST) {
int len=0;
while (LIST) {len++; LIST = LIST->rest;}
return (len);
}
/* ----------------------------------------------------------------- */
listVector* appendVectorToListVector(const vec_ZZ &v, listVector *REST) {
// listVector *LIST;
listVector * LIST = new listVector(v);
LIST->rest = REST;
return (LIST);
}
/* ----------------------------------------------------------------- */
listVector *copyListVector(listVector *l)
{
listVector *result = NULL;
listVector **rest_p = &result;
while (l != NULL) {
*rest_p = new listVector(l->first, 0, l->index_hint);
rest_p = &(*rest_p)->rest;
l = l->rest;
}
return result;
}
/* ----------------------------------------------------------------- */
void freeListVector( listVector* p )
{
while (p != NULL) {
listVector *rest = p->rest;
delete p;
p = rest;
}
}
/* ----------------------------------------------------------------- */
listCone* createListCone() {
listCone* z;
z = new listCone;
if (z==0) {
cerr << "Memory exhausted" << endl;
exit(1);
}
z->coefficient=1;
z->vertex=0;
z->rays=0;
z->facets=0;
z->determinant = 0;
z->dual_determinant = 0;
z->latticePoints=0;
z->subspace_generators = 0;
z->equalities = 0;
z->rest=0;
z->index_hint = -1;
return (z);
}
/* ----------------------------------------------------------------- */
int lengthListCone(listCone* LIST) {
int len=0;
while (LIST) {len++; LIST = LIST->rest;}
return (len);
}
/* ----------------------------------------------------------------- */
void freeCone(listCone *cone)
{
delete cone->vertex;
freeListVector(cone->rays);
freeListVector(cone->facets);
freeListVector(cone->latticePoints);
freeListVector(cone->subspace_generators);
freeListVector(cone->equalities);
delete cone;
}
void freeListCone(listCone *list)
{
while (list != NULL) {
listCone *rest = list->rest;
freeCone(list);
list = rest;
}
}
listCone *appendListCones(listCone *A, listCone *B)
{
if (A == NULL) return B;
else {
listCone *C;
for (C = A; C->rest!=NULL; C = C->rest);
C->rest = B;
return A;
}
}
listCone *copyCone(const listCone *cone)
{
listCone *copy = createListCone();
copy->coefficient = cone->coefficient;
copy->vertex = new Vertex(*cone->vertex);
copy->determinant = cone->determinant;
copy->rays = copyListVector(cone->rays);
copy->dual_determinant = cone->dual_determinant;
copy->facets = copyListVector(cone->facets);
copy->facet_divisors = cone->facet_divisors;
copy->latticePoints = copyListVector(cone->latticePoints);
copy->lattice_points_scalar_products = cone->lattice_points_scalar_products;
copy->subspace_generators = copyListVector(cone->subspace_generators);
copy->equalities = copyListVector(cone->equalities);
copy->rest = NULL;
copy->index_hint = cone->index_hint;
return copy;
}
//Copy a list of cones.
listCone *copyListCone(const listCone *cone)
{
if ( !cone)
return NULL;
listCone *copyList = copyCone(cone); //copy one cone.
copyList->rest = copyListCone(cone->rest); //copy the rest.
return copyList;
}
int ambient_cone_dimension(const listCone *cone)
{
if (cone == NULL) return 0;
return cone->vertex->vertex->numerators().length();
}
|