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

funtkion pathOnlyContainsDefaults getestet

parent 1b9d40d6
No related branches found
No related tags found
No related merge requests found
......@@ -28,13 +28,24 @@ public class Nloc {
// while adding header droplets that only have paths with default channels
// at bifurcations
// the list representing the sequence //
List<Droplet> dropletSequence = null;
Pump pump = this.getPump();
// get the payload path
List<Channel> pathlist = this.getAllPaths();
List<Channel> moduleChanList =
this.getModulesByName(Arrays.asList(modulesToVisit));
List<Channel> payloadPath = this.getDesiredPath(moduleChanList, pathlist);
List<List<Channel>> pathlist = this.getAllPaths();
List<Channel> moduleChanList = null;
List<Channel> payloadPath = null;
try {
moduleChanList = this.getModulesByName(Arrays.asList(modulesToVisit));
payloadPath = this.getDesiredPath(moduleChanList, pathlist);
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(1);
}
// set up initial list of sequence tuples
Droplet payloadDroplet = new Droplet(DropletType.PAYLOAD,"p");
SequenceTuple payldTuple = new SequenceTuple(payloadDroplet,payloadPath,0,0);
Channel previousBifurcation = payldTuple.getPreviousBifurcation();
payldTuple.setCurrentBifurcation(previousBifurcation);
......@@ -55,12 +66,91 @@ public class Nloc {
Channel bifurcSuccessor =
payloadPath.get(payloadPath.indexOf(currentBifurcation) + 1);
Channel bifurcationDefaultPath =
currentBifurcation.getChildrenList().get(0);
// bifurcation priority: prio = 0 if default channel; prio >= 1 if not
// default and threrfore header droplet needed
int prio = currentBifurcation.getChildrenList().indexOf(bifurcSuccessor);
if (prio > 0) {
// we need a header droplet
// get list of all possible header paths
List<List<Channel>> possibleHeaderPathlist = this.getAllPathsFromTo(
pump,bifurcationDefaultPath);
// find header droplets with only default pahts
List<SequenceTuple> headersWithDefaultPaths =
new ArrayList<SequenceTuple>();
for (List<Channel> path: possibleHeaderPathlist) {
if (this.pathOnlyContainsDefaults(path)) {
String randHeaderName =
"h-" + ThreadLocalRandom.current().nextInt(1000, 10000);
SequenceTuple tmpTuple =
new SequenceTuple(new Droplet(DropletType.HEADER,randHeaderName),
path, currentBifurcation);
headersWithDefaultPaths.add(tmpTuple);
// calculate and set pump offsets
List<Channel> payloadPathToCurrentBifurcation =
payloadPath.subList(0,payloadPath.indexOf(currentBifurcation));
int pathLenPayloadDroplet = this.getPayloadPathlength(
payloadPathToCurrentBifurcation);
int maxPathLenNewDroplet = getHeaderPathlength(path);
int minPathLenNewDroplet =
maxPathLenNewDroplet - bifurcationDefaultPath.getHSteps() + 1;
int newTupleMinPos = minPathLenNewDroplet - pathLenPayloadDroplet;
int newTupleMaxPos = maxPathLenNewDroplet - pathLenPayloadDroplet;
tmpTuple.setMinPos(newTupleMinPos);
tmpTuple.setMaxPos(newTupleMaxPos);
}
}
if (headersWithDefaultPaths.isEmpty()) {
// if no header with default path is found empty sequencetuple list
// and stop the search
s1.clear();
suitableHeaderFound = false;
} else {
int oldSeqTupListLen = s1.size();
for (SequenceTuple hstup: headersWithDefaultPaths) {
if (!SequenceTuple.conflictingOffsets(hstup, s1)) {
s1.add(hstup);
}
}
}
} else {
// no header needed just ascend to next bifurcation
payldTuple.setCurrentBifurcation(payldTuple.getPreviousBifurcation());
}
} while (suitableHeaderFound &&
!(plt.getCurrentBifurcation() instanceof Pump));
!(payldTuple.getCurrentBifurcation() instanceof Pump));
if (!s1.isEmpty()) {
int min = 0, max = 0;
for (SequenceTuple stl: s1) {
int tmp = stl.getMinPos();
if (tmp > max) max = tmp;
if (tmp < min) min = tmp;
}
int span = max - min;
pump.setSteps(span);
s1 = setTuplePumpoffsetToPumpPosition(s1, min);
dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(),
s1, s1.get(0).getMinPos());
}
return dropletSequence;
}
public List<Droplet> getShortestSequenceExhaustive(String[] modulesToVisit) {
......@@ -71,7 +161,7 @@ public class Nloc {
List<SequenceTuple> currentSeq;
try {
possibleSequences = getPossibleSequencesExhausitve(modulesToVisit);
possibleSequences = getPossibleSequencesExhaustive(modulesToVisit);
// sort the list of possible sequences according to the sequences length
possibleSequences.sort((a,b) -> a.size() - b.size());
......@@ -120,6 +210,16 @@ public class Nloc {
return dropletSequence;
}
public boolean pathOnlyContainsDefaults(List<Channel> path) {
boolean onlyDefaults = true;
for (Channel ch: path) {
if (ch.isBifurcation()) {
onlyDefaults &= path.contains(ch.getChildrenList().get(0));
}
}
return onlyDefaults;
}
public void setDropletList(List<Droplet> dropletList) {
this.dropletList = dropletList;
}
......
......@@ -43,6 +43,16 @@ public class SequenceTuple {
this.currentBifuraction = stup.getCurrentBifurcation();
}
public static boolean conflictingOffsets(SequenceTuple stup,
List<SequenceTuple> stl) {
boolean conflict = false;
for (SequenceTuple tmp: stl) {
conflict |= (stup.getMinPos() == tmp.getMinPos()) &&
(stup.getMaxPos() == tmp.getMaxPos());
}
return conflict;
}
public int getMinPos() {
return minPos;
}
......
......@@ -10,47 +10,56 @@ public class TestNloc {
public static void main(String[] args) {
List<Channel> chList = getNlocS3(); //getNlocSXX();
List<Channel> chList = getNlocSXX(); //getNlocSXX();
Nloc nl = new Nloc(chList);
List<List<Channel>> allPaths = nl.getAllPaths();
int count = 0;
//
//String[] mtv = { m2 d1 m4 h2 m1 d5}; // S3 problem
//String[] mtv = { "f2", "m3", "h0", "m5"}; //old S2 problem
//String[] mtv = { "f2", "m3", "m0", "m5"}; //old S2 problem
//try {
// List<List<SequenceTuple>> stll = nl.getPossibleSequencesExhaustive(mtv);
// //printSequences(stll);
//} catch (Exception e) {
// e.printStackTrace();
//}
//List<Droplet> drlist = nl.getShortestSequenceExhaustive(mtv);
//printDropletSequence(drlist);
//printPumpcontents(p);
for (List<Channel> path: allPaths) {
String[] mtv = { "h0", "d0", "m2", "m3"};
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("");
try {
List<List<SequenceTuple>> stll = nl.getPossibleSequencesExhaustive(modulesToVisit);
//printSequences(stll);
} catch (Exception e) {
e.printStackTrace();
}
List<Droplet> drlist = nl.getShortestSequenceExhaustive(modulesToVisit);
printDropletSequence(drlist);
try {
List<Channel> ptt = nl.getDesiredPath(nl.getModulesByName(Arrays.asList(mtv)),allPaths);
System.out.println("only defaults: " + nl.pathOnlyContainsDefaults(ptt));
} catch (Exception e) {
System.out.println(e.getMessage());
}
//int count = 0;
////
////String[] mtv = { m2 d1 m4 h2 m1 d5}; // S3 problem
////String[] mtv = { "f2", "m3", "h0", "m5"}; //old S2 problem
////String[] mtv = { "f2", "m3", "m0", "m5"}; //old S2 problem
////try {
//// List<List<SequenceTuple>> stll = nl.getPossibleSequencesExhaustive(mtv);
//// //printSequences(stll);
////} catch (Exception e) {
//// e.printStackTrace();
////}
////List<Droplet> drlist = nl.getShortestSequenceExhaustive(mtv);
////printDropletSequence(drlist);
////printPumpcontents(p);
//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("");
// try {
// List<List<SequenceTuple>> stll = nl.getPossibleSequencesExhaustive(modulesToVisit);
// //printSequences(stll);
// } catch (Exception e) {
// e.printStackTrace();
// }
// List<Droplet> drlist = nl.getShortestSequenceExhaustive(modulesToVisit);
// printDropletSequence(drlist);
//}
}
public static void printDropletSequence(List<Droplet> drList) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment