当前位置: 首页 > news >正文

启发式算法解决TSP、0/1背包和电路板问题

1. Las Vegas

题目

设计一个 Las Vegas 随机算法,求解电路板布线问题。将该算法与分支限界算法结合,观察求解效率。

代码

python代码如下:

# -*- coding: utf-8 -*-
"""
@Date    : 2024/1/4 
@Time    : 16:21
@Author  : MainJay
@Desc    : LasVegas算法解决电路问题
"""
import heapq
import randommaps = []
nums = 8for i in range(nums):m = []for j in range(nums):m.append(1 if random.random() < 0.3 else 0)maps.append(m)
b_x = random.randint(0, nums - 1)
b_y = random.randint(0, nums - 1)
e_x = random.randint(0, nums - 1)
e_y = random.randint(0, nums - 1)
while maps[b_x][b_y] == 1:b_x = random.randint(0, nums - 1)b_y = random.randint(0, nums - 1)
while maps[e_x][e_y] == 1:e_x = random.randint(0, nums - 1)e_y = random.randint(0, nums - 1)class Position(object):targetPosition = Nonedef __init__(self, x: int, y: int, length: int = 0):self.x = xself.y = yself.length = lengthdef __lt__(self, other):return self.length + abs(Position.targetPosition.x - self.x) + abs(Position.targetPosition.y - self.y) - (other.length + abs(Position.targetPosition.x - other.x) + abs(Position.targetPosition.y - other.y))class LasVegas(object):def __init__(self, initPosition: Position, targetPosition: Position):self.initPosition = initPositionPosition.targetPosition = targetPositiondef run(self):priority_queue = []heapq.heappush(priority_queue, self.initPosition)directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]flag = False  # 判断是否找到了解print(f"目标位置:{Position.targetPosition.x},{Position.targetPosition.y}")while priority_queue:item = heapq.heappop(priority_queue)print(f"现在位置:{item.x}, {item.y}")if item.x == Position.targetPosition.x and item.y == Position.targetPosition.y:flag = True# 找到解跳出break# 遍历can_position = []for direction in directions:t_x = item.x + direction[0]t_y = item.y + direction[1]if 0 <= t_x < len(maps) and 0 <= t_y < len(maps[0]):if maps[t_x][t_y] == 0:  # 没有标记且没有墙can_position.append(Position(t_x, t_y, item.length + 1))if len(can_position) > 0:# LasVegas算法随机挑选一个放入队列m_position = can_position[random.randint(0, len(can_position) - 1)]# 挑选的这个标记为已经走过maps[m_position.x][m_position.y] = 2heapq.heappush(priority_queue, m_position)return flagbegin = Position(b_x, b_y)
end = Position(e_x, e_y)
l = LasVegas(begin, end)
l.run()

运行结果

[1, 0, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 1, 1]
[1, 1, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 1, 0, 1, 0]
[1, 0, 0, 0, 0, 0, 0, 1]
[0, 1, 0, 0, 1, 1, 1, 0]
[0, 1, 0, 0, 1, 0, 0, 0]目标位置:5, 6
现在位置:3, 4
现在位置:3, 5
现在位置:4, 5
现在位置:5, 5
现在位置:5, 6

2. 模拟退火算法

题目

上机实现TSP的模拟退火算法,随机生成一定规模的数据或用通用数据集比较其它人的结果,分析算法的性能,摸索实现中技术问题的解决。

代码

python代码如下:

# -*- coding: utf-8 -*-
"""
@Date    : 2024/1/3 
@Time    : 16:15
@Author  : MainJay
@Desc    : 模拟退火算法解决TSP问题
"""
import random
from math import exp
import matplotlib.pyplot as pltdef create_new(ans: list):"""随机产生一个解:param ans: 原解:return: 返回一个解"""random_index1 = random.randint(0, len(ans) - 1)random_index2 = random.randint(0, len(ans) - 1)ans[random_index1], ans[random_index2] = ans[random_index2], ans[random_index1]return ansdef create_distance(nums: int = 25):"""随机生成距离矩阵:param nums: 城市数量:return: 矩阵函数"""distance = []for i in range(nums):d = []for j in range(nums):if i > j:d.append(distance[j][i])elif i == j:d.append(0)else:d.append(random.randint(0, 100) + random.random())distance.append(d)return distanceclass SimulatedAnnealing(object):def __init__(self, distance: list, initialTemperature: float = 100, endTemperature: float = 10, L: int = 5,alpha: float = 0.05):""":param distance: 距离矩阵:param initialTemperature: 初始温度:param endTemperature: 退火温度:param L: 每个温度的迭代次数:param alpha: 每次退火分数"""self.distance = distanceself.temperature = initialTemperatureself.endTemperature = endTemperatureself.L = Lself.result = []  # 记录每次退火过程中的最优解self.t = []  # 记录每次退火过程中的温度,用于画图self.alpha = alphadef temperature_down(self):"""温度退火:return:"""self.temperature = self.temperature * (1 - self.alpha)def cal_ans(self, ans: list):"""计算解的值:param ans: 解:return: 解的权值"""val = 0.00for i in range(0, len(ans) - 1):val += self.distance[ans[i]][ans[i + 1]]val += self.distance[ans[-1]][ans[0]]return valdef annealing(self):"""模拟退火过程:return:"""ans = list(range(len(self.distance)))  # 随机初始化一个解val = self.cal_ans(ans)while self.temperature > self.endTemperature:  # 直到温度降到指定结束温度时结束退火过程for i in range(self.L):  # 在每个温度迭代L次new_ans = create_new(ans)new_val = self.cal_ans(new_ans)df = new_val - valif df < 0:ans, val = new_ans, new_valelif random.uniform(0, 1) < 1 / (exp(df / self.temperature)):ans, val = new_ans, new_valself.result.append(val)self.t.append(self.temperature)self.temperature_down()def plot(self):# 在生成的坐标系下画折线图plt.plot(self.t, self.result)plt.gca().invert_xaxis()# 显示图形plt.show()distance = create_distance()
simulatedAnnealing = SimulatedAnnealing(distance)
simulatedAnnealing.annealing()
simulatedAnnealing.plot()

运行结果

请添加图片描述

3. 遗传算法

题目

上机实现 0/1 背包问题的遗传算法,分析算法的性能。

代码

python代码如下:

# -*- coding: utf-8 -*-
"""
@Date    : 2024/1/4 
@Time    : 14:45
@Author  : MainJay
@Desc    : 遗传算法解决0/1背包问题
"""
import random
import heapq
import copy
import matplotlib.pyplot as pltnums = 10
weights = []
values = []
W = 400for i in range(nums):weights.append(random.randint(0, 100))values.append(random.randint(0, 100))class GeneticAlgorithm(object):def __init__(self, N: int = 6, Nums: int = 10, Mutation_probability: float = 0.1, iter_num: int = 10):self.N = Nself.Nums = Numsself.iter_num = iter_num# 初始化种群self.population = []self.Mutation_probability = Mutation_probabilityfor i in range(N):p = []for j in range(len(weights)):p.append(random.randint(0, 1))self.population.append(p)def selectNPopulation(self, population: list):"""挑选一个种群:param population: 原始种群:return: 新种群"""nums = 0# 创建一个空的优先队列priority_queue = []for item in population:heapq.heappush(priority_queue, Individual(item))pops = []total_v = 0.00p = []# 优胜虐汰,挑选前Nums满足条件的while priority_queue and nums < self.Nums:item = heapq.heappop(priority_queue)if item.total_weight > W:continuepops.append(item.chromosome)total_v += item.total_valuep.append(total_v)nums += 1p = [item / total_v for item in p]# 根据概率分布随机挑选一个new_pop = []for i in range(self.N):rand = random.random()for j in range(len(p)):if rand <= p[j]:new_pop.append(pops[j])breakreturn new_popdef cross_population(self, population: list):parents = copy.deepcopy(population)for i in range(self.N):mother = parents[random.randint(0, len(parents) - 1)]father = parents[random.randint(0, len(parents) - 1)]threshold = random.randint(0, len(weights) - 1)sun1 = mother[:threshold] + father[threshold:]sun2 = father[:threshold] + mother[threshold:]population.append(sun1)population.append(sun2)return populationdef population_variation(self, population: list):"""种群基因突变:param population: 种群:return: 一个种群"""if random.random() < self.Mutation_probability:rand_pop = random.randint(0, len(population) - 1)rand_index = random.randint(0, len(weights) - 1)population[rand_pop][rand_index] = 1 - population[rand_pop][rand_index]return populationdef genetic(self):x = []y = []for i in range(self.iter_num):print(f"第{i + 1}代")print(f"种群为{self.population}")x.append(i + 1)y.append(Individual(self.population[0]).total_value)s_pop = self.selectNPopulation(self.population)c_pop = self.cross_population(s_pop)p_pop = self.population_variation(c_pop)self.population = p_popself.plot(x, y)def plot(self, x, y):# 在生成的坐标系下画折线图plt.plot(x, y)# 显示图形plt.show()class Individual(object):def __init__(self, chromosome: list):""":param chromosome: 染色体的列表"""self.chromosome = chromosomeself.total_weight = 0.00self.total_value = 0.00for i in range(len(chromosome)):if chromosome[i] == 1:self.total_weight += weights[i]self.total_value += values[i]def __lt__(self, other):return self.total_value > other.total_valueg = GeneticAlgorithm()
g.genetic()

运行结果

第1代
种群为[[0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 1, 1, 0, 0, 0], [1, 1, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 0, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 0, 1, 0, 1, 1, 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 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1]]
第10代
种群为[[1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 1]]

请添加图片描述

相关文章:

启发式算法解决TSP、0/1背包和电路板问题

1. Las Vegas 题目 设计一个 Las Vegas 随机算法&#xff0c;求解电路板布线问题。将该算法与分支限界算法结合&#xff0c;观察求解效率。 代码 python代码如下&#xff1a; # -*- coding: utf-8 -*- """ Date : 2024/1/4 Time : 16:21 Author : …...

阿里云新用户的定义与权益

随着云计算的普及&#xff0c;阿里云作为国内领先的云计算服务提供商&#xff0c;吸引了越来越多的用户。对于新用户来说&#xff0c;了解阿里云新用户的定义和相关权益非常重要&#xff0c;因为它关系到用户能否享受到更多的优惠和服务。 一、阿里云新用户的定义 阿里云新用户…...

go语言多线程操作

目录 引言 一、如何实现多线程 1. 线程的创建与管理: 2. 共享资源与同步: 3. 线程间通信: 4. 线程的生命周期管理: 5. 线程安全: 6. 考虑并发问题: 7. 性能与资源利用: 8. 特定语言或框架的工具和库: 二、go语言多线程 Goroutine 1. 轻量级: 2. 动态栈: 3. 调度:…...

GreatSQL社区2023全年技术文章总结

GreatSQL社区自成立以来一直致力于为广大的数据库爱好者提供一个交流与学习的平台。在2023年&#xff0c;我们见证了社区的蓬勃发展&#xff0c;见证了众多技术文章的诞生与分享。 此篇总结呈现GreatSQL社区2023年社区技术文章在CSDN发布的全部。这些文章涵盖了GreatSQL、MGR、…...

【论文阅读笔记】Stable View Synthesis 和 Enhanced Stable View Synthesis

目录 Stable View Synthesis摘要引言 Enhanced Stable View Synthesis 从Mip-NeRF360的对比实验中找到的两篇文献&#xff0c;使用了卷积神经网络进行渲染和新视角合成&#xff0c;特此记录一下 ToDo Stable View Synthesis paper&#xff1a;https://readpaper.com/pdf-ann…...

网络报文分析程序的设计与实现(2024)

1.题目描述 在上一题的基础上&#xff0c;参照教材中各层报文的头部结构&#xff0c;结合使用 wireshark 软件&#xff08;下载地址 https://www.wireshark.org/download.html#releases&#xff09;观察网络各层报文捕获&#xff0c;解析和分析的过程&#xff08;如下 图所示&a…...

贯穿设计模式-享元模式思考

写享元模式的时候&#xff0c;会想使用ConcurrentHashMap来保证并发&#xff0c;没有使用双重锁会不会有问题&#xff1f;但是在synchronize代码块里面需要尽量避免throw异常&#xff0c;希望有经验的同学能够给出解答&#xff1f; 1月6号补充&#xff1a;没有使用双重锁会有问…...

牛客刷题:BC45 小乐乐改数字(中等)

自我介绍&#xff1a;一个脑子不好的大一学生&#xff0c;c语言接触还没到半年&#xff0c;若涉及到效率等问题&#xff0c;各位都可以在评论区提出见解&#xff0c;谢谢啦。 该账号介绍&#xff1a;此帐号会发布游戏&#xff08;目前还只会简单小游戏&#xff09;&#xff0c…...

设计模式学习2

代理模式&#xff1a;Proxy 动机 “增加一层间接层”是软件系统中对许多复杂问题的一种常见解决方案。在面向对象系统中&#xff0c;直接食用某些对象会带来很多问题&#xff0c;作为间接层的proxy对象便是解决这一问题的常见手段。 2.伪代码&#xff1a; class ISubject{ pu…...

Rust:如何判断位置结构的JSON串的成员的数据类型

如何判断位置结构的JSON串的成员的数据类型&#xff0c;给一个Rust的例子&#xff0c;其中包含对数组的判断&#xff1f; 在Rust中&#xff0c;你可以使用serde_json库来处理JSON数据&#xff0c;并通过serde_json::Value类型的方法来判断JSON串中成员的数据类型。以下是一个示…...

Kafka(五)生产者

目录 Kafka生产者1 配置生产者bootstrap.serverskey.serializervalue.serializerclient.id""acksallbuffer.memory33554432(32MB)compression.typenonebatch.size16384(16KB)max.in.flight.requests.per.connection5max.request.size1048576(1MB)receive.buffer.byte…...

【Leetcode】242.有效的字母异位词

一、题目 1、题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。 示例1: 输入: s = "anagram", t = "nagaram" 输出: true示例2: 输入: …...

【数据库原理】(16)关系数据理论的函数依赖

一.函数依赖的概念 函数依赖是关系数据库中核心的概念&#xff0c;它指的是在属性集之间存在的一种特定的关系。这种关系表明&#xff0c;一个属性集的值可以唯一确定另一个属性集的值。 属性子集&#xff1a;在关系模式中&#xff0c;X和Y可以是单个属性&#xff0c;也可以是…...

脆弱的SSL加密算法漏洞原理以及修复方法

漏洞名称&#xff1a;弱加密算法、脆弱的加密算法、脆弱的SSL加密算法、openssl的FREAK Attack漏洞 漏洞描述&#xff1a;脆弱的SSL加密算法&#xff0c;是一种常见的漏洞&#xff0c;且至今仍有大量软件支持低强度的加密协议&#xff0c;包括部分版本的openssl。其实&#xf…...

SVN迁移至GitLab,并附带历史提交记录(二)

与《SVN迁移至GitLab&#xff0c;并附带历史提交记录》用的 git svn clone不同&#xff0c;本文使用svn2git来迁移项目代码。 一、准备工作 安装Git环境&#xff0c;配置本地git账户信息&#xff1a; git config --global user.name "XXX" git config --global us…...

如何创建容器搭建节点

1.注册Discord账号 https://discord.com/这是登录网址: https://discord.com/ 2.点击startnow注册,用discord注册或者邮箱注册都可,然后登录tickhosting Tick Hosting这是登录网址:Tick Hosting 3.创建servers 4.点击你创建的servers,按照图中步骤进行...

微众区块链观察节点的架构和原理 | 科普时间

践行区块链公共精神&#xff0c;实现更好的公众开放与监督&#xff01;2023年12月&#xff0c;微众区块链观察节点正式面向公众开放接入功能。从开放日起&#xff0c;陆续有多个观察节点在各地运行&#xff0c;同步区块链数据&#xff0c;运行区块链浏览器观察检视数据&#xf…...

React Admin 前端脚手架之ant-design-pro

文章目录 一、React Admin 前端脚手架选型二、React Admin 前端脚手架之ant-design-pro三、ant-design-pro使用步骤四、调试主题五、常用总结(持续更新)EditableProTable组件 常用组件EditableProTable组件 编辑某行后,保存时候触发发送请求EditableProTable组件,添加记录提…...

向爬虫而生---Redis 基石篇1 <拓展str>

前言: 本来是基于scrapy-redis进行讲解的,需要拓展一下redis; 包含用法,设计,高并发,阻塞等; 要应用到爬虫开发中,这些基础理论我觉得还是有必要了解一下; 所以,新开一栏! 把redis这个环节系统补上,再转回去scrapy-redis才好深入; 正文: Redis是一种内存数据库&#xff0c…...

【野火i.MX6ULL开发板】利用microUSB线烧入Debian镜像

0、前言 烧入Debian镜像有两种方式&#xff1a;SD卡、USB SD卡&#xff1a;需要SD卡&#xff08;不是所有型号都可以&#xff0c;建议去了解了解&#xff09;、SD卡读卡器 USB&#xff1a;需要microUSB线 由于SD卡的网上资料很多了&#xff0c;又因为所需硬件&#xff08;SD卡…...

“我在大A炒自己”

嘻嘻嘻&#xff0c;大伙儿好像还挺喜欢我闲聊&#xff0c;今天太忙&#xff0c;没得空精进技术&#xff0c;那咱还是接着闲聊吧&#x1f602;&#x1f602; 看到标题点进来的各位大A真爱粉&#xff0c;请先收下我的崇高敬意&#xff01;&#xff01;别误会&#xff0c;标题说的…...

js 颜色转换,RGB颜色转换为16进制,16进制颜色转为RGB格式

颜色转换&#xff0c;RGB颜色转换为16进制,16进制颜色转为RGB格式&#xff0c;可以自己设置透明度。 //十六进制颜色值的正则表达式 var reg /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; /*RGB颜色转换为16进制*/ String.prototype.colorHex function () {var that this;if (/^…...

uniapp中用户登录数据的存储方法探究

Hello大家好&#xff01;我是咕噜铁蛋&#xff01;作为一个博主&#xff0c;我们经常需要在应用程序中实现用户登录功能&#xff0c;并且需要将用户的登录数据进行存储&#xff0c;以便在多次使用应用程序时能够方便地获取用户信息。铁蛋通过科技手段帮大家收集整理了些知识&am…...

引导过程与服务控制

文章目录 一、Linux操作系统引导过程1、开机启动的完整过程1.1 开机自检&#xff08;BIOS&#xff09;1.2 MBR引导1.3 GRUB菜单1.4 加载内核&#xff08;kernel&#xff09;1.5 init进程初始化 2、系统初始化进程2.1 init进程2.2 systemdinit与systemd区别 3、Systemd单元类型4…...

《矩阵分析》笔记

来源&#xff1a;【《矩阵分析》期末速成 主讲人&#xff1a;苑长&#xff08;5小时冲上90&#xff09;】https://www.bilibili.com/video/BV1A24y1p76q?vd_sourcec4e1c57e5b6ca4824f87e74170ffa64d 这学期考矩阵论&#xff0c;使用教材是《矩阵论简明教程》&#xff0c;因为没…...

『App自动化测试之Appium应用篇』| Appium常用API及操作

『App自动化测试之Appium应用篇』| Appium常用API及操作 1 press_keycode1.1 键盘操作1.2 关于KeyCode1.3 press_keycode源码1.4 电话键相关1.5 控制键相关1.6 基本按键相关1.7 组合键相关1.8 符号键相关1.9 使用举例 2 swip方法2.1 swip说明2.2 swip使用方法2.3 使用示例 3 sc…...

VSCode搭建 .netcore 开发环境

一、MacOS 笔者笔记本电脑上安装的是macOS High Sierra(10.13)&#xff0c;想要尝试一下新版本的.netcore&#xff0c;之前系统是10.12时&#xff0c;.netcore 3.1刚出来时安装过3.1版本&#xff0c;很久没更新了&#xff0c;最近.net8出来了&#xff0c;想试一下&#xff0c;…...

python 写自动点击爬取数据

今天来点不一样的&#xff01;哥们 提示&#xff1a; 这里只是用于自己学习的 &#xff0c;请勿用违法地方 效果图 会进行点击下一页 进行抓取 需要其他操作也可以自己写 文章目录 今天来点不一样的&#xff01;哥们前言一、上代码&#xff1f;总结 前言 爬虫是指通过编程自动…...

CSDN博客重新更新

说来惭愧&#xff0c;好久没更新博客文章&#xff0c;导致个人博客网站&#xff1a;https://lenky.info/ 所在的网络空间和域名都过期了都没发觉&#xff0c;直到有个同事在Dim上问我我的个人博客为啥打不开了。。。幸好之前有做整站备份&#xff0c;后续慢慢把内容都迁回CSDN上…...

《剑指 Offer》专项突破版 - 面试题 5 : 单词长度的最大乘积(C++ 实现)

目录 前言 方法一 方法二 前言 题目链接&#xff1a;318. 最大单词长度乘积 - 力扣&#xff08;LeetCode&#xff09; 题目&#xff1a; 输入一个字符串数组 words&#xff0c;请计算不包含相同字符的两个字符串 words[i] 和 words[j] 的长度乘积的最大值。如果所有字符串…...

手机上的网站是怎么做的吗/精准粉丝引流推广

摘要 腾兴网为您分享:mysql中utf-8编码数据库转换成GBK编码的问题&#xff0c;之了课堂&#xff0c;易信&#xff0c;一折包邮&#xff0c;星球联盟等软件知识&#xff0c;以及七日杀&#xff0c;草莓软件&#xff0c;装修施工站&#xff0c;桔子会&#xff0c;桌面切换&#x…...

vs2012 vb 网站开发/google竞价推广

FS7501C USB 5V输入&#xff0c;升压给双节锂电池充电芯片IC 支持USB输入&#xff1a;5V2A最大。智能兼容5V1A&#xff0c;0.5A充电器&#xff0c;兼容不拉垮充电器。 &#xff08;输出端&#xff0c;即电池端&#xff09;充电电流最大1A&#xff0c;可调设置最大充电电流。…...

网站开发表格/广东省广州市白云区

个人整理 部分收藏于&#xff1a;http://www.cnblogs.com/hgmyz/p/5313983.html 自从学习.NET以来&#xff0c;优雅的编程风格&#xff0c;极度简单的可扩展性&#xff0c;足够强大开发工具&#xff0c;极小的学习曲线&#xff0c;让我对这个平台产生了浓厚的兴趣&#xff0c;在…...

广东网站建设服务公司/淘客推广

前言 市面上有 N 多个查询天气信息的软件、小程序以及网页入口&#xff0c;基本都是通过调用天气查询 API 去实现的。 今天整理了一下多种场景的天气预报API 接口分享给大家&#xff0c;有需要赶紧收藏起来。 天气预报查询 天气预报查询支持全国以及全球多个城市的天气查询…...

营销到底是干嘛的/优质的seo快速排名优化

为什么80%的码农都做不了架构师&#xff1f;>>> 查看显卡型号 lspci -nn | grep VGA 添加backports源&#xff0c;更新源 sudo echo "deb http://httpredir.debian.org/debian jessie-backports main contrib non-free" >> /etc/apt/sources.list…...

用JSP做的网站的缺点/百度广告联盟平台官网

【基础类】 问题一&#xff1a;RabbitMQ 中的 broker 是指什么&#xff1f;cluster 又是指什么&#xff1f; 答&#xff1a;broker 是指一个或多个 erlang node 的逻辑分组&#xff0c;且 node 上运行着 RabbitMQ 应用程序。cluster 是在 broker 的基础之上&#xff0c;增加了…...