You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
\item \lect Complete the following python script with the necessary statements.
|
|
|
|
The final script should map each integer of a list of five integers to four possible colours such that the mapping returns different colours for adjacent integers.
|
|
|
|
|
|
% You need to declare and populate a z3 \texttt{Datatype}
|
|
% Furthermore, you need to create a list of five distinct integers and bound them.
|
|
% Finally, enforce the constraints on the uninterpreted function ....
|
|
|
|
|
|
\begin{pythonSourceCode}
|
|
from itertools import combinations
|
|
from z3 import *
|
|
|
|
solver = Solver()
|
|
|
|
# Declare a Datatype and populate it with 4 colours.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Declare a function from integers to your custom datatype
|
|
|
|
|
|
variables = list()
|
|
for i in range(0,5):
|
|
variables.append(Int(i))
|
|
# Bound each integer i such that 0 <= i < 5
|
|
|
|
|
|
|
|
|
|
# Enfore that all i are distinct
|
|
|
|
|
|
|
|
# Enforce that colours are different for adjacent integers
|
|
for combi in combinations(variables,2):
|
|
|
|
|
|
|
|
result = solver.check()
|
|
if result == sat:
|
|
print(solver.model())
|
|
\end{pythonSourceCode}
|