@iyulab/u-metaheur 0.4.1 → 0.4.3
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.
- package/README.md +71 -30
- package/node/u_metaheur.cjs +39 -39
- package/node/u_metaheur.d.cts +16 -2
- package/node/u_metaheur_bg.wasm +0 -0
- package/package.json +1 -1
- package/u_metaheur.d.ts +16 -2
- package/u_metaheur_bg.js +39 -39
- package/u_metaheur_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -24,32 +24,50 @@ u-metaheur provides generic implementations of common metaheuristic algorithms.
|
|
|
24
24
|
|
|
25
25
|
## Key Traits
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
// GA — implement these for your domain
|
|
29
|
-
trait Chromosome: Clone + Send + Sync {
|
|
30
|
-
fn fitness(&self) -> f64;
|
|
31
|
-
}
|
|
32
|
-
trait Crossover<C: Chromosome> {
|
|
33
|
-
fn crossover(&self, parent1: &C, parent2: &C, rng: &mut Rng) -> C;
|
|
34
|
-
}
|
|
35
|
-
trait Mutation<C: Chromosome> {
|
|
36
|
-
fn mutate(&self, chromosome: &mut C, rng: &mut Rng);
|
|
37
|
-
}
|
|
27
|
+
Each algorithm asks for one small trait from your domain:
|
|
38
28
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
| Algorithm | Implement | You provide |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| GA | `ga::GaProblem` (+ `ga::Individual`) | create, evaluate, crossover and mutate individuals |
|
|
32
|
+
| BRKGA | `brkga::BrkgaDecoder` | `decode(&[f64]) -> f64` — random keys to a cost |
|
|
33
|
+
| SA | `sa::SaProblem` | an initial solution, its `cost`, a `neighbor` |
|
|
34
|
+
| ALNS | `alns::AlnsProblem` + `DestroyOperator` / `RepairOperator` | a solution, its cost, destroy and repair moves |
|
|
35
|
+
|
|
36
|
+
Every cost is minimised.
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
```rust
|
|
39
|
+
use rand::{Rng, RngExt};
|
|
40
|
+
use u_metaheur::brkga::{BrkgaConfig, BrkgaDecoder, BrkgaRunner};
|
|
41
|
+
use u_metaheur::sa::{SaConfig, SaProblem, SaRunner};
|
|
42
|
+
|
|
43
|
+
// BRKGA: the decoder turns random keys into a cost -- here, how far the keys
|
|
44
|
+
// are from ascending order.
|
|
45
|
+
struct Sorted;
|
|
46
|
+
impl BrkgaDecoder for Sorted {
|
|
47
|
+
fn decode(&self, keys: &[f64]) -> f64 {
|
|
48
|
+
keys.windows(2).filter(|w| w[0] > w[1]).count() as f64
|
|
49
|
+
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
let config = BrkgaConfig::new(6).with_stagnation_limit(200).with_seed(7);
|
|
52
|
+
let result = BrkgaRunner::run(&Sorted, &config).unwrap();
|
|
53
|
+
assert_eq!(result.best_cost, 0.0);
|
|
54
|
+
|
|
55
|
+
// SA: minimise (x - 3)^2 by small random steps.
|
|
56
|
+
struct Parabola;
|
|
57
|
+
impl SaProblem for Parabola {
|
|
58
|
+
type Solution = f64;
|
|
59
|
+
fn initial_solution<R: Rng>(&self, _rng: &mut R) -> f64 {
|
|
60
|
+
0.0
|
|
61
|
+
}
|
|
62
|
+
fn cost(&self, x: &f64) -> f64 {
|
|
63
|
+
(x - 3.0).powi(2)
|
|
64
|
+
}
|
|
65
|
+
fn neighbor<R: Rng>(&self, x: &f64, rng: &mut R) -> f64 {
|
|
66
|
+
x + rng.random_range(-0.5..0.5)
|
|
67
|
+
}
|
|
52
68
|
}
|
|
69
|
+
let result = SaRunner::run(&Parabola, &SaConfig::default().with_seed(7));
|
|
70
|
+
assert!((result.best - 3.0).abs() < 0.1);
|
|
53
71
|
```
|
|
54
72
|
|
|
55
73
|
## Features
|
|
@@ -60,10 +78,10 @@ trait RepairOperator<S> {
|
|
|
60
78
|
|
|
61
79
|
```toml
|
|
62
80
|
[dependencies]
|
|
63
|
-
u-metaheur =
|
|
81
|
+
u-metaheur = "0.4"
|
|
64
82
|
|
|
65
83
|
# with serde support
|
|
66
|
-
u-metaheur = {
|
|
84
|
+
u-metaheur = { version = "0.4", features = ["serde"] }
|
|
67
85
|
```
|
|
68
86
|
|
|
69
87
|
## Build & Test
|
|
@@ -98,22 +116,45 @@ The package resolves per environment via a conditional `exports` map:
|
|
|
98
116
|
| Bundlers (webpack, Vite, …) | ESM + WebAssembly ESM-integration (`default` condition) |
|
|
99
117
|
| Node.js — `require()`, ESM `import`, CJS TS runners (`tsx`, `ts-node`) | CJS glue loading the wasm from the filesystem (`node` condition) — no loader hooks or flags |
|
|
100
118
|
|
|
119
|
+
### Quick Start
|
|
120
|
+
|
|
121
|
+
Both functions solve a travelling-salesman tour over `nodes` (`[x, y]` pairs)
|
|
122
|
+
and return the best tour found and its closed length:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import { run_ga, run_sa } from '@iyulab/u-metaheur';
|
|
126
|
+
|
|
127
|
+
// The corners of a unit square: the shortest closed tour is its perimeter, 4.
|
|
128
|
+
const nodes = [[0, 0], [1, 0], [1, 1], [0, 1]];
|
|
129
|
+
|
|
130
|
+
const ga = run_ga({ nodes, population_size: 30, generations: 50 });
|
|
131
|
+
const sa = run_sa({ nodes, iterations: 2000 });
|
|
132
|
+
console.log(ga.best_distance, ga.best_tour); // 4 [ ... ]
|
|
133
|
+
console.log(sa.best_distance, sa.iterations_run);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`run_ga` also takes `mutation_rate`; `run_sa` takes `initial_temp` and
|
|
137
|
+
`cooling_rate`. Every setting is optional except `nodes`, and a setting the
|
|
138
|
+
function does not have is rejected rather than ignored.
|
|
139
|
+
|
|
101
140
|
### TypeScript
|
|
102
141
|
|
|
103
|
-
Every exported function declares its return
|
|
104
|
-
generated from the same structs the binding
|
|
105
|
-
from what it actually returns:
|
|
142
|
+
Every exported function declares its parameter and return types, and the
|
|
143
|
+
declarations are generated from the same structs the binding reads and
|
|
144
|
+
serialises, so they cannot drift from what it actually accepts and returns:
|
|
106
145
|
|
|
107
146
|
```ts
|
|
108
|
-
export function run_ga(
|
|
147
|
+
export function run_ga(config: GaConfig): GaResult;
|
|
109
148
|
```
|
|
110
149
|
|
|
111
150
|
An absent optional value is declared `T | undefined`, which is what the binding
|
|
112
151
|
sends. Nothing needs an `as` cast -- and a wrong assumption about a result's
|
|
113
152
|
shape is a compile error rather than something that fails at run time.
|
|
114
153
|
|
|
115
|
-
|
|
116
|
-
|
|
154
|
+
The same holds on the way in: a setting the configuration does not have
|
|
155
|
+
does not compile. The binding still validates every input at the boundary, for
|
|
156
|
+
JavaScript callers and for values that reach it through a cast, and a rejected
|
|
157
|
+
one says what was wrong.
|
|
117
158
|
|
|
118
159
|
## Related
|
|
119
160
|
|
package/node/u_metaheur.cjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* # Returns
|
|
14
14
|
* JS object with `best_distance`, `best_tour`, `generations_run`.
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {GaConfig} config
|
|
16
16
|
* @returns {GaResult}
|
|
17
17
|
*/
|
|
18
18
|
function run_ga(config) {
|
|
@@ -39,7 +39,7 @@ exports.run_ga = run_ga;
|
|
|
39
39
|
*
|
|
40
40
|
* # Returns
|
|
41
41
|
* JS object with `best_distance`, `best_tour`, `iterations_run`.
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {SaConfig} config
|
|
43
43
|
* @returns {SaResult}
|
|
44
44
|
*/
|
|
45
45
|
function run_sa(config) {
|
|
@@ -53,7 +53,7 @@ exports.run_sa = run_sa;
|
|
|
53
53
|
function __wbg_get_imports() {
|
|
54
54
|
const import0 = {
|
|
55
55
|
__proto__: null,
|
|
56
|
-
|
|
56
|
+
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
57
57
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
58
58
|
return ret;
|
|
59
59
|
},
|
|
@@ -64,56 +64,56 @@ function __wbg_get_imports() {
|
|
|
64
64
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
65
65
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
66
66
|
},
|
|
67
|
-
|
|
67
|
+
__wbg___wbindgen_bigint_get_as_i64_a2383202b9353e4c: function(arg0, arg1) {
|
|
68
68
|
const v = arg1;
|
|
69
69
|
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
70
70
|
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
71
71
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
72
72
|
},
|
|
73
|
-
|
|
73
|
+
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
|
|
74
74
|
const v = arg0;
|
|
75
75
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
76
76
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
77
77
|
},
|
|
78
|
-
|
|
78
|
+
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
|
|
79
79
|
const ret = debugString(arg1);
|
|
80
80
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
81
81
|
const len1 = WASM_VECTOR_LEN;
|
|
82
82
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
83
83
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
84
84
|
},
|
|
85
|
-
|
|
85
|
+
__wbg___wbindgen_in_92f62ee1427d9e49: function(arg0, arg1) {
|
|
86
86
|
const ret = arg0 in arg1;
|
|
87
87
|
return ret;
|
|
88
88
|
},
|
|
89
|
-
|
|
89
|
+
__wbg___wbindgen_is_bigint_b123553bed3bb382: function(arg0) {
|
|
90
90
|
const ret = typeof(arg0) === 'bigint';
|
|
91
91
|
return ret;
|
|
92
92
|
},
|
|
93
|
-
|
|
93
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
94
94
|
const ret = typeof(arg0) === 'function';
|
|
95
95
|
return ret;
|
|
96
96
|
},
|
|
97
|
-
|
|
97
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
98
98
|
const val = arg0;
|
|
99
99
|
const ret = typeof(val) === 'object' && val !== null;
|
|
100
100
|
return ret;
|
|
101
101
|
},
|
|
102
|
-
|
|
102
|
+
__wbg___wbindgen_jsval_eq_02babf21faa37971: function(arg0, arg1) {
|
|
103
103
|
const ret = arg0 === arg1;
|
|
104
104
|
return ret;
|
|
105
105
|
},
|
|
106
|
-
|
|
106
|
+
__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
|
|
107
107
|
const ret = arg0 == arg1;
|
|
108
108
|
return ret;
|
|
109
109
|
},
|
|
110
|
-
|
|
110
|
+
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
|
|
111
111
|
const obj = arg1;
|
|
112
112
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
113
113
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
114
114
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
|
|
117
117
|
const obj = arg1;
|
|
118
118
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
119
119
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -121,37 +121,37 @@ function __wbg_get_imports() {
|
|
|
121
121
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
122
122
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
123
123
|
},
|
|
124
|
-
|
|
124
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
125
125
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
126
126
|
},
|
|
127
|
-
|
|
127
|
+
__wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
|
|
128
128
|
const ret = arg0.call(arg1);
|
|
129
129
|
return ret;
|
|
130
130
|
}, arguments); },
|
|
131
|
-
|
|
131
|
+
__wbg_done_b41a1d26cdb37fb6: function(arg0) {
|
|
132
132
|
const ret = arg0.done;
|
|
133
133
|
return ret;
|
|
134
134
|
},
|
|
135
|
-
|
|
135
|
+
__wbg_entries_fb6397112b1de25f: function(arg0) {
|
|
136
136
|
const ret = Object.entries(arg0);
|
|
137
137
|
return ret;
|
|
138
138
|
},
|
|
139
139
|
__wbg_getRandomValues_436a51d0629d84e1: function() { return handleError(function (arg0, arg1) {
|
|
140
140
|
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
141
141
|
}, arguments); },
|
|
142
|
-
|
|
142
|
+
__wbg_get_658f6698067d9515: function() { return handleError(function (arg0, arg1) {
|
|
143
143
|
const ret = Reflect.get(arg0, arg1);
|
|
144
144
|
return ret;
|
|
145
145
|
}, arguments); },
|
|
146
|
-
|
|
146
|
+
__wbg_get_6c896e0571ddae51: function(arg0, arg1) {
|
|
147
147
|
const ret = arg0[arg1 >>> 0];
|
|
148
148
|
return ret;
|
|
149
149
|
},
|
|
150
|
-
|
|
150
|
+
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
|
|
151
151
|
const ret = arg0[arg1 >>> 0];
|
|
152
152
|
return ret;
|
|
153
153
|
},
|
|
154
|
-
|
|
154
|
+
__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
|
|
155
155
|
let result;
|
|
156
156
|
try {
|
|
157
157
|
result = arg0 instanceof ArrayBuffer;
|
|
@@ -161,7 +161,7 @@ function __wbg_get_imports() {
|
|
|
161
161
|
const ret = result;
|
|
162
162
|
return ret;
|
|
163
163
|
},
|
|
164
|
-
|
|
164
|
+
__wbg_instanceof_Map_b2611749102d7ba3: function(arg0) {
|
|
165
165
|
let result;
|
|
166
166
|
try {
|
|
167
167
|
result = arg0 instanceof Map;
|
|
@@ -171,7 +171,7 @@ function __wbg_get_imports() {
|
|
|
171
171
|
const ret = result;
|
|
172
172
|
return ret;
|
|
173
173
|
},
|
|
174
|
-
|
|
174
|
+
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
|
|
175
175
|
let result;
|
|
176
176
|
try {
|
|
177
177
|
result = arg0 instanceof Uint8Array;
|
|
@@ -181,56 +181,56 @@ function __wbg_get_imports() {
|
|
|
181
181
|
const ret = result;
|
|
182
182
|
return ret;
|
|
183
183
|
},
|
|
184
|
-
|
|
184
|
+
__wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
|
|
185
185
|
const ret = Array.isArray(arg0);
|
|
186
186
|
return ret;
|
|
187
187
|
},
|
|
188
|
-
|
|
188
|
+
__wbg_isSafeInteger_717808ad6a54bd9e: function(arg0) {
|
|
189
189
|
const ret = Number.isSafeInteger(arg0);
|
|
190
190
|
return ret;
|
|
191
191
|
},
|
|
192
|
-
|
|
192
|
+
__wbg_iterator_e3c31c892080e444: function() {
|
|
193
193
|
const ret = Symbol.iterator;
|
|
194
194
|
return ret;
|
|
195
195
|
},
|
|
196
|
-
|
|
196
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
197
197
|
const ret = arg0.length;
|
|
198
198
|
return ret;
|
|
199
199
|
},
|
|
200
|
-
|
|
200
|
+
__wbg_length_d4bdea10311bd9cf: function(arg0) {
|
|
201
201
|
const ret = arg0.length;
|
|
202
202
|
return ret;
|
|
203
203
|
},
|
|
204
|
-
|
|
204
|
+
__wbg_new_1dbf7428bba60a42: function(arg0) {
|
|
205
205
|
const ret = new Uint8Array(arg0);
|
|
206
206
|
return ret;
|
|
207
207
|
},
|
|
208
|
-
|
|
208
|
+
__wbg_new_617a8cdb8bb1130e: function() {
|
|
209
209
|
const ret = new Object();
|
|
210
210
|
return ret;
|
|
211
211
|
},
|
|
212
|
-
|
|
212
|
+
__wbg_new_ee2291f50781bf1d: function() {
|
|
213
213
|
const ret = new Array();
|
|
214
214
|
return ret;
|
|
215
215
|
},
|
|
216
|
-
|
|
216
|
+
__wbg_next_33784799010f1bbe: function(arg0) {
|
|
217
217
|
const ret = arg0.next;
|
|
218
218
|
return ret;
|
|
219
219
|
},
|
|
220
|
-
|
|
220
|
+
__wbg_next_f4aac29c42af995c: function() { return handleError(function (arg0) {
|
|
221
221
|
const ret = arg0.next();
|
|
222
222
|
return ret;
|
|
223
223
|
}, arguments); },
|
|
224
|
-
|
|
224
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
225
225
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
226
226
|
},
|
|
227
|
-
__wbg_set_13d25b81ab403f5e: function(arg0, arg1, arg2) {
|
|
228
|
-
arg0[arg1 >>> 0] = arg2;
|
|
229
|
-
},
|
|
230
227
|
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
231
228
|
arg0[arg1] = arg2;
|
|
232
229
|
},
|
|
233
|
-
|
|
230
|
+
__wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
|
|
231
|
+
arg0[arg1 >>> 0] = arg2;
|
|
232
|
+
},
|
|
233
|
+
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
|
|
234
234
|
const ret = arg0.value;
|
|
235
235
|
return ret;
|
|
236
236
|
},
|
package/node/u_metaheur.d.cts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
export interface GaConfig {
|
|
4
|
+
nodes: [number, number][];
|
|
5
|
+
population_size?: number;
|
|
6
|
+
generations?: number;
|
|
7
|
+
mutation_rate?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export interface GaResult {
|
|
4
11
|
best_distance: number;
|
|
5
12
|
best_tour: number[];
|
|
6
13
|
generations_run: number;
|
|
7
14
|
}
|
|
8
15
|
|
|
16
|
+
export interface SaConfig {
|
|
17
|
+
nodes: [number, number][];
|
|
18
|
+
initial_temp?: number;
|
|
19
|
+
cooling_rate?: number;
|
|
20
|
+
iterations?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
export interface SaResult {
|
|
10
24
|
best_distance: number;
|
|
11
25
|
best_tour: number[];
|
|
@@ -26,7 +40,7 @@ export interface SaResult {
|
|
|
26
40
|
* # Returns
|
|
27
41
|
* JS object with `best_distance`, `best_tour`, `generations_run`.
|
|
28
42
|
*/
|
|
29
|
-
export function run_ga(config:
|
|
43
|
+
export function run_ga(config: GaConfig): GaResult;
|
|
30
44
|
|
|
31
45
|
/**
|
|
32
46
|
* Runs Simulated Annealing for TSP.
|
|
@@ -44,4 +58,4 @@ export function run_ga(config: any): GaResult;
|
|
|
44
58
|
* # Returns
|
|
45
59
|
* JS object with `best_distance`, `best_tour`, `iterations_run`.
|
|
46
60
|
*/
|
|
47
|
-
export function run_sa(config:
|
|
61
|
+
export function run_sa(config: SaConfig): SaResult;
|
package/node/u_metaheur_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/u_metaheur.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
export interface GaConfig {
|
|
4
|
+
nodes: [number, number][];
|
|
5
|
+
population_size?: number;
|
|
6
|
+
generations?: number;
|
|
7
|
+
mutation_rate?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export interface GaResult {
|
|
4
11
|
best_distance: number;
|
|
5
12
|
best_tour: number[];
|
|
6
13
|
generations_run: number;
|
|
7
14
|
}
|
|
8
15
|
|
|
16
|
+
export interface SaConfig {
|
|
17
|
+
nodes: [number, number][];
|
|
18
|
+
initial_temp?: number;
|
|
19
|
+
cooling_rate?: number;
|
|
20
|
+
iterations?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
export interface SaResult {
|
|
10
24
|
best_distance: number;
|
|
11
25
|
best_tour: number[];
|
|
@@ -26,7 +40,7 @@ export interface SaResult {
|
|
|
26
40
|
* # Returns
|
|
27
41
|
* JS object with `best_distance`, `best_tour`, `generations_run`.
|
|
28
42
|
*/
|
|
29
|
-
export function run_ga(config:
|
|
43
|
+
export function run_ga(config: GaConfig): GaResult;
|
|
30
44
|
|
|
31
45
|
/**
|
|
32
46
|
* Runs Simulated Annealing for TSP.
|
|
@@ -44,4 +58,4 @@ export function run_ga(config: any): GaResult;
|
|
|
44
58
|
* # Returns
|
|
45
59
|
* JS object with `best_distance`, `best_tour`, `iterations_run`.
|
|
46
60
|
*/
|
|
47
|
-
export function run_sa(config:
|
|
61
|
+
export function run_sa(config: SaConfig): SaResult;
|
package/u_metaheur_bg.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* # Returns
|
|
12
12
|
* JS object with `best_distance`, `best_tour`, `generations_run`.
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {GaConfig} config
|
|
14
14
|
* @returns {GaResult}
|
|
15
15
|
*/
|
|
16
16
|
export function run_ga(config) {
|
|
@@ -36,7 +36,7 @@ export function run_ga(config) {
|
|
|
36
36
|
*
|
|
37
37
|
* # Returns
|
|
38
38
|
* JS object with `best_distance`, `best_tour`, `iterations_run`.
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {SaConfig} config
|
|
40
40
|
* @returns {SaResult}
|
|
41
41
|
*/
|
|
42
42
|
export function run_sa(config) {
|
|
@@ -46,7 +46,7 @@ export function run_sa(config) {
|
|
|
46
46
|
}
|
|
47
47
|
return takeFromExternrefTable0(ret[0]);
|
|
48
48
|
}
|
|
49
|
-
export function
|
|
49
|
+
export function __wbg_Error_30c8987f7c2ed4e2(arg0, arg1) {
|
|
50
50
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
51
51
|
return ret;
|
|
52
52
|
}
|
|
@@ -57,56 +57,56 @@ export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
|
57
57
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
58
58
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
59
59
|
}
|
|
60
|
-
export function
|
|
60
|
+
export function __wbg___wbindgen_bigint_get_as_i64_a2383202b9353e4c(arg0, arg1) {
|
|
61
61
|
const v = arg1;
|
|
62
62
|
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
63
63
|
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
64
64
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
65
65
|
}
|
|
66
|
-
export function
|
|
66
|
+
export function __wbg___wbindgen_boolean_get_5b446f51afd21013(arg0) {
|
|
67
67
|
const v = arg0;
|
|
68
68
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
69
69
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
70
70
|
}
|
|
71
|
-
export function
|
|
71
|
+
export function __wbg___wbindgen_debug_string_4687d8d8c2017d52(arg0, arg1) {
|
|
72
72
|
const ret = debugString(arg1);
|
|
73
73
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
74
74
|
const len1 = WASM_VECTOR_LEN;
|
|
75
75
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
76
76
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
77
77
|
}
|
|
78
|
-
export function
|
|
78
|
+
export function __wbg___wbindgen_in_92f62ee1427d9e49(arg0, arg1) {
|
|
79
79
|
const ret = arg0 in arg1;
|
|
80
80
|
return ret;
|
|
81
81
|
}
|
|
82
|
-
export function
|
|
82
|
+
export function __wbg___wbindgen_is_bigint_b123553bed3bb382(arg0) {
|
|
83
83
|
const ret = typeof(arg0) === 'bigint';
|
|
84
84
|
return ret;
|
|
85
85
|
}
|
|
86
|
-
export function
|
|
86
|
+
export function __wbg___wbindgen_is_function_1f9d30630b8b1d3d(arg0) {
|
|
87
87
|
const ret = typeof(arg0) === 'function';
|
|
88
88
|
return ret;
|
|
89
89
|
}
|
|
90
|
-
export function
|
|
90
|
+
export function __wbg___wbindgen_is_object_3c45d4f2dde4e749(arg0) {
|
|
91
91
|
const val = arg0;
|
|
92
92
|
const ret = typeof(val) === 'object' && val !== null;
|
|
93
93
|
return ret;
|
|
94
94
|
}
|
|
95
|
-
export function
|
|
95
|
+
export function __wbg___wbindgen_jsval_eq_02babf21faa37971(arg0, arg1) {
|
|
96
96
|
const ret = arg0 === arg1;
|
|
97
97
|
return ret;
|
|
98
98
|
}
|
|
99
|
-
export function
|
|
99
|
+
export function __wbg___wbindgen_jsval_loose_eq_677f21e468d6b461(arg0, arg1) {
|
|
100
100
|
const ret = arg0 == arg1;
|
|
101
101
|
return ret;
|
|
102
102
|
}
|
|
103
|
-
export function
|
|
103
|
+
export function __wbg___wbindgen_number_get_2e0e7dee9f701a71(arg0, arg1) {
|
|
104
104
|
const obj = arg1;
|
|
105
105
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
106
106
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
107
107
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
108
108
|
}
|
|
109
|
-
export function
|
|
109
|
+
export function __wbg___wbindgen_string_get_0380ccaa2f57f0d9(arg0, arg1) {
|
|
110
110
|
const obj = arg1;
|
|
111
111
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
112
112
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -114,37 +114,37 @@ export function __wbg___wbindgen_string_get_92ab86bb19cbc12f(arg0, arg1) {
|
|
|
114
114
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
115
115
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
116
116
|
}
|
|
117
|
-
export function
|
|
117
|
+
export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
|
|
118
118
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
119
119
|
}
|
|
120
|
-
export function
|
|
120
|
+
export function __wbg_call_6137034ef55c9d0f() { return handleError(function (arg0, arg1) {
|
|
121
121
|
const ret = arg0.call(arg1);
|
|
122
122
|
return ret;
|
|
123
123
|
}, arguments); }
|
|
124
|
-
export function
|
|
124
|
+
export function __wbg_done_b41a1d26cdb37fb6(arg0) {
|
|
125
125
|
const ret = arg0.done;
|
|
126
126
|
return ret;
|
|
127
127
|
}
|
|
128
|
-
export function
|
|
128
|
+
export function __wbg_entries_fb6397112b1de25f(arg0) {
|
|
129
129
|
const ret = Object.entries(arg0);
|
|
130
130
|
return ret;
|
|
131
131
|
}
|
|
132
132
|
export function __wbg_getRandomValues_436a51d0629d84e1() { return handleError(function (arg0, arg1) {
|
|
133
133
|
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
134
134
|
}, arguments); }
|
|
135
|
-
export function
|
|
135
|
+
export function __wbg_get_658f6698067d9515() { return handleError(function (arg0, arg1) {
|
|
136
136
|
const ret = Reflect.get(arg0, arg1);
|
|
137
137
|
return ret;
|
|
138
138
|
}, arguments); }
|
|
139
|
-
export function
|
|
139
|
+
export function __wbg_get_6c896e0571ddae51(arg0, arg1) {
|
|
140
140
|
const ret = arg0[arg1 >>> 0];
|
|
141
141
|
return ret;
|
|
142
142
|
}
|
|
143
|
-
export function
|
|
143
|
+
export function __wbg_get_unchecked_288889d017702237(arg0, arg1) {
|
|
144
144
|
const ret = arg0[arg1 >>> 0];
|
|
145
145
|
return ret;
|
|
146
146
|
}
|
|
147
|
-
export function
|
|
147
|
+
export function __wbg_instanceof_ArrayBuffer_a99f175873e5d9b8(arg0) {
|
|
148
148
|
let result;
|
|
149
149
|
try {
|
|
150
150
|
result = arg0 instanceof ArrayBuffer;
|
|
@@ -154,7 +154,7 @@ export function __wbg_instanceof_ArrayBuffer_d4ff01f8247925ae(arg0) {
|
|
|
154
154
|
const ret = result;
|
|
155
155
|
return ret;
|
|
156
156
|
}
|
|
157
|
-
export function
|
|
157
|
+
export function __wbg_instanceof_Map_b2611749102d7ba3(arg0) {
|
|
158
158
|
let result;
|
|
159
159
|
try {
|
|
160
160
|
result = arg0 instanceof Map;
|
|
@@ -164,7 +164,7 @@ export function __wbg_instanceof_Map_1ff6a2b54c899f0d(arg0) {
|
|
|
164
164
|
const ret = result;
|
|
165
165
|
return ret;
|
|
166
166
|
}
|
|
167
|
-
export function
|
|
167
|
+
export function __wbg_instanceof_Uint8Array_828cef2aaacafc31(arg0) {
|
|
168
168
|
let result;
|
|
169
169
|
try {
|
|
170
170
|
result = arg0 instanceof Uint8Array;
|
|
@@ -174,56 +174,56 @@ export function __wbg_instanceof_Uint8Array_598adc0fef426aa8(arg0) {
|
|
|
174
174
|
const ret = result;
|
|
175
175
|
return ret;
|
|
176
176
|
}
|
|
177
|
-
export function
|
|
177
|
+
export function __wbg_isArray_e15a2ff68ffdbef2(arg0) {
|
|
178
178
|
const ret = Array.isArray(arg0);
|
|
179
179
|
return ret;
|
|
180
180
|
}
|
|
181
|
-
export function
|
|
181
|
+
export function __wbg_isSafeInteger_717808ad6a54bd9e(arg0) {
|
|
182
182
|
const ret = Number.isSafeInteger(arg0);
|
|
183
183
|
return ret;
|
|
184
184
|
}
|
|
185
|
-
export function
|
|
185
|
+
export function __wbg_iterator_e3c31c892080e444() {
|
|
186
186
|
const ret = Symbol.iterator;
|
|
187
187
|
return ret;
|
|
188
188
|
}
|
|
189
|
-
export function
|
|
189
|
+
export function __wbg_length_7f3c00c40364105e(arg0) {
|
|
190
190
|
const ret = arg0.length;
|
|
191
191
|
return ret;
|
|
192
192
|
}
|
|
193
|
-
export function
|
|
193
|
+
export function __wbg_length_d4bdea10311bd9cf(arg0) {
|
|
194
194
|
const ret = arg0.length;
|
|
195
195
|
return ret;
|
|
196
196
|
}
|
|
197
|
-
export function
|
|
197
|
+
export function __wbg_new_1dbf7428bba60a42(arg0) {
|
|
198
198
|
const ret = new Uint8Array(arg0);
|
|
199
199
|
return ret;
|
|
200
200
|
}
|
|
201
|
-
export function
|
|
201
|
+
export function __wbg_new_617a8cdb8bb1130e() {
|
|
202
202
|
const ret = new Object();
|
|
203
203
|
return ret;
|
|
204
204
|
}
|
|
205
|
-
export function
|
|
205
|
+
export function __wbg_new_ee2291f50781bf1d() {
|
|
206
206
|
const ret = new Array();
|
|
207
207
|
return ret;
|
|
208
208
|
}
|
|
209
|
-
export function
|
|
209
|
+
export function __wbg_next_33784799010f1bbe(arg0) {
|
|
210
210
|
const ret = arg0.next;
|
|
211
211
|
return ret;
|
|
212
212
|
}
|
|
213
|
-
export function
|
|
213
|
+
export function __wbg_next_f4aac29c42af995c() { return handleError(function (arg0) {
|
|
214
214
|
const ret = arg0.next();
|
|
215
215
|
return ret;
|
|
216
216
|
}, arguments); }
|
|
217
|
-
export function
|
|
217
|
+
export function __wbg_prototypesetcall_bc27214492979395(arg0, arg1, arg2) {
|
|
218
218
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
219
219
|
}
|
|
220
|
-
export function __wbg_set_13d25b81ab403f5e(arg0, arg1, arg2) {
|
|
221
|
-
arg0[arg1 >>> 0] = arg2;
|
|
222
|
-
}
|
|
223
220
|
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
224
221
|
arg0[arg1] = arg2;
|
|
225
222
|
}
|
|
226
|
-
export function
|
|
223
|
+
export function __wbg_set_bea140a88be9b277(arg0, arg1, arg2) {
|
|
224
|
+
arg0[arg1 >>> 0] = arg2;
|
|
225
|
+
}
|
|
226
|
+
export function __wbg_value_f3c585ee8f5ba40c(arg0) {
|
|
227
227
|
const ret = arg0.value;
|
|
228
228
|
return ret;
|
|
229
229
|
}
|
package/u_metaheur_bg.wasm
CHANGED
|
Binary file
|