Changeset 1991 in genesis
- Timestamp:
- Apr 12, 2004, 12:43:03 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/channelga.ml
r1990 r1991 16 16 can see eachother, so they should be apart) 17 17 18 special cases: 19 - on node x, interfaces y and z are well separated and can live on the 20 same channel 21 - interface x on node y will bother interface z on node w and need to 22 be on separate channels 23 - on node x, channels y, z and w are not usable 24 - node x y and z should be treated as one node 25 - if at all possible, do not put accesspoints above channel 11 26 18 27 - install an O'Caml compiler. /usr/ports/lang/ocaml/ in FreeBSD, ocaml in 19 28 Debian. … … 33 42 (* a few constants suitable for twiddling *) 34 43 (** How large a population should the system maintain? *) 35 let population_size = 10044 let population_size = 20 36 45 (** How long should the system iterate after an improvement? *) 37 and max_stagnant_iterations = 1000046 and max_stagnant_iterations = 2000 38 47 (** What is the chance for an ESSID to channel assignment to mutate to a 39 48 random channel? *) … … 69 78 (** The global groups hash, mapping from essid to group struct. *) 70 79 let groups = Hashtbl.create 4 80 81 let nointerference = Hashtbl.create 4 82 let unusable = Hashtbl.create 4 83 let interference = [] 84 85 let scoretable = [ ((<=) 2, 1); 86 ((==) 2, -30); 87 ((==) 1, -70); 88 ((==) 0, -100) ] 89 let rec runtable t diff = 90 match t with 91 [] -> assert false 92 | (cond, s)::xs -> if (cond diff) then s 93 else runtable xs diff 71 94 72 95 (* some convenience functions *) … … 91 114 let copyarray src dest = Array.blit src 0 dest 0 (Array.length src) 92 115 116 let in_list l i = try 117 let _ = List.find ((==) i) l in 118 true 119 with Not_found -> false 120 93 121 (** Given a list, return a list of pairs with all possible combinations of 94 122 items from the given list *) … … 99 127 100 128 (** Given a configuration and two wi's, return the score *) 101 let wi_score c wi1 wi2 = 102 let scoretable = [ ((<=) 2, 1); 103 ((==) 2, -1); 104 ((==) 1, -5); 105 ((==) 0, -10) ] in 129 let wi_score c unusable nointerference wi1 wi2 = 106 130 let channel1 = c wi1.wi_essid in 107 131 let channel2 = c wi2.wi_essid in 108 132 let diff = abs (channel1 - channel2) in 109 let rec runtable t = match t with 110 [] -> assert false 111 | (cond, s)::xs -> if (cond diff) then s 112 else runtable xs in 113 runtable scoretable;; 133 let is_unusable = in_list unusable in 134 if (is_unusable channel1) || (is_unusable channel2) then -10000 135 else if in_list nointerference (maketuple wi1 wi2) then 1 136 else runtable scoretable diff;; 114 137 115 138 (** Given a configuration and a node, return the score. this is simply the sum of … … 117 140 efficiency *) 118 141 let node_score c n = 119 let foldfunc acc (wi1, wi2) = acc + (wi_score c wi1 wi2) in 142 let nointerference_ = try Hashtbl.find nointerference n.node_name 143 with Not_found -> [] in 144 let unusable_ = try Hashtbl.find unusable n.node_name 145 with Not_found -> [] in 146 let foldfunc acc (wi1, wi2) = acc + (wi_score c unusable_ nointerference_ wi1 wi2) in 120 147 let base_score = List.fold_left foldfunc 0 (combinations n.node_wis) in 121 148 base_score * (List.length n.node_wis) 149 150 let test_interference c (wi1, wi2) = 151 let channel1 = c wi1.wi_essid in 152 let channel2 = c wi2.wi_essid in 153 let diff = abs (channel1 - channel2) in 154 runtable scoretable diff 122 155 123 156 (** Given a list of nodes and a configuration, return the score for the whole 124 157 configuration. This is the sum of the scores for all nodes. *) 125 158 let score_configuration ns c = 126 let foldfunc acc n = acc + (node_score (Hashtbl.find c) n) in 159 let mapper = Hashtbl.find c in 160 let foldfunc acc n = acc + (node_score mapper n) in 127 161 let nodescores = List.fold_left foldfunc 0 ns in 128 nodescores 162 let interference_penalty = List.fold_left (fun a i -> a + test_interference mapper i) 0 interference in 163 nodescores + interference_penalty;; 129 164 130 165 (** Given a filename, return a list of all the lines in the file with the given 131 filename *)166 filename. Don't count on the order of the lines in the result. *) 132 167 let snarf_lines fname = 133 168 let infile = open_in fname in
Note:
See TracChangeset
for help on using the changeset viewer.