MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / generateAssignments

Function generateAssignments

scripts/fungrim/sample.ts:178–203  ·  view source on GitHub ↗
(
  variables: string[],
  domains: Record<string, Json>,
  seed: number,
  maxCandidates: number
)

Source from the content-addressed store, hash-verified

176 * accepted instances.
177 */
178export function generateAssignments(
179 variables: string[],
180 domains: Record<string, Json>,
181 seed: number,
182 maxCandidates: number
183): Assignment[] {
184 if (variables.length === 0) return [{}];
185 const rng = mulberry32(seed);
186 const pools = variables.map((v) => poolForDomain(domains[v]));
187 const seen = new Set<string>();
188 const out: Assignment[] = [];
189 const space = pools.reduce((acc, p) => acc * p.length, 1);
190 const tries = Math.min(maxCandidates * 4, space * 2, 400);
191 for (let t = 0; t < tries && out.length < maxCandidates; t++) {
192 const a: Assignment = {};
193 for (let i = 0; i < variables.length; i++) {
194 const pool = pools[i];
195 a[variables[i]] = pool[Math.floor(rng() * pool.length)];
196 }
197 const key = JSON.stringify(a);
198 if (seen.has(key)) continue;
199 seen.add(key);
200 out.push(a);
201 }
202 return out;
203}

Callers 1

numericCheckEntryFunction · 0.90

Calls 6

poolForDomainFunction · 0.85
mulberry32Function · 0.70
mapMethod · 0.65
hasMethod · 0.65
addMethod · 0.65
floorMethod · 0.45

Tested by

no test coverage detected