File: queens.pn

package info (click to toggle)
maria 1.3.5-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,068 kB
  • sloc: cpp: 43,408; yacc: 8,080; ansic: 436; sh: 404; lisp: 395; makefile: 228; perl: 21
file content (22 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// The N Queens constraint satisfaction problem as a high-level Petri net.
// Generalised by Marko Mkel from Michael J. Sanders,
// "Constraint Programming with Object-Oriented Petri Nets", in
// "1998 IEEE International Conference on Systems, Man, and Cybernetics",
// pages 289--294, Figure 1 on page 290.

/// The queen data type.
typedef int (1..8) q_t;

/// The available queens.
place InColumn (0,#q_t) q_t: q_t q: q;

/// Solve the constraint satisfaction problem "N Queens".
/// The indexes of the variables .c represent row values.
/// The values bound to the variables .c represent column values.
/// The guard expression prohibits diagonal attacks.
/// Horizontal and vertical attacks are prohibited by the net structure.
trans solve
in { place InColumn: q_t q: .c; }
gate q_t q1 && q_t q2 (q2 != q1) &&
(is q_t .c q1 - is q_t .c q2 != q1 - q2 &&
 is q_t .c q1 - is q_t .c q2 != q2 - q1);