Algorithm interface - get a value by name
Inject a variable and values to iterate over. The variable must not have been resolved yet.
Apply a function over every possible value of the given variable, without resolving it (unless it's already resolved). The function is assumed to be injective (does not produce duplicate outputs for distinct inputs).
Returns true if there are more states to iterate over, otherwise returns false
Algorithm interface - set a value by name
Resets iteration to the beginning. Equivalent to but faster than constructing a new MapSetVisitor instance (visitor = MapSetVisitor(visitor.set)).
Apply a function over every possible value of the given variable, without resolving it (unless it's already resolved).
An algorithm which divides two numbers. When the divisor is zero, we don't even query the dividend, therefore processing all dividends in one iteration.
alias M = MapSet!(string, int); M m = M.unitSet .cartesianProduct("divisor" , [0, 1, 2]) .cartesianProduct("dividend", [0, 1, 2]); assert(m.count == 9); auto v = MapSetVisitor!(string, int)(m); M results; int iterations; while (v.next()) { iterations++; auto divisor = v.get("divisor"); if (divisor == 0) continue; auto dividend = v.get("dividend"); v.put("quotient", dividend / divisor); results = results.merge(v.currentSubset); } assert(iterations == 7); // 1 for division by zero + 3 for division by one + 3 for division by two assert(results.get("divisor", 2).get("dividend", 2).all("quotient") == [1]); assert(results.get("divisor", 0).count == 0);
Allows executing a deterministic algorithm over all states in a given MapSet. If a variable is not queried by the algorithm, states for all variations of that variable are processed in one iteration.