Skip to content

Commit

Permalink
Debug seating arrangement
Browse files Browse the repository at this point in the history
  • Loading branch information
syntnc committed Nov 7, 2017
1 parent 9613fea commit e9d57b1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions IIIT-A Lab (IAIN532C)/Lab 4/seating_arrangement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def __init__(self, roll_no, friends):
self.friends = friends
self.remaining_seats = [(row, column) for column in range(N) for row in range(M)]
self.sitting = False

def __repr__(self):
return self.roll_no

def seat_exists(x, y):
'''CHECKS IF X AND Y VALUE IS INSIDE MATRIX'''
Expand All @@ -30,8 +33,11 @@ def make_graph():
def check_valid(student, seat):
'''CHECKS IF A PARTICULAR SEAT IS VALID FOR A PARTICULAR STUDENT'''
for dx, dy in ADJACENT:
if seat_exists(seat[0] + dx, seat[1] + dy) and SEAT_MATRIX[seat[0] + dx][seat[1] + dy].roll_no in GRAPH[student.roll_no]:
return False
if seat_exists(seat[0] + dx, seat[1] + dy):
if SEAT_MATRIX[seat[0] + dx][seat[1] + dy] is None:
continue
if SEAT_MATRIX[seat[0] + dx][seat[1] + dy].roll_no in GRAPH[student.roll_no]:
return False
return True

def set_seat(student, seat):
Expand Down Expand Up @@ -72,9 +78,9 @@ def arc_consistency():

def backtrack(seat):
'''BACKTRACK WITH MINIMUM REMAINING VALUES HEURISTIC, FOLLOWED BY DEGREE HEURISTIC IN ROW-MAJOR FORMAT'''
STUDENTS.sort(key=lambda x: (len(x.remaining_seats), -len(x.friends), x.roll_no))
STUDENTS.sort(key=lambda x: (len(x.remaining_seats), len(x.friends), x.roll_no))
for student in STUDENTS:
if not student.seating and check_valid(student, seat):
if not student.sitting and check_valid(student, seat):
set_seat(student, seat)
if seat == (M - 1, N - 1):
return True
Expand Down

0 comments on commit e9d57b1

Please sign in to comment.