about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/GraphViz/Old
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/GraphViz/Old')
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/CVS/Entries6
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/dot_to_graph.m107
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/draw_dot.m26
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/draw_graph.m310
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/graphToDot.m84
-rw-r--r--sourcecodes/bnt-master/GraphViz/Old/pre_pesha_graph_to_dot.m166
8 files changed, 701 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/GraphViz/Old/CVS/Entries b/sourcecodes/bnt-master/GraphViz/Old/CVS/Entries
new file mode 100644
index 00000000..50af46f1
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/CVS/Entries
@@ -0,0 +1,6 @@
+/dot_to_graph.m/1.1.1.1/Tue Jan 27 21:01:54 2004//
+/draw_dot.m/1.1.1.1/Tue Jan 27 20:42:50 2004//
+/draw_graph.m/1.1.1.1/Tue Jan 27 21:03:56 2004//
+/graphToDot.m/1.1.1.1/Tue Feb  3 17:15:18 2004//
+/pre_pesha_graph_to_dot.m/1.1.1.1/Tue Jan 27 20:47:40 2004//
+D
diff --git a/sourcecodes/bnt-master/GraphViz/Old/CVS/Repository b/sourcecodes/bnt-master/GraphViz/Old/CVS/Repository
new file mode 100644
index 00000000..83ba7005
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/GraphViz/Old
diff --git a/sourcecodes/bnt-master/GraphViz/Old/CVS/Root b/sourcecodes/bnt-master/GraphViz/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/GraphViz/Old/dot_to_graph.m b/sourcecodes/bnt-master/GraphViz/Old/dot_to_graph.m
new file mode 100644
index 00000000..59beb8fc
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/dot_to_graph.m
@@ -0,0 +1,107 @@
+function [Adj, labels, x, y] = dot_to_graph(filename)
+
+% [Adj, labels, x, y] = dot_to_graph(filename)
+% Extract a matrix representation, node labels, and node position coordinates
+% from a file in GraphViz format http://www.research.att.com/sw/tools/graphviz
+%
+% INPUTS:
+%    'filename' - the file in DOT format containing the graph layout.
+% OUTPUT:
+%  'Adj'    - an adjacency matrix representation of the graph in 'filename';
+% 'labels'  - a character array with the names of the nodes of the graph;
+%    'x'    - a row vector with the x-coordinates of the nodes in 'filename';
+%    'y'    - a row vector with the y-coordinates of the nodes in 'filename'.
+%
+% WARNINGS: not guaranted to parse ANY GraphViz file. Debugged on undirected 
+%       sample graphs from GraphViz(Heawood, Petersen, ER, ngk10_4, process). 
+%       Complaines about RecursionLimit set only to 500 on huge graphs.
+%       Ignores singletons (disjoint nodes).         
+% Sample DOT code "ABC.dot", read by [Adj, labels, x, y] = dot_to_graph('ABC.dot')
+% digraph G {
+%       A [pos="28,31"];
+%       B [pos="74,87"];
+%       A -- B [pos="e,61,71 41,47 46,53 50,58 55,64"];
+% }
+%                                                     last modified: Jan 2004
+% by Alexi Savov:  asavov @wustl.edu  |  http://artsci.wustl.edu/~azsavov
+%    Leon Peshkin: pesha @ai.mit.edu  |  http://www.ai.mit.edu/~pesha 
+
+if ~exist(filename)                % Checks whether the specified file exists.
+   error('* * * File does not exist or could not be found. * * *');     return;
+end;
+
+lines = textread(filename,'%s','delimiter','\n','commentstyle','c');  % Read file into cell array
+dot_lines = strvcat(lines);                                % of lines, ignoring C-style comments
+
+if findstr(dot_lines(1,:), 'graph ') == []           % Is this a DOT file ?
+   error('* * * File does not appear to be in valid DOT format. * * *');    return;
+end;
+
+Nlns = size(dot_lines,1);             % The number of lines;
+labels = {};
+unread = 1:Nlns;             % 'unread' list of lines which has not been examined yet
+edge_id = 1;
+for line_ndx = 1:Nlns   % This section sets the adjacency matrix A(Lnode,Rnode) = edge_id.
+    line = dot_lines(line_ndx,:);
+    Ddash_pos = strfind(line, ' -- ') + 1;    % double dash positions
+    arrow_pos = strfind(line, ' -> ') + 1;    % arrow  dash positions
+    tokens = strread(line,'%s','delimiter',' "');
+    left_bound = 1;
+    for dash_pos = [Ddash_pos arrow_pos];  % if empty - not a POS line
+        Lnode = sscanf(line(left_bound:dash_pos -2), '%s');
+        Rnode = sscanf(line(dash_pos +3 : length(line)-1),'%s',1);
+        Lndx = strmatch(Lnode, labels, 'exact');
+        Rndx = strmatch(Rnode, labels, 'exact');
+        if isempty(Lndx)         % extend our list of labels 
+            labels{end+1} = Lnode;
+            Lndx = length(labels);
+        end
+        if isempty(Rndx)
+            labels{end+1} = Rnode;
+            Rndx = length(labels);
+        end
+        Adj(Lndx, Rndx) = edge_id;;
+        if  ismember(dash_pos, Ddash_pos)   % The edge is undirected, A(Rndx,LndxL) is also set to 1;
+            Adj(Rndx, Lndx) = edge_id;
+        end
+        edge_id = edge_id + 1; 
+        left_bound = dash_pos + 3;
+        unread = setdiff(unread, line_ndx); 
+    end
+end
+Nvrt = length(labels);    % number of vertices we found  [Do we ever have singleton vertices ???]
+% labels = strvcat(labels); % convert to the searchable array
+x = zeros(1, Nvrt); 
+y = zeros(1, Nvrt);
+lst_node = 0;
+        % Find node's position coordinates if they are contained in 'filename'.
+for line_ndx = unread        % Look for node's coordiantes among the 'unread' lines.
+    line = dot_lines(line_ndx,:);
+    bra_pos  = strfind(line, '[');       % has to have "[" if it has the lable
+    pos_pos = strfind(line, 'pos');     % position of the "pos"
+    for node = 1:Nvrt     % look through the list of labels 
+        %  THE NEXT STATEMENT we assume no label is substring of any other label
+        lbl_pos = strfind(line, labels{node});
+        if (~isempty(lbl_pos) & ~isempty(bra_pos) & (x(node) == 0))  % make sure we have not seen it 
+            if (lbl_pos(1) < bra_pos(1))  % label has to be to the left of braket
+                lst_node = node;
+            end
+        end
+    end
+    if (~isempty(pos_pos) & lst_node)   % this line contains SOME position  
+        [node_pos] = sscanf(line(pos_pos:length(line)), ' pos  = "%d,%d"')';
+        x(lst_node) = node_pos(1);
+        y(lst_node) = node_pos(2);
+        lst_node = 0;   %  not to assign position several times 
+    end
+end
+
+if (isempty(find(x)) & (nargout > 2))   % If coordinates were requested, but not found in 'filename'.
+    warning('File does not contain node coordinates.');
+end;
+if ~(size(Adj,1)==size(Adj,2))           % Make sure Adj is a square matrix. ? 
+    Adj = eye(max(size(Adj)),size(Adj,1))*Adj*eye(size(Adj,2),max(size(Adj)));
+end;
+x = .9*(x-min(x))/range(x)+.05;  % normalise and push off margins 
+y = .9*(y-min(y))/range(y)+.05; 
+
diff --git a/sourcecodes/bnt-master/GraphViz/Old/draw_dot.m b/sourcecodes/bnt-master/GraphViz/Old/draw_dot.m
new file mode 100644
index 00000000..d6f37f81
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/draw_dot.m
@@ -0,0 +1,26 @@
+function draw_dot(adj);
+%
+%  draw_dot(name) 
+%  
+% Sample code illustrating use of dot_to_graph.m function
+% Leon Peshkin  
+if ispc, shell = 'dos'; else, shell = 'unix'; end  %  Which OS ?
+
+cmdline = strcat(shell,'(''neato -V'')');
+status = eval(cmdline);
+[status, result] = dos('neato -V');  % request version to check NEATO
+if status == 1,  fprintf('Complaining \n'); exit, end
+
+tmpDOTfile = '_GtDout.dot';            % to be platform independant no use of directories
+tmpLAYOUT  = '_LAYout.dot'; 
+directed = 0;                          % assume UN-directed graph
+graph_to_dot(adj > 0, 'directed', directed, 'filename', tmpDOTfile);  % save in file
+
+cmdline = strcat([shell '(''neato -Tdot ' tmpDOTfile ' -o ' tmpLAYOUT ''')']); % preserve trailing spaces 
+status = eval(cmdline);         %  get NEATO todo layout
+
+[adj, labels, x, y] = dot_to_graph(tmpLAYOUT);  %  load layout 
+delete(tmpLAYOUT); delete(tmpDOTfile);     % clean up temporary files
+
+figure(1); clf; axis square      %  now plot 
+[x, y, h] = draw_graph(adj>0, labels, zeros(size(x,2),1), x, y);
\ No newline at end of file
diff --git a/sourcecodes/bnt-master/GraphViz/Old/draw_graph.m b/sourcecodes/bnt-master/GraphViz/Old/draw_graph.m
new file mode 100644
index 00000000..06e3d7a1
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/draw_graph.m
@@ -0,0 +1,310 @@
+function [x, y, h] = draw_graph(adj, labels, node_t, x, y)
+% DRAW_LAYOUT		Draws a layout for a graph 
+%
+%  [<X, Y>] = DRAW_LAYOUT(ADJ, <LABELS, ISBOX, X, Y>)
+%
+% Inputs :
+%	ADJ : Adjacency matrix (source, sink)
+%       LABELS : Cell array containing labels <Default : '1':'N'>
+%       ISBOX : 1 if node is a box, 0 if oval <Default : zeros>
+%       X, Y, : Coordinates of nodes on the unit square <Default : calls make_layout>
+%
+% Outputs :
+%	X, Y : Coordinates of nodes on the unit square
+%       H    : Object handles 
+%
+% Usage Example : [x, y] = draw_layout([0 1;0 0], {'Hidden','Visible'}, [1 0]');
+%
+% h(i,1) is the text handle - color
+% h(i,2) is the circle handle - facecolor
+%
+% Note	:
+% See also MAKE_LAYOUT
+
+% Uses :
+
+% Change History :
+% Date		Time		Prog	Note
+% 13-Apr-2000	 9:06 PM	ATC	Created under MATLAB 5.3.1.29215a (R11.1)
+
+% ATC = Ali Taylan Cemgil,
+% SNN - University of Nijmegen, Department of Medical Physics and Biophysics
+% e-mail : cemgil@mbfys.kun.nl 
+adj = double(adj);
+N = size(adj,1);
+if nargin<2,
+%  labels = cellstr(char(zeros(N,1)+double('+')));
+  labels = cellstr(int2str((1:N)'));
+end;
+
+if nargin<3,
+  node_t = zeros(N,1);
+%  node_t = rand(N,1) > 0.5;
+else
+  node_t = node_t(:);
+end;
+  
+axis([0 1 0 1]);
+set(gca,'XTick',[],'YTick',[],'box','on');
+% axis('square');
+%colormap(flipud(gray));
+
+if nargin<4,
+  [x y] = make_layout(adj);
+end;
+
+idx1 = find(node_t==0); wd1=[];
+if ~isempty(idx1),
+[h1 wd1] = textoval(x(idx1), y(idx1), labels(idx1));
+end;
+
+idx2 = find(node_t~=0); wd2 = [];
+if ~isempty(idx2),
+[h2 wd2] = textbox(x(idx2), y(idx2), labels(idx2));
+end;
+
+wd = zeros(size(wd1,1)+size(wd2,1),2);
+if ~isempty(idx1), wd(idx1, :) = wd1;  end;
+if ~isempty(idx2), wd(idx2, :) = wd2; end;
+
+for i=1:N,
+  j = find(adj(i,:)==1);
+  for k=j,
+    if x(k)-x(i)==0,
+	sign = 1;
+	if y(i)>y(k), alpha = -pi/2; else alpha = pi/2; end;
+    else
+	alpha = atan((y(k)-y(i))/(x(k)-x(i)));
+	if x(i)<x(k), sign = 1; else sign = -1; end;
+    end;
+    dy1 = sign.*wd(i,2).*sin(alpha);   dx1 = sign.*wd(i,1).*cos(alpha);
+    dy2 = sign.*wd(k,2).*sin(alpha);   dx2 = sign.*wd(k,1).*cos(alpha);    
+    if adj(k,i)==0, % if directed edge
+      arrow([x(i)+dx1 y(i)+dy1],[x(k)-dx2 y(k)-dy2]);
+    else	   
+      line([x(i)+dx1 x(k)-dx2],[y(i)+dy1 y(k)-dy2],'color','k');
+      adj(k,i)=-1; % Prevent drawing lines twice
+    end;
+  end;
+end;
+
+if nargout>2,
+  h = zeros(length(wd),2);
+  if ~isempty(idx1),
+    h(idx1,:) = h1;
+  end;
+  if ~isempty(idx2),
+    h(idx2,:) = h2;
+  end;
+end;
+
+%%%%%
+
+function [t, wd] = textoval(x, y, str)
+% TEXTOVAL		Draws an oval around text objects
+% 
+%  [T, WIDTH] = TEXTOVAL(X, Y, STR)
+%  [..] = TEXTOVAL(STR)  % Interactive
+% 
+% Inputs :
+%    X, Y : Coordinates
+%    TXT  : Strings
+% 
+% Outputs :
+%    T : Object Handles
+%    WIDTH : x and y Width of ovals 
+%
+% Usage Example : [t] = textoval('Visit to Asia?');
+% 
+% 
+% Note     :
+% See also TEXTBOX
+
+% Uses :
+
+% Change History :
+% Date		Time		Prog	Note
+% 15-Jun-1998	10:36 AM	ATC	Created under MATLAB 5.1.0.421
+
+% ATC = Ali Taylan Cemgil,
+% SNN - University of Nijmegen, Department of Medical Physics and Biophysics
+% e-mail : cemgil@mbfys.kun.nl 
+
+temp = [];
+
+switch nargin,
+  case 1,
+    str = x;
+    if ~isa(str,'cell') str=cellstr(str); end;
+    N = length(str);
+    wd = zeros(N,2);
+    for i=1:N,
+      [x, y] = ginput(1);
+      tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle');
+      [ptc wx wy] = draw_oval(tx, x, y);
+      wd(i,:) = [wx wy];
+      delete(tx);      
+      tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle');
+      temp = [temp ; tx ptc];
+    end;
+  case 3,
+    if ~isa(str,'cell') str=cellstr(str); end;
+    N = length(str);    
+    wd = zeros(N,2);
+    for i=1:N,
+      tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle');
+     [ptc wx wy] = draw_oval(tx, x(i), y(i));
+      wd(i,:) = [wx wy];
+      delete(tx);
+      tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle');      
+      temp = [temp;  tx ptc];
+    end;
+  otherwise,
+end;  
+
+if nargout>0, t = temp; end;
+
+%%%%%%%%%
+
+
+function [ptc, wx, wy] = draw_oval(tx, x, y)
+% Draws an oval box around a tex object
+sz = get(tx,'Extent');
+wy = sz(4);
+wx = max(2/3*sz(3), wy); 
+wx = 0.5*wx; % KPM
+wy = 0.5*wy;
+ptc = ellipse(x, y, wx, wy);
+set(ptc, 'FaceColor','w');
+
+
+%%%%%%%%%%%%%
+
+function [p] = ellipse(x, y, rx, ry, c)
+% ELLIPSE		Draws Ellipse shaped patch objects
+% 
+%  [<P>] = ELLIPSE(X, Y, Rx, Ry, C)
+% 
+% Inputs :
+%    X : N x 1 vector of x coordinates
+%    Y : N x 1 vector of y coordinates
+%    Rx, Ry : Radii
+%    C : Color index
+%
+% 
+% Outputs :
+%    P = Handles of Ellipse shaped path objects
+% 
+% Usage Example : [] = ellipse();
+% 
+% 
+% Note     :
+% See also 
+
+% Uses :
+
+% Change History :
+% Date		Time		Prog	Note
+% 27-May-1998	 9:55 AM	ATC	Created under MATLAB 5.1.0.421
+
+% ATC = Ali Taylan Cemgil,
+% SNN - University of Nijmegen, Department of Medical Physics and Biophysics
+% e-mail : cemgil@mbfys.kun.nl 
+
+if (nargin < 2) error('Usage Example : e = ellipse([0 1],[0 -1],[1 0.5],[2 0.5]); '); end;
+if (nargin < 3) rx = 0.1; end;
+if (nargin < 4) ry = rx; end;
+if (nargin < 5) c = 1; end;
+
+if length(c)==1, c = ones(size(x)).*c; end;
+if length(rx)==1, rx = ones(size(x)).*rx; end;
+if length(ry)==1, ry = ones(size(x)).*ry; end;
+  
+n = length(x);
+p = zeros(size(x));
+t = 0:pi/30:2*pi;
+for i=1:n,
+	px = rx(i)*cos(t)+x(i);
+	py = ry(i)*sin(t)+y(i);
+	p(i) = patch(px,py,c(i));
+end;
+
+if nargout>0, pp = p; end;
+
+%%%%%
+
+function [t, wd] = textbox(x,y,str)
+% TEXTBOX	Draws A Box around the text 
+% 
+%  [T, WIDTH] = TEXTBOX(X, Y, STR)
+%  [..] = TEXTBOX(STR)
+% 
+% Inputs :
+%    X, Y : Coordinates
+%    TXT  : Strings
+% 
+% Outputs :
+%    T : Object Handles
+%    WIDTH : x and y Width of boxes 
+%% 
+% Usage Example : t = textbox({'Ali','Veli','49','50'});
+% 
+% 
+% Note     :
+% See also TEXTOVAL
+
+% Uses :
+
+% Change History :
+% Date		Time		Prog	Note
+% 09-Jun-1998	11:43 AM	ATC	Created under MATLAB 5.1.0.421
+
+% ATC = Ali Taylan Cemgil,
+% SNN - University of Nijmegen, Department of Medical Physics and Biophysics
+% e-mail : cemgil@mbfys.kun.nl 
+
+% See
+temp = [];
+
+switch nargin,
+  case 1,
+    str = x;
+    if ~isa(str,'cell') str=cellstr(str); end;
+    N = length(str);  
+    wd = zeros(N,2);
+    for i=1:N,
+      [x, y] = ginput(1);
+      tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle');
+      [ptc wx wy] = draw_box(tx, x, y); 
+      wd(i,:) = [wx wy];
+      delete(tx);
+      tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle');      
+      temp = [temp; tx ptc];
+    end;
+  case 3,
+    if ~isa(str,'cell') str=cellstr(str); end;    
+    N = length(str);
+    for i=1:N,
+      tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle');
+      [ptc wx wy] = draw_box(tx, x(i), y(i));
+      wd(i,:) = [wx wy];
+      delete(tx);
+      tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle');      
+      temp = [temp; tx ptc];
+    end;
+     
+  otherwise,
+
+end;  
+
+if nargout>0, t = temp; end;
+
+
+function [ptc, wx, wy] = draw_box(tx, x, y)
+% Draws a box around a tex object
+      sz = get(tx,'Extent');
+      wy = 2/3*sz(4);
+      wx = max(2/3*sz(3), wy);
+      ptc = patch([x-wx x+wx x+wx x-wx], [y+wy y+wy y-wy y-wy],'w');
+      set(ptc, 'FaceColor','w');
+
diff --git a/sourcecodes/bnt-master/GraphViz/Old/graphToDot.m b/sourcecodes/bnt-master/GraphViz/Old/graphToDot.m
new file mode 100644
index 00000000..1f3d232e
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/graphToDot.m
@@ -0,0 +1,84 @@
+function graphToDot(adj, varargin)
+% GRAPHTODOT Makes a GraphViz (AT&T) ile representing  an adjacency matrix
+% function graphToDot(adj, ...)
+% Optional arguments should be passed as name/value pairs [default]
+%
+% 'filename' - if omitted, writes to 'tmp.dot'
+% 'arc_label' - arc_label{i,j} is a string attached to the i-j arc [""]
+% 'node_label' - node_label{i} is a string attached to the node i ["i"]
+% 'width'     - width in inches [10]
+% 'height'    - height in inches [10]
+% 'leftright' - 1 means layout left-to-right, 0 means top-to-bottom [0]
+% 'directed'  - 1 means use directed arcs, 0 means undirected [1]
+%
+% For details on graphviz, See http://www.research.att.com/sw/tools/graphviz
+%
+% See also dot_to_graph and draw_dot
+%
+% First version written by Kevin Murphy 2002.
+% Modified by Leon Peshkin, Jan 2004.
+                   
+node_label = [];   arc_label = [];   % set default args
+width = 10;        height = 10;
+leftright = 0;     directed = 1;     filename = 'tmp.dot';
+           
+for i = 1:2:nargin-1                    % get optional args
+    switch varargin{i}
+        case 'filename', filename = varargin{i+1};
+        case 'node_label', node_label = varargin{i+1};
+        case 'arc_label', arc_label = varargin{i+1};
+        case 'width', width = varargin{i+1};
+        case 'height', height = varargin{i+1};
+        case 'leftright', leftright = varargin{i+1};
+        case 'directed', directed = varargin{i+1};
+    end
+end
+
+fid = fopen(filename, 'w');
+if directed
+    fprintf(fid, 'digraph G {\n');
+    arctxt = '->'; 
+    if isempty(arc_label)
+        labeltxt = '';
+    else
+        labeltxt = '[label="%s"]';
+    end
+else
+    fprintf(fid, 'graph G {\n');
+    arctxt = '--'; 
+    if isempty(arc_label)
+        labeltxt = '[dir=none]';
+    else
+        labeltext = '[label="%s",dir=none]';
+    end
+end
+edgeformat = strcat(['%d ',arctxt,' %d ',labeltxt,';\n']);
+fprintf(fid, 'center = 1;\n');
+fprintf(fid, 'size=\"%d,%d\";\n', width, height);
+if leftright
+    fprintf(fid, 'rankdir=LR;\n');
+end
+Nnds = length(adj);
+for node = 1:Nnds               %  process nodes 
+    if isempty(node_label)
+        fprintf(fid, '%d;\n', node);
+    else
+        fprintf(fid, '%d [ label = "%s" ];\n', node,
+node_label{node});
+    end
+end
+for node1 = 1:Nnds   % process edges
+    if directed
+        arcs = find(adj(node1,:));         % children(adj, node);
+    else
+        arcs = find(adj(node1,node1+1:Nnds)); % remove duplicate arcs
+    end
+    for node2 = arcs
+        fprintf(fid, edgeformat, node1, node2);
+    end
+end
+fprintf(fid, '}');
+fclose(fid); 
+
+
+
diff --git a/sourcecodes/bnt-master/GraphViz/Old/pre_pesha_graph_to_dot.m b/sourcecodes/bnt-master/GraphViz/Old/pre_pesha_graph_to_dot.m
new file mode 100644
index 00000000..49f226f6
--- /dev/null
+++ b/sourcecodes/bnt-master/GraphViz/Old/pre_pesha_graph_to_dot.m
@@ -0,0 +1,166 @@
+function graph_to_dot(G, varargin)
+% DAG_TO_DOT Make a file representing the directed graph in dotty format.
+% dag_to_dot(G, ...)
+%
+% Optional arguments should be passed as name/value pairs [default]
+%
+% 'filename' - if omitted, we write to 'tmp.dot', convert this to 'tmp.ps',
+%              and then call ghostview automatically 
+% 'arc_label' - arc_label{i,j} is a string attached to the i->j arc. [""]
+% 'node_label' - node_label{i} is a string attached to node i. ["i"]
+% 'width'      - width in inches [10]
+% 'height'     - height in inches [10]
+% 'leftright'  - 1 means layout left-to-right, 0 means top-to-bottom [0]
+% 'directed'  - 1 means use directed arcs, 0 means undirected [1]
+%
+% For details on dotty, See http://www.research.att.com/sw/tools/graphviz
+%
+% Example:
+% G = rand(5,5);
+% names = cell(5,5);
+% names{1,2} = 'arc 1-2';
+% graph_to_dot(G, 'arc_label', names)
+% or graph_to_dot(G, 'arc_label', 'numbers') % prints value of G(i,j) on i->j arc 
+
+% Kevin Murphy, 1998
+
+% set default args
+filename = [];
+node_label = [];
+arc_label = [];
+width = 10;
+height = 10;
+leftright = 0;
+directed = 1;
+% get optional args
+args = varargin;
+for i=1:2:length(args)
+  switch args{i}
+   case 'filename', filename = args{i+1};
+   case 'node_label', node_label = args{i+1};
+   case 'arc_label', arc_label = args{i+1};
+   case 'width', width = args{i+1};
+   case 'height', height = args{i+1};
+   case 'leftright', leftright = args{i+1};
+   case 'directed', directed = args{i+1};
+  end
+end
+
+if isstr(arc_label) & strcmp(arc_label, 'numbers')
+  N = length(G);
+  arc_label = cell(N,N);
+  for i=1:N
+    for j=1:N
+      arc_label{i,j} = sprintf('%4.2f', G(i,j));
+    end
+  end
+end
+
+if isempty(filename)
+  make_file(G, 'tmp.dot', node_label, arc_label, width, height, leftright, directed);
+  if isunix
+    !dot -Tps tmp.dot -o tmp.ps
+
+    !gs tmp.ps &
+  else
+    dos('dot -Tps tmp.dot -o tmp.ps');
+    dos('gsview32 tmp.ps &');
+  end
+else
+  
+  
+  make_file(G, filename, node_label, arc_label, width, height, leftright, directed);
+end
+
+
+%%%%%%
+
+function make_file(G, filename, node_label, arc_label, width, height, leftright, directed)
+
+n = length(G);
+fid = fopen(filename, 'w');
+if directed
+  fprintf(fid, 'digraph G {\n');
+else
+  fprintf(fid, 'graph G {\n');
+end
+fprintf(fid, 'center = 1;\n');
+fprintf(fid, 'size=\"%d,%d\";\n', width, height);
+if leftright
+  fprintf(fid, 'rankdir=LR;\n');
+end
+for i=1:n
+  if isempty(node_label)
+    fprintf(fid, '%d;\n', i);
+  else
+    fprintf(fid, '%d [ label = "%s" ];\n', i, node_label{i});
+  end
+end
+if directed
+  for i=1:n
+    cs = children(G,i);
+    for j=1:length(cs)
+      c = cs(j);
+      if isempty(arc_label)
+	fprintf(fid, '%d -> %d;\n', i, c);
+      else
+	fprintf(fid, '%d -> %d [label="%s"];\n', i, c, arc_label{i,c});
+      end
+    end
+  end
+else
+  for i=1:n
+    ns = intersect(neighbors(G,i), i+1:n); % remove duplicate arcs
+    for j=1:length(ns)
+      c = ns(j);
+      if isempty(arc_label)
+	fprintf(fid, '%d -- %d [dir=none];\n', i, c);
+      else
+	fprintf(fid, '%d -- %d [label="%s",dir=none];\n', i, c, arc_label{i,c});
+      end
+    end
+  end
+end
+fprintf(fid, '\n}');
+fclose(fid);
+
+
+
+%%%%%%%%%%%%%%%
+
+function cs = children(adj_mat, i, t)
+% CHILDREN Return the indices of a node's children in sorted order
+% c = children(adj_mat, i, t)
+%
+% t is an optional argument: if present, dag is assumed to be a 2-slice DBN
+
+if nargin < 3 
+  cs = find(adj_mat(i,:));
+else
+  if t==1
+    cs = find(adj_mat(i,:));
+  else
+    ss = length(adj_mat)/2;
+    j = i+ss;
+    cs = find(adj_mat(j,:)) + (t-2)*ss;
+  end
+end
+
+%%%%%%%%%%%%
+
+function ps = parents(adj_mat, i)
+% PARENTS Return the list of parents of node i
+% ps = parents(adj_mat, i)
+
+ps = find(adj_mat(:,i))';
+
+%%%%%%%%%%%%%
+
+function ns = neighbors(adj_mat, i)
+% NEIGHBORS Find the parents and children of a node in a graph.
+% ns = neighbors(adj_mat, i)
+
+ns = union(children(adj_mat, i), parents(adj_mat, i));
+
+
+