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

das aufteilen von Nloc und TestNloc weiterbetrieben

parent 36d565cc
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@
basedir = "${build}"
includes="**/*.class">
<manifest>
<attribute name="Main-Class" value="nloc.Nloc"/>
<attribute name="Main-Class" value="nloc.TestNloc"/>
</manifest>
</jar>
</target>
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
......@@ -26,19 +26,28 @@ public class Channel extends NlocEntity implements Comparable<Channel> {
public int getLastDropletDistance() {
int minDist = Integer.MAX_VALUE;
if (!this.containsDroplets()) {
if (dropletList.isEmpty()) {
minDist = -1;
} else {
for (Droplet dr : dropletList) {
int dist = dr.getPosition().getSteps();
if (dist < minDist) {
minDist = dist;
}
}
// Sort dropletlist accoring to droplet position (smallest position first)
dropletList.sort((d1,d2) ->
d1.getPosition().getSteps() - d2.getPosition().getSteps());
minDist = dropletList.get(0).getPosition().getSteps();
//for (Droplet dr : dropletList) {
// int dist = dr.getPosition().getSteps();
// if (dist < minDist) {
// minDist = dist;
// }
//}
}
return minDist;
}
public List<Droplet> getDropletList() {
return dropletList;
}
public void removeDroplet(Droplet droplet) {
dropletList.remove(droplet);
}
......
......@@ -7,6 +7,7 @@ public class Droplet {
public Droplet(DropletType type, Position position) {
this.position = position;
this.type = type;
this.position.getChannel().addDroplet(this);
}
public void move() {
......
......@@ -8,6 +8,58 @@ import java.util.Arrays;
public class Nloc {
private static final int MIN_TIMEDIFF = 6;
private List<Channel> chanlist;
private List<Droplet> dropletList;
public Nloc (List<Channel> chanlist) {
this.chanlist = chanlist;
this.dropletList = new ArrayList<Droplet>();
}
public void addChannel(Channel chan) {
chanlist.add(chan);
}
public Pump getPump() {
Pump pump = null;
for (Channel chan : chanlist) {
if (chan instanceof Pump) pump = (Pump)chan;
}
return pump;
}
public Pump generateDropletSequence(List<String> modules) {
Pump pump = this.getPump();
int timediff = MIN_TIMEDIFF + 1;
List<Channel> modPath = this.getModulesByName(modules);
List<List<Channel>> pathlist = this.getAllPaths();
List<Channel> desiredPath = getDesiredPath(modPath, pathlist);
int noOfDroplets = this.getNumberOfDroplets(desiredPath);
pump.setSteps(noOfDroplets + (noOfDroplets - 1) * timediff);
for (int i = 0; i < noOfDroplets; i++){
if (!pump.containsDroplets()) {
Droplet droplet = new Droplet(DropletType.PAYLOAD,
new Position(pump,0));
} else {
Droplet droplet = new Droplet(DropletType.HEADER,
new Position(pump,i + i * timediff));
}
dropletList.add(droplet);
}
return pump;
}
public boolean allDropletsInSink() {
boolean allInSink = true;
for (Droplet dr : dropletList) {
allInSink &= dr.isInSink();
}
return allInSink;
}
public int getNumberOfDroplets(List<Channel> desiredPath) {
int numOfDroplets = 1;
......@@ -21,9 +73,6 @@ public class Nloc {
}
return numOfDroplets;
}
public List<Droplet> generateDropletSequence(List<String> modules) {
}
public List<Channel> getDesiredPath(List<Channel> modules,
List<List<Channel>> pathlist) {
......@@ -36,8 +85,7 @@ public class Nloc {
return found;
}
public List<Channel> getModulesByName(List<String> names,
List<Channel> chanlist) {
private List<Channel> getModulesByName(List<String> names) {
List<Channel> ret = new ArrayList<Channel>();
for (String name : names) {
for (Channel ch : chanlist) {
......@@ -49,9 +97,10 @@ public class Nloc {
return ret;
}
public List<List<Channel>> getAllPaths(Channel chan, List<Channel> path) {
public List<List<Channel>> getAllPaths() {
List<List<Channel>> pl = new ArrayList<List<Channel>>();
getAllPathsRecursive(chan, path, pl);
List<Channel> path = new ArrayList<Channel>();
getAllPathsRecursive(this.getPump(), path, pl);
return pl;
}
......
package nloc;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Arrays;
public class TestNloc {
public static void main(String[] args) {
List<Channel> chanlist = getNloc0();
Channel p0 = chanlist.get(chanlist.size() - 2);
List<Channel> mod = getModulesByName(Arrays.asList("m1","m2"), chanlist);
Nloc nloc0 = new Nloc(getNloc0());
Nloc nloc2 = new Nloc(getNloc2());
Nloc nloc3 = new Nloc(getNloc3());
List<List<Channel>> pathlist = getAllPaths(p0, new ArrayList<Channel>());
printPaths(pathlist);
Pump pump = nloc2.generateDropletSequence(Arrays.asList("m1","m2"));
List<Channel> desiredPath = getDesiredPath(mod, pathlist);
System.out.println("Desired Path:");
if (desiredPath.isEmpty()) {
System.out.println("No such Path!");
} else {
printPath(desiredPath);
}
List<Droplet> drList = pump.getDropletList();
System.out.println("Number of Droplets neede: " + drList.size());
System.out.println("Number of Droplets needed: " + getNumberOfDroplets(desiredPath));
}
......@@ -78,6 +74,70 @@ public class TestNloc {
return chanlist;
}
public static List<Channel> getNloc2() {
Channel chan0 = new Channel(8,8);
Channel chan1 = new Channel(10,11);
Channel chan2 = new Channel(11,12);
Channel chan3 = new Channel(19,21);
Channel chan4 = new Channel(19,21);
Channel chan5 = new Channel(35,39);
Channel chan6 = new Channel(8,8);
Channel chan7 = new Channel(10,11);
Channel chan8 = new Channel(11,12);
Channel chan9 = new Channel(10,11);
Channel chan10 = new Channel(10,11);
Channel chan11 = new Channel(8,8);
Channel chan12 = new Channel(10,11);
Channel chan13 = new Channel(11,12);
Channel chan14 = new Channel(10,11);
Channel chan15 = new Channel(10,11);
Channel chan16 = new Channel(13,14);
Module m0 = new Module("m0", 12,10);
Module m1 = new Module("m1", 10,10);
Module m2 = new Module("m2", 12,10);
Module m3 = new Module("m3", 10,10);
Module m4 = new Module("m4", 10,10);
Pump p0 = new Pump();
Sink s0 = new Sink();
List<Channel> chanlist = Arrays.asList(chan0, chan1, chan2, chan3, chan4,
chan5, chan6, chan7, chan8, chan9, chan10, chan11, chan12, chan13,
chan14, chan15, chan16, m0, m1, m2, m3, m4, p0, s0);
p0.addChild(chan0);
chan0.addChild(chan1);
chan0.addChild(chan2);
chan1.addChild(chan3);
chan3.addChild(m4);
m4.addChild(chan4);
chan4.addChild(chan5);
chan5.addChild(s0);
chan2.addChild(chan6);
chan6.addChild(chan7);
chan6.addChild(chan8);
chan7.addChild(m0);
chan8.addChild(m1);
m0.addChild(chan9);
m1.addChild(chan10);
chan9.addChild(chan11);
chan10.addChild(chan11);
chan11.addChild(chan12);
chan11.addChild(chan13);
chan12.addChild(m2);
chan13.addChild(m3);
m2.addChild(chan14);
m3.addChild(chan15);
chan15.addChild(chan16);
chan14.addChild(chan16);
chan16.addChild(chan5);
return chanlist;
}
public static List<Channel> getNloc3() {
Channel chan0 = new Channel(6,6);
Channel chan1 = new Channel(8,8);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment