Changeset 1991 in genesis


Ignore:
Timestamp:
Apr 12, 2004, 12:43:03 AM (21 years ago)
Author:
lodewijk
Message:
  • ondersteuning voor de speciale gevallen in de functies gezet. het wordt nog niet geparseerd.
  • de verschillende knobs en bobs wat getweaked zodat het sneller gaat.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/channelga.ml

    r1990 r1991  
    1616      can see eachother, so they should be apart)
    1717
     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
    1827 - install an O'Caml compiler. /usr/ports/lang/ocaml/ in FreeBSD, ocaml in
    1928   Debian.
     
    3342(* a few constants suitable for twiddling *)
    3443(** How large a population should the system maintain? *)
    35 let population_size = 100
     44let population_size = 20
    3645(** How long should the system iterate after an improvement? *)
    37 and max_stagnant_iterations = 10000
     46and max_stagnant_iterations = 2000
    3847(** What is the chance for an ESSID to channel assignment to mutate to a
    3948    random channel? *)
     
    6978(** The global groups hash, mapping from essid to group struct. *)
    7079let groups = Hashtbl.create 4
     80
     81let nointerference = Hashtbl.create 4
     82let unusable = Hashtbl.create 4
     83let interference = []
     84
     85let scoretable = [ ((<=) 2,  1);
     86                   ((==) 2, -30);
     87                   ((==) 1, -70);
     88                   ((==) 0, -100) ]
     89let 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
    7194
    7295(* some convenience functions *)
     
    91114let copyarray src dest = Array.blit src 0 dest 0 (Array.length src)
    92115
     116let in_list l i = try
     117                        let _ = List.find ((==) i) l in
     118                        true
     119                  with Not_found -> false
     120
    93121(** Given a list, return a list of pairs with all possible combinations of
    94122   items from the given list *)
     
    99127
    100128(** 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
     129let wi_score c unusable nointerference wi1 wi2 =
    106130        let channel1 = c wi1.wi_essid in
    107131        let channel2 = c wi2.wi_essid in
    108132        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;;
    114137
    115138(** Given a configuration and a node, return the score. this is simply the sum of
     
    117140   efficiency *)
    118141let 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
    120147        let base_score = List.fold_left foldfunc 0 (combinations n.node_wis) in
    121148        base_score * (List.length n.node_wis)
     149
     150let 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
    122155
    123156(** Given a list of nodes and a configuration, return the score for the whole
    124157    configuration. This is the sum of the scores for all nodes. *)
    125158let 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
    127161        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;;
    129164
    130165(** 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. *)
    132167let snarf_lines fname =
    133168        let infile = open_in fname in
Note: See TracChangeset for help on using the changeset viewer.