I'm currently trying to model a problem with GLPK. I am in a situation where I have two binary variables $a, b$ and I need a function
$$f: \{0,1\}^2 \rightarrow \{0,1\}$$ such that
$$f(0,0) := f(0,1) := f(1,0) := 0$$ and $$f(1,1) := 1$$
(So: $f = \land$)
Is it possible to get this with linear operations?
What I've tried
- $f(a,b) := a \cdot b$, but this is not linear
- $f(a,b) := \min(a,b) = \frac{a+b-|a-b|}{2}$, but I don't know how to get $|a-b|$ with GLPK (this might not be possible, as the absolute value function is not a linear function)
- define a function just like I did above: I don't know if / how this is possible with GLPK
- using a parameter
parameter solution:
param logicalAnd{i in 0..1, j in 0..1} :=
if i = 1 and j = 1 then 1
else 0;
s.t. rest4{i in players, o in players}:
sum{j in matches} (
logicalAnd[x[i, j, 0]][x[o, j, 0]] +
logicalAnd[x[i, j, 1]][x[o, j, 1]]
) <= 1;
Results in
Reading model section from partition.mod...
partition.mod:33: subscript expression has invalid type
Context: ...rs } : sum { j in matches } ( logicalAnd [ x [ i , j , 0 ] ]
MathProg model processing error