aboutsummaryrefslogtreecommitdiff
path: root/packages/anastasis-core/src/policy-suggestion.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/anastasis-core/src/policy-suggestion.ts')
-rw-r--r--packages/anastasis-core/src/policy-suggestion.ts25
1 files changed, 19 insertions, 6 deletions
diff --git a/packages/anastasis-core/src/policy-suggestion.ts b/packages/anastasis-core/src/policy-suggestion.ts
index 7eb6c21cc..2c25caaa4 100644
--- a/packages/anastasis-core/src/policy-suggestion.ts
+++ b/packages/anastasis-core/src/policy-suggestion.ts
@@ -84,9 +84,16 @@ function assignProviders(
for (const provSel of providerSelections) {
// First, check if selection is even possible with the methods offered
let possible = true;
- for (const methIndex in provSel) {
- const provIndex = provSel[methIndex];
+ for (const methSelIndex in provSel) {
+ const provIndex = provSel[methSelIndex];
+ if (typeof provIndex !== "number") {
+ throw Error("invariant failed");
+ }
+ const methIndex = methodSelection[methSelIndex];
const meth = methods[methIndex];
+ if (!meth) {
+ throw Error("invariant failed");
+ }
const prov = providers[provIndex];
if (!prov.methodCost[meth.type]) {
possible = false;
@@ -96,7 +103,6 @@ function assignProviders(
if (!possible) {
continue;
}
-
// Evaluate diversity, always prefer policies
// that increase diversity.
const providerSet = new Set<string>();
@@ -163,10 +169,19 @@ function assignProviders(
/**
* A provider selection maps a method selection index to a provider index.
+ *
+ * I.e. "PSEL[i] = x" means that provider with index "x" should be used
+ * for method with index "MSEL[i]"
*/
type ProviderSelection = number[];
/**
+ * A method selection "MSEL[j] = y" means that policy method j
+ * should use method y.
+ */
+type MethodSelection = number[];
+
+/**
* Compute provider mappings.
* Enumerates all n-combinations with repetition of m providers.
*/
@@ -184,7 +199,7 @@ function enumerateProviderMappings(
}
for (let j = start; j < m; j++) {
a[i] = j;
- sel(i + 1, j);
+ sel(i + 1, 0);
if (limit && selections.length >= limit) {
break;
}
@@ -199,8 +214,6 @@ interface PolicySelectionResult {
policy_providers: PolicyProvider[];
}
-type MethodSelection = number[];
-
/**
* Compute method selections.
* Enumerates all n-combinations without repetition of m methods.