Commit 2e72c27b authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

ein teil der rekursion beim generieren der endgueltigen dropletzequenz aus den...

ein teil der rekursion beim generieren der endgueltigen dropletzequenz aus den moeglichen sequenzen fehlt noch. und zwar der backtrack fall
parent 672ca9c5
......@@ -124,7 +124,7 @@ public class Droplet {
}
public void setPosition(Position position) {
if (position != null) {
if (this.position != null) {
this.position.getChannel().removeDroplet(this);
}
this.position = position;
......
......@@ -95,6 +95,32 @@ public class Nloc {
// return tmpSeqs;
// }
//ListIterator<SequenceTuple> seqIter = currentSeq.ListIterator();
//while (seqIter.hasNext()) {
// SequenceTuple currentSeqTuple = seqIter.next();
// int minPos = currentSeqTuple.getMinPos();
// int maxPos = currentSeqTuple.getMaxPos();
// Position initialDropletPosition = new Position(pump, minPos);
// Droplet currentDroplet = currentSeqTuple.getDroplet();
//
// if (position.alreadyOccupied(dropletSequence)) {
// // if occupied first try to increase position until max is reached
// // if max is also occupied then step back one droplet in list
// // and increase its position
// // if all fails return null pump indicating that no sequence could
// // be found
// for (int i = minPos; i <= maxPos; i++) {
// }
// } else {
// currentDroplet.setPosition(initialDropletPosition);
// dropletSequence.add(currentDroplet);
// }
//}
public Pump getShortestSequence(String[] modulesToVisit) {
Pump pump = this.getPump();
......@@ -105,24 +131,67 @@ public class Nloc {
// sort the list of possible sequences according to the sequences length
possibleSequences.sort((a,b) -> a.size() - b.size());
List<SequenceTuple> shortSeq = possibleSequences.get(0);
List<SequenceTuple> currentSeq = possibleSequences.get(0);
int min = 0, max = 0;
for (SequenceTuple stl: shortSeq) {
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);
Droplet[] pumpArray = new Droplet[span];
List<Droplet> dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(), currentSeq, currentSeq.get(0).getMinPos());
} catch(NoSuchModuleException nsme) {
System.out.println(nsme.getMessage());
}
return pump;
}
private List<Droplet> generateDropletListRecursive(
List<Droplet> dropletList, List<SequenceTuple> currentSequence,
int currentPos) {
if (dropletList.size() == currentSequence.size()) {
return dropletList;
} else {
if (dropletList.isEmpty() ||
!Position.isOccupied(dropletList, currentPos)) {
SequenceTuple tmpTup = currentSequence.get(dropletList.size());
Droplet tmpDr = tmpTup.getDroplet();
tmpDr.setPosition(new Position(this.getPump(), currentPos));
dropletList.add(tmpDr);
// set current pos to minimum of the following sequence tuple
if (dropletList.size() < currentSequence.size()) {
currentPos =
currentSequence.get(dropletList.size()).getMinPos();
}
return generateDropletListRecursive(dropletList, currentSequence,
currentPos);
} else {
SequenceTuple tmpTup = currentSequence.get(dropletList.size());
if (currentPos < tmpTup.getMaxPos()) {
currentPos++;
return generateDropletListRecursive(dropletList, currentSequence,
currentPos);
} else {
return null;
}
//Droplet tmpDr = dropletList.get(dropletList.size() - 1);
//if (currentPos <= tmpDr
}
}
}
public List<List<SequenceTuple>> getPossibleSequences(
String[] modulesToVisit) throws NoSuchModuleException {
......
......@@ -22,6 +22,10 @@ public class Position {
return chan;
}
public void setSteps(int step) {
this.step = step;
}
public void increment(Droplet droplet) {
if (!droplet.isInSink()) {
int chansteps = 0;
......@@ -82,4 +86,17 @@ public class Position {
}
return following;
}
public static boolean isOccupied(List<Droplet> dropletList,
int currentPos) {
boolean occupied = false;
for (Droplet dr: dropletList) {
Position drPos = dr.getPosition();
if (currentPos == drPos.getSteps()) {
occupied = true;
}
}
return occupied;
}
}
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