igraph_wrapper 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.
@@ -0,0 +1,88 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+ require 'find'
4
+
5
+ extension_name = 'IgraphWrapper/IgraphWrapper'
6
+ dir_config(extension_name)
7
+
8
+ parts = RUBY_DESCRIPTION.split(' ')
9
+ type = parts[0]
10
+ type = type[4..-1] if type.start_with?('tcs-')
11
+ type = 'ree' if 'ruby' == type && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
12
+ is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
13
+ is_linux = RbConfig::CONFIG['host_os'] =~ /(linux)/
14
+ is_darwin = RbConfig::CONFIG['host_os'] =~ /(darwin??)/
15
+ platform = RUBY_PLATFORM
16
+ version = RUBY_VERSION.split('.')
17
+
18
+
19
+ if is_darwin
20
+ puts "DEFINE Darwin"
21
+ $defs.push("-DDarwin")
22
+ else
23
+ puts "Unknown platform"
24
+ $defs.push("-DUnknownPlatform")
25
+ end
26
+ puts ">>>>> Creating Makefile for #{type} version #{RUBY_VERSION} on #{platform} (#{RbConfig::CONFIG['host_os']}) <<<<<"
27
+
28
+
29
+ puts "#{CONFIG["dldflags"]}"
30
+ CONFIG["DLDFLAGS"].gsub!(/-multiply_definedsuppress/, '')
31
+ $DLDFLAGS = CONFIG["DLDFLAGS"]
32
+ puts "#{CONFIG["DLDFLAGS"]}, #{$DLDFLAGS}"
33
+
34
+ puts CONFIG['CPPOUTFILE']
35
+
36
+ CONFIG["CFLAGS"] = '-O2 -Wall -pthread -fmessage-length=0 -fPIC -std=c++0x'
37
+
38
+ sep = File::PATH_SEPARATOR
39
+ is_igraph = true
40
+ if is_darwin
41
+ search_path = "/usr/local/Cellar/igraph/0.7.0/include/igraph"
42
+ search_file = "/igraph.h"
43
+ puts "Looking for igraph.h in "+search_path+"/*"
44
+ file_exist = nil
45
+ if File.exist?(search_path)
46
+ Find.find(search_path) do |path|
47
+ if (FileTest.directory?(path))
48
+ puts path+search_file
49
+ temp_name = (path).gsub(/\/usr\/local\/Cellar\/igraph.h\//,'')
50
+ count = temp_name.count('/')
51
+ if ((count == 0) && (File.exist?(path+search_file)))
52
+ file_exist = "-I#{path}"
53
+ break
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ if(is_igraph && file_exist != nil)
61
+ $INCFLAGS << " " << file_exist.quote
62
+ puts "found"
63
+ else
64
+ puts "not found"
65
+ is_igraph = false
66
+ end
67
+
68
+ path = "/usr/lib:/usr/local/lib/"
69
+ puts "Looking for igraph (function main) in "+path
70
+ if(is_igraph && find_library("igraph",nil,path))
71
+ puts "found"
72
+ else
73
+ puts "not found"
74
+ is_igraph = false
75
+ end
76
+ else
77
+ is_igraph = false;
78
+ end
79
+
80
+
81
+ if(is_igraph)
82
+ puts "*** With IGRAPH_MODULE ***"
83
+ $defs.push("-DIGRAPH_MODULE")
84
+ end
85
+
86
+ #swig -ruby -o IgraphWrapper.cpp -c++ ../../src/IgraphWrapper.i
87
+
88
+ create_makefile (extension_name)
@@ -0,0 +1,96 @@
1
+ //
2
+ // myGraph.cpp
3
+ //
4
+ //
5
+ // Created by Mathieu Bouchard on 2014-06-06.
6
+ //
7
+ //
8
+
9
+ #include "igraph_wrap.h"
10
+
11
+ vector<vector<double> > SolveAllPairsShortestPath(vector<vector<size_t> > pairs)
12
+ {
13
+ int n = 0;
14
+ map<size_t, size_t> id2zid;
15
+ vector<size_t> zid2id;
16
+
17
+ size_t* _pairs = new size_t[2*pairs.size()];
18
+
19
+ for(size_t i = 0; i < pairs.size(); ++i)
20
+ {
21
+ if(id2zid.count(pairs[i][0]) == 0)
22
+ {
23
+ id2zid[pairs[i][0]] = n;
24
+ zid2id.push_back(pairs[i][0]);
25
+ ++n;
26
+ }
27
+ if(id2zid.count(pairs[i][1]) == 0)
28
+ {
29
+ id2zid[pairs[i][1]] = n;
30
+ zid2id.push_back(pairs[i][1]);
31
+ ++n;
32
+ }
33
+ }
34
+
35
+ char* _error = NULL;
36
+ void* graph_lib = NULL;
37
+
38
+ dlerror();
39
+
40
+
41
+ for(size_t i = 0; i < pairs.size(); ++i)
42
+ {
43
+ _pairs[i*2] = id2zid[pairs[i][0]];
44
+ _pairs[i*2+1] = id2zid[pairs[i][1]];
45
+ }
46
+
47
+ graph_lib = dlopen("/usr/local/lib/libigraphwrap.dylib", RTLD_LAZY);
48
+ if(graph_lib == NULL)
49
+ {
50
+ if ((_error = dlerror()) != NULL)
51
+ {
52
+ printf("Cannot load function %s\n", _error);
53
+ }
54
+ }
55
+
56
+ double* (*allsp)(size_t*, size_t, size_t);
57
+ *(void **) (&allsp) = dlsym(graph_lib, "SolveAllPairsShortestPath");
58
+
59
+ if ((_error = dlerror()) != NULL) {
60
+ fprintf(stderr, "%s\n", _error);
61
+ exit(EXIT_FAILURE);
62
+ }
63
+
64
+
65
+ double* _out = (*allsp)(_pairs, pairs.size(), zid2id.size());
66
+
67
+ vector<vector<double> > out(n+1);
68
+ vector<double> temp(n,0.0);
69
+
70
+
71
+ for(size_t i = 0; i < n; ++i)
72
+ {
73
+ out[i] = temp;
74
+ //out.push_back(temp);
75
+ for(size_t j = 0; j < n; ++j)
76
+ {
77
+ //printf("%ld, %ld = %f ", i, j, _out[i*n+j]);
78
+ out[i][j] = _out[i*n+j];
79
+ //out.back().push_back(n);
80
+ }
81
+ }
82
+ out[n] = temp;
83
+ for(size_t i = 0; i < n; ++i)
84
+ out[n][i] = zid2id[i];
85
+
86
+ printf("Cleaning stuff\n");
87
+
88
+ delete[] _out;
89
+ delete[] _pairs;
90
+
91
+ dlclose(graph_lib);
92
+
93
+ printf("Success\n");
94
+
95
+ return out;
96
+ }
@@ -0,0 +1,24 @@
1
+ //
2
+ // myGraph.h
3
+ //
4
+ //
5
+ // Created by Mathieu Bouchard on 2014-03-21.
6
+ //
7
+ //
8
+
9
+ #ifndef IgraphWrapper_h
10
+ #define IgraphWrapper_h
11
+
12
+ #include <dlfcn.h>
13
+ #include <string>
14
+ #include <iostream>
15
+ #include <unistd.h>
16
+ #include <vector>
17
+ #include <map>
18
+ #include <string>
19
+
20
+ using namespace std;
21
+
22
+ vector<vector<double> > SolveAllPairsShortestPath(vector<vector<size_t> > pairs);
23
+
24
+ #endif
@@ -0,0 +1,5 @@
1
+ module IgraphWrapper
2
+
3
+ end
4
+
5
+ require "IgraphWrapper/IgraphWrapper"
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: igraph_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathieu Bouchard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A ruby wrapper on the iGraph library
14
+ email: mathbouchard@gmail.com
15
+ executables: []
16
+ extensions:
17
+ - ext/IgraphWrapper/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ext/IgraphWrapper/IgraphWrapper.cpp
21
+ - ext/IgraphWrapper/extconf.rb
22
+ - ext/IgraphWrapper/igraph_wrap.cpp
23
+ - ext/IgraphWrapper/igraph_wrap.h
24
+ - lib/IgraphWrapper.rb
25
+ homepage: http://igraph.org
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: iGraph Wrapper Gem
49
+ test_files: []