Skip to content
Snippets Groups Projects
Commit 1ff0fa2b authored by erwan's avatar erwan
Browse files

fix: the mutant generation was wrong

parent fa338e34
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 06/04/2022 (at 15:39) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/04/2022 (at 17:20) by Erwan Jahier> *)
open Register
......@@ -10,32 +10,46 @@ let debug = false
type distance = Far | Close
let mutate_value distance = function
| F (minf,f,maxf) ->
let deltaf = match distance with
| Far -> (maxf-.minf)
| Close -> (maxf-.minf) /. 100.
in
let nf =
if minf > f -. deltaf then
minf+.(Random.float (2.0 *. deltaf))
else if maxf < f +. deltaf then
maxf -. (Random.float (2.0 *. deltaf))
else
f+.(Random.float (2.0 *. deltaf)) -. deltaf
let nf = match distance with
| Far -> Random.float (maxf-.minf) +. minf
| Close ->
let delta = Random.float (maxf-.minf)/.100. -. (maxf-.minf)/.200. in
if f+.delta<minf || f+.delta>maxf then f-.delta else f+.delta
in
F(minf, nf, maxf)
| I (mini,i,maxi) ->
let deltai = match distance with
| Far -> (maxi - mini) / 2
| Close -> ((maxi - mini) / 100)
in
let deltai = 1+Random.int (max 1 deltai) in
let ni = if i=mini then i+deltai else if i=maxi then i-deltai else
if Random.bool () then i+deltai else i-deltai
assert (mini<maxi);
let ni = match distance with
| Far ->
let ni = Random.int(maxi-mini) + mini in
if ni = i then maxi else ni
| Close ->
if i=mini then i+1 else if i=maxi then i-1 else
if Random.bool () then i+1 else i-1
in
I (mini,ni,maxi)
| B b -> B (not b)
| B b -> B (not b)
(*
in order to test the distribution of the mutants
let a = Array.make 10 0 in
let p = ref (I (3, 4, 6)) in
for i=1 to 100000 do
p:=mutate_value Far !p;
match !p with I(_,i,_) -> a.(i) <-a.(i)+1;
done;
a;;
let a = Array.make 10 0 in
let p = ref (F (3., 4., 6.)) in
for i=1 to 100000 do
p:=mutate_value Far !p;
match !p with F(_,f,_) -> a.(int_of_float f) <-a.(int_of_float f)+1;
done;
a;;
*)
let one_dim_succ d n =
let p = Array.copy n in
let j = Random.int (Array.length p) in
......@@ -176,6 +190,7 @@ let (fchc : out_channel -> ('v SimuState.t -> int) -> 'v SimuState.t -> int
let cost p = run (point_to_ss p ss_init) in
let pinit = ss_to_point ss_init in
let percent_done = ref 0 in
Functory.Cores.set_number_of_cores ss_init.sasarg.cores_nb;
let g =
{
init = ({ st = pinit ; d = 0 ; cost = cost pinit ; cpt = 0 }, Q.empty, ());
......
(* Time-stamp: <modified the 12/10/2021 (at 15:42) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/04/2022 (at 17:17) by Erwan Jahier> *)
(* This is algo 3.1 in the book *)
open Algo
......@@ -16,6 +16,7 @@ let (colors : 'v neighbor list -> 'v list) = fun nl ->
nb: suppose that all states are in [0;k-1]
*)
let (free : 'v neighbor list -> 'v list) = fun nl ->
assert (List.for_all (fun n -> state n < k) nl); (* all colors should be < k *)
let comp_neg x y = - (compare x y) in
let n_colors = List.map (fun n -> state n) nl in (* neighbor colors *)
let n_colors = (* neighbor colors, no duplicate, in descending order *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment