~fluidity-core/fluidity/refactor-netcdf

« back to all changes in this revision

Viewing changes to spatialindex-1.5/regressiontest/rtree/Generator.cc

  • Committer: Jon Hill
  • Date: 2013-02-16 09:01:40 UTC
  • mfrom: (3981.7.159 fluidity)
  • Revision ID: jon.hill@imperial.ac.uk-20130216090140-bplzxqzdk1eik4za
Megre from trunk, fixing several conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Spatial Index Library
2
 
//
3
 
// Copyright (C) 2002 Navel Ltd.
4
 
//
5
 
// This library is free software; you can redistribute it and/or
6
 
// modify it under the terms of the GNU Lesser General Public
7
 
// License as published by the Free Software Foundation; either
8
 
// version 2.1 of the License, or (at your option) any later version.
9
 
//
10
 
// This library is distributed in the hope that it will be useful,
11
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
// Lesser General Public License for more details.
14
 
//
15
 
// You should have received a copy of the GNU Lesser General Public
16
 
// License along with this library; if not, write to the Free Software
17
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
//
19
 
//  Email:
20
 
//    mhadji@gmail.com
21
 
 
22
 
#include <tools/Tools.h>
23
 
#include <cmath>
24
 
#include <limits>
25
 
 
26
 
#include <set>
27
 
 
28
 
#define INSERT 1
29
 
#define DELETE 0
30
 
#define QUERY 2
31
 
 
32
 
class Region
33
 
{
34
 
public:
35
 
        double m_xmin, m_ymin, m_xmax, m_ymax;
36
 
 
37
 
        Region(double x1, double y1, double x2, double y2)
38
 
        {
39
 
                m_xmin = (x1 < x2) ? x1 : x2;
40
 
                m_ymin = (y1 < y2) ? y1 : y2;
41
 
                m_xmax = (x1 > x2) ? x1 : x2;
42
 
                m_ymax = (y1 > y2) ? y1 : y2;
43
 
        }
44
 
};
45
 
 
46
 
int main(int argc, char** argv)
47
 
{
48
 
        if (argc != 3)
49
 
        {
50
 
                std::cerr << "Usage: " << argv[0] << " number_of_data time_instants." << std::endl;
51
 
                return -1;
52
 
        }
53
 
 
54
 
        size_t simulationLength = atol(argv[2]);
55
 
        size_t numberOfObjects = atol(argv[1]);
56
 
        std::map<size_t, Region> data;
57
 
        Tools::Random rnd;
58
 
 
59
 
        for (size_t i = 0; i < numberOfObjects; i++)
60
 
        {
61
 
                double x = rnd.nextUniformDouble();
62
 
                double y = rnd.nextUniformDouble();
63
 
                double dx = rnd.nextUniformDouble(0.0001, 0.1);
64
 
                double dy = rnd.nextUniformDouble(0.0001, 0.1);
65
 
                Region r = Region(x, y, x + dx, y + dy);
66
 
 
67
 
                data.insert(std::pair<size_t, Region>(i, r));
68
 
 
69
 
                std::cout << INSERT << " " << i << " " << r.m_xmin << " " << r.m_ymin << " "
70
 
                        << r.m_xmax << " " << r.m_ymax << std::endl;
71
 
        }
72
 
 
73
 
        if (simulationLength == 0)
74
 
        {
75
 
                for (size_t i = 0; i < 10; i++)
76
 
                {
77
 
                        double stx = rnd.nextUniformDouble();
78
 
                        double sty = rnd.nextUniformDouble();
79
 
                        std::cout << QUERY << " 9999999 " << stx << " " << sty << " " << (stx + 0.01) << " " << (sty + 0.01) << std::endl;
80
 
                }
81
 
        }
82
 
 
83
 
        size_t A = static_cast<size_t>(std::floor(static_cast<double>(numberOfObjects) * 0.05));
84
 
 
85
 
        for (size_t T = 1; T <= simulationLength; T++)
86
 
        {
87
 
                std::cerr << (simulationLength + 1 - T) << std::endl;
88
 
                std::set<size_t> examined;
89
 
 
90
 
                for (size_t a = 0; a < A; a++)
91
 
                {
92
 
                        // find an id that is not yet examined.
93
 
                        size_t id = static_cast<size_t>(rnd.nextUniformLong(0, numberOfObjects));
94
 
                        std::set<size_t>::iterator itSet = examined.find(id);
95
 
 
96
 
                        while (itSet != examined.end())
97
 
                        {
98
 
                                id = static_cast<size_t>(rnd.nextUniformLong(0, numberOfObjects));
99
 
                                itSet = examined.find(id);
100
 
                        }
101
 
                        examined.insert(id);
102
 
 
103
 
                        std::map<size_t, Region>::iterator itMap = data.find(id);
104
 
                        assert(itMap != data.end());
105
 
 
106
 
                        std::cout << DELETE << " " << id << " " << (*itMap).second.m_xmin << " " << (*itMap).second.m_ymin << " "
107
 
                                << (*itMap).second.m_xmax << " " << (*itMap).second.m_ymax << std::endl;
108
 
 
109
 
                        double x = rnd.nextUniformDouble();
110
 
                        double dx = rnd.nextUniformDouble(0.0001, 0.1);
111
 
                        (*itMap).second.m_xmin = x;
112
 
                        (*itMap).second.m_xmax = x + dx;
113
 
                        double y = rnd.nextUniformDouble();
114
 
                        double dy = rnd.nextUniformDouble(0.0001, 0.1);
115
 
                        (*itMap).second.m_ymin = y;
116
 
                        (*itMap).second.m_ymax = y + dy;
117
 
 
118
 
                        std::cout << INSERT << " " << id << " " << (*itMap).second.m_xmin << " " << (*itMap).second.m_ymin << " "
119
 
                                << (*itMap).second.m_xmax << " " << (*itMap).second.m_ymax << std::endl;
120
 
                }
121
 
 
122
 
                double stx = rnd.nextUniformDouble();
123
 
                double sty = rnd.nextUniformDouble();
124
 
                std::cout << QUERY << " 9999999 " << stx << " " << sty << " " << (stx + 0.01) << " " << (sty + 0.01) << std::endl;
125
 
        }
126
 
 
127
 
        return 0;
128
 
}