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. Robot or RandomWalkRobot) """ robots = [] counter = 0 room = RectangularRoom(width, height) while num_trials != 0: anim = proj09_visualize.RobotVisualization(num_trials, width, height) if num_robots > 0: while counter <= num_robots: if robot_type == 'standard': room = RectangularRoom(width, height) stanrobot = StandardRobot(room, speed) robots.append(stanrobot) counter = counter + 1 if min_coverage * room.getNumTiles() == room.getNumCleanedTiles(): num_trials = num_trials - 1 anim.done()
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials, robot_type): ta = 0 nt = num_trials while nt > 0: anim = proj09_visualize.RobotVisualization(num_robots, width, height) robots = [] avgt = 0 room = RectangularRoom(width, height) for k in range(0, num_robots): robots.append(robot_type(room, speed)) timestep = 0 while int(room.getNumTiles() * min_coverage) - 1 >= room.getNumCleanedTiles(): for robot in robots: robot.updatePositionAndClean() anim.update(room, robots) timestep += 1 avgt += timestep ta += avgt nt -= 1 trials = float(ta) / float(num_trials) print trials anim.done() return trials """ 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. Robot or RandomWalkRobot) """ raise NotImplementedError
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. Robot or RandomWalkRobot) """ results = [] for i in range(0, int(num_trials)): anim = proj09_visualize.RobotVisualization(num_robots, width, height) room = RectangularRoom(width, height) robots = [] min_clean = round(room.getNumTiles() * min_coverage) for i in range(0, int(num_robots)): if robot_type == StandardRobot: robots.append(StandardRobot(room, speed)) else: robots.append(RandomWalkRobot(room, speed)) time = 0 while room.getNumCleanedTiles() < min_clean: for robot in robots: robot.updatePositionAndClean() anim.update(room, robots) time += 1 anim.done() results.append(time) ans = sum(results) / len(results) return ans
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials, robot_type, delay, animate): """ 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. Robot or RandomWalkRobot) """ avg = 0 movie = '' for num in range(num_trials): time = 0 room = RectangularRoom(width, height) if animate is True: movie = proj09_visualize.RobotVisualization( num_robots, width, height, delay) robot_list = [] for x in range(num_robots): robot_list.append(robot_type(room, speed)) num_tiles = float(room.getNumTiles()) while float(room.getNumCleanedTiles()) / num_tiles < min_coverage: for robot in robot_list: robot.updatePositionAndClean() if animate is True: movie.update(room, robot_list) time += 1 if animate is True: movie.done() avg += time return avg / num_trials
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials,robot_type): anim = proj09_visualize.RobotVisualization(num_robots, width, height) totaltime = 0 num = num_trials while num > 0: room = RectangularRoom(width, height) i = num_robots robots = [] while i > 0: robots.append(robot_type(room,speed)) i = i - 1 while min_coverage * room.getNumTiles() + 1 > room.getNumCleanedTiles(): for robot in robots: robot.updatePositionAndClean() totaltime = totaltime + 1 anim.update(room, robots) num = num - 1 anim.done() return float(totaltime/num_trials)
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. Robot or RandomWalkRobot) """ totaltime = 0 num = num_trials while num > 0: anim = proj09_visualize.RobotVisualization(num_robots, width, height) room = RectangularRoom(width, height) i = num_robots robots = [] while i > 0: if robot_type == "StandardRobot": robots.append(StandardRobot(room, speed)) i -= 1 while min_coverage * room.getNumTiles() > room.getNumCleanedTiles(): for robot in robots: robot.updatePositionAndClean() totaltime += 1 anim.update(room, robots) num -= 1 anim.done() return float(totaltime / num_trials)
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials, robot_type): results = [] for i in range(0, num_trials): anim = proj09_visualize.RobotVisualization(num_robots, width, height) room = RectangularRoom(width, height) robots=[] for num in range(0, num_robots): #robot = StandardRobot(room, speed) #robot.position = room.getRandomPosition() #robot.setRobotDirection() #robot.direction = robot.getRobotDirection() robots.append(StandardRobot(room, speed)) #print "Trial Number: ", i + 1 for i in range(0, num_robots): time = 0 while len(room.cleaned) < (room.getNumTiles() * min_coverage): for robot in robots: robot.updatePositionAndClean() anim.update(room, robots) print len(room.cleaned) print room.getNumTiles() time = time + 1 results.append(time) anim.done() avg = sum(results) / len(results) print results print avg return avg