Line | |
---|

1 | #include <fstream> |
---|

2 | #include <iostream> |
---|

3 | |
---|

4 | #include <lemon/xy.h> |
---|

5 | #include <lemon/maps.h> |
---|

6 | #include <lemon/error.h> |
---|

7 | #include <lemon/list_graph.h> |
---|

8 | #include <lemon/graph_reader.h> |
---|

9 | #include <lemon/graph_utils.h> |
---|

10 | |
---|

11 | using namespace lemon; |
---|

12 | |
---|

13 | typedef ListGraph Graph; |
---|

14 | typedef xy<double> Coordinates; |
---|

15 | typedef Graph::NodeMap<Coordinates> CoordinatesMap; |
---|

16 | typedef Graph::Node Node; |
---|

17 | |
---|

18 | class CoordReaderMap: public MapBase<Node, double> |
---|

19 | { |
---|

20 | CoordinatesMap * cm; |
---|

21 | char xoy; |
---|

22 | |
---|

23 | public: |
---|

24 | CoordReaderMap(char xory, CoordinatesMap * coordmap): cm(coordmap) |
---|

25 | { |
---|

26 | switch(xory) |
---|

27 | { |
---|

28 | case 'x': |
---|

29 | case 'y': |
---|

30 | xoy=xory; |
---|

31 | break; |
---|

32 | default: |
---|

33 | throw UninitializedParameter() ; |
---|

34 | } |
---|

35 | } |
---|

36 | |
---|

37 | void set(Node node, double coord) |
---|

38 | { |
---|

39 | switch(xoy) |
---|

40 | { |
---|

41 | case 'x': |
---|

42 | (*cm)[node].x=coord; |
---|

43 | break; |
---|

44 | case 'y': |
---|

45 | (*cm)[node].y=coord; |
---|

46 | break; |
---|

47 | default: |
---|

48 | throw UninitializedParameter() ; |
---|

49 | } |
---|

50 | } |
---|

51 | }; |
---|

52 | |
---|

53 | int main(void) |
---|

54 | { |
---|

55 | Graph g; |
---|

56 | CoordinatesMap cm(g); |
---|

57 | |
---|

58 | CoordReaderMap xreader('x',&cm); |
---|

59 | CoordReaderMap yreader('y',&cm); |
---|

60 | |
---|

61 | std::ifstream is("dijkstra_test.lemon"); |
---|

62 | |
---|

63 | GraphReader<Graph> reader(is, g); |
---|

64 | reader.addNodeMap("coordinates_x", xreader); |
---|

65 | reader.addNodeMap("coordinates_y", yreader); |
---|

66 | reader.run(); |
---|

67 | |
---|

68 | return 0; |
---|

69 | } |
---|

**Note:** See

TracBrowser
for help on using the repository browser.