Created
November 26, 2012 01:45
-
-
Save mooreniemi/4146168 to your computer and use it in GitHub Desktop.
600x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# === Problem 3 | |
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials, | |
robot_type): | |
""" | |
Runs NUM_TRIALS trials of the simulation and returns the mean number of | |
time-steps needed to clean the fraction MIN_COVERAGE of the room. | |
The simulation is run with NUM_ROBOTS robots of type ROBOT_TYPE, each with | |
speed SPEED, in a room of dimensions WIDTH x HEIGHT. | |
num_robots: an int (num_robots > 0) | |
speed: a float (speed > 0) | |
width: an int (width > 0) | |
height: an int (height > 0) | |
min_coverage: a float (0 <= min_coverage <= 1.0) | |
num_trials: an int (num_trials > 0) | |
robot_type: class of robot to be instantiated (e.g. StandardRobot or | |
RandomWalkRobot) | |
""" | |
timeCount = 0.0 | |
robotlist=[] | |
for trials in range(num_trials): | |
room = RectangularRoom(width,height) | |
coverage = (min_coverage * room.getNumTiles()) | |
robotlist.append(robot_type(room,speed)) | |
while coverage > room.getNumCleanedTiles(): | |
timeCount = timeCount + 1 | |
for robot in robotlist: | |
robot.updatePositionAndClean() | |
return timeCount / num_trials |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment