Exemplo n.º 1
0
 private void ExecutedStartAnalyticsCommand(object sender, ExecutedRoutedEventArgs e)
 {
     SelectedStrategy.Environment.SetValue("Drive", new StudioStorageRegistry {
         MarketDataSettings = SelectedStrategy.MarketDataSettings
     }.DefaultDrive);
     SelectedStrategy.Start();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up the strategy to be executed
        /// </summary>
        /// <param name="initializeStrategy">Holds info to initialize the given strategy</param>
        private void InitializeUserStrategy(InitializeStrategy initializeStrategy)
        {
            try
            {
                if (_asyncClassLogger.IsInfoEnabled)
                {
                    _asyncClassLogger.Info("Setting up user strategy to run: " + initializeStrategy.StrategyType.FullName,
                                           _type.FullName, "InitializeUserStrategy");
                }

                // Get new Key.
                string key = ApplicationIdGenerator.NextId();

                // Save Strategy details in new Strategy Executor object
                StrategyExecutor strategyExecutor = new StrategyExecutor(key, initializeStrategy.StrategyType, initializeStrategy.CtorArguments);

                // Add to local map
                _strategiesCollection.AddOrUpdate(key, strategyExecutor, (ky, value) => strategyExecutor);

                //Register Event
                strategyExecutor.StatusChanged     += OnStatusChanged;
                strategyExecutor.ExecutionReceived += OnExecutionArrived;

                // Save Brief info of constructor parameters
                StringBuilder briefInfo = new StringBuilder();

                // Add Strategy Description
                briefInfo.Append(LoadCustomStrategy.GetCustomClassSummary(initializeStrategy.StrategyType));
                briefInfo.Append(" :: ");

                // Add Parameters Description
                foreach (object ctorArgument in initializeStrategy.CtorArguments)
                {
                    briefInfo.Append(ctorArgument.ToString());
                    briefInfo.Append("|");
                }

                // Create object to add to AddStrattegy.cs object
                SelectedStrategy selectedStrategy = new SelectedStrategy
                {
                    Key       = key,
                    Symbol    = initializeStrategy.CtorArguments[3].ToString(),
                    BriefInfo = briefInfo.ToString()
                };

                // Create object to pass to event aggregator.
                AddStrategy addStrategy = new AddStrategy(selectedStrategy);

                // Publish event to notify listeners.
                EventSystem.Publish <AddStrategy>(addStrategy);
            }
            catch (Exception exception)
            {
                _asyncClassLogger.Error(exception, _type.FullName, "InitializeUserStrategy");
            }
        }
Exemplo n.º 3
0
        private void ExecutedSetParametersCommand(object sender, ExecutedRoutedEventArgs e)
        {
            var strategy = (StrategyContainer)SelectedStrategy.Clone();

            strategy.StrategyInfo = Strategy.StrategyInfo;
            strategy.SessionType  = SessionType.Battle;
            strategy.Portfolio    = Strategy.Portfolio;

            new AddStrategyCommand(Strategy.StrategyInfo, strategy, SessionType.Battle).SyncProcess(this);
        }
Exemplo n.º 4
0
        private void CanExecuteStopStrategyCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!SelectedStrategy.IsStrategy())
            {
                e.CanExecute = false;
                return;
            }

            e.CanExecute = SelectedStrategy.SessionType != SessionType.Optimization
                                ? SelectedStrategy.ProcessState == ProcessStates.Started
                                : new StopStrategyCommand(SelectedStrategy).CanProcess(SelectedStrategy);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Determines the complete call to the stored procedure if executing the algorithm via CLR.
        /// </summary>
        /// <param name="strWhere">passed to the SelectedStrategy's parameter.</param>
        /// <param name="strOrderBy">passed to the SelectedStrategy's parameter.</param>
        /// <param name="strFirstSQL">passed to the SelectedStrategy's parameter.</param>
        /// <param name="strOperators">passed to the SelectedStrategy's parameter.</param>
        /// <param name="strOrderByAttributes">passed to the SelectedStrategy's parameter.</param>
        /// <returns>A string to be used to execute the stored procedure.</returns>
        public string GetStoredProcedureCommand(string strWhere, string strOrderBy, string strFirstSQL,
                                                string strOperators, string strOrderByAttributes)
        {
            string storedProcedureCommand = SelectedStrategy.GetStoredProcedureCommand(strWhere, strOrderBy, strFirstSQL,
                                                                                       strOperators, strOrderByAttributes);

            storedProcedureCommand = Regex.Replace(storedProcedureCommand, @"dbo\.prefSQL_[^ ]* ", "dbo.prefSQL_SkylineSampling ");

            if (SelectedStrategy.GetType() != typeof(SkylineSQL))
            {
                storedProcedureCommand += ", " + SubsetCount + ", " + SubsetDimension + ", " +
                                          SelectedStrategy.GetType().Name + ", " +
                                          (SelectedStrategy.HasIncomparablePreferences ? "1" : "0");
            }

            return(storedProcedureCommand);
        }
Exemplo n.º 6
0
 private void CanExecuteRemoveEmulation(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = SelectedStrategy.IsStrategy() && SelectedStrategy.SessionType != SessionType.Battle;
 }
Exemplo n.º 7
0
 private void CanExecuteRemoveStrategy(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = SelectedStrategy.IsStrategy() && SelectedStrategy.SessionType == SessionType.Battle && SelectedStrategy.ProcessState == ProcessStates.Stopped;
 }
Exemplo n.º 8
0
 private void CanExecuteRemoveStrategy(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = SelectedStrategy.IsTerminal();
 }
Exemplo n.º 9
0
 private void CanExecuteStopAnalyticsCommand(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = SelectedStrategy.IsAnalytics() && SelectedStrategy.ProcessState == ProcessStates.Started;
 }
Exemplo n.º 10
0
 private void ExecutedStopAnalyticsCommand(object sender, ExecutedRoutedEventArgs e)
 {
     SelectedStrategy.Stop();
 }
Exemplo n.º 11
0
        /// <summary>
        ///     Calculate the necessary subset skylines and merge them into the skyline sample which will finally be reported by
        ///     the skyline sampling algorithm.
        /// </summary>
        /// <remarks>
        ///     Calculate subsets of preferences. For each subset, calculate a skyline via the selected skyline algorithm. Determine the
        ///     objects for which the calculation of a subset skyline with respect to the subset's complement is necessary; if
        ///     so, calculate this subset complement skyline via the selected skyline algorithm and remove dominated objects from
        ///     the subset skyline. Finally, merge the subset skyline into the skyline sample which will be reported by the
        ///     skyline sampling algorithm.
        /// </remarks>
        /// <param name="database">
        ///     A Collection by which a row can be accessed via its unique ID. The values represent the database
        ///     rows including the preceding SkylineAttribute columns.
        /// </param>
        /// <param name="dataTableTemplate">
        ///     An empty DataTable with all columns to return to which the column
        ///     InternalArtificialUniqueRowIdentifierColumnName has already been added.
        /// </param>
        /// <param name="sw">
        ///     To measture the time spent to perform this whole algorithm. Has to be started before calling this
        ///     method, will be running after this method.
        /// </param>
        private IReadOnlyDictionary <long, object[]> CalculateSkylineSampleFinalDatabase(
            IReadOnlyDictionary <long, object[]> database, DataTable dataTableTemplate, Stopwatch sw)
        {
            var skylineSampleFinalDatabase = new Dictionary <long, object[]>();

            foreach (CLRSafeHashSet <int> subset in Utility.Subsets)
            {
                IEnumerable <object[]> useDatabase = database.Values;

                string subpaceOperators = GetOperatorsWithIgnoredEntriesString(subset);

                SelectedStrategy.HasIncomparablePreferences = subpaceOperators.Contains("INCOMPARABLE");

                SelectedStrategy.PrepareDatabaseForAlgorithm(ref useDatabase, subset.ToList(),
                                                             Utility.PreferenceColumnIndex, Utility.IsPreferenceIncomparable);

                sw.Stop();
                TimeMilliseconds += sw.ElapsedMilliseconds;
                DataTable subsetDataTable = SelectedStrategy.GetSkylineTable(useDatabase,
                                                                             dataTableTemplate.Clone(), DataRecordTemplate, subpaceOperators);
                TimeMilliseconds   += SelectedStrategy.TimeMilliseconds;
                NumberOfOperations += SelectedStrategy.NumberOfComparisons;
                sw.Restart();

                IDictionary <long, object[]> subsetDatabase = GetDatabaseFromDataTable(database, subsetDataTable);

                IEnumerable <Tuple <long[], string[]> > databaseForPairwiseComparison =
                    GetDatabaseForPairwiseComparison(subsetDatabase.Values, subset.ToList());

                IEnumerable <CLRSafeHashSet <long> > rowsWithEqualValuesWithRespectToSubsetColumns =
                    CompareEachRowWithRespectToSubsetColumnsPairwise(databaseForPairwiseComparison);

                CLRSafeHashSet <int> subsetComplement = Utility.GetSubsetComplement(subset);
                string subsetComplementOperators      =
                    GetOperatorsWithIgnoredEntriesString(Utility.GetSubsetComplement(subset));

                SelectedStrategy.HasIncomparablePreferences = subsetComplementOperators.Contains("INCOMPARABLE");
                List <int> subsetComplementList = subsetComplement.ToList();

                foreach (CLRSafeHashSet <long> rowsWithEqualValues in rowsWithEqualValuesWithRespectToSubsetColumns)
                {
                    IReadOnlyDictionary <long, object[]> rowsWithEqualValuesDatabase = GetSubsetOfDatabase(database,
                                                                                                           rowsWithEqualValues);

                    useDatabase = rowsWithEqualValuesDatabase.Values;
                    SelectedStrategy.PrepareDatabaseForAlgorithm(ref useDatabase, subsetComplementList,
                                                                 Utility.PreferenceColumnIndex, Utility.IsPreferenceIncomparable);

                    sw.Stop();
                    TimeMilliseconds += sw.ElapsedMilliseconds;
                    DataTable subsetComplementDataTable =
                        SelectedStrategy.GetSkylineTable(useDatabase,
                                                         dataTableTemplate.Clone(), DataRecordTemplate, subsetComplementOperators);
                    TimeMilliseconds   += SelectedStrategy.TimeMilliseconds;
                    NumberOfOperations += SelectedStrategy.NumberOfComparisons;
                    sw.Restart();

                    IReadOnlyDictionary <long, object[]> subsetComplementDatabase =
                        new ReadOnlyDictionary <long, object[]>(GetDatabaseFromDataTable(database,
                                                                                         subsetComplementDataTable));

                    RemoveDominatedObjects(rowsWithEqualValues, subsetComplementDatabase, subsetDatabase);
                }

                MergeSubsetSkylineIntoFinalSkylineSample(new ReadOnlyDictionary <long, object[]>(subsetDatabase),
                                                         skylineSampleFinalDatabase);
            }

            return(skylineSampleFinalDatabase);
        }
Exemplo n.º 12
0
 private bool CheckStrategyType()
 {
     return(SelectedStrategy != null && ((IsTerminal && SelectedStrategy.IsTerminal()) || (IsStrategy && SelectedStrategy.IsStrategy())));
 }