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

simulation um verschmelzungen zu finden mal angefangen

parent f133039e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
package nloc;
public class CoalescedDropletException extends Exception {
public CoalescedDropletException () {
super();
}
public CoalescedDropletException (String message) {
super(message);
}
}
......@@ -22,6 +22,10 @@ public class Droplet {
return position;
}
public boolean coalesce() {
return false;
}
public void setPosition(Position position) {
this.position.getChannel().removeDroplet(this);
this.position = position;
......
......@@ -28,6 +28,29 @@ public class Nloc {
return pump;
}
public boolean simulate() {
boolean works = true;
while (!allDropletsInSink()) {
try {
this.moveDroplets();
} catch (CoalescedDropletException e) {
works = false;
System.out.println(e.toString());
break;
}
}
return works;
}
public void moveDroplets() throws CoalescedDropletException {
for (Droplet dr : dropletList) {
dr.move();
}
for (Droplet dr: dropletList) {
if (dr.coalesce()) throw new CoalescedDropletException();
}
}
public Pump generateDropletSequence(List<String> modules) {
Pump pump = this.getPump();
......@@ -42,13 +65,12 @@ public class Nloc {
for (int i = 0; i < noOfDroplets; i++){
if (!pump.containsDroplets()) {
Droplet droplet = new Droplet(DropletType.PAYLOAD,
new Position(pump,0));
dropletList.add(new Droplet(DropletType.PAYLOAD,
new Position(pump,0)));
} else {
Droplet droplet = new Droplet(DropletType.HEADER,
new Position(pump,i + i * timediff));
dropletList.add(new Droplet(DropletType.HEADER,
new Position(pump,i + i * timediff)));
}
dropletList.add(droplet);
}
return pump;
}
......
......@@ -38,6 +38,7 @@ public class Position {
List<Channel> possibleChannels = chan.getChildrenList();
if (!possibleChannels.isEmpty() && possibleChannels.size() == 1) {
System.out.println("At normal Channel");
this.chan.removeDroplet(droplet);
this.chan = possibleChannels.get(0);
this.chan.addDroplet(droplet);
......@@ -57,6 +58,7 @@ public class Position {
* The list of channels is already ordered by length and thus the
* priority.
*/
System.out.println("At Bifurcation");
Channel following = null;
for (Channel ch : possibleChannels) {
if (!ch.containsDroplets()) {
......
......@@ -19,6 +19,12 @@ public class TestNloc {
List<Droplet> drList = pump.getDropletList();
System.out.println("Number of Droplets neede: " + drList.size());
if (nloc2.simulate()) {
System.out.println("The sequence is good");
} else {
System.out.println("The sequence sucks");
}
}
......
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