From 7d9dd4116495c1fcfde500d8239b08ca3ea77a14 Mon Sep 17 00:00:00 2001 From: Peter Wagenhuber <peda@servus.at> Date: Thu, 18 May 2017 21:35:19 +0200 Subject: [PATCH] csv ausgabe implementiert --- src/Nloc.java | 15 ++++++++--- src/TestNloc.java | 65 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/Nloc.java b/src/Nloc.java index 8ef3dc8..28bbdb1 100644 --- a/src/Nloc.java +++ b/src/Nloc.java @@ -97,7 +97,7 @@ public class Nloc { // calculate and set pump offsets List<Channel> payloadPathToCurrentBifurcation = - payloadPath.subList(0,payloadPath.indexOf(currentBifurcation)); + payloadPath.subList(0,payloadPath.indexOf(currentBifurcation) + 1); int pathLenPayloadDroplet = this.getPayloadPathlength( payloadPathToCurrentBifurcation); @@ -112,6 +112,10 @@ public class Nloc { tmpTuple.setMaxPos(newTupleMaxPos); } } + + //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 @@ -122,18 +126,23 @@ public class Nloc { for (SequenceTuple hstup: headersWithDefaultPaths) { if (!SequenceTuple.conflictingOffsets(hstup, s1)) { s1.add(hstup); + break; } } - if (oldSeqTupListLen < s1.size()) { + //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(); suitableHeaderFound = false; } } + payldTuple.setCurrentBifurcation(payldTuple.getPreviousBifurcation()); } else { // no header needed just ascend to next bifurcation payldTuple.setCurrentBifurcation(payldTuple.getPreviousBifurcation()); } - } while (suitableHeaderFound && !(payldTuple.getCurrentBifurcation() instanceof Pump)); diff --git a/src/TestNloc.java b/src/TestNloc.java index 0064149..552648f 100644 --- a/src/TestNloc.java +++ b/src/TestNloc.java @@ -10,7 +10,7 @@ public class TestNloc { public static void main(String[] args) { - List<Channel> chList = getNlocSXX(); //getNlocSXX(); + List<Channel> chList = getNlocS3(); //getNlocSXX(); Nloc nl = new Nloc(chList); @@ -50,31 +50,74 @@ public class TestNloc { ////printDropletSequence(drlist); ////printPumpcontents(p); + 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 + " " ); - } - System.out.println(""); + //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); - List<Droplet> drlist = nl.getShortestSequenceOnlyDefaultPathHeader(modulesToVisit); - printDropletSequence(drlist); + long timeStart = System.nanoTime(); + List<Droplet> drlist = nl.getShortestSequenceExhaustive(modulesToVisit); + //List<Droplet> drlist = nl.getShortestSequenceOnlyDefaultPathHeader(modulesToVisit); + long timeEnd = System.nanoTime(); + long duration = (timeEnd - timeStart); + printCSV(modulesToVisit, drlist, duration); + //printDropletSequence(drlist); + //printDuration(duration); + } + long overallEnd = System.nanoTime(); + long overallDuration = (overallEnd - overallStart); + printDuration(overallDuration); + } + + public static void printCSV(String[] modulesToVisit, List<Droplet> drlist, + long duration) { + String csv = ""; + for (String str: modulesToVisit) { + csv = csv.concat(str + " "); + } + csv = csv.concat(";"); + if (drlist == null || drlist.isEmpty()) { + csv = csv.concat("No"); + } else { + csv = csv.concat("Yes"); + } + csv = csv.concat(";"); + duration /= 1000000; + csv = csv.concat(duration + " ms"); + System.out.println( csv); + } + + public static void printDuration(long duration) { + System.out.print("Duration: "); + if (duration < 1000) { + System.out.println(duration + " ns"); + } else if (duration < 1000000) { + duration /= 1000; + System.out.println(duration + " micro sec"); + } else if (duration < 1000000000) { + duration /= 1000000; + System.out.println(duration + " ms"); + } else { + duration /= 1000000000; + System.out.println(duration + " s"); } } public static void printDropletSequence(List<Droplet> drList) { if (drList == null || drList.isEmpty()) { - System.out.println("No Sequence Found"); + System.out.println("No Sequence Found\n"); } else { for (Droplet dr: drList) { System.out.print("Droplet: " + dr.getName() + " Pos: " + dr.getPosition().getSteps() + " Outlet: " + dr.getPumpOutlet().getName()); -- GitLab