- Timestamp:
- Mar 28, 2004, 10:17:28 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/channelga.py
r1935 r1936 3 3 # fout. wat er wel goed in zit is het parseren van de bestaande situatie en 4 4 # het scoren van (nu random) configuraties. 5 5 # 6 6 # de score functie is nu redelijk simplistisch: 7 7 # - de score van een combinatie van twee interfaces op een node is 1 als er 8 # twee of meer kanalen tussen zitten, en -1 als dat niet zo is 8 # twee of meer kanalen tussen zitten, en -1 als er 1 kanaal tussen zit, -5 9 # als er geen kanaal tussen zit en -10 als de kanalen hetzelfde zijn 9 10 # - de score van een node is de som van de scores van alle combinaties van 10 11 # interfaces van die node, maal het aantal interfaces. dat laatste omdat … … 18 19 # recombination gebeuren op de oplossing zelf ipv op een bitstring 19 20 # representatie. selection is dom en neemt gewoon de helft beste oplossingen. 21 # 22 # lvoge@cs.vu.nl 20 23 import re 21 24 import random … … 44 47 for wi in wis: 45 48 wi.setNode(self) 46 def wi_byname(self, name):47 wi = filter(lambda wi: wi.name == name, self.wis)48 assert len(wi) == 149 return wi[0]50 49 def score(self): 51 50 score = 0 … … 65 64 if diff > 2: 66 65 score = score + 1 66 elif diff == 2: 67 score = score - 1 68 elif diff == 1: 69 score = score - 5 67 70 else: 68 score = score - 1 71 score = score - 10 69 72 score = score * len(self.wis) 70 73 return score 74 75 class SuperNode(Node): 76 def __init__(self, name, nodes): 77 self.name = name 78 self.nodes = nodes 79 self.wis = [] 80 for n in nodes: 81 self.wis.extend(n.wis) 71 82 72 83 class WI: … … 203 214 group.uniq() 204 215 216 def parse_coupled(filename): 217 try: 218 for line in open(filename).readlines(): 219 supername, rest = line[:-1].split(':') 220 subnodes = [] 221 for nodename in rest.split(' '): 222 if nodename == '': 223 continue 224 node = nodes[nodename] 225 del nodes[nodename] 226 subnodes.append(node) 227 node = SuperNode(supername, subnodes) 228 nodes[supername] = node 229 except: 230 pass 231 205 232 # END UGLY PARSING CODE 206 233 … … 208 235 out.write("digraph plot {\n") 209 236 for essid in groups: 210 out.write("\"%s\" [label=\"%s\\n(%d)\"]\n" % (essid, essid, groups[essid].channel))237 out.write("\"%s\" [label=\"%s\\n(%d)\"]\n" % (essid, essid, conf[essid])) 211 238 for nodename in nodes.keys(): 212 239 for wi in nodes[nodename].wis: … … 217 244 218 245 parse_metafile('l') 246 parse_coupled('coupled.conf') 219 247 220 248 for essid in groups.keys(): … … 226 254 population.append(conf) 227 255 228 for iteration in range(1000): 256 last_high_score = -10000000 257 iterations_since_new_high_score = 0 258 while iterations_since_new_high_score < 1000: 229 259 for i in range(0, 9): 230 260 p = population[i].copy() … … 233 263 population[i + 10].mutate(0.05) 234 264 population.sort(lambda a, b: cmp(b.score(), a.score())) 235 print population[0].score(), map(lambda g: g.channel, groups.values()) 265 high_score = population[0].score() 266 if high_score > last_high_score: 267 last_high_score = high_score 268 iterations_since_new_high_score = 0 269 iterations_since_new_high_score = iterations_since_new_high_score + 1 270 print high_score 236 271 plot_configuration(population[0].conf, open("foo.dot", 'w')) 237 272 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')
Note:
See TracChangeset
for help on using the changeset viewer.