sábado, 5 de febrero de 2011

Lemon Graph Library (LGL) instalation - logbook

In a previous post I wrote about a library dedicated to work with graph. It is called Lemon Graph Library (LGL). The idea is eventually integrate LGL with R via Rcpp. So it seems that I first need to install the LGL.

Why to install LGL instead of simply use its .cc and .h files? Well, I look inside the .cc and .h files and the inclusion of other .h headers goes like this:

#include<lemon/tolerance.h>
#include<lemon/core.h>

(I pick this lines from ../lemon/base.cc). So it seems that in order that the inclusion of the headers can be donde, then the library needs to be installed.

So, in this post I will write the logbook about the installation of LGL.
I will follow this instructions.

I had downloaded lemon-1.2.1.tar.gz and untared it. Now I'm in a ubuntu console inside the lemon-1.2.1 directory. I then proceed:

../lemon-1.2.1$ ./configure

and seems to work. Now I proceed:

../lemon-1.2.1$ make

and also seems to work. Now I proceed:

../lemon-1.2.1$ make check

and I get this:

test/test_tools_fail.cc:23: error: Don't panic. Failing is the right behaviour here.
/bin/bash: line 5:  7977 Aborted                 ${dir}$tst
XFAIL: test/test_tools_fail
PASS: test/test_tools_pass
u: 0.07s, s: 0.03s, cu: 0s, cs: 0s, real: 0.100001s (77313 time queries)
u: 3.27826e-09s, s: 0s, cu: 0s, cs: 0s, real: 3.12811e-09s (33554432 tests)
Total: u: 0.11s, s: 0s, cu: 0s, cs: 0s, real: 0.104962s
u: 0.000859375s, s: 0.0003125s, cu: 0s, cs: 0s, real: 0.00124676s (128 tests)
Total: u: 0.11s, s: 0.04s, cu: 0s, cs: 0s, real: 0.159585s
PASS: test/time_measure_test
PASS: test/unionfind_test
=====================================================
All 36 tests behaved as expected (1 expected failure)
=====================================================

It seems that there is a failure, but this failure is intentional. So, it also seems to work. Now I proceed:

../lemon-1.2.1$ sudo make install

and it seems to work (note that I used sudo (root permissions), so I installed the library in the standard directory) and I get this (Note that in the blog the vertical pipe character may not appear. I put all this here because I want to have a register about what happens):

test -z "/usr/local/lib" || /bin/mkdir -p "/usr/local/lib"
 /bin/bash ./libtool   --mode=install /usr/bin/install -c   lemon/libemon.la '/usr/local/lib'
libtool: install: /usr/bin/install -c lemon/.libs/libemon.lai /usr/local/lib/libemon.la
libtool: install: /usr/bin/install -c lemon/.libs/libemon.a /usr/local/lib/libemon.a
libtool: install: chmod 644 /usr/local/lib/libemon.a
libtool: install: ranlib /usr/local/lib/libemon.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
  /bin/bash ./libtool   --mode=install /usr/bin/install -c tools/dimacs-solver tools/dimacs-to-lgf tools/lgf-gen '/usr/local/bin'
libtool: install: /usr/bin/install -c tools/dimacs-solver /usr/local/bin/dimacs-solver
libtool: install: /usr/bin/install -c tools/dimacs-to-lgf /usr/local/bin/dimacs-to-lgf
libtool: install: /usr/bin/install -c tools/lgf-gen /usr/local/bin/lgf-gen
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
 /usr/bin/install -c tools/lemon-0.x-to-1.x.sh '/usr/local/bin'
test -z "/usr/local/include/lemon/bits" || /bin/mkdir -p "/usr/local/include/lemon/bits"
 /usr/bin/install -c -m 644 lemon/bits/alteration_notifier.h lemon/bits/array_map.h lemon/bits/bezier.h lemon/bits/default_map.h lemon/bits/edge_set_extender.h lemon/bits/enable_if.h lemon/bits/graph_adaptor_extender.h lemon/bits/graph_extender.h lemon/bits/map_extender.h lemon/bits/path_dump.h lemon/bits/solver_bits.h lemon/bits/traits.h lemon/bits/variant.h lemon/bits/vector_map.h '/usr/local/include/lemon/bits'
test -z "/usr/local/include/lemon/concepts" || /bin/mkdir -p "/usr/local/include/lemon/concepts"
 /usr/bin/install -c -m 644 lemon/concepts/digraph.h lemon/concepts/graph.h lemon/concepts/graph_components.h lemon/concepts/heap.h lemon/concepts/maps.h lemon/concepts/path.h '/usr/local/include/lemon/concepts'
test -z "/usr/local/include/lemon" || /bin/mkdir -p "/usr/local/include/lemon"
 /usr/bin/install -c -m 644 lemon/adaptors.h lemon/arg_parser.h lemon/assert.h lemon/bellman_ford.h lemon/bfs.h lemon/bin_heap.h lemon/binomial_heap.h lemon/bucket_heap.h lemon/capacity_scaling.h lemon/cbc.h lemon/circulation.h lemon/clp.h lemon/color.h lemon/concept_check.h lemon/connectivity.h lemon/core.h lemon/cost_scaling.h lemon/counter.h lemon/cplex.h lemon/cycle_canceling.h lemon/dfs.h lemon/dheap.h lemon/dijkstra.h lemon/dim2.h lemon/dimacs.h lemon/edge_set.h lemon/elevator.h lemon/error.h lemon/euler.h lemon/fib_heap.h lemon/fractional_matching.h lemon/full_graph.h lemon/glpk.h lemon/gomory_hu.h lemon/graph_to_eps.h lemon/grid_graph.h lemon/hartmann_orlin_mmc.h lemon/howard_mmc.h lemon/hypercube_graph.h lemon/karp_mmc.h '/usr/local/include/lemon'
 /usr/bin/install -c -m 644 lemon/kruskal.h lemon/hao_orlin.h lemon/lgf_reader.h lemon/lgf_writer.h lemon/list_graph.h lemon/lp.h lemon/lp_base.h lemon/lp_skeleton.h lemon/maps.h lemon/matching.h lemon/math.h lemon/min_cost_arborescence.h lemon/nauty_reader.h lemon/network_simplex.h lemon/pairing_heap.h lemon/path.h lemon/planarity.h lemon/preflow.h lemon/quad_heap.h lemon/radix_heap.h lemon/radix_sort.h lemon/random.h lemon/smart_graph.h lemon/soplex.h lemon/static_graph.h lemon/suurballe.h lemon/time_measure.h lemon/tolerance.h lemon/unionfind.h lemon/bits/windows.h '/usr/local/include/lemon'
test -z "/usr/local/include/lemon" || /bin/mkdir -p "/usr/local/include/lemon"
 /usr/bin/install -c -m 644 lemon/config.h '/usr/local/include/lemon'
test -z "/usr/local/lib/pkgconfig" || /bin/mkdir -p "/usr/local/lib/pkgconfig"
 /usr/bin/install -c -m 644 lemon/lemon.pc '/usr/local/lib/pkgconfig'

Now is time to make a simple test to see if I can use the library (for the moment in the standard way, not including it in R). I will try what is written here which says:

$g++ -O2 mycode.cc -lemon

But for that, I need a mycode.cc example, so I will try this one (obtained from here):

#include <iostream>
#include <lemon/list_graph.h>

using namespace lemon;
using namespace std;

int main()
{
  ListDigraph g;

  ListDigraph::Node u = g.addNode();
  ListDigraph::Node v = g.addNode();
  ListDigraph::Arc  a = g.addArc(u, v);

  cout << "Hello World! This is LEMON library here." << endl;
  cout << "We have a directed graph with " << countNodes(g) << " nodes "
       << "and " << countArcs(g) << " arc." << endl;

  return 0;
}

It works as can be seen from what I had obtained:

$./a.out
Hello World! This is LEMON library here.
We have a directed graph with 2 nodes and 1 arc.

Now I have to try to integrate Lemon to R via Rcpp. So I write a file called myexample_inline.R with this content:

 inc <- '
        #include <lemon/list_graph.h>
        using namespace lemon ;
        '
 
 src <- '
        int xx = Rcpp::as<int>(x);

        int res = xx + 1;

        ListDigraph g;

        ListDigraph::Node u = g.addNode();
        ListDigraph::Node v = g.addNode();
        ListDigraph::Arc  a = g.addArc(u, v);

        int i = countNodes(g);
        int j = countArcs(g);

        Rprintf("num nodes is %d , and num edges is %d \\n",i,j);

        return Rcpp::wrap(res);
        '

 fun <- cxxfunction( signature(x="numeric"), body=src,include=inc, plugin="Rcpp")

Then I run R from a ubuntu terminal and in the R console I obtain:


> library("inline")
> library("Rcpp")
> source("myexample_inline.R")
> fun(1)
num nodes is 2 , and num edges is 1 
[1] 2

So it works !!!

TODO: What if I want to construct a package that uses LGL. How I do that? The right thing is that the installation of a R package can not depend on the installation of another non R package as LGL. So this is something that I need to explore.

TODO: Now I have a question. In the example the C++ function is "inlined" in R. So, if I want to call that function from other C++ function: How I do it? And if it is possible: It is (in terms of speed) convenient?
Maybe "inlining" is not the best choice. What other options do I have? Maybe this (and this) may be helpful.
Also I open this question in http://stackoverflow.com/, so maybe I get some answer from there.
This is the rcpp-development list which I have subscribed to.

Salut !