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
|
/* convert.cpp -- Data conversions
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 <cassert>
#include "convert.h"
#include "ramon.h"
listVector*
transformArrayBigVectorToListVector(const mat_ZZ &A, int numOfVectors,
int numOfVars)
{
int i;
listVector *L = NULL, **endL;
endL = &L;
for (i=0; i<numOfVectors; i++) {
*endL = createListVector(A[i]);
endL = &(*endL)->rest;
}
return L;
}
mat_ZZ
createConeDecMatrix(const listCone *cone, int numOfRays, int numOfVars)
{
int i;
mat_ZZ mat;
listVector *tmp;
mat.SetDims(numOfRays, numOfVars);
tmp=cone->rays;
for (i=0; i<numOfRays; i++) {
mat[i] = tmp->first;
tmp=tmp->rest;
}
//removeListVector(cone->rays);
return (mat);
}
mat_ZZ
createFacetMatrix(const listCone *cone, int numOfFacets, int numOfVars)
{
int i;
mat_ZZ mat;
listVector *tmp;
mat.SetDims(numOfFacets, numOfVars);
tmp=cone->facets;
for (i=0; i<numOfFacets; i++) {
ZZ multiplier, remainder;
DivRem(multiplier, remainder,
cone->determinant, cone->facet_divisors[i]);
assert(IsZero(remainder));
mat[i] = tmp->first * multiplier;
tmp=tmp->rest;
}
return (mat);
}
mat_ZZ
createFacetMatrix2(const listCone *cone, int numOfFacets, int numOfVars)
{
int i;
mat_ZZ mat;
listVector *tmp;
mat.SetDims(numOfFacets, numOfVars);
tmp=cone->facets;
for (i=0; i<numOfFacets; i++) {
ZZ multiplier, remainder;
DivRem(multiplier, remainder,
abs(cone->determinant), cone->facet_divisors[i]);
assert(IsZero(remainder));
mat[i] = tmp->first * multiplier;
tmp=tmp->rest;
}
return (mat);
}
/* latte to NTL conversions */
/* converts a latte listVector to a mat_ZZ */
mat_ZZ
convert_listVector_to_mat_ZZ(listVector *list) {
listVector *tmp_list = list;
int rows = tmp_list->first.length();
int cols = lengthListVector(tmp_list);
int cur_col = 0;
mat_ZZ m;
m.SetDims(cols, rows);
/* add columns as rows and then take the transpose */
while (tmp_list) {
m[cur_col] = tmp_list->first;
cur_col++;
tmp_list = tmp_list->rest;
}
return (transpose(m));
}
|