annotate DEPENDENCIES/generic/include/boost/graph/write_dimacs.hpp @ 118:770eb830ec19 emscripten

Typo fix
author Chris Cannam
date Wed, 18 May 2016 16:14:08 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (c) 2006, Stephan Diederich
Chris@16 2 //
Chris@16 3 // This code may be used under either of the following two licences:
Chris@16 4 //
Chris@16 5 // Permission is hereby granted, free of charge, to any person
Chris@16 6 // obtaining a copy of this software and associated documentation
Chris@16 7 // files (the "Software"), to deal in the Software without
Chris@16 8 // restriction, including without limitation the rights to use,
Chris@16 9 // copy, modify, merge, publish, distribute, sublicense, and/or
Chris@16 10 // sell copies of the Software, and to permit persons to whom the
Chris@16 11 // Software is furnished to do so, subject to the following
Chris@16 12 // conditions:
Chris@16 13 //
Chris@16 14 // The above copyright notice and this permission notice shall be
Chris@16 15 // included in all copies or substantial portions of the Software.
Chris@16 16 //
Chris@16 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@16 18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
Chris@16 19 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@16 20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Chris@16 21 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Chris@16 22 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Chris@16 23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Chris@16 24 // OTHER DEALINGS IN THE SOFTWARE. OF SUCH DAMAGE.
Chris@16 25 //
Chris@16 26 // Or:
Chris@16 27 //
Chris@16 28 // Distributed under the Boost Software License, Version 1.0.
Chris@16 29 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 30 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 31
Chris@16 32 /*
Chris@16 33 Writes maximal flow problem in extended DIMACS format to an OutputIterator
Chris@16 34 Vertex indices are read from an IndexMap and shiftet by 1.
Chris@16 35 so their new range is [1..num_vertices(g)]
Chris@16 36 */
Chris@16 37
Chris@16 38 /* ----------------------------------------------------------------- */
Chris@16 39
Chris@16 40 #include <vector>
Chris@16 41 #include <string>
Chris@16 42 #include <ostream>
Chris@16 43
Chris@16 44 namespace boost {
Chris@16 45
Chris@16 46 template <class Graph, class CapacityMap, class IndexMap>
Chris@16 47 void write_dimacs_max_flow(const Graph& g,
Chris@16 48 CapacityMap capacity,
Chris@16 49 IndexMap idx,
Chris@16 50 typename graph_traits<Graph>::vertex_descriptor src,
Chris@16 51 typename graph_traits<Graph>::vertex_descriptor sink,
Chris@16 52 std::ostream& out)
Chris@16 53 {
Chris@16 54 typedef typename graph_traits<Graph>::edge_iterator edge_iterator;
Chris@16 55
Chris@16 56 out << "c DIMACS max-flow file generated from boost::write_dimacs_max_flow" << std::endl;
Chris@16 57 out << "p max " << num_vertices(g) << " " << num_edges(g) << std::endl; //print problem description "max" and number of verts and edges
Chris@16 58 out << "n " << get(idx, src) + 1 << " s" << std::endl;; //say which one is source
Chris@16 59 out << "n " << get(idx, sink) + 1 << " t" << std::endl; //say which one is sink
Chris@16 60
Chris@16 61 //output the edges
Chris@16 62 edge_iterator ei, e_end;
Chris@16 63 for(boost::tie(ei,e_end) = edges(g); ei!=e_end; ++ei){
Chris@16 64 out << "a " << idx[ source(*ei, g) ] + 1 << " " << idx[ target(*ei, g) ] + 1 << " " << get(capacity,*ei) << std::endl;
Chris@16 65 }
Chris@16 66 }
Chris@16 67
Chris@16 68 } // namespace boost