Skip to content

Instantly share code, notes, and snippets.

@spoorcc
Created December 22, 2015 15:22
Show Gist options
  • Save spoorcc/b9b46906d26f670cce72 to your computer and use it in GitHub Desktop.
Save spoorcc/b9b46906d26f670cce72 to your computer and use it in GitHub Desktop.
SciLab script to check Isomorphism of graphs
funcprot(0);
function plot_graph_matrix(graph)
Matplot((1 - graph) * 255);
endfunction
function sorted_graph = sort_rows(graph)
sorted_graph = gsort(graph, 'lr');
endfunction
function sorted_graph = sort_cols(graph)
sorted_graph = gsort(graph, 'lc');
endfunction
function sorted_graph = sort_graph(graph)
sorted_graph = zeros(graph);
tmp_graph = graph;
while ~isequal(sorted_graph, tmp_graph)
sorted_graph = tmp_graph
tmp_graph = sort_rows(tmp_graph);
tmp_graph = sort_cols(tmp_graph);
end
return sorted_graph
endfunction
function equal_graph = are_graphs_equal(a, b)
sorted_a = sort_graph(a);
sorted_b = sort_graph(b);
equal_graph = isequal(sorted_a, sorted_b);
endfunction
graph_a = [0,1,0,1,0,1,0,0;
1,0,1,0,1,0,0,0;
0,1,0,1,0,0,0,1;
1,0,1,0,0,0,1,0;
0,1,0,0,0,1,0,1;
1,0,0,0,1,0,1,0;
0,0,0,1,0,1,0,1;
0,0,1,0,1,0,1,0]
graph_b = [0,1,1,0,0,0,1,0;
1,0,0,1,0,0,0,1;
1,0,0,1,1,0,0,0;
0,1,1,0,0,1,0,0;
0,0,1,0,0,1,1,0;
0,0,0,1,1,0,0,1;
1,0,0,0,1,0,0,1;
0,1,0,0,0,1,1,0]
disp(are_graphs_equal(graph_a, graph_b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment