COIN-OR::LEMON - Graph Library

Changeset 1208:f486d30e4e7b in lemon-0.x for src/lemon/graph_writer.h


Ignore:
Timestamp:
03/09/05 15:15:22 (15 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1627
Message:

Easy input-output function for common graphs.
Modified Exception handling in graph_reader.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/graph_writer.h

    r1188 r1208  
    2828#include <memory>
    2929
     30#include <lemon/map_utils.h>
    3031#include <lemon/invalid.h>
    3132#include <lemon/error.h>
     
    163164    /// it constructs the given map and it use the given writer as the
    164165    /// default skipper.
    165     GraphWriter(std::ostream& _os, Graph& _graph) : os(_os), graph(_graph) {}
     166    GraphWriter(std::ostream& _os, const Graph& _graph)
     167      : os(_os), graph(_graph) {}
    166168
    167169
     
    368370
    369371    std::ostream& os;
    370     Graph& graph;
     372    const Graph& graph;
    371373
    372374  };
    373375
     376  /// Ready to use writer function. 
     377  template<typename Graph, typename CapacityMap, typename CostMap>
     378  void writeGraph(std::ostream& os, const Graph &g,
     379                  const CapacityMap& capacity, const typename Graph::Node &s,
     380                  const typename Graph::Node &t, const CostMap& cost) {
     381    GraphWriter<Graph> reader(os, g);
     382    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
     383    reader.addNodeMap("id", nodeIdMap);
     384    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
     385    reader.addEdgeMap("id", edgeIdMap);
     386    reader.addEdgeMap("capacity", capacity);
     387    reader.addEdgeMap("cost", cost);
     388    reader.addNode("source", s);
     389    reader.addNode("target", t);
     390    reader.run();
     391  }
     392
     393  /// Ready to use writer function. 
     394  template<typename Graph, typename CapacityMap, typename CostMap>
     395  void writeGraph(std::ostream& os, const Graph &g,
     396                  const CapacityMap& capacity, const typename Graph::Node &s,
     397                  const typename Graph::Node &t) {
     398    GraphWriter<Graph> reader(os, g);
     399    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
     400    reader.addNodeMap("id", nodeIdMap);
     401    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
     402    reader.addEdgeMap("id", edgeIdMap);
     403    reader.addEdgeMap("capacity", capacity);
     404    reader.addNode("source", s);
     405    reader.addNode("target", t);
     406    reader.run();
     407  }
     408
     409  /// Ready to use writer function. 
     410  template<typename Graph, typename CapacityMap>
     411  void writeGraph(std::ostream& os, const Graph &g,
     412                  const CapacityMap& capacity, const typename Graph::Node &s) {
     413    GraphWriter<Graph> reader(os, g);
     414    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
     415    reader.addNodeMap("id", nodeIdMap);
     416    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
     417    reader.addEdgeMap("id", edgeIdMap);
     418    reader.addEdgeMap("capacity", capacity);
     419    reader.addNode("source", s);
     420    reader.run();
     421  }
     422  /// Ready to use writer function. 
     423  template<typename Graph, typename CapacityMap>
     424  void writeGraph(std::ostream& os, const Graph &g,
     425                  const CapacityMap& capacity) {
     426    GraphWriter<Graph> reader(os, g);
     427    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
     428    reader.addNodeMap("id", nodeIdMap);
     429    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
     430    reader.addEdgeMap("id", edgeIdMap);
     431    reader.addEdgeMap("capacity", capacity);
     432    reader.run();
     433  }
     434  /// Ready to use writer function. 
     435  template<typename Graph>
     436  void writeGraph(std::ostream& os, const Graph &g) {
     437    GraphWriter<Graph> reader(os, g);
     438    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
     439    reader.addNodeMap("id", nodeIdMap);
     440    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
     441    reader.addEdgeMap("id", edgeIdMap);
     442    reader.run();
     443  }
     444
    374445
    375446}
Note: See TracChangeset for help on using the changeset viewer.