COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
12/15/04 20:56:55 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1427
Message:

graph_io under construction
This is a working version, but needs more improvments.

todo:

documention + fix the file format
improve the exception system

add some possible asserts

tutorials

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/deba/graph_io_test.cc

    r1036 r1037  
    11#include <lemon/smart_graph.h>
     2
     3#include "map_utils.h"
     4
     5
    26#include "graph_reader.h"
     7#include "graph_writer.h"
    38
    49#include <iostream>
     
    1217  SmartGraph graph;
    1318  GraphReader<SmartGraph> reader(input, graph);
     19
    1420  SmartGraph::NodeMap<int> id(graph);
    1521  reader.readNodeMap("id", id);
     22
    1623  SmartGraph::NodeMap<int> cost(graph);
    1724  reader.readNodeMap("cost", cost);
     25 
    1826  SmartGraph::NodeMap<string> color(graph);
    1927  reader.readNodeMap("color", color);
     28
    2029  SmartGraph::NodeMap<string> description(graph);
    2130  reader.readNodeMap<QuotedStringReader>("description", description);
     31
    2232  SmartGraph::EdgeMap<char> mmap(graph);
    2333  reader.readEdgeMap("mmap", mmap);
     34
    2435  reader.skipEdgeMap<QuotedStringReader>("description");
     36
     37  SmartGraph::Node source;
     38  reader.readNode("source", source);
     39 
     40  SmartGraph::Edge newedge;
     41  reader.readEdge("newedge", newedge);
     42
    2543  try {
    2644    reader.read();
     
    3755    cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)]  << endl;
    3856  }
     57
     58  cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl;
     59  cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)]  << endl;
     60
     61  ofstream output("copy.lgf");
     62  GraphWriter<SmartGraph> writer(output, graph);
     63 
     64  DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph);
     65 
     66  writer.writeNodeMap("id", node_ids);
     67  writer.writeNodeMap<QuotedStringWriter>("format", description);
     68
     69  DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph);
     70
     71  writer.writeEdgeMap("id", edge_ids);
     72  writer.writeEdgeMap("chars", mmap);
     73 
     74  writer.writeNode("source", node_ids.inverse()[3]);
     75  writer.writeEdge("elek", edge_ids.inverse()[6]);
     76  writer.write();
     77 
    3978  return 0;
    4079}
Note: See TracChangeset for help on using the changeset viewer.