Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding All Ways in FlowChart diagram?
    primarykey
    data
    text
    <p>I made an FlowChart diagram editor on Java. It It drows flowscharts and connect them each other and creates me two array. One of it shows connection nodes and lines , other shows connnecting elements eachother. I have to find all ways from starting Begin Two And . For example if I have some diamond for decision I have two seperate way ..I want to get all this ways..Which algorithms I must use?</p> <p><strong>Edit 3:SOLVED</strong> Hi again and i solved my problem my self..Here my codes .. ))</p> <pre><code> public void search(){ // System.out.print(map.length); for(i=0;i&lt;map.length;i++) visit[i]=0; visit[0]=1; find(0,map.length-1,1); } public void find(int i,int d,int step){ for(int j=0;j&lt;map.length;j++){ System.out.println("&gt;&gt;"+i+"-&gt;"+j); if(visit[j]!=0 || map[i][j]==0) continue; if(j==d){ visit[j]=step; OutputCycle(); visit[j]=0; return; } System.out.println(""+i+" to "+j); visit[j]=step; find(j,d,step+1); visit[j]=0; } } public void OutputCycle(){ System.out.println("OUTPUT"); for(k=0;k&lt;visit.length;k++){ for(int i=0;i&lt;visit.length;i++){ if(visit[i]==k+1){ System.out.print(i); } } } System.out.println(); } </code></pre> <p><strong>Edit 1:</strong> As I woreked on my problem I solved one part no there is also mistakes... Here my problem deeper description : I have an array that describes connection between elements </p> <pre><code> j A B C D E A 0 1 0 0 0 B 1 0 1 1 0 i C 0 1 0 0 1 D 0 1 0 0 1 E 0 0 1 1 0 </code></pre> <p>This is my connection array ..I am trying to find all ways from starting A to E </p> <p>There is 2 way </p> <p>A->B->C->E </p> <p>A->B->D->E </p> <p>I canfind first way which searchin array from left to rigt. If I see 1 I took walu e of J and go to J`th element line in i,make that element 2 and start searchign from [i,j+1] and if reached E then send result.</p> <p>But here my problem is in econd search in first line it wont see 1 and will go second line and there is first element 1 but it refers to first line and it will be loop.</p> <p>Also I tried to use DFS with using backtrack but it doesnt refer to show all paths ,only one path.</p> <p>And I have tried to making all below column to 0 if i foun 1 and start seaching [i,j] but in second seach it wont see anything and my arry table comes a blank table )).</p> <p>I know I am missing one thing but I cant figure it ..</p> <p><strong>Edit 2:</strong></p> <p>Now I closed to solution but there is problem againg. I used this code for calculating paths from matrix </p> <pre><code>import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * * @author Meko */ public class Main { List visited = new ArrayList(); List allObjects = new ArrayList(); int map[][] = {{3, 1, 0, 0, 0}, {1, 0, 1, 1, 0}, {0, 1, 0, 0, 3}, {0, 1, 0, 0, 3}, {0, 0, 1, 1, 0}}; int i, j, k; public Main() { ShowArray(); System.out.println(); find(0, 0); System.out.println(); result(); System.out.println(); afterFind(); System.out.println(); } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here new Main(); } public void ShowArray() { for (int i = 0; i &lt; map.length; i++) { for (int j = 0; j &lt; map.length; j++) { System.out.print(" " + map[i][j]); } System.out.println(""); } } public void find(int sRow, int sCol) { for (i = sRow; i &lt; map.length; i++) { for (j = sCol; j &lt; map.length; j++) { if (map[i][j] == 1) { map[i][j] = 2; visited.add(" " + i + " " + j); for (k = i; k &lt; map.length; k++) { map[k][i] = 0; } find(j, i); } else if (map[i][j] == 3) { visited.add(" " + i + " " + j); for (k = i; k &lt; map.length; k++) { map[k][i] = 0; } System.out.println("Founded"); map[i][j] = 2; find(0, 0); } } } } public void result() { System.out.println(visited); } public void afterFind() { for (int i = 0; i &lt; map.length; i++) { for (int j = 0; j &lt; map.length; j++) { System.out.print(" " + map[i][j]); } System.out.println(""); } } </code></pre> <p>}</p> <p>End it`s output is </p> <pre><code>3 1 0 0 0 1 0 1 1 0 0 1 0 0 3 0 1 0 0 3 0 0 1 1 0 </code></pre> <p>Founded Founded Founded</p> <p>[ 0 0, 0 1, 1 2, 2 4, 1 3, 3 4]</p> <pre><code>0 2 0 0 0 0 0 2 2 0 0 0 0 0 2 0 0 0 0 2 0 0 0 0 0 </code></pre> <p>2 means visited and changed.. Problem is as you se in visited list it adds</p> <p>00 , 01 , 12, 24 this is first path but then only 13,34 .this is because I change rest of array to 0 to not search. How can I solve this? it must 00,01,12,24 and 00,01 or 10,13,34.. Any Idea?? And I dont figure this is DFS or BFS ? or some thing else??</p>
    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.
 

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