Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReplayStrategy"/> class.
 /// </summary>
 internal ReplayStrategy(Configuration configuration, IRandomValueGenerator generator,
                         ScheduleTrace trace, bool isFair)
     : base(configuration, generator, isFair)
 {
     this.ScheduleTrace = trace;
     this.ErrorText     = string.Empty;
 }
Example #2
0
 public GrowingTreeAlgorithm(IRandomPointGenerator randomPointGenerator, IRandomValueGenerator randomValueGenerator, IDirectionsFlagParser directionsFlagParser, IArrayHelper arrayHelper)
 {
     _randomPointGenerator = randomPointGenerator;
     _randomValueGenerator = randomValueGenerator;
     _directionsFlagParser = directionsFlagParser;
     _arrayHelper          = arrayHelper;
 }
 public FutureSymbolGenerator(RandomDataGeneratorSettings settings, IRandomValueGenerator random)
     : base(settings, random)
 {
     _minExpiry = settings.Start;
     _maxExpiry = settings.End;
     _market    = settings.Market;
 }
Example #4
0
        /// <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);
            }
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComboStrategy"/> class.
 /// </summary>
 internal ComboStrategy(Configuration configuration, IRandomValueGenerator generator,
                        InterleavingStrategy prefixStrategy, InterleavingStrategy suffixStrategy)
     : base(configuration, generator, suffixStrategy.IsFair)
 {
     this.PrefixStrategy = prefixStrategy;
     this.SuffixStrategy = suffixStrategy;
 }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlledRuntime"/> class.
        /// </summary>
        internal ControlledRuntime(Configuration configuration, ISchedulingStrategy strategy,
                                   IRandomValueGenerator valueGenerator)
            : base(configuration, valueGenerator)
        {
            IsExecutionControlled = true;

            this.RootTaskId         = Task.CurrentId;
            this.NameValueToActorId = new ConcurrentDictionary <string, ActorId>();

            this.CoverageInfo = new CoverageInfo();

            var scheduleTrace = new ScheduleTrace();

            if (configuration.IsLivenessCheckingEnabled)
            {
                strategy = new TemperatureCheckingStrategy(configuration, this.Monitors, strategy);
            }

            this.Scheduler      = new OperationScheduler(this, strategy, scheduleTrace, this.Configuration);
            this.TaskController = new TaskController(this, this.Scheduler);

            // Update the current asynchronous control flow with this runtime instance,
            // allowing future retrieval in the same asynchronous call stack.
            AssignAsyncControlFlowRuntime(this);
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrioritizationStrategy"/> class.
 /// </summary>
 internal PrioritizationStrategy(Configuration configuration, IRandomValueGenerator generator)
     : base(configuration, generator, false)
 {
     this.PriorityChangePoints   = configuration.StrategyBound;
     this.HighPrioritySet        = new List <Guid>();
     this.LowPrioritySet         = new List <Guid>();
     this.LowPriorityProbability = 0;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoyoteRuntime"/> class.
 /// </summary>
 protected CoyoteRuntime(Configuration configuration, IRandomValueGenerator valueGenerator)
 {
     this.Configuration      = configuration;
     this.Monitors           = new List <Monitor>();
     this.ValueGenerator     = valueGenerator;
     this.OperationIdCounter = 0;
     this.IsRunning          = true;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExplorationStrategy"/> class.
 /// </summary>
 protected ExplorationStrategy(Configuration configuration, IRandomValueGenerator generator, bool isFair)
 {
     this.Configuration        = configuration;
     this.RandomValueGenerator = generator;
     this.MaxSteps             = isFair ? configuration.MaxFairSchedulingSteps : configuration.MaxUnfairSchedulingSteps;
     this.StepCount            = 0;
     this.IsFair = isFair;
 }
 public void Setup()
 {
     _random           = new RandomValueGenerator();
     _mazePointFactory = new Mock <IMazePointFactory>();
     _mazePointFactory.Setup(x => x.MakePoint(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
     .Returns((int x, int y, int z) => new MazePoint(x, y, z));
     _randomPoint = new RandomPointGenerator(_random, _mazePointFactory.Object);
 }
Example #11
0
 /// <summary>
 /// Base constructor implementation for Symbol generator
 /// </summary>
 /// <param name="settings">random data generation run settings</param>
 /// <param name="random">produces random values for use in random data generation</param>
 protected BaseSymbolGenerator(RandomDataGeneratorSettings settings, IRandomValueGenerator random)
 {
     Settings = settings;
     Random   = random;
     _symbols = new FixedSizeHashQueue <Symbol>(1000);
     SymbolPropertiesDatabase = SymbolPropertiesDatabase.FromDataFolder();
     MarketHoursDatabase      = MarketHoursDatabase.FromDataFolder();
 }
    public ActionResult Create()
    {
        IRandomValueGenerator generator = RandomValueGeneratorFactory.GetGenerator();
        int value = generator.GenerateRandomValue();

        // Do other stuff
        return(View(...));
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrioritizationStrategy"/> class.
 /// </summary>
 internal PrioritizationStrategy(Configuration configuration, IRandomValueGenerator generator)
     : base(configuration, generator, false)
 {
     this.PrioritizedOperationGroups = new List <OperationGroup>();
     this.PriorityChangePoints       = new HashSet <int>();
     this.NumPriorityChangePoints    = 0;
     this.MaxPriorityChangePoints    = 0;
     this.MaxPriorityChanges         = configuration.StrategyBound;
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PCTStrategy"/> class.
 /// </summary>
 internal PCTStrategy(int maxDelays, IRandomValueGenerator random, int priorityChangePoints)
 {
     this.RandomValueGenerator   = random;
     this.MaxSteps               = maxDelays;
     this.PriorityChangePoints   = priorityChangePoints;
     this.HighPrioritySet        = new List <Guid>();
     this.LowPrioritySet         = new List <Guid>();
     this.LowPriorityProbability = 0;
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DFSStrategy"/> class.
 /// </summary>
 internal DFSStrategy(Configuration configuration, IRandomValueGenerator generator)
     : base(configuration, generator, false)
 {
     this.SchIndex        = 0;
     this.NondetIndex     = 0;
     this.ScheduleStack   = new List <List <SChoice> >();
     this.BoolNondetStack = new List <List <NondetBooleanChoice> >();
     this.IntNondetStack  = new List <List <NondetIntegerChoice> >();
 }
 public OptionSymbolGenerator(RandomDataGeneratorSettings settings, IRandomValueGenerator random, decimal underlyingPrice, decimal maximumStrikePriceDeviation)
     : base(settings, random)
 {
     _minExpiry                   = settings.Start;
     _maxExpiry                   = settings.End;
     _market                      = settings.Market;
     _underlyingPrice             = underlyingPrice;
     _symbolChainSize             = settings.ChainSymbolCount;
     _maximumStrikePriceDeviation = maximumStrikePriceDeviation;
 }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PCTStrategy"/> class.
 /// </summary>
 public PCTStrategy(int maxSteps, int maxPrioritySwitchPoints, IRandomValueGenerator random)
 {
     this.RandomValueGenerator    = random;
     this.MaxScheduledSteps       = maxSteps;
     this.ScheduledSteps          = 0;
     this.ScheduleLength          = 0;
     this.MaxPrioritySwitchPoints = maxPrioritySwitchPoints;
     this.PrioritizedOperations   = new List <AsyncOperation>();
     this.PriorityChangePoints    = new HashSet <int>();
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PCTStrategy"/> class.
 /// </summary>
 internal PCTStrategy(int maxSteps, int maxPrioritySwitchPoints, IRandomValueGenerator generator)
 {
     this.RandomValueGenerator    = generator;
     this.MaxSteps                = maxSteps;
     this.StepCount               = 0;
     this.ScheduleLength          = 0;
     this.MaxPrioritySwitchPoints = maxPrioritySwitchPoints;
     this.PrioritizedOperations   = new List <AsyncOperation>();
     this.PriorityChangePoints    = new HashSet <int>();
 }
Example #19
0
        /// <summary>
        /// Creates a <see cref="FuzzingStrategy"/> from the specified configuration.
        /// </summary>
        internal static FuzzingStrategy Create(Configuration configuration, IRandomValueGenerator generator)
        {
            switch (configuration.SchedulingStrategy)
            {
            case "pct":
                return(new PCTStrategy(configuration.MaxUnfairSchedulingSteps, generator, configuration.StrategyBound));

            default:
                return(new BoundedRandomStrategy(configuration.MaxUnfairSchedulingSteps, generator));
            }
        }
Example #20
0
        /// <summary>
        /// Creates a <see cref="FuzzingStrategy"/> from the specified configuration.
        /// </summary>
        internal static FuzzingStrategy Create(Configuration configuration, IRandomValueGenerator generator)
        {
            switch (configuration.SchedulingStrategy)
            {
            case "prioritization":
                return(new PrioritizationStrategy(configuration, generator));

            default:
                // return new RandomStrategy(configuration, generator);
                return(new BoundedRandomStrategy(configuration, generator));
            }
        }
Example #21
0
        public Board(IRandomValueGenerator valueGenerator, int size)
        {
            _valueGenerator = valueGenerator;

            if (size <= 1)
            {
                throw new ArgumentException("Incorrect board size!");
            }

            _size  = size;
            _board = new BoardSquare[_size, _size];

            CreateBoardSquares();
        }
Example #22
0
        /// <summary>
        /// Creates a <see cref="SystematicStrategy"/> from the specified configuration.
        /// </summary>
        internal static SystematicStrategy Create(Configuration configuration, IRandomValueGenerator generator)
        {
            SystematicStrategy strategy = null;

            if (configuration.SchedulingStrategy is "replay")
            {
                strategy = new ReplayStrategy(configuration);
            }
            else if (configuration.SchedulingStrategy is "random")
            {
                strategy = new RandomStrategy(configuration.MaxFairSchedulingSteps, generator);
            }
            else if (configuration.SchedulingStrategy is "pct")
            {
                strategy = new PCTStrategy(configuration.MaxUnfairSchedulingSteps, configuration.StrategyBound, generator);
            }
            else if (configuration.SchedulingStrategy is "fairpct")
            {
                var prefixLength = configuration.SafetyPrefixBound is 0 ?
                                   configuration.MaxUnfairSchedulingSteps : configuration.SafetyPrefixBound;
                var prefixStrategy = new PCTStrategy(prefixLength, configuration.StrategyBound, generator);
                var suffixStrategy = new RandomStrategy(configuration.MaxFairSchedulingSteps, generator);
                strategy = new ComboStrategy(prefixStrategy, suffixStrategy);
            }
            else if (configuration.SchedulingStrategy is "probabilistic")
            {
                strategy = new ProbabilisticRandomStrategy(configuration.MaxFairSchedulingSteps,
                                                           configuration.StrategyBound, generator);
            }
            else if (configuration.SchedulingStrategy is "rl")
            {
                strategy = new QLearningStrategy(configuration.MaxUnfairSchedulingSteps, generator);
            }
            else if (configuration.SchedulingStrategy is "dfs")
            {
                strategy = new DFSStrategy(configuration.MaxUnfairSchedulingSteps);
            }

            if (configuration.SchedulingStrategy != "replay" &&
                configuration.ScheduleFile.Length > 0)
            {
                strategy = new ReplayStrategy(configuration, strategy);
            }

            return(strategy);
        }
Example #23
0
        public TickGenerator(RandomDataGeneratorSettings settings, TickType[] tickTypes, Security security, IRandomValueGenerator random)
        {
            _random    = random;
            _settings  = settings;
            _tickTypes = tickTypes;
            Security   = security;
            SymbolPropertiesDatabase = SymbolPropertiesDatabase.FromDataFolder();
            MarketHoursDatabase      = MarketHoursDatabase.FromDataFolder();

            if (Symbol.SecurityType.IsOption())
            {
                _priceGenerator = new OptionPriceModelPriceGenerator(security);
            }
            else
            {
                _priceGenerator = new RandomPriceGenerator(security, random);
            }
        }
Example #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlledRuntime"/> class.
        /// </summary>
        internal ControlledRuntime(Configuration configuration, ISchedulingStrategy strategy,
                                   IRandomValueGenerator valueGenerator)
            : base(configuration, valueGenerator)
        {
            IncrementExecutionControlledUseCount();

            this.RootTaskId         = Task.CurrentId;
            this.NameValueToActorId = new ConcurrentDictionary <string, ActorId>();

            this.CoverageInfo = new CoverageInfo();

            var scheduleTrace = new ScheduleTrace();

            if (configuration.IsLivenessCheckingEnabled)
            {
                strategy = new TemperatureCheckingStrategy(configuration, this.Monitors, strategy);
            }

            this.Scheduler      = new OperationScheduler(this, strategy, scheduleTrace, this.Configuration);
            this.TaskController = new TaskController(this, this.Scheduler);
        }
Example #25
0
        /// <summary>
        /// Creates a <see cref="InterleavingStrategy"/> from the specified configuration.
        /// </summary>
        internal static InterleavingStrategy Create(Configuration configuration, IRandomValueGenerator generator)
        {
            InterleavingStrategy strategy = null;
            if (configuration.SchedulingStrategy is "replay")
            {
                var trace = ScheduleTrace.Deserialize(configuration, out bool isFair);
                strategy = new ReplayStrategy(configuration, generator, trace, isFair);
            }
            else if (configuration.SchedulingStrategy is "random")
            {
                strategy = new RandomStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "prioritization")
            {
                strategy = new PrioritizationStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "fair-prioritization")
            {
                var prefixStrategy = new PrioritizationStrategy(configuration, generator);
                var suffixStrategy = new RandomStrategy(configuration, generator);
                strategy = new ComboStrategy(configuration, generator, prefixStrategy, suffixStrategy);
            }
            else if (configuration.SchedulingStrategy is "probabilistic")
            {
                strategy = new ProbabilisticRandomStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "rl")
            {
                strategy = new QLearningStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "dfs")
            {
                strategy = new DFSStrategy(configuration, generator);
            }

            return strategy;
        }
        private void LoadExternalRandomGenerators()
        {
            foreach (string file in Directory.EnumerateFiles(Directory.GetCurrentDirectory()))
            {
                try
                {
                    Assembly assembly      = Assembly.LoadFrom(file);
                    Type[]   exportedTypes = assembly.GetExportedTypes();

                    Type[] randomGeneraterTypes = Array.FindAll(exportedTypes,
                                                                x => typeof(IRandomValueGenerator).IsAssignableFrom(x) && !x.IsAbstract);

                    foreach (Type randomGeneratorType in randomGeneraterTypes)
                    {
                        IRandomValueGenerator randomValueGenerator = (IRandomValueGenerator)Activator.CreateInstance(randomGeneratorType);
                        _randomGenerators.Add(randomValueGenerator);
                    }
                }
                catch (Exception)
                {
                    //throw new PluginLoadException(e.Message);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProbabilisticRandomStrategy"/> class.
 /// </summary>
 internal ProbabilisticRandomStrategy(int maxSteps, int numberOfCoinFlips, IRandomValueGenerator generator)
     : base(maxSteps, generator)
 {
     this.NumberOfCoinFlips = numberOfCoinFlips;
 }
 public RandomPointGenerator(IRandomValueGenerator randomValueGenerator, IMazePointFactory mazePointFactory)
 {
     _randomValueGenerator = randomValueGenerator;
     _mazePointFactory     = mazePointFactory;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ActorUnitTestingRuntime"/> class.
        /// </summary>
        internal ActorUnitTestingRuntime(Configuration configuration, Type actorType, IRandomValueGenerator valueGenerator)
            : base(configuration, valueGenerator)
        {
            if (!actorType.IsSubclassOf(typeof(Actor)))
            {
                this.Assert(false, "Type '{0}' is not an actor.", actorType.FullName);
            }

            var id = new ActorId(actorType, null, this);

            this.Instance = ActorFactory.Create(actorType);
            IActorManager actorManager;

            if (this.Instance is StateMachine stateMachine)
            {
                actorManager = new StateMachineManager(this, stateMachine, Guid.Empty);
            }
            else
            {
                actorManager = new ActorManager(this, this.Instance, Guid.Empty);
            }

            this.ActorInbox = new EventQueue(actorManager);
            this.Instance.Configure(this, id, actorManager, this.ActorInbox);
            this.Instance.SetupEventHandlers();
            if (this.Instance is StateMachine)
            {
                this.LogWriter.LogCreateStateMachine(this.Instance.Id, null, null);
            }
            else
            {
                this.LogWriter.LogCreateActor(this.Instance.Id, null, null);
            }

            this.IsActorWaitingToReceiveEvent = false;
        }
Example #30
0
        /// <summary>
        /// Creates a ad-hoc symbol generator depending on settings
        /// </summary>
        /// <param name="settings">random data generator settings</param>
        /// <param name="random">produces random values for use in random data generation</param>
        /// <returns>New symbol generator</returns>
        public static BaseSymbolGenerator Create(RandomDataGeneratorSettings settings, IRandomValueGenerator random)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings), "Settings cannot be null or empty");
            }

            if (random is null)
            {
                throw new ArgumentNullException(nameof(random), "Randomizer cannot be null");
            }

            switch (settings.SecurityType)
            {
            case SecurityType.Option:
                return(new OptionSymbolGenerator(settings, random, 100m, 75m));

            case SecurityType.Future:
                return(new FutureSymbolGenerator(settings, random));

            default:
                return(new DefaultSymbolGenerator(settings, random));
            }
        }
 public DefaultScenarioContextFactory(IRandomValueGenerator uniqueValueGenerator)
 {
     _uniqueValueGenerator = uniqueValueGenerator;
 }