필터 지우기
필터 지우기

Approximate vertex cover problem

조회 수: 3 (최근 30일)
Ivan
Ivan 2013년 11월 12일
편집: Ivan 2013년 11월 30일
Hello, I have 2 question: I want you resolve Approximate vertex cover problem, therefore
1.Can someone give me function who will choice random edge(2 vertex, ex: u and v) in graph, 2.And then function who will delete all egdes incident on either u and v.
Thank you!

채택된 답변

Ben Petschel
Ben Petschel 2013년 11월 15일
Assuming you've got an incidence matrix A with A(u,v) if there is an edge from u to v, then a random edge could be selected with
i = randsample(find(A),1);
[u,v] = ind2sub(size(A),i);
and then delete the edges with
A(u,:) = 0; % edges from u
A(:,u) = 0; % edges to u
A(v,:) = 0;
A(:,v) = 0;
This is probably not the most efficient algorithm but if the number of vertices is large then it should run a lot faster if you make A a sparse array.

추가 답변 (1개)

Ivan
Ivan 2013년 11월 15일
편집: Ivan 2013년 11월 30일
Thank you, but [u,v] should be two adjacent vertices, and ind2sub don't do that. ind2sub do right for v, but for u he backs size of edges.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by