From 22c12cf1104a8a2ac52b87fb769ba78484f1f27b Mon Sep 17 00:00:00 2001
From: Peter Wagenhuber <peda@servus.at>
Date: Wed, 12 Apr 2017 13:08:56 +0200
Subject: [PATCH] found out problem stated in issue #3

---
 src/Nloc.java     | 15 ++++++++-------
 src/TestNloc.java | 32 ++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/src/Nloc.java b/src/Nloc.java
index 166ce01..27094c9 100644
--- a/src/Nloc.java
+++ b/src/Nloc.java
@@ -70,7 +70,7 @@ public class Nloc {
   public List<BFTableEntry> initializeBifTable(List<Channel> desiredPath) {
     List<BFTableEntry> bftable = new ArrayList<BFTableEntry>();
     
-    ListIterator<Channel> iter = path.listIterator();
+    ListIterator<Channel> iter = desiredPath.listIterator();
     while(iter.hasNext()) {
       Channel current = iter.next();
       if (current.isBifurcation()) {
@@ -142,14 +142,15 @@ public class Nloc {
     return allInSink;
   }
 
-  public List<Channel> getDesiredPath(List<Channel> modules,
+  public List<List<Channel>> getDesiredPath(List<Channel> modules,
       List<List<Channel>> pathlist) throws NlocStructureException {
-    List<Channel> found = new ArrayList<Channel>();
+    List<List<Channel>> found = new ArrayList<List<Channel>>();
     for (List<Channel> path : pathlist) {
-      if (path.containsAll(modules) && found.isEmpty()) {
-        found = path;
-      } else if (path.containsAll(modules) && !found.isEmpty()) {
-        throw new NlocStructureException("Paths are not unique!");
+      //if (path.containsAll(modules) && found.isEmpty()) {
+      if (path.containsAll(modules)) {
+        found.add(path);
+      //} else if (path.containsAll(modules) && !found.isEmpty()) {
+      //  throw new NlocStructureException("Paths are not unique!");
       } 
     }
     if (found.isEmpty()) {
diff --git a/src/TestNloc.java b/src/TestNloc.java
index 140d9b1..515cc80 100644
--- a/src/TestNloc.java
+++ b/src/TestNloc.java
@@ -8,25 +8,29 @@ import java.util.Arrays;
 public class TestNloc {
 
 
-  // TODO: @peda find new algorithm
   public static void main(String[] args) {
 
-    Nloc nlS1 = new Nloc(getNlocS1());
-    Nloc nlS2 = new Nloc(getNlocS2());
-    Nloc nlS6 = new Nloc(getNlocS6());
+    //Nloc nlSX = new Nloc(getNlocS1());
+    //Nloc nlSX = new Nloc(getNlocS2());
+    Nloc nlSX = new Nloc(getNlocS6());
 
-    List<List<Channel>> pathlist = nlS2.getAllPaths();
+    List<List<Channel>> pathlist = nlSX.getAllPaths();
+    try {
+      List<Channel> modulesToVisit = nlSX.getModulesByName(Arrays.asList("m4","m1","m3","h0","m5"));
+      List<List<Channel>> payloadPaths = nlSX.getDesiredPath(modulesToVisit, pathlist);
 
-    printPaths(pathlist);
 
-    Pump pump = nlS2.getPump();
-    Channel ch = nlS2.getModuleByName("ch26");
-    List<List<Channel>> pathlist1 = nlS2.getAllPathsFromTo(pump, ch);
+      Pump pump = nlSX.getPump();
+      Channel ch = nlSX.getModuleByName("ch15");
+      List<List<Channel>> pathlist1 = nlSX.getAllPathsFromTo(pump, ch);
 
-    printPaths(pathlist1);
+      printPaths(pathlist);
+      printPaths(payloadPaths);
+      //printPaths(pathlist1);
 
-
-    
+    } catch (Exception e) {
+      System.out.println( e.getMessage());
+    }
   }
 
   public static void printPath(List<Channel> path) {
@@ -259,8 +263,8 @@ public class TestNloc {
     Channel ch7 = new Channel("ch7",1,1);
     Channel ch8 = new Channel("ch8",1,1);
     Channel ch9 = new Channel("ch9",1,1);
-    Channel ch10 = new Channel("ch10",1,1);
-    Channel ch11 = new Channel("ch11",3,3);
+    Channel ch10 = new Channel("ch10",3,3);
+    Channel ch11 = new Channel("ch11",1,1);
     Channel ch12 = new Channel("ch12",1,1);
     Channel ch13 = new Channel("ch13",1,1);
     Channel ch14 = new Channel("ch14",3,3);
-- 
GitLab