diff --git a/src/Droplet.java b/src/Droplet.java index 99f2fe0f88ba4ffb5c04547ae8c47fcfd7804411..58efdb17f7fbc188343a5dd52f26c1ff797db27d 100644 --- a/src/Droplet.java +++ b/src/Droplet.java @@ -72,10 +72,13 @@ public class Droplet { } else { if (pSteps < hSteps && this.type == DropletType.HEADER) { factor = (float)pSteps / hSteps; + normStep = (int)Math.ceil((this.position.getSteps() - 1) * factor); } else if (pSteps > hSteps && this.type == DropletType.PAYLOAD) { factor = (float)hSteps / pSteps; - } - normStep = (int)Math.ceil((this.position.getSteps() - 1) * factor); + normStep = (int)Math.ceil((this.position.getSteps() - 1) * factor); + } else { + normStep = this.position.getSteps(); + } } return normStep; } @@ -99,6 +102,7 @@ public class Droplet { if (drlist.indexOf(this) + 1 == drlist.size()) { List<Channel> childChanList = this.position.getChannel().getChildrenList(); + int minChanTs = this.position.getChannel().getMinSteps(); // Check if the following channel is a sink @@ -109,33 +113,31 @@ public class Droplet { // 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; - } + childChanList.get(0) instanceof Module && + !childChanList.get(0).getNormalizedSortedDropletList().isEmpty() && + (this.type != + childChanList.get(0).getNormalizedSortedDropletList().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 coalesce = false; } else { - // Next is no sink + // Next is no sink and no module with different type of droplet next for (Channel chan : childChanList) { List<Droplet> childDrList = chan.getNormalizedSortedDropletList(); if (!childDrList.isEmpty()) { 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; diff --git a/src/Nloc.java b/src/Nloc.java index 55adb568cd175c628453b6bf9514cd4528792eb5..a112798e1e6884e03715ffefc4e0475ecae3e3d8 100644 --- a/src/Nloc.java +++ b/src/Nloc.java @@ -51,7 +51,8 @@ public class Nloc { currentSeq = resetPayloadDropletPosition(currentSeq); } while (!possibleSequences.isEmpty() && - dropletSequence.size() != currentSeq.size()); + dropletSequence.size() != currentSeq.size() && + !sequenceFunctinal()); if (dropletSequence.size() != currentSeq.size()) { pump = null; @@ -213,7 +214,7 @@ public class Nloc { return pump; } - public boolean simulate() { + public boolean sequenceFunctinal() { this.dropletList = this.getPump().getDropletList(); boolean works = true; while (!allDropletsInSink()) { diff --git a/src/TestNloc.java b/src/TestNloc.java index 8b5b4fe7699fcc10b44a35d87c0b5d5bd1447ee6..af3e9330760ce93d83241fe3a91f2c2a22b125c4 100644 --- a/src/TestNloc.java +++ b/src/TestNloc.java @@ -11,29 +11,35 @@ public class TestNloc { public static void main(String[] args) { //Nloc nl = new Nloc(getNlocS5()); - List<Channel> chList = getNlocSC(); + List<Channel> chList = getNlocS5(); Nloc nl = new Nloc(chList); - Pump pump = nl.getPump(); - pump.setSteps(3); + //Pump pump = nl.getPump(); + //pump.setSteps(2); //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,3)); - hdr.setName("h"); + //Sink s0 = new Sink(); + //Channel c2 = new Channel("ch2", 3, 5); + //Module m0 = new Module("m0", 5,1); + //c1.addChild(c2); + //Droplet pld = new Droplet(DropletType.PAYLOAD, new Position(pump,1)); + //pld.setName("p"); + //Droplet hdr = new Droplet(DropletType.HEADER, new Position(pump,2)); + //hdr.setName("h"); + // + //System.out.println(pld.coalesce()); // //int normStep = hdr.getNormalizedSteps(); //System.out.println("Normalized Steps: " + normStep); //nl.setDropletList(pump.getDropletList()); - if (nl.simulate()) { - System.out.println("Success!! Don't coalesce"); - } else { - System.out.println("Did coalesce!"); - } + //if (nl.simulate()) { + // System.out.println("Success!! Don't coalesce"); + //} else { + // System.out.println("Did coalesce!"); + //} - //List<List<Channel>> allPaths = nl.getAllPaths(); + List<List<Channel>> allPaths = nl.getAllPaths(); + allPaths.remove(4); //try { // String[] mtv = {"f2", "m3", "h0", "m5"}; @@ -48,19 +54,19 @@ public class TestNloc { //} //printPaths(allPaths); - //int count = 0; - //for (List<Channel> path: allPaths) { + int count = 0; + for (List<Channel> path: allPaths) { - // String[] modulesToVisit = extractModuleStringArrayFromPath(path); + String[] modulesToVisit = extractModuleStringArrayFromPath(path); - // System.out.println("Modules to visit: "); - // for (String str: modulesToVisit) { - // System.out.print(str + " " ); - // } - // System.out.println("Pathnum: " + count++); - // Pump p = nl.getShortestSequence(modulesToVisit); - // printPumpcontents(p); - //} + System.out.println("Modules to visit: "); + for (String str: modulesToVisit) { + System.out.print(str + " " ); + } + System.out.println("Pathnum: " + count++); + Pump p = nl.getShortestSequence(modulesToVisit); + printPumpcontents(p); + } } @@ -1039,11 +1045,11 @@ public class TestNloc { public static List<Channel> getNlocSC() { // channel(name, psteps, hsteps) - Channel ch1 = new Channel("ch1",3,5); + Channel ch1 = new Channel("ch1",1,1); Channel ch2 = new Channel("ch2",1,1); Channel ch3 = new Channel("ch3",1,1); - Module m0 = new Module("m0", 2,1); + Module m0 = new Module("m0", 3,1); Module m1 = new Module("m1", 1,3); Pump p0 = new Pump();