Esempio n. 1
0
def main():
    room_inventory = readData.importRoomInventory(
        "DataFiles/roomInventory.csv")

    ts1 = ses.TimeSlot("F", "W", "4:00 PM", "7:00 PM")
    course1 = ses.Course("15.051", "Economics", 58, ses.Instructor("Arnie"),
                         ts1)

    rooms = allowedRooms(course1, room_inventory)
    print len(rooms), len(room_inventory)
    print min([r.capacity for r in rooms])

    course1.addRoomPrefs((ses.Room("E62-223", 100), ), True)
    rooms = allowedRooms(course1, room_inventory)
    print len(rooms), len(room_inventory)
    print rooms[0]

    viable_times = allowedTimes(course1, [])
    print len(viable_times)

    #some sanity checks
    assert (ts1 in viable_times)
    for ts in viable_times:
        assert (course1.isViableTime(ts))
        print ts

    #all times
    all_times = genAllTimeSlots()
    for t in all_times:
        print t
Esempio n. 2
0
def importRoomInventory(csv_filename):
    """Import room inventory to a list roomInstance"""
    f = csv.reader(open(csv_filename, 'rU'))
    headers = f.next()

    rooms = []
    for roomInfo in f:
        #Treat the seating style separately
        assert (headers[2] == "Seating Style")
        av_equip = []
        if roomInfo[2]:
            av_equip = [roomInfo[2]]

        #Treat remaining equipment, if non-blank
        paired_info = zip(headers[3:],
                          roomInfo[3:])  #exclude the name and size
        #only add to list if nonblank
        av_equip += [h for h, r in paired_info if r]

        sName = roomInfo[0]
        if sName in rooms:
            raise ses.SESError("Room %s appears twice in inventory." % sName)
        else:
            r = ses.Room(sName, roomInfo[1], av_equip)
            rooms.append(r)

    return rooms
Esempio n. 3
0
def _createRooms(d, roomInventory, respectRoom, num_prefs=3):
    """return a prefernece ordered, list of rooms.  
    d is a dictionary of room_prefs {"Room 1":"E51-135", "Room 2":"E62-133"}
    blank requests are ignored.
    Rooms not in inventory will be created if respectRoom = True.
    If room not inventory, and not "respect", will log error."""
    out, all_in_inv = [], True
    for ix_pref in range(1, num_prefs + 1):
        roomName = d.get("Room " + str(ix_pref), "").strip()
        del d["Room " + str(ix_pref)]

        if not roomName:
            continue

        #search for it in the list.
        room_list = filter(lambda x: str(x) == roomName, roomInventory)

        if room_list:
            assert len(room_list) == 1
            out.append(room_list[0])


#         elif respectRoom:
#             out.append(ses.Room(roomName, ses.Room.MAX_SIZE))
        else:
            out.append(ses.Room(roomName, ses.Room.MAX_SIZE))
            all_in_inv = False

            #only issue warning if not respect room
            if not respectRoom:
                pub.sendMessage("warning",
                                "Room %s not in inventory" % roomName)

    return out, all_in_inv
Esempio n. 4
0
def main():
    course1 = ses.Course("15.051", "Economics", 70, ses.Instructor("Arnie"),
                         ses.TimeSlot("", "M W", "10:00 AM", "11:30 AM"))
    course2 = ses.Course("15.052",
                         "Economics",
                         50,
                         ses.Instructor("Arnie"),
                         ses.TimeSlot("H1", "F", "4:00 PM", "7:00 PM"),
                         av_requirements=["camera"])
    course3 = ses.Course("15.052",
                         "Economics",
                         52,
                         ses.Instructor("Dimitris"),
                         ses.TimeSlot("F", "W", "10:00 AM", "11:00 AM"),
                         av_requirements=["camera"],
                         classtype="REC")
    courses = [course1, course2, course3]

    room1 = ses.Room("E52-135", 100, ["projector"])
    room2 = ses.Room("E52-140", 50, ["projector", " camera "])
    rooms = [room1, room2]

    config_options = config.Options()

    optimizer = Optimizer_(courses, rooms, config_options)
    optimizer.build()
    optimizer.m.update()

    print "Object Details"
    print "numVariables \t", len(optimizer.vars)

    optimizer.m.printStats()
    optimizer.updateObjFcnAndSolve([10], 0, 0)

    print "Max Congestion \t %f" % optimizer.maxCongVar.x
    courses = optimizer.retrieveAssignment()
    for c in courses:
        print c, c.assignedRoom, c.assignedTime
Esempio n. 5
0
def addAssignments(courses, roomInventory, csv_filename):
    """Add assignments to courselist  
    """
    f = csv.reader(open(csv_filename, 'rU'))
    headers = f.next()
    all_viable = []

    for courseInfo in f:
        d = dict(zip(headers, courseInfo))
        #make sure course exists
        find_course = lambda c: c.isSame(d["Course"], d["Section"], d[
            "classtype"])
        course = filter(find_course, courses)
        if not course:
            raise ses.SESError("Course %s-%s-%s not in list" %
                               (d["Course"], d["Section"], d["classtype"]))
        else:
            assert (len(course) == 1)
            course = course[0]

        #we only add details for courses that are properly assigned
        if not (d["Room"] and d["StartTime"] and d["EndTime"] and d["Days"]):
            pub.sendMessage(
                "warning", "Course %s-%s-%s not properly assigned\n" %
                (d["Course"], d["Section"], d["classtype"]))
            continue

        #create the room
        #this is an annoyance because of roomnames
        find_room = lambda r: str(r) == d["Room"].strip().upper()
        room = filter(find_room, roomInventory)
        if room:
            assert len(room == 0)
            room = room[0]
        else:
            #fail silently
            pub.sendMessage("warning",
                            "Room %s not in inventory\n" % d["Room"])
            room = ses.Room(d["Room"], ses.Room.MAX_SIZE)

        #create the timeslot
        sdays = d["Days"].split(", ")
        sdays = " ".join(sdays)
        ts = ses.TimeSlot(d["Half"], sdays, d["StartTime"], d["EndTime"])

        course.addAssignment(room, ts, False)

    return courses