Find maximum clique with recursive function
이전 댓글 표시
I am solving an problem which has been stated and discussed here: maximum clique problem solve
As the OP showed in the above thread, the original version is inefficient because it is checking a bunch of sets of nodes that cannot possibly be part of a clique. So we need a smarter way to pick which nodes to check.
Therefore, based the tiny improvement in the accepted answer in maximum clique problem solve, I also tried:
- disregard nodes with length < length(clique)
- disregard nodes with the first element > clique(1)
- disregard nodes with the last element < clique(end)
- disregard nodes that are not in the follow list of first elemnt in the current clique
if ~any(node == clique) && length(graph{node}) >= length(clique) && graph{node}(1) <= clique(1) && graph{node}(end) >= clique(end) && any(node == graph{clique(1)})
Unfortunately, this runs for ~60 seconds on my computer, which is still not fast enough to pass the grader...
I also come up with the order of operands of && operator. So I change the above line to:
if any(node == graph{clique(1)}) && length(graph{node}) >= length(clique) && graph{node}(1) <= clique(1) && graph{node}(end) >= clique(end) && ~any(node == clique)
Although this gets a bit faster and runs for ~40 seconds on my computer, unfortunately this is still not fast enough to pass the grader...
I HOPE SOMEONE COULD PROVIDE SOME ADVICES.
ANY SUGGESTIONS WILL BE APPRECIATED.
댓글 수: 5
I had the problem in the linked question already: The text of the question does not mention explicitly, what the code should calculate. I have to guess the intention from the result given by the slow example code. If I get such a question as a student, I'd refuse to solve it and ask for a clear problem description at first.
I'd just optimized the code blindly without understanding, what it does. I get the result
1769 1773 1774 1833 2222
but do not have the faintest idea, what this should be. In consequence I cannot rewrite the code in an efficient way, because the most important part of the description is missing.
Sorry, maybe it is only a langauge problem, because I'm not a native speaker.
Jan
2021년 8월 12일
Okay, it's clear now.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!