Graph
::getSubGraph
Возвращает подграф.
Блокноты MuPAD® будут демонтированы в будущем релизе. Используйте live скрипты MATLAB® вместо этого.
Live скрипты MATLAB поддерживают большую часть функциональности MuPAD, хотя существуют некоторые различия. Для получения дополнительной информации смотрите, Преобразуют Notebook MuPAD в Live скрипты MATLAB.
Graph::getSubGraph(G
, Vertex
)
Graph::getSubGraph(G, Vertex)
возвращает подграф согласно заданным вершинам.
Graph::getSubGraph(G)
возвращает график, который только содержит заданные вершины и принадлежащие ребра.
Во-первых, полный график задан с некоторыми дополнительными настройками:
G1 := Graph::createCompleteGraph(5): G1 := Graph::setEdgeWeights(G1, [[1,2]], [20]): G1 := Graph::setEdgeCosts(G1, [[1, 2]], [20]): G1 := Graph::setEdgeDescriptions(G1, [[1, 2]], ["Shortcut"]): Graph::printGraphInformation(G1)
Vertices: [1, 2, 3, 4, 5] Edges: [[1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 3], [2, 4], [2, 5], [3\ , 1], [3, 2], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 5], [5, 1], [5, \ 2], [5, 3], [5, 4]] Vertex weights: no vertex weights. Edge descriptions: [1, 2] = "Shortcut", [2, 1] = "Shortcut" Edge weights: [1, 2] = 20, [2, 1] = 20 (other existing edges have no weigh\ t) Edge costs: [1, 2] = 20, [2, 1] = 20 (other existing edges have costs zero) Adjacency list (out): 1 = [2, 3, 4, 5], 2 = [1, 3, 4, 5], 3 = [1, 2, 4, 5]\ , 4 = [1, 2, 3, 5], 5 = [1, 2, 3, 4] Adjacency list (in): 1 = [2, 3, 4, 5], 2 = [1, 3, 4, 5], 3 = [1, 2, 4, 5],\ 4 = [1, 2, 3, 5], 5 = [1, 2, 3, 4] Graph is undirected.
Теперь мы получаем подграф для вершин 1,2,4
:
G2 := Graph::getSubGraph(G1, [1, 2, 4]): Graph::printGraphInformation(G2)
Vertices: [1, 2, 4] Edges: [[1, 2], [1, 4], [2, 1], [2, 4], [4, 1], [4, 2]] Vertex weights: no vertex weights. Edge descriptions: [1, 2] = "Shortcut", [2, 1] = "Shortcut" Edge weights: [1, 2] = 20, [2, 1] = 20 (other existing edges have no weigh\ t) Edge costs: [1, 2] = 20, [2, 1] = 20 (other existing edges have costs zero) Adjacency list (out): 1 = [2, 4], 2 = [1, 4], 4 = [1, 2] Adjacency list (in): 1 = [2, 4], 2 = [1, 4], 4 = [1, 2] Graph is undirected.
Подграф для вершин 1,3,4
похож:
G2 := Graph::getSubGraph(G1, [1, 3, 4]): Graph::printGraphInformation(G2)
Vertices: [1, 3, 4] Edges: [[1, 3], [1, 4], [3, 1], [3, 4], [4, 1], [4, 3]] Vertex weights: no vertex weights. Edge descriptions: no edge descriptions. Edge weights: no edge weights. Edge costs: no edge costs. Adjacency list (out): 1 = [3, 4], 3 = [1, 4], 4 = [1, 3] Adjacency list (in): 1 = [3, 4], 3 = [1, 4], 4 = [1, 3] Graph is undirected.
|
График |
|
Список, содержащий одну или несколько вершин |
График