Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Raphael Finkel 10/2008, 6/2018
- fullRange(1..m) . % the ruler is a permutation of numbers 1 .. m
- subRange(1..m-1) . % differences in array index
- diff(1.. 2*m-1) . % differences in array value, offset by m
- position(1..m) .
- % #domain fullRange(Row) . % Row is index, Col is value
- % #domain fullRange(Row1) . % Row is index, Col is value
- % #domain fullRange(Col) . % Row is index, Col is value
- % #domain fullRange(Col1) . % Row is index, Col is value
- % #domain subRange(Delta) .
- % #domain diff(Diff) .
- % #domain position(Pos) .
- % exactly one value in each index
- 1 {setting(Row, Col_):fullRange(Col_)} 1 :- fullRange(Row) .
- % exactly one index for each value (no duplicates allowed)
- 1 {setting(Row_, Col):fullRange(Row_)} 1 :- fullRange(Col) .
- % difference between values at Row and at Row+Delta is Diff
- delta(Delta, Row, Diff) :-
- Row + Delta <= m , setting(Row, Col), Row+Delta == Row1,
- setting(Row1, Col1),
- Diff == m + Col1 - Col,
- fullRange(Row;Row1), subRange(Delta) .
- :- delta(Delta, Row, Diff), Delta + Row > m . % uniqueness
- % not necessary, but seems to speed up clasp:
- 1 {delta(Delta, Row, Diff_):diff(Diff_)} 1 :-
- Row + Delta <= m ,
- subRange(Delta), fullRange(Row) .
- % constraint on differences
- 0 {delta(Delta, Row_, Diff):fullRange(Row_)} 1 :-
- Delta < m-1 ,
- subRange(Delta), fullRange(Row), diff(Diff).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement