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

soweit ich seh sollts mal funktionieren. mehr test dann moregen

parent 0e9fe450
......@@ -31,6 +31,13 @@ public class Droplet {
this.name = name;
}
public Droplet(Droplet dr) {
this.position = dr.getPosition();
this.type = dr.getType();
this.pumpOutlet = dr.getPumpOutlet();
this.name = dr.getName();
}
public void move() {
position.increment(this);
}
......
......@@ -169,7 +169,6 @@ public class Nloc {
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);
......@@ -178,29 +177,75 @@ public class Nloc {
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);
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());
}
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);
......@@ -374,29 +419,24 @@ public class Nloc {
}
public List<List<SequenceTuple>> computeSequences(List<SequenceTuple> seqTup){
//List<SequenceTuple> seqTup, Channel currentBifurcation) {
List<List<SequenceTuple>> seqTupList = new ArrayList<List<SequenceTuple>>();
SequenceTuple currentSeqTup = seqTup.get(0);
//SequenceTuple currentSeqTup = seqTup.get(0);
getSequencesAtBifurcationRecursive(seqTup, currentSeqTup, seqTupList);
getSequencesAtBifurcationRecursive(seqTup, 0, seqTupList);
//System.out.println("returning " + seqTupList);
return seqTupList;
}
private void getSequencesAtBifurcationRecursive(
List<SequenceTuple> seqTupList, SequenceTuple currentSeqTup,
List<SequenceTuple> seqTupList, int currentSeqTupIndex,
List<List<SequenceTuple>> possibleSequences) {
System.out.println("Working on: " + currentSeqTup + " Name: " + currentSeqTup.getDroplet().getName());
SequenceTuple currentSeqTup = seqTupList.get(currentSeqTupIndex);
Channel currentBifurcation = currentSeqTup.getCurrentBifurcation();
currentSeqTup.setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
System.out.println("Current Bifurcation: " + currentBifurcation.getName());
//currentSeqTup.setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
// check if header droplet is needed
List<Channel> dropletPath = currentSeqTup.getPath();
Channel bifurcSuccessor =
dropletPath.get(dropletPath.indexOf(currentBifurcation) + 1);
......@@ -406,29 +446,38 @@ public class Nloc {
int prio = currentBifurcation.getChildrenList().indexOf(bifurcSuccessor);
if (currentSeqTup.equals(seqTupList.get(seqTupList.size() - 1))) {
System.out.println("At the last Sequence Tuple in List");
// if at last sequence tuple add another header droplet tuple if needed
// and add the list of sequence tuples to the possible sequences list
if (dropletPath.contains(currentBifurcation) && prio > 0) {
System.out.println("We need header droplets");
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
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);
//System.out.println("iterating through pathlist");
List<SequenceTuple> tmp = new ArrayList<SequenceTuple>();
for (SequenceTuple stup: seqTupList) {
tmp.add(new SequenceTuple(stup));
}
SequenceTuple tmpTuple =
new SequenceTuple(new Droplet(DropletType.HEADER,"h"),path,
currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
System.out.println("Adding header droplet: " + tmpTuple.getDroplet() + " current Bifurc: " + tmpTuple.getCurrentBifurcation().getName());
tmp.add(tmpTuple);
//System.out.println("tmp:");
//for (SequenceTuple tstu: tmp) {
// System.out.println("tstu: " + tstu);
//}
// calculate and set pump offsets
......@@ -460,69 +509,75 @@ public class Nloc {
tmpTuple.setMaxPos(newTupleMaxPos);
possibleSequences.add(tmp);
//System.out.println("adding tmp to possible sequences " + possibleSequences);
}
} else {
//System.out.println("else");
possibleSequences.add(seqTupList);
}
} else {
//if (dropletPath.contains(currentBifurcation) && prio > 0) {
// // 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);
// for (List<Channel> path: pathList) {
// List<SequenceTuple> tmp = new ArrayList<SequenceTuple>(seqTupList);
// SequenceTuple tmpTuple =
// new SequenceTuple(new Droplet(DropletType.HEADER,"h"),path,
// currentBifurcation);
// tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
// tmp.add(seqTupList.indexOf(currentSeqTup) + 1, tmpTuple);
// // calculate and set pump offsets
// int minPos = currentSeqTup.getMinPos();
// int maxPos = currentSeqTup.getMaxPos();
// List<Channel> pathToCurrentBifurcation =
// dropletPath.subList(0,dropletPath.indexOf(currentBifurcation) + 1);
// int pathLenCurrDroplet = 0;
// if (currentSeqTup.getDroplet().getType() == DropletType.HEADER) {
// pathLenCurrDroplet = getHeaderPathlength(pathToCurrentBifurcation);
// } else {
// pathLenCurrDroplet = getPayloadPathlength(pathToCurrentBifurcation);
// }
// int maxPathLenNewDroplet = getHeaderPathlength(path);
// int minPathLenNewDroplet =
// maxPathLenNewDroplet - defaultChan.getHSteps() + 1;
// //System.out.println("minPos: " + minPos + " pathLenCurrDroplet: " +
// // pathLenCurrDroplet + " minPathLenNewDroplet: " + minPathLenNewDroplet);
// int newTupleMinPos =
// minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
// int newTupleMaxPos =
// maxPos - (pathLenCurrDroplet - maxPathLenNewDroplet);
// tmpTuple.setMinPos(newTupleMinPos);
// tmpTuple.setMaxPos(newTupleMaxPos);
// getSequencesAtBifurcationRecursive(tmp,
// seqTupList.get(seqTupList.indexOf(currentSeqTup) + 1),
// possibleSequences);
// }
//} else {
// SequenceTuple nextSeqTup =
// seqTupList.get(seqTupList.indexOf(currentSeqTup) + 1);
// getSequencesAtBifurcationRecursive(seqTupList, nextSeqTup,
// possibleSequences);
//}
//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);
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));
}
SequenceTuple tmpTuple =
new SequenceTuple(new Droplet(DropletType.HEADER,"h"),path,
currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
tmp.add(seqTupList.indexOf(currentSeqTup) + 1, tmpTuple);
// calculate and set pump offsets
int minPos = currentSeqTup.getMinPos();
int maxPos = currentSeqTup.getMaxPos();
List<Channel> pathToCurrentBifurcation =
dropletPath.subList(0,dropletPath.indexOf(currentBifurcation) + 1);
int pathLenCurrDroplet = 0;
if (currentSeqTup.getDroplet().getType() == DropletType.HEADER) {
pathLenCurrDroplet = getHeaderPathlength(pathToCurrentBifurcation);
} else {
pathLenCurrDroplet = getPayloadPathlength(pathToCurrentBifurcation);
}
int maxPathLenNewDroplet = getHeaderPathlength(path);
int minPathLenNewDroplet =
maxPathLenNewDroplet - defaultChan.getHSteps() + 1;
//System.out.println("minPos: " + minPos + " pathLenCurrDroplet: " +
// pathLenCurrDroplet + " minPathLenNewDroplet: " + minPathLenNewDroplet);
int newTupleMinPos =
minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
int newTupleMaxPos =
maxPos - (pathLenCurrDroplet - maxPathLenNewDroplet);
tmpTuple.setMinPos(newTupleMinPos);
tmpTuple.setMaxPos(newTupleMaxPos);
getSequencesAtBifurcationRecursive(tmp, currentSeqTupIndex + 1,
possibleSequences);
}
} else {
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex + 1,
possibleSequences);
}
}
}
}
......@@ -35,6 +35,14 @@ public class SequenceTuple {
this.currentBifuraction = null;
}
public SequenceTuple(SequenceTuple stup) {
this.minPos = stup.getMinPos();
this.maxPos = stup.getMaxPos();
this.droplet = stup.getDroplet();
this.path = stup.getPath();
this.currentBifuraction = stup.getCurrentBifurcation();
}
public int getMinPos() {
return minPos;
}
......
......@@ -11,8 +11,12 @@ public class TestNloc {
public static void main(String[] args) {
//Nloc nl = new Nloc(getNlocS5());
List<Channel> chList = getNlocSXX();
//
//TODO: this
//List<Channel> chList = getNlocSTestLast(); //getNlocSXX();
List<Channel> chList = getNlocSXX(); //getNlocSXX();
Nloc nl = new Nloc(chList);
//Pump pump = nl.getPump();
//pump.setSteps(2);
//Channel c1 = new Channel("ch1", 3, 5);
......@@ -38,8 +42,10 @@ public class TestNloc {
// System.out.println("Did coalesce!");
//}
//TODO: this
List<List<Channel>> allPaths = nl.getAllPaths();
//printPaths(allPaths);
printPaths(allPaths);
//allPaths.remove(4);
//try {
......@@ -55,7 +61,8 @@ public class TestNloc {
//}
//printPaths(allPaths);
String[] mtv = {"h0", "m2", "m1", "m3"};
//TODO: this
String[] mtv = {"h0", "m2", "m3"};
try {
List<List<SequenceTuple>> stll = nl.getPossibleSequences(mtv);
printSequences(stll);
......@@ -75,7 +82,26 @@ public class TestNloc {
// 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) {
......@@ -1132,6 +1158,48 @@ public class TestNloc {
return chlist;
}
public static List<Channel> getNlocSTestLast() {
// 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);
Channel ch4 = new Channel("ch4",1,1);
Channel ch5 = new Channel("ch5",3,3);
Channel ch6 = new Channel("ch6",1,1);
Channel ch7 = new Channel("ch7",1,1);
Channel ch8 = new Channel("ch8",1,1);
Module m0 = new Module("m0", 5,1);
Module h0 = new Module("h0", 5,1);
Pump p0 = new Pump();
Sink s0 = new Sink();
List<Channel> chlist = Arrays.asList(ch1, ch2, ch3, ch4, ch5, ch6, ch7,
ch8, m0, h0, p0, s0);
p0.addChild(ch1);
p0.addChild(ch2);
ch2.addChild(h0);
h0.addChild(ch3);
ch1.addChild(ch4);
ch3.addChild(ch4);
ch4.addChild(ch5);
ch4.addChild(ch6);
ch5.addChild(m0);
m0.addChild(ch7);
ch6.addChild(ch8);
ch7.addChild(ch8);
ch8.addChild(s0);
return chlist;
}
public static List<Channel> getNlocSC() {
// channel(name, psteps, hsteps)
......
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