Skip to content
Snippets Groups Projects
Commit 3ed02429 authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

vor dem umbau von path zu list<chan>

parent c1f7da54
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -8,16 +8,20 @@ public class Nloc {
public static void main(String[] args) {
Channel chan0 = new Channel(6,6);
Channel chan1 = new Channel(8,8);
Channel chan2 = new Channel(8,8);
Channel chan2 = new Channel(9,9);
Channel chan3 = new Channel(11,12);
Channel chan4 = new Channel(19,21);
Channel chan5 = new Channel(5,5);
Channel chan6 = new Channel(8,8);
Channel chan7 = new Channel(9,10);
Channel chan8 = new Channel(25,28);
Channel chan9 = new Channel(25,28);
Channel chan10 = new Channel(25,28);
Module m0 = new Module("m0", 22,10);
Module m1 = new Module("m1", 10,10);
Module m2 = new Module("m2", 22,10);
Module m3 = new Module("m3", 10,10);
Pump p0 = new Pump();
Sink s0 = new Sink();
......@@ -25,103 +29,52 @@ public class Nloc {
p0.addChild(chan0);
chan0.addChild(chan1);
chan1.addChild(chan3);
chan1.addChild(chan2);
chan2.addChild(chan4);
chan0.addChild(chan2);
chan1.addChild(m0);
m0.addChild(chan3);
chan3.addChild(chan5);
chan4.addChild(chan7);
chan7.addChild(m1);
m1.addChild(chan8);
chan8.addChild(s0);
chan2.addChild(m1);
m1.addChild(chan4);
chan4.addChild(chan5);
chan5.addChild(chan6);
chan5.addChild(chan7);
chan6.addChild(m2);
chan7.addChild(m3);
m2.addChild(chan8);
m3.addChild(chan9);
chan8.addChild(chan10);
chan9.addChild(chan10);
chan10.addChild(s0);
chan5.addChild(m0);
m0.addChild(chan6);
chan6.addChild(chan7);
getAllPaths(p0);
//List<Path> pl = new ArrayList<Path>();
List<Path> pathlist = getAllPaths(p0, new Path());
//printAllPaths(p0,new Path(), pl);
//System.out.println(pl);
//for (Path p : pl) {
// for (Channel ch : p.getChanlist()) {
// System.out.println("ID: " + ch.getID());
// }
//}
// for(Channel ch : chan0.getChildren()) {
// System.out.println("ID: " + ch.getID() + " pSteps: " + ch.getPSteps());
// }
// for(Channel ch : chan1.getChildren()) {
// System.out.println("ID: " + ch.getID() + " pSteps: " + ch.getPSteps());
// }
// for(Channel ch : chan2.getChildren()) {
// System.out.println("ID: " + ch.getID() + " pSteps: " + ch.getPSteps());
// }
}
// list nodes_to_visit = {root};
// while( nodes_to_visit isn't empty ) {
// currentnode = nodes_to_visit.take_first();
// nodes_to_visit.prepend( currentnode.children );
// //do something
// }
//
//stack.push(root)
//while !stack.isEmpty() do
// node = stack.pop()
// for each node.childNodes do
// stack.push(stack)
// endfor
// // …
//endwhile
public static void getAllPaths(Channel chan) {
Path p = new Path();
List<Path> pl = new ArrayList<Path>();
Stack<Channel> chanStack = new Stack<Channel>();
chanStack.push(chan);
while(!chanStack.empty()) {
Channel temp = chanStack.pop();
System.out.println("path add: " + temp.getID());
p.add(temp);
if (temp.getChildren().size() == 0) {
System.out.println(chanStack);
for (Channel c : p.getChanlist()) {
System.out.println( c + ": " + c.getID());
}
}
for (Channel chl : temp.getChildren()) {
System.out.println("stack push " + chl.getID());
System.out.println(chanStack);
chanStack.push(chl);
public static void printPaths(List<Path> pathlist) {
System.out.println("Number of paths found: " + pathlist.size());
for (Path p : pathlist) {
for (Channel ch : p.getChanlist()) {
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
}
}
public static void printAllPaths(Channel chan, Path path, List<Path> pathlist) {
public static List<Path> getAllPaths(Channel chan, Path path) {
List<Path> pl = new ArrayList<Path>();
getAllPathsRecursive(chan, path, pl);
return pl;
}
public static void getAllPathsRecursive(Channel chan, Path path, List<Path> pathlist) {
path.add(chan);
if (chan.getChildren().size() == 0) {
System.out.println("Here" );
for (Channel ch : path.getChanlist()) {
System.out.print(ch.getID() + " ; ");
}
System.out.println( "");
pathlist.add(path);
} else {
for (Channel ch : chan.getChildren()) {
printAllPaths(ch, new Path(path), pathlist);
}
}
}
public static void printPath(Channel chan) {
System.out.println("ID: " + chan.getID() + " pSteps: " + chan.getPSteps());
if (chan.getChildren().size() != 0) {
for (Channel ch : chan.getChildren()) {
printPath(ch);
getAllPathsRecursive(ch, new Path(path), pathlist);
}
}
}
}
......@@ -25,8 +25,4 @@ public class Path {
public List<Channel> getChanlist() {
return path;
}
public Channel pollLast() {
return path.pollLast();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment