单源最短路径使用Dijkstra算法,给定起点,输出该点和其他所有节点的最短路径。本文为您介绍PAI-Studio提供的单源最短路径组件。
PAI-Studio支持通过可视化或PAI命令方式,配置单源最短路径组件的参数。
可视化方式
页签 | 参数 | 描述 |
---|---|---|
字段设置 | 选择源顶点列 | 边表的起点所在列。 |
选择目标顶点列 | 边表的终点所在列。 | |
选择边权值列 | 边表边的权重所在列。 | |
参数设置 | 起始节点 ID | 用于计算最短路径的起始节点,必填。 |
执行调优 | 进程数 | 作业并行执行的节点数。数字越大并行度越高,但是框架通讯开销会增大。 |
进程内存 | 单个作业可使用的最大内存量。系统默认为每个作业分配4096 MB内存,实际使用内存超过该值,会抛出OutOfMemory异常。 |
PAI命令方式
PAI -name SSSP
-project algo_public
-DinputEdgeTableName=SSSP_func_test_edge
-DfromVertexCol=flow_out_id
-DtoVertexCol=flow_in_id
-DoutputTableName=SSSP_func_test_result
-DhasEdgeWeight=true
-DedgeWeightCol=edge_weight
-DstartVertex=a;
参数 | 是否必选 | 描述 | 默认值 |
---|---|---|---|
inputEdgeTableName | 是 | 输入边表名。 | 无 |
inputEdgeTablePartitions | 否 | 输入边表的分区。 | 全表读入 |
fromVertexCol | 是 | 输入边表的起点所在列。 | 无 |
toVertexCol | 是 | 输入边表的终点所在列。 | 无 |
outputTableName | 是 | 输出表名。 | 无 |
outputTablePartitions | 否 | 输出表的分区。 | 无 |
lifecycle | 否 | 输出表的生命周期。 | 无 |
workerNum | 否 | 作业并行执行的节点数。数字越大并行度越高,但是框架通讯开销会增大。 | 未设置 |
workerMem | 否 | 单个作业可使用的最大内存量。系统默认为每个作业分配4096 MB内存,实际使用内存超过该值,会抛出OutOfMemory异常。 | 4096 |
splitSize | 否 | 数据切分大小。 | 64 |
startVertex | 是 | 起始节点ID。 | 无 |
hasEdgeWeight | 否 | 输入边表的边是否有权重。 | false |
edgeWeightCol | 否 | 输入边表边的权重所在列。 | 无 |
使用示例
- 生成训练数据。
drop table if exists SSSP_func_test_edge; create table SSSP_func_test_edge as select flow_out_id,flow_in_id,edge_weight from ( select "a" as flow_out_id,"b" as flow_in_id,1.0 as edge_weight from dual union all select "b" as flow_out_id,"c" as flow_in_id,2.0 as edge_weight from dual union all select "c" as flow_out_id,"d" as flow_in_id,1.0 as edge_weight from dual union all select "b" as flow_out_id,"e" as flow_in_id,2.0 as edge_weight from dual union all select "e" as flow_out_id,"d" as flow_in_id,1.0 as edge_weight from dual union all select "c" as flow_out_id,"e" as flow_in_id,1.0 as edge_weight from dual union all select "f" as flow_out_id,"g" as flow_in_id,3.0 as edge_weight from dual union all select "a" as flow_out_id,"d" as flow_in_id,4.0 as edge_weight from dual ) tmp;
对应的图结构如下所示。 - 查看训练结果。
+------------+------------+------------+--------------+ | start_node | dest_node | distance | distance_cnt | +------------+------------+------------+--------------+ | a | b | 1.0 | 1 | | a | c | 3.0 | 1 | | a | d | 4.0 | 3 | | a | a | 0.0 | 0 | | a | e | 3.0 | 1 | +------------+------------+------------+--------------+
在文档使用中是否遇到以下问题
更多建议
匿名提交