跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法 最短路径问题是有权还是没权问题呢?
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/26 14:45:57
![跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法 最短路径问题是有权还是没权问题呢?](/uploads/image/z/11628440-8-0.jpg?t=%E8%B7%AA%E6%B1%82%E8%A7%A3%E9%87%8A+Matlab%E4%B8%ADgraphshortestpath%E7%9A%84%E5%85%B7%E4%BD%93%E7%94%A8%E6%B3%95+%E9%9C%80%E8%A6%81%E4%BB%80%E4%B9%88%E5%8F%82%E6%95%B0%2C%E7%9F%A9%E9%98%B5%2C%E5%BE%97%E5%88%B0%E4%BB%80%E4%B9%88%E7%BB%93%E6%9E%9C%3F%E6%98%AF%E4%B8%80%E4%B8%AA%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84%E9%97%AE%E9%A2%98%2C%E6%8D%AE%E8%AF%B4%E6%98%AF%E5%B0%81%E8%A3%85%E5%A5%BD%E7%9A%84floyd%2CDijkstra+%E7%AE%97%E6%B3%95++%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84%E9%97%AE%E9%A2%98%E6%98%AF%E6%9C%89%E6%9D%83%E8%BF%98%E6%98%AF%E6%B2%A1%E6%9D%83%E9%97%AE%E9%A2%98%E5%91%A2%3F)
跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法 最短路径问题是有权还是没权问题呢?
跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?
是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法
最短路径问题是有权还是没权问题呢?
跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法 最短路径问题是有权还是没权问题呢?
我看了一下这个函数的例子
默认是Dijkstra 算法
是有权的, 我想如果把权都赋1的话, 就相当于没权的了
参数是带权的稀疏矩阵及结点
看看这两个例子(一个有向一个无向), 或许你能找到你想知道的
% Create a directed graph with 6 nodes and 11 edges
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21]; %这是权
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W) %有权的有向图
h = view(biograph(DG,[],'ShowWeights','on')) %画图, 这个好玩
% Find shortest path from 1 to 6
[dist,path,pred] = graphshortestpath(DG,1,6) %找顶点1到6的最短路径
% Mark the nodes and edges of the shortest path
set(h.Nodes(path),'Color',[1 0.4 0.4]) %上色
edges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
set(edges,'LineColor',[1 0 0]) %上色
set(edges,'LineWidth',1.5) %上色
下面是无向图的例子
% % Solving the previous problem for an undirected graph
% UG = tril(DG + DG')
% h = view(biograph(UG,[],'ShowArrows','off','ShowWeights','on'))
% % Find the shortest path between node 1 and 6
% [dist,path,pred] = graphshortestpath(UG,1,6,'directed',false)
% % Mark the nodes and edges of the shortest path
% set(h.Nodes(path),'Color',[1 0.4 0.4])
% fowEdges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
% revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(path)),'ID'));
% edges = [fowEdges;revEdges];
% set(edges,'LineColor',[1 0 0])
% set(edges,'LineWidth',1.5)
%
对matlab我只知皮毛, 只是对你这个问题感兴趣而已(以前学过), 可别怪我没答到点子上哈