【问题标题】:Implement custom algorithm In Graphframes在 Graphframes 中实现自定义算法
【发布时间】:2019-07-11 03:05:46
【问题描述】:

我想使用运行 pyspark 2.3 的 GraphFrames 在图上运行双连通图算法。

我意识到所有内置算法都在 Scala 中使用 GraphX 运行。

有没有一种方法可以在 scala - GraphX 中实现双连接算法,然后在 GraphFrames 对象上调用它?

有人熟悉这样的解决方案吗?

【问题讨论】:

    标签: apache-spark pyspark spark-graphx connected-components graphframes


    【解决方案1】:

    不,我不熟悉任何解决方案;我相信用这些程序是做不到的,最好的办法是用 JavaScript 制作你自己的程序(最好),如果你想要简单的 3D 图形,请查看 three.js,如果不是,只需使用 SVG 绘制各种形状,甚至纯CSS,这里是一些用于从两点创建一条线的 JavaScript 代码,只需将其与点数组一起使用来绘制图形(这里包含两个函数/类,一个是创建 DOM 节点的辅助函数):

    var Grapher = new (function() {
        this.el = function(opts) {
            if(!svgList.split(" ").find(x => x == opts.tag)) {
                this.node = document.createElement(opts.tag || "div");
            } else {
                this.node = document.createElementNS('http://www.w3.org/2000/svg', opts.tag);
            } 
    
            for(var k in opts) {
                if(k == "style") {
                    for(var s in opts[k]) {
                        this.node.style[s] = opts[k][s];
                    }
                } else if(k != "parent"){
                    this.node[k] = opts[k];
                }
            }
    
    
    
            this.setAttrs = (attrs) => {
                for(var k in attrs) {
                    this.node.setAttribute(k, attrs[k]);
                }
            };
            this.getAttr = (at) => {
                return this.node.getAttribute(at);
            };
    
            this.setStyle = (stl) => {
                for(var k in stl) {
                    this.node.style[k] = stl[k];
                }
            }
    
            var attr = opts.attr || {};
            this.setAttrs(attr);
            var optsPar = opts.parent;
            var par = null;
            if(optsPar) {
                if(optsPar.constructor == String) {
                    par = f("#" + optsPar);
                } else if(optsPar instanceof Element) {
                    par = optsPar;
                }
            }
    
            this.parent = par || document.body || {appendChild: (d) => {}};
            this.parent.appendChild(this.node);
         };
        this.line = (opts) => {
            var start = opts.start || {x:0,y:0},
                end = opts.end || {x:0,y:0},
                rise = end.y - start.y,
                run = end.x - start.x,
                slope = rise / run,
                boxWidth = Math.sqrt((rise * rise) + (run * run)),
                degAngle = Math.atan(slope) * 180 / Math.PI,
                thickness = opts.thickness || "2",
                holder = new this.el({
                    attr: {
                        class:"lineBox"
                    },
                    style: {
                        position:"absolute",
                        left:start.x,
                        top:start.y,
                        width:`${boxWidth}px`,
                        height:`${thickness}px`,
                        transform:`rotate(${degAngle}deg)`,
                        transformOrigin:"0 0",
                        background:opts.texture || "black"
                    },
                     parent:opts.parent
    
                });
        }
    })();
    

    然后使用 line 函数绘制各种线(从点到点):

    Grapher.line({
        start: {
            x:2,
            y:200
        }
        end: {
            x:10,
            y:500
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多