Commit 8298eb0b authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

die coalesce funktion muss noch ueberarbeitet werden vorallem wenn der...

die coalesce funktion muss noch ueberarbeitet werden vorallem wenn der naechste channel ein modul ist und ein payload und ein header modul verglichen werden
parent 744891e5
......@@ -21,7 +21,7 @@ public class Channel extends NlocEntity implements Comparable<Channel> {
}
public boolean containsDroplets() {
return !dropletList.isEmpty();
return !this.dropletList.isEmpty();
}
public int getLastDropletDistance() {
......@@ -30,7 +30,7 @@ public class Channel extends NlocEntity implements Comparable<Channel> {
minDist = -1;
} else {
// Sort dropletlist accoring to droplet position (smallest position first)
dropletList.sort((d1,d2) ->
this.dropletList.sort((d1,d2) ->
d1.getPosition().getSteps() - d2.getPosition().getSteps());
minDist = dropletList.get(0).getPosition().getSteps();
......@@ -55,21 +55,21 @@ public class Channel extends NlocEntity implements Comparable<Channel> {
}
public List<Droplet> getNormalizedSortedDropletList() {
dropletList.sort((d1,d2) ->
this.dropletList.sort((d1,d2) ->
d1.getNormalizedSteps() - d2.getNormalizedSteps());
return dropletList;
return this.dropletList;
}
public List<Droplet> getDropletList() {
return dropletList;
return this.dropletList;
}
public void removeDroplet(Droplet droplet) {
dropletList.remove(droplet);
this.dropletList.remove(droplet);
}
public void addDroplet(Droplet droplet) {
dropletList.add(droplet);
this.dropletList.add(droplet);
}
public void removeAllDroplets() {
......
......@@ -119,7 +119,6 @@ public class Droplet {
this.getNormalizedSteps()) <= Nloc.MIN_TIMEDIFF;
}
}
return coalesce;
}
......
......@@ -3,8 +3,10 @@ package nloc;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Iterator;
import java.util.Arrays;
import java.lang.Math;
import java.util.ConcurrentModificationException;
public class Nloc {
......@@ -63,6 +65,9 @@ public class Nloc {
return pump;
}
public void setDropletList(List<Droplet> dropletList) {
this.dropletList = dropletList;
}
public List<SequenceTuple> resetPayloadDropletPosition(
List<SequenceTuple> currentSequence) {
......@@ -209,8 +214,10 @@ public class Nloc {
}
public boolean simulate() {
this.dropletList = this.getPump().getDropletList();
boolean works = true;
while (!allDropletsInSink()) {
//while (!allDropletsInSink()) {
for(int i = 0; i < 10; i++) {
try {
this.moveDroplets();
} catch (CoalescedDropletException e) {
......@@ -227,11 +234,18 @@ public class Nloc {
}
public void moveDroplets() throws CoalescedDropletException {
for (Droplet dr : dropletList) {
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());
dr.move();
System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
}
for (Droplet dr: dropletList) {
if (dr.coalesce()) throw new CoalescedDropletException(dr);
System.out.println("");
for (Droplet dr: drArr) {
System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
if (dr.coalesce()) {
throw new CoalescedDropletException(dr);
}
}
}
......
......@@ -26,6 +26,8 @@ public class Position {
this.step = step;
}
// create a new position object to be able to create a new dropletlist to
// avoid concurrent modification errors
public void increment(Droplet droplet) {
if (!droplet.isInSink()) {
int chansteps = 0;
......@@ -40,10 +42,10 @@ public class Position {
} else {
this.step = 1;
List<Channel> possibleChannels = chan.getChildrenList();
List<Channel> possibleChannels = this.chan.getChildrenList();
if (!possibleChannels.isEmpty() && possibleChannels.size() == 1) {
this.chan.removeDroplet(droplet);
//this.chan.removeDroplet(droplet);
this.chan = possibleChannels.get(0);
this.chan.addDroplet(droplet);
} else {
......@@ -53,7 +55,7 @@ public class Position {
} else {
this.chan = getFollowingChannel(possibleChannels);
}
temp.removeDroplet(droplet);
//temp.removeDroplet(droplet);
this.chan.addDroplet(droplet);
}
}
......
......@@ -10,8 +10,23 @@ public class TestNloc {
public static void main(String[] args) {
Nloc nl = new Nloc(getNlocS3());
List<List<Channel>> allPaths = nl.getAllPaths();
//Nloc nl = new Nloc(getNlocS5());
Nloc nl = new Nloc(getNlocSC());
Pump pump = nl.getPump();
pump.setSteps(2);
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");
//nl.setDropletList(pump.getDropletList());
if (nl.simulate()) {
System.out.println("Success!! Don't coalesce");
} else {
System.out.println("Did coalesce!");
}
//List<List<Channel>> allPaths = nl.getAllPaths();
//try {
// String[] mtv = {"f2", "m3", "h0", "m5"};
......@@ -26,19 +41,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);
//}
}
......@@ -1013,4 +1028,29 @@ public class TestNloc {
ch53.addChild(s0);
return chlist;
}
public static List<Channel> getNlocSC() {
// channel(name, psteps, hsteps)
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 m1 = new Module("m1", 1,3);
Pump p0 = new Pump();
Sink s0 = new Sink();
List<Channel> chlist = Arrays.asList(ch1, ch2, ch3, m0, m1, p0, s0);
p0.addChild(ch1);
ch1.addChild(m0);
m0.addChild(ch2);
ch2.addChild(m1);
m1.addChild(ch3);
ch3.addChild(s0);
return chlist;
}
}
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