1. Strategies for NP-Complete Problems
-- Identify computationally tractable special cases.
- knapsack capacity W = polynomial in number of items n
-- Heuristics
- Pretty good greedy heuristic
- Excellent dynamic programming heuristic
-- Exponential time but better than brute-force search
- O(nW)-time dynamic programming vs. O(2^n) brute-force search.
2. Knapsack Revisited
-- Input: n items. Each has a positive value vi and a size wi . Also, knapsack capacity is W.
-- Output: A subset S in {1, 2, ..., n} that maximizes Sum(i in S) {vi} subject to Sum(i in S) {wi} <=W
3. A Greedy Heuristic
-- Motivation: Ideal items have big value, small size.
-- Step 1: Sort and reindex item so that v1/w1 >= v2/w2 >= ... >=vn/wn
-- Step 2: Pack items in this order until one doesn't fit, then halt. (can continue to pack the follow-up items that can fit)
4. A Refined Greedy Heuristic
-- Fact: Greedy solution can be arbitrarily bad relative to an optimal solution.(i.e. v1 = 2, w1 = 1, v2 = 1000, w2 = 1000, W = 1000)
-- Fix: Step 3: Return either the Step 2 solution, or the maximum valuable item, whichever is better.
-- Theorem: Value of the 3-step greedy solution is always at least 50% value of an optimal solution. -- Runnig time: O(n log n)
5. Greedy Fractional Algorithm
-- We were allowed to fill fully the knapsack using a suitable “fraction" (like 70%) of item (k+1)
-- Greedy fractional solution at least as good as every non-fractional feasible solution.
-- Let S = an arbitrary feasible solution
-- Suppose l units of knapsack filled by S with items not packed by the greedy fractional solution
-- Must be at least l units of knapsack filled by greedy fractional solution not packed by S
-- By greedy criterion, items in Greedy Fractional solution have larger bang-per-buck vi/wi than those in S [i.e., more valuable use of space]
-- Total value of greedy fractional solution at least that of S
6. Analysis of Greedy Heuristic
-- Suppose our greedy algorithm picks the 1st k items (sorted by vi/wi ).
-- Value of 3-step greedy algorithm >= total value of 1st k items
Value of 3-step greedy algorithm >= value of (k + 1)th item
2 (value of 3-step greedy) >= total value of 1st (k + 1) items = total value of greedy fractional solution >= optimal knapsack solution
-- Analysis is Tight (i.e. W = 1000 , v1 = 502, v2 = v3 = 500, w1 = 501, w2 = w3 = 500)
7. A Refined Analysis
-- Suppose: Every item i has size wi <= 10% * knapsack capacity W.
-- Consequence: If greedy algorithm fails to pack all items, then the knapsack is >= 90% full.
-- Value of 2-step greedy algorithm >= 90% * value of greedy fractional solution >= 90% * value of an optimal solution.
-- In general, if maxi wi <= m%W, then 2-step greedy value is >= (1 - m%)*optimal
8. Arbitrarily Good Approximation
-- Goal: For a user-specified parameter e > 0 (e.g., e = 0.01), guarantee a (1 - e)-approximation.
-- Catch: Running time will increase as e decreases. (i.e., algorithm exports a running time vs. accuracy trade-off).
-- High-level idea: Exactly solve a slightly incorrect, but easier, knapsack instance.
-- If vi's are integers, can solve knapsack via dynamic programming in O(n^2vmax) time, where vmax = maxi{vi}.
-- Plan: Throw out lower-order bits of the vi's!
9. A Dynamic Programming Heuristic
-- Step 1: Round each vi down to the nearest multiple of m [larger m ==> throw out more info ==> less accuracy ==> m depends on e]
Divide the results by m to get vi' (integers). (i.e., vi' = floor(vi/m) )
-- Step 2: Use dynamic programming to solve the knapsack instance with values v1', ... , vn', sizes w1, ..., wn, capacity W.
Running time = O(n^2 max{vi'})
10. Two Dynamic Programming Algorithms
-- Dynamic programming algorithm #1:
-- Assume sizes wi and capacity W are integers
-- Running time = O(nW)
-- Dynamic programming algorithm #2:
-- Assume values vi are integers
-- Running time = O(n^2vmax), where vmax = max{vi}
11. The Subproblems and Recurrence
-- Subprolems: For i = 0, 1, ... , n and x = 0, 1, ... , n*vmax define
S(i,x) = minimum total size needed to achieve value >= x while using only the first i items. (Or +Infinity if impossible)
-- Recurrence: (i >= 1)
S(i,x) = min { S(i-1,x) [Case 1, item i not used in optimal solution] , wi + S(i-1,x-vi) [Case 2, item i used in optimal solution, interpreted as 0 if vi > x]
12. The Algorithm
-- Let A = 2-D array [indexed by i = 0, 1, ... , n and x = 0, 1, ... , n*vmax]
-- Base case: A[0,x] = 0 if x = 0 , +Infinity otherwise
-- For i = 1, 2, ... , n
For x = 0, 1, ... , n*vmax
A[i,x] = min{A[i-1,x] , wi+ A[i-1,x-vi]}
-- Return the largest x such that A[n,x] <= W
-- Running time: O(n^2vmax)
13. Accuracy Analysis
-- Since we rounded down to the nearest multiple of m, m*vi' in [vi-m , vi] for each item i.
-- If S* = optimal solution to the original problem (with the original vi), and S = our heuristic's solution, then
Sum(i in S){vi'} >= Sum(i in S*){vi'} [Since S is optimal for the vi']
-- Sum(i in S){vi} >= m * Sum(i in S) {vi'} >= m * Sum(i in S*){vi'} >= Sum{i in S*} {vi -m} >= Sum(i in S*} - nm
-- Constraint: Sum(i in S){vi} >= (1-e)*Sum(i in S*){vi}
-- To achieve above constraint: Choose m small enough that mn <= e * Sum(i in S*){vi}
Sum(i in S*){vi} is unknown to algorithm, but definitely >= vmax
Sufficient: Set m so that mn <= e*vmax, i.e., heuristic uses m = e*vmax/n
-- Running time is O(n^2vmax') , vmax' <= vmax/m = vmax / (e*vmax/n) , so running time is O(n^3/e)
相关推荐
2. **贪心算法(Greedy Algorithm)**:在每一步选择局部最优解以期望达到全局最优。 3. **完全搜索(Complete Search)**:对所有可能的情况进行遍历以找到最优解。 4. **填充算法(Flood Fill)**:用于二维数组或...
例如,在解决TSP时,可以使用诸如 nearest neighbor 或 greedy algorithm 的简单策略,或者更复杂的算法如 Christofides algorithm 或 Lin-Kernighan heuristic。对于背包问题,动态规划是一种常用的高效方法,而...
#### 二、贪心算法(Greedy Algorithm) **知识点概览:** 贪心算法是一种在每一步选择中都采取当前看起来最优的选择,以期达到全局最优解的算法策略。适用于问题满足贪心选择性质和最优子结构性质。 **核心思想:...
内容概要:本文详细介绍了如何利用Matlab构建、优化和应用决策分类树。首先,讲解了数据准备阶段,将数据与程序分离,确保灵活性。接着,通过具体实例展示了如何使用Matlab内置函数如fitctree快速构建决策树模型,并通过可视化工具直观呈现决策树结构。针对可能出现的过拟合问题,提出了基于成本复杂度的剪枝方法,以提高模型的泛化能力。此外,还分享了一些实用技巧,如处理连续特征、保存模型、并行计算等,帮助用户更好地理解和应用决策树。 适合人群:具有一定编程基础的数据分析师、机器学习爱好者及科研工作者。 使用场景及目标:适用于需要进行数据分类任务的场景,特别是当需要解释性强的模型时。主要目标是教会读者如何在Matlab环境中高效地构建和优化决策分类树,从而应用于实际项目中。 其他说明:文中不仅提供了完整的代码示例,还强调了代码模块化的重要性,便于后续维护和扩展。同时,对于初学者来说,建议从简单的鸢尾花数据集开始练习,逐步掌握决策树的各项技能。
《营销调研》第7章-探索性调研数据采集.pptx
Assignment1_search_final(1).ipynb
美团优惠券小程序带举牌小人带菜谱+流量主模式,挺多外卖小程序的,但是都没有搭建教程 搭建: 1、下载源码,去微信公众平台注册自己的账号 2、解压到桌面 3、打开微信开发者工具添加小程序-把解压的源码添加进去-appid改成自己小程序的 4、在pages/index/index.js文件搜流量主广告改成自己的广告ID 5、到微信公众平台登陆自己的小程序-开发管理-开发设置-服务器域名修改成
《计算机录入技术》第十八章-常用外文输入法.pptx
基于Andorid的跨屏拖动应用设计实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
《网站建设与维护》项目4-在线购物商城用户管理功能.pptx
区块链_房屋转租系统_去中心化存储_数据防篡改_智能合约_S_1744435730
《计算机应用基础实训指导》实训五-Word-2010的文字编辑操作.pptx
《移动通信(第4版)》第5章-组网技术.ppt
ABB机器人基础.pdf
《综合布线施工技术》第9章-综合布线实训指导.ppt
很不错的一套站群系统源码,后台配置采集节点,输入目标站地址即可全自动智能转换自动全站采集!支持 https、支持 POST 获取、支持搜索、支持 cookie、支持代理、支持破解防盗链、支持破解防采集 全自动分析,内外链接自动转换、图片地址、css、js,自动分析 CSS 内的图片使得页面风格不丢失: 广告标签,方便在规则里直接替换广告代码 支持自定义标签,标签可自定义内容、自由截取、内容正则截取。可以放在模板里,也可以在规则里替换 支持自定义模板,可使用标签 diy 个性模板,真正做到内容上移花接木 调试模式,可观察采集性能,便于发现和解决各种错误 多条采集规则一键切换,支持导入导出 内置强大替换和过滤功能,标签过滤、站内外过滤、字符串替换、等等 IP 屏蔽功能,屏蔽想要屏蔽 IP 地址让它无法访问 ****高级功能*****· url 过滤功能,可过滤屏蔽不采集指定链接· 伪原创,近义词替换有利于 seo· 伪静态,url 伪静态化,有利于 seo· 自动缓存自动更新,可设置缓存时间达到自动更新,css 缓存· 支持演示有阿三源码简繁体互转· 代理 IP、伪造 IP、随机 IP、伪造 user-agent、伪造 referer 来路、自定义 cookie,以便应对防采集措施· url 地址加密转换,个性化 url,让你的 url 地址与众不同· 关键词内链功能· 还有更多功能等你发现…… 程序使用非常简单,仅需在后台输入一个域名即可建站,不限子域名,站群利器,无授权,无绑定限制,使用后台功能可对页面进行自定义修改,在程序后台开启生 成功能,只要访问页面就会生成一个本地文件。当用户再次访问的时候就直接访问网站本地的页面,所以目标站点无法访问了也没关系,我们的站点依然可以访问, 支持伪静态、伪原创、生成静态文件、自定义替换、广告管理、友情链接管理、自动下载 CSS 内的图。
【自然语言处理】文本分类方法综述:从基础模型到深度学习的情感分析系统设计
基于Andorid的下拉浏览应用设计实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
内容概要:本文详细介绍了一个原创的P2插电式混合动力系统Simulink模型,该模型基于逻辑门限值控制策略,涵盖了多个关键模块如工况输入、驾驶员模型、发动机模型、电机模型、制动能量回收模型、转矩分配模型、运行模式切换模型、档位切换模型以及纵向动力学模型。模型支持多种标准工况(WLTC、UDDS、EUDC、NEDC)和自定义工况,并展示了丰富的仿真结果,包括发动机和电机转矩变化、工作模式切换、档位变化、电池SOC变化、燃油消耗量、速度跟随和最大爬坡度等。此外,文章还深入探讨了逻辑门限值控制策略的具体实现及其效果,提供了详细的代码示例和技术细节。 适合人群:汽车工程专业学生、研究人员、混动汽车开发者及爱好者。 使用场景及目标:①用于教学和科研,帮助理解和掌握P2混动系统的原理和控制策略;②作为开发工具,辅助设计和优化混动汽车控制系统;③提供仿真平台,评估不同工况下的混动系统性能。 其他说明:文中不仅介绍了模型的整体架构和各模块的功能,还分享了许多实用的调试技巧和优化方法,使读者能够更好地理解和应用该模型。
内容概要:本文详细介绍了基于ADMM(交替方向乘子法)算法在电力系统分布式调度中的应用,特别是并行(Jacobi)和串行(Gauss-Seidel)两种不同更新模式的实现。文中通过MATLAB代码展示了这两种模式的具体实现方法,并比较了它们的优劣。并行模式适用于多核计算环境,能够充分利用硬件资源,尽管迭代次数较多,但总体计算时间较短;串行模式则由于“接力式”更新机制,通常收敛更快,但在计算资源有限的情况下可能会形成瓶颈。此外,文章还讨论了惩罚系数rho的自适应调整策略以及在电-气耦合系统优化中的应用实例。 适合人群:从事电力系统优化、分布式计算研究的专业人士,尤其是有一定MATLAB编程基础的研究人员和技术人员。 使用场景及目标:①理解和实现ADMM算法在电力系统分布式调度中的应用;②评估并行和串行模式在不同应用场景下的性能表现;③掌握惩罚系数rho的自适应调整技巧,提高算法收敛速度和稳定性。 其他说明:文章提供了详细的MATLAB代码示例,帮助读者更好地理解和实践ADMM算法。同时,强调了在实际工程应用中需要注意的关键技术和优化策略。