Professional Documents
Culture Documents
PROBLEMS
CHAPTER 4
RECALL THE PUZZLES BELOW
• Would the problem solving approaches we have gone
through solve them? i.e. path finding search and
adversarial searches
CONSTRAINT SATISFACTION
PROBLEMS (CSPS)
EMPTY CELLS=53
• A student did two quizzes and their sum total was above
5. The second test is out of 10. The scores of the first test
were either 1, 2, or 3. What was the actual score of each
test?
• The problem can be represented as follows:
INBUILT CLASS CONSTRAINT
ExactSumConstraint Enforces that values of given variables sum exactly to a given amount
• Continuous variables
• Any real number between two values e.g. temperatures
between 0 and 1 can have values such as 0.10, 0.11, 0.12..
VARIETIES OF CONSTRAINTS
• CSPs work with different types number of variables:
• Unary constraints involve a single variable,
• e.g., x=1, SA ≠ green
• Binary constraints involve pairs of variables,
• e.g., x ≠y, SA ≠ WA
• Higher-order constraints involve 3 or more variables,
• e.g., cryptarithmetic column constraints, (a*100 + b*45 +
c*10 + d*25) <= 3000:
PROCUREMENT CSP EXAMPLE
• Chocolate A
• Chocolate B
• Chocolate C
• Chocolate D
CONSTRAINTS
• The sum of weights, the number of bars x weight of each bar (a*100
+ b*45 + c*10 + d*25), should be less than 3kg (<=3000g=3kgs)
• We need to generate similar constraints for the rest of the variables
• volume -->(a*8*2.5*0.5 + b*6*2*0.5 * c*2*2*0.5 + d*3*3*0.5) <=
1000cm3=10dm
• value--> (a*8 + b*6.8 + c*4 + d*3) < 300
VARIABLES & DOMAINS
• Based on the weight limit you cant carry more than 30 bars of
Chocolate A. Based on value we cant bring more than 37 bars,
and based on volume we cant bring more than 100bars.
• constraint
• all values in a row must be different
• all values in a columns must be different
• each nine (3x3) squares must have all different values,
• Cells already solved should not be solved
SUDOKU
EXERCISE
EXERCISE - OPTIMIZATION
• You have been requested to write a program for a drinks vending
machine at your college that assists in providing change. The user
inserts coins upto a total of Ksh.50, then they select a drink. Simulate
this by prompting for input of the drink cost and cash given. Change
is provided in denomination of 1, 5, 10, 20 and 40 shillings coins.
The machine cannot issue more than 5 pieces of 1 shilling coins, 4
pieces of 5 shillings coins, 2 pieces of 10 shillings coins, 2 pieces of
20 shillings coins, and 1 piece of 40 shillings coins.
• Write a program that can determine how much change the user
should get. It should recommend the combination that uses the least
number of coins.
ZEBRA PUZZLE
TIMETABLING PROBLEM
• Assume that you are in charge of creating a laboratory schedule for the classes in the Department of
Computing at UISU-A. Begin by finding out how many classes are offered in a semester for all programs
running in the department, how many laboratories are used, and how many faulty members teach in a
semester. A class schedule prepared by the academic advisor, indicates when a specific class should run
and who will be teaching it. They ensure that no collisions occur i.e. no faculty selects two courses that
run at the same time. However, the responsibility of ensuring that these classes are allocated a laboratory
with no collisions is your responsibility. Create a tentative class schedule and use it to write a program
that can generate the lab schedule – The lab schedule allocates each class to a lab. Factor in constraints
such as the number of labs, and permitted time slots (based on the class schedule).
• For extra credit: Write a program that can generate the class schedule when provided with the list of
courses and faculty teaching the courses. Assume undergraduate courses run twice a week (Mon/Wed or
Tue/Thur 7:00am – 9:00pm) and graduate courses run one a week from (Mon-Friday 5:40pm).
Undergraduate classes should run at the same time.