lemongraph 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +674 -0
- data/README.md +6 -0
- data/ext/lemon-1.3.1/AUTHORS +26 -0
- data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
- data/ext/lemon-1.3.1/INSTALL +167 -0
- data/ext/lemon-1.3.1/LICENSE +32 -0
- data/ext/lemon-1.3.1/NEWS +337 -0
- data/ext/lemon-1.3.1/README +50 -0
- data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
- data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
- data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
- data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
- data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
- data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
- data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
- data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
- data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
- data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
- data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
- data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
- data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
- data/ext/lemon-1.3.1/lemon/assert.h +214 -0
- data/ext/lemon-1.3.1/lemon/base.cc +37 -0
- data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
- data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
- data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
- data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
- data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
- data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
- data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
- data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
- data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
- data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
- data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
- data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
- data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
- data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
- data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
- data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
- data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
- data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
- data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
- data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
- data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
- data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
- data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
- data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
- data/ext/lemon-1.3.1/lemon/clp.h +164 -0
- data/ext/lemon-1.3.1/lemon/color.cc +44 -0
- data/ext/lemon-1.3.1/lemon/color.h +204 -0
- data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
- data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
- data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
- data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
- data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
- data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
- data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
- data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
- data/ext/lemon-1.3.1/lemon/core.h +2506 -0
- data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
- data/ext/lemon-1.3.1/lemon/counter.h +249 -0
- data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
- data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
- data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
- data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
- data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
- data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
- data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
- data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
- data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
- data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
- data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
- data/ext/lemon-1.3.1/lemon/error.h +276 -0
- data/ext/lemon-1.3.1/lemon/euler.h +287 -0
- data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
- data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
- data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
- data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
- data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
- data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
- data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
- data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
- data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
- data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
- data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
- data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
- data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
- data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
- data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
- data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
- data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
- data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
- data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
- data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
- data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
- data/ext/lemon-1.3.1/lemon/lp.h +95 -0
- data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
- data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
- data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
- data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
- data/ext/lemon-1.3.1/lemon/math.h +77 -0
- data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
- data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
- data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
- data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
- data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
- data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
- data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
- data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
- data/ext/lemon-1.3.1/lemon/path.h +1164 -0
- data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
- data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
- data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
- data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
- data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
- data/ext/lemon-1.3.1/lemon/random.cc +29 -0
- data/ext/lemon-1.3.1/lemon/random.h +1005 -0
- data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
- data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
- data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
- data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
- data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
- data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
- data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
- data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
- data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
- data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
- data/ext/lemongraph/arc_map.cc +1007 -0
- data/ext/lemongraph/digraph.cc +282 -0
- data/ext/lemongraph/digraph_arc.cc +153 -0
- data/ext/lemongraph/digraph_node.cc +277 -0
- data/ext/lemongraph/edge_map.cc +770 -0
- data/ext/lemongraph/extconf.rb +53 -0
- data/ext/lemongraph/graph.cc +351 -0
- data/ext/lemongraph/graph_arc.cc +95 -0
- data/ext/lemongraph/graph_edge.cc +153 -0
- data/ext/lemongraph/graph_item.cc +76 -0
- data/ext/lemongraph/graph_node.cc +321 -0
- data/ext/lemongraph/lemongraph.cc +260 -0
- data/ext/lemongraph/lemongraph.hh +295 -0
- data/ext/lemongraph/lemongraph.map +6 -0
- data/ext/lemongraph/lemongraph_export.hh +31 -0
- data/ext/lemongraph/node_map.cc +1011 -0
- data/lemongraph.gemspec +176 -0
- data/lib/lemongraph/graphviz.rb +240 -0
- data/lib/lemongraph/version.rb +4 -0
- data/lib/lemongraph.rb +21 -0
- data/samples/lemondeps.rb +38 -0
- metadata +202 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
dev = false
|
|
4
|
+
llvm = false
|
|
5
|
+
|
|
6
|
+
unless have_library('lemon') then
|
|
7
|
+
#abort "-----\nLEMON is missing. Please install LEMON (eg \'sudo apt install liblemon-dev\').\n-----"
|
|
8
|
+
ext_dir = File.absolute_path(File.join('..', '..'), __FILE__)
|
|
9
|
+
lemon_src_dir = File.join(ext_dir, 'lemon-1.3.1')
|
|
10
|
+
lemon_build_dir = File.join(lemon_src_dir, 'build')
|
|
11
|
+
lemon_install_dir = File.join(lemon_src_dir, 'install')
|
|
12
|
+
|
|
13
|
+
abort "-----\ncmake is missing. Please install cmake (eg \'sudo apt install cmake\').\n-----" unless find_executable('cmake')
|
|
14
|
+
|
|
15
|
+
unless File.exist? lemon_install_dir then
|
|
16
|
+
Dir.mkdir lemon_build_dir
|
|
17
|
+
|
|
18
|
+
Dir.chdir(lemon_build_dir) do
|
|
19
|
+
cmd = "cmake -DCMAKE_INSTALL_PREFIX='#{lemon_install_dir}' -DCMAKE_BUILD_TYPE=Release .."
|
|
20
|
+
message cmd + "\n"
|
|
21
|
+
abort("-----\n#{caller[0]}\nCannot cmake lemon-1.3.1.\n-----") unless system cmd
|
|
22
|
+
|
|
23
|
+
cmd = "make"
|
|
24
|
+
message cmd + "\n"
|
|
25
|
+
abort("-----\n#{caller[0]}\nCannot make lemon-1.3.1.\n-----") unless system cmd
|
|
26
|
+
|
|
27
|
+
cmd = "make install"
|
|
28
|
+
message cmd + "\n"
|
|
29
|
+
abort("-----\n#{caller[0]}\nCannot install lemon-1.3.1.\n-----") unless system cmd
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
append_cppflags "-I'#{File.join(lemon_install_dir, 'include')}'"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if llvm then
|
|
37
|
+
MakeMakefile::CONFIG['CC'] = 'clang'
|
|
38
|
+
MakeMakefile::CONFIG['CXX'] = 'clang++'
|
|
39
|
+
append_cppflags('-Wall -Wextra -Wdeprecated-declarations -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wmissing-noreturn -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable') if dev
|
|
40
|
+
$CPPFLAGS << ' -fdeclspec'
|
|
41
|
+
else
|
|
42
|
+
append_cppflags('-Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable') if dev
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
append_cppflags('-fvisibility=hidden')
|
|
46
|
+
|
|
47
|
+
append_ldflags('-Wl,--version-script=lemongraph.map')
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
create_makefile 'lemongraph/lemongraph'
|
|
51
|
+
|
|
52
|
+
File.write('Makefile', File.read('Makefile').sub(/^V = 0$/, 'V = 1')) if dev
|
|
53
|
+
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/* Copyright (C) 2022 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
|
|
2
|
+
*
|
|
3
|
+
* This file is part of LemonGraph. <https://gitlab.ensta-bretagne.fr/bollenth/lemongraph>
|
|
4
|
+
*
|
|
5
|
+
* LemonGraph is free software: you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License,
|
|
8
|
+
* or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* LemonGraph is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
* See the GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU General Public License
|
|
16
|
+
* along with LemonGraph. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#include "lemongraph.hh"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
VALUE c_Graph;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/* Document-class: LemonGraph::Graph
|
|
27
|
+
* Undirected graph.
|
|
28
|
+
*
|
|
29
|
+
* The undirected graphs fulfill the concept of directed graphs,
|
|
30
|
+
* since each edge can also be regarded as two oppositely directed arcs.
|
|
31
|
+
* Undirected graphs provide an {Edge} type for the undirected edges and an {Arc} type for the directed arcs.
|
|
32
|
+
*
|
|
33
|
+
* In LEMON, each undirected edge has an inherent orientation.
|
|
34
|
+
* Thus it can define if an arc is forward or backward oriented in an undirected graph with respect to this default oriantation of the represented edge.
|
|
35
|
+
* With the direction() and direct() functions the direction of an arc can be obtained and set, respectively.
|
|
36
|
+
*
|
|
37
|
+
* Only nodes and edges can be added to or removed from an undirected graph and the corresponding arcs are added or removed automatically.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
static void lemongraph_graph_free(void *p)
|
|
42
|
+
{
|
|
43
|
+
lemon::ListGraph *g = (lemon::ListGraph*)p;
|
|
44
|
+
delete g;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
static size_t lemongraph_graph_size(const void* p)
|
|
49
|
+
{
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const rb_data_type_t lemongraph_graph_type = {
|
|
55
|
+
.wrap_struct_name = "LemonGraph::Graph",
|
|
56
|
+
.function = {
|
|
57
|
+
.dmark = NULL,
|
|
58
|
+
.dfree = lemongraph_graph_free,
|
|
59
|
+
.dsize = lemongraph_graph_size,
|
|
60
|
+
},
|
|
61
|
+
.parent = NULL,
|
|
62
|
+
.data = NULL,
|
|
63
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
VALUE lemongraph_graph_alloc(VALUE klass)
|
|
68
|
+
{
|
|
69
|
+
lemon::ListGraph *g = new lemon::ListGraph();
|
|
70
|
+
return TypedData_Wrap_Struct(klass, &lemongraph_graph_type, g);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/* Method called by _dup_ and _clone_ methods.
|
|
75
|
+
* @return [self]
|
|
76
|
+
*/
|
|
77
|
+
VALUE lemongraph_graph_initialize_copy(VALUE self, VALUE orig)
|
|
78
|
+
{
|
|
79
|
+
|
|
80
|
+
rb_call_super(1, &orig);
|
|
81
|
+
lemon::ListGraph& from = lemongraph_graph_rb2ref(orig);
|
|
82
|
+
lemon::ListGraph& to = lemongraph_graph_rb2ref(self);
|
|
83
|
+
lemon::graphCopy(from, to).run();
|
|
84
|
+
return self;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/* Adds a new node to the graph
|
|
89
|
+
* @return [Node] the newly created node
|
|
90
|
+
*/
|
|
91
|
+
VALUE lemongraph_graph_add_node(VALUE self)
|
|
92
|
+
{
|
|
93
|
+
lemon::ListGraph::Node n = lemongraph_graph_rb2ref(self).addNode();
|
|
94
|
+
return lemongraph_make_unnode(n, self);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
void lemongraph_graph_raise_if_not_valid_node(const lemon::ListGraph& graph, VALUE rbgraph, VALUE node)
|
|
99
|
+
{
|
|
100
|
+
if (rb_class_of(node) != c_UnNode) {
|
|
101
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
|
|
102
|
+
rb_class_name(c_UnNode), rb_obj_classname(node));
|
|
103
|
+
}
|
|
104
|
+
if (rb_iv_get(node, "@graph") != rbgraph)
|
|
105
|
+
rb_raise(rb_eRuntimeError, "this node does not belong to the graph");
|
|
106
|
+
if (!graph.valid(lemongraph_rbunnode2unnode(node)))
|
|
107
|
+
rb_raise(rb_eRuntimeError, "node is not valid for the graph");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
/* Adds a new {Edge} to the graph with between nodes _u_ and _v_.
|
|
112
|
+
* @param u [Node]
|
|
113
|
+
* @param v [Node]
|
|
114
|
+
* @return [Edge] the newly created edge
|
|
115
|
+
*/
|
|
116
|
+
VALUE lemongraph_graph_add_edge(VALUE self, VALUE u, VALUE v)
|
|
117
|
+
{
|
|
118
|
+
lemon::ListGraph &g = lemongraph_graph_rb2ref(self);
|
|
119
|
+
lemongraph_graph_raise_if_not_valid_node(g, self, u);
|
|
120
|
+
lemongraph_graph_raise_if_not_valid_node(g, self, v);
|
|
121
|
+
lemon::ListGraph::Edge e = g.addEdge(
|
|
122
|
+
lemongraph_rbunnode2unnode(u),
|
|
123
|
+
lemongraph_rbunnode2unnode(v));
|
|
124
|
+
return lemongraph_make_unedge(e, self);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
/* Test if the given node edge or arc is valid, i.e. it is a real node/edge/arc of the graph.
|
|
129
|
+
* @param item [Node, Edge, Arc]
|
|
130
|
+
* @return [Boolean]
|
|
131
|
+
*/
|
|
132
|
+
VALUE lemongraph_graph_item_is_valid(VALUE self, VALUE item)
|
|
133
|
+
{
|
|
134
|
+
bool r = false;
|
|
135
|
+
VALUE klass = rb_class_of(item);
|
|
136
|
+
if (klass == c_UnNode) {
|
|
137
|
+
if (rb_iv_get(item, "@graph") == self)
|
|
138
|
+
r = lemongraph_graph_rb2ref(self).valid(lemongraph_rbunnode2unnode(item));
|
|
139
|
+
}
|
|
140
|
+
else if (klass == c_UnEdge) {
|
|
141
|
+
if (rb_iv_get(item, "@graph") == self)
|
|
142
|
+
r = lemongraph_graph_rb2ref(self).valid(lemongraph_rbunedge2unedge(item));
|
|
143
|
+
}
|
|
144
|
+
else if (klass == c_UnArc) {
|
|
145
|
+
if (rb_iv_get(item, "@graph") == self)
|
|
146
|
+
r = lemongraph_graph_rb2ref(self).valid(lemongraph_rbunarc2unarc(item));
|
|
147
|
+
}
|
|
148
|
+
else
|
|
149
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", a %" PRIsVALUE " or a %" PRIsVALUE ", not a %s",
|
|
150
|
+
rb_class_name(c_UnNode), rb_class_name(c_UnEdge), rb_class_name(c_UnArc), rb_obj_classname(item));
|
|
151
|
+
return r ? Qtrue : Qfalse;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
/* Erases the node or edge from the graph.
|
|
156
|
+
* @return [self]
|
|
157
|
+
* @overload erase(node)
|
|
158
|
+
* Erases the given node along with its incidents edges from the graph.
|
|
159
|
+
* @param node [Node] the node to erase
|
|
160
|
+
* @overload erase(edge)
|
|
161
|
+
* Erases the given edge from the graph.
|
|
162
|
+
* @param arc [Edge] the edge to erase
|
|
163
|
+
*/
|
|
164
|
+
VALUE lemongraph_graph_erase_item(VALUE self, VALUE item)
|
|
165
|
+
{
|
|
166
|
+
VALUE klass = rb_class_of(item);
|
|
167
|
+
if (klass == c_UnNode) {
|
|
168
|
+
if (rb_iv_get(item, "@graph") != self)
|
|
169
|
+
rb_raise(rb_eRuntimeError, "this node does not belong to the graph");
|
|
170
|
+
lemongraph_graph_rb2ref(self).erase(lemongraph_rbunnode2unnode(item));
|
|
171
|
+
}
|
|
172
|
+
else if (klass == c_UnEdge) {
|
|
173
|
+
if (rb_iv_get(item, "@graph") != self)
|
|
174
|
+
rb_raise(rb_eRuntimeError, "this edge does not belong to the graph");
|
|
175
|
+
lemongraph_graph_rb2ref(self).erase(lemongraph_rbunedge2unedge(item));
|
|
176
|
+
}
|
|
177
|
+
else if (klass == c_UnArc)
|
|
178
|
+
rb_raise(rb_eTypeError, "cannot erase a %" PRIsVALUE " from a %" PRIsVALUE, rb_class_name(c_UnArc), rb_class_name(c_Graph));
|
|
179
|
+
else
|
|
180
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE " or a %" PRIsVALUE ", not a %s",
|
|
181
|
+
rb_class_name(c_UnNode), rb_class_name(c_UnEdge), rb_obj_classname(item));
|
|
182
|
+
return self;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
/* Erases all nodes and edges from the graph
|
|
187
|
+
* @return [self]
|
|
188
|
+
*/
|
|
189
|
+
VALUE lemongraph_graph_clear(VALUE self)
|
|
190
|
+
{
|
|
191
|
+
lemongraph_graph_rb2ref(self).clear();
|
|
192
|
+
return self;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
/* Number of nodes in the graph.
|
|
197
|
+
* @return [Integer]
|
|
198
|
+
*/
|
|
199
|
+
VALUE lemongraph_graph_nb_nodes(VALUE self)
|
|
200
|
+
{
|
|
201
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
202
|
+
return INT2NUM(lemon::countNodes(g));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
/* Returns an array containing all the nodes of the graph.
|
|
207
|
+
* @return [Array<Node>]
|
|
208
|
+
*/
|
|
209
|
+
VALUE lemongraph_graph_nodes(VALUE self)
|
|
210
|
+
{
|
|
211
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
212
|
+
VALUE a = rb_ary_new_capa(lemon::countNodes(g));
|
|
213
|
+
for (lemon::ListGraph::NodeIt n(g); n != lemon::INVALID; ++n)
|
|
214
|
+
rb_ary_push(a, lemongraph_make_unnode(n, self));
|
|
215
|
+
return a;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
static VALUE lemongraph_graph_nodeenum_nbnodes(VALUE obj, VALUE args, VALUE eobj)
|
|
220
|
+
{
|
|
221
|
+
(void)args;
|
|
222
|
+
(void)eobj;
|
|
223
|
+
return lemongraph_graph_nb_nodes(obj);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
/* Calls the block, if given, once for each {Node} in the graph.
|
|
228
|
+
* The nodes are passed as parameters to the block.
|
|
229
|
+
*
|
|
230
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
231
|
+
* @return [self, Enumerator]
|
|
232
|
+
* @overload each_node
|
|
233
|
+
* @yieldparam node [Node]
|
|
234
|
+
* @return [self]
|
|
235
|
+
* @overload each_node
|
|
236
|
+
* @return [Enumerator]
|
|
237
|
+
*/
|
|
238
|
+
VALUE lemongraph_graph_each_node(VALUE self)
|
|
239
|
+
{
|
|
240
|
+
RETURN_SIZED_ENUMERATOR(self, 0, 0, lemongraph_graph_nodeenum_nbnodes);
|
|
241
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
242
|
+
for (lemon::ListGraph::NodeIt n(g); n != lemon::INVALID; ++n)
|
|
243
|
+
rb_yield(lemongraph_make_unnode(n, self));
|
|
244
|
+
return self;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
/* Number of edges in the graph.
|
|
249
|
+
* @return [Integer]
|
|
250
|
+
*/
|
|
251
|
+
VALUE lemongraph_graph_nb_edges(VALUE self)
|
|
252
|
+
{
|
|
253
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
254
|
+
return INT2NUM(lemon::countEdges(g));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
/* Returns an array containing all the edges of the graph.
|
|
259
|
+
* @return [Array<Edge>]
|
|
260
|
+
*/
|
|
261
|
+
VALUE lemongraph_graph_edges(VALUE self)
|
|
262
|
+
{
|
|
263
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
264
|
+
VALUE a = rb_ary_new_capa(lemon::countEdges(g));
|
|
265
|
+
for (lemon::ListGraph::EdgeIt e(g); e != lemon::INVALID; ++e)
|
|
266
|
+
rb_ary_push(a, lemongraph_make_unedge(e, self));
|
|
267
|
+
return a;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
static VALUE lemongraph_graph_edgeenum_nbedges(VALUE obj, VALUE args, VALUE eobj)
|
|
272
|
+
{
|
|
273
|
+
(void)args;
|
|
274
|
+
(void)eobj;
|
|
275
|
+
return lemongraph_graph_nb_edges(obj);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
/* Calls the block, if given, once for each {Edge} in the graph.
|
|
280
|
+
* The edges are passed as parameters to the block.
|
|
281
|
+
*
|
|
282
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
283
|
+
* @return [self, Enumerator]
|
|
284
|
+
* @overload each_edge
|
|
285
|
+
* @yieldparam edge [Edge]
|
|
286
|
+
* @return [self]
|
|
287
|
+
* @overload each_edge
|
|
288
|
+
* @return [Enumerator]
|
|
289
|
+
*/
|
|
290
|
+
VALUE lemongraph_graph_each_edge(VALUE self)
|
|
291
|
+
{
|
|
292
|
+
RETURN_SIZED_ENUMERATOR(self, 0, 0, lemongraph_graph_edgeenum_nbedges);
|
|
293
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
294
|
+
for (lemon::ListGraph::EdgeIt n(g); n != lemon::INVALID; ++n)
|
|
295
|
+
rb_yield(lemongraph_make_unedge(n, self));
|
|
296
|
+
return self;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
/* Number of arcs in the graph.
|
|
301
|
+
* @return [Integer]
|
|
302
|
+
*/
|
|
303
|
+
VALUE lemongraph_graph_nb_arcs(VALUE self)
|
|
304
|
+
{
|
|
305
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
306
|
+
return INT2NUM(lemon::countArcs(g));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
/* Returns an array containing all the arcs of the graph.
|
|
311
|
+
* @return [Array<Arc>]
|
|
312
|
+
*/
|
|
313
|
+
VALUE lemongraph_graph_arcs(VALUE self)
|
|
314
|
+
{
|
|
315
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
316
|
+
VALUE ar = rb_ary_new_capa(lemon::countArcs(g));
|
|
317
|
+
for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a)
|
|
318
|
+
rb_ary_push(ar, lemongraph_make_unarc(a, self));
|
|
319
|
+
return ar;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
static VALUE lemongraph_graph_arcenum_nbarcs(VALUE obj, VALUE args, VALUE eobj)
|
|
324
|
+
{
|
|
325
|
+
(void)args;
|
|
326
|
+
(void)eobj;
|
|
327
|
+
return lemongraph_graph_nb_arcs(obj);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
/* Calls the block, if given, once for each {Arc} in the graph.
|
|
332
|
+
* The arcs are passed as parameters to the block.
|
|
333
|
+
*
|
|
334
|
+
* Returns _self_, or, if no block is given, an Enumerator is returned.
|
|
335
|
+
* @return [self, Enumerator]
|
|
336
|
+
* @overload each_arc
|
|
337
|
+
* @yieldparam arc [Arc]
|
|
338
|
+
* @return [self]
|
|
339
|
+
* @overload each_arc
|
|
340
|
+
* @return [Enumerator]
|
|
341
|
+
*/
|
|
342
|
+
VALUE lemongraph_graph_each_arc(VALUE self)
|
|
343
|
+
{
|
|
344
|
+
RETURN_SIZED_ENUMERATOR(self, 0, 0, lemongraph_graph_arcenum_nbarcs);
|
|
345
|
+
lemon::ListGraph& g = lemongraph_graph_rb2ref(self);
|
|
346
|
+
for (lemon::ListGraph::ArcIt a(g); a != lemon::INVALID; ++a)
|
|
347
|
+
rb_yield(lemongraph_make_unarc(a, self));
|
|
348
|
+
return self;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/* Copyright (C) 2022 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
|
|
2
|
+
*
|
|
3
|
+
* This file is part of LemonGraph. <https://gitlab.ensta-bretagne.fr/bollenth/lemongraph>
|
|
4
|
+
*
|
|
5
|
+
* LemonGraph is free software: you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License,
|
|
8
|
+
* or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* LemonGraph is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
* See the GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU General Public License
|
|
16
|
+
* along with LemonGraph. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#include "lemongraph.hh"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
VALUE c_UnArc;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/* Document-class: LemonGraph::Graph::Arc
|
|
27
|
+
* Arc of a {Graph}, from a source {Node} to a target {Node}.
|
|
28
|
+
* Each {Edge} of a {Graph} is composed of two arcs in opposite direction.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
VALUE lemongraph_make_unarc(const lemon::ListGraph::Arc& arc, VALUE graph)
|
|
33
|
+
{
|
|
34
|
+
if (arc == lemon::INVALID)
|
|
35
|
+
return Qnil;
|
|
36
|
+
VALUE args[2] = {INT2NUM(lemon::ListGraph::id(arc)), graph};
|
|
37
|
+
return rb_class_new_instance(2, args, c_UnArc);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/* @!visibility private
|
|
42
|
+
*/
|
|
43
|
+
VALUE lemongraph_unarc_initialize(VALUE self, VALUE id, VALUE graph)
|
|
44
|
+
{
|
|
45
|
+
if (rb_obj_is_kind_of(graph, c_Graph) != Qtrue) {
|
|
46
|
+
rb_raise(rb_eRuntimeError, "expecting a %" PRIsVALUE " as graph, not a %s",
|
|
47
|
+
rb_class_name(c_Graph), rb_obj_classname(graph));
|
|
48
|
+
}
|
|
49
|
+
VALUE args[2] = {id, graph};
|
|
50
|
+
return rb_call_super(2, args);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/* Test if the arc is valid, i.e. it is a real arc of the graph it belons to.
|
|
55
|
+
* @return [Boolean]
|
|
56
|
+
*/
|
|
57
|
+
VALUE lemongraph_unarc_is_valid(VALUE self)
|
|
58
|
+
{
|
|
59
|
+
return lemongraph_graph_rb2ref(rb_iv_get(self, "@graph")).valid(lemongraph_rbunarc2unarc(self)) ? Qtrue : Qfalse;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/* Returns the source node of the arc.
|
|
64
|
+
* @return [Node]
|
|
65
|
+
*/
|
|
66
|
+
VALUE lemongraph_unarc_source(VALUE self)
|
|
67
|
+
{
|
|
68
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
69
|
+
lemon::ListGraph::Node n = lemongraph_graph_rb2ref(g).source(lemongraph_rbunarc2unarc(self));
|
|
70
|
+
return lemongraph_make_unnode(n, g);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/* Returns the target node of the arc.
|
|
75
|
+
* @return [Node]
|
|
76
|
+
*/
|
|
77
|
+
VALUE lemongraph_unarc_target(VALUE self)
|
|
78
|
+
{
|
|
79
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
80
|
+
lemon::ListGraph::Node n = lemongraph_graph_rb2ref(g).target(lemongraph_rbunarc2unarc(self));
|
|
81
|
+
return lemongraph_make_unnode(n, g);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/* Returns the arc corresponding to the same edge as _self_ but in the opposite orientation.
|
|
86
|
+
* @return [Arc]
|
|
87
|
+
*/
|
|
88
|
+
VALUE lemongraph_unarc_opposite(VALUE self)
|
|
89
|
+
{
|
|
90
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
91
|
+
lemon::ListGraph::Arc a = lemongraph_graph_rb2ref(g).oppositeArc(lemongraph_rbunarc2unarc(self));
|
|
92
|
+
return lemongraph_make_unarc(a, g);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* Copyright (C) 2022 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
|
|
2
|
+
*
|
|
3
|
+
* This file is part of LemonGraph. <https://gitlab.ensta-bretagne.fr/bollenth/lemongraph>
|
|
4
|
+
*
|
|
5
|
+
* LemonGraph is free software: you can redistribute it and/or modify it
|
|
6
|
+
* under the terms of the GNU General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License,
|
|
8
|
+
* or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* LemonGraph is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
* See the GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU General Public License
|
|
16
|
+
* along with LemonGraph. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#include "lemongraph.hh"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
VALUE c_UnEdge;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/* Document-class: LemonGraph::Graph::Edge
|
|
27
|
+
* Edge of a {Graph}, between two {Node}s _u_ and _v_.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
VALUE lemongraph_make_unedge(const lemon::ListGraph::Edge& edge, VALUE graph)
|
|
32
|
+
{
|
|
33
|
+
if (edge == lemon::INVALID)
|
|
34
|
+
return Qnil;
|
|
35
|
+
VALUE args[2] = {INT2NUM(lemon::ListGraph::id(edge)), graph};
|
|
36
|
+
return rb_class_new_instance(2, args, c_UnEdge);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/* @!visibility private
|
|
41
|
+
*/
|
|
42
|
+
VALUE lemongraph_unedge_initialize(VALUE self, VALUE id, VALUE graph)
|
|
43
|
+
{
|
|
44
|
+
if (rb_obj_is_kind_of(graph, c_Graph) != Qtrue) {
|
|
45
|
+
rb_raise(rb_eRuntimeError, "expecting a %" PRIsVALUE " as graph, not a %s",
|
|
46
|
+
rb_class_name(c_Graph), rb_obj_classname(graph));
|
|
47
|
+
}
|
|
48
|
+
VALUE args[2] = {id, graph};
|
|
49
|
+
return rb_call_super(2, args);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/* Erases the edge from the graph it belongs to.
|
|
54
|
+
* @return [self]
|
|
55
|
+
*/
|
|
56
|
+
VALUE lemongraph_unedge_erase(VALUE self)
|
|
57
|
+
{
|
|
58
|
+
lemongraph_graph_rb2ref(rb_iv_get(self, "@graph")).erase(lemongraph_rbunedge2unedge(self));
|
|
59
|
+
return self;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/* Test if the edge is valid, i.e. it is a real edge of the graph it belons to.
|
|
64
|
+
* @return [Boolean]
|
|
65
|
+
*/
|
|
66
|
+
VALUE lemongraph_unedge_is_valid(VALUE self)
|
|
67
|
+
{
|
|
68
|
+
return lemongraph_graph_rb2ref(rb_iv_get(self, "@graph")).valid(lemongraph_rbunedge2unedge(self)) ? Qtrue : Qfalse;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/* Returns the first node of the edge.
|
|
73
|
+
* @return [Node]
|
|
74
|
+
*/
|
|
75
|
+
VALUE lemongraph_unedge_u(VALUE self)
|
|
76
|
+
{
|
|
77
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
78
|
+
lemon::ListGraph::Node n = lemongraph_graph_rb2ref(g).u(lemongraph_rbunedge2unedge(self));
|
|
79
|
+
return lemongraph_make_unnode(n, g);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/* Returns the second node of the edge.
|
|
84
|
+
* @return [Node]
|
|
85
|
+
*/
|
|
86
|
+
VALUE lemongraph_unedge_v(VALUE self)
|
|
87
|
+
{
|
|
88
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
89
|
+
lemon::ListGraph::Node n = lemongraph_graph_rb2ref(g).v(lemongraph_rbunedge2unedge(self));
|
|
90
|
+
return lemongraph_make_unnode(n, g);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/* Changes the first node of the edge to _node_.
|
|
95
|
+
* @param node [Node] the edge's new _u_ node
|
|
96
|
+
* @return [node]
|
|
97
|
+
*/
|
|
98
|
+
VALUE lemongraph_unedge_change_u(VALUE self, VALUE node)
|
|
99
|
+
{
|
|
100
|
+
if (rb_class_of(node) != c_UnNode) {
|
|
101
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
|
|
102
|
+
rb_class_name(c_UnNode), rb_obj_classname(node));
|
|
103
|
+
}
|
|
104
|
+
VALUE graph = rb_iv_get(self, "@graph");
|
|
105
|
+
if (rb_iv_get(node, "@graph") != graph)
|
|
106
|
+
rb_raise(rb_eRuntimeError, "edge and node not from the sams graph");
|
|
107
|
+
lemongraph_graph_rb2ref(graph).changeU(lemongraph_rbunedge2unedge(self), lemongraph_rbunnode2unnode(node));
|
|
108
|
+
return self;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/* Changes the second node of the edge to _node_.
|
|
113
|
+
* @param node [Node] the edge's new _v_ node
|
|
114
|
+
* @return [node]
|
|
115
|
+
*/
|
|
116
|
+
VALUE lemongraph_unedge_change_v(VALUE self, VALUE node)
|
|
117
|
+
{
|
|
118
|
+
if (rb_class_of(node) != c_UnNode) {
|
|
119
|
+
rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
|
|
120
|
+
rb_class_name(c_UnNode), rb_obj_classname(node));
|
|
121
|
+
}
|
|
122
|
+
VALUE graph = rb_iv_get(self, "@graph");
|
|
123
|
+
if (rb_iv_get(node, "@graph") != graph)
|
|
124
|
+
rb_raise(rb_eRuntimeError, "edge and node not from the sams graph");
|
|
125
|
+
lemongraph_graph_rb2ref(graph).changeV(lemongraph_rbunedge2unedge(self), lemongraph_rbunnode2unnode(node));
|
|
126
|
+
return self;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/* Returns the {Arc} that represents the edge and whose direction is
|
|
131
|
+
* the same as the inherent orientation of _self_ (from _u_ to _v_).
|
|
132
|
+
* @return [Arc]
|
|
133
|
+
*/
|
|
134
|
+
VALUE lemongraph_unedge_arc1(VALUE self)
|
|
135
|
+
{
|
|
136
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
137
|
+
lemon::ListGraph::Arc a = lemongraph_graph_rb2ref(g).direct(lemongraph_rbunedge2unedge(self), true);
|
|
138
|
+
return lemongraph_make_unarc(a, g);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/* Returns the {Arc} that represents the edge and whose direction is
|
|
143
|
+
* the opposite as the inherent orientation of _self_ (so, from _v_ to _u_).
|
|
144
|
+
* @return [Arc]
|
|
145
|
+
*/
|
|
146
|
+
VALUE lemongraph_unedge_arc2(VALUE self)
|
|
147
|
+
{
|
|
148
|
+
VALUE g = rb_iv_get(self, "@graph");
|
|
149
|
+
lemon::ListGraph::Arc a = lemongraph_graph_rb2ref(g).direct(lemongraph_rbunedge2unedge(self), false);
|
|
150
|
+
return lemongraph_make_unarc(a, g);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|