@iyulab/u-metaheur 0.9.0 → 0.11.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 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.9"
81
+ u-metaheur = "0.11"
82
82
 
83
83
  # with serde support
84
- u-metaheur = { version = "0.9", features = ["serde"] }
84
+ u-metaheur = { version = "0.11", features = ["serde"] }
85
85
  ```
86
86
 
87
87
  ## Build & Test
@@ -142,6 +142,10 @@ console.log(sa.best_distance, sa.iterations_run);
142
142
  `cooling_rate`. Every setting is optional except `nodes`, and a setting the
143
143
  function does not have is rejected rather than ignored.
144
144
 
145
+ `codes()` returns every refusal `code` the functions throw, with the fields that
146
+ can come with it — `{ refusals: [{ code, fields }], violations: [] }` — built from
147
+ the table the refusals come from; the table below explains each.
148
+
145
149
  ### Errors
146
150
 
147
151
  A refusal throws an `Error` whose `message` is readable text and which carries a
@@ -162,7 +166,7 @@ try {
162
166
  | `insufficient_data` | `parameter` (`"nodes"`), `min`, `got` | Fewer than 2 nodes |
163
167
  | `parameter_out_of_range` | `parameter`, `min`, `max`, `exclusive_min`, `exclusive_max`, `got` | `population_size < 2`, `generations` or `iterations` below 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` |
164
168
  | `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` |
165
- | `malformed_input` | `parameter` | 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 |
169
+ | `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 |
166
170
 
167
171
  ### TypeScript
168
172
 
@@ -1,5 +1,22 @@
1
1
  /* @ts-self-types="./u_metaheur.d.cts" */
2
2
 
3
+ /**
4
+ * Every refusal `code` the functions of this package throw, with the fields
5
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
6
+ *
7
+ * It is built from the table the refusals come from, so a caller that
8
+ * translates codes can check its list against the package's.
9
+ * @returns {Codes}
10
+ */
11
+ function codes() {
12
+ const ret = wasm.codes();
13
+ if (ret[2]) {
14
+ throw takeFromExternrefTable0(ret[1]);
15
+ }
16
+ return takeFromExternrefTable0(ret[0]);
17
+ }
18
+ exports.codes = codes;
19
+
3
20
  /**
4
21
  * Runs a Genetic Algorithm for TSP.
5
22
  *
@@ -1,5 +1,33 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * A refusal reason: the `code` an `Error` carries and the fields that can
5
+ * stand beside it.
6
+ */
7
+ export interface RefusalCode {
8
+ code: string;
9
+ fields: string[];
10
+ }
11
+
12
+ /**
13
+ * A violation a checker reports. This package has no checker; the type is
14
+ * here so every engine's [`Codes`] has one shape.
15
+ */
16
+ export interface ViolationCode {
17
+ code: string;
18
+ fields: string[];
19
+ checkers: string[];
20
+ }
21
+
22
+ /**
23
+ * What this package can answer with besides a result: every refusal
24
+ * `code`, and no violations -- it has no checker.
25
+ */
26
+ export interface Codes {
27
+ refusals: RefusalCode[];
28
+ violations: ViolationCode[];
29
+ }
30
+
3
31
  export interface GaConfig {
4
32
  nodes: [number, number][];
5
33
  /**
@@ -36,6 +64,15 @@ export interface SaResult {
36
64
  }
37
65
 
38
66
 
67
+ /**
68
+ * Every refusal `code` the functions of this package throw, with the fields
69
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
70
+ *
71
+ * It is built from the table the refusals come from, so a caller that
72
+ * translates codes can check its list against the package's.
73
+ */
74
+ export function codes(): Codes;
75
+
39
76
  /**
40
77
  * Runs a Genetic Algorithm for TSP.
41
78
  *
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "iyulab"
6
6
  ],
7
7
  "description": "Domain-agnostic metaheuristic optimization framework: GA, BRKGA, SA, ALNS.",
8
- "version": "0.9.0",
8
+ "version": "0.11.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/u_metaheur.d.ts CHANGED
@@ -1,5 +1,33 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * A refusal reason: the `code` an `Error` carries and the fields that can
5
+ * stand beside it.
6
+ */
7
+ export interface RefusalCode {
8
+ code: string;
9
+ fields: string[];
10
+ }
11
+
12
+ /**
13
+ * A violation a checker reports. This package has no checker; the type is
14
+ * here so every engine's [`Codes`] has one shape.
15
+ */
16
+ export interface ViolationCode {
17
+ code: string;
18
+ fields: string[];
19
+ checkers: string[];
20
+ }
21
+
22
+ /**
23
+ * What this package can answer with besides a result: every refusal
24
+ * `code`, and no violations -- it has no checker.
25
+ */
26
+ export interface Codes {
27
+ refusals: RefusalCode[];
28
+ violations: ViolationCode[];
29
+ }
30
+
3
31
  export interface GaConfig {
4
32
  nodes: [number, number][];
5
33
  /**
@@ -36,6 +64,15 @@ export interface SaResult {
36
64
  }
37
65
 
38
66
 
67
+ /**
68
+ * Every refusal `code` the functions of this package throw, with the fields
69
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
70
+ *
71
+ * It is built from the table the refusals come from, so a caller that
72
+ * translates codes can check its list against the package's.
73
+ */
74
+ export function codes(): Codes;
75
+
39
76
  /**
40
77
  * Runs a Genetic Algorithm for TSP.
41
78
  *
package/u_metaheur.js CHANGED
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./u_metaheur_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- run_ga, run_sa
8
+ codes, run_ga, run_sa
9
9
  } from "./u_metaheur_bg.js";
package/u_metaheur_bg.js CHANGED
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Every refusal `code` the functions of this package throw, with the fields
3
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
4
+ *
5
+ * It is built from the table the refusals come from, so a caller that
6
+ * translates codes can check its list against the package's.
7
+ * @returns {Codes}
8
+ */
9
+ export function codes() {
10
+ const ret = wasm.codes();
11
+ if (ret[2]) {
12
+ throw takeFromExternrefTable0(ret[1]);
13
+ }
14
+ return takeFromExternrefTable0(ret[0]);
15
+ }
16
+
1
17
  /**
2
18
  * Runs a Genetic Algorithm for TSP.
3
19
  *
Binary file