/// <summary> /// Initializes a new instance of the <see cref="OperationScheduler"/> class. /// </summary> private OperationScheduler(Configuration configuration) { this.Configuration = configuration; this.SchedulingPolicy = configuration.IsConcurrencyFuzzingEnabled ? SchedulingPolicy.Fuzzing : SchedulingPolicy.Systematic; this.ValueGenerator = new RandomValueGenerator(configuration); if (!configuration.UserExplicitlySetLivenessTemperatureThreshold && configuration.MaxFairSchedulingSteps > 0) { configuration.LivenessTemperatureThreshold = configuration.MaxFairSchedulingSteps / 2; } if (this.SchedulingPolicy is SchedulingPolicy.Systematic) { this.Strategy = SystematicStrategy.Create(configuration, this.ValueGenerator); if (this.Strategy is ReplayStrategy replayStrategy) { this.ReplayStrategy = replayStrategy; this.IsReplayingSchedule = true; } } else if (this.SchedulingPolicy is SchedulingPolicy.Fuzzing) { this.Strategy = FuzzingStrategy.Create(configuration, this.ValueGenerator); } }
/// <summary> /// Initializes a new instance of the <see cref="OperationScheduler"/> class. /// </summary> private OperationScheduler(SchedulingPolicy policy, IRandomValueGenerator valueGenerator, Configuration configuration) { this.Configuration = configuration; this.SchedulingPolicy = policy; this.ValueGenerator = valueGenerator; if (!configuration.UserExplicitlySetLivenessTemperatureThreshold && configuration.MaxFairSchedulingSteps > 0) { configuration.LivenessTemperatureThreshold = configuration.MaxFairSchedulingSteps / 2; } if (this.SchedulingPolicy is SchedulingPolicy.Systematic) { this.Strategy = SystematicStrategy.Create(configuration, this.ValueGenerator); if (this.Strategy is ReplayStrategy replayStrategy) { this.ReplayStrategy = replayStrategy; this.IsReplayingSchedule = true; } // Wrap the strategy inside a liveness checking strategy. if (this.Configuration.IsLivenessCheckingEnabled) { this.Strategy = new TemperatureCheckingStrategy(this.Configuration, this.Strategy as SystematicStrategy); } } else if (this.SchedulingPolicy is SchedulingPolicy.Fuzzing) { this.Strategy = FuzzingStrategy.Create(configuration, this.ValueGenerator); } }
public static IEnumerable <Tuple <int, int> > Explore <V, E>( this Graph <V, E> graph, int from, ExplorationStrategy strategy ) { var visited = new HashSet <int>(); var open = new Deque <int> { from }; while (!open.IsEmpty) { var current = strategy(open); visited.Add(current); foreach (var(_, index) in graph.EdgesFrom(current)) { yield return(new Tuple <int, int>(current, index)); if (!visited.Contains(index)) { open.Add(index); } } } }
/// <summary> /// Sets the specification engine. /// </summary> internal void SetSpecificationEngine(SpecificationEngine specificationEngine) { if (this.SchedulingPolicy is SchedulingPolicy.Systematic && this.Configuration.IsLivenessCheckingEnabled) { this.Strategy = new TemperatureCheckingStrategy(this.Configuration, specificationEngine, this.Strategy as SystematicStrategy); } }
/// <summary> /// Uses the local Multi-Armed-Bandits to explore the action space and uses the global Multi-Armed-Bandit to exploit the best performing actions. /// </summary> /// <param name="context">The current search context.</param> /// <param name="state">The game state for the node.</param> /// <param name="gMAB">The global Multi-Armed-Bandit.</param> /// <returns>An <see cref="A"/> that was selected from the global Multi-Armed-Bandit.</returns> private A NaïveSampling(SearchContext <D, P, A, S, Sol> context, P state, IDictionary <long, Dictionary <int, LocalArm> > gMAB) { var apply = context.Application; var stateClone = context.Cloner.Clone(state); var stateHash = stateClone.HashMethod(); if (!gMAB.ContainsKey(stateHash)) { gMAB.Add(stateHash, new Dictionary <int, LocalArm>()); } // Use a policy p_0 to determine whether to explore or exploit // If explore was selected // x_1...x_n is sampled by using a policy p_l to select a value for each X_i in X independently. // As a side effect, the resulting value combination is added to the global MAB. // If exploit was selected // x_1...x_n is sampled by using a policy p_g to select a value combination using MAB_g. // Can only exploit if there is anything to exploit in the first place if (gMAB[stateHash].IsNullOrEmpty() || ExplorationStrategy.Policy(context, 0)) { // Explore // Create an action according to policy p_1 var action = SamplingStrategy.Sample(stateClone); var actionHash = action.GetHashCode(); // Evaluate the sampled action var endState = PlayoutStrategy.Playout(context, apply.Apply(context, stateClone, action)); var tempNode = new TreeSearchNode <P, A> { Payload = action }; var reward = EvaluationStrategy.Evaluate(context, tempNode, endState); // Add the action to the global MAB if (gMAB[stateHash].ContainsKey(actionHash)) { gMAB[stateHash][actionHash].Visit(reward); } else { var newArm = new LocalArm(action); newArm.Visit(reward); gMAB[stateHash].Add(actionHash, newArm); } return(action); } // Exploit; epsilon-greedy by returning the action with the highest expected reward with probability 1-e, otherwise returning random. return(_rng.NextDouble() <= 1 - PolicyGlobal ? gMAB[stateHash].Values.OrderByDescending(i => i.ExpectedReward).First().Action : gMAB[stateHash].RandomElementOrDefault().Value.Action); }
public static IEnumerable <Tuple <int, int> > FindDepthsFrom <V, E>( this Graph <V, E> graph, int origin, ExplorationStrategy strategy ) { var result = new Dictionary <int, int> { [origin] = 0 }; foreach (var(from, to) in graph.Explore(origin, strategy)) { result[to] = result[from] + 1; } return(result.Select(pair => new Tuple <int, int>(pair.Key, pair.Value))); }
/// <summary> /// Initializes a new instance of the <see cref="OperationScheduler"/> class. /// </summary> private OperationScheduler(Configuration configuration, SchedulingPolicy policy, IRandomValueGenerator generator) { this.Configuration = configuration; this.SchedulingPolicy = policy; this.ValueGenerator = generator; this.Reducers = new List <IScheduleReducer>(); if (configuration.IsSharedStateReductionEnabled) { this.Reducers.Add(new SharedStateReducer()); } if (!configuration.UserExplicitlySetLivenessTemperatureThreshold && configuration.MaxFairSchedulingSteps > 0) { configuration.LivenessTemperatureThreshold = configuration.MaxFairSchedulingSteps / 2; } if (this.SchedulingPolicy is SchedulingPolicy.Interleaving) { this.Strategy = InterleavingStrategy.Create(configuration, generator); if (this.Strategy is ReplayStrategy replayStrategy) { this.ReplayStrategy = replayStrategy; this.IsReplayingSchedule = true; } // Wrap the strategy inside a liveness checking strategy. if (configuration.IsLivenessCheckingEnabled) { this.Strategy = new TemperatureCheckingStrategy(configuration, generator, this.Strategy as InterleavingStrategy); } } else if (this.SchedulingPolicy is SchedulingPolicy.Fuzzing) { this.Strategy = FuzzingStrategy.Create(configuration, generator); } }
// To be used when RelaxedConcurrencyTesting is enabled. public void SetSchedulerStrategyToDelayFuzzing() { this.SchedulingPolicy = SchedulingPolicy.Fuzzing; this.Strategy = FuzzingStrategy.Create(this.Configuration, this.ValueGenerator); }