nlopt 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/nlopt/gradient.rb +8 -5
- data/lib/nlopt/opt.rb +25 -0
- data/lib/nlopt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c779a5c494c4f27159c477063ddf7574c40b9813936d25ca24a0e9b72a6c897c
|
4
|
+
data.tar.gz: dc7dd6083dfc4696ad9795fcb3565d7a67ecd150ca14b56bc99afdc171908335
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9dde169b1604d8a2c4a726aff6faecfde7d63180a936ec4f0d640d02bb6f36cee1833718f3486c926da8332b34e0a6cdcf34518b853c1cbcf7a386873ccb378
|
7
|
+
data.tar.gz: 37b4f469c22ff6e21d4e1012ad1fcd7f6c09cc478cc215917d01a73c9aef04003dbce4c95f44f836dbf6b71c82e604acf43dddc8f9b8bb6ff510a871e6d3bd69
|
data/CHANGELOG.md
CHANGED
data/lib/nlopt/gradient.rb
CHANGED
@@ -6,12 +6,12 @@ module NLopt
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def [](index)
|
9
|
-
check_index(index)
|
9
|
+
index = check_index(index)
|
10
10
|
@ptr[index * Fiddle::SIZEOF_DOUBLE, Fiddle::SIZEOF_DOUBLE].unpack1("d")
|
11
11
|
end
|
12
12
|
|
13
13
|
def []=(index, value)
|
14
|
-
check_index(index)
|
14
|
+
index = check_index(index)
|
15
15
|
@ptr[index * Fiddle::SIZEOF_DOUBLE, Fiddle::SIZEOF_DOUBLE] = [value].pack("d")
|
16
16
|
end
|
17
17
|
|
@@ -26,10 +26,13 @@ module NLopt
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
def check_index(
|
30
|
-
|
31
|
-
|
29
|
+
def check_index(original_index)
|
30
|
+
index = original_index
|
31
|
+
index += @n if index < 0
|
32
|
+
if index < 0 || index >= @n
|
33
|
+
raise IndexError, "index #{original_index} outside of array bounds"
|
32
34
|
end
|
35
|
+
index
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
data/lib/nlopt/opt.rb
CHANGED
@@ -14,6 +14,9 @@ module NLopt
|
|
14
14
|
|
15
15
|
@opt = FFI.nlopt_create(algorithm, n)
|
16
16
|
@opt.free = FFI["nlopt_destroy"]
|
17
|
+
|
18
|
+
@inequality_constraints = []
|
19
|
+
@equality_constraints = []
|
17
20
|
end
|
18
21
|
|
19
22
|
def dimension
|
@@ -64,12 +67,26 @@ module NLopt
|
|
64
67
|
out_dptr { |ptr| FFI.nlopt_get_upper_bounds(@opt, ptr) }
|
65
68
|
end
|
66
69
|
|
70
|
+
def add_inequality_constraint(fc, tol: 0)
|
71
|
+
cb = objective_callback(fc)
|
72
|
+
check_res FFI.nlopt_add_inequality_constraint(@opt, cb, nil, tol)
|
73
|
+
@inequality_constraints << cb # keep reference
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_equality_constraint(h, tol: 0)
|
77
|
+
cb = objective_callback(h)
|
78
|
+
check_res FFI.nlopt_add_equality_constraint(@opt, cb, nil, tol)
|
79
|
+
@equality_constraints << cb # keep reference
|
80
|
+
end
|
81
|
+
|
67
82
|
def remove_inequality_constraints
|
68
83
|
check_res FFI.nlopt_remove_inequality_constraints(@opt)
|
84
|
+
@inequality_constraints.clear
|
69
85
|
end
|
70
86
|
|
71
87
|
def remove_equality_constraints
|
72
88
|
check_res FFI.nlopt_remove_equality_constraints(@opt)
|
89
|
+
@equality_constraints.clear
|
73
90
|
end
|
74
91
|
|
75
92
|
def set_stopval(stopval)
|
@@ -207,6 +224,10 @@ module NLopt
|
|
207
224
|
end
|
208
225
|
end
|
209
226
|
|
227
|
+
def initial_step(x)
|
228
|
+
out_dptr { |ptr| FFI.nlopt_get_initial_step(@opt, alloc_dptr(x), ptr) }
|
229
|
+
end
|
230
|
+
|
210
231
|
def set_population(pop)
|
211
232
|
check_res FFI.nlopt_set_population(@opt, pop)
|
212
233
|
end
|
@@ -223,6 +244,10 @@ module NLopt
|
|
223
244
|
FFI.nlopt_get_vector_storage(@opt)
|
224
245
|
end
|
225
246
|
|
247
|
+
def to_ptr
|
248
|
+
@opt
|
249
|
+
end
|
250
|
+
|
226
251
|
private
|
227
252
|
|
228
253
|
def check_res(res)
|
data/lib/nlopt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nlopt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fiddle
|