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

jetzt geht mal das generieren der possibleSequences

parent ba96749d
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@ import java.util.Iterator;
import java.util.Arrays;
import java.lang.Math;
import java.util.ConcurrentModificationException;
import java.util.concurrent.ThreadLocalRandom;
public class Nloc {
......@@ -49,7 +51,7 @@ public class Nloc {
dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(), currentSeq, currentSeq.get(0).getMinPos());
currentSeq = resetPayloadDropletPosition(currentSeq);
//currentSeq = resetPayloadDropletPosition(currentSeq);
} while (!possibleSequences.isEmpty() &&
dropletSequence.size() != currentSeq.size() &&
!this.sequenceFunctinal());
......@@ -180,19 +182,12 @@ public class Nloc {
List<List<SequenceTuple>> oldsequences;
do {
oldsequences = new ArrayList<List<SequenceTuple>>(sequences);
//System.out.println("oldseq: " + oldsequences);
//System.out.println("");
List<List<SequenceTuple>> tmpSeqs = new ArrayList<List<SequenceTuple>>();
//System.out.println("sequences before for computing: " + sequences);
//System.out.println("");
for (List<SequenceTuple> stl: sequences) {
tmpSeqs.addAll(
this.computeSequences(stl));
}
sequences = tmpSeqs;
//System.out.println("sequences after for computing: " + sequences);
//System.out.println("");
//System.out.println("");
} while (sequences.size() != oldsequences.size());
} catch (Exception e) {
System.out.println( e.getMessage());
......@@ -200,53 +195,6 @@ public class Nloc {
return sequences;
}
//public List<List<SequenceTuple>> getPossibleSequences(
// String[] modulesToVisit) throws NoSuchModuleException {
// Droplet payloadDroplet = new Droplet(DropletType.PAYLOAD,"p");
// List<List<SequenceTuple>> sequences = new ArrayList<List<SequenceTuple>>();
// List<List<Channel>> pathlist = this.getAllPaths();
// try {
// // Create initial list of possilbe sequences
// List<Channel> moduleChanList =
// this.getModulesByName(Arrays.asList(modulesToVisit));
// List<Channel> payloadPath = this.getDesiredPath(moduleChanList, pathlist);
// SequenceTuple plt = new SequenceTuple(payloadDroplet,payloadPath,0,0);
// Channel previousBifurcation = plt.getPreviousBifurcation();
// plt.setCurrentBifurcation(previousBifurcation);
// List<SequenceTuple> s1 = new ArrayList<SequenceTuple>();
// s1.add(plt);
// sequences.add(s1);
// List<Channel> bifurcationList = this.getBifurcationList(payloadPath);
// // actually compile list of sequences going through the bifurcations from
// // "end" to "start"
// //for (int i = bifurcationList.size() - 1; i >= 0; --i) {
// //Channel currentBifurcation = bifurcationList.get(i);
// List<List<SequenceTuple>> oldsequences;
// do {
// oldsequences = new ArrayList<List<SequenceTuple>>(sequences);
// List<List<SequenceTuple>> tmpSeqs = new ArrayList<List<SequenceTuple>>();
// for (List<SequenceTuple> stl: sequences) {
// tmpSeqs.addAll(
// this.computeSequences(stl));
// }
// sequences = tmpSeqs;
// } while (sequences.size() != oldsequences.size());
// //}
// } catch (Exception e) {
// System.out.println( e.getMessage());
// }
// return sequences;
// }
public void addChannel(Channel chan) {
chanlist.add(chan);
}
......@@ -290,13 +238,9 @@ 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());
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());
if (dr.coalesce()) {
throw new CoalescedDropletException(dr);
}
......@@ -435,7 +379,6 @@ public class Nloc {
SequenceTuple currentSeqTup = seqTupList.get(currentSeqTupIndex);
Channel currentBifurcation = currentSeqTup.getCurrentBifurcation();
//currentSeqTup.setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
List<Channel> dropletPath = currentSeqTup.getPath();
Channel bifurcSuccessor =
......@@ -452,7 +395,6 @@ public class Nloc {
if (dropletPath.contains(currentBifurcation) && prio > 0 &&
!(currentBifurcation instanceof Pump)) {
//System.out.println("we need header");
// we need header droplet
// cirst check all possible paths of header droplets
......@@ -463,22 +405,18 @@ public class Nloc {
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
for (List<Channel> path: pathList) {
//System.out.println("iterating through pathlist");
List<SequenceTuple> tmp = new ArrayList<SequenceTuple>();
for (SequenceTuple stup: seqTupList) {
tmp.add(new SequenceTuple(stup));
}
String randHeaderName =
"h-" + ThreadLocalRandom.current().nextInt(1000, 10000);
SequenceTuple tmpTuple =
new SequenceTuple(new Droplet(DropletType.HEADER,"h"),path,
currentBifurcation);
new SequenceTuple(new Droplet(DropletType.HEADER,randHeaderName),
path, currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
tmp.add(tmpTuple);
//System.out.println("tmp:");
//for (SequenceTuple tstu: tmp) {
// System.out.println("tstu: " + tstu);
//}
// calculate and set pump offsets
int minPos = currentSeqTup.getMinPos();
......@@ -498,8 +436,6 @@ public class Nloc {
int minPathLenNewDroplet =
maxPathLenNewDroplet - defaultChan.getHSteps() + 1;
//System.out.println("minPos: " + minPos + " pathLenCurrDroplet: " +
// pathLenCurrDroplet + " minPathLenNewDroplet: " + minPathLenNewDroplet);
int newTupleMinPos =
minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
int newTupleMaxPos =
......@@ -509,34 +445,39 @@ public class Nloc {
tmpTuple.setMaxPos(newTupleMaxPos);
possibleSequences.add(tmp);
//System.out.println("adding tmp to possible sequences " + possibleSequences);
}
} else if (!(currentBifurcation instanceof Pump)) {
// we still have some bifurcations to check
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex,
possibleSequences);
} else {
//System.out.println("else");
possibleSequences.add(seqTupList);
}
} else {
//possibleSequences.add(seqTupList);
if (dropletPath.contains(currentBifurcation) && prio > 0 &&
!(currentBifurcation instanceof Pump)) {
//System.out.println("we need header for: " + currentSeqTup.getDroplet() + " " + currentSeqTup.getDroplet().getName());
//System.out.println("At: " + currentBifurcation.getName());
// we need header droplet
// cirst check all possible paths of header droplets
Channel defaultChan = currentBifurcation.getChildrenList().get(0);
List<List<Channel>> pathList =
this.getAllPathsFromTo(dropletPath.get(0), defaultChan);
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
for (List<Channel> path: pathList) {
//List<SequenceTuple> tmp = new ArrayList<SequenceTuple>(seqTupList);
List<SequenceTuple> tmp = new ArrayList<SequenceTuple>();
for (SequenceTuple stup: seqTupList) {
tmp.add(new SequenceTuple(stup));
}
String randHeaderName =
"h-" + ThreadLocalRandom.current().nextInt(1000, 10000);
SequenceTuple tmpTuple =
new SequenceTuple(new Droplet(DropletType.HEADER,"h"),path,
currentBifurcation);
new SequenceTuple(new Droplet(DropletType.HEADER,randHeaderName),
path, currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
......@@ -560,8 +501,6 @@ public class Nloc {
int minPathLenNewDroplet =
maxPathLenNewDroplet - defaultChan.getHSteps() + 1;
//System.out.println("minPos: " + minPos + " pathLenCurrDroplet: " +
// pathLenCurrDroplet + " minPathLenNewDroplet: " + minPathLenNewDroplet);
int newTupleMinPos =
minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
int newTupleMaxPos =
......@@ -573,6 +512,12 @@ public class Nloc {
getSequencesAtBifurcationRecursive(tmp, currentSeqTupIndex + 1,
possibleSequences);
}
} else if (!(currentBifurcation instanceof Pump)) {
// we still have some bifurcations to check
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex,
possibleSequences);
} else {
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex + 1,
possibleSequences);
......
......@@ -10,104 +10,32 @@ public class TestNloc {
public static void main(String[] args) {
//Nloc nl = new Nloc(getNlocS5());
//
//TODO: this
//List<Channel> chList = getNlocSTestLast(); //getNlocSXX();
List<Channel> chList = getNlocSXX(); //getNlocSXX();
List<Channel> chList = getNlocS2(); //getNlocSXX();
Nloc nl = new Nloc(chList);
//Pump pump = nl.getPump();
//pump.setSteps(2);
//Channel c1 = new Channel("ch1", 3, 5);
//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!");
//}
//TODO: this
List<List<Channel>> allPaths = nl.getAllPaths();
printPaths(allPaths);
//allPaths.remove(4);
//try {
// String[] mtv = {"f2", "m3", "h0", "m5"};
// List<List<SequenceTuple>> posSeqs = nl.getPossibleSequences(mtv);
// //printSequences(posSeqs);
// System.out.println("DEBUG:");
// Pump p0 = nl.getShortestSequence(mtv);
// printPumpcontents(p0);
//} catch (Exception e) {
// System.out.println(e.getMessage());
//}
//printPaths(allPaths);
//TODO: this
//String[] mtv = {"h3", "m1", "m3", "m0", "m5"};
//try {
// List<List<SequenceTuple>> stll = nl.getPossibleSequences(mtv);
// printSequences(stll);
//} catch (NoSuchModuleException e) {
// System.out.println(e.getMessage());
//}
int count = 0;
for (List<Channel> path: allPaths) {
String[] modulesToVisit = extractModuleStringArrayFromPath(path);
System.out.println("Pathnum: " + count++);
System.out.println("Modules to visit: ");
for (String str: modulesToVisit) {
System.out.print(str + " " );
}
System.out.println("Pathnum: " + count++);
System.out.println("");
try {
List<List<SequenceTuple>> stll = nl.getPossibleSequences(modulesToVisit);
printSequences(stll);
} catch (Exception e) {
e.printStackTrace();
}
//Pump p = nl.getShortestSequence(modulesToVisit);
//printPumpcontents(p);
Pump p = nl.getShortestSequence(modulesToVisit);
printPumpcontents(p);
}
//Droplet pld = new Droplet(DropletType.PAYLOAD,"p");
//Droplet hdr = new Droplet(DropletType.HEADER,"h");
//List<Droplet> drlist = new ArrayList<Droplet>();
//drlist.add(pld);
//drlist.add(hdr);
//List<Droplet> newlist = new ArrayList<Droplet>();
//for (Droplet dr: drlist) {
// newlist.add(new Droplet(dr));
//}
//System.out.println("Printing original list:");
//for (Droplet dr: drlist) {
// System.out.println("Droplet: " + dr);
//}
//System.out.println("Printing copy of list:");
//for (Droplet dr: newlist) {
// System.out.println("Droplet: " + dr);
//}
}
public static void printPumpcontents(Pump pump) {
......@@ -1092,75 +1020,92 @@ public class TestNloc {
// channel(name, psteps, hsteps)
Channel ch1 = new Channel("ch1",1,1);
Channel ch2 = new Channel("ch2",1,1);
Channel ch3 = new Channel("ch3",3,3);
Channel ch4 = new Channel("ch4",1,1);
Channel ch3 = new Channel("ch3",1,1);
Channel ch4 = new Channel("ch4",3,3);
Channel ch5 = new Channel("ch5",1,1);
Channel ch6 = new Channel("ch6",1,1);
Channel ch7 = new Channel("ch7",1,1);
Channel ch8 = new Channel("ch8",3,3);
Channel ch8 = new Channel("ch8",1,1);
Channel ch9 = new Channel("ch9",1,1);
Channel ch10 = new Channel("ch10",1,1);
Channel ch10 = new Channel("ch10",3,3);
Channel ch11 = new Channel("ch11",1,1);
Channel ch12 = new Channel("ch12",3,3);
Channel ch12 = new Channel("ch12",1,1);
Channel ch13 = new Channel("ch13",1,1);
Channel ch14 = new Channel("ch14",1,1);
Channel ch15 = new Channel("ch15",1,1);
Channel ch15 = new Channel("ch15",3,3);
Channel ch16 = new Channel("ch16",1,1);
Channel ch17 = new Channel("ch17",1,1);
Channel ch18 = new Channel("ch18",1,1);
Channel ch19 = new Channel("ch19",1,1);
Channel ch20 = new Channel("ch20",1,1);
Module m0 = new Module("m0", 5,1);
Module m1 = new Module("m1", 5,1);
Module m2 = new Module("m2", 5,1);
Module m3 = new Module("m3", 5,1);
Module h0 = new Module("h0", 5,1);
Module h1 = new Module("h1", 5,1);
Module d0 = new Module("d0", 5,1);
Module d1 = new Module("d1", 5,1);
Pump p0 = new Pump();
Sink s0 = new Sink();
List<Channel> chlist = Arrays.asList(ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8,
ch9, ch10, ch11, ch12, ch13, ch14, ch15, ch16, ch17, m0, m1, m2, m3,
h0, p0, s0);
ch9, ch10, ch11, ch12, ch13, ch14, ch15, ch16, ch17, ch18, ch19, ch20,
m0, m1, m2, m3, h0, h1, d0, d1, p0, s0);
p0.addChild(ch1);
p0.addChild(ch2);
p0.addChild(ch17);
p0.addChild(ch3);
ch1.addChild(ch3);
ch1.addChild(ch4);
ch1.addChild(ch5);
ch3.addChild(m0);
m0.addChild(ch6);
ch4.addChild(m0);
m0.addChild(ch7);
ch2.addChild(h0);
h0.addChild(ch5);
ch5.addChild(h1);
h1.addChild(ch8);
ch2.addChild(h0);
h0.addChild(ch6);
ch17.addChild(ch7);
ch5.addChild(ch7);
ch6.addChild(ch9);
ch3.addChild(ch9);
ch7.addChild(ch8);
ch7.addChild(ch9);
ch9.addChild(ch10);
ch9.addChild(ch11);
ch8.addChild(m1);
m1.addChild(ch10);
ch10.addChild(m1);
m1.addChild(ch12);
ch10.addChild(ch11);
ch9.addChild(ch11);
ch6.addChild(ch11);
ch4.addChild(ch11);
ch11.addChild(d0);
d0.addChild(ch13);
ch11.addChild(ch12);
ch11.addChild(ch13);
ch7.addChild(ch14);
ch8.addChild(ch14);
ch12.addChild(ch14);
ch13.addChild(ch14);
ch12.addChild(m2);
m2.addChild(ch14);
ch14.addChild(ch15);
ch13.addChild(ch15);
ch14.addChild(ch16);
ch15.addChild(m2);
m2.addChild(ch17);
ch16.addChild(d1);
d1.addChild(ch18);
ch17.addChild(ch19);
ch18.addChild(ch19);
ch15.addChild(m3);
m3.addChild(ch16);
ch19.addChild(m3);
m3.addChild(ch20);
ch20.addChild(s0);
ch16.addChild(s0);
return chlist;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment