基于星雀(Nutcracker)和麻雀(Sparrow)算法的物流配送路径规划问题求解程序

想和大神交朋友或想软件开发兼职接项目,请通过手机端搜小#程#序: "黄页小艺” 。

# %%
import folium
import random
import numpy as np
from tqdm import tqdm
from copy import deepcopy
from random import randint
import matplotlib.pyplot as plt
from geopy.distance import geodesic
#
# # %%
# pip install geopy
#
# # %%
# 需求点数量
demand_point_num=20# 供应点数量
supply_point_num=3# 冷库集合
cold_storage_num=5# 节点总数
point_num=demand_point_num+supply_point_num+cold_storage_num# 产品种类
product_type=3# 车辆数
vehicle_num=8# 需求矩阵
demand_matrix={}
for d in range(demand_point_num):for p in range(product_type):demand_matrix[d,p]=randint(10,100)# 时间窗
time_window={}
for d in range(demand_point_num):t1,t2,t=randint(0,100),randint(0,100),randint(1,10)ET,LT=min(t1,t2),max(t1,t2)time_window[d]=(ET,LT,t)# 车辆的容量
vehicle_capacity={}
for v in range(vehicle_num):vehicle_capacity[v]=[]for p in range(product_type):vehicle_capacity[v].append(randint(200,500))# 车辆的承重和体积
vehicle_weight={}
vehicle_volume={}
for v in range(vehicle_num):vehicle_weight[v]=randint(500,1000)vehicle_volume[v]=randint(500,1000)# 车辆的运行速度/最远行驶距离
vehicle_speed={}
vehicle_distance={}
for v in range(vehicle_num):vehicle_speed[v]=randint(20,30)vehicle_distance=randint(100000,200000)# 车辆的固定/单位成本
vehicle_fix_cost={}
vehicle_unit_cost={}
for v in range(vehicle_num):vehicle_fix_cost[v]=randint(1000,2000)vehicle_unit_cost[v]=randint(5,10)/1e4# 车辆早到/晚到的惩罚成本
a1,a2=10,10# 产品的重量和体积
product_weight={}
product_volume={}
for p in range(product_type):product_weight[p]=randint(1,5)product_volume[p]=randint(1,5)# 冷库的建设成本
cold_storage_fix_cost={}
for c in range(cold_storage_num):cold_storage_fix_cost[c]=randint(1000000,3000000)# 产品的重量/体积
product_weight={}
product_volume={}
for p in range(product_type):product_weight[p]=randint(1,5)product_volume[p]=randint(1,5)# 节点坐标
node_point={}
for p in range(point_num):lat=randint(30421,30425)/1000lon=randint(120510,120530)/1000node_point[p]=(lat,lon)# 距离矩阵
distance_matrix={}
for p1 in range(point_num):for p2 in range(point_num):distance=geodesic(node_point[p1],node_point[p2]).mdistance_matrix[p1,p2]=distance# %%
'''
整数转二进制
'''
def toBit(num,length):bit=[]for i in range(length-1,-1,-1):bit.append(int(num/(supply_point_num+cold_storage_num)**i))num-=bit[-1]*(supply_point_num+cold_storage_num)**ireturn bit'''
星雀个体
'''
class Nutcracker:def __init__(self,individual):self.individual=individualself.result=self.decode()self.fitness=self.get_fitness()def decode(self):result={}bit=toBit(self.individual[0],vehicle_num)demand=deepcopy(demand_matrix)for i in self.individual[1]:result[i]={}serve_order=self.individual[2+i]capacity=deepcopy(vehicle_capacity[i])# 计算开始时间cur_time=distance_matrix[0,bit[i]]/vehicle_speed[i]cur_point=bit[i]result[i][cur_point]={}result[i][cur_point]['serve']={0:0,1:0,2:0}result[i][cur_point]['time']={'t1':cur_time,'t2':cur_time,'t3':cur_time}for j in serve_order:jj=j+supply_point_num+cold_storage_num# 车辆没有剩余容量if sum(capacity)==0:break# 需求点没有剩余需求if sum([demand[j,p] for p in range(product_type)])==0:continueresult[i][j]={}# 计算需求量result[i][j]['serve']={}for p in range(product_type):min_num=min(demand[j,p],capacity[p])demand[j,p]-=min_numcapacity[p]-=min_numresult[i][j]['serve'][p]=min_num# 计算时间arrive_time=cur_time+distance_matrix[cur_point,jj]/vehicle_speed[i]satrt_serve_time=max(arrive_time,time_window[j][0])departure_time=satrt_serve_time+time_window[j][2]result[i][j]['time']={'t1':arrive_time,'t2':satrt_serve_time,'t3':departure_time}cur_time=departure_timecur_point=jreturn resultdef get_fitness(self):fitness=0self.result=self.decode()# 冷库建设成本bit=toBit(self.individual[0],vehicle_num)cold_set=set()for b in bit:if b>=supply_point_num:cold_set.add(b-supply_point_num)fitness+=sum([cold_storage_fix_cost[c] for c in cold_set])/(5*365)# 车辆运输成本 for i in self.result:if self.result[i]:fitness+=vehicle_fix_cost[i]cur_point=bit[i]for j in self.result[i]:jj=j+supply_point_num+cold_storage_numfitness+=vehicle_unit_cost[i]*distance_matrix[cur_point,jj]cur_point=jj# 需求延误成本for j in range(demand_point_num):min_arrive_time=1e8max_arrive_time=0for i in self.result:if j in self.result[i]:min_arrive_time=min(min_arrive_time,self.result[i][j]['time']['t1'])max_arrive_time=max(max_arrive_time,self.result[i][j]['time']['t1'])fitness+=a1*max(0,time_window[j][0]-min_arrive_time)fitness+=a2*max(0,max_arrive_time-time_window[j][1])self.fitness=1/fitnessreturn 1/fitness'''
生成个体
'''
def gen_nutcracker():num=randint(0,(supply_point_num+cold_storage_num)**vehicle_num-1)vehicle_order=[i for i in range(vehicle_num)]random.shuffle(vehicle_order)serve_order=[]for i in range(vehicle_num):cur_order=[j for j in range(demand_point_num)]random.shuffle(cur_order)serve_order.append(cur_order)individual=[num]+[vehicle_order]+serve_ordernutcracker=Nutcracker(individual)return nutcracker'''
生成种群
'''
def get_population(num):population=[]for i in range(num):population.append(gen_nutcracker())return population'''
获取最优个体
'''
def get_best_nutcracker(population):best_fitness=0best_nutcracker=Nonefor nutcracker in population:fitness=nutcracker.get_fitness()if fitness>best_fitness:best_fitness=fitnessbest_nutcracker=nutcrackerreturn best_nutcracker'''
觅食阶段
'''
def forage(nutcracker,population):# 随机探索if random.random()<exploring_probability:individual=nutcracker.individualindividual[0]=randint(0,(supply_point_num+cold_storage_num)**vehicle_num-1)nutcracker=Nutcracker(individual)return nutcracker# 最优探索else:best_nutcracker=get_best_nutcracker(population)individual=nutcracker.individualbest_individual=best_nutcracker.individualindividual[0]=best_individual[0]nutcracker=Nutcracker(individual)return nutcracker'''
储存阶段
'''
def store(nutcracker,best_population):new_best_population=deepcopy(best_population)new_best_population.append(nutcracker)new_best_population=sorted(new_best_population, key=lambda x: x.get_fitness())return new_best_population[1:]'''
Levy飞行距离
'''
def levy_distance(nutcracker1,nutcracker2):individual1=nutcracker1.individualindividual2=nutcracker2.individualdistance=abs(individual1[0]-individual2[0])/max(individual1[0],individual2[0])for i in range(vehicle_num+1):ii=i+1sum1=0for j in range(len(individual1[ii])):sum1+=j*individual1[ii][j]sum2=0for j in range(len(individual2[ii])):sum2+=j*individual2[ii][j]distance+=abs(sum1-sum2)/max(sum1,sum2)return distance'''
缓存搜索阶段
'''
def search(nutcracker,best_population):individual=nutcracker.individualfor cur_nutcracker in best_population:if levy_distance(nutcracker,cur_nutcracker)>distance:continuecur_individual=cur_nutcracker.individualnew_individual=[]for i in range(len(individual)):if randint(0,1):new_individual.append(individual[i])else:new_individual.append(cur_individual[i])new_nutcracker=Nutcracker(new_individual)if new_nutcracker.get_fitness()>nutcracker.get_fitness():nutcracker=deepcopy(new_nutcracker)return nutcrackerdef swap(nutcracker):individual=deepcopy(nutcracker.individual)for i in range(len(individual[1])):for j in range(i+1,len(individual[1])):individual[1][i],individual[1][j]=individual[1][j],individual[1][i]new_nutcracker=Nutcracker(individual)if nutcracker.get_fitness()>new_nutcracker.get_fitness():individual[1][i],individual[1][j]=individual[1][j],individual[1][i]return Nutcracker(individual)def new_search(nutcracker,best_population):individual=nutcracker.individualfor cur_nutcracker in best_population:if levy_distance(nutcracker,cur_nutcracker)>distance:continuecur_individual=cur_nutcracker.individualnew_individual=[]for i in range(len(individual)):if randint(0,1):new_individual.append(individual[i])else:new_individual.append(cur_individual[i])new_nutcracker=Nutcracker(new_individual)if new_nutcracker.get_fitness()>nutcracker.get_fitness():nutcracker=deepcopy(new_nutcracker)return swap(nutcracker)# %%
'''
绘制收敛图
'''
def plot_convergence(convergence_records):num_curves = len(convergence_records)  for i in range(num_curves):cur=convergence_records[i]convergence_records[i]=[1/i for i in cur]colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']  plt.figure(figsize=(20, 10))for i, record in enumerate(convergence_records):iterations = list(range(1, len(record) + 1))plt.plot(iterations, record, marker='o', label=f'Curve {i+1}', color=colors[i % len(colors)])plt.title('Convergence Plots')  plt.xlabel('Iteration') plt.ylabel('Cost')  plt.legend()plt.grid(False)  plt.show()'''
绘制路线图
'''
def plot_locations(m,locations,color):locations.append(locations[0])folium.PolyLine(locations, color=color, weight=2.5, opacity=1).add_to(m)for i, (lat, lon) in enumerate(locations):color='blue'for k in node_point:point=(lat, lon)if point==node_point[k]:if k<supply_point_num:color='red'elif k<supply_point_num+cold_storage_num:color='green'folium.Marker([lat, lon], popup=f'Location {i+1}',icon=folium.Icon(color=color)).add_to(m)return mdef plot_route(nutcracker):m = folium.Map(location=node_point[0], zoom_start=13,tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_en&size=1&scale=1&style=8&x={x}&y={y}&z={z}', attr='高德-中英文对照')color_list = ['red', 'blue', 'green', 'purple', 'orange','darkred', 'lightred', 'beige', 'darkblue', 'darkgreen','cadetblue', 'darkpurple', 'white', 'pink', 'lightblue','lightgreen', 'gray', 'black', 'lightgray']cnt=0for v in best_nutcracker.result:locations=[]if not best_nutcracker.result[v]:continuefor p in nutcracker.result[v]:locations.append(node_point[p])m=plot_locations(m,locations,color_list[cnt])cnt+=1return m# %%
# ### 基础算法# In[4]:# 种群数量
population_num=20# 储存数量
store_num=5# 迭代次数
iteration_num=100# 探索概率
exploring_probability=0.5# 飞行距离
distance=2# 生成初始种群
population=get_population(population_num)# 最优个体
best_nutcracker=get_best_nutcracker(population)# 迭代求解
record=[best_nutcracker.get_fitness()]
best_population=sorted(population, key=lambda x: x.get_fitness())[-store_num:]
for it in tqdm(range(iteration_num)):for i in range(len(population)):nutcracker=population[i]# 觅食阶段nutcracker=forage(nutcracker,population)# 储存阶段best_population=store(nutcracker,best_population)# 缓存搜索阶段nutcracker=search(nutcracker,best_population)# 更新个体population[i]=nutcracker# 更新最优个体if nutcracker.get_fitness()>best_nutcracker.get_fitness():best_nutcracker=deepcopy(nutcracker)record.append(best_nutcracker.get_fitness())plot_convergence([record])
m=plot_route(best_nutcracker)
m.save('basis.html')# %%
# ### 改进算法# In[5]:# 种群数量
population_num=20# 储存数量
store_num=5# 迭代次数
iteration_num=100# 探索概率
exploring_probability=0.5# 飞行距离
distance=2# 生成初始种群
population=get_population(population_num)# 最优个体
best_nutcracker=get_best_nutcracker(population)# 迭代求解
record1=[best_nutcracker.fitness]
best_population=sorted(population, key=lambda x: x.fitness)[-store_num:]
for it in tqdm(range(iteration_num)):for i in range(len(population)):nutcracker=population[i]# 觅食阶段new_nutcracker=forage(nutcracker,population)dert_fitness=new_nutcracker.get_fitness()-nutcracker.get_fitness()if dert_fitness>0 or random.random()<np.exp(dert_fitness/(it+1)):nutcracker=deepcopy(new_nutcracker)# 储存阶段best_population=store(nutcracker,best_population)# 缓存搜索阶段nutcracker=new_search(nutcracker,best_population)# 更新个体population[i]=nutcracker# 更新最优个体if nutcracker.fitness>best_nutcracker.fitness:best_nutcracker=deepcopy(nutcracker)record1.append(best_nutcracker.fitness)plot_convergence([record1])
m=plot_route(best_nutcracker)
m.save('improve.html')# %%
# 整数转二进制
def toBit(num, length):bit = []for i in range(length - 1, -1, -1):bit.append(int(num / (supply_point_num + cold_storage_num) ** i))num -= bit[-1] * (supply_point_num + cold_storage_num) ** ireturn bit# 麻雀个体
class Sparrow:def __init__(self, individual):self.individual = individualself.fitness = self.get_fitness()def get_fitness(self):fitness = 0result = self.decode()# 冷库建设成本bit = toBit(self.individual[0], vehicle_num)cold_set = set()for b in bit:if b >= supply_point_num:cold_set.add(b - supply_point_num)fitness += sum([cold_storage_fix_cost[c] for c in cold_set]) / (5 * 365)# 车辆运输成本 for i in result:if result[i]:fitness += vehicle_fix_cost[i]cur_point = bit[i]for j in result[i]:jj = j + supply_point_num + cold_storage_numfitness += vehicle_unit_cost[i] * distance_matrix[cur_point, jj]cur_point = jj# 需求延误成本for j in range(demand_point_num):min_arrive_time = 1e8max_arrive_time = 0for i in result:if j in result[i]:min_arrive_time = min(min_arrive_time, result[i][j]['time']['t1'])max_arrive_time = max(max_arrive_time, result[i][j]['time']['t1'])fitness += a1 * max(0, time_window[j][0] - min_arrive_time)fitness += a2 * max(0, max_arrive_time - time_window[j][1])self.fitness = 1 / fitnessreturn 1 / fitnessdef decode(self):result = {}bit = toBit(self.individual[0], vehicle_num)demand = deepcopy(demand_matrix)for i in self.individual[1]:result[i] = {}serve_order = self.individual[2 + i]capacity = deepcopy(vehicle_capacity[i])# 计算开始时间cur_time = distance_matrix[0, bit[i]] / vehicle_speed[i]cur_point = bit[i]result[i][cur_point] = {}result[i][cur_point]['serve'] = {0: 0, 1: 0, 2: 0}result[i][cur_point]['time'] = {'t1': cur_time, 't2': cur_time, 't3': cur_time}for j in serve_order:jj = j + supply_point_num + cold_storage_num# 车辆没有剩余容量if sum(capacity) == 0:break# 需求点没有剩余需求if sum([demand[j, p] for p in range(product_type)]) == 0:continueresult[i][j] = {}# 计算需求量result[i][j]['serve'] = {}for p in range(product_type):min_num = min(demand[j, p], capacity[p])demand[j, p] -= min_numcapacity[p] -= min_numresult[i][j]['serve'][p] = min_num# 计算时间arrive_time = cur_time + distance_matrix[cur_point, jj] / vehicle_speed[i]satrt_serve_time = max(arrive_time, time_window[j][0])departure_time = satrt_serve_time + time_window[j][2]result[i][j]['time'] = {'t1': arrive_time, 't2': satrt_serve_time, 't3': departure_time}cur_time = departure_timecur_point = jreturn result# 生成个体
def gen_sparrow():num = randint(0, (supply_point_num + cold_storage_num) ** vehicle_num - 1)vehicle_order = [i for i in range(vehicle_num)]random.shuffle(vehicle_order)serve_order = []for i in range(vehicle_num):cur_order = [j for j in range(demand_point_num)]random.shuffle(cur_order)serve_order.append(cur_order)individual = [num] + [vehicle_order] + serve_ordersparrow = Sparrow(individual)return sparrow# 生成种群
def get_population(num):population = []for i in range(num):population.append(gen_sparrow())return population# 获取最优个体
def get_best_sparrow(population):best_fitness = float('inf')best_sparrow = Nonefor sparrow in population:if sparrow.fitness < best_fitness:best_fitness = sparrow.fitnessbest_sparrow = sparrowreturn best_sparrow
# 混沌序列生成器(Logistic映射)
def logistic_map(x, r=3.99):return r * x * (1 - x)# 混沌初始化种群
def chaos_initialize_sparrows(population_size):population = []x = 0.5  # 初始值for _ in range(population_size):individual = []for _ in range(vehicle_num):x = logistic_map(x)num = int(x * ((supply_point_num + cold_storage_num) ** vehicle_num))vehicle_order = [i for i in range(vehicle_num)]random.shuffle(vehicle_order)serve_order = []for i in range(vehicle_num):cur_order = [j for j in range(demand_point_num)]random.shuffle(cur_order)serve_order.append(cur_order)individual = [num] + [vehicle_order] + serve_orderpopulation.append(Sparrow(individual))return population
# 觅食阶段
def forage(sparrow, population):# 随机探索if random.random() < exploring_probability:individual = sparrow.individualindividual[0] = randint(0, (supply_point_num + cold_storage_num) ** vehicle_num - 1)sparrow = Sparrow(individual)return sparrow# 最优探索else:best_sparrow = get_best_sparrow(population)individual = sparrow.individualbest_individual = best_sparrow.individualindividual[0] = best_individual[0]sparrow = Sparrow(individual)return sparrow# 储存阶段
def store(sparrow, best_population):new_best_population = deepcopy(best_population)new_best_population.append(sparrow)new_best_population = sorted(new_best_population, key=lambda x: x.fitness)return new_best_population[1:]# Levy飞行距离
def levy_distance(nutcracker1, nutcracker2):individual1 = nutcracker1.individualindividual2 = nutcracker2.individualdistance = abs(individual1[0] - individual2[0]) / max(individual1[0], individual2[0])for i in range(vehicle_num + 1):ii = i + 1sum1 = 0for j in range(len(individual1[ii])):sum1 += j * individual1[ii][j]sum2 = 0for j in range(len(individual2[ii])):sum2 += j * individual2[ii][j]distance += abs(sum1 - sum2) / max(sum1, sum2)return distance# 缓存搜索阶段
def search(sparrow, best_population):individual = sparrow.individualfor cur_sparrow in best_population:if levy_distance(sparrow, cur_sparrow) > distance:continuecur_individual = cur_sparrow.individualnew_individual = []for i in range(len(individual)):if randint(0, 1):new_individual.append(individual[i])else:new_individual.append(cur_individual[i])new_sparrow = Sparrow(new_individual)if new_sparrow.fitness > sparrow.fitness:sparrow = deepcopy(new_sparrow)return sparrow# 绘制收敛图
def plot_convergence(convergence_records):num_curves = len(convergence_records)  for i in range(num_curves):cur = convergence_records[i]convergence_records[i] = [1 / i for i in cur]colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']  plt.figure(figsize=(20, 10))for i, record in enumerate(convergence_records):iterations = list(range(1, len(record) + 1))plt.plot(iterations, record, marker='o', label=f'Curve {i+1}', color=colors[i % len(colors)])plt.title('Convergence Plots')  plt.xlabel('Iteration') plt.ylabel('Cost')  plt.legend()plt.grid(False)  plt.show()# %%
# 种群数量
population_num=20# 储存数量
store_num=5# 迭代次数
iteration_num=100# 探索概率
exploring_probability=0.5# 飞行距离
distance=2# 生成初始种群
population=get_population(population_num)# 最优个体
best_sparrow = get_best_sparrow(population)# 迭代求解
record2 = [best_sparrow.fitness]
best_population = sorted(population, key=lambda x: x.fitness)[-store_num:]
for it in tqdm(range(iteration_num)):for i in range(len(population)):sparrow = population[i]# 觅食阶段sparrow = forage(sparrow, population)# 储存阶段best_population = store(sparrow, best_population)# 缓存搜索阶段sparrow = search(sparrow, best_population)# 更新个体population[i] = sparrow# 更新最优个体if sparrow.fitness > best_sparrow.fitness:best_sparrow = deepcopy(sparrow)record2.append(best_sparrow.fitness)
plot_convergence([record2])# %%# 绘制收敛图的函数
def plot_convergence(convergence_records):num_curves = len(convergence_records)  for i in range(num_curves):cur = convergence_records[i]convergence_records[i] = [1 / i for i in cur]colors = ['b', 'g', 'r']  # 定义三条记录的颜色plt.figure(figsize=(20, 10))# 定义每条曲线的中文标签labels = ['NOA', 'NOA_SA', 'SSA']for i, record in enumerate(convergence_records):iterations = list(range(1, len(record) + 1))plt.plot(iterations, record, marker='o', label=labels[i], color=colors[i])plt.title('Convergence Plots')  plt.xlabel('Itterations')plt.ylabel('Cost')plt.legend()plt.grid(False)  plt.show()convergence_records = [record, record1, record2]
print(f'NOA:{record}')
print(f'NOA_SA:{record1}')
print(f'SSA:{record2}')# 调用函数绘制图表
plot_convergence(convergence_records)
**需软件开发兼职接项目,请通过手机端搜小#程#序: "黄页小艺”** 。

这段代码实现了一个基于星雀(Nutcracker)和麻雀(Sparrow)算法的物流配送路径规划问题求解程序,主要功能包括以下几个方面:

一、问题定义与参数设置

  1. 定义了物流配送中的各种参数,如需求点数量、供应点数量、冷库数量、产品种类、车辆数等。
  2. 生成了需求矩阵、时间窗、车辆容量、车辆承重和体积、车辆速度和行驶距离、车辆成本、产品重量和体积、冷库建设成本等数据。
  3. 定义了节点坐标和距离矩阵。

二、算法实现

  1. 整数转二进制函数toBit函数将一个整数转换为特定长度的二进制表示,用于后续的编码和解码操作。

  2. 个体类定义

    • Nutcracker类表示星雀个体,包含个体的编码、解码和适应度计算方法。解码过程根据个体编码确定车辆的服务顺序和路径,计算各种成本(冷库建设成本、车辆运输成本、需求延误成本)作为适应度。
    • Sparrow类表示麻雀个体,功能与星雀个体类似,也包含编码、解码和适应度计算方法。
  3. 生成个体和种群

    • gen_nutcracker函数生成星雀个体,包括随机生成的车辆分配、车辆顺序和服务顺序。
    • gen_sparrow函数生成麻雀个体,方式与生成星雀个体类似。
    • get_population函数根据给定数量生成星雀或麻雀种群。
  4. 获取最优个体get_best_nutcrackerget_best_sparrow函数分别用于在星雀和麻雀种群中获取适应度最高的个体。

  5. 觅食阶段forage函数实现了星雀和麻雀的觅食行为,包括随机探索和最优探索两种方式。

  6. 储存阶段store函数将当前个体加入到最佳种群中,并返回更新后的最佳种群。

  7. 缓存搜索阶段

    • search函数根据 Levy 飞行距离在最佳种群中进行搜索,生成新的个体,如果新个体适应度更高则更新当前个体。
    • new_search函数在search函数的基础上增加了交换操作,进一步探索解空间。
  8. 混沌初始化种群chaos_initialize_sparrows函数使用 Logistic 映射生成混沌序列,用于初始化麻雀种群,增加种群的多样性。

  9. Levy 飞行距离计算levy_distance函数计算两个个体之间的 Levy 飞行距离,用于缓存搜索阶段判断个体之间的相似性。

三、算法运行与结果展示

  1. 基础算法运行

    • 设置种群数量、储存数量、迭代次数、探索概率和飞行距离等参数。
    • 生成初始种群,找到最优个体。
    • 通过迭代进行觅食、储存和缓存搜索等操作,更新种群和最优个体,并记录最优个体的适应度。
    • 绘制收敛图,展示算法在迭代过程中适应度的变化情况。
    • 绘制路线图,使用 Folium 库在地图上展示车辆的行驶路径。
  2. 改进算法运行:与基础算法类似,但在觅食阶段增加了基于适应度差值和随机概率的接受新个体的条件。

  3. 麻雀算法运行

    • 定义麻雀个体和相关操作,与星雀算法类似。
    • 生成麻雀种群,进行迭代求解,记录适应度并绘制收敛图。
  4. 综合结果展示

    • 定义绘制收敛图的函数plot_convergence,可以同时展示多个算法的收敛情况,并为每条曲线添加中文标签。
    • 将三种算法(基础算法、改进算法、麻雀算法)的收敛记录合并,调用plot_convergence函数绘制综合收敛图。

总体来说,这段代码通过实现不同的优化算法来解决物流配送中的路径规划问题,包括确定车辆的分配、服务顺序和路径,以最小化总成本。同时,通过绘制收敛图和路线图展示算法的性能和结果。
需软件开发兼职接项目,请通过手机端搜小#程#序: "黄页小艺”

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/450704.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ChatGPT 现已登陆 Windows 平台

今天&#xff0c;OpenAI 宣布其人工智能聊天机器人平台 ChatGPT 已开始预览专用 Windows 应用程序。OpenAI 表示&#xff0c;该应用目前仅适用于 ChatGPT Plus、Team、Enterprise 和 Edu 用户&#xff0c;是一个早期版本&#xff0c;将在今年晚些时候推出"完整体验"。…

[每周一更]-(第119期):“BP”大揭秘:生物学与金融学中的微小单位竟有如此大不同!

最近&#xff08;2024.09.29&#xff09;央行要把存量房贷在LPR&#xff08;贷款市场报价利率&#xff09;基础上&#xff0c;降低30BP&#xff0c;刚好基因行业内&#xff0c;也有bp的概念&#xff0c;通过发音无法区分&#xff0c;以下就讲解下生物学的bp和金融学的BP的概念的…

汽车零部件行业CRM应用数字化解决方案解析

1.行业背景与挑战分析 近年来&#xff0c;随着国家对新能源汽车行业的大力支持&#xff0c;国内汽车产业不仅在国内市场实现了弯道超车&#xff0c;而且新能源汽车的海外出口也开拓了新的市场&#xff0c;为自主品牌的新能源战略贡献了新的增长点&#xff1b;这一迅猛发展的趋…

最新版快递小程序源码 独立版快递系统 附教程

内容目录 一、详细介绍二、效果展示1.部分代码2.效果图展示 三、学习资料下载 一、详细介绍 懂得都懂&#xff0c;现在电商平台退换货量大&#xff0c;快递需求量大&#xff0c;对接物流一个单子4块到6块之间 其中间是例如润 其余的 就不说了吧 互站上买的源码 分享一下 还有…

如何查看默认网关地址:详细步骤

在日常的网络配置与故障排查中&#xff0c;了解并正确查看默认网关地址是一项基础且至关重要的技能。默认网关是连接本地网络与外部网络&#xff08;如互联网&#xff09;的关键节点&#xff0c;它扮演着数据包转发的重要角色。无论是家庭网络、办公室网络还是更复杂的网络环境…

SSM框架学习(六、快速启动框架:SpringBoot3实战)

目录 一、SpringBoot3介绍 1.SpringBoot3简介 2.快速入门 3.入门总结 &#xff08;1&#xff09;Question1&#xff1a;为什么依赖不需要写版本&#xff1f; &#xff08;2&#xff09;Question2&#xff1a;启动器&#xff08;starter&#xff09;是什么&#xff1f; &a…

震惊!OpenAI突破性进展,清华天才联手破解扩散模型难题!

扩散模型很成功&#xff0c;但也有一块重大短板&#xff1a;采样速度非常慢&#xff0c;生成一个样本往往需要执行成百上千步采样。为此&#xff0c;研究社区已经提出了多种扩展蒸馏&#xff08;diffusion distillation&#xff09;技术&#xff0c;包括直接蒸馏、对抗蒸馏、渐…

如何将LiDAR坐标系下的3D点投影到相机2D图像上

将激光雷达点云投影到相机图像上做数据层的前融合&#xff0c;或者把激光雷达坐标系下标注的物体点云的3d bbox投影到相机图像上画出来&#xff0c;都需要做点云3D点坐标到图像像素坐标的转换计算&#xff0c;也就是LiDAR 3D坐标转像素坐标。 看了网上一些文章都存在有错误或者…

利用Llama3、CrewAI与Groq打造高效智能邮件客服系统

一、唠嗑 如果说AI的到来&#xff0c;哪个行业最有危机感&#xff0c;我觉得电商客服应该是榜上有名的。目前像淘宝、京东其实也是先用AI客服进行回复&#xff0c;客户不满意才使用人工客服&#xff0c;从而达到降本增效的目的。 而本次&#xff0c;就是使用 Llama3 CrewAI …

顺序表的查找

. GetElem(L,i):按位查找。获取L中的第i个位置元素的值。 静态查找&#xff1a; #define MaxSzie 10 typedef struct{ElemType data[MaxSize];int length; }Sqlist;ElemType GetElem(Sqlist L,int i) {return L.data[i-1]; }动态分配&#xff1a; #define InitSzie 10 type…

公司新来一个同事,把枚举运用得炉火纯青...

1.概览 在本文中&#xff0c;我们将看到什么是 Java 枚举&#xff0c;它们解决了哪些问题以及如何在实践中使用 Java 枚举实现一些设计模式。 enum关键字在 java5 中引入&#xff0c;表示一种特殊类型的类&#xff0c;其总是继承java.lang.Enum类&#xff0c;更多内容可以自行…

SpringBoot驱动的车辆信息管理平台

2相关技术 2.1 MYSQL数据库 MySQL是一个真正的多用户、多线程SQL数据库服务器。 是基于SQL的客户/服务器模式的关系数据库管理系统&#xff0c;它的有点有有功能强大、使用简单、管理方便、安全可靠性高、运行速度快、多线程、跨平台性、完全网络化、稳定性等&#xff0c;非常…

如何使用C#实现Padim算法的训练和推理

目录 说明 项目背景 算法实现 预处理模块——图像预处理 主要模块——训练&#xff1a;Resnet层信息提取 主要模块——信息处理&#xff0c;计算Anomaly Map 主要模块——评估 主要模块——评估&#xff1a;门限值的确定 主要模块——推理 写在最后 项目下载链接 说…

【即见未来,为何不拜】聊聊分布式系统中的故障监测机制——Phi Accrual failure detector

前言 昨天在看tcp拥塞控制中的BBR(Bottleneck Bandwidth and Round-trip propagation time)算法时&#xff0c;发现了这一特点&#xff1a; 在BBR以前的拥塞控制算法中(如Reno、Cubic、Vegas)&#xff0c;都依赖于丢包事件的发生&#xff0c;在高并发时则会看到网络波动的现象…

【含开题报告+文档+PPT+源码】基于SSM的景行天下旅游网站的设计与实现

开题报告 随着互联网的快速发展&#xff0c;旅游业也逐渐进入了数字化时代。作为一个旅游目的地&#xff0c;云浮市意识到了互联网在促进旅游业发展方面的巨大潜力。为了更好地推广云浮的旅游资源&#xff0c;提高旅游服务质量&#xff0c;云浮市决定开发一个专门的旅游网站。…

深入理解计算机系统--计算机系统漫游

对于一段最基础代码的文件hello.c&#xff0c;解释程序的运行 #include <stdio.h>int main() {printf ( "Hello, world\n") ;return 0; }1.1、信息就是位上下文 源程序是由值 0 和 1 组成的位&#xff08;比特&#xff09;序列&#xff0c;8 个位被组织成一组…

梯度下降算法优化—随机梯度下降、小批次、动量、Adagrad等方法pytorch实现

现有不足 现有调整网络的方法是借助成本函数的梯度下降方法&#xff0c;也就是给函数作切线&#xff0c;不断逼近最优点&#xff0c;即成本函数为零的点。 梯度下降的一般公式为&#xff1a; 即根据每个节点成本函数的梯度进行更新&#xff0c;使用该方法有一些问题&#xff…

探索OpenCV的人脸检测:用Haar特征分类器识别图片中的人脸

目录 简介 OpenCV和Haar特征分类器 实现人脸检测 1. 导入所需库 2. 加载图片和Haar特征分类器 3. 检测人脸 4. 标注人脸 5. 显示 6、结果展示 结论 简介 在计算机视觉和图像处理领域&#xff0c;人脸识别是一项重要的技术。它不仅应用于安全监控、人机交互&#xff0…

10秒钟用Midjourney画出国风味的变形金刚

上魔咒 Optimus Prime comes from the movie Transformers, Chinese style, Wu ShanMing, Ink Painting Halo Dyeing, Conceptual of the Digita Art, MasterComposition, Romantic Ancient Style, Inspired by traditional patterns and symbols, Minimalism, do not con…

day01 -- MybatisPlus

1. MybatisPlus简介 有基础的同学可结合资源中的代码一起看 MyBatis 的增强工具&#xff0c;在 MyBatis 的基础上只做增强不做改变&#xff0c;为简化开发、提高效率而生 特性 通用的 CRUD 操作&#xff1a;内置通用 Mapper、通用 Service&#xff0c;仅仅通过少量配置即可实…