1 | /* -*- C++ -*- |
---|

2 | * demo/lp_maxflow_demo.cc - Part of LEMON, a generic C++ optimization library |
---|

3 | * |
---|

4 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|

5 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|

6 | * |
---|

7 | * Permission to use, modify and distribute this software is granted |
---|

8 | * provided that this copyright notice appears in all copies. For |
---|

9 | * precise terms see the accompanying LICENSE file. |
---|

10 | * |
---|

11 | * This software is provided "AS IS" with no warranty of any kind, |
---|

12 | * express or implied, and with no claim as to its suitability for any |
---|

13 | * purpose. |
---|

14 | * |
---|

15 | */ |
---|

16 | |
---|

17 | ///\ingroup demos |
---|

18 | ///\file |
---|

19 | ///\brief Demonstrating graph input and output |
---|

20 | /// |
---|

21 | /// This simple demo program gives an example of how to read and write |
---|

22 | /// a graph and additional maps (on the nodes or the edges) from/to a |
---|

23 | /// stream. |
---|

24 | |
---|

25 | |
---|

26 | #include <iostream> |
---|

27 | #include <lemon/smart_graph.h> |
---|

28 | #include <lemon/invalid.h> |
---|

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

30 | #include <lemon/graph_writer.h> |
---|

31 | |
---|

32 | |
---|

33 | using namespace lemon; |
---|

34 | |
---|

35 | int main() { |
---|

36 | SmartGraph graph; |
---|

37 | |
---|

38 | try { |
---|

39 | std::string filename="sample.lgf"; |
---|

40 | GraphReader<SmartGraph> reader(filename,graph); |
---|

41 | SmartGraph::EdgeMap<int> cap(graph); |
---|

42 | reader.readEdgeMap("capacity",cap); |
---|

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

44 | |
---|

45 | std::cout << "Hello! We have read a graph from file " << filename<< |
---|

46 | " and some maps on it:\n now we write it to the standard output!" << |
---|

47 | std::endl; |
---|

48 | |
---|

49 | |
---|

50 | GraphWriter<SmartGraph> writer(std::cout, graph); |
---|

51 | writer.writeEdgeMap("multiplicity", cap); |
---|

52 | writer.run(); |
---|

53 | |
---|

54 | } catch (DataFormatError& error) { |
---|

55 | std::cerr << error.what() << std::endl; |
---|

56 | } |
---|

57 | |
---|

58 | |
---|

59 | return 0; |
---|

60 | } |
---|