You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoadAsciiGraph.m 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function [graph] = LoadAsciiGraph(dataFilePath, dataFileName, numNodes, debug, debugPath)
  2. testing = 0;
  3. if nargin >= 3
  4. if nargin < 4
  5. debug = 0;
  6. end
  7. if nargin < 5
  8. debugPath = 'debug/';
  9. end
  10. fullOutPath = strcat(dataFilePath, debugPath);
  11. if isdir(fullOutPath) == 0 && debug == 1
  12. mkdir(fullOutPath);
  13. end
  14. dataFullName = strcat(dataFilePath,dataFileName);
  15. outFullName = strcat(fullOutPath,dataFileName);
  16. graph = sparse(numNodes,numNodes); %% initilaize with zero
  17. edges = load(dataFullName);
  18. n = size(edges,1);
  19. % m = size(edges,2);
  20. for e=1:n
  21. i = edges(e,1)+1;
  22. j = edges(e,2)+1;
  23. if (i ~= j)
  24. graph(i,j) = 1;
  25. graph(j,i) = 1; % sigal: 18.11.12 make sure graph undirected
  26. else
  27. fprintf('Invalid edge %d (%d,%d)\n',e,i,j);
  28. end
  29. end
  30. if debug == 1
  31. %save(strcat(outFullName,'_graph.txt'), 'graph', '-ascii');
  32. if testing == 1
  33. graph(1,2) =1;
  34. graph(2,3) =1;
  35. rows=sum(graph,1);
  36. cols=sum(graph,2);
  37. diff = rows-cols';
  38. nodes = find(diff);
  39. nnzx = nnz(graph);
  40. sumx = sum(sum(graph));
  41. end
  42. SaveIntMatrixToFile(strcat(outFullName,'_graph.txt'), graph);
  43. save(strcat(outFullName,'_graph.mat'), 'graph');
  44. save(strcat(outFullName,'_loadAsciiGraph.mat'));
  45. end
  46. else
  47. fprintf('Invalid parameters. expecting: dataFilePath, dataFileName, numNodes\n');
  48. end