From 053a038bf8356d90499fabde8a10a4477a609ff4 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Fri, 18 Mar 2016 21:07:08 +0100 Subject: [PATCH] Add lemon graph library --- lib/import/import-lemon.mk | 2 + lib/mk/lemon.mk | 11 +++ ports/lemon.hash | 1 + ports/lemon.port | 92 +++++++++++++++++++ run/lemon.run | 43 +++++++++ src/lib/lemon/BpGraphReader.patch | 144 ++++++++++++++++++++++++++++++ src/lib/lemon/BpGraphWriter.patch | 53 +++++++++++ src/lib/lemon/lemon/config.h | 13 +++ src/test/lemon/target.mk | 6 ++ 9 files changed, 365 insertions(+) create mode 100644 lib/import/import-lemon.mk create mode 100644 lib/mk/lemon.mk create mode 100644 ports/lemon.hash create mode 100644 ports/lemon.port create mode 100644 run/lemon.run create mode 100644 src/lib/lemon/BpGraphReader.patch create mode 100644 src/lib/lemon/BpGraphWriter.patch create mode 100644 src/lib/lemon/lemon/config.h create mode 100644 src/test/lemon/target.mk diff --git a/lib/import/import-lemon.mk b/lib/import/import-lemon.mk new file mode 100644 index 0000000..83fe758 --- /dev/null +++ b/lib/import/import-lemon.mk @@ -0,0 +1,2 @@ +INC_DIR += $(call select_from_ports,lemon)/include +REP_INC_DIR += src/lib/lemon diff --git a/lib/mk/lemon.mk b/lib/mk/lemon.mk new file mode 100644 index 0000000..7294fad --- /dev/null +++ b/lib/mk/lemon.mk @@ -0,0 +1,11 @@ +LEMON_DIR = $(call select_from_ports,lemon)/src/lib/lemon/lemon/ +LIBS += stdcxx libm +INC_DIR += $(call select_from_ports,lemon)/include/ +INC_DIR += $(REP_DIR)/src/lib/lemon/ +SRC_CC = base.cc + +CC_WARN = + +vpath %.cc $(LEMON_DIR) + +#SHARED_LIB = yes diff --git a/ports/lemon.hash b/ports/lemon.hash new file mode 100644 index 0000000..ed27ad4 --- /dev/null +++ b/ports/lemon.hash @@ -0,0 +1 @@ +daa765889c3d4005a752f78fe978cbe463a39f98 diff --git a/ports/lemon.port b/ports/lemon.port new file mode 100644 index 0000000..0c62482 --- /dev/null +++ b/ports/lemon.port @@ -0,0 +1,92 @@ +LICENSE := Boost Software License 1.0 +VERSION := 1.3 +DOWNLOADS := lemon.archive + +URL(lemon) := http://lemon.cs.elte.hu/pub/sources/lemon-$(VERSION).tar.gz +SHA(lemon) := c833604b790e6f45d5cf8da304d9b23ba74eae6c +DIR(lemon) := src/lib/lemon + +PATCHES := $(addprefix src/lib/lemon/,BpGraphReader.patch BpGraphWriter.patch) + +DIRS := include/lemon + +DIR_CONTENT(include/lemon) := $(addprefix src/lib/lemon/lemon/,concepts \ + bits \ + adaptors.h\ + arg_parser.h\ + assert.h\ + bellman_ford.h\ + bfs.h\ + bin_heap.h\ + binomial_heap.h\ + bucket_heap.h\ + capacity_scaling.h\ + cbc.h\ + christofides_tsp.h\ + circulation.h\ + clp.h\ + color.h\ + concept_check.h\ + connectivity.h\ + core.h\ + cost_scaling.h\ + counter.h\ + cplex.h\ + cycle_canceling.h\ + dfs.h\ + dheap.h\ + dijkstra.h\ + dim2.h\ + dimacs.h\ + edge_set.h\ + edmonds_karp.h\ + elevator.h\ + error.h\ + euler.h\ + fib_heap.h\ + fractional_matching.h\ + full_graph.h\ + glpk.h\ + gomory_hu.h\ + graph_to_eps.h\ + greedy_tsp.h\ + grid_graph.h\ + grosso_locatelli_pullan_mc.h\ + hao_orlin.h\ + hartmann_orlin_mmc.h\ + howard_mmc.h\ + hypercube_graph.h\ + insertion_tsp.h\ + karp_mmc.h\ + kruskal.h\ + lgf_reader.h\ + lgf_writer.h\ + list_graph.h\ + lp_base.h\ + lp.h\ + lp_skeleton.h\ + maps.h\ + matching.h\ + math.h\ + max_cardinality_search.h\ + min_cost_arborescence.h\ + nagamochi_ibaraki.h\ + nauty_reader.h\ + nearest_neighbor_tsp.h\ + network_simplex.h\ + opt2_tsp.h\ + pairing_heap.h\ + path.h\ + planarity.h\ + preflow.h\ + quad_heap.h\ + radix_heap.h\ + radix_sort.h\ + random.h\ + smart_graph.h\ + soplex.h\ + static_graph.h\ + suurballe.h\ + time_measure.h\ + tolerance.h\ + unionfind.h) diff --git a/run/lemon.run b/run/lemon.run new file mode 100644 index 0000000..3fe6049 --- /dev/null +++ b/run/lemon.run @@ -0,0 +1,43 @@ +build "core init test/lemon" + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + +} + +build_boot_image { + core init test-lemon + ld.lib.so libc.lib.so + libm.lib.so + stdcxx.lib.so +} + +append qemu_args " -nographic -m 64 " + +run_genode_until "child \"test-lemon\" exited with exit value 0" 20 + diff --git a/src/lib/lemon/BpGraphReader.patch b/src/lib/lemon/BpGraphReader.patch new file mode 100644 index 0000000..cae2280 --- /dev/null +++ b/src/lib/lemon/BpGraphReader.patch @@ -0,0 +1,144 @@ ++++ src/lib/lemon/lemon/lgf_reader.h 2016-03-11 13:36:16.116842723 +0100 +@@ -2229,7 +2229,8 @@ namespace lemon { + Attributes; + Attributes _attributes; + +- bool _use_nodes; ++ bool _use_red_nodes; ++ bool _use_blue_nodes; + bool _use_edges; + + bool _skip_nodes; +@@ -2246,7 +2247,7 @@ namespace lemon { + /// input stream. + BpGraphReader(BGR& graph, std::istream& is = std::cin) + : _is(&is), local_is(false), _graph(graph), +- _use_nodes(false), _use_edges(false), ++ _use_red_nodes(false), _use_blue_nodes(false), _use_edges(false), + _skip_nodes(false), _skip_edges(false) {} + + /// \brief Constructor +@@ -2256,7 +2257,7 @@ namespace lemon { + BpGraphReader(BGR& graph, const std::string& fn) + : _is(new std::ifstream(fn.c_str())), local_is(true), + _filename(fn), _graph(graph), +- _use_nodes(false), _use_edges(false), ++ _use_red_nodes(false), _use_blue_nodes(false), _use_edges(false), + _skip_nodes(false), _skip_edges(false) { + if (!(*_is)) { + delete _is; +@@ -2271,7 +2272,7 @@ namespace lemon { + BpGraphReader(BGR& graph, const char* fn) + : _is(new std::ifstream(fn)), local_is(true), + _filename(fn), _graph(graph), +- _use_nodes(false), _use_edges(false), ++ _use_red_nodes(false), _use_blue_nodes(false), _use_edges(false), + _skip_nodes(false), _skip_edges(false) { + if (!(*_is)) { + delete _is; +@@ -2318,7 +2319,7 @@ namespace lemon { + + BpGraphReader(BpGraphReader& other) + : _is(other._is), local_is(other.local_is), _graph(other._graph), +- _use_nodes(other._use_nodes), _use_edges(other._use_edges), ++ _use_red_nodes(other._use_red_nodes), _use_blue_nodes(other._use_blue_nodes), _use_edges(other._use_edges), + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { + + other._is = 0; +@@ -2612,8 +2613,9 @@ namespace lemon { + template + BpGraphReader& useNodes(const Map& map) { + checkConcept, Map>(); +- LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); +- _use_nodes = true; ++ LEMON_ASSERT(!_use_red_nodes&&!_use_blue_nodes, "Multiple usage of useNodes() member"); ++ _use_red_nodes = true; ++ _use_blue_nodes = true; + _writer_bits::DefaultConverter converter; + for (RedNodeIt n(_graph); n != INVALID; ++n) { + _red_node_index.insert(std::make_pair(converter(map[n]), n)); +@@ -2633,8 +2635,9 @@ namespace lemon { + BpGraphReader& useNodes(const Map& map, + const Converter& converter = Converter()) { + checkConcept, Map>(); +- LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); +- _use_nodes = true; ++ LEMON_ASSERT(!_use_red_nodes&&!_use_blue_nodes, "Multiple usage of useNodes() member"); ++ _use_red_nodes = true; ++ _use_blue_nodes = true; + for (RedNodeIt n(_graph); n != INVALID; ++n) { + _red_node_index.insert(std::make_pair(converter(map[n]), n)); + } +@@ -2644,6 +2647,54 @@ namespace lemon { + return *this; + } + ++ template ++ BpGraphReader& useRedNodes(const Map& map) { ++ checkConcept, Map>(); ++ LEMON_ASSERT(!_use_red_nodes, "Multiple usage of useNodes() member"); ++ _use_red_nodes = true; ++ _writer_bits::DefaultConverter converter; ++ for (RedNodeIt n(_graph); n != INVALID; ++n) { ++ _red_node_index.insert(std::make_pair(converter(map[n]), n)); ++ } ++ return *this; ++ } ++ ++ template ++ BpGraphReader& useRedNodes(const Map& map, ++ const Converter& converter = Converter()) { ++ checkConcept, Map>(); ++ LEMON_ASSERT(!_use_red_nodes, "Multiple usage of useNodes() member"); ++ _use_red_nodes = true; ++ for (RedNodeIt n(_graph); n != INVALID; ++n) { ++ _red_node_index.insert(std::make_pair(converter(map[n]), n)); ++ } ++ return *this; ++ } ++ ++ template ++ BpGraphReader& useBlueNodes(const Map& map) { ++ checkConcept, Map>(); ++ LEMON_ASSERT(!_use_blue_nodes, "Multiple usage of useNodes() member"); ++ _use_blue_nodes = true; ++ _writer_bits::DefaultConverter converter; ++ for (BlueNodeIt n(_graph); n != INVALID; ++n) { ++ _blue_node_index.insert(std::make_pair(converter(map[n]), n)); ++ } ++ return *this; ++ } ++ ++ template ++ BpGraphReader& useBlueNodes(const Map& map, ++ const Converter& converter = Converter()) { ++ checkConcept, Map>(); ++ LEMON_ASSERT(!_use_blue_nodes, "Multiple usage of useNodes() member"); ++ _use_blue_nodes = true; ++ for (BlueNodeIt n(_graph); n != INVALID; ++n) { ++ _blue_node_index.insert(std::make_pair(converter(map[n]), n)); ++ } ++ return *this; ++ } ++ + /// \brief Use previously constructed edge set + /// + /// Use previously constructed edge set, and specify the edge +@@ -2800,7 +2851,7 @@ namespace lemon { + throw FormatError("Extra character at the end of line"); + + RedNode n; +- if (!_use_nodes) { ++ if (!_use_red_nodes) { + n = _graph.addRedNode(); + if (label_index != -1) + _red_node_index.insert(std::make_pair(tokens[label_index], n)); +@@ -2893,7 +2944,7 @@ namespace lemon { + throw FormatError("Extra character at the end of line"); + + BlueNode n; +- if (!_use_nodes) { ++ if (!_use_blue_nodes) { + n = _graph.addBlueNode(); + if (label_index != -1) + _blue_node_index.insert(std::make_pair(tokens[label_index], n)); diff --git a/src/lib/lemon/BpGraphWriter.patch b/src/lib/lemon/BpGraphWriter.patch new file mode 100644 index 0000000..c5f23bd --- /dev/null +++ b/src/lib/lemon/BpGraphWriter.patch @@ -0,0 +1,53 @@ ++++ src/lib/lemon/lemon/lgf_writer.h 2016-03-11 14:02:04.371252232 +0100 +@@ -1683,9 +1683,9 @@ namespace lemon { + std::string _edges_caption; + std::string _attributes_caption; + +- typedef std::map RedNodeIndex; ++ typedef std::map RedNodeIndex; + RedNodeIndex _red_node_index; +- typedef std::map BlueNodeIndex; ++ typedef std::map BlueNodeIndex; + BlueNodeIndex _blue_node_index; + typedef std::map EdgeIndex; + EdgeIndex _edge_index; +@@ -2125,8 +2125,8 @@ namespace lemon { + } + + if (label == 0) { +- IdMap id_map(_graph); +- _writer_bits::MapLess > id_less(id_map); ++ IdMap id_map(_graph); ++ _writer_bits::MapLess > id_less(id_map); + std::sort(nodes.begin(), nodes.end(), id_less); + } else { + label->sort(nodes); +@@ -2136,7 +2136,7 @@ namespace lemon { + RedNode n = nodes[i]; + if (label == 0) { + std::ostringstream os; +- os << _graph.id(static_cast(n)); ++ os << _graph.id(static_cast(n)); + _writer_bits::writeToken(*_os, os.str()); + *_os << '\t'; + _red_node_index.insert(std::make_pair(n, os.str())); +@@ -2185,8 +2185,8 @@ namespace lemon { + } + + if (label == 0) { +- IdMap id_map(_graph); +- _writer_bits::MapLess > id_less(id_map); ++ IdMap id_map(_graph); ++ _writer_bits::MapLess > id_less(id_map); + std::sort(nodes.begin(), nodes.end(), id_less); + } else { + label->sort(nodes); +@@ -2196,7 +2196,7 @@ namespace lemon { + BlueNode n = nodes[i]; + if (label == 0) { + std::ostringstream os; +- os << _graph.id(static_cast(n)); ++ os << _graph.id(static_cast(n)); + _writer_bits::writeToken(*_os, os.str()); + *_os << '\t'; + _blue_node_index.insert(std::make_pair(n, os.str())); diff --git a/src/lib/lemon/lemon/config.h b/src/lib/lemon/lemon/config.h new file mode 100644 index 0000000..4bd829d --- /dev/null +++ b/src/lib/lemon/lemon/config.h @@ -0,0 +1,13 @@ +#define LEMON_VERSION "1.3" +#define LEMON_HAVE_LONG_LONG 1 +#define LEMON_HAVE_LP 1 +//#define LEMON_HAVE_MIP 0 +//#define LEMON_HAVE_GLPK 0 +//#define LEMON_HAVE_CPLEX 0 +#define LEMON_HAVE_SOPLEX 1 +//#define LEMON_HAVE_CLP 0 +//#define LEMON_HAVE_CBC 0 +#define LEMON_DEFAULT_LP "SOPLEX" +//#define LEMON_DEFAULT_MIP "" +//#define LEMON_USE_PTHREAD 0 +//#define LEMON_USE_WIN32_THREADS 0 diff --git a/src/test/lemon/target.mk b/src/test/lemon/target.mk new file mode 100644 index 0000000..0704c07 --- /dev/null +++ b/src/test/lemon/target.mk @@ -0,0 +1,6 @@ +TARGET = test-lemon +LIBS = lemon stdcxx +LEMON = $(call select_from_ports,lemon)/src/lib/lemon/test +SRC_CC = graph_test.cc + +vpath graph_test.cc $(LEMON)