all_different
relationalai.semantics.reasoners.prescriptive
all_different(*args: b.Value) -> b.AggregateReturn an all-different constraint.
Use this inside Model.require and
pass the resulting fragment to Problem.satisfy.
Arguments must reference decision variables declared via
Problem.solve_for.
For grouped constraints (for example, “all values are distinct per row”),
scope it with Aggregate.per.
Parameters
Section titled “Parameters”
(*argsValue, default:()) - One or more decision-variable expressions that must take distinct values.
Returns
Section titled “Returns”Aggregate- A solver aggregate representing the all-different constraint.
Examples
Section titled “Examples”Constrain values to be distinct per row:
from relationalai.semantics import Integer, Modelfrom relationalai.semantics.reasoners.prescriptive import Problem, all_different
m = Model("all_different_demo")Cell = m.Concept("Cell", identify_by={"row": Integer, "col": Integer})Cell.val = m.Property(f"{Cell} has {Integer:val}")m.define( Cell.new(row=0, col=0), Cell.new(row=0, col=1), Cell.new(row=1, col=0), Cell.new(row=1, col=1),)problem = Problem(m, Integer)problem.solve_for(Cell.val, name=["x", Cell.row, Cell.col], lower=1, upper=4)problem.satisfy(m.require(all_different(Cell.val).per(Cell.row)).where(Cell))