Loading [Contrib]/a11y/accessibility-menu.js
Download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
PyCSP3 Model (see pycsp.org)
 
Execution:
  python3 TrafficLights.py
"""
 
from pycsp3 import *
 
R, RY, G, Y = "red", "red-yellow", "green", "yellow"
 
table = {(R, R, G, G), (RY, R, Y, R), (G, G, R, R), (Y, R, RY, R)}
 
# v[i] is the color for the ith vehicle traffic light
v = VarArray(size=4, dom={R, RY, G, Y})
 
# p[i] is the color for the ith pedestrian traffic light
p = VarArray(size=4, dom={R, G})
 
satisfy(
    (v[i], p[i], v[(i + 1) % 4], p[(i + 1) % 4]) in table for i in range(4)
)