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

pfadgenerierung mit 2 verschiedenen nlocs

parent b04668f6
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
......@@ -6,6 +6,78 @@ import java.util.Stack;
public class Nloc {
public static void main(String[] args) {
Channel p0 = getNloc0();
List<List<Channel>> pathlist = getAllPaths(p0, new ArrayList<Channel>());
printPaths(pathlist);
}
public static void printPaths(List<List<Channel>> pathlist) {
System.out.println("Number of paths found: " + pathlist.size());
for (List<Channel> p : pathlist) {
for (Channel ch : p) {
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
}
}
public static List<List<Channel>> getAllPaths(Channel chan, List<Channel> path) {
List<List<Channel>> pl = new ArrayList<List<Channel>>();
getAllPathsRecursive(chan, path, pl);
return pl;
}
public static void getAllPathsRecursive(Channel chan, List<Channel> path, List<List<Channel>> pathlist) {
path.add(chan);
if (chan.getChildren().size() == 0) {
pathlist.add(path);
} else {
for (Channel ch : chan.getChildren()) {
getAllPathsRecursive(ch, new ArrayList<Channel>(path), pathlist);
}
}
}
public static Channel getNloc0() {
Channel chan0 = new Channel(6,6);
Channel chan1 = 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);
Module m0 = new Module("m0", 22,10);
Module m1 = new Module("m1", 10,10);
Pump p0 = new Pump();
Sink s0 = new Sink();
p0.addChild(chan0);
chan0.addChild(chan1);
chan1.addChild(chan2);
chan1.addChild(chan3);
chan2.addChild(chan4);
chan3.addChild(chan5);
chan5.addChild(m0);
m0.addChild(chan6);
chan4.addChild(chan7);
chan6.addChild(chan7);
chan7.addChild(m1);
m1.addChild(chan8);
chan8.addChild(s0);
return p0;
}
public static Channel getNloc3() {
Channel chan0 = new Channel(6,6);
Channel chan1 = new Channel(8,8);
Channel chan2 = new Channel(9,9);
......@@ -46,36 +118,6 @@ public class Nloc {
chan9.addChild(chan10);
chan10.addChild(s0);
List<List<Channel>> pathlist = getAllPaths(p0, new ArrayList<Channel>());
printPaths(pathlist);
}
public static void printPaths(List<List<Channel>> pathlist) {
System.out.println("Number of paths found: " + pathlist.size());
for (List<Channel> p : pathlist) {
for (Channel ch : p) {
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
}
}
public static List<List<Channel>> getAllPaths(Channel chan, List<Channel> path) {
List<List<Channel>> pl = new ArrayList<List<Channel>>();
getAllPathsRecursive(chan, path, pl);
return pl;
}
public static void getAllPathsRecursive(Channel chan, List<Channel> path, List<List<Channel>> pathlist) {
path.add(chan);
if (chan.getChildren().size() == 0) {
pathlist.add(path);
} else {
for (Channel ch : chan.getChildren()) {
getAllPathsRecursive(ch, new ArrayList<Channel>(path), pathlist);
}
}
return p0;
}
}
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