Commit 744891e5 authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

das finden einer sequenz geht mal fuer alle moegelichen pfade. es ist aber 1....

das finden einer sequenz geht mal fuer alle moegelichen pfade. es ist aber 1. ziemlich langsam und 2. enthaelt es noch einen ueblen hack. es sollte bei der generierung der moeglichen sequenzen wenn die bifurcation list abgearbeitet wird fuer jede moegliche sequenz ein neues payload droplet angelegt werden und nicht immer das gleiche benutzt werden
parent 09bf8f1c
......@@ -20,66 +20,72 @@ public class Nloc {
public Pump getShortestSequence(String[] modulesToVisit) {
Pump pump = this.getPump();
pump.removeAllDroplets();
// while still elements in List<List<SequenceTuple>> and
// dropletSequence.size() != currentSeq.size()
try {
List<List<SequenceTuple>> possibleSequences =
getPossibleSequences(modulesToVisit);
List<List<SequenceTuple>> possibleSequences;
List<Droplet> dropletSequence;
List<SequenceTuple> currentSeq;
try {
possibleSequences = getPossibleSequences(modulesToVisit);
// sort the list of possible sequences according to the sequences length
possibleSequences.sort((a,b) -> a.size() - b.size());
List<SequenceTuple> currentSeq = possibleSequences.get(0);
//for (SequenceTuple seqTup: currentSeq) {
// System.out.println("Droplet: " + seqTup.getDroplet().getName() + " Minpos: " + seqTup.getMinPos() + " Maxpos: " + seqTup.getMaxPos());
// System.out.print("Path: ");
// List<Channel> dropletpath = seqTup.getPath();
// for (Channel ch: dropletpath) {
// System.out.print(" ch: " + ch.getName() + " len: " + ch.getHSteps());
// }
// System.out.println("");
//}
//System.out.println("");
int min = 0, max = 0;
for (SequenceTuple stl: currentSeq) {
int tmp = stl.getMinPos();
if (tmp > max) max = tmp;
if (tmp < min) min = tmp;
do {
pump.removeAllDroplets();
currentSeq = possibleSequences.remove(0);
int min = 0, max = 0;
for (SequenceTuple stl: currentSeq) {
int tmp = stl.getMinPos();
if (tmp > max) max = tmp;
if (tmp < min) min = tmp;
}
int span = max - min;
pump.setSteps(span);
currentSeq = setTuplePumpoffsetToPumpPosition(currentSeq, min);
dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(), currentSeq, currentSeq.get(0).getMinPos());
currentSeq = resetPayloadDropletPosition(currentSeq);
} while (!possibleSequences.isEmpty() &&
dropletSequence.size() != currentSeq.size());
if (dropletSequence.size() != currentSeq.size()) {
pump = null;
}
int span = max - min;
pump.setSteps(span);
currentSeq = setTuplePumpoffsetToPumpPosition(currentSeq, min);
List<Droplet> dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(), currentSeq, currentSeq.get(0).getMinPos());
} catch(NoSuchModuleException nsme) {
System.out.println(nsme.getMessage());
System.exit(1);
}
// dropletSequence.size() != currentSeq.size() return null else return pump
return pump;
}
/*
* TODO: comment on the parameters of the function
*
*/
public List<SequenceTuple> resetPayloadDropletPosition(
List<SequenceTuple> currentSequence) {
for (SequenceTuple stup: currentSequence) {
if (stup.getDroplet().getType() == DropletType.PAYLOAD) {
stup.setMinPos(0);
stup.setMaxPos(0);
}
}
return currentSequence;
}
public List<SequenceTuple> setTuplePumpoffsetToPumpPosition(
List<SequenceTuple> currentSequence, int minOffset) {
//for (List<SequenceTuple> stl: currentSequence) {
for (SequenceTuple stup: currentSequence) {
int pumpOffsetMin = stup.getMinPos();
stup.setMinPos(pumpOffsetMin + Math.abs(minOffset));
int pumpOffsetMax = stup.getMaxPos();
stup.setMaxPos(pumpOffsetMax + Math.abs(minOffset));
}
//}
for (SequenceTuple stup: currentSequence) {
int pumpOffsetMin = stup.getMinPos();
stup.setMinPos(pumpOffsetMin + Math.abs(minOffset));
int pumpOffsetMax = stup.getMaxPos();
stup.setMaxPos(pumpOffsetMax + Math.abs(minOffset));
}
return currentSequence;
}
......
......@@ -10,11 +10,23 @@ public class TestNloc {
public static void main(String[] args) {
Nloc nl = new Nloc(getNlocS2());
Nloc nl = new Nloc(getNlocS3());
List<List<Channel>> allPaths = nl.getAllPaths();
//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);
int count = 0;
for (List<Channel> path: allPaths) {
String[] modulesToVisit = extractModuleStringArrayFromPath(path);
......@@ -23,7 +35,7 @@ public class TestNloc {
for (String str: modulesToVisit) {
System.out.print(str + " " );
}
System.out.println("");
System.out.println("Pathnum: " + count++);
Pump p = nl.getShortestSequence(modulesToVisit);
printPumpcontents(p);
}
......@@ -33,7 +45,7 @@ public class TestNloc {
public static void printPumpcontents(Pump pump) {
List<Droplet> drlist = pump.getDropletList();
for (Droplet dr: drlist) {
System.out.print("Droplet: " + dr.getName() + " Pos: " + dr.getPosition().getSteps());
System.out.print("Droplet: " + dr.getName() + " Pos: " + dr.getPosition().getSteps() + " Outlet: " + dr.getPumpOutlet().getName());
if (drlist.indexOf(dr) == drlist.size() - 1) {
System.out.println("");
} else {
......@@ -57,10 +69,10 @@ public class TestNloc {
for (SequenceTuple stup: seq) {
if (seq.indexOf(stup) == (seq.size() - 1)) {
System.out.print(stup.getDroplet().getName() + ": " + stup.getMinPos() +
":" + stup.getMaxPos());
":" + stup.getMaxPos() + " : " + stup.getPath().get(1).getName());
} else {
System.out.print(stup.getDroplet().getName() + ": " + stup.getMinPos() +
":" + stup.getMaxPos() + " -> ");
":" + stup.getMaxPos() + " : " + stup.getPath().get(1).getName() + " -> ");
}
}
System.out.println("\n");
......
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