Esempio n. 1
0
 public void TerminateCaluculations()
 {
     StopSimulations = true;
     Methods.JoinAll(5000);
     Methods.TerminateAll();
     MonteCarloData = new ThreadedDictionary <string, ThreadedList <double[]> >();
 }
Esempio n. 2
0
 public void Delete()
 {
     Data = new ThreadedDictionary <TKey, TValue>();
     if (System.IO.File.Exists(FullPath))
     {
         System.IO.File.Delete(FullPath);
     }
 }
Esempio n. 3
0
        public FileDictionary(string FullPath, int SaveInterval = int.MaxValue)
        {
            Data = new ThreadedDictionary <TKey, TValue>();
            this.SaveInterval  = SaveInterval;
            this.FullPath      = FullPath;
            this.FullDirectory = Path.GetDirectoryName(FullPath);

            this.CheckPermissions();
            this.LoadData();

            if (SaveInterval > 0 && SaveInterval < int.MaxValue)
            {
                Timers.Run(() => this.PaceMaker(), SaveInterval, null, true, true);
            }
        }
Esempio n. 4
0
        private void InitRequestManager()
        {
            FileDealRequest = new File("DealRequest", true);
            ThreadRequest   = new ThreadedMethod(100, System.Threading.ThreadPriority.Highest, 1);
            DataDealRequest = new ThreadedDictionary <TickTime, DealRequest>();

            string data = FileDealRequest.Load();

            if (System.String.IsNullOrEmpty(data))
            {
                return;
            }

            DataDealRequest.XmlDeserialize(data);
        }
Esempio n. 5
0
        public void Learn(string name, int number, Dictionary <string, double> result)
        {
            if (result == null || result.Count <= 0)
            {
                return;
            }

            Data[number].Add(result);
            TrainingStrength += result.Count;

            ThreadedDictionary <string, double> buffor = (ThreadedDictionary <string, double>)result;
            string data = buffor.XmlSerialize();


            Database.Set(name + "-" + number, data);
        }
Esempio n. 6
0
        public FileDictionary(string FullPath, int SaveInterval = 0, bool enabled = true)
        {
            this.Enabled       = enabled;
            Data               = new ThreadedDictionary <TKey, TValue>();
            this.SaveInterval  = SaveInterval;
            this.FullPath      = Files.GetFullPath(FullPath);  //FullPath;
            this.FullDirectory = Files.GetDirectory(FullPath); // Path.GetDirectoryName(FullPath);

            this.CheckPermissions();
            this.Load();

            if (SaveInterval > 0 && SaveInterval <= 0)
            {
                Timers.Run(() => this.PaceMaker(), SaveInterval, null, true, true);
            }
        }
Esempio n. 7
0
        public KeyValuePair <TickTime, string>[] GetNextData(DataType type, TickTime init)
        {
            ThreadedDictionary <TickTime, string> data = new ThreadedDictionary <TickTime, string>();

            if ((type & DataType.Input) > 0)
            {
                data.AddRange(InputData.ToDictionary());
            }
            if ((type & DataType.Error) > 0)
            {
                data.AddRange(ErrorData.ToDictionary());
            }
            if ((type & DataType.Output) > 0)
            {
                data.AddRange(OutputData.ToDictionary());
            }

            return(data?.Where(x => x.Key > init)?.Select(x => { return new KeyValuePair <TickTime, string>(x.Key.Copy(), x.Value); })?.ToArray() ?? new KeyValuePair <TickTime, string> [0]);
        }
Esempio n. 8
0
        private void LoadData()
        {
            if (Database.Count <= 0)
            {
                return;
            }

            string[] keys   = Database.Keys;
            object[] values = Database.Values;


            for (int i = 0; i < keys.Length; i++)
            {
                string key  = keys[i];
                string data = (string)values[i];

                var    split  = key.SplitSafe('-');
                string name   = split[0];
                int    number = int.Parse(split[1]);

                ThreadedDictionary <string, double> buffor = new ThreadedDictionary <string, double>();
                buffor.XmlDeserialize(data);

                if (!Data.ContainsKey(number))
                {
                    Data.Add(number, new ThreadedList <Dictionary <string, double> >(), true);
                }

                Data[number].Add((Dictionary <string, double>)buffor);

                if (!LoadedFiles.Contains(name))
                {
                    LoadedFiles.Add(name);
                }
            }
        }
Esempio n. 9
0
 public void Reset()
 {
     Data = new ThreadedDictionary <TKey, TValue>();
     this.Save();
 }
Esempio n. 10
0
        private void PruneMap(ThreadedDictionary<ulong, List<PostUID>> map)
        {
            if (map.SafeCount < PruneSize)
                return;

            List<ulong> removeIDs = new List<ulong>();

            map.LockWriting(delegate()
            {
                while (map.Count > 0 && map.Count > PruneSize)
                {
                    ulong furthest = Core.UserID;

                    // get furthest id
                    foreach (ulong id in map.Keys)
                        if ((id ^ Core.UserID) > (furthest ^ Core.UserID))
                            furthest = id;

                    // remove one
                    map.Remove(furthest);
                }
            });
        }