00001
00002
00003 #include "GraphContainer.h"
00004 #include "GraphProperties.h"
00005 #include "Changelist.h"
00006 #include "ChangeTimeline.h"
00007 #include "ByteOutBuffer.h"
00008 #include "AttributeBlob.h"
00009 #include "GraphLoaderKFile.h"
00010 #include "GraphServer.h"
00011
00012 #include "RTree.h"
00013
00014 #include "AttributeParser.h"
00015
00016 #include "ByteInBuffer.h"
00017 #include "GraphParser.h"
00018
00019 #include <stdlib.h>
00020 #include <iostream>
00021 #include <fstream>
00022 #include <string>
00023
00024 #if defined(__GNUC__)
00025 #include <sys/time.h>
00026
00027 double timestamp() {
00028 struct timeval tp;
00029 gettimeofday(&tp, NULL);
00030 return double(tp.tv_sec) + tp.tv_usec / 1000000.;
00031 }
00032 #else
00033 double timestamp() {
00034 return 0.0;
00035 }
00036 #endif
00037
00038 class TestParserCallback : public VGServer::GraphParserCallbackAdapter
00039 {
00040 public:
00041
00042 void eventStartEdgeBody(unsigned int objnum)
00043 {
00044 std::cout << "Parser: " << objnum << " edges\n";
00045 }
00046 void eventEdge(const std::vector<VGServer::AnyType> &vals)
00047 {
00048
00049 }
00050
00051 };
00052
00053 int main(int argc, char *argv[])
00054 {
00055 using namespace VGServer;
00056
00057 srand(time(NULL));
00058
00059 GraphProperties gp;
00060 gp.directed = false;
00061
00062 gp.vertexattr.push_back(AttributeProperties("x", AnyType(int(0)) ));
00063 gp.vertexattr.push_back(AttributeProperties("y", AnyType(int(0)) ));
00064 gp.vertexattr.push_back(AttributeProperties("level", AnyType(int(0)) ));
00065
00066 gp.vertexattr[0].varying = true;
00067 gp.vertexattr[1].varying = true;
00068
00069 gp.edgeattr.push_back(AttributeProperties("distance", AnyType(int(0)) ));
00070 gp.edgeattr.push_back(AttributeProperties("direction", AnyType(char(0)) ));
00071 gp.edgeattr.push_back(AttributeProperties("speed", AnyType(char(0)) ));
00072
00073 gp.calcAttributeLookups();
00074
00075 #if 0
00076 std::string arg(argv[1]);
00077 AttributeSelectorList froot;
00078
00079 try {
00080 froot.parseString(arg, gp, VE_EDGE);
00081 }
00082 catch(VGServer::ConversionException &e)
00083 {
00084 std::cout << "ConversionEx: " << e.what() << "\n";
00085 }
00086 catch(VGServer::ParseException &e)
00087 {
00088 std::cout << "ParseEx: " << e.what() << "\n";
00089 }
00090
00091 std::cout << "Parsed: " << froot.toString() << "\n";
00092
00093 return 0;
00094 #endif
00095
00096 #if 0
00097 GraphLoaderKFile loader(gp);
00098
00099 if (!loader.load(std::cin)) return 0;
00100
00101 GraphContainer gc(gp);
00102
00103 gc.applyGraphData( loader.finish() );
00104
00105 assert( gc.checkReferences() );
00106
00107 gc.saveSnapshot(std::cout);
00108 return 0;
00109 #endif
00110 #if 1
00111 GraphContainer gc(gp);
00112
00113 std::ifstream fin("karten/deu.ksnap");
00114
00115 if (!gc.loadSnapshot(fin)) {
00116 std::cerr << "Loading of snapshot failed.\n";
00117 return 0;
00118 }
00119
00120 assert( gc.checkReferences() );
00121 #endif
00122
00123 ChangeTimeline ct (gc);
00124
00125 #if 1
00126 double ats1 = timestamp();
00127
00128 int chg = 0;
00129
00130 std::vector<class EdgeRef> edgelist;
00131
00132 for(int li = 0; li < 100; li++)
00133 {
00134 ct.advanceTimeFrame();
00135
00136 int vertexnum = gc.getVertexCount();
00137 int randnum = 10000;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 for(int i = 0; i < randnum; i++)
00152 {
00153 int vid1 = rand() % vertexnum;
00154 vid1 = i;
00155
00156 edgelist = gc.getEdgeList(vid1, ct.getChangelistEnd());
00157 if (edgelist.size() == 0) {
00158 randnum++;
00159 continue;
00160 }
00161
00162 if (ct.setEdgeAttr(edgelist[0].getSource(),
00163 edgelist[0].getTarget(),
00164 2,
00165 110))
00166 {
00167 chg++;
00168 }
00169 }
00170 std::cerr << "Changes: " << chg << "\n";
00171 }
00172
00173 double ats2 = timestamp();
00174
00175 std::cout << "Change time: " << (ats2-ats1) << "\n";
00176
00177
00178 #endif
00179
00180 #if 1
00181
00182
00183
00184
00185
00186 double ts1 = timestamp();
00187
00188 ByteBuffer bb;
00189
00190 for(unsigned int i = 0; i < 1; i++)
00191 {
00192 gc.getArea(0,0,10000000,10000000, NULL,
00193 "","","(src.x - 200000) * 0.03, src.y, tgt.x, tgt.y, speed", ct, bb);
00194 }
00195
00196 double ts2 = timestamp();
00197
00198 std::cerr << "Query time: " << (ts2-ts1) << " sec. Result size: " << bb.size() << std::endl;
00199
00200 TestParserCallback cb;
00201
00202 GraphParser<TestParserCallback>::parse(cb, bb);
00203 #endif
00204
00205 #if 0
00206 Changelist cl(gc);
00207
00208 double ts1 = timestamp();
00209
00210 ByteOutBuffer bob = gc.getNearestNeighbor(0,0,1000000,10000000, 843761, 489432,
00211 "", "*", "*", cl);
00212
00213 double ts2 = timestamp();
00214
00215 std::cout << "Query time: " << (ts2-ts1)/20.0 << " sec. Result size: " << bob.size() << std::endl;
00216 #endif
00217
00218 #if 0
00219 RTree tree;
00220
00221 for(vertexid_t vi = 0; vi < gd.vertices.size()-1; vi++)
00222 {
00223 if (not gd.existVertex(vi)) continue;
00224
00225 int x1 = gd.getVertexAttr(vi, 0).getInteger();
00226 int y1 = gd.getVertexAttr(vi, 1).getInteger();
00227
00228 unsigned int endedgeidx = gd.vertices[vi+1].edgeidx;
00229
00230 for(unsigned int ei = gd.vertices[vi].edgeidx; ei < endedgeidx; ei++)
00231 {
00232 vertexid_t tvi = gd.edges[ei].target;
00233 if (tvi == VERTEX_INVALID) break;
00234 if (not gd.existVertex(tvi)) continue;
00235
00236 int x2 = gd.getVertexAttr(tvi, 0).getInteger();
00237 int y2 = gd.getVertexAttr(tvi, 1).getInteger();
00238
00239
00240
00241
00242 tree.insertRect(RTree::Rect(std::min(x1,x2), std::min(-y1,-y2),
00243 std::max(x1,x2), std::max(-y1,-y2)),
00244 RTreeData(0,0));
00245
00246 }
00247 }
00248
00249 assert(tree.testTree());
00250
00251 #if 0
00252 for(vertexid_t vi = 0; vi < gd.vertices.size()-1; vi++)
00253 {
00254 if (not gd.existVertex(vi)) continue;
00255
00256 unsigned int x1 = gd.getVertexAttr(vi, 0).getInteger();
00257 unsigned int y1 = gd.getVertexAttr(vi, 1).getInteger();
00258
00259 unsigned int endedgeidx = gd.vertices[vi+1].edgeidx;
00260
00261 for(unsigned int ei = gd.vertices[vi].edgeidx; ei < endedgeidx; ei++)
00262 {
00263 vertexid_t tvi = gd.edges[ei].target;
00264 if (tvi == VERTEX_INVALID) break;
00265 if (not gd.existVertex(tvi)) continue;
00266
00267 unsigned int x2 = gd.getVertexAttr(tvi, 0).getInteger();
00268 unsigned int y2 = gd.getVertexAttr(tvi, 1).getInteger();
00269
00270
00271
00272
00273 bool b = tree.deleteRect(RTree::Rect(std::min(x1,x2), std::min(-y1,-y2),
00274 std::max(x1,x2), std::max(-y1,-y2)),
00275 0);
00276
00277 assert(b);
00278
00279 }
00280 }
00281
00282 assert(tree.testTree());
00283 assert(tree.empty());
00284 #endif
00285
00286 std::ofstream ffig("o.fig");
00287
00288
00289
00290 tree.writeFig(true, ffig, 1);
00291
00292 #endif
00293 }