GLPK/Modeling Logical Constraints

From Wikibooks, open books for an open world
Jump to: navigation, search

Logical constraints involving binaries can be modelled as follows

var x, binary;
var y, binary;
var z, binary;

# z = x or y
s.t. c1: x     <= z;
s.t. c2: y     <= z;
s.t. c3: x + y >= z;

# z = x and y
s.t. c1: x     >= z;
s.t. c2: y     >= z;
s.t. c3: x + y <= z + 1;

# s = x xor y
# c = x and y
s.t. c1: x + y = 2*c + s;

# z = not x
s.t. c1: x = 1 - z;