MapSetVisitor

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.

Constructors

this
this(Set set)
Undocumented in source.

Members

Aliases

Set
alias Set = MapSet!(A, V)
Undocumented in source.

Functions

get
V get(A name)

Algorithm interface - get a value by name

next
bool next()

Returns true if there are more states to iterate over, otherwise returns false

put
void put(A name, V value)

Algorithm interface - set a value by name

reset
void reset()

Resets iteration to the beginning. Equivalent to but faster than constructing a new MapSetVisitor instance (visitor = MapSetVisitor(visitor.set)).

transform
void transform(A name, void delegate(ref V value) fun)

Apply a function over every possible value of the given variable, without resolving it (unless it's already resolved).

Structs

Var
struct Var
Undocumented in source.

Variables

currentSubset
Set currentSubset;
resolvedValues
V[A] resolvedValues;
Undocumented in source.
set
Set set;
Undocumented in source.
singularValues
V[A] singularValues;
Undocumented in source.
stack
Var[] stack;
Undocumented in source.

Examples

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);

Meta