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

numer of droplets wird schon generiert

parent 4056cbac
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
...@@ -3,6 +3,7 @@ import java.util.ArrayList; ...@@ -3,6 +3,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Arrays;
public class Channel extends NlocEntity implements Comparable<Channel> { public class Channel extends NlocEntity implements Comparable<Channel> {
private int pSteps, hSteps; private int pSteps, hSteps;
...@@ -40,8 +41,8 @@ public class Channel extends NlocEntity implements Comparable<Channel> { ...@@ -40,8 +41,8 @@ public class Channel extends NlocEntity implements Comparable<Channel> {
} }
} }
public SortedSet<Channel> getChildren() { public List<Channel> getChildrenList() {
return children; return Arrays.asList(children.toArray(new Channel[0]));
} }
public List<Channel> getParents() { public List<Channel> getParents() {
......
...@@ -2,6 +2,7 @@ package nloc; ...@@ -2,6 +2,7 @@ package nloc;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Arrays; import java.util.Arrays;
public class Nloc { public class Nloc {
...@@ -10,7 +11,7 @@ public class Nloc { ...@@ -10,7 +11,7 @@ public class Nloc {
List<Channel> chanlist = getNloc3(); List<Channel> chanlist = getNloc3();
Channel p0 = chanlist.get(chanlist.size() - 2); Channel p0 = chanlist.get(chanlist.size() - 2);
List<Channel> mod = getModulesByName(Arrays.asList("m2","m3"), chanlist); List<Channel> mod = getModulesByName(Arrays.asList("m1","m2"), chanlist);
List<List<Channel>> pathlist = getAllPaths(p0, new ArrayList<Channel>()); List<List<Channel>> pathlist = getAllPaths(p0, new ArrayList<Channel>());
printPaths(pathlist); printPaths(pathlist);
...@@ -21,15 +22,29 @@ public class Nloc { ...@@ -21,15 +22,29 @@ public class Nloc {
if (desiredPath.size() == 0) { if (desiredPath.size() == 0) {
System.out.println("No such Path!"); System.out.println("No such Path!");
} else { } else {
for (Channel ch : desiredPath) { printPath(desiredPath);
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
} }
System.out.println("Number of Droplets needed: " + getNumberOfDroplets(desiredPath));
} }
public static int getNumberOfDroplets(List<Channel> desiredPath) {
int numOfDroplets = 1;
ListIterator<Channel> iter = desiredPath.listIterator();
while(iter.hasNext()) {
Channel current = iter.next();
if (current.isBifurcation()) {
numOfDroplets *= (current.getChildrenList().indexOf(iter.next()) + 1);
iter.previous();
}
}
return numOfDroplets;
}
//public static List<Droplet> generateDropletSequence(List<Channel> path) {
//}
public static List<Channel> getDesiredPath(List<Channel> modules, public static List<Channel> getDesiredPath(List<Channel> modules,
List<List<Channel>> pathlist) { List<List<Channel>> pathlist) {
List<Channel> found = new ArrayList<Channel>(); List<Channel> found = new ArrayList<Channel>();
...@@ -54,13 +69,17 @@ public class Nloc { ...@@ -54,13 +69,17 @@ public class Nloc {
return ret; return ret;
} }
public static void printPath(List<Channel> path) {
for (Channel ch : path) {
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
}
public static void printPaths(List<List<Channel>> pathlist) { public static void printPaths(List<List<Channel>> pathlist) {
System.out.println("Number of paths found: " + pathlist.size()); System.out.println("Number of paths found: " + pathlist.size());
for (List<Channel> p : pathlist) { for (List<Channel> p : pathlist) {
for (Channel ch : p) { printPath(p);
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
} }
} }
...@@ -72,10 +91,10 @@ public class Nloc { ...@@ -72,10 +91,10 @@ public class Nloc {
public static void getAllPathsRecursive(Channel chan, List<Channel> path, List<List<Channel>> pathlist) { public static void getAllPathsRecursive(Channel chan, List<Channel> path, List<List<Channel>> pathlist) {
path.add(chan); path.add(chan);
if (chan.getChildren().size() == 0) { if (chan.getChildrenList().size() == 0) {
pathlist.add(path); pathlist.add(path);
} else { } else {
for (Channel ch : chan.getChildren()) { for (Channel ch : chan.getChildrenList()) {
getAllPathsRecursive(ch, new ArrayList<Channel>(path), pathlist); getAllPathsRecursive(ch, new ArrayList<Channel>(path), pathlist);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment