relax4 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -102,6 +102,13 @@ and run
102
102
 
103
103
  == HISTORY
104
104
 
105
+ <em>1.0.5</em>
106
+ * fix in previous version didn't quite solve the problem; new fix applied
107
+
108
+ <em>1.0.4</em>
109
+ * fixed apparent bug in ascnt2_ that caused memory corruption or infinite loop
110
+ * switched to gemma for basic rake tasks
111
+
105
112
  <em>1.0.3</em>
106
113
  * now uses RELAX4_UNCAPACITATED by default for uncapacitated problems
107
114
  * updated docs
data/ext/relax4.c CHANGED
@@ -8,15 +8,15 @@
8
8
  * 1) Now using dynamic (malloc'd) rather than static arrays.
9
9
  * 2) An apparent bug in ascnt2_ has been fixed: the prdcsr array is a
10
10
  * node-length array, but it was indexed by the 'nb' variable, which can become
11
- * larger than the number of nodes. A new arc-length array (temp_nb) has been
12
- * added to avoid this.
11
+ * larger than the number of nodes. The prdcsr array is now as long as the max
12
+ * of the number of arcs and the number of nodes.
13
13
  *
14
14
  * The f2c linkage dependencies have been removed, but the FORTRAN character of
15
15
  * the code has been largely preserved -- you have been warned.
16
16
  */
17
17
 
18
18
  #include "stdlib.h"
19
- /*#include "stdio.h" */ /* just for tracing*/
19
+ /* #include "stdio.h" */ /* just for tracing*/
20
20
  #include "assert.h"
21
21
  #include "relax4.h"
22
22
 
@@ -35,6 +35,7 @@ typedef char logical1;
35
35
  #define TRUE_ (1)
36
36
  #define FALSE_ (0)
37
37
  #define min(a,b) ((a) <= (b) ? (a) : (b))
38
+ #define max(a,b) ((a) >= (b) ? (a) : (b))
38
39
 
39
40
  /*
40
41
  * Begin translated RELAX4 code...
@@ -322,10 +323,6 @@ struct {
322
323
 
323
324
  #define cr_1 cr_
324
325
 
325
- /* Temporary added by JLM to avoid out-of-bounds problem caused by using the
326
- * prdcsr array in ascnt2_. */
327
- RELAX4_INT *temp_nb;
328
-
329
326
  /* Subroutine */ int inidat_(void)
330
327
  {
331
328
  /* System generated locals */
@@ -3670,7 +3667,7 @@ L4:
3670
3667
  if (arrayrc_1.rc[arc - 1] == 0) {
3671
3668
  *delx += arrayu_1.u[arc - 1];
3672
3669
  ++nb;
3673
- temp_nb[nb - 1] = arc; /* was blk2_3.prdcsr */
3670
+ blk2_3.prdcsr[nb - 1] = arc;
3674
3671
  }
3675
3672
  }
3676
3673
  /* L6: */
@@ -3705,7 +3702,7 @@ L4:
3705
3702
 
3706
3703
  i__1 = nb;
3707
3704
  for (i__ = 1; i__ <= i__1; ++i__) {
3708
- arc = temp_nb[i__ - 1]; /* was blk2_3.prdcsr */
3705
+ arc = blk2_3.prdcsr[i__ - 1];
3709
3706
  if (blk13_1.tnxtin[arc - 1] == -1) {
3710
3707
  j = arraye_1.endn[arc - 1];
3711
3708
  blk13_1.tnxtin[arc - 1] = blk12_1.tfstin[j - 1];
@@ -3808,11 +3805,11 @@ int relax4_init(RELAX4_INT num_nodes, RELAX4_INT num_arcs,
3808
3805
  blk15_1.i15 = NULL;
3809
3806
  blk16_1.i16 = NULL;
3810
3807
  blk17_1.i17 = NULL;
3811
- temp_nb = NULL;
3812
3808
 
3813
3809
  arrayrc_1.rc = malloc(num_arcs*sizeof(RELAX4_INT));
3814
3810
  blk1_1.i1 = malloc(num_nodes*sizeof(RELAX4_INT));
3815
- blk2_1.i2 = malloc(num_nodes*sizeof(RELAX4_INT));
3811
+ /* fix for out-of-bounds error in ascnt2_; see comment at top of file */
3812
+ blk2_1.i2 = malloc(max(num_nodes,num_arcs)*sizeof(RELAX4_INT));
3816
3813
  blk3_1.i3 = malloc(num_nodes*sizeof(RELAX4_INT));
3817
3814
  blk4_1.i4 = malloc(num_arcs*sizeof(RELAX4_INT));
3818
3815
  blk5_1.i5 = malloc(num_nodes*sizeof(RELAX4_INT));
@@ -3828,7 +3825,6 @@ int relax4_init(RELAX4_INT num_nodes, RELAX4_INT num_arcs,
3828
3825
  blk15_1.i15 = malloc(num_nodes*sizeof(RELAX4_INT));
3829
3826
  blk16_1.i16 = malloc(num_nodes*sizeof(RELAX4_INT));
3830
3827
  blk17_1.i17 = malloc(num_nodes*sizeof(RELAX4_INT));
3831
- temp_nb = malloc(num_arcs*sizeof(RELAX4_INT));
3832
3828
 
3833
3829
  if (arrayrc_1.rc == NULL ||
3834
3830
  blk1_1.i1 == NULL ||
@@ -3847,8 +3843,7 @@ int relax4_init(RELAX4_INT num_nodes, RELAX4_INT num_arcs,
3847
3843
  blk14_1.i14 == NULL ||
3848
3844
  blk15_1.i15 == NULL ||
3849
3845
  blk16_1.i16 == NULL ||
3850
- blk17_1.i17 == NULL ||
3851
- temp_nb == NULL) {
3846
+ blk17_1.i17 == NULL) {
3852
3847
  relax4_free();
3853
3848
  return RELAX4_FAIL_OUT_OF_MEMORY;
3854
3849
  }
@@ -3962,6 +3957,5 @@ void relax4_free()
3962
3957
  if(blk15_1.i15 ) free(blk15_1.i15 );
3963
3958
  if(blk16_1.i16 ) free(blk16_1.i16 );
3964
3959
  if(blk17_1.i17 ) free(blk17_1.i17 );
3965
- if(temp_nb ) free(temp_nb );
3966
3960
  }
3967
3961
 
@@ -1,3 +1,3 @@
1
1
  module Relax4
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
data/test/test_relax4.rb CHANGED
@@ -92,6 +92,17 @@ class TestRelax4< Test::Unit::TestCase
92
92
  assert_equal 28759, problem_cost(prob, flows)
93
93
  end
94
94
 
95
+ def test_solve_6
96
+ # This problem also caused issues in the ascnt2_ routine for the same
97
+ # reasons as the problem in test_solve_5. The fix for that didn't entirely
98
+ # resolve the issue; see comments in relax4.c.
99
+ # This bug affected versions 1.0.4 and earlier.
100
+ prob = problem_from_relax4_inp 'test/test_solve_6.inp'
101
+ prob[:capacities].map! {|x| [x, Relax4::RELAX4_UNCAPACITATED].min}
102
+ flows = Relax4.solve(prob)
103
+ assert_equal 16925, problem_cost(prob, flows)
104
+ end
105
+
95
106
  def test_solve_lemon_1
96
107
  # Some tests stolen from LEMON version 1.2 (test/min_cost_flow_test.cc).
97
108
  # Note that we can't handle minimum flows, so we can only run tests with the
@@ -0,0 +1,259 @@
1
+ 17 240
2
+ 1 2 244 50000000
3
+ 1 3 738 50000000
4
+ 1 4 643 50000000
5
+ 1 5 578 50000000
6
+ 1 6 514 50000000
7
+ 1 7 433 50000000
8
+ 1 8 365 50000000
9
+ 1 9 294 50000000
10
+ 1 10 140 50000000
11
+ 1 11 79 50000000
12
+ 1 12 169 50000000
13
+ 1 13 287 50000000
14
+ 1 14 359 50000000
15
+ 1 15 207 50000000
16
+ 2 1 32 50000000
17
+ 2 3 769 50000000
18
+ 2 4 674 50000000
19
+ 2 5 609 50000000
20
+ 2 6 545 50000000
21
+ 2 7 464 50000000
22
+ 2 8 396 50000000
23
+ 2 9 325 50000000
24
+ 2 10 171 50000000
25
+ 2 11 110 50000000
26
+ 2 12 200 50000000
27
+ 2 13 318 50000000
28
+ 2 14 390 50000000
29
+ 2 15 238 50000000
30
+ 3 1 103 50000000
31
+ 3 2 72 50000000
32
+ 3 4 745 50000000
33
+ 3 5 680 50000000
34
+ 3 6 616 50000000
35
+ 3 7 535 50000000
36
+ 3 8 467 50000000
37
+ 3 9 396 50000000
38
+ 3 10 242 50000000
39
+ 3 11 181 50000000
40
+ 3 12 271 50000000
41
+ 3 13 389 50000000
42
+ 3 14 461 50000000
43
+ 3 15 309 50000000
44
+ 4 1 198 50000000
45
+ 4 2 167 50000000
46
+ 4 3 96 50000000
47
+ 4 5 775 50000000
48
+ 4 6 711 50000000
49
+ 4 7 630 50000000
50
+ 4 8 562 50000000
51
+ 4 9 491 50000000
52
+ 4 10 337 50000000
53
+ 4 11 276 50000000
54
+ 4 12 366 50000000
55
+ 4 13 484 50000000
56
+ 4 14 556 50000000
57
+ 4 15 404 50000000
58
+ 5 1 263 50000000
59
+ 5 2 232 50000000
60
+ 5 3 161 50000000
61
+ 5 4 66 50000000
62
+ 5 6 776 50000000
63
+ 5 7 695 50000000
64
+ 5 8 627 50000000
65
+ 5 9 556 50000000
66
+ 5 10 402 50000000
67
+ 5 11 341 50000000
68
+ 5 12 431 50000000
69
+ 5 13 549 50000000
70
+ 5 14 621 50000000
71
+ 5 15 469 50000000
72
+ 6 1 327 50000000
73
+ 6 2 296 50000000
74
+ 6 3 225 50000000
75
+ 6 4 130 50000000
76
+ 6 5 65 50000000
77
+ 6 7 759 50000000
78
+ 6 8 691 50000000
79
+ 6 9 620 50000000
80
+ 6 10 466 50000000
81
+ 6 11 405 50000000
82
+ 6 12 495 50000000
83
+ 6 13 613 50000000
84
+ 6 14 685 50000000
85
+ 6 15 533 50000000
86
+ 7 1 408 50000000
87
+ 7 2 377 50000000
88
+ 7 3 306 50000000
89
+ 7 4 211 50000000
90
+ 7 5 146 50000000
91
+ 7 6 82 50000000
92
+ 7 8 772 50000000
93
+ 7 9 701 50000000
94
+ 7 10 547 50000000
95
+ 7 11 486 50000000
96
+ 7 12 576 50000000
97
+ 7 13 694 50000000
98
+ 7 14 766 50000000
99
+ 7 15 614 50000000
100
+ 8 1 476 50000000
101
+ 8 2 445 50000000
102
+ 8 3 374 50000000
103
+ 8 4 279 50000000
104
+ 8 5 214 50000000
105
+ 8 6 150 50000000
106
+ 8 7 69 50000000
107
+ 8 9 769 50000000
108
+ 8 10 615 50000000
109
+ 8 11 554 50000000
110
+ 8 12 644 50000000
111
+ 8 13 762 50000000
112
+ 8 14 834 50000000
113
+ 8 15 682 50000000
114
+ 9 1 547 50000000
115
+ 9 2 516 50000000
116
+ 9 3 445 50000000
117
+ 9 4 350 50000000
118
+ 9 5 285 50000000
119
+ 9 6 221 50000000
120
+ 9 7 140 50000000
121
+ 9 8 72 50000000
122
+ 9 10 686 50000000
123
+ 9 11 625 50000000
124
+ 9 12 715 50000000
125
+ 9 13 833 50000000
126
+ 9 14 905 50000000
127
+ 9 15 753 50000000
128
+ 10 1 136 50000000
129
+ 10 2 105 50000000
130
+ 10 3 599 50000000
131
+ 10 4 504 50000000
132
+ 10 5 439 50000000
133
+ 10 6 375 50000000
134
+ 10 7 294 50000000
135
+ 10 8 226 50000000
136
+ 10 9 155 50000000
137
+ 10 11 214 50000000
138
+ 10 12 304 50000000
139
+ 10 13 422 50000000
140
+ 10 14 494 50000000
141
+ 10 15 342 50000000
142
+ 11 1 231 50000000
143
+ 11 2 200 50000000
144
+ 11 3 968 50000000
145
+ 11 4 873 50000000
146
+ 11 5 808 50000000
147
+ 11 6 744 50000000
148
+ 11 7 663 50000000
149
+ 11 8 595 50000000
150
+ 11 9 524 50000000
151
+ 11 10 370 50000000
152
+ 11 12 91 50000000
153
+ 11 13 209 50000000
154
+ 11 14 281 50000000
155
+ 11 15 129 50000000
156
+ 12 1 388 50000000
157
+ 12 2 357 50000000
158
+ 12 3 1125 50000000
159
+ 12 4 1030 50000000
160
+ 12 5 965 50000000
161
+ 12 6 901 50000000
162
+ 12 7 820 50000000
163
+ 12 8 752 50000000
164
+ 12 9 681 50000000
165
+ 12 10 527 50000000
166
+ 12 11 466 50000000
167
+ 12 13 119 50000000
168
+ 12 14 191 50000000
169
+ 12 15 286 50000000
170
+ 13 1 270 50000000
171
+ 13 2 239 50000000
172
+ 13 3 1007 50000000
173
+ 13 4 912 50000000
174
+ 13 5 847 50000000
175
+ 13 6 783 50000000
176
+ 13 7 702 50000000
177
+ 13 8 634 50000000
178
+ 13 9 563 50000000
179
+ 13 10 409 50000000
180
+ 13 11 348 50000000
181
+ 13 12 438 50000000
182
+ 13 14 73 50000000
183
+ 13 15 168 50000000
184
+ 14 1 198 50000000
185
+ 14 2 167 50000000
186
+ 14 3 935 50000000
187
+ 14 4 840 50000000
188
+ 14 5 775 50000000
189
+ 14 6 711 50000000
190
+ 14 7 630 50000000
191
+ 14 8 562 50000000
192
+ 14 9 491 50000000
193
+ 14 10 337 50000000
194
+ 14 11 276 50000000
195
+ 14 12 366 50000000
196
+ 14 13 484 50000000
197
+ 14 15 96 50000000
198
+ 15 1 103 50000000
199
+ 15 2 72 50000000
200
+ 15 3 840 50000000
201
+ 15 4 745 50000000
202
+ 15 5 680 50000000
203
+ 15 6 616 50000000
204
+ 15 7 535 50000000
205
+ 15 8 467 50000000
206
+ 15 9 396 50000000
207
+ 15 10 242 50000000
208
+ 15 11 181 50000000
209
+ 15 12 271 50000000
210
+ 15 13 389 50000000
211
+ 15 14 461 50000000
212
+ 16 1 0 50000000
213
+ 16 2 0 50000000
214
+ 16 3 0 50000000
215
+ 16 4 0 50000000
216
+ 16 5 0 50000000
217
+ 16 6 0 50000000
218
+ 16 7 0 50000000
219
+ 16 8 0 50000000
220
+ 16 9 0 50000000
221
+ 16 10 0 50000000
222
+ 16 11 0 50000000
223
+ 16 12 0 50000000
224
+ 16 13 0 50000000
225
+ 16 14 0 50000000
226
+ 16 15 0 50000000
227
+ 1 17 0 50000000
228
+ 2 17 0 50000000
229
+ 3 17 0 50000000
230
+ 4 17 0 50000000
231
+ 5 17 0 50000000
232
+ 6 17 0 50000000
233
+ 7 17 0 50000000
234
+ 8 17 0 50000000
235
+ 9 17 0 50000000
236
+ 10 17 0 50000000
237
+ 11 17 0 50000000
238
+ 12 17 0 50000000
239
+ 13 17 0 50000000
240
+ 14 17 0 50000000
241
+ 15 17 0 50000000
242
+ 5
243
+ 11
244
+ -6
245
+ -5
246
+ -6
247
+ 1
248
+ -1
249
+ -5
250
+ -5
251
+ -2
252
+ 1
253
+ 13
254
+ 8
255
+ 2
256
+ 8
257
+ 0
258
+ -19
259
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relax4
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Lees-Miller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-24 00:00:00 +01:00
18
+ date: 2010-09-25 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -33,14 +33,15 @@ extra_rdoc_files:
33
33
  files:
34
34
  - lib/relax4.rb
35
35
  - lib/relax4/version.rb
36
+ - test/test_solve_6.inp
37
+ - test/test_solve_5.inp
38
+ - test/test_solve_4.inp
39
+ - test/RELAX4.INP
36
40
  - ext/extconf.rb
37
41
  - ext/relax4.c
38
42
  - ext/relax4.h
39
43
  - ext/relax4_wrap.c
40
44
  - README.rdoc
41
- - test/RELAX4.INP
42
- - test/test_solve_4.inp
43
- - test/test_solve_5.inp
44
45
  - test/test_relax4.rb
45
46
  has_rdoc: true
46
47
  homepage: http://relax4.rubyforge.org/
@@ -50,6 +51,10 @@ post_install_message:
50
51
  rdoc_options:
51
52
  - --main
52
53
  - README.rdoc
54
+ - --title
55
+ - relax4-1.0.5
56
+ - --exclude
57
+ - ext
53
58
  require_paths:
54
59
  - lib
55
60
  - ext