From 3c446d4e5d04fabeb3b943d42300fbeb20fd90c7 Mon Sep 17 00:00:00 2001
From: Jarrod Pas <j.pas@usask.ca>
Date: Wed, 26 Jul 2017 14:34:24 -0600
Subject: [PATCH] Fixes NCF in HCBF

---
 pydtn/communities/base.py | 2 +-
 pydtn/routers/hcbf.py     | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/pydtn/communities/base.py b/pydtn/communities/base.py
index 39afcd8..132c2ef 100644
--- a/pydtn/communities/base.py
+++ b/pydtn/communities/base.py
@@ -114,7 +114,7 @@ class EpochCommunity(TickProcess):
     def get_ncf(self, x, c_y):
         ''''''
         g = self.old_graph
-        if x not in c_y or x not in g:
+        if x not in g or x in c_y:
             return 0
         return sum([
             g[x][y]['duration']
diff --git a/pydtn/routers/hcbf.py b/pydtn/routers/hcbf.py
index 01badf1..c8af6dc 100644
--- a/pydtn/routers/hcbf.py
+++ b/pydtn/routers/hcbf.py
@@ -49,7 +49,9 @@ def hcbf(self, packet, state):
             return False
         # lp(max_lp) == lp(self)
 
-    elif not_local_community:
+        return False
+
+    if not_local_community:
         max_cbc = max(not_local_community, key=cbc)
         if cbc(max_cbc) > cbc(self):
             send(max_cbc, 'cbc')
@@ -58,7 +60,8 @@ def hcbf(self, packet, state):
             return False
         # cbc(max_cbc) == cbc(self)
 
-        max_ncf = max(not_local_community, key=ncf)
+    if local_community:
+        max_ncf = max(local_community, key=ncf)
         if ncf(max_ncf) > ncf(self):
             send(max_ncf, 'ncf')
             return True
@@ -66,7 +69,6 @@ def hcbf(self, packet, state):
             return False
         # ncf(max_ncf) == ncf(self)
 
-    elif local_community:
         max_ui = max(local_community, key=ui)
         if ui(max_ui) > ui(self):
             send(max_ui, 'ui_lonely')
-- 
GitLab