Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well most of the algorithms, at least the ones I found, implementing BFS or DFS will output the nodes they visit - for instance when a dead-end is visited, upon backtracking, the deadend node is also is truly shown in the path. The main issue is to create a queue data structure in matlab; I couldnt find any useful available Queue implementations, so I used structures (I am sure it's not a very efficient way but I need to store data in matlab in the following format, for instance:</p> <pre><code>[['1', '4', '8'], ['1', '2', '5', '9'], ['1', '2', '5', '10'], ['1', '4', '7', '11']] the Pseudo code is: function [nodes,links] = bfs4(GRAPH, start, destination)% def BFS(graph,start,end,q): nodes=struct; links=struct; path = struct; temp_path = start; last_node=[]; % q.enqueue(temp_path) path(1).data = temp_path; while size(fieldnames(path),1)~=0 tmp_path = path(1).data; if length(path) == 1 path=struct; else path = path(2:end); end last_node = tmp_path(end); % Storing the nodes in Two Forms (NODEs) and (LINKs) if last_node == destination tmp_path; if size(fieldnames(nodes),1)==0 nodes(end).data=tmp_path else nodes(end+1).data=tmp_path end % taking the links link=[]; for i=1:(length(tmp_path)-1) link(i) = GRAPH(GRAPH(:,2)==tmp_path(i) &amp; GRAPH(:,3)==tmp_path(i+1)); end if size(fieldnames(links),1)==0 links(end).data=link; else links(end+1).data=link; end end [row] = find(GRAPH(:,2)==last_node); for i=1:size(row,1) % be careful -- the condition to be remove GRAPH(row(i),10)&gt;0 if GRAPH(row(i),10)&gt;0 &amp;&amp; ismember(GRAPH(row(i),3),tmp_path)==0 new_path=[]; new_path = [tmp_path GRAPH(row(i),3)]; if size(fieldnames(path),1)==0 path(end).data = new_path; else path(end+1).data = new_path; end end end end % while end % function </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload