genmodel 0.0.28 → 0.0.29
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 +4 -4
- data/ext/Genmodel/GraphTools.cpp +44 -29
- data/ext/Genmodel/GraphTools.h +6 -4
- data/ext/Genmodel/extconf.rb +30 -30
- data/ext/Genmodel/mygraph.cpp +134 -0
- data/ext/Genmodel/mygraph.h +52 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80b1bb7189a1c9e2306ec09c5147261d392e846a
|
4
|
+
data.tar.gz: 429c9a6c5cf1c9b25ff02def102414c44f196a62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37cea0d64109fd0831e07b0cae8ee67aafb8201a9a119e51bc902a4945b7707e68ffa33bb619667f9002e09fbd2eab886d684a0285017bb947e8d2f221f464c1
|
7
|
+
data.tar.gz: bd42525f466d8b05deb0ba2f61d92cd3d4aac25d55618382fd7e1d4f42a0af75f19ffd683dd308b4b131099876b7c548d249c2f9b0ffc0aeb664f2d6cf0b62d7
|
data/ext/Genmodel/GraphTools.cpp
CHANGED
@@ -16,8 +16,8 @@
|
|
16
16
|
|
17
17
|
vector<vector<size_t> > GmGraph::GetCliqueCover()
|
18
18
|
{
|
19
|
-
size_t n = countNodes(g);
|
20
|
-
size_t e = countEdges(g);
|
19
|
+
size_t n = g.n();//countNodes(g);
|
20
|
+
size_t e = g.e();//countEdges(g);
|
21
21
|
vector<vector<size_t> > out;
|
22
22
|
|
23
23
|
vector<bool> done(e,false);
|
@@ -38,8 +38,8 @@ vector<vector<size_t> > GmGraph::GetCliqueCover()
|
|
38
38
|
vector<size_t> node_depth(n,0);
|
39
39
|
|
40
40
|
vector<size_t> clique;
|
41
|
-
size_t curr_n =
|
42
|
-
size_t next_n =
|
41
|
+
size_t curr_n = u(curr_e);
|
42
|
+
size_t next_n = v(curr_e);
|
43
43
|
|
44
44
|
//ve.push_back(e);
|
45
45
|
|
@@ -64,14 +64,13 @@ vector<vector<size_t> > GmGraph::GetCliqueCover()
|
|
64
64
|
size_t next_nn = -1;
|
65
65
|
for(size_t i = 0; i < de.size(); i++)
|
66
66
|
{
|
67
|
-
size_t nn =
|
68
|
-
size_t onn = (g.id(g.u(g.e_id(de[i]))) == curr_n ? g.id(g.u(g.e_id(de[i]))) : g.id(g.v(g.e_id(de[i]))));
|
67
|
+
size_t nn = u(de[i]) == curr_n ? v(de[i]) : u(de[i]);
|
69
68
|
++(node_depth[nn]);
|
70
69
|
if(node_in[nn] && !done[de[i]])
|
71
70
|
{
|
72
71
|
done[de[i]] = true;
|
73
72
|
added++;
|
74
|
-
//printf("\t2-From %ld : Add edge %ld (depth %ld) [added = %ld] d=%ld --> %ld
|
73
|
+
//printf("\t2-From %ld : Add edge %ld (depth %ld) [added = %ld] d=%ld --> %ld\n", curr_n, de[i], depth, added, de.size(), nn);
|
75
74
|
}
|
76
75
|
if(node_depth[nn] == depth && next_n == -1 && !done[de[i]] && !node_in[nn])
|
77
76
|
{
|
@@ -103,96 +102,111 @@ vector<vector<size_t> > GmGraph::GetCliqueCover()
|
|
103
102
|
|
104
103
|
vector<size_t> GmGraph::ie(size_t i)
|
105
104
|
{
|
106
|
-
vector<size_t> out(di(i));
|
105
|
+
/*vector<size_t> out(di(i));
|
107
106
|
size_t ii = 0;
|
108
107
|
for (ListGraph::IncEdgeIt _e(g, g.n_id(i)); _e != INVALID; ++_e, ++ii)
|
109
108
|
out[ii] = (g.id(_e)-g.id(_e)%2)/2;
|
110
|
-
return out
|
109
|
+
return out;*/
|
110
|
+
return g.ie(i);
|
111
111
|
}
|
112
112
|
|
113
113
|
BitVector GmGraph::ie2bv(size_t i)
|
114
114
|
{
|
115
|
-
BitVector out(countEdges(g)
|
115
|
+
/*BitVector out(countEdges(g));
|
116
116
|
for (ListGraph::IncEdgeIt _e(g, g.n_id(i)); _e != INVALID; ++_e)
|
117
117
|
out.set((g.id(_e)-g.id(_e)%2)/2, true);
|
118
|
-
return out
|
118
|
+
return out;*/
|
119
|
+
return g.ie2bv(i);
|
119
120
|
}
|
120
121
|
|
121
122
|
vector<size_t> GmGraph::in(size_t i)
|
122
123
|
{
|
123
|
-
vector<size_t> out(di(i));
|
124
|
+
/*vector<size_t> out(di(i));
|
124
125
|
size_t ii = 0;
|
125
126
|
for (ListGraph::IncEdgeIt _e(g, g.n_id(i)); _e != INVALID; ++_e, ++ii)
|
126
127
|
out[ii] = (g.id(g.u(_e)) == i ? g.id(g.v(_e)) : g.id(g.u(_e)));
|
127
|
-
return out
|
128
|
+
return out;*/
|
129
|
+
return g.in(i);
|
128
130
|
}
|
129
131
|
|
130
132
|
BitVector GmGraph::in2bv(size_t i)
|
131
133
|
{
|
132
|
-
BitVector out(countNodes(g));
|
134
|
+
/*BitVector out(countNodes(g));
|
133
135
|
for (ListGraph::IncEdgeIt _e(g, g.n_id(i)); _e != INVALID; ++_e)
|
134
136
|
(g.id(g.u(_e)) == i ? out.set(g.id(g.v(_e)),true) : out.set(g.id(g.u(_e)),true));
|
135
|
-
return out
|
137
|
+
return out;*/
|
138
|
+
return g.in2bv(i);
|
136
139
|
}
|
137
140
|
|
138
|
-
|
139
141
|
size_t GmGraph::n()
|
140
142
|
{
|
141
|
-
return countNodes(g);
|
143
|
+
//return countNodes(g);
|
144
|
+
return g.n();
|
142
145
|
}
|
143
146
|
|
144
147
|
size_t GmGraph::e()
|
145
148
|
{
|
146
|
-
return countEdges(g);
|
149
|
+
//return countEdges(g);
|
150
|
+
return g.e();
|
147
151
|
}
|
148
152
|
|
149
153
|
size_t GmGraph::di(size_t i)
|
150
154
|
{
|
151
|
-
return countIncEdges(g, g.n_id(i));
|
155
|
+
//return countIncEdges(g, g.n_id(i));
|
156
|
+
return g.di(i);
|
152
157
|
}
|
153
158
|
|
154
159
|
size_t GmGraph::AddNode()
|
155
160
|
{
|
156
|
-
return g.id(g.addNode());
|
161
|
+
//return g.id(g.addNode());
|
162
|
+
return g.addNode();
|
157
163
|
}
|
158
164
|
|
159
165
|
size_t GmGraph::AddEdge(size_t i, size_t j)
|
160
166
|
{
|
161
|
-
return g.id(g.addEdge(g.n_id(i), g.n_id(j)));
|
167
|
+
//return g.id(g.addEdge(g.n_id(i), g.n_id(j)));
|
168
|
+
return g.addEdge(i,j);
|
162
169
|
}
|
163
170
|
|
164
171
|
size_t GmGraph::u(size_t i)
|
165
172
|
{
|
166
|
-
return g.id(g.u(g.e_id(i)));
|
173
|
+
//return g.id(g.u(g.e_id(i)));
|
174
|
+
return g.u(i);
|
167
175
|
}
|
168
176
|
size_t GmGraph::v(size_t i)
|
169
177
|
{
|
170
|
-
return g.id(g.v(g.e_id(i)));
|
178
|
+
//return g.id(g.v(g.e_id(i)));
|
179
|
+
return g.v(i);
|
171
180
|
}
|
172
181
|
|
173
182
|
void GmGraph::EraseNode(size_t i)
|
174
183
|
{
|
175
|
-
g.erase(g.n_id(i));
|
184
|
+
//g.erase(g.n_id(i));
|
185
|
+
g.eraseNode(i);
|
176
186
|
}
|
177
187
|
|
178
188
|
void GmGraph::EraseEdge(size_t i)
|
179
189
|
{
|
180
|
-
g.erase(g.e_id(i));
|
190
|
+
//g.erase(g.e_id(i));
|
191
|
+
g.eraseNode(i);
|
181
192
|
}
|
182
193
|
|
183
194
|
void GmGraph::ChangeU(size_t i, size_t j)
|
184
195
|
{
|
185
|
-
g.changeU(g.e_id(i),g.n_id(j));
|
196
|
+
//g.changeU(g.e_id(i),g.n_id(j));
|
197
|
+
g.changeU(i,j);
|
186
198
|
}
|
187
199
|
|
188
200
|
void GmGraph::ChangeV(size_t i, size_t j)
|
189
201
|
{
|
190
|
-
g.changeV(g.e_id(i),g.n_id(j));
|
202
|
+
//g.changeV(g.e_id(i),g.n_id(j));
|
203
|
+
g.changeV(i,j);
|
191
204
|
}
|
192
205
|
|
193
206
|
void GmGraph::Contract(size_t i, size_t j, bool r)
|
194
207
|
{
|
195
|
-
g.contract(g.n_id(i), g.n_id(j), r);
|
208
|
+
//g.contract(g.n_id(i), g.n_id(j), r);
|
209
|
+
g.contract(i, j, r);
|
196
210
|
}
|
197
211
|
|
198
212
|
void GmGraph::Clear()
|
@@ -207,5 +221,6 @@ void GmGraph::ReserveNode(size_t n)
|
|
207
221
|
|
208
222
|
void GmGraph::ReserveEdge(size_t m)
|
209
223
|
{
|
210
|
-
g.reserveEdge(2 * m);
|
224
|
+
//g.reserveEdge(2 * m);
|
225
|
+
g.reserveEdge(m);
|
211
226
|
}
|
data/ext/Genmodel/GraphTools.h
CHANGED
@@ -9,11 +9,12 @@
|
|
9
9
|
#ifndef _GraphTools_h
|
10
10
|
#define _GraphTools_h
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
//#include <lemon/concepts/graph.h>
|
13
|
+
//#include <lemon/list_graph.h>
|
14
|
+
#include "mygraph.h"
|
14
15
|
#include "BitVector.h"
|
15
16
|
|
16
|
-
using namespace lemon;
|
17
|
+
//using namespace lemon;
|
17
18
|
using namespace std;
|
18
19
|
|
19
20
|
class GmGraph
|
@@ -43,7 +44,8 @@ public:
|
|
43
44
|
|
44
45
|
vector<vector<size_t> > GetCliqueCover();
|
45
46
|
|
46
|
-
ListGraph g;
|
47
|
+
//ListGraph g;
|
48
|
+
myGraph g;
|
47
49
|
};
|
48
50
|
|
49
51
|
#endif
|
data/ext/Genmodel/extconf.rb
CHANGED
@@ -91,28 +91,28 @@ if is_darwin
|
|
91
91
|
is_osi = false
|
92
92
|
end
|
93
93
|
|
94
|
-
search_path = "/usr/local/Cellar/lemon-graph/"
|
95
|
-
search_file = "/include/lemon/core.h"
|
96
|
-
puts "Looking for lemon/core.h in "+search_path+"/*"
|
97
|
-
file_exist = nil
|
98
|
-
Find.find(search_path) do |path|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
if(is_osi && file_exist != nil)
|
110
|
-
|
111
|
-
|
112
|
-
else
|
113
|
-
|
114
|
-
|
115
|
-
end
|
94
|
+
#search_path = "/usr/local/Cellar/lemon-graph/"
|
95
|
+
#search_file = "/include/lemon/core.h"
|
96
|
+
#puts "Looking for lemon/core.h in "+search_path+"/*"
|
97
|
+
#file_exist = nil
|
98
|
+
#Find.find(search_path) do |path|
|
99
|
+
# if (FileTest.directory?(path))
|
100
|
+
# puts path+search_file
|
101
|
+
# temp_name = (path).gsub(/\/usr\/local\/Cellar\/lemon-graph\//,'')
|
102
|
+
# count = temp_name.count('/')
|
103
|
+
# if ((count == 0) && (File.exist?(path+search_file)))
|
104
|
+
# file_exist = "-I#{path}/include"
|
105
|
+
# break
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#end
|
109
|
+
#if(is_osi && file_exist != nil)
|
110
|
+
# $INCFLAGS << " " << file_exist.quote
|
111
|
+
# puts "found"
|
112
|
+
#else
|
113
|
+
# puts "not found"
|
114
|
+
# is_osi = false
|
115
|
+
#end
|
116
116
|
|
117
117
|
|
118
118
|
path = "/usr/lib:/usr/local/lib/"
|
@@ -169,14 +169,14 @@ if is_darwin
|
|
169
169
|
#is_osi = false
|
170
170
|
end
|
171
171
|
|
172
|
-
path = "/usr/lib:/usr/local/lib/"
|
173
|
-
puts "Looking for libemon.dylib (function main) in "+path
|
174
|
-
if(is_osi && find_library("emon",nil,path))
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
end
|
172
|
+
#path = "/usr/lib:/usr/local/lib/"
|
173
|
+
#puts "Looking for libemon.dylib (function main) in "+path
|
174
|
+
#if(is_osi && find_library("emon",nil,path))
|
175
|
+
# puts "found"
|
176
|
+
# else
|
177
|
+
# puts "not found"
|
178
|
+
# is_osi = false
|
179
|
+
#end
|
180
180
|
|
181
181
|
elsif is_linux
|
182
182
|
# path = Dir.home+"/ibm/ILOG/CPLEX_Studio126/cplex/include:/opt/ibm/ILOG/CPLEX_Studio126/cplex/include"
|
@@ -0,0 +1,134 @@
|
|
1
|
+
//
|
2
|
+
// myGraph.cpp
|
3
|
+
//
|
4
|
+
//
|
5
|
+
// Created by Mathieu Bouchard on 2014-03-21.
|
6
|
+
//
|
7
|
+
//
|
8
|
+
|
9
|
+
#include "mygraph.h"
|
10
|
+
|
11
|
+
vector<size_t> myGraph::ie(size_t i)
|
12
|
+
{
|
13
|
+
vector<size_t> out(incs[i].size());
|
14
|
+
map<size_t, size_t>::iterator it;
|
15
|
+
size_t ii;
|
16
|
+
for (it = incs[i].begin(); it != incs[i].end(); ++it)
|
17
|
+
out[ii] = it->second;
|
18
|
+
return out;
|
19
|
+
}
|
20
|
+
|
21
|
+
BitVector myGraph::ie2bv(size_t i)
|
22
|
+
{
|
23
|
+
BitVector out(_e);
|
24
|
+
map<size_t, size_t>::iterator it;
|
25
|
+
size_t ii;
|
26
|
+
for (it = incs[i].begin(); it != incs[i].end(); ++it)
|
27
|
+
out.set(it->second, true);
|
28
|
+
return out;
|
29
|
+
}
|
30
|
+
|
31
|
+
vector<size_t> myGraph::in(size_t i)
|
32
|
+
{
|
33
|
+
vector<size_t> out(incs[i].size());
|
34
|
+
map<size_t, size_t>::iterator it;
|
35
|
+
size_t ii;
|
36
|
+
for (it = incs[i].begin(); it != incs[i].end(); ++it)
|
37
|
+
out[ii] = it->first;
|
38
|
+
return out;
|
39
|
+
}
|
40
|
+
|
41
|
+
BitVector myGraph::in2bv(size_t i)
|
42
|
+
{
|
43
|
+
BitVector out(_n);
|
44
|
+
map<size_t, size_t>::iterator it;
|
45
|
+
for (it = incs[i].begin(); it != incs[i].end(); ++it)
|
46
|
+
out.set(it->first, true);
|
47
|
+
return out;
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
size_t myGraph::n()
|
52
|
+
{
|
53
|
+
return _n;
|
54
|
+
}
|
55
|
+
|
56
|
+
size_t myGraph::e()
|
57
|
+
{
|
58
|
+
return _e;
|
59
|
+
}
|
60
|
+
|
61
|
+
size_t myGraph::di(size_t i)
|
62
|
+
{
|
63
|
+
return incs[i].size();
|
64
|
+
}
|
65
|
+
|
66
|
+
size_t myGraph::addNode()
|
67
|
+
{
|
68
|
+
incs.push_back(map<size_t,size_t>());
|
69
|
+
return _n++;
|
70
|
+
}
|
71
|
+
|
72
|
+
size_t myGraph::addEdge(size_t i, size_t j)
|
73
|
+
{
|
74
|
+
if(incs[i].count(j) > 0)
|
75
|
+
return incs[i][j];
|
76
|
+
else
|
77
|
+
{
|
78
|
+
edges.push_back(pair<size_t, size_t>(i,j));
|
79
|
+
return _e++;
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
size_t myGraph::u(size_t i)
|
84
|
+
{
|
85
|
+
return edges[i].first;
|
86
|
+
}
|
87
|
+
|
88
|
+
size_t myGraph::v(size_t i)
|
89
|
+
{
|
90
|
+
return edges[i].second;
|
91
|
+
}
|
92
|
+
|
93
|
+
void myGraph::eraseNode(size_t i)
|
94
|
+
{
|
95
|
+
throw string("myGraph : Not implemented.");
|
96
|
+
}
|
97
|
+
|
98
|
+
void myGraph::eraseEdge(size_t i)
|
99
|
+
{
|
100
|
+
throw string("myGraph : Not implemented.");
|
101
|
+
}
|
102
|
+
|
103
|
+
void myGraph::changeU(size_t i, size_t j)
|
104
|
+
{
|
105
|
+
throw string("myGraph : Not implemented.");
|
106
|
+
}
|
107
|
+
|
108
|
+
void myGraph::changeV(size_t i, size_t j)
|
109
|
+
{
|
110
|
+
throw string("myGraph : Not implemented.");
|
111
|
+
}
|
112
|
+
|
113
|
+
void myGraph::contract(size_t i, size_t j, bool r)
|
114
|
+
{
|
115
|
+
throw string("myGraph : Not implemented.");
|
116
|
+
}
|
117
|
+
|
118
|
+
void myGraph::clear()
|
119
|
+
{
|
120
|
+
_n=0;
|
121
|
+
_e=0;
|
122
|
+
edges.clear();
|
123
|
+
incs.clear();
|
124
|
+
}
|
125
|
+
|
126
|
+
void myGraph::reserveNode(size_t n)
|
127
|
+
{
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
void myGraph::reserveEdge(size_t m)
|
132
|
+
{
|
133
|
+
edges.reserve(m);
|
134
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
//
|
2
|
+
// myGraph.h
|
3
|
+
//
|
4
|
+
//
|
5
|
+
// Created by Mathieu Bouchard on 2014-03-21.
|
6
|
+
//
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef _myGraph_h
|
10
|
+
#define _myGraph_h
|
11
|
+
|
12
|
+
#include <vector>
|
13
|
+
#include <map>
|
14
|
+
#include "BitVector.h"
|
15
|
+
|
16
|
+
using namespace std;
|
17
|
+
|
18
|
+
class myGraph
|
19
|
+
{
|
20
|
+
public:
|
21
|
+
myGraph() : _n(0), _e(0) {}
|
22
|
+
~myGraph() {}
|
23
|
+
size_t addNode();
|
24
|
+
size_t addEdge(size_t i, size_t j);
|
25
|
+
void eraseNode(size_t i);
|
26
|
+
void eraseEdge(size_t i);
|
27
|
+
void changeU(size_t i, size_t j);
|
28
|
+
void changeV(size_t i, size_t j);
|
29
|
+
size_t u(size_t i);
|
30
|
+
size_t v(size_t i);
|
31
|
+
size_t di(size_t i);
|
32
|
+
size_t n();
|
33
|
+
size_t e();
|
34
|
+
|
35
|
+
void contract(size_t i, size_t j, bool r = true);
|
36
|
+
void clear();
|
37
|
+
void reserveNode(size_t n);
|
38
|
+
void reserveEdge(size_t m);
|
39
|
+
|
40
|
+
vector<size_t> ie(size_t i);
|
41
|
+
BitVector ie2bv(size_t i);
|
42
|
+
vector<size_t> in(size_t i);
|
43
|
+
BitVector in2bv(size_t i);
|
44
|
+
|
45
|
+
vector<pair<size_t,size_t> > edges;
|
46
|
+
vector<map<size_t, size_t> > incs;
|
47
|
+
|
48
|
+
size_t _n;
|
49
|
+
size_t _e;
|
50
|
+
};
|
51
|
+
|
52
|
+
#endif
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genmodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathieu Bouchard
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- ext/Genmodel/ProblemReaderOsi.cpp
|
34
34
|
- ext/Genmodel/ProblemReaderOsi.h
|
35
35
|
- ext/Genmodel/extconf.rb
|
36
|
+
- ext/Genmodel/mygraph.cpp
|
37
|
+
- ext/Genmodel/mygraph.h
|
36
38
|
- lib/Genmodel.rb
|
37
39
|
homepage: https://github.com/mathbouchard/GenModelGem
|
38
40
|
licenses:
|