Skip to content

设置节点连接 - SetNodeConnection

函数简介

设置两个节点间的连接关系,可新增/更新边(并设置权重),或删除对应的边。

接口名称

SetNodeConnection

DLL调用

c
int32_t SetNodeConnection(int64_t instance, int64_t graphPtr, char* from, char* to, bool canConnect, double weight);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
graphPtr长整数型图的指针。
from字符串起始节点名称。
to字符串目标节点名称。
canConnect整数型是否可以连接(true 创建/更新边;false 删除边)。
weight双精度浮点数连接权重(canConnect 为 true 时使用;-1 表示使用欧氏距离)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]");
if (graphPtr != 0) {
    int ret = ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long graphPtr = ola.CreateGraph(@"[{"directed":false,"from":"上海","to":"北京","weight":3.0},{"directed":false,"from":"北京","to":"深圳","weight":5.0}]");
if (graphPtr != 0)
{
    int ret = ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
graph_ptr = ola.CreateGraph(r'[{"directed":false,"from":"上海","to":"北京","weight":3.0},{"directed":false,"from":"北京","to":"深圳","weight":5.0}]')
if graph_ptr != 0:
    ret = ola.SetNodeConnection(graph_ptr, "上海", "深圳", True, 8.0)
    ola.DeleteGraph(graph_ptr)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]");
if (graphPtr != 0) {
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]")
if(graphPtr) {
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]")
If graphPtr <> 0 Then
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
graphPtr = ola.CreateGraph (“[{\“directed\“:false,\“from\“:\“上海\“,\“to\“:\“北京\“,\“weight\“:3.0},{\“directed\“:false,\“from\“:\“北京\“,\“to\“:\“深圳\“,\“weight\“:5.0}]“)
.如果真 (graphPtr ≠ 0)
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph (graphPtr)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]");
if(graphPtr){
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]")
如果真 (graphPtr ≠ 0)
{
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long graphPtr = ola.CreateGraph("[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]");
if (graphPtr != 0) {
    ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    ola.DeleteGraph(graphPtr);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long graphPtr = CreateGraph(instance, "[{\"directed\":false,\"from\":\"上海\",\"to\":\"北京\",\"weight\":3.0},{\"directed\":false,\"from\":\"北京\",\"to\":\"深圳\",\"weight\":5.0}]");
if (graphPtr != 0) {
    int ret = ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    DeleteGraph(instance, graphPtr);
}
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long graphPtr = CreateGraph(instance, @"[{"directed":false,"from":"上海","to":"北京","weight":3.0},{"directed":false,"from":"北京","to":"深圳","weight":5.0}]");
if (graphPtr != 0) {
    int ret = ola.SetNodeConnection(graphPtr, "上海", "深圳", true, 8.0);
    DeleteGraph(instance, graphPtr);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
graph_ptr = ola.CreateGraph(instance, b'[{"directed":false,"from":"上海","to":"北京","weight":3.0},{"directed":false,"from":"北京","to":"深圳","weight":5.0}]')
if graph_ptr:
    ret = ola.SetNodeConnection(graph_ptr, "上海", "深圳", True, 8.0)
    ola.DeleteGraph(instance, graph_ptr)

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
graphPtr 是有效的图指针确保 graphPtr 是有效的图指针。
节点必须已存在于图中节点必须已存在于图中。
当 canConnect 为 true 且 we当 canConnect 为 true 且 weight 为 -1 时,自动使用欧几里得距离作为边权重。
当 canConnect 为 false 时当 canConnect 为 false 时,会删除对应的边。