author | alpar |
Thu, 31 Mar 2005 14:04:13 +0000 | |
changeset 1284 | b941d044f87b |
parent 1277 | e4cc8e996912 |
child 1286 | 692948b894e8 |
permissions | -rw-r--r-- |
hegyi@1277 | 1 |
#include <fstream> |
hegyi@1277 | 2 |
#include <iostream> |
hegyi@1277 | 3 |
|
hegyi@1277 | 4 |
#include <lemon/xy.h> |
alpar@1278 | 5 |
#include <lemon/maps.h> |
hegyi@1277 | 6 |
#include <lemon/error.h> |
hegyi@1277 | 7 |
#include <lemon/list_graph.h> |
hegyi@1277 | 8 |
#include <lemon/graph_reader.h> |
hegyi@1277 | 9 |
#include <lemon/graph_utils.h> |
hegyi@1277 | 10 |
|
hegyi@1277 | 11 |
using namespace lemon; |
hegyi@1277 | 12 |
|
hegyi@1277 | 13 |
typedef ListGraph Graph; |
hegyi@1277 | 14 |
typedef xy<double> Coordinates; |
hegyi@1277 | 15 |
typedef Graph::NodeMap<Coordinates> CoordinatesMap; |
hegyi@1277 | 16 |
typedef Graph::Node Node; |
hegyi@1277 | 17 |
|
alpar@1278 | 18 |
class CoordReaderMap: public MapBase<Node, double> |
hegyi@1277 | 19 |
{ |
hegyi@1277 | 20 |
CoordinatesMap * cm; |
hegyi@1277 | 21 |
char xoy; |
hegyi@1277 | 22 |
|
hegyi@1277 | 23 |
public: |
alpar@1278 | 24 |
CoordReaderMap(char xory, CoordinatesMap * coordmap): cm(coordmap) |
hegyi@1277 | 25 |
{ |
hegyi@1277 | 26 |
switch(xory) |
hegyi@1277 | 27 |
{ |
hegyi@1277 | 28 |
case 'x': |
hegyi@1277 | 29 |
case 'y': |
hegyi@1277 | 30 |
xoy=xory; |
hegyi@1277 | 31 |
break; |
hegyi@1277 | 32 |
default: |
hegyi@1277 | 33 |
throw UninitializedParameter() ; |
hegyi@1277 | 34 |
} |
hegyi@1277 | 35 |
} |
hegyi@1277 | 36 |
|
hegyi@1277 | 37 |
void set(Node node, double coord) |
hegyi@1277 | 38 |
{ |
hegyi@1277 | 39 |
switch(xoy) |
hegyi@1277 | 40 |
{ |
hegyi@1277 | 41 |
case 'x': |
hegyi@1277 | 42 |
(*cm)[node].x=coord; |
hegyi@1277 | 43 |
break; |
hegyi@1277 | 44 |
case 'y': |
hegyi@1277 | 45 |
(*cm)[node].y=coord; |
hegyi@1277 | 46 |
break; |
hegyi@1277 | 47 |
default: |
hegyi@1277 | 48 |
throw UninitializedParameter() ; |
hegyi@1277 | 49 |
} |
hegyi@1277 | 50 |
} |
hegyi@1277 | 51 |
}; |
hegyi@1277 | 52 |
|
hegyi@1277 | 53 |
int main(void) |
hegyi@1277 | 54 |
{ |
hegyi@1277 | 55 |
Graph g; |
hegyi@1277 | 56 |
CoordinatesMap cm(g); |
hegyi@1277 | 57 |
|
hegyi@1277 | 58 |
CoordReaderMap xreader('x',&cm); |
hegyi@1277 | 59 |
CoordReaderMap yreader('y',&cm); |
hegyi@1277 | 60 |
|
hegyi@1277 | 61 |
std::ifstream is("dijkstra_test.lemon"); |
hegyi@1277 | 62 |
|
hegyi@1277 | 63 |
GraphReader<Graph> reader(is, g); |
hegyi@1277 | 64 |
reader.addNodeMap("coordinates_x", xreader); |
hegyi@1277 | 65 |
reader.addNodeMap("coordinates_y", yreader); |
hegyi@1277 | 66 |
reader.run(); |
hegyi@1277 | 67 |
|
hegyi@1277 | 68 |
return 0; |
hegyi@1277 | 69 |
} |