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

abschulssberichte erstellt

parent 7d9dd411
#!/bin/bash
for nloc in S1 S2 S3 S4 S5; do
for mode in onlydefault random exhaustive; do
java -Xmx16g -Dmode=$mode -Dnloc=$nloc -Doutput=csv -Dexperiment="all" -jar build/dsgen.jar >> ${nloc}-${mode}.csv
done
done
#!/bin/bash
for nloc in S1 S2 S3 S4 S5; do
for i in $(seq 1 1000); do
java -jar -Dexperiment=all -Dmode=random -Dnloc=$nloc -Doutput=csv build/dsgen.jar > ${nloc}-randomstat.txt
noofnos=$(grep No ${nloc}-randomstat.txt | wc -l)
duration=$(grep Duration ${nloc}-randomstat.txt | cut -d ' ' -f 2)
echo "$noofnos;$duration" >> ${nloc}-randstat.csv
done
done
#for i in $(seq 1 1000); do
# java -jar -Dexperiment=all -Dmode=random -Dnloc=S1 -Doutput=csv build/dsgen.jar > S1-randomstat.txt
# noofnos=$(grep No S1-randomstat.txt | wc -l)
# duration=$(grep Duration S1-randomstat.txt | cut -d ' ' -f 2)
# echo "$noofnos ; $duration"
#done
......@@ -113,9 +113,6 @@ public class Nloc {
}
}
//for (SequenceTuple stup: headersWithDefaultPaths) {
// System.out.println("stup to add to list: " + stup.getDroplet().getName() + " : " + stup.getMinPos() + ":" + stup.getMaxPos());
//}
if (headersWithDefaultPaths.isEmpty()) {
// if no header with default path is found empty sequencetuple list
// and stop the search
......@@ -129,9 +126,6 @@ public class Nloc {
break;
}
}
//for (SequenceTuple stup: s1) {
// System.out.println("SequenceTuple: " + stup.getDroplet().getName() + " : " + stup.getMinPos() + ":" + stup.getMaxPos());
//}
if ( !(payldTuple.getCurrentBifurcation() instanceof Pump) &&
oldSeqTupListLen >= s1.size()) {
s1.clear();
......@@ -166,60 +160,65 @@ public class Nloc {
return dropletSequence;
}
public List<Droplet> getShortestSequenceExhaustive(String[] modulesToVisit) {
public List<Droplet> getShortestSequence(String[] modulesToVisit,
SequenceGenerationMode mode) {
Pump pump = this.getPump();
List<List<SequenceTuple>> possibleSequences;
List<Droplet> dropletSequence = null;
List<SequenceTuple> currentSeq;
if (mode == SequenceGenerationMode.ONLYDEFAULT) {
dropletSequence = getShortestSequenceOnlyDefaultPathHeader(modulesToVisit);
} else {
Pump pump = this.getPump();
List<List<SequenceTuple>> possibleSequences;
List<SequenceTuple> currentSeq;
try {
possibleSequences = getPossibleSequencesExhaustive(modulesToVisit);
// sort the list of possible sequences according to the sequences length
possibleSequences.sort((a,b) -> a.size() - b.size());
List<List<Channel>> pathlist = this.getAllPaths();
List<Channel> moduleChanList;
List<Channel> payloadPath;
try {
moduleChanList = this.getModulesByName(Arrays.asList(modulesToVisit));
payloadPath = this.getDesiredPath(moduleChanList, pathlist);
do {
possibleSequences = getPossibleSequences(modulesToVisit, mode);
// sort the list of possible sequences according to the sequences length
possibleSequences.sort((a,b) -> a.size() - b.size());
pump.removeAllDroplets();
currentSeq = possibleSequences.remove(0);
//System.out.println("Working on sequence");
//for (SequenceTuple stup: currentSeq) {
// if (currentSeq.indexOf(stup) == (currentSeq.size() - 1)) {
// System.out.print(stup.getDroplet().getName() + ": " + stup.getMinPos() + ":" + stup.getMaxPos() + " : " + stup.getPath().get(1).getName());
// } else {
// System.out.print(stup.getDroplet().getName() + ": " + stup.getMinPos() + ":" + stup.getMaxPos() + " : " + stup.getPath().get(1).getName() + " -> ");
// }
//}
//System.out.println("\n");
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);
do {
currentSeq = setTuplePumpoffsetToPumpPosition(currentSeq, min);
pump.removeAllDroplets();
currentSeq = possibleSequences.remove(0);
dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(), currentSeq, currentSeq.get(0).getMinPos());
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 = resetPayloadDropletPosition(currentSeq);
} while (!possibleSequences.isEmpty() &&
!(dropletSequence.size() == currentSeq.size() &&
this.sequenceFunctional()));
currentSeq = setTuplePumpoffsetToPumpPosition(currentSeq, min);
if (dropletSequence.size() != currentSeq.size()) {
dropletSequence.clear();
}
dropletSequence = generateDropletListRecursive(new ArrayList<Droplet>(), currentSeq, currentSeq.get(0).getMinPos());
currentSeq = resetPayloadDropletPosition(currentSeq);
} while (!possibleSequences.isEmpty() &&
!(dropletSequence.size() == currentSeq.size() &&
this.sequenceFunctional(payloadPath)));
if (dropletSequence.size() != currentSeq.size()) {
dropletSequence.clear();
}
} catch(NoSuchModuleException nsme) {
System.out.println(nsme.getMessage());
System.exit(1);
}
} catch(NoSuchModuleException nsme) {
System.out.println(nsme.getMessage());
System.exit(1);
} catch(NlocStructureException nse) {
System.out.println(nse.getMessage());
System.exit(1);
}
}
return dropletSequence;
}
......@@ -322,8 +321,8 @@ public class Nloc {
}
}
public List<List<SequenceTuple>> getPossibleSequencesExhaustive(
String[] modulesToVisit) throws NoSuchModuleException {
public List<List<SequenceTuple>> getPossibleSequences(
String[] modulesToVisit, SequenceGenerationMode mode) throws NoSuchModuleException {
Droplet payloadDroplet = new Droplet(DropletType.PAYLOAD,"p");
......@@ -350,7 +349,7 @@ public class Nloc {
List<List<SequenceTuple>> tmpSeqs = new ArrayList<List<SequenceTuple>>();
for (List<SequenceTuple> stl: sequences) {
tmpSeqs.addAll(
this.computeSequences(stl));
this.computeSequences(stl, mode));
}
sequences = tmpSeqs;
} while (sequences.size() != oldsequences.size());
......@@ -380,15 +379,19 @@ public class Nloc {
return pump;
}
public boolean sequenceFunctional() {
public boolean sequenceFunctional(List<Channel> payloadPath) {
boolean works = true;
while (!allDropletsInSink()) {
try {
this.moveDroplets();
this.moveDroplets(payloadPath);
} catch (CoalescedDropletException e) {
works = false;
//System.out.println("Coalesce! Droplet: " + e.getDroplet().getName() + " Position: " + e.getDroplet().getPosition().getChannel().getName());
break;
} catch (PayloadPathIncorrectException exc) {
works = false;
System.out.println("Payload path not correct");
break;
}
}
return works;
......@@ -398,10 +401,17 @@ public class Nloc {
return dropletList;
}
public void moveDroplets() throws CoalescedDropletException {
public void moveDroplets(List<Channel> payloadPath)
throws CoalescedDropletException, PayloadPathIncorrectException {
Droplet[] drArr = this.dropletList.toArray(new Droplet[dropletList.size()]);
for (Droplet dr : drArr) {
dr.move();
if (dr.getType() == DropletType.PAYLOAD) {
if (payloadPath.contains(dr.getPosition().getChannel())) {
throw new PayloadPathIncorrectException();
}
}
}
for (Droplet dr: drArr) {
if (dr.coalesce()) {
......@@ -525,20 +535,20 @@ public class Nloc {
}
}
public List<List<SequenceTuple>> computeSequences(List<SequenceTuple> seqTup){
public List<List<SequenceTuple>> computeSequences(List<SequenceTuple> seqTup,
SequenceGenerationMode mode){
List<List<SequenceTuple>> seqTupList = new ArrayList<List<SequenceTuple>>();
//SequenceTuple currentSeqTup = seqTup.get(0);
getSequencesAtBifurcationRecursive(seqTup, 0, seqTupList);
//System.out.println("returning " + seqTupList);
getSequencesAtBifurcationRecursive(seqTup, 0, seqTupList, mode);
return seqTupList;
}
private void getSequencesAtBifurcationRecursive(
List<SequenceTuple> seqTupList, int currentSeqTupIndex,
List<List<SequenceTuple>> possibleSequences) {
List<List<SequenceTuple>> possibleSequences,
SequenceGenerationMode mode) {
SequenceTuple currentSeqTup = seqTupList.get(currentSeqTupIndex);
Channel currentBifurcation = currentSeqTup.getCurrentBifurcation();
......@@ -567,54 +577,32 @@ public class Nloc {
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
for (List<Channel> path: 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,randHeaderName),
path, currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
tmp.add(tmpTuple);
if (mode == SequenceGenerationMode.EXHAUSTIVE) {
for (List<Channel> path: pathList) {
// calculate and set pump offsets
int minPos = currentSeqTup.getMinPos();
int maxPos = currentSeqTup.getMaxPos();
List<SequenceTuple> tmp =
generateNewListOfSequenceTuples(seqTupList,
path, currentBifurcation, currentSeqTup, dropletPath,
defaultChan);
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);
possibleSequences.add(tmp);
}
int maxPathLenNewDroplet = getHeaderPathlength(path);
int minPathLenNewDroplet =
maxPathLenNewDroplet - defaultChan.getHSteps() + 1;
int newTupleMinPos =
minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
int newTupleMaxPos =
maxPos - (pathLenCurrDroplet - maxPathLenNewDroplet);
tmpTuple.setMinPos(newTupleMinPos);
tmpTuple.setMaxPos(newTupleMaxPos);
} else if (mode == SequenceGenerationMode.RANDOMHEADER) {
List<Channel> path =
pathList.get(ThreadLocalRandom.current().nextInt(0,pathList.size()));
List<SequenceTuple> tmp =
generateNewListOfSequenceTuples(seqTupList,
path, currentBifurcation, currentSeqTup, dropletPath,
defaultChan);
possibleSequences.add(tmp);
}
} else if (!(currentBifurcation instanceof Pump)) {
} else if ( !(currentBifurcation instanceof Pump)) {
// we still have some bifurcations to check
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex,
possibleSequences);
possibleSequences, mode);
} else {
possibleSequences.add(seqTupList);
}
......@@ -631,61 +619,86 @@ public class Nloc {
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
for (List<Channel> path: 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,randHeaderName),
path, currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
if (mode == SequenceGenerationMode.EXHAUSTIVE) {
for (List<Channel> path: pathList) {
tmp.add(seqTupList.indexOf(currentSeqTup) + 1, tmpTuple);
List<SequenceTuple> tmp = generateNewListOfSequenceTuples(seqTupList,
path, currentBifurcation, currentSeqTup, dropletPath,
defaultChan);
// 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);
getSequencesAtBifurcationRecursive(tmp, currentSeqTupIndex + 1,
possibleSequences, mode);
}
} else if (mode == SequenceGenerationMode.RANDOMHEADER) {
int maxPathLenNewDroplet = getHeaderPathlength(path);
int minPathLenNewDroplet =
maxPathLenNewDroplet - defaultChan.getHSteps() + 1;
List<Channel> path = pathList.get(
ThreadLocalRandom.current().nextInt(0,pathList.size()));
int newTupleMinPos =
minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
int newTupleMaxPos =
maxPos - (pathLenCurrDroplet - maxPathLenNewDroplet);
tmpTuple.setMinPos(newTupleMinPos);
tmpTuple.setMaxPos(newTupleMaxPos);
List<SequenceTuple> tmp = generateNewListOfSequenceTuples(seqTupList,
path, currentBifurcation, currentSeqTup, dropletPath,
defaultChan);
getSequencesAtBifurcationRecursive(tmp, currentSeqTupIndex + 1,
possibleSequences);
possibleSequences, mode);
}
} else if (!(currentBifurcation instanceof Pump)) {
// we still have some bifurcations to check
currentSeqTup.
setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex,
possibleSequences);
possibleSequences, mode);
} else {
getSequencesAtBifurcationRecursive(seqTupList, currentSeqTupIndex + 1,
possibleSequences);
possibleSequences, mode);
}
}
}
private List<SequenceTuple> generateNewListOfSequenceTuples(
List<SequenceTuple> seqTupList, List<Channel> path,
Channel currentBifurcation, SequenceTuple currentSeqTup,
List<Channel> dropletPath, Channel defaultChan) {
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,randHeaderName),
path, currentBifurcation);
tmpTuple.setCurrentBifurcation(tmpTuple.getPreviousBifurcation());
tmp.add(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;
int newTupleMinPos =
minPos - (pathLenCurrDroplet - minPathLenNewDroplet);
int newTupleMaxPos =
maxPos - (pathLenCurrDroplet - maxPathLenNewDroplet);
tmpTuple.setMinPos(newTupleMinPos);
tmpTuple.setMaxPos(newTupleMaxPos);
return tmp;
}
}
package nloc;
public class PayloadPathIncorrectException extends Exception {
public PayloadPathIncorrectException () {
super();
}
public PayloadPathIncorrectException (String message) {
super(message);
}
}
package nloc;
public enum SequenceGenerationMode {
EXHAUSTIVE, RANDOMHEADER, ONLYDEFAULT;
}
......@@ -10,71 +10,135 @@ public class TestNloc {
public static void main(String[] args) {
List<Channel> chList = getNlocS3(); //getNlocSXX();
Nloc nl = new Nloc(chList);
String experiment = System.getProperty("experiment");
String mode = System.getProperty("mode");
String nloc = System.getProperty("nloc");
String output = System.getProperty("output");
String[] modulesToVisit = null;
SequenceGenerationMode modeEnum = null;
if (nloc == null) {
System.out.println("Usage: java -D<sysprop1> -D<sysprop2> -jar build/dsgen.jar\nValid system properties are:");
System.out.println("");
System.out.println("experiment");
System.out.println("Vaules for experiment are a string containing all modules the payload droplet must visit delimited by space. e.g: \"m0 d1 h3\" or the string all to do all possible experiments");
System.out.println("Default: all");
System.out.println("");
System.out.println("mode");
System.out.println("Values for mode: exhaustive, random, onlydefault");
System.out.println("Deafult: exhaustive");
System.out.println("");
System.out.println("nloc");
System.out.println("Values for nloc: S1, S2, S3, S4, S5");
System.out.println("No default. Mandatory input!");
System.out.println("");
System.out.println("output");
System.out.println("Values for output: csv, sequence");
System.out.println("Default: sequence");
System.out.println("");
System.exit(0);
}
if (experiment == null) {
experiment = "all";
}
if (mode == null) {
mode = "exhaustive";
}
if (output == null) {
output = "sequence";
}
List<Channel> chlist = null;
switch(nloc) {
case "S1":
chlist = getNlocS1();
break;
case "S2":
chlist = getNlocS2();
break;
case "S3":
chlist = getNlocS3();
break;
case "S4":
chlist = getNlocS4();
break;
case "S5":
chlist = getNlocS5();
break;
default:
System.out.println("The choice of an nloc is mandatory!");
System.exit(1);
}
//List<Channel> chList = getNlocS5(); //getNlocSXX();
Nloc nl = new Nloc(chlist);
if (mode.equals("exhaustive")) {
modeEnum = SequenceGenerationMode.EXHAUSTIVE;
} else if (mode.equals("random")) {
modeEnum = SequenceGenerationMode.RANDOMHEADER;
} else if (mode.equals("onlydefault")) {
modeEnum = SequenceGenerationMode.ONLYDEFAULT;
} else {
modeEnum = SequenceGenerationMode.EXHAUSTIVE;
}
if (!experiment.equals("all")) {
modulesToVisit = experiment.split(" ");
doSpecificExperiment(modulesToVisit, nl, modeEnum, output);
} else {
System.out.println("all experiments");
doAllExperiments(nl, modeEnum, output);
}
}
public static void doSpecificExperiment(String[] modulesToVisit, Nloc nl,
SequenceGenerationMode mode, String output) {
long timeStart = System.nanoTime();
List<Droplet> drlist = nl.getShortestSequence(modulesToVisit, mode);
long timeEnd = System.nanoTime();
long duration = (timeEnd - timeStart);
if (output.equals("csv")) {
printCSV(modulesToVisit, drlist, duration);
} else {
printDropletSequence(modulesToVisit, drlist);
printDuration(duration);
}
}
public static void doAllExperiments(Nloc nl, SequenceGenerationMode mode,
String output) {
List<List<Channel>> allPaths = nl.getAllPaths();
//String[] mtv = { "h0", "d0", "m2", "m3"};
//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());
//}
//Droplet hdr1 = new Droplet(DropletType.HEADER,"h1");
//Droplet hdr2 = new Droplet(DropletType.HEADER,"h2");
//SequenceTuple st1 = new SequenceTuple(hdr1,allPaths.get(0),4,3);
//SequenceTuple st2 = new SequenceTuple(hdr2,allPaths.get(0),4,3);
//List<SequenceTuple> stl = new ArrayList<SequenceTuple>();
//stl.add(st1);
//System.out.println("SequenceTuple conflicting: " + SequenceTuple.conflictingOffsets(st2,stl));
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);
allPaths.remove(1);
allPaths.remove(3);
allPaths.remove(4);
allPaths.remove(5);
long overallStart = System.nanoTime();
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 + " " );