
CSE 571: Graduate AI
Homework on Constraint Logic Programming
Use Constraint Logic Programming to solve the following problems:
1. (Warm-up) Solve the following linear inequalities:
x1 + 2x2 7
x2 – x1 2
0 x1 5
0 x2 10
2. (Simple Scheduling) There are 6 tasks to schedule. Each of the tasks takes
exactly one time point to execute and only one task can be executed at a time. In
other words, there are only 6 time points for this scheduling problem. Find a
schedule such that the following criteria are met:
Task 1 has to be executed some time before task 5.
Tasks 2 and 4 have to be executed with at least 2 time points apart from each
other.
Tasks 3 and 6 are executed by the separation of 1 time point.
Task 1 cannot be executed at time point 1.
Task 4 has to be executed at time point 4.
[Hint: You may want to use the predefined predicate all_different.]
3. (Graph-coloring) Given a graph G(V,E), such that V={v1,v2,v3,v4} and E =
{(v1,v2), (v1,v3), (v2,v3), (v1,v4), (v2,v4)} and colors red, green and blue, assign
colors to each vertex so that no two vertices has the same color.
[Hint: You can interpret the problem as not assigning the same color to v1 and v2
for instance]
4. (Knapsack) Consider a simple knapsack problem with 5 items. Each item has a
cost and value associated with it. We have a sack with a given capacity 12 and
the goal is to select a subset of the items which can fit into the sack while
maximizing the total value. Each item has the following cost and value:
Item 1: cost = 4; value = 5
Item 2: cost = 5; value = 6
Item 3: cost = 6; value = 3
Item 4: cost = 5; value = 8
Item 5: cost = 3; value = 2
[Hint: You may want to use a binary variable to represent if an item is in a sack or not. It
is a much simpler version of the cumulative scheduling example shown in class. You do
not have to use list, using a binary variable to represent each item might be easier]