PS8, p2: I am having trouble stopping the function. I still haven't figured out the inner workings of the function exactly, but it is hard to test new ideas/implementations without having a way to stop it. Anyways, I use a while totalWork < maxWork which causes a problem since it doesn't reach the maxWork ever, just gets close. Anyways, I'm gonna put it don't for a bit and come back tomorrow. Some suggestions would be much appreciated. http://codepad.org/TrVO7rmm
in ideal, ctrl-c will stop a an infinite loop/recursion - you may have to hold it down for a while. if that doesn't work, ctrl-f6 - but then you 'loose' all the context.
also, open the subjects text file and copy the first ten or fifteen lines to a new file, name it appropriately and use it to develop/debug your function
general comments - lines 25 and 26 could be replaced with- for course, candidateWork in courseList.iteritems() http://docs.python.org/library/stdtypes.html#dict.iteritems
For some reason I thought iteritems was new in 2.7 which is why I avoided it... As for the stopping of the function, I can personally stop it (with ctrl-c). That isn't the problem. My problem is that if I loop the function with while totalWork < maxWork, the loop may turn infinite if totalWork = 14 while maxWork = 15 and there are no items with a work value of 1. Does that make any sense? Basically I need a way to tell the computer loop while totalWork < 15 or until you run through and no selections are made because nothing + totalWork <= 15 Here's the basic outline of what I think it should do: greedyadvisor(subjects, maxWork, comparator): totalWork = 0 picksDict = {} while totalWork < maxWork OR no selections can be made: blah blah blah picksDict[pick] = (value, work) totalWork += pick[work] return picksDict The problem I'm having is with that second condition of the while loop...
seems like if that happened then candidate will still be (0, 0) when the for loop exits? you could test for that and break out of the while down around line 33.
Blah, the whole thing is off. The way I have it now produces wonky results... back to the drawing board I guess
Ok, so this is what I now have: http://codepad.org/JdNCDOwy It works for my shortened list (if comparator = cmpValue). If I try and run it with cmpRatio I get a ZeroDivisionError: float division because my first test case is (0, 0) and if I use cmpWork I get ValueError: list.remove(x): x not in list again because the test case is (0, 0). Should I rework cmpRatio/cmpWork to match my implementation of greedyAdvisor or do I need to rework my code to work with the given comparators?
Also, my code will not work if totalWork ever can't = maxWork...so thats a potential problem.
start currentPickVW at (-1, -1)? or (0, -1)? for cmpRatio if the for loop exits and currentPickVW is unchanged you probably want to break out of the while loop because there aren't any more courses that meet the requirements even if you are less than maxWork
if I start currentPickVW at (-1, -1) cmpRatio works, but cmpWork still doesn't since the the min work of any course is 1. So, starting currentPickVW at (-1, 2[or any i > 1]) works I guess. Although that doesn't seem like the best option, because what if there was a course list in which the min work was higher than whatever I set for the work val of currentPickVW? Oh well, it solves the given problem.
Take that back, cmpWork doesn't seem to work for any maxWork value higher than 15...
Or any value lower for that matter...
Never mind. All three comparators work on the full course list provided (not 100% sure why using my shorter list was a problem...)
Join our real-time social learning platform and learn together with your friends!