SparkTC
来源:互联网 发布:enchant.js 编辑:程序博客网 时间:2024/06/07 06:10
1. 计算传递闭包(可到达路径数目)
2. 自动生成图,使用可变Set存储起点,终点
def generateGraph = { val edges: mutable.Set[(Int, Int)] = mutable.Set.empty while (edges.size < numEdges) { val from = rand.nextInt(numVertices) val to = rand.nextInt(numVertices) if (from != to) edges.+=((from, to)) } edges.toSeq }3. 初始化sparkConf, 以及初始化数据
val sparkConf = new SparkConf().setAppName("SparkTC") val spark = new SparkContext(sparkConf) val slices = if (args.length > 0) args(0).toInt else 2 var tc = spark.parallelize(generateGraph, slices).cache()4. 翻转起点和终点,方便join, (x,y) (y,z) ==>(x,z) 需要翻转(x,y)为(y,x)才能join出正确结果
val edges = tc.map(x => (x._2, x._1))
5.不断join,union并计算个数直到不变
var oldCount = 0L var nextCount = tc.count() do { oldCount = nextCount // Perform the join, obtaining an RDD of (y, (z, x)) pairs, // then project the result to obtain the new (x, z) paths. tc = tc.union(tc.join(edges).map(x => (x._2._2, x._2._1))).distinct().cache() nextCount = tc.count() } while (nextCount != oldCount)
0 0
- SparkTC
- SparkTC :Transitive closure on a graph(图中节点的可达性)
- 数据挖掘书单
- C语言字节对齐问题详解(对齐、字节序、网络序等)
- ubuntu 安装 wps.deb
- 如何使用pdf转换器
- 2017.07.19笔记、异常
- SparkTC
- 不要做一个浮躁的程序员
- 设计模式---抽象工厂模式
- hdu 1269 (tarjan)
- 在大数据中如何寻找相似的文档(shingle, minhash, LSH)(一)
- Objective-C语法之代码块(block)的使用
- 支付宝双功能支付详解
- css框架960Grid介绍
- codeforces 449C construtive algorithms,number theory