On ps11, problem 4: Why is it that when I raise the number of trials to perform, my code doesn't run? It runs at 1 and sometimes 2... that's what really gets me. Why does it sometimes run at NUMTRIALS = 2, but not always?
Here's a copy of my code: def showPlot1(): """ Produces a plot showing dependence of cleaning time on room size. """ # TODO: Your code goes here roomSizes = [] averageTimes = [] NUMTRIALS = 2 for m in xrange(1,11): for n in xrange(1,11): rS = runSimulation(1,1.0,m,n,1.0,NUMTRIALS,Robot,RectangularRoomDirty,False) totalTime = 0 for L in rS: ## print len(L) totalTime += len(L) averageTime = float(totalTime) / NUMTRIALS averageTimes.append(averageTime) roomSizes.append(m*n) ## pylab.figure() pylab.plot(roomSizes,averageTimes, 'ro') pylab.title('Average Time for One Robot to Clean a Room of Size X Over 20 Trials') pylab.xlabel('Room Size') pylab.ylabel('Time') pylab.axis([0,110,0,700]) pylab.show()
RectangularRoomDirty is just a class I added in case one of the later problems specified that a room was partially cleaned. That way I could reduce the complexity of numCleanedTiles to constant for RectangularRoomDirty. It doesn't change the function of runSimulation, just adds a parameter. Also, I don't know how to do the dpaste thing... If someone would instruct me, that would be helpful.
do you have an error being raised?, Dpaste.com is simple, just paste in the box, in the first drop down box select python, hit the big PASTE button. then copy the URL from your address bar into your question
There is no error. The program just doesn't return. The thing that is troubling is that sometimes, it does return, and sometimes it doesn't. I know that since it uses randomness, there is some probability that the robot will never clean the room, but with the amount of trials I am doing and the number of times it has not returned, that's far too improbable. I think it may be a memory issue, but I am unsure why this would cause a memory issue - it's only 200 trials with average room size of about 30.
have you tried skipping this problem in the set and coming back to it after the next one? they give you a little piece of code so you can watch your robots live, see how they are moving also have you tried just lowering your percent of room cleaned? sometimes that last square gets REALLY lucky and never gets touched, 30*30 is a large room
Yeah, I've finished the problem set except for this function. And I know the code works on this function for a single trial of each room size (100 trials) consistently, and even two trials per room size (200 trials)... sometimes. Just sometimes it never comes back. My thought process is that if it is able to go through 100 trials (each room size from 1x1,1x2,...1x10,2x1,2x2,...,10x10) at least once consistently, then it's not a problem with the function working-- it must be a problem with the memory, but I don't understand enough about memory to really debug that. Also, the average room size is about 30 squares- the largest room is only a 10x10. How did you implement the function?
if your asking for my answer, here it is http://dpaste.com/571620/ otherwise i can't see whats wrong, maybe its your RunSimulation code that is wrong
Hmm... I'm not sure. I rebooted my machine and tried it again, and suddenly it works. I guess rebooting Python wasn't enough-- it was a problem with my machine. Next time, I'll try that first. Thanks for your help. I'm starting ps12 soon, so I'll be sure to respond to your question when I finish.
do you have a mac? its been an issue on the mac, affects the lectures
Join our real-time social learning platform and learn together with your friends!