I’m working to translate some economics models from GAMS into Julia using the Complementarity package and I’m running into an issue where a variable is defined on a larger set than its complementary equation. Here is a small example of the situation:
model = MCPModel()
A = [1,2,3,4]
B = [1,2,3]
@variable(model, X[A])
@mapping(model, Y[x = B], x^2)
@complementarity(model, Y, X)
Where B is a proper subset of A. Running this I get a KeyError because A contains elements that B does not.
The error message is quite clear, there are extra keys in the variable that aren’t in the equation. The workaround can’t be to “not have mismatched keys” because I’m implementing a model where the mapping is only defined on a subset of the variable domain.
My temporary solution to is to implement a kronecker-delta function that “turns-off” the keys that aren’t needed. I’m not crazy about this; however, since it requires a special function for each mapping.
I think the best solution is a macro for the Kronecker-Delta function, define the mapping on the entire set, and put the filter condition in X kron_δ.
Something like:
macro kron_δ(x,X)
x = esc(x)
X = esc(X)
quote
$x in $X
end
end
model = MCPModel()
A = [1,2,3,4]
B = [1,2,3]
@variable(model, X[A])
@mapping(model, Y[x = A], @δ(x,B)*X[x]^x)
@complementarity(model, Y, X)
I’m new to Julia, so this may not be the “best” method, but the macro seems to be the key.