Encodings for adding simple constraints¶
The following encodings contain the rules of the standard COOM encoding split up into program parts for the part of a constraint they specify,
i.e. the constraint itself, one of the sub-expressions of a boolean constraint (binary, unary, function), or parts of a table constraint (allow, column).
The active/1 externals is used here to only check for constraint violations of bounds that are active.
Encodings ¶
src/coomsuite/encodings/multi/new-constraint.lp
¶
Encoding
Encodings for boolean constraints¶
Encodings ¶
src/coomsuite/encodings/multi/new-function.lp
¶
Encoding
#program new_function(fun,agg,p).
function(fun,agg,p).
defined(fun) :- function(fun,agg,p), value(fun,_).
value(fun,V) :- function(fun,agg,p), V = #count{ X : set(p,X), include(X) }, agg = "count".
value(fun,V) :- function(fun,agg,p), V = #sum { V',X : set(p,X), value(X,V') }, agg = "sum".
value(fun,V) :- function(fun,agg,p), V = #min { V',X : set(p,X), value(X,V') }, agg = "min".
value(fun,V) :- function(fun,agg,p), V = #max { V',X : set(p,X), value(X,V') }, agg = "max".
Encodings ¶
src/coomsuite/encodings/multi/new-unary.lp
¶
Encoding
Encodings ¶
src/coomsuite/encodings/multi/new-binary.lp
¶
Encoding
boolean binaries
defined(f) :- binary(f,xl,op,xr), defined(xl), defined(xr).
satisfied(f) :- binary(f,xl,op,xr), VL = VR, value(xl,VL), value(xr,VR), op = "=".
satisfied(f) :- binary(f,xl,op,xr), VL != VR, value(xl,VL), value(xr,VR), op = "!=".
satisfied(f) :- binary(f,xl,op,xr), VL > VR, value(xl,VL), value(xr,VR), op = ">".
satisfied(f) :- binary(f,xl,op,xr), VL >= VR, value(xl,VL), value(xr,VR), op = ">=".
satisfied(f) :- binary(f,xl,op,xr), VL < VR, value(xl,VL), value(xr,VR), op = "<".
satisfied(f) :- binary(f,xl,op,xr), VL <= VR, value(xl,VL), value(xr,VR), op = "<=".
satisfied(f) :- binary(f,xl,op,xr), 1 <= { satisfied(xl); satisfied(xr) }, op = "||".
satisfied(f) :- binary(f,xl,op,xr), satisfied(xl), satisfied(xr), op = "&&".
numeric binaries
defined(f) :- binary(f,xl,op,xr), value(f,_).
value(f,VL+VR) :- binary(f,xl,op,xr), value(xl,VL), value(xr,VR), op = "+".
value(f,VL-VR) :- binary(f,xl,op,xr), value(xl,VL), value(xr,VR), op = "-".
value(f,VL*VR) :- binary(f,xl,op,xr), value(xl,VL), value(xr,VR), op = "*".
value(f, VL) :- binary(f,xl,op,xr), value(xl,VL), not value(xr,_), op = "+".
value(f, VR) :- binary(f,xl,op,xr), value(xr,VR), not value(xl,_), op = "+".
value(f, VL) :- binary(f,xl,op,xr), value(xl,VL), not value(xr,_), op = "-".
value(f,-VR) :- binary(f,xl,op,xr), value(xr,VR), not value(xl,_), op = "-".
Encodings for table constraints¶
Encodings ¶
src/coomsuite/encodings/multi/new-allow.lp
¶
Encodings ¶
src/coomsuite/encodings/multi/new-column.lp
¶
Encoding
table_bound is only needed if the corresponding table constraint is incremental
table_bound(c,id,bound).
undefined(c,id) :- column(c,id,_,x), not include(x).
defined(c,id) :- column(c,id,_,_), not undefined(c,id).
not_hit(c,id,Row) :- allow(Idx,(col,Row),_), column(c,id,col,x), c=(Idx,_), not value(x,V) : allow(Idx,(col,Row),V).
satisfied(c,id) :- allow(Idx,(_,Row),_), column(c,id,_,_), c=(Idx,_), not not_hit(c,id,Row).