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.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

Set
alias Set = MapSet!(A, V, nullValue)

Underlying MapSet.

Functions

copy
void copy(A source, A target)

Algorithm interface - copy a value target another name, without resolving it (unless it's already resolved).

dup
MapSetVisitor dup()
Undocumented in source. Be warned that the author may not have intended to support it.
get
V get(A name)

Algorithm interface - get a value by name

getAll
const(V)[] getAll(A name)

Get all possible values for this variable at this point. Should be used mainly for debugging.

inject
void inject(A name, V[] values)

Inject a variable and values to iterate over. The variable must not have been resolved yet.

injectiveTransform
void injectiveTransform(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). The function is assumed to be injective (does not produce duplicate outputs for distinct inputs).

multiTransform
void multiTransform(A[] inputs, A[] outputs, void delegate(scope V[] inputValues, scope V[] outputValues) fun)

Perform a transformation with multiple inputs and outputs. Inputs and outputs must not overlap. Can be used to perform binary operations, copy-transforms, and more.

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

targetTransform
void targetTransform(A input, A output, void delegate(ref const V inputValue, out V outputValue) fun)

Perform a transformation with one input and one output. Does not reorder the MapSet.

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

Properties

currentSubset
Set currentSubset [@property getter]

Peek at the subset the algorithm is currently working with.

Structs

Var
struct Var

Internal state.

VarState
struct VarState
initialVarState
VarState[A] initialVarState;
Undocumented in source.

Variables

set
Set set;

Underlying MapSet.

stack
Var[] stack;
Undocumented in source.
stackPos
size_t stackPos;
Undocumented in source.
varState
VarState[A] varState;
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