public JScriptAssertion(string expression, string[] assemblyNames, string[] imports) { if (string.IsNullOrEmpty(expression) || expression.TrimStart().Length == 0) { return; } ProcessDirectives(expression, ref assemblyNames, ref imports); var engine = VsaEngine.CreateEngineAndGetGlobalScope(/* fast */ false, assemblyNames ?? new string[0]).engine; if (imports != null && imports.Length > 0) { foreach (var import in imports) { Import.JScriptImport(import, engine); } } // // We pick on of two expression evaluation strategies depending // on the level of trust available. The full trust version is // faster as it compiles the expression once into a JScript // function and then simply invokes at the time it needs to // evaluate the context. The partial trust strategy is slower // as it compiles the expression each time an evaluation occurs // using the JScript eval. // _evaluationStrategy = FullTrustEvaluationStrategy.IsApplicable() ? (EvaluationStrategy) new FullTrustEvaluationStrategy(expression, engine) : new PartialTrustEvaluationStrategy(expression, engine); }
private void ParseEvaluationStrategyEnum() { string sPattern2 = @".*EVALUATE USING\s*\((?<strategyClause>.*)\)"; Match match2 = Regex.Match(_sql, sPattern2, RegexOptions.IgnoreCase); if (match2.Success) { _strategyClause = match2.Groups["strategyClause"].Value; } switch (_strategyClause.ToLower()) { case "monte carlo": _strategy = EvaluationStrategy.MonteCarlo; break; case "naive": _strategy = EvaluationStrategy.Naive; break; case "lazy": _strategy = EvaluationStrategy.Lazy; break; case "extensional": _strategy = EvaluationStrategy.Extensional; break; default: _strategy = EvaluationStrategy.Default; break; } }
public ColorExpression(int pixelIndex, Color targetColor, int priority, int tolerance, EvaluationStrategy strategy) { TargetColor = targetColor; PixelIndex = pixelIndex; Priority = priority; Tolerance = tolerance; Strategy = strategy; }
/// <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 JScriptAssertion(string expression, string[] assemblyNames, string[] imports) { if (expression == null || expression.Length == 0 || expression.TrimStart().Length == 0) { return; } ProcessDirectives(expression, ref assemblyNames, ref imports); VsaEngine engine = VsaEngine.CreateEngineAndGetGlobalScope(/* fast */ false, assemblyNames != null ? assemblyNames : new string[0]).engine; if (imports != null && imports.Length > 0) { foreach (string import in imports) Import.JScriptImport(import, engine); } // // We pick on of two expression evaluation strategies depending // on the level of trust available. The full trust version is // faster as it compiles the expression once into a JScript // function and then simply invokes at the time it needs to // evaluate the context. The partial trust strategy is slower // as it compiles the expression each time an evaluation occurs // using the JScript eval. // _evaluationStrategy = FullTrustEvaluationStrategy.IsApplicable() ? (EvaluationStrategy) new FullTrustEvaluationStrategy(expression, engine) : new PartialTrustEvaluationStrategy(expression, engine); }
private void ParseEvaluationStrategyEnum() { string sPattern2 = @".*EVALUATE USING\s*\((?<strategyClause>.*)\)"; Match match2 = Regex.Match(_sql, sPattern2, RegexOptions.IgnoreCase); if (match2.Success) { _strategyClause = match2.Groups["strategyClause"].Value; } switch (_strategyClause.ToLower()){ case "monte carlo": _strategy = EvaluationStrategy.MonteCarlo; break; case "naive": _strategy = EvaluationStrategy.Naive; break; case "lazy": _strategy = EvaluationStrategy.Lazy; break; case "extensional": _strategy = EvaluationStrategy.Extensional; break; default: _strategy = EvaluationStrategy.Default; break; } }
public RomanNumeral(int number, EvaluationStrategy strategy) { Number = number; Text = strategy.Evaluate(number); }