File: ramon.cpp

package info (click to toggle)
latte-int 1.7.6%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 38,260 kB
  • sloc: cpp: 32,231; sh: 4,413; makefile: 811; perl: 300
file content (163 lines) | stat: -rw-r--r-- 4,526 bytes parent folder | download
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
/* ramon.cpp -- Helper functions

   Copyright 2002-2004 Raymond Hemmecke
   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 <fstream>
#include "ramon.h"

/* ----------------------------------------------------------------- */
vec_ZZ createVector(int numOfVars) {
  vec_ZZ w;

  w.SetLength(numOfVars);
  return (w);
}
/* ----------------------------------------------------------------- */
vec_ZZ* createArrayVector(int numOfVectors) {
  vec_ZZ* w;

  w = new vec_ZZ[numOfVectors+1];
  if (w==0) {
    cerr << "Memory exhausted?" << endl;
    exit(1);
  }
  return (w);
}
/* ----------------------------------------------------------------- */
listVector* createListVector(vec_ZZ v) {
  return (appendVectorToListVector(v,0));
}
/* ----------------------------------------------------------------- */
 void removeListVector( listVector* p )
        {

            if( p->rest != NULL )
            {
                listVector *oldNode = p->rest;
                p->rest = p->rest->rest;  // Bypass deleted node
                delete oldNode;
            }
        }
/* ----------------------------------------------------------------- */
listVector* updateBasis(listVector *v, listVector *endBasis) {
  endBasis->rest = v;
  v->rest=0;
  endBasis = endBasis->rest;
  return (endBasis);
}
/* ----------------------------------------------------------------- */
int isVectorEqualToVector(vec_ZZ v, vec_ZZ w, int numOfVars) {
  int i;

//    if ((v==0) || (w==0)) return (0);
  for (i=0; i<numOfVars; i++) if (!(v[i]==w[i])) return (0);
  return (1);
}
/* NOTE: This function changes the LIST pointer. */ 
/* ----------------------------------------------------------------- */
int isVectorInListVector(vec_ZZ v, listVector* LIST, int numOfVars) {
  vec_ZZ w;

  while (LIST) {
    w = LIST->first;
    LIST = LIST->rest;
    if (isVectorEqualToVector(v,w,numOfVars)==1) return (1);
  }
  return (0);
}

/*
 * This function does NOT change the LIST pointer 
 */
int
isVectorInListVector(const vec_ZZ & v, listVector *list) {
   int numOfVars = v.length();
   listVector *tmp_list = list;

   while (tmp_list) {
      if (!isVectorEqualToVector(v, tmp_list->first, numOfVars)) {
         return (0);
      }
      tmp_list = tmp_list->rest;
   }
   return (1);
}

/* ----------------------------------------------------------------- */
listVector* readListVector(char *fileName, int* numOfVars) {
  int i,j,numOfVectors;
  listVector *basis, *endBasis;
  vec_ZZ b;

  /* Reads numOfVars, numOfVectors, list of vectors. */

  //setbuf(stdout,0);
  ifstream in(fileName);
  if(!in){
    cerr << "Cannot open input file in readListVector." << endl;
    exit(1);
  }

  in >> numOfVectors;
  in >> (*numOfVars);

  basis = createListVector(createVector(*numOfVars));
  endBasis = basis;

  for (i=0; i<numOfVectors; i++) {
    b=createVector(*numOfVars);
    for (j=0; j<(*numOfVars); j++) in >> b[j];
    endBasis->rest = createListVector(b);
    endBasis=endBasis->rest;
  }

/*  printf("List of vectors:\n");
  printf("================\n");
  printListVector(basis->rest,numOfVars); */

  return(basis->rest);
}
/* ----------------------------------------------------------------- */
/*
 * Testing whether or not two lists contain exactly the same
 * points. This is a debugging diagnostic function.
 */
int
isEqual(listVector *first, listVector *second) {
   int first_len = lengthListVector(first);
   int second_len = lengthListVector(second);
   listVector *tmp_list = first;
    
   if (first_len != second_len) {
      return (0);
   }
  
   /*
    * since the two lists have the same length, if every point in one list
    * is contained in the other list, the two lists must be equal.
    */ 
   while (tmp_list) {
      if (!isVectorInListVector(tmp_list->first, second)) {
         return (0);
      }
      tmp_list = tmp_list->rest;
   }
   return (1);
}