COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/peter/xy-reader.cc @ 1286:692948b894e8

Last change on this file since 1286:692948b894e8 was 1286:692948b894e8, checked in by Hegyi Péter, 15 years ago

Peter is able to read xy vector from file.

File size: 1.4 KB
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
11using namespace lemon;
12
13typedef ListGraph Graph;
14typedef xy<double> Coordinates;
15typedef Graph::NodeMap<Coordinates> CoordinatesMap;
16typedef Graph::Node Node;
17typedef Graph::EdgeIt EdgeIt;
18typedef Graph::NodeIt NodeIt;
19
20class CoordReaderMap: public MapBase <Node, double>
21{
22    CoordinatesMap & cm;
23    char xoy;
24
25public:
26    CoordReaderMap(char xory, CoordinatesMap & coordmap): cm(coordmap)
27    {
28        switch(xory)
29        {
30            case 'x':
31            case 'y':
32                xoy=xory;
33                break;
34            default:
35                throw UninitializedParameter() ;
36        }
37    }
38
39    void set(Node node, double coord)
40    {
41        switch(xoy)
42        {
43            case 'x':
44                cm[node].x=coord;
45                break;
46            case 'y':
47                cm[node].y=coord;
48                break;
49            default:
50                throw UninitializedParameter() ;
51        }
52    }
53};
54
55int main(void)
56{
57    Graph g;
58    CoordinatesMap cm(g);
59
60    CoordReaderMap xreader('x',cm);
61    CoordReaderMap yreader('y',cm);
62
63    std::ifstream is("graphocska.lemon");
64   
65    GraphReader<Graph> reader(is, g);
66    reader.addNodeMap("coordinates_x", xreader);
67    reader.addNodeMap("coordinates_y", yreader);
68    reader.run();
69    std::cout << "Megvagyok" << std::endl;
70
71    for (NodeIt i(g); i!=INVALID; ++i)
72        std::cout << " " << g.id(i) << " " << cm[i];
73    std::cout << std::endl;
74
75    return 0;
76}
Note: See TracBrowser for help on using the repository browser.