Lecture 1-2


P19.Optimizing and heuristic algorithms

  • 最优解(优化算法)和启发式的区别、原因

相关知识点

  • 有关optimization的三个定义
    • optimization problem: can be described as the problem of finding the best solution from the set of all feasible solutions in some real or imagined scenario.
    • optimization model: can be described as a mathematical representation of optimization problem. It consists of parameters, decision variables, objective function and constraints.
    • optimization method: is an algorithm that is applied in order to solve an optimation problem.

最优解和启发式的区别

  • Optimizing and heuristic alogirithms
    • There are two categories of algorithms for sloving optimization problems
      • Optimizing: Guarantees to find the optimal solution
      • Heuristic: Does not guarantee to find the optimal solution, but usually generates a "good" solution within a reasonable amount of time.
    • Typically, heuristics can be stated as rules of thumb(经验法则) and they are often designed for a specific problem.

P20.Why heuristics?

为什么要选择启发式

  1. 得到最优解要消耗大量计算资源
    • An optimizing algorithm might consume too much resources.
  2. 输入可能不是很准确,而启发式算法有较强的鲁棒性,能够找到一个不错的解
    • Input to algorithm might be inaccurate and a heuristically good solution might be good enough.
  3. 启发式算法更容易理解
    • For a non-expert, it might be easier to uderstand a heuristic rather than an optimizing algorithm.

P22.Constructive heuristics(建设性启发式)

  • 均匀分布,在某个范围内等概率生成某些数
  • 步骤、过程,step0-2、了解一下流程图

定义

  • A constructive heuristic is a method that iteratively "builds up" a solution.(迭代地构建解决方案)

怎么构建

  • Assuming that a solution consists of solution components, it starts with nothing and adds one value of exactly one variable(恰好一个变量的值) in each iteration.

  • 详细描述

  • Let x = (x_1, x_2, x_n) denote a solution to our problem

    • 对应上面的Assuming a solution consists of solution components
  • step0: Initialization: Begin with all free solution x^{(0)} = (-, ..., -) and set solution index t = 0

    • 对应上面的start with nothing
  • step1: Termination criteria: If t = n, then break with approximate optimum (近似最优)x = x^{(t)}

    • 对应下方的终止条件
  • setp2: Choose a solution component x_p and a value for x_p that plausibly(似真的) leads to a good feasible solution at termination.

  • Set x^{(t+1)} = x^{t} but with fixed variable x_p

  • Set solution index t = t+1, and go to step1

    • 选择一个解决方案组件xp,并为xp选择一个值,该值似乎可以在终止时提供一个良好的可行解决方案。
    • 对应于上面的adds one value of exactly one variable in each iteration

结束条件

  • The algorithm ends when all variables have been assigned a value.

用途

  • ... are used to generate a feasible starting solution which can be improved by other algorithm later on.

P24.Greedy algorithm

构造启发式的一种自然且常见的类型是贪婪算法

  • A natural, and common type of constructive heuristics is greedy algorithms.
    • Each variable fixings(变量固定值) is choosen as the variable that locally improve the objective most.
    • Of course, variable fixings are choosen without breaking feasibility.

P26-.Huffman’s algorithm

  • 哈夫曼编码、文字压缩

  • Huffman's algorithm - A greedy, constructive, algorithm for text compression.

  • Huffman's algorithm is a greedy algorithm that identifies the optimal code for a particular character set and text to code.(只需记住它是一种贪婪算法)

P29.Graph

图的定义

  • A graph is a set of objects that are connected to each other through links.

P31.Binary tree

什么是树

  • 两种定义方式
    • A tree is an undirected graph where each pair of vertices is connected by exactly one path.
    • A tree connected with n vertices and n-1 edges.

什么是二叉树

  • A binary tree is a rooted tree in which no node has more than two children.

P35.Tries(prefix trees)

什么是Tries

  • Character codes can be represented using a special type of tree.
  • In a tries, each node is associated with a string and each edge is labeled with a sequence of characters.
  • The root is an empty node.
  • The value of a node is concatenating the value of its parent with the character sequence on the edge connecting it with the parent.

P36.Definition - Prefix

什么是前缀、后缀

  • A prefix can be described as a starting of a word.
举例:zhuyun的前缀
zhuyun
zhuyu
zhuy
zhu
zh
z

什么是前缀码

  • No character code is a prefix of another character code. This type of encoding is called prefix code.

给出字符串、能够写出前缀后缀、注意不止一个、是有一系列的前缀(上方的举例中有)

P42-.Huffmans’s algorithm

给一个例子,然后画出过程,构建huffman🎄

  • P43~P50中有例子

P58.Neighborhood search

用来求解背包问题(18年新题目)、把背包问题描述成数学的形式、自己写一遍算法、写出计算步骤

  • 定义邻居
    • 如果是在一维坐标轴上的实数
      • N ( \overline { x } ) = \left\{ x \in \mathbb { R } ^ { 1 } : | x - \overline { x } | \leq 1 \right\}
    • 如果是二维坐标
      • N ( \overline { x } , \overline { y } ) = \left\{ ( x , y ) \in \mathbb { R } ^ { 2 } : \sqrt { ( x - \overline { x } ) ^ { 2 } + ( x - \overline { y } ) ^ { 2 } } \leq 1 \right\}
  • 背包问题
    • Parameters:
      • n: The number of items
      • l: {1, ..., n} Index set over the n items
      • p_i: The value of item i
      • w_i: The weight of item i
      • W: The weight capacity of the knapsack
    • Decision variables:
      • x _ { i } \in \{ 0,1 \}
      • x_i = 1 if the item is chosen
      • x_i = 0 if the item is not chosen
    • Objective function:
      • Maximize \sum _ { i \in 1 } p _ { i } x _ { i }
    • Constraints:
      • \sum _ { i \in l } w _ { i } x _ { i } \leq W
      • x _ { i } \in \{ 0,1 \} \quad \forall i \in l
  • Example:
    • Maximize:

      • \sum _ { i = 1 } ^ { 4 } 4 x _ { 1 } + 10 x _ { 2 } + 5 x _ { 3 } + 8 x _ { 4 }
    • Subject to:

      • \sum _ { i = 1 } ^ { 4 } 3 x _ { 1 } + 9 x _ { 2 } + 4 x _ { 3 } + 6 x _ { 4 } \leq 12
      • x _ { i } \in \{ 0,1 \} \quad \forall i \in \{ 1,2,3,4 \}

  • 构建数学模型

    • Parameters:

      • n: 4
      • l: {1, 2, 3, 4}
      • p: {4, 10, 5, 8}
      • w: {3, 9, 4, 6}
      • W: 12
    • Decision variables:

      • x _ { i } \in \{ 0,1 \}
    • Subjective function:

      • MAX\sum _ { i = 1 } ^ { 4 } 4 x _ { 1 } + 10 x _ { 2 } + 5 x _ { 3 } + 8 x _ { 4 }
    • Constraints:

      • \sum _ { i = 1 } ^ { 4 } 3 x _ { 1 } + 9 x _ { 2 } + 4 x _ { 3 } + 6 x _ { 4 } \leq 12
  • 求解

x(0) = [0 0 1 0]T      Z = 5

N(x(0))  [1 0 1 0]T      Z = 9

            [0 1 1 0]T      infeasible

            [0 0 0 0]T      Z = 0

            [0 0 1 1]T      Z = 13

x(1) = [0 0 1 1]T

N(x(1))  [1 0 1 1]T     infeasible

            [0 1 1 1]T      infeasible

            [0 0 0 1]T      Z = 8

            [0 0 1 0]T      Z = 5

break

x(1) is local optimal

P89.Tabu search (不确定会考)

  • 哪些要、哪些不要
x(0) = [0 0 1 0]T      Z = 5               tabu:None

N(x(0))  [1 0 1 0]T      Z = 9

            [0 1 1 0]T      infeasible

            [0 0 0 0]T      Z = 0

            [0 0 1 1]T      Z = 13

x(1) = [0 0 1 1]T                             tabu: x(0)

N(x(1))  [1 0 1 1]T     infeasible

            [0 1 1 1]T      infeasible

            [0 0 0 1]T      Z = 8

            [0 0 1 0]T      Z = 5 (不选,this is tabu)



x(2) = [0 0 0 1]                                tabu:x(1)

N(x(2))  [1 0 0 1]   Z = 12

             [0 1 0 1]   infeasible

             [0 0 1 1]   tabu

             [0 0 0 0]    Z = 0

...


P108.Recursion

定义

  • A function that is defined in terms of itself is called recursive.

  • Recursive functions require at least one base case

    • A base case is an input value for which the function can be calculated without recursion.
    • Without a base case it is not possible to terminate the calculation of a recursion function.
    • 什么是base case(考点):base case是一个(输入)值,不需要递归就可以为其计算函数。

举例

  • Example: f(x) = 2f(x -1) , where f(0) = 0 (x >= 0), f(0)=0为base case

递归的基本规则

  • Fundamental rules of recursion:
    • Base cases: There needs to be at least one base case, which can be solved whithout recursion.
    • Progress: For the cases that are solved using recursion, recursive calls must progress towards a base case.

P119.Mergesort

  • 先分解再合并排序的过程
  • 写出每步步骤

分治divide-and- conquer

  • Divide-and-conquer is an algorithm design technique based on recursion.

  • 分治是一种基于递归的算法设计技术。

  • Divide: Smaller problems are solved recursively

  • Conquer: The solutions to the original problem is found by combining the solutions to the (smaller) subproblems.

    • 原问题的解是由(较小的)子问题的解的组合得到的。

P133.Dynamic Programming

  • 动态规划找出最优解、相比贪心算法的优点

P138

  • 不选、选、画出图、动态规划要掌握该图
  • 背包问题的动态规划图
  • 图一定要会画(必考
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354