Commit d530c512 authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

die normalizierung fuer die coalesce funktion berichtigt. jetzt muss aber noch...

die normalizierung fuer die coalesce funktion berichtigt. jetzt muss aber noch die coalesce funktion selber genau angesehen werden.
parent 8298eb0b
......@@ -2,6 +2,7 @@ package nloc;
import java.util.List;
import java.util.ArrayList;
import java.lang.Math;
public class Droplet {
private Position position;
......@@ -64,12 +65,19 @@ public class Droplet {
int hSteps = chan.getHSteps();
float factor = 1;
if (pSteps < hSteps && this.type == DropletType.HEADER) {
factor = (float)pSteps / hSteps;
} else if (pSteps > hSteps && this.type == DropletType.PAYLOAD) {
factor = (float)hSteps / pSteps;
}
return (int)(this.position.getSteps() * factor);
int normStep;
if (this.position.getSteps() == 1) {
return this.position.getSteps();
} else {
if (pSteps < hSteps && this.type == DropletType.HEADER) {
factor = (float)pSteps / hSteps;
} else if (pSteps > hSteps && this.type == DropletType.PAYLOAD) {
factor = (float)hSteps / pSteps;
}
normStep = (int)Math.ceil((this.position.getSteps() - 1) * factor);
}
return normStep;
}
public Position getPosition() {
......@@ -97,6 +105,17 @@ public class Droplet {
if (childChanList.size() == 1 &&
childChanList.get(0) instanceof Sink) {
coalesce = false;
// if this droplet is a PAYLOAD droplet and the following is a
// HEADER Droplet and is in a Module (or the other way round)
// they don't coalesce
} else if (childChanList.size() == 1 &&
childChanList.get(0) instanceof Module) {
List<Droplet> followingDroplets =
childChanList.get(0).getNormalizedSortedDropletList();
if (!followingDroplets.isEmpty() &&
this.type != followingDroplets.get(0).getType()) {
coalesce = false;
}
} else if (minChanTs - this.getNormalizedSteps() > Nloc.MIN_TIMEDIFF) {
// droplet is last in channel and remaining time in channel is
// greater than MIN_TIMEDIFF
......@@ -109,14 +128,14 @@ public class Droplet {
coalesce |= (this.position.getChannel().getMinSteps() +
childDrList.get(0).getNormalizedSteps() -
this.getNormalizedSteps()
) <= Nloc.MIN_TIMEDIFF;
) < Nloc.MIN_TIMEDIFF;
}
}
}
} else { // not last droplet in channel
Droplet followingDroplet = drlist.get(drlist.indexOf(this) + 1);
coalesce = (followingDroplet.getNormalizedSteps() -
this.getNormalizedSteps()) <= Nloc.MIN_TIMEDIFF;
this.getNormalizedSteps()) < Nloc.MIN_TIMEDIFF;
}
}
return coalesce;
......
......@@ -216,8 +216,8 @@ public class Nloc {
public boolean simulate() {
this.dropletList = this.getPump().getDropletList();
boolean works = true;
//while (!allDropletsInSink()) {
for(int i = 0; i < 10; i++) {
while (!allDropletsInSink()) {
//for(int i = 0; i < 10; i++) {
try {
this.moveDroplets();
} catch (CoalescedDropletException e) {
......@@ -236,13 +236,13 @@ public class Nloc {
public void moveDroplets() throws CoalescedDropletException {
Droplet[] drArr = this.dropletList.toArray(new Droplet[dropletList.size()]);
for (Droplet dr : drArr) {
System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
//System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
dr.move();
System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
}
System.out.println("");
for (Droplet dr: drArr) {
System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
//System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
if (dr.coalesce()) {
throw new CoalescedDropletException(dr);
}
......
......@@ -11,13 +11,20 @@ public class TestNloc {
public static void main(String[] args) {
//Nloc nl = new Nloc(getNlocS5());
Nloc nl = new Nloc(getNlocSC());
List<Channel> chList = getNlocSC();
Nloc nl = new Nloc(chList);
Pump pump = nl.getPump();
pump.setSteps(2);
pump.setSteps(3);
//Channel c1 = new Channel("ch1", 3, 5);
//Channel c2 = new Channel("ch2", 5, 1);
Droplet pld = new Droplet(DropletType.PAYLOAD, new Position(pump,1));
pld.setName("p");
Droplet hdr = new Droplet(DropletType.HEADER, new Position(pump,2));
Droplet hdr = new Droplet(DropletType.HEADER, new Position(pump,3));
hdr.setName("h");
//
//int normStep = hdr.getNormalizedSteps();
//System.out.println("Normalized Steps: " + normStep);
//nl.setDropletList(pump.getDropletList());
if (nl.simulate()) {
......@@ -1032,7 +1039,7 @@ public class TestNloc {
public static List<Channel> getNlocSC() {
// channel(name, psteps, hsteps)
Channel ch1 = new Channel("ch1",1,1);
Channel ch1 = new Channel("ch1",3,5);
Channel ch2 = new Channel("ch2",1,1);
Channel ch3 = new Channel("ch3",1,1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment