Index: nodes/channelga.py
===================================================================
--- nodes/channelga.py	(revision 1929)
+++ nodes/channelga.py	(revision 1935)
@@ -23,6 +23,6 @@
 
 # deze twee zijn nodig voor de evaluatie van een configuratie
-nodes = {}		# lijst van Node instanties
-groups = []		# lijst van Group instanties
+nodes = {}		# nodename -> Node
+groups = {}		# essid -> WIGroup
 
 population = []
@@ -34,4 +34,7 @@
 		d[e] = 1
 	return d.keys()
+
+def multiget(d, ks):
+	return map(lambda k: d[k], ks)
 
 class Node:
@@ -86,4 +89,6 @@
 		self.wis.append(wi)
 		wi.setGroup(self)
+	def uniq(self):
+		self.wis = uniq(self.wis)
 
 class Configuration:
@@ -93,9 +98,11 @@
 	def copy(self):
 		c = Configuration()
-		c.conf = self.conf[:]
+		c.conf = self.conf.copy()
 		c.calculated_score = None
 		return c
 	def randomize(self):
-		self.conf = [random.randint(1, 13) for i in range(len(groups))]
+		self.conf = {}
+		for essid in groups.keys():
+			self.conf[essid] = random.randint(1, 13)
 		self.calculated_score = None
 	def score(self):
@@ -103,6 +110,6 @@
 		if self.calculated_score != None:
 			return self.calculated_score
-		for i in range(len(self.conf)):
-			groups[i].channel = self.conf[i]
+		for essid in groups.keys():
+			groups[essid].channel = self.conf[essid]
 		score = 0
 		for node in nodes.values():
@@ -111,10 +118,11 @@
 		return score
 	def mutate(self, rate):
-		for i in range(len(groups)):
+		for essid in groups.keys():
 			if random.random() <= rate:
-				self.conf[i] = random.randint(1, 13)
+				self.conf[essid] = random.randint(1, 13)
 	def crossover(self, partner, numpoints):
 		# pick the crossover points
-		points = [random.randint(0, len(groups) - 1) for i in range(numpoints)]
+		essids = groups.keys()
+		points = [random.randint(0, len(essids) - 1) for i in range(numpoints)]
 		points.sort()
 		conf = []
@@ -125,8 +133,7 @@
 			if who == 0:
 				l = self.conf[lastpoint:point]
-				who = 1
 			else:
 				l = partner.conf[lastpoint:point]
-				who = 0
+			who = 1 - who
 			conf.extend(l)
 			lastpoint = point
@@ -142,46 +149,44 @@
 # BEGIN UGLY PARSING CODE
 
-ipdict = {}
-ipnr_node = {}
-node_ipnr = {}
-node_links = {}
+to_resolve = []		# list of (essid, WI) tuples
 
 def parse_wleiden_conf(lines):
-	ipnr = None
+	essid = None
 	wi = None
-	peer = None
-	omni = 0
+	wis = []
 	for l in lines:
 		if wi != None:
-			match = re.match("^\EW.*", l)
-			if match != None:
+			match = re.match("^MODE=master.*", l)
+			if match != None:
+				master = 1
+			match = re.match("^ESSID=(.*)", l)
+			if match != None:
+				essid = match.group(1)
+			match = re.match("^EW[0-9]*", l)
+			if match != None:
+				if master == 1:
+					group = WIGroup(essid)
+					groups[essid] = group
+					group.add_wi(wi)
+				else:
+					# defer, may come way later
+					to_resolve.append( (essid, wi) )
+				master = 0
 				wi = None
-				ipnr = None
-				peer = None
-				continue
-			match = re.match("^SDESC=omni.*", l)
-			if match != None:
-				omni = 1
-			match = re.match("^IP=([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*).*", l)
-			if match != None:
-				ipnr = match.group(1)
-				if not node_ipnr.has_key(nodename):
-					node_ipnr[nodename] = []
-				node_ipnr[nodename].append(ipnr)
-				ipnr_node[ipnr] = nodename
-			match = re.match("^POINT_TO_POINT=([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*).*", l)
-			if match != None:
-				peer = match.group(1)
-				if not node_links.has_key(nodename):
-					node_links[nodename] = []
-				node_links[nodename].append( (peer, wi) )
+				essid = None
 		else:
 			match = re.match("^\$nodename='([^']*)';.*", l)
 			if match != None:
 				nodename = match.group(1).lower()
+			match = re.match("^\$config{'wi[0-9]*:[0-9].*", l)
+			if match != None:
+				continue
 			match = re.match("^\$config{'(wi[0-9]*).*", l)
 			if match != None:
-				wi = match.group(1)
-				omni = 0
+				wi = WI(match.group(1))
+				wis.append(wi)
+				master = 0
+	node = Node(nodename, wis)
+	nodes[nodename] = node
 
 # gegeven een file met filenames van wleiden.conf's, parseer ze allemaal en
@@ -190,57 +195,11 @@
 	for fname in open(filename).readlines():
 		parse_wleiden_conf(open(fname[:-1]).readlines())
-	for nodename in node_ipnr.keys():
-		wis = []
-		if node_links.has_key(nodename):
-			d = {}
-			for peer, wi in node_links[nodename]:
-				if not d.has_key(wi):
-					wis.append(WI(wi))
-					d[wi] = 1
-		node = Node(nodename, wis)
-		nodes[nodename] = node
-
-	for nodename in node_links.keys():
-		node = nodes[nodename]
-
-		for peerip, winame in node_links[nodename]:
-			wi = node.wi_byname(winame)
-			if not ipnr_node.has_key(peerip):
-				print "Warning: node %s links to phantom IP %s" % (nodename, peerip)
-				continue
-			peername = ipnr_node[peerip]
-			bail = 0
-			for peerspeerip, peerswiname in node_links[peername]:
-				if not ipnr_node.has_key(peerspeerip):
-					print "Warning: node %s links to phantom IP %s" % (nodename, peerspeerip)
-					bail = 1
-					break
-				if ipnr_node[peerspeerip] == nodename:
-					break
-			if bail:
-				continue
-			peer = nodes[peername]
-			peerwi = peer.wi_byname(peerswiname)
-			# komt wi voor deze node al voor in de bestaande
-			# groepen?
-			group = None
-			for i in range(len(groups)):
-				if filter(lambda wi: wi.node.name == nodename and wi.name == winame, groups[i].wis) != []:
-					group = groups[i]
-					break
-			if group == None:
-				for i in range(len(groups)):
-					if filter(lambda wi: wi.node.name == peername and wi.name == peerswiname, groups[i].wis) != []:
-						group = groups[i]
-						break
-				if group == None:
-					# nee. maak een groep en voeg beide
-					# endpoints toe
-					group = WIGroup("group%d" % len(groups))
-					group.add_wi(wi)
-					groups.append(group)
-			group.add_wi(peerwi)
-	for group in groups:
-		group.wis = uniq(group.wis)
+	for essid, wi in to_resolve:
+		if not groups.has_key(essid):
+			print "Warning: node %s, %s refers to unknown essid %s" % (wi.node.name, wi.name, essid)
+			continue
+		groups[essid].add_wi(wi)
+	for group in groups.values():
+		group.uniq()
 
 # END UGLY PARSING CODE
@@ -248,14 +207,17 @@
 def plot_configuration(conf, out):
 	out.write("digraph plot {\n")
-	for i in range(len(groups)):
-		out.write("group%s [label=\"%d\"]\n" % (i, conf[i]))
+	for essid in groups:
+		out.write("\"%s\" [label=\"%s\\n(%d)\"]\n" % (essid, essid, groups[essid].channel))
 	for nodename in nodes.keys():
 		for wi in nodes[nodename].wis:
 			if wi.group == None:
 				continue
-			out.write("%s -> %s\n" % (nodename, wi.group.name))
+			out.write("\"%s\" -> \"%s\"\n" % (nodename, wi.group.name))
 	out.write("}")
 
 parse_metafile('l')
+
+for essid in groups.keys():
+	print essid, map(lambda wi: wi.node.name, groups[essid].wis)
 
 for i in range(20):
@@ -267,9 +229,9 @@
 	for i in range(0, 9):
 		p = population[i].copy()
-		population[i].crossover(population[i + 10], random.randint(1, 4) * 2)
+		#population[i].crossover(population[i + 10], random.randint(1, 4) * 2)
 		population[i + 10] = p
 		population[i + 10].mutate(0.05)
 	population.sort(lambda a, b: cmp(b.score(), a.score()))
-print population[0].score()
+	print population[0].score(), map(lambda g: g.channel, groups.values())
 plot_configuration(population[0].conf, open("foo.dot", 'w'))
 os.system('neato -Gstart=foo -Goverlap=false/scale -Gsplines=true -Gsep=2 -Gratio=fill -Gnslimit=50.0 -Grotate=90 -Gsize="11,7.5" -Tps -o channelga.ps foo.dot')
