-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathCombinedWeighter.fs
More file actions
42 lines (34 loc) · 1.53 KB
/
CombinedWeighter.fs
File metadata and controls
42 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace VSharp.Interpreter.IL
open System
open VSharp.Interpreter.IL
open VSharp.Interpreter.IL.TypeUtils
/// <summary>
/// Combines two weighters using the given combinator function.
/// </summary>
type internal CombinedWeighter(one : IWeighter, another : IWeighter, combinator : uint option -> uint option -> uint option) =
interface IWeighter with
override x.Weight(state) =
let oneWeight = one.Weight state
let anotherWeight = another.Weight state
combinator oneWeight anotherWeight
type internal AugmentedWeighter(baseWeighter : IWeighter, mapping : uint option -> uint option) =
interface IWeighter with
override x.Weight(state) = baseWeighter.Weight state |> mapping
module internal WeightOperations =
let withInverseLinearFallback bound (one : uint option) (another : uint option) =
match one, another with
| (None | Some 0u), Some anotherWeight ->
let fallbackWeight = max 0 (int bound - int anotherWeight)
Some(uint fallbackWeight)
| Some oneWeight, _ -> Some(bound + oneWeight)
| None, None -> None
let inverseLogarithmic (maxValuePower : uint) (weight : uint option) =
match weight with
| None -> None
| Some weight ->
let log =
match weight with
| 0u -> 0.0
| _ -> Math.Log2 (float weight)
let newWeight = Math.Pow(2.0, float maxValuePower - 5.0) * (32.0 - log)
newWeight |> Math.Floor |> uint |> Some