コード例 #1
0
  def greedyCord(self, simulator):
    #print "Starting Greedy Coordination"

    task_allocation = []

    idle_bots = simulator.getIdleBots()
    assigned_bots = []

    random.shuffle(idle_bots)

    for bot in idle_bots:
      goal = self.findBestBin(bot, [], simulator)
      # print goal
      if goal is not None:
        loc = simulator.bins[goal].loc
        end_loc = [loc[0], 0]
        simulator.bins[goal].bot_assigned = True

        if len(simulator.orchard_map[loc[0]][loc[1]].wkrs) == 0:
          task_allocation.append(robotTask(bot, [loc, end_loc], ['get', 'place']))
        else:
          if simulator.bots[bot].hasBin():
            #task_allocation.append([bot, [loc], ['get']])
            task_allocation.append(robotTask(bot, [loc, end_loc], ['swap', 'place']))
          else:
            # Getting a bin then moving to goal location
            r_loc = simulator.bots[bot].loc
            r_loc = [r_loc[0],0]
            #task_allocation.append([bot, [r_loc,loc],['get', 'get']])
            task_allocation.append(robotTask(bot, [r_loc,loc,end_loc], ['get', 'swap', 'place']))
        assigned_bots.append(bot)

    for bot in assigned_bots:
      idle_bots.remove(bot)

    deliverys = simulator.getBinDeliveryRequests()

    for loc in deliverys:
      if idle_bots != []:
        c_bot = self.findClosestBot(loc, idle_bots, simulator)
        if simulator.bots[c_bot].hasBin():
          task_allocation.append([c_bot, [loc], ['place']])
        else:
          # Getting a bin then moving to goal location
          r_loc = simulator.bots[c_bot].loc
          r_loc = [r_loc[0],0]
          task_allocation.append(robotTask(c_bot, [r_loc,loc],['get', 'place']))
        
        wkrs = simulator.orchard_map[loc[0]][loc[1]].wkrs
        for worker in wkrs:
          simulator.wkrs[worker].request_akn = True
          simulator.wkrs[worker].delivery = False

        idle_bots.remove(c_bot)

    return task_allocation
コード例 #2
0
 def resetRequests(self,simulator):
   deliveries = simulator.getBinDeliveryRequests() 
コード例 #3
0
  def auctionCord(self, simulator):
    task_allocation = []

    #Get idle bots, bins needing pickup, locations needing bin delivery
    idle_bots = simulator.getIdleBots() 
    deliverys = simulator.getBinDeliveryRequests() 

    # While still robots without plans
    still_planning = True
    prev_idle = copy.deepcopy(idle_bots)

    while still_planning:
      
      plans = []
      for bot in idle_bots:
        plans.append(self.getRobotPlan(bot, simulator))

      if len(plans) > 1:
        plans = self.findNonConflictPlan(plans)


      for plan in plans:
        if plan != []:
          c_bot = plan[0]
          loc = simulator.bins[plan[1]].loc
          end_loc = [loc[0], 0]
          simulator.bins[plan[1]].bot_assigned = True
          idle_bots.remove(c_bot)
          r_loc = simulator.bots[c_bot].loc
          r_loc = [r_loc[0],0]
          if len(simulator.orchard_map[loc[0]][loc[1]].wkrs) == 0:
            if simulator.bots[c_bot].hasBin():
              task_allocation.append(robotTask(bot, [simulator.bots[c_bot].loc, loc, end_loc], ['place', 'get', 'place']))
            else:
              task_allocation.append(robotTask(bot, [loc, end_loc], ['get', 'place']))
          else:
            if simulator.bots[c_bot].hasBin():
              #print "condition 2"
              task_allocation.append(robotTask(c_bot, [loc, end_loc], ['swap', 'place']))
            else:
              # Getting a bin then moving to goal location
              task_allocation.append(robotTask(c_bot, [r_loc,loc,end_loc],['get', 'swap', 'place']))


      still_planning = not(idle_bots == [] or prev_idle == idle_bots)
      prev_idle = copy.deepcopy(idle_bots)

    for loc in deliverys:
      if idle_bots != []:
        c_bot = self.findClosestBot(loc, idle_bots, simulator)
        if simulator.bots[c_bot].hasBin():
          task_allocation.append(robotTask(c_bot, [loc], ['place']))
        else:
          # Getting a bin then moving to goal location
          r_loc = simulator.bots[c_bot].loc
          r_loc = [r_loc[0],0]
          task_allocation.append(robotTask(c_bot, [r_loc,loc],['get', 'place']))
        wkrs = simulator.orchard_map[loc[0]][loc[1]].wkrs
        for worker in wkrs:
          simulator.wkrs[worker].request_akn = True
          simulator.wkrs[worker].delivery = False
        #print task_allocation[0].tasks
        idle_bots.remove(c_bot)



    return task_allocation