예제 #1
0
def gen_agents(size,
               d_input,
               r_input,
               c_input,
               num_pre_dem=False,
               peak_loc=False):

    drones = []
    if type(d_input) == int:
        for d in range(d_input):
            drones.append(
                m.drone(
                    [random.randint(0, size[0]),
                     random.randint(0, size[1])], d))
    else:
        for idx, d in enumerate(d_input):
            drones.append(m.drone([d[0], d[1]], idx))

    restaurants = []
    if type(r_input) == int:
        for r in range(r_input):
            restaurants.append(
                m.restaurant(
                    [random.randint(0, size[0]),
                     random.randint(0, size[1])]))
    else:
        for r in r_input:
            restaurants.append(m.restaurant(r))

    chargers = []
    if not c_input:
        c_loc = [[size[0] / 4, size[1] / 2], [size[0] * 3 / 4, size[1] / 2]]
        for c in c_loc:
            chargers.append(m.charge([c[0], c[1]]))
    elif type(c_input) == int:
        for c in range(c_input):
            chargers.append(
                m.charge(
                    [random.randint(0, size[0]),
                     random.randint(0, size[1])]))
    else:
        for c in c_input:
            chargers.append(
                m.charge(
                    [random.randint(0, size[0]),
                     random.randint(0, size[1])]))

    jobs_na = []
    if num_pre_dem:
        for i in range(num_pre_dem):
            demand = dem.mapGenerator(size, False, peak_loc)
            rest, cust_to_charge = m.pick_restaurant(demand, restaurants,
                                                     chargers)
            job = m.job(demand, rest, 0, random.randint(10, 25),
                        cust_to_charge)
            jobs_na.append(job)

    return drones, restaurants, chargers, jobs_na
예제 #2
0
def main_loop(drones,
              restaurants,
              chargers,
              jobs_a,
              jobs_na,
              jobs_c,
              t,
              spawn_prob,
              size,
              peak_loc,
              learning_weights=False):

    demand = dem.mapGenerator(size, spawn_prob, peak_loc)
    slow = False

    if demand:
        rest, cust_to_charge = m.pick_restaurant(demand, restaurants, chargers)
        job = m.job(demand, rest, t, random.randint(10, 25), cust_to_charge)
        jobs_na.append(job)

    for d in drones:
        d.move_to_goal(t, chargers)

    if not learning_weights:
        no_job_drone = [
            x for x in drones
            if x.job == 0 or x.job.state == 4 and x.battery >= 90
        ]
    else:
        no_job_drone = [x for x in drones if x.job == 0 or x.job.state == 4]

    if learning_weights:
        s = time.time()
        score_matrix = m.NNscores(no_job_drone, jobs_na, t, learning_weights,
                                  len(drones))
        if time.time() - s > 0.008:
            slow = True
    else:
        score_matrix = m.simpleScores(no_job_drone, jobs_na, t)
    idx_drones, idx_jobs_na = m.hungarianMethod(score_matrix)

    for idx, drone in enumerate(idx_drones):
        if int(score_matrix[drone, idx_jobs_na[idx]]) != 100000:
            no_job_drone[drone].set_job(jobs_na[idx_jobs_na[idx]])
            jobs_a.append(jobs_na[idx_jobs_na[idx]])

    # added for KPI
    for job in jobs_a:
        if job.state == 3:
            jobs_c.append(job)

    jobs_na = [x for x in jobs_na if x.state == 0]
    jobs_a = [x for x in jobs_a if x.state != 3]

    return jobs_na, jobs_a, jobs_c, slow
예제 #3
0
               -0.0005058854834270043, 0.98813616677188, 1.124796722093522,
               -0.32571743636542916, -0.17580636537189864,
               -0.010327358384964347, 0.9861115479780318, 0.5705700709535082,
               -0.9390895310960459, -0.6529715741626314
           ]]]
weights = [np.array(x) for x in weights]

#################################################################################
#### Restaurant Locations
#################################################################################
np.random.seed(1)
rest_loc = []
for i in range(20):
    rest_loc.append(
        dem.mapGenerator(gridSize=(1000, 1000),
                         spawn_prob=False,
                         peakCoordinates=False))
np.random.seed(None)

# resttest = np.random.rand(3)


#################################################################################
#### Simulation Function
#################################################################################
def run_sim(runs, ticks, num_drones, num_restaurants, demandRate, rest_loc,
            learning_weights):

    size = (1000, 1000)

    rest_loc = rest_loc[0:num_restaurants]