1 /* RegularTriangulation.cpp -- Support for regular triangulations
2
3 Copyright 2006, 2007 Matthias Koeppe
4
5 This file is part of LattE.
6
7 LattE is free software; you can redistribute it and/or modify it
8 under the terms of the version 2 of the GNU General Public License
9 as published by the Free Software Foundation.
10
11 LattE is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with LattE; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */
20
21 #include <cassert>
22 #include <vector>
23 #include "latte_gmp.h"
24 #include "latte_random.h"
25 #include "RegularTriangulationWithCddlib.h"
26
27 using namespace std;
28
29 vector<listVector *>
ray_array(listCone * cone)30 ray_array(listCone *cone)
31 {
32 int num_rays = lengthListVector(cone->rays);
33 vector<listVector *> rays(num_rays);
34 int j;
35 listVector *ray;
36 for (j = 0, ray = cone->rays; ray!=NULL; j++, ray = ray->rest)
37 rays[j] = ray;
38 return rays;
39 }
40
41 typedef void
42 height_function_type(mpq_t height, const vec_ZZ &ray, void *data);
43
44 void
random_height(mpq_t height,const vec_ZZ & ray,void * data)45 random_height(mpq_t height, const vec_ZZ &ray, void *data)
46 {
47 int max_height = * (int *) data;
48 int h = uniform_random_number(1, max_height);
49 mpq_set_si(height, h, 1);
50 }
51
52 void
biased_random_height(mpq_t height,const vec_ZZ & ray,void * data)53 biased_random_height(mpq_t height, const vec_ZZ &ray, void *data)
54 {
55 int percentage = * (int *) data;
56 int x = uniform_random_number(0, 99);
57 mpq_set_si(height, (x < percentage) ? 2 : 1, 1);
58 }
59
60 void
delone_height(mpq_t height,const vec_ZZ & ray,void * data)61 delone_height(mpq_t height, const vec_ZZ &ray, void *data)
62 {
63 ZZ h;
64 int i;
65 for (i = 0; i<ray.length(); i++) {
66 h += ray[i] * ray[i];
67 }
68 mpq_class hq = convert_ZZ_to_mpq(h);
69 mpq_set(height, hq.get_mpq_t());
70 }
71
72 void
prescribed_height(mpq_t height,const vec_ZZ & ray_vector,void * data)73 prescribed_height(mpq_t height, const vec_ZZ &ray_vector, void *data)
74 {
75 prescribed_height_data *height_data = (prescribed_height_data *) data;
76 ZZ h;
77 h = 0;
78 listVector *ray;
79 int index;
80 #if 0
81 cerr << "ray_vector: " << ray_vector << endl;
82 #endif
83 for (ray = height_data->special_rays, index = 0; ray != NULL; ray = ray->rest, index++) {
84 #if 0
85 cerr << "special ray: " << ray->first << endl;
86 #endif
87 if (ray->first == ray_vector) {
88 h = (*height_data->special_heights)[index];
89 break;
90 }
91 }
92 mpq_class hq = convert_ZZ_to_mpq(h);
93 mpq_set(height, hq.get_mpq_t());
94 }
95