5 Choosing the optimal algorithm

在优化CPU密集型软件时,首要任务是找到最佳算法。对于排序、搜索和数学计算等任务来说,选择合适的算法非常重要。通过选择最佳算法,你可以比优化脑海中首先想到的算法获得更好的效果。在某些情况下,你可能需要测试多个不同的算法,以找到在典型的测试数据集上表现最好的算法。
话虽如此,我必须警告不要过度设计。如果简单算法足够快地完成工作,就不要使用复杂的高级算法。例如,有些程序员甚至对最小的数据列表使用哈希表。哈希表可以大幅提高在非常大的数据库中的搜索时间,但对于那些列表非常小,二分查找甚至线性查找就足够快的情况下,使用哈希表是没有必要的。哈希表会增加程序和数据文件的大小。如果瓶颈是文件访问或缓存访问而不是CPU时间,实际上可能会降低速度。复杂的算法的另一个缺点是会增加程序开发的成本和出错的可能性。
对于不同目的的不同算法的讨论超出了本手册的范围。你需要参考关于算法和数据结构的通用文献,以了解标准任务(如排序和搜索)的算法,或者更复杂数学任务的专门文献。
在开始编码之前,你可以考虑是否有其他人已经在你之前完成了相同的工作。许多常见任务的优化函数库可从多个来源获取。例如,Boost库包含了许多常见目的的经过良好测试的库(www.boost.org)。"英特尔数学核心库"包含了许多常见的数学计算函数,包括线性代数和统计学,而"英特尔性能基元"库则包含了许多音频和视频处理、信号处理、数据压缩和加密的函数(www.intel.com)。如果使用英特尔函数库,请确保其在非英特尔处理器上表现良好,详见第143页的说明。
在开始编程之前,选择最优算法往往比实际做到更容易。许多程序员发现,只有在将整个软件项目组合起来进行测试后,才会发现有更聪明的做事方式。通过测试和分析程序性能以及研究瓶颈问题,你可以对问题的整体结构有更好的理解。这种新的认识可能会导致对程序的完全重设计,例如当你发现有更聪明的数据组织方式时。
对已经工作的程序进行全面重设计当然是一项相当大的工作,但可能是一个不错的投资。重新设计不仅可以提高性能,还很可能导致更好结构的程序,更易于维护。你在重新设计程序上花费的时间实际上可能比你在原始设计不良的程序上解决问题所花费的时间少。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Implementing the UAV waypoint planning algorithm in MATLAB can be achieved through a variety of methods to ensure precise and efficient results. Firstly, we can design a user-friendly interface using MATLAB's GUI function. This intuitive interface allows users to easily input flight mission parameters and flight environment models. Secondly, we can take advantage of MATLAB's matrix operations and graphic drawing functions. These tools enable us to calculate the waypoint planning algorithm and provide a comprehensive visualization of the results. Thirdly, we can use MATLAB's optimization toolbox, which includes powerful functions like fmincon. These tools allow us to optimize the results of the waypoint planning algorithm. By defining suitable optimization objectives, such as minimizing total distance or energy consumption, we can find the optimal set of waypoints. Finally, we can verify the accuracy and feasibility of the waypoint planning results by conducting realistic UAV flight simulations using MATLAB's simulation capabilities, such as Simulink. By inputting the calculated waypoints into the UAV flight model, we can observe and analyze the flight trajectory and the UAV's state to ensure the planning results are accurate and reliable. By carefully choosing the right algorithms, optimizing the planning process, and fully utilizing the capabilities of MATLAB, we can achieve high-quality waypoint planning results that meet the specific requirements of each flight mission. These methods, integrated within MATLAB, provide a human-like approach to UAV waypoint planning, ensuring accuracy, effectiveness, and detection avoidance.还能检测出来,这个基础上再修改
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值