@iyulab/u-metaheur 0.12.1 → 0.14.0
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 +20 -10
- package/node/u_metaheur.cjs +47 -13
- package/node/u_metaheur.d.cts +48 -13
- package/node/u_metaheur_bg.wasm +0 -0
- package/package.json +1 -1
- package/u_metaheur.d.ts +48 -13
- package/u_metaheur_bg.js +47 -13
- package/u_metaheur_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -78,10 +78,10 @@ assert!((result.best - 3.0).abs() < 0.1);
|
|
|
78
78
|
|
|
79
79
|
```toml
|
|
80
80
|
[dependencies]
|
|
81
|
-
u-metaheur = "0.
|
|
81
|
+
u-metaheur = "0.14"
|
|
82
82
|
|
|
83
83
|
# with serde support
|
|
84
|
-
u-metaheur = { version = "0.
|
|
84
|
+
u-metaheur = { version = "0.14", features = ["serde"] }
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
## Build & Test
|
|
@@ -123,8 +123,9 @@ re-bundling services fail on the same import. Use a bundler or Node.
|
|
|
123
123
|
|
|
124
124
|
### Quick Start
|
|
125
125
|
|
|
126
|
-
Both functions
|
|
127
|
-
|
|
126
|
+
Both functions run this crate's own runners — `GaRunner` and `SaRunner` — on a
|
|
127
|
+
travelling-salesman tour over `nodes` (`[x, y]` pairs), and return the best tour
|
|
128
|
+
found, its closed length, and why the run stopped:
|
|
128
129
|
|
|
129
130
|
```js
|
|
130
131
|
import { run_ga, run_sa } from '@iyulab/u-metaheur';
|
|
@@ -132,15 +133,24 @@ import { run_ga, run_sa } from '@iyulab/u-metaheur';
|
|
|
132
133
|
// The corners of a unit square: the shortest closed tour is its perimeter, 4.
|
|
133
134
|
const nodes = [[0, 0], [1, 0], [1, 1], [0, 1]];
|
|
134
135
|
|
|
135
|
-
const ga = run_ga({ nodes, population_size: 30, generations: 50 });
|
|
136
|
-
const sa = run_sa({ nodes, iterations: 2000 });
|
|
137
|
-
console.log(ga.best_distance, ga.best_tour); // 4 [ ... ]
|
|
136
|
+
const ga = run_ga({ nodes, population_size: 30, generations: 50, seed: 7 });
|
|
137
|
+
const sa = run_sa({ nodes, iterations: 2000, seed: 7 });
|
|
138
|
+
console.log(ga.best_distance, ga.best_tour, ga.stop_reason); // 4 [ ... ] iteration_limit
|
|
138
139
|
console.log(sa.best_distance, sa.iterations_run);
|
|
140
|
+
|
|
141
|
+
// The same seed gives the same tour.
|
|
142
|
+
console.log(run_ga({ nodes, population_size: 30, generations: 50, seed: 7 }).best_tour.join() === ga.best_tour.join()); // true
|
|
139
143
|
```
|
|
140
144
|
|
|
141
145
|
`run_ga` also takes `mutation_rate`; `run_sa` takes `initial_temp` and
|
|
142
|
-
`cooling_rate`.
|
|
143
|
-
|
|
146
|
+
`cooling_rate`. Both take `seed` (a whole number from 0 to 2^64 − 1 — a run that
|
|
147
|
+
ends on its own budget is reproduced exactly) and `time_limit_ms` (at least 1 —
|
|
148
|
+
the run returns the best tour found by then). `stop_reason` is
|
|
149
|
+
`"iteration_limit"` when the run spent its `generations` / `iterations`,
|
|
150
|
+
`"time_limit"` when the clock ran out first, and for `run_sa` `"completed"` when
|
|
151
|
+
the temperature cooled to nothing first. Every setting is optional except
|
|
152
|
+
`nodes`, and a setting the function does not have is rejected rather than
|
|
153
|
+
ignored.
|
|
144
154
|
|
|
145
155
|
`codes()` returns every refusal `code` the functions throw, with the fields that
|
|
146
156
|
can come with it — `{ refusals: [{ code, fields }], violations: [] }` — built from
|
|
@@ -164,7 +174,7 @@ try {
|
|
|
164
174
|
| `code` | Fields | Meaning |
|
|
165
175
|
|---|---|---|
|
|
166
176
|
| `insufficient_data` | `parameter` (`"nodes"`), `min`, `got` | Fewer than 2 nodes |
|
|
167
|
-
| `parameter_out_of_range` | `parameter`, `min`, `max`, `exclusive_min`, `exclusive_max`, `got` | `population_size < 2`, `generations` or `
|
|
177
|
+
| `parameter_out_of_range` | `parameter`, `min`, `max`, `exclusive_min`, `exclusive_max`, `got` | `population_size < 2`, `generations`, `iterations` or `time_limit_ms` below 1, a `seed` outside 0 to 2^64 − 1 (a negative count included: `population_size: -1` is `{ min: 2, max: null, got: -1 }`, the same as `1`), `initial_temp ≤ 0`, or `cooling_rate` outside (0, 1). `min` / `max` are the closed (included) bounds and are always present — `null` on a side that is open or unbounded; `exclusive_min` / `exclusive_max` are the open (excluded) bounds, present only when that end is open: `initial_temp` (> 0) is refused with `min: null, exclusive_min: 0`, `cooling_rate` with `exclusive_min: 0, exclusive_max: 1` |
|
|
168
178
|
| `value_not_finite` | `parameter`, `index` | A NaN or ±Infinity anywhere in an argument — `parameter` is the path to it (`config.nodes[1]`), `index` its position in that array, or `null` |
|
|
169
179
|
| `malformed_input` | `parameter`, `index` (inside an array) | An argument of the wrong shape or type (a missing or unknown key), a count that is not a whole number (`population_size: 2.5` — `parameter` is the field), or a JSON string |
|
|
170
180
|
| `internal` | — | A result the package could not hand back — a fault in the package, not in the input; please report it |
|
package/node/u_metaheur.cjs
CHANGED
|
@@ -18,17 +18,22 @@ function codes() {
|
|
|
18
18
|
exports.codes = codes;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Runs
|
|
21
|
+
* Runs the crate's genetic algorithm ([`crate::ga::GaRunner`]) on the
|
|
22
|
+
* travelling-salesman tour over `nodes`: order crossover, swap mutation,
|
|
23
|
+
* tournament selection, a nearest-neighbour tour in the first population.
|
|
22
24
|
*
|
|
23
25
|
* # Arguments
|
|
24
26
|
* `config` — native JS object with fields:
|
|
25
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
26
|
-
* - `population_size`: integer (default 100)
|
|
27
|
-
* - `generations`: integer (default 200)
|
|
27
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
28
|
+
* - `population_size`: integer (default 100, at least 2)
|
|
29
|
+
* - `generations`: integer (default 200, at least 1) — run as given
|
|
28
30
|
* - `mutation_rate`: float 0–1 (default 0.05)
|
|
31
|
+
* - `seed`: whole number 0 to 2^64 − 1 (optional) — reproducible runs
|
|
32
|
+
* - `time_limit_ms`: whole number, at least 1 (optional)
|
|
29
33
|
*
|
|
30
34
|
* # Returns
|
|
31
|
-
* JS object with `best_distance`, `best_tour`, `generations_run
|
|
35
|
+
* JS object with `best_distance`, `best_tour`, `generations_run`,
|
|
36
|
+
* `stop_reason`.
|
|
32
37
|
* @param {GaConfig} config
|
|
33
38
|
* @returns {GaResult}
|
|
34
39
|
*/
|
|
@@ -42,20 +47,21 @@ function run_ga(config) {
|
|
|
42
47
|
exports.run_ga = run_ga;
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
|
-
* Runs
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Neighbour move: 2-opt segment reversal between two random positions.
|
|
50
|
+
* Runs the crate's simulated annealing ([`crate::sa::SaRunner`]) on the
|
|
51
|
+
* travelling-salesman tour over `nodes`, from the nearest-neighbour tour,
|
|
52
|
+
* with 2-opt moves and geometric cooling (`T *= cooling_rate` per move).
|
|
49
53
|
*
|
|
50
54
|
* # Arguments
|
|
51
55
|
* `config` — native JS object with fields:
|
|
52
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
53
|
-
* - `initial_temp`: float (default 1000.0)
|
|
56
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
57
|
+
* - `initial_temp`: float (default 1000.0, > 0)
|
|
54
58
|
* - `cooling_rate`: float in (0, 1) (default 0.995)
|
|
55
|
-
* - `iterations`: integer (default 5000)
|
|
59
|
+
* - `iterations`: integer (default 5000, at least 1)
|
|
60
|
+
* - `seed`, `time_limit_ms`: as `run_ga`'s
|
|
56
61
|
*
|
|
57
62
|
* # Returns
|
|
58
|
-
* JS object with `best_distance`, `best_tour`, `iterations_run
|
|
63
|
+
* JS object with `best_distance`, `best_tour`, `iterations_run`,
|
|
64
|
+
* `stop_reason`.
|
|
59
65
|
* @param {SaConfig} config
|
|
60
66
|
* @returns {SaResult}
|
|
61
67
|
*/
|
|
@@ -120,6 +126,10 @@ function __wbg_get_imports() {
|
|
|
120
126
|
const ret = typeof(arg0) === 'string';
|
|
121
127
|
return ret;
|
|
122
128
|
},
|
|
129
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
130
|
+
const ret = arg0 === undefined;
|
|
131
|
+
return ret;
|
|
132
|
+
},
|
|
123
133
|
__wbg___wbindgen_jsval_eq_02babf21faa37971: function(arg0, arg1) {
|
|
124
134
|
const ret = arg0 === arg1;
|
|
125
135
|
return ret;
|
|
@@ -254,6 +264,14 @@ function __wbg_get_imports() {
|
|
|
254
264
|
const ret = arg0.next();
|
|
255
265
|
return ret;
|
|
256
266
|
}, arguments); },
|
|
267
|
+
__wbg_now_e7c6795a7f81e10f: function(arg0) {
|
|
268
|
+
const ret = arg0.now();
|
|
269
|
+
return ret;
|
|
270
|
+
},
|
|
271
|
+
__wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
|
|
272
|
+
const ret = arg0.performance;
|
|
273
|
+
return ret;
|
|
274
|
+
},
|
|
257
275
|
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
258
276
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
259
277
|
},
|
|
@@ -267,6 +285,22 @@ function __wbg_get_imports() {
|
|
|
267
285
|
__wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
|
|
268
286
|
arg0[arg1 >>> 0] = arg2;
|
|
269
287
|
},
|
|
288
|
+
__wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
|
|
289
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
290
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
291
|
+
},
|
|
292
|
+
__wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
|
|
293
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
294
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
295
|
+
},
|
|
296
|
+
__wbg_static_accessor_SELF_0b583911f537483a: function() {
|
|
297
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
298
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
299
|
+
},
|
|
300
|
+
__wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
|
|
301
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
302
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
303
|
+
},
|
|
270
304
|
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
|
|
271
305
|
const ret = arg0.value;
|
|
272
306
|
return ret;
|
package/node/u_metaheur.d.cts
CHANGED
|
@@ -39,12 +39,27 @@ export interface GaConfig {
|
|
|
39
39
|
*/
|
|
40
40
|
generations?: number;
|
|
41
41
|
mutation_rate?: number;
|
|
42
|
+
/**
|
|
43
|
+
* RNG seed, a whole number from 0 to 2^64 - 1: the same request and seed
|
|
44
|
+
* give the same tour when the run ends on its own budget.
|
|
45
|
+
*/
|
|
46
|
+
seed?: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Wall-clock budget in milliseconds, at least 1: the run returns the best
|
|
49
|
+
* tour found by then (`stop_reason: "time_limit"`).
|
|
50
|
+
*/
|
|
51
|
+
time_limit_ms?: number | null;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
export interface GaResult {
|
|
45
55
|
best_distance: number;
|
|
46
56
|
best_tour: number[];
|
|
47
57
|
generations_run: number;
|
|
58
|
+
/**
|
|
59
|
+
* Why the run stopped: `"iteration_limit"` (it ran its `generations`) or
|
|
60
|
+
* `"time_limit"`.
|
|
61
|
+
*/
|
|
62
|
+
stop_reason: "iteration_limit" | "time_limit";
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
export interface SaConfig {
|
|
@@ -55,12 +70,26 @@ export interface SaConfig {
|
|
|
55
70
|
* At least 1 (`run_sa` checks it; see [`Whole`] for why it is signed).
|
|
56
71
|
*/
|
|
57
72
|
iterations?: number;
|
|
73
|
+
/**
|
|
74
|
+
* RNG seed, a whole number from 0 to 2^64 - 1 (as `run_ga`'s).
|
|
75
|
+
*/
|
|
76
|
+
seed?: number | null;
|
|
77
|
+
/**
|
|
78
|
+
* Wall-clock budget in milliseconds, at least 1 (as `run_ga`'s).
|
|
79
|
+
*/
|
|
80
|
+
time_limit_ms?: number | null;
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
export interface SaResult {
|
|
61
84
|
best_distance: number;
|
|
62
85
|
best_tour: number[];
|
|
63
86
|
iterations_run: number;
|
|
87
|
+
/**
|
|
88
|
+
* Why the run stopped: `"iteration_limit"` (it ran its `iterations`),
|
|
89
|
+
* `"completed"` (the temperature cooled to nothing first) or
|
|
90
|
+
* `"time_limit"`.
|
|
91
|
+
*/
|
|
92
|
+
stop_reason: "iteration_limit" | "completed" | "time_limit";
|
|
64
93
|
}
|
|
65
94
|
|
|
66
95
|
|
|
@@ -74,34 +103,40 @@ export interface SaResult {
|
|
|
74
103
|
export function codes(): Codes;
|
|
75
104
|
|
|
76
105
|
/**
|
|
77
|
-
* Runs
|
|
106
|
+
* Runs the crate's genetic algorithm ([`crate::ga::GaRunner`]) on the
|
|
107
|
+
* travelling-salesman tour over `nodes`: order crossover, swap mutation,
|
|
108
|
+
* tournament selection, a nearest-neighbour tour in the first population.
|
|
78
109
|
*
|
|
79
110
|
* # Arguments
|
|
80
111
|
* `config` — native JS object with fields:
|
|
81
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
82
|
-
* - `population_size`: integer (default 100)
|
|
83
|
-
* - `generations`: integer (default 200)
|
|
112
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
113
|
+
* - `population_size`: integer (default 100, at least 2)
|
|
114
|
+
* - `generations`: integer (default 200, at least 1) — run as given
|
|
84
115
|
* - `mutation_rate`: float 0–1 (default 0.05)
|
|
116
|
+
* - `seed`: whole number 0 to 2^64 − 1 (optional) — reproducible runs
|
|
117
|
+
* - `time_limit_ms`: whole number, at least 1 (optional)
|
|
85
118
|
*
|
|
86
119
|
* # Returns
|
|
87
|
-
* JS object with `best_distance`, `best_tour`, `generations_run
|
|
120
|
+
* JS object with `best_distance`, `best_tour`, `generations_run`,
|
|
121
|
+
* `stop_reason`.
|
|
88
122
|
*/
|
|
89
123
|
export function run_ga(config: GaConfig): GaResult;
|
|
90
124
|
|
|
91
125
|
/**
|
|
92
|
-
* Runs
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* Neighbour move: 2-opt segment reversal between two random positions.
|
|
126
|
+
* Runs the crate's simulated annealing ([`crate::sa::SaRunner`]) on the
|
|
127
|
+
* travelling-salesman tour over `nodes`, from the nearest-neighbour tour,
|
|
128
|
+
* with 2-opt moves and geometric cooling (`T *= cooling_rate` per move).
|
|
96
129
|
*
|
|
97
130
|
* # Arguments
|
|
98
131
|
* `config` — native JS object with fields:
|
|
99
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
100
|
-
* - `initial_temp`: float (default 1000.0)
|
|
132
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
133
|
+
* - `initial_temp`: float (default 1000.0, > 0)
|
|
101
134
|
* - `cooling_rate`: float in (0, 1) (default 0.995)
|
|
102
|
-
* - `iterations`: integer (default 5000)
|
|
135
|
+
* - `iterations`: integer (default 5000, at least 1)
|
|
136
|
+
* - `seed`, `time_limit_ms`: as `run_ga`'s
|
|
103
137
|
*
|
|
104
138
|
* # Returns
|
|
105
|
-
* JS object with `best_distance`, `best_tour`, `iterations_run
|
|
139
|
+
* JS object with `best_distance`, `best_tour`, `iterations_run`,
|
|
140
|
+
* `stop_reason`.
|
|
106
141
|
*/
|
|
107
142
|
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
|
@@ -39,12 +39,27 @@ export interface GaConfig {
|
|
|
39
39
|
*/
|
|
40
40
|
generations?: number;
|
|
41
41
|
mutation_rate?: number;
|
|
42
|
+
/**
|
|
43
|
+
* RNG seed, a whole number from 0 to 2^64 - 1: the same request and seed
|
|
44
|
+
* give the same tour when the run ends on its own budget.
|
|
45
|
+
*/
|
|
46
|
+
seed?: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Wall-clock budget in milliseconds, at least 1: the run returns the best
|
|
49
|
+
* tour found by then (`stop_reason: "time_limit"`).
|
|
50
|
+
*/
|
|
51
|
+
time_limit_ms?: number | null;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
export interface GaResult {
|
|
45
55
|
best_distance: number;
|
|
46
56
|
best_tour: number[];
|
|
47
57
|
generations_run: number;
|
|
58
|
+
/**
|
|
59
|
+
* Why the run stopped: `"iteration_limit"` (it ran its `generations`) or
|
|
60
|
+
* `"time_limit"`.
|
|
61
|
+
*/
|
|
62
|
+
stop_reason: "iteration_limit" | "time_limit";
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
export interface SaConfig {
|
|
@@ -55,12 +70,26 @@ export interface SaConfig {
|
|
|
55
70
|
* At least 1 (`run_sa` checks it; see [`Whole`] for why it is signed).
|
|
56
71
|
*/
|
|
57
72
|
iterations?: number;
|
|
73
|
+
/**
|
|
74
|
+
* RNG seed, a whole number from 0 to 2^64 - 1 (as `run_ga`'s).
|
|
75
|
+
*/
|
|
76
|
+
seed?: number | null;
|
|
77
|
+
/**
|
|
78
|
+
* Wall-clock budget in milliseconds, at least 1 (as `run_ga`'s).
|
|
79
|
+
*/
|
|
80
|
+
time_limit_ms?: number | null;
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
export interface SaResult {
|
|
61
84
|
best_distance: number;
|
|
62
85
|
best_tour: number[];
|
|
63
86
|
iterations_run: number;
|
|
87
|
+
/**
|
|
88
|
+
* Why the run stopped: `"iteration_limit"` (it ran its `iterations`),
|
|
89
|
+
* `"completed"` (the temperature cooled to nothing first) or
|
|
90
|
+
* `"time_limit"`.
|
|
91
|
+
*/
|
|
92
|
+
stop_reason: "iteration_limit" | "completed" | "time_limit";
|
|
64
93
|
}
|
|
65
94
|
|
|
66
95
|
|
|
@@ -74,34 +103,40 @@ export interface SaResult {
|
|
|
74
103
|
export function codes(): Codes;
|
|
75
104
|
|
|
76
105
|
/**
|
|
77
|
-
* Runs
|
|
106
|
+
* Runs the crate's genetic algorithm ([`crate::ga::GaRunner`]) on the
|
|
107
|
+
* travelling-salesman tour over `nodes`: order crossover, swap mutation,
|
|
108
|
+
* tournament selection, a nearest-neighbour tour in the first population.
|
|
78
109
|
*
|
|
79
110
|
* # Arguments
|
|
80
111
|
* `config` — native JS object with fields:
|
|
81
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
82
|
-
* - `population_size`: integer (default 100)
|
|
83
|
-
* - `generations`: integer (default 200)
|
|
112
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
113
|
+
* - `population_size`: integer (default 100, at least 2)
|
|
114
|
+
* - `generations`: integer (default 200, at least 1) — run as given
|
|
84
115
|
* - `mutation_rate`: float 0–1 (default 0.05)
|
|
116
|
+
* - `seed`: whole number 0 to 2^64 − 1 (optional) — reproducible runs
|
|
117
|
+
* - `time_limit_ms`: whole number, at least 1 (optional)
|
|
85
118
|
*
|
|
86
119
|
* # Returns
|
|
87
|
-
* JS object with `best_distance`, `best_tour`, `generations_run
|
|
120
|
+
* JS object with `best_distance`, `best_tour`, `generations_run`,
|
|
121
|
+
* `stop_reason`.
|
|
88
122
|
*/
|
|
89
123
|
export function run_ga(config: GaConfig): GaResult;
|
|
90
124
|
|
|
91
125
|
/**
|
|
92
|
-
* Runs
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* Neighbour move: 2-opt segment reversal between two random positions.
|
|
126
|
+
* Runs the crate's simulated annealing ([`crate::sa::SaRunner`]) on the
|
|
127
|
+
* travelling-salesman tour over `nodes`, from the nearest-neighbour tour,
|
|
128
|
+
* with 2-opt moves and geometric cooling (`T *= cooling_rate` per move).
|
|
96
129
|
*
|
|
97
130
|
* # Arguments
|
|
98
131
|
* `config` — native JS object with fields:
|
|
99
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
100
|
-
* - `initial_temp`: float (default 1000.0)
|
|
132
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
133
|
+
* - `initial_temp`: float (default 1000.0, > 0)
|
|
101
134
|
* - `cooling_rate`: float in (0, 1) (default 0.995)
|
|
102
|
-
* - `iterations`: integer (default 5000)
|
|
135
|
+
* - `iterations`: integer (default 5000, at least 1)
|
|
136
|
+
* - `seed`, `time_limit_ms`: as `run_ga`'s
|
|
103
137
|
*
|
|
104
138
|
* # Returns
|
|
105
|
-
* JS object with `best_distance`, `best_tour`, `iterations_run
|
|
139
|
+
* JS object with `best_distance`, `best_tour`, `iterations_run`,
|
|
140
|
+
* `stop_reason`.
|
|
106
141
|
*/
|
|
107
142
|
export function run_sa(config: SaConfig): SaResult;
|
package/u_metaheur_bg.js
CHANGED
|
@@ -15,17 +15,22 @@ export function codes() {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Runs
|
|
18
|
+
* Runs the crate's genetic algorithm ([`crate::ga::GaRunner`]) on the
|
|
19
|
+
* travelling-salesman tour over `nodes`: order crossover, swap mutation,
|
|
20
|
+
* tournament selection, a nearest-neighbour tour in the first population.
|
|
19
21
|
*
|
|
20
22
|
* # Arguments
|
|
21
23
|
* `config` — native JS object with fields:
|
|
22
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
23
|
-
* - `population_size`: integer (default 100)
|
|
24
|
-
* - `generations`: integer (default 200)
|
|
24
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
25
|
+
* - `population_size`: integer (default 100, at least 2)
|
|
26
|
+
* - `generations`: integer (default 200, at least 1) — run as given
|
|
25
27
|
* - `mutation_rate`: float 0–1 (default 0.05)
|
|
28
|
+
* - `seed`: whole number 0 to 2^64 − 1 (optional) — reproducible runs
|
|
29
|
+
* - `time_limit_ms`: whole number, at least 1 (optional)
|
|
26
30
|
*
|
|
27
31
|
* # Returns
|
|
28
|
-
* JS object with `best_distance`, `best_tour`, `generations_run
|
|
32
|
+
* JS object with `best_distance`, `best_tour`, `generations_run`,
|
|
33
|
+
* `stop_reason`.
|
|
29
34
|
* @param {GaConfig} config
|
|
30
35
|
* @returns {GaResult}
|
|
31
36
|
*/
|
|
@@ -38,20 +43,21 @@ export function run_ga(config) {
|
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
|
-
* Runs
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* Neighbour move: 2-opt segment reversal between two random positions.
|
|
46
|
+
* Runs the crate's simulated annealing ([`crate::sa::SaRunner`]) on the
|
|
47
|
+
* travelling-salesman tour over `nodes`, from the nearest-neighbour tour,
|
|
48
|
+
* with 2-opt moves and geometric cooling (`T *= cooling_rate` per move).
|
|
45
49
|
*
|
|
46
50
|
* # Arguments
|
|
47
51
|
* `config` — native JS object with fields:
|
|
48
|
-
* - `nodes`: `[[x, y], ...]` (required)
|
|
49
|
-
* - `initial_temp`: float (default 1000.0)
|
|
52
|
+
* - `nodes`: `[[x, y], ...]` (required, at least 2)
|
|
53
|
+
* - `initial_temp`: float (default 1000.0, > 0)
|
|
50
54
|
* - `cooling_rate`: float in (0, 1) (default 0.995)
|
|
51
|
-
* - `iterations`: integer (default 5000)
|
|
55
|
+
* - `iterations`: integer (default 5000, at least 1)
|
|
56
|
+
* - `seed`, `time_limit_ms`: as `run_ga`'s
|
|
52
57
|
*
|
|
53
58
|
* # Returns
|
|
54
|
-
* JS object with `best_distance`, `best_tour`, `iterations_run
|
|
59
|
+
* JS object with `best_distance`, `best_tour`, `iterations_run`,
|
|
60
|
+
* `stop_reason`.
|
|
55
61
|
* @param {SaConfig} config
|
|
56
62
|
* @returns {SaResult}
|
|
57
63
|
*/
|
|
@@ -112,6 +118,10 @@ export function __wbg___wbindgen_is_string_90b56bc79aad6f6c(arg0) {
|
|
|
112
118
|
const ret = typeof(arg0) === 'string';
|
|
113
119
|
return ret;
|
|
114
120
|
}
|
|
121
|
+
export function __wbg___wbindgen_is_undefined_8865fb403f8fe9d8(arg0) {
|
|
122
|
+
const ret = arg0 === undefined;
|
|
123
|
+
return ret;
|
|
124
|
+
}
|
|
115
125
|
export function __wbg___wbindgen_jsval_eq_02babf21faa37971(arg0, arg1) {
|
|
116
126
|
const ret = arg0 === arg1;
|
|
117
127
|
return ret;
|
|
@@ -246,6 +256,14 @@ export function __wbg_next_f4aac29c42af995c() { return handleError(function (arg
|
|
|
246
256
|
const ret = arg0.next();
|
|
247
257
|
return ret;
|
|
248
258
|
}, arguments); }
|
|
259
|
+
export function __wbg_now_e7c6795a7f81e10f(arg0) {
|
|
260
|
+
const ret = arg0.now();
|
|
261
|
+
return ret;
|
|
262
|
+
}
|
|
263
|
+
export function __wbg_performance_3fcf6e32a7e1ed0a(arg0) {
|
|
264
|
+
const ret = arg0.performance;
|
|
265
|
+
return ret;
|
|
266
|
+
}
|
|
249
267
|
export function __wbg_prototypesetcall_bc27214492979395(arg0, arg1, arg2) {
|
|
250
268
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
251
269
|
}
|
|
@@ -259,6 +277,22 @@ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
|
259
277
|
export function __wbg_set_bea140a88be9b277(arg0, arg1, arg2) {
|
|
260
278
|
arg0[arg1 >>> 0] = arg2;
|
|
261
279
|
}
|
|
280
|
+
export function __wbg_static_accessor_GLOBAL_266715b9d96ba635() {
|
|
281
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
282
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
283
|
+
}
|
|
284
|
+
export function __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179() {
|
|
285
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
286
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
287
|
+
}
|
|
288
|
+
export function __wbg_static_accessor_SELF_0b583911f537483a() {
|
|
289
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
290
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
291
|
+
}
|
|
292
|
+
export function __wbg_static_accessor_WINDOW_d7f903d1508cbdc4() {
|
|
293
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
294
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
295
|
+
}
|
|
262
296
|
export function __wbg_value_f3c585ee8f5ba40c(arg0) {
|
|
263
297
|
const ret = arg0.value;
|
|
264
298
|
return ret;
|
package/u_metaheur_bg.wasm
CHANGED
|
Binary file
|