Changeset 1937 in genesis
- Timestamp:
- Mar 28, 2004, 11:20:44 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/channelga.py
r1936 r1937 1 # experiment met e en genetisch algoritmevoor de kanalenplanning1 # experiment met evolutionary programming voor de kanalenplanning 2 2 # het genetische zit er nu nauwelijks in, en wat er in zit is ongetwijfeld 3 3 # fout. wat er wel goed in zit is het parseren van de bestaande situatie en … … 38 38 return d.keys() 39 39 40 def multiget(d, ks):41 return map(lambda k: d[k], ks)42 43 40 class Node: 44 41 def __init__(self, name, wis): 45 42 self.name = name 46 43 self.wis = wis 44 self.special = {} 47 45 for wi in wis: 48 46 wi.setNode(self) … … 70 68 else: 71 69 score = score - 10 70 if self.special.has_key(wi_i.group.channel): 71 score = score + self.special[wi_i.group.channel] 72 72 score = score * len(self.wis) 73 73 return score 74 74 def setSpecialScoreForChannels(self, score, channels): 75 for c in channels: 76 self.special[c] = score 77 78 # een supernode is een verzameling subnodes, bv cetim1, cetim2 en cetim3. 75 79 class SuperNode(Node): 76 80 def __init__(self, name, nodes): … … 78 82 self.nodes = nodes 79 83 self.wis = [] 84 self.special = {} 80 85 for n in nodes: 81 86 self.wis.extend(n.wis) … … 103 108 self.wis = uniq(self.wis) 104 109 110 # een configuratie is een bepaalde bedeling van kanalen aan groepen. aangezien 111 # groepen keyed zijn op essid is de concrete configuratie hier een dict van 112 # essids naar kanalen. 105 113 class Configuration: 106 114 def __init__(self): … … 137 145 points = [random.randint(0, len(essids) - 1) for i in range(numpoints)] 138 146 points.sort() 139 conf = []147 conf = {} 140 148 who = 0 141 149 lastpoint = 0 … … 143 151 point = points.pop(0) 144 152 if who == 0: 145 l = self.conf[lastpoint:point]153 d = self.conf 146 154 else: 147 l = partner.conf[lastpoint:point]155 d = partner.conf 148 156 who = 1 - who 149 conf.extend(l) 157 for i in range(lastpoint, point + 1): 158 conf[essids[i]] = d[essids[i]] 150 159 lastpoint = point 151 160 if who == 0: 152 l = self.conf[lastpoint:]161 d = self.conf 153 162 else: 154 l = partner.conf[lastpoint:] 155 conf.extend(l) 163 d = partner.conf 164 for i in range(lastpoint, len(essids)): 165 conf[essids[i]] = d[essids[i]] 156 166 assert len(conf) == len(groups) 157 167 self.conf = conf … … 230 240 pass 231 241 242 def parse_special(filename): 243 for line in open(filename).readlines(): 244 fields = line[:-1].split(' ') 245 nodename = fields[0] 246 score = int(fields[1]) 247 channels = map(lambda c: int(c), fields[2:]) 248 nodes[nodename].setSpecialScoreForChannels(score, channels) 249 232 250 # END UGLY PARSING CODE 233 251 … … 235 253 out.write("digraph plot {\n") 236 254 for essid in groups: 237 out.write("\"%s\" [ label=\"%s\\n(%d)\"]\n" % (essid, essid, conf[essid]))255 out.write("\"%s\" [shape=box label=\"%s\\n(%d)\"]\n" % (essid, essid, conf[essid])) 238 256 for nodename in nodes.keys(): 239 257 for wi in nodes[nodename].wis: … … 245 263 parse_metafile('l') 246 264 parse_coupled('coupled.conf') 265 parse_special('special.conf') 247 266 248 267 for essid in groups.keys():
Note:
See TracChangeset
for help on using the changeset viewer.