Skip to content

Commit

Permalink
major bug fixed for dynamic networks, there were duplicate links 2 ,
Browse files Browse the repository at this point in the history
Also the way of deleting was not right, now fixed. Added safety warning for multiple edges
  • Loading branch information
AkandaAshraf committed Jan 29, 2019
1 parent 3926448 commit cafca42
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ def adjPower(self,P,useGPU=False):

def checkSameEntryAdj(self, node1, node2,warning = True):
if self.adjMatDict[node1.ID, node2.ID] == 1 or self.adjMatDict[node1.ID, node2.ID] is not None:
#if set((node1.ID, node2.ID)) <= set(self.adjMatDict):

if warning:
warnings.warn(
"multiple edge connection detected and ignored!",
"multiple edge connection detected!"+str(node1.ID)+":"+str(node2.ID),

)
return True
Expand Down
4 changes: 3 additions & 1 deletion Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, DNA, Graph):
self.selfConnected=False
self.selfConnectionsNumber = 0
self.Graph.nodeCount += 1
self.MultipleEdgeSafeGraph = True

def __del__(self):
'''
Expand Down Expand Up @@ -87,7 +88,8 @@ def __add__(self, other):

other.inDegree += 1
other.outDegree += 1

if self.MultipleEdgeSafeGraph:
self.Graph.checkSameEntryAdj(self,other)
self.Graph.adjMatDict[self.ID, other.ID] = 1
self.Graph.adjMatDict[other.ID, self.ID] = 1

Expand Down
11 changes: 8 additions & 3 deletions Socialiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,22 @@ def simpleRandomSocialiserSingleEdgeMultiProcessed(self,numberofProcesses, resoc


nodesCombination = list(set(itertools.combinations(nodes, 2)))
# tempSameEntryCheck =collections.defaultdict(lambda: None)
indicesToBeDeltedtemp = []
if resocialising:
l = 0
for nodes in nodesCombination:
# tempSameEntryCheck[nodes[0].ID,nodes[1].ID] =1
if self.graph.checkSameEntryAdj(nodes[0], nodes[1],
warning=False) or self.graph.checkSameEntryAdj(nodes[1],
nodes[0],
warning=False):
del nodesCombination[l]
l +=1
warning=False) or nodes[0].ID==nodes[1].ID:
# del nodesCombination[l]
indicesToBeDeltedtemp.append(l)

l +=1

nodesCombination = [x for i, x in enumerate(nodesCombination) if i not in indicesToBeDeltedtemp]
np.random.shuffle(nodesCombination)
np.random.shuffle(nodesCombination)
np.random.shuffle(nodesCombination)
Expand Down
6 changes: 3 additions & 3 deletions testScriptAkandaMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@
file = 'H:/testEdgesEvolution/'
# os.makedirs(file)

G2 = RandomSocialGraphAdvanced(labelSplit=[5,10,15,20],connectionPercentageWithMatchedNodes=5,connectionPercentageWithMatchedNodesWithRandomness=1,explorationProbability=0.3,addTraidtionalFeatures=False,additionalFeatureLen=1000, npDistFunc=['np.random.randint(3, high=500)'],popularityPreferenceIntensity=0.5,mutualPreferenceIntensity=[0.9,0.3,0.1],genFeaturesFromSameDistforAllLabel=False,keepHistory=True,useGPU = False,numberofProcesses=None,createInGPUMem=False)
G2.socialise()
G2.socialise()
G2 = RandomSocialGraphAdvanced(labelSplit=[50,100,150,200],connectionPercentageWithMatchedNodes=5,connectionPercentageWithMatchedNodesWithRandomness=1,explorationProbability=0.3,addTraidtionalFeatures=False,additionalFeatureLen=1000, npDistFunc=['np.random.randint(3, high=500)'],popularityPreferenceIntensity=0.5,mutualPreferenceIntensity=[0.9,0.3,0.1],genFeaturesFromSameDistforAllLabel=False,keepHistory=True,useGPU = False,numberofProcesses=None,createInGPUMem=False)
G2.socialise()



WriteToFile(G2).easySaveEverything(file)
# file = 'H:/testEvolution2/'
# os.makedirs(file)
Expand Down

0 comments on commit cafca42

Please sign in to comment.