def visibility_graph(series):
g = nx.Graph() # convert list of magnitudes into list of tuples that hold the index
tseries = []
n = 0
for magnitude in series:
tseries.append((n, magnitude))
n += 1 '''add nodes'''
for i in range(len(tseries)):
(ta, ya) = tseries[i]
g.add_node(ta, mag=ya) '''add edges'''
for a, b in combinations(tseries, 2):
(ta, ya) = a
(tb, yb) = b
connect = True
if tb - ta > 1:
(tc, yc) = max(tseries[ta + 1:tb]) #我的算法
print(tc,yc)
if (yc > yb + (ya - yb) * ((tb - tc) / (tb - ta))):
connect = False # medium = tseries[ta+1 :tb] #别人的算法
# for tc, yc in medium:
# if yc > yb + (ya - yb) * ((tb - tc) / (tb - ta)):
# connect = False if connect:
g.add_edge(ta, tb) return g

在第22行中,由于tseires 变成了嵌入元组, 所以max(tseries[ta + 1:tb]) 会取下标最大的值, 而非最大的第二个元素.

[(0, 0.19024852355156963),
(1, 0.6660417262541884),
(2, 0.395523497583831),
(3, 0.19024852355156963)]

my bug of VG algorithm的更多相关文章

  1. [poj2492]A Bug's Life(并查集+补集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 34678   Accepted: 11339 D ...

  2. POJ 2492 A Bug's Life

    传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...

  3. [POJ2586]Y2K Accounting Bug

    [POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  4. hdu A Bug's Life

    题目意思:给定一系列数对,例如a和b,表示a和b不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况. 例如给定: 1    2 3    4 1    3 那这里就是说1和2不是同种性别 ...

  5. 给MySQL官方提交的bug report备忘

    1.  Bug #72215 When LOCK_plugin conflicts very much, one uninstall-audit-plugin operation crash  htt ...

  6. How to implement an algorithm from a scientific paper

    Author: Emmanuel Goossaert 翻译 This article is a short guide to implementing an algorithm from a scie ...

  7. POJ2492 A Bug's Life

    Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 33833   Accepted: 11078 Description Ba ...

  8. POJ2586Y2K Accounting Bug(贪心 + 不好想)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12251   Accepted: 62 ...

  9. HNU 12833 Omar’s Bug(分情况讨论)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12833&courseid=268 解题报告:有个11个 ...

随机推荐

  1. spring cloud微服务快速教程之(八) Spring Cloud Alibaba--nacos(二)、配置中心

    0-前言 上一篇我们介绍了nacos作为服务注册发现组件的功能,nacos还具有配置中心的功能,而且支持热加载: 在此之前,配置中心有Spring Cloud Config,实际上,用这个有很多风险和 ...

  2. form表单中给input 添加 数量可以增减的按钮

    只需给input表单增加type=number即可

  3. maven 上传 jar 到本地私服

    You'll need to add a RankLib <dependency> tag set to your existing <dependencies> list. ...

  4. 判定PDF文件是否能够正常打开

    下载iTextSharp.dll using iTextSharp.text.pdf; PdfReader reader = new PdfReader(strPath + "\\" ...

  5. 在oracle中使用merge into实现更新和插入数据

    目录 oracle中使用merge into DUAL表解释 使用场景 用法 单表 多表 oracle中使用merge into DUAL表解释 在Oracle数据库中,dual是Oracle中的一个 ...

  6. P1527 [国家集训队]矩阵乘法 [整体二分]

    权值排序,整体二分,没了. // by Isaunoya #include <bits/stdc++.h> using namespace std; #define rep(i, x, y ...

  7. udp_demo(傻瓜来回发送)

    代码讲解 import socket # 发送数据 def send_data(udp_socket, dest_ip, dest_port): send_msg = input('请输入要发送的数据 ...

  8. F.Three pahs on a tree

    思路 两次bfs找出树的直径并处理出端点离树上各叶子节点的距离,在直径上找一点的子树叶子p3,使得dis(p1,p2) + dis(p2,p3) + dis(p1,p3)最大 易知上式是路径实长的两倍 ...

  9. 09 : 构造方法 & 代码块

    构造方法 概念 构造方法是一种特殊的方法,它是一个与类同名的方法 对象的创建就是通过构造方法来完成. 其功能主要是完成对象的创建或者对象的初始化 当类实例化new一个对象时会自动调用构造方法 构造方法 ...

  10. laravel本地化扩展包的下载使用

    1.下载扩展包 composer require caouecs/laravel-lang:~3.0 2.下载完成之后在根目录下的vendor中caouces\src下就是语言的扩展包 2.1我们复制 ...