Beispiel #1
0
        public AlgoResult(Map map, IAlgo algo, long initTime, long searchTime)
        {
            InitTime   = initTime;
            SearchTime = searchTime;

            Robots = algo.Robots.Select(r => new RobotResult(r, map)).ToList();
        }
        public IAlgo create()
        {
            IAlgo algoritme = null;

            switch (this.algo)
            {
            case "simple":
                algoritme = new Simple();
                break;

            case "ascii":
                algoritme = new Ascii();
                break;

            case "shift":
                algoritme = new Shift();
                break;

            default:
                break;
            }

            if (algoritme == null)
            {
                return(null);
            }

            return(algoritme);
        }
        private void OrdersStorage_AlgoChanged(DataStorage <Order> sender, IAlgo oldalgo, IAlgo newalgo)
        {
            sender.Entities.ListChanged  += Entities_ListChanged;
            sender.Entities.BeforeRemove += Entities_BeforeRemove;

            Orders.Clear();
        }
Beispiel #4
0
        public IEnumerable <Order> GetOrders(IAlgo algo)
        {
            var regex    = new Regex(@"^.*\((?<json>(?:.*))\)");
            var response = RequestPubJson($"l=0&a={algo.Id}");
            var match    = regex.Match(response.Content);

            if (!match.Success || string.IsNullOrEmpty(match.Groups["json"].Value))
            {
                return(null);
            }

            var jobject = JObject.Parse(match.Groups["json"].Value);

            var euServer     = jobject["eu"];
            var euOrders     = euServer["orders"];
            var resultEurope = GetOrderFromJtoken(euOrders, ServerEnum.Europe);

            var usServer  = jobject["usa"];
            var usOrders  = usServer["orders"];
            var resultUsa = GetOrderFromJtoken(usOrders, ServerEnum.Usa);

            var result = resultEurope?.Concat(resultUsa) ?? resultUsa ?? new List <Order>();

            return(result);
        }
 public HealthController(IGenericRepository <Model.Instance, Guid> instanceRepository,
                         IGenericRepository <Model.Result, Guid> resultRepository,
                         IGenericRepository <Model.User, Guid> userRepository,
                         IAlgo algo)
 {
     this.instanceRepository = instanceRepository;
     this.resultRepository   = resultRepository;
     this.userRepository     = userRepository;
     this.algo = algo;
 }
Beispiel #6
0
 public InstanceController(IGenericRepository <Model.Instance, Guid> instanceRepository,
                           IGenericRepository <Model.Result, Guid> resultRepository,
                           IAlgo algo,
                           IMapper mapper)
 {
     this.instanceRepository = instanceRepository;
     this.resultRepository   = resultRepository;
     this.algo   = algo;
     this.mapper = mapper;
 }
Beispiel #7
0
        public virtual void SelectAnotherAlgo(IAlgo newAlgo)
        {
            var oldAlgo = Algo;
            AlgoChanging?.Invoke(this, oldAlgo, newAlgo);

            Entities = new NiceBindingList<T>();
            Algo = newAlgo;

            AlgoChanged?.Invoke(this, oldAlgo, newAlgo);
        }
Beispiel #8
0
        public async Task <string> LoadCode(IAlgo algo)
        {
            var codeBaseUrl        = Assembly.GetExecutingAssembly().CodeBase;
            var filePathToCodeBase = new Uri(codeBaseUrl).LocalPath;
            var directoryPath      = Path.GetDirectoryName(filePathToCodeBase);

            using (var f = File.OpenRead(Path.Combine(directoryPath, $"Implementation\\{algo.FileName}")))
                using (var stm = new StreamReader(f))
                    return(await stm.ReadToEndAsync());
        }
Beispiel #9
0
        public static IAlgo CreateAlgo(AlgoType algoType, int?start = null, double?value = null)
        {
            IAlgoFactory factory = null;

            if (!Factories.ContainsKey(algoType))
            {
                throw new Exception("Invalid algo type");
            }
            switch (algoType)
            {
            case AlgoType.Constant:
                Factories.TryGetValue(AlgoType.Constant, out factory);
                break;

            case AlgoType.Increment:
                Factories.TryGetValue(AlgoType.Increment, out factory);
                break;

            case AlgoType.Multiple:
                Factories.TryGetValue(AlgoType.Multiple, out factory);
                break;

            case AlgoType.Exp:
                Factories.TryGetValue(AlgoType.Exp, out factory);
                break;

            case AlgoType.Fibonacci:
                Factories.TryGetValue(AlgoType.Fibonacci, out factory);
                break;
            }
            try
            {
                IAlgo algo = null;
                if (value.HasValue)
                {
                    algo = factory.CreateAlgo(start.Value, value.Value);
                }
                else if (start.HasValue)
                {
                    algo = factory.CreateAlgo(start.Value);
                }
                else
                {
                    algo = factory.CreateAlgo();
                }

                return(algo);
            }
            catch
            {
                throw new Exception($"Invalid parameters for algo type: {algoType.ToString()}");
            }
        }
Beispiel #10
0
        /// <summary>
        /// Запуск алгоритма
        /// </summary>
        /// <param name="e"></param>
        /// <param name="algo">Конкретный алгоритм поиска кратчайшего пути</param>
        private void RunAlgo(MouseEventArgs e, IAlgo algo)
        {
            string len = algo.Run1().ToString();

            textBox1.Text = len;
            if (len != "0")
            {
                int[]       mas = algo.GetPath();
                List <Node> myN = new List <Node>();

                foreach (var el in mas)
                {
                    for (int i = 0; i < grList.Count; i++)
                    {
                        Node nd = grList[i] as Node;
                        if (nd != null)
                        {
                            int num = int.Parse(nd.Name.Replace("x", "")) - 1;
                            if (num == el)
                            {
                                myN.Add(nd);
                                grList[i].BackColor = Color.SeaGreen;
                                break;
                            }
                        }
                    }
                }

                foreach (var gr in grList)
                {
                    Arc arc = gr as Arc;
                    if (arc != null)
                    {
                        for (int i = 0; i < myN.Count - 1; i++)
                        {
                            if (arc.MyNodes(myN[i], myN[i + 1]))
                            {
                                gr.BackColor = Color.SeaGreen;
                                break;
                            }
                        }
                    }
                }
                myN.Clear();
            }
            else
            {
                MessageBox.Show("Путь между заданными вершинами отсутствует");
            }

            canva.Refresh();
            //
        }
Beispiel #11
0
        public DataStorage(IAlgo algo, int frequencyQueryMilliseconds, Dispatcher currentDispatcher = null)
        {
            _currentDispatcher = currentDispatcher;
            _frequencyQueryMilliseconds = frequencyQueryMilliseconds;

            Algo = algo;

            Entities = new NiceBindingList<T>();

            ApiClient = new ApiClient();

            _timer = new Timer(TimerOnElapsed, null, 0, _frequencyQueryMilliseconds);
        }
Beispiel #12
0
        protected DataStorage(IAlgo algo, int frequencyQueryMilliseconds)
        {
            _syncContext = SynchronizationContext.Current;
            _frequencyQueryMilliseconds = frequencyQueryMilliseconds;

            Algo = algo;

            Entities = new NiceBindingList <T>();

            ApiClient = new ApiClient();

            _timer = new Timer(TimerOnElapsed, null, 0, _frequencyQueryMilliseconds);
        }
Beispiel #13
0
        public OrdersStorage(IAlgo algo, int frequencyQueryMilliseconds, IEnumerable <short> targetLevels)
            : base(algo, frequencyQueryMilliseconds)
        {
            if (targetLevels == null)
            {
                return;
            }
            _targetLevels = new Dictionary <short, decimal>();

            foreach (var targetLevel in targetLevels.OrderBy(tl => tl))
            {
                _targetLevels.Add(targetLevel, decimal.MinusOne);
            }
        }
Beispiel #14
0
        public string run(string password, string algo)
        {
            AlgorithmFactory factory   = new AlgorithmFactory(algo);
            IAlgo            algorithm = factory.create();

            if (algorithm == null)
            {
                return(null);
            }

            string newPassword = algorithm.generate(password);

            return(newPassword);
        }
Beispiel #15
0
        public void ListenAlgo(IAlgo algo)
        {
            var callbackChannel = OperationContext.Current.GetCallbackChannel <IDataCallBacks>();

            if (!_subscribers.ContainsKey(callbackChannel))
            {
                _subscribers.Add(callbackChannel, algo.Id);
            }

            if (!_ordersStorages.ContainsKey(algo.Id))
            {
                var orderStorageForAlgo = new OrdersStorage(algo, 1000);

                orderStorageForAlgo.Entities.ListChanged += Entities_ListChanged;
                //orderStorageForAlgo.Entities.BeforeRemove += Entities_BeforeRemove;

                _ordersStorages.Add(algo.Id, orderStorageForAlgo);
            }
        }
Beispiel #16
0
 public void SetAlgo(IAlgo algo)
 {
     this.algo = algo;
 }
 private void OrdersStorage_AlgoChanging(DataStorage <Order> sender, IAlgo oldAlgo, IAlgo newAlgo)
 {
     sender.Entities.ListChanged  -= Entities_ListChanged;
     sender.Entities.BeforeRemove -= Entities_BeforeRemove;
 }
Beispiel #18
0
        static async Task MainAlgo()
        {
            logger.LogInformation($"Starting");
            var timestamp           = DateTime.Now.ToString("yyyyMMddHHmmss");
            var dir                 = appSettings.defaultDirectory;
            var sourceTargetCouples = appSettings.SourceTargetCouples.Where(c => c.Active).Select(couple => couple);

            foreach (var sourceTarget in sourceTargetCouples)
            {
                logger.LogInformation($"Batch : {sourceTarget.Name}");
                var sparqlQueryable1 = SparqlQueryable.Create(string.IsNullOrWhiteSpace(sourceTarget.endpointUri1) ? sourceTarget.rdfFile1 : sourceTarget.endpointUri1, sourceTarget.namedGraph1);
                var sparqlQueryable2 = SparqlQueryable.Create(string.IsNullOrWhiteSpace(sourceTarget.endpointUri2) ? sourceTarget.rdfFile2 : sourceTarget.endpointUri2, sourceTarget.namedGraph2);

                var   similarityResults = new BlockingCollection <SimilarityResult>();
                var   file           = System.IO.Path.Combine(dir, $"{sourceTarget.Name}.json");
                var   sourceSubjects = new List <string>();
                var   targetSubjects = new List <string>();
                IAlgo algo           = null;
                if (!appSettings.ForceSimilarityComputation && System.IO.File.Exists(file))
                {
                    logger.LogInformation($"opening file : {file}");
                    var similarityResultsArray = await GetSimilarityResults(file);

                    foreach (var item in similarityResultsArray)
                    {
                        similarityResults.Add(item);
                    }
                    sourceSubjects.AddRange(similarityResults.Select(sr => sr.Uri1).Distinct());
                    targetSubjects.AddRange(similarityResults.Select(sr => sr.Uri2).Distinct());
                }
                else
                {
                    algo = await Setup(sourceTarget.endpointUri1, sourceTarget.endpointUri2, sourceTarget.rdfFile1, sourceTarget.rdfFile2, sourceTarget.namedGraph1, sourceTarget.namedGraph2, sourceTarget.classesToSelect1, sourceTarget.classesToSelect2);

                    if (algo == null)
                    {
                        return;
                    }
                    var(subs1, subs2) = algo.GetSubjects();
                    sourceSubjects.AddRange(subs1);

                    targetSubjects.AddRange(subs2);
                    var numberOfSimilarityComputation = (double)sourceSubjects.Count * targetSubjects.Count;
                    logger.LogInformation($"{numberOfSimilarityComputation} to process...");
                    var count       = 0d;
                    var pourcentage = 0;

                    // parallel loop on instances from the source
                    await Task.Run(() => Parallel.ForEach(sourceSubjects, s1 =>
                    {
                        foreach (var s2 in targetSubjects)
                        {
                            var similarityResult = algo.SimilarityComputation(s1, s2).Result;
                            similarityResults.Add(similarityResult);
                            count++;
                            var currentPourcentage = (int)Math.Floor(count / numberOfSimilarityComputation * 100);
                            if (currentPourcentage > pourcentage)
                            {
                                pourcentage++;
                                logger.LogInformation($"{pourcentage}%");
                            }
                        }
                    }));

                    try
                    {
                        await System.IO.File.WriteAllTextAsync(System.IO.Path.Combine(appSettings.defaultDirectory, $"scoresNonAggregated_{sourceTarget.Name}.json"), JsonConvert.SerializeObject(((Algo)algo).subScores
                                                                                                                                                                                                  .Where(s => s.s != null && s.t != null && s.w > 0 && s.n != null && s.n.Any(sub => sub.c > 0 && sub.v > 0 && sub.o > 0 && sub.m > 0 && sub.p != null))));

                        await algo.SaveTranslations(System.IO.Path.Combine(appSettings.defaultDirectory, appSettings.translationsPath));

                        if (similarityResults != null && similarityResults.Any())
                        {
                            await SaveSimilarityResults(similarityResults.ToList(), System.IO.Path.Combine(dir, $"{sourceTarget.Name}.json"));
                        }
                        else
                        {
                            throw new Exception("similarityResults is null or empty !");
                        }
                    }
                    catch (System.Exception e)
                    {
                        logger.LogError(e.Message);
                        logger.LogError(e.StackTrace);
                        logger.LogError(e.ToString());
                    }
                }

                if (string.IsNullOrWhiteSpace(sourceTarget.refalign))
                {
                    continue;
                }
                var dic = similarityResults
                          .Where(s => s != null && !string.IsNullOrWhiteSpace(s.Uri1))
                          .GroupBy(s => s.Uri1).ToDictionary(s => s.Key, s => s.ToList());
                var positions          = new List <int>(); // contains the position of the referrer in our results list. The lower, the better.
                var positionsFound     = new List <int>(); // contains the position of the referrer in our results list. The lower it is, the better (without those not found)
                var indexNegativeCount = 0;
                var notFoundInDict     = 0;
                var s2FoundInDict      = 0;
                var alignments         = Tools.GetRefalignResources(sourceTarget.refalign);
                logger.LogInformation($"dictionary size : {dic.Count}");
                var sourceAlignmentNotInSourceSubjects = 0;
                var targetAlignmentNotInTargetSubjects = 0;
                var predictedMatch             = new List <SimilarityResult>();
                var numberOfBetterElementsList = new List <int>();
                var minSimilarityValue         = double.PositiveInfinity;
                foreach (var alignment in alignments)
                {
                    try
                    {
                        var s1 = alignment.Source;
                        if (!sourceSubjects.Contains(s1))
                        {
                            Console.Write(s1);
                            sourceAlignmentNotInSourceSubjects++;
                        }
                        var s2 = alignment.Target;
                        if (!targetSubjects.Contains(s2))
                        {
                            targetAlignmentNotInTargetSubjects++;
                        }
                        if (!sourceSubjects.Contains(s1) && !targetSubjects.Contains(s2))
                        {
                            s1 = alignment.Target;
                            s2 = alignment.Source;
                        }
                        if (!dic.ContainsKey(s1))
                        {
                            notFoundInDict++;
                            if (dic.ContainsKey(s2))
                            {
                                s2FoundInDict++;
                            }
                            continue;
                        }
                        var similarityResultList = dic[s1].OrderByDescending(s => s.Result).Where(s => s.Uri1 != null && s.Uri2 != null).ToList();
                        predictedMatch.Add(similarityResultList.ElementAt(0));


                        var index = similarityResultList.Select(s => s.Uri2).ToList().IndexOf(s2);
                        var s1s2  = similarityResultList.ElementAt(similarityResultList.Count > index ? (index >= 0 ? index : similarityResultList.Count - 1) : similarityResultList.Count - 1);
                        if (s1s2.Uri2 != s2)
                        {
                            throw new Exception("s1s2.Uri2 != s2");
                        }
                        if (s1s2.Uri1 != s1)
                        {
                            throw new Exception("s1s2.Uri1 != s1");
                        }
                        if (double.IsNaN(s1s2.Result))
                        {
                            logger.LogInformation($"Nan : {s1} // {s2}");
                        }
                        var numberOfBetterElements = similarityResultList.Where(sr1 => sr1.Result > s1s2.Result).Count();
                        minSimilarityValue = minSimilarityValue > s1s2.Result ? s1s2.Result : minSimilarityValue;

                        numberOfBetterElementsList.Add(numberOfBetterElements);
                        if (index == -1)
                        {
                            index = targetSubjects.Count;
                            indexNegativeCount++;
                        }
                        else
                        {
                            positionsFound.Add(index);
                        }
                        positions.Add(index);
                    }
                    catch (System.Exception e)
                    {
                        logger.LogError(e.Message);
                        logger.LogError(e.StackTrace);
                        logger.LogError(e.ToString());
                    }
                }
                logger.LogInformation($"# of not found match (should be 0) : {positions.Count - positionsFound.Count}");
                logger.LogInformation($"# of found match (i.e. index = 0) (should NOT be 0) : {positionsFound.Count}");
                logger.LogInformation($"# of positions (should NOT be 0) : {positions.Count}");
                logger.LogInformation($"# of source alignment not in source subjects (should be 0) : {sourceAlignmentNotInSourceSubjects}");
                logger.LogInformation($"# of target alignment not in target subjects (should be 0) : {targetAlignmentNotInTargetSubjects}");
                logger.LogInformation($"# negative index (should be 0) : {indexNegativeCount}");
                logger.LogInformation($"# source alignment not found in dictionary (should be 0) : {notFoundInDict}");
                logger.LogInformation($"# target alignment found in dictionary (should be 0 if there are no common resources) : {s2FoundInDict}");
                logger.LogInformation($"average position : {(positions.Any() ? positions.Average() : 0)}");
                logger.LogInformation($"average position (with only found): {(positionsFound.Any() ? positionsFound.Average() : 0)}");
                logger.LogInformation($"# of alignments (for real)=(in theory): {positions.Count} = {alignments.Count()} ({(int)Math.Floor(((double)positions.Count) / ((double)alignments.Count()) * 100d)})");
                logger.LogInformation($"# of alignments in results (for real)=(in theory): {positionsFound.Count} = {alignments.Count()} ({(int)Math.Floor(((double)positionsFound.Count) / ((double)alignments.Count()) * 100d)}%)");
                logger.LogInformation($"# of good positions (good alignments) (should be equal to {alignments.Count()}) : {(positions.Where(p => p == 0).Count())} ({(int)Math.Floor(((double)positions.Where(p => p == 0).Count()) / ((double)alignments.Count()) * 100d)}%)");


                double threshold = 0.0357769130450459;//DOREMUS FPT
                logger.LogInformation($"average # of better elements : {numberOfBetterElementsList.Average()}");
                logger.LogInformation($"# of predicted match : {predictedMatch.Count}");
                logger.LogInformation($"min result : {(predictedMatch.Any() ? predictedMatch.Min(p => p.Result) : 0)}");
                logger.LogInformation($"max result : {(predictedMatch.Any() ? predictedMatch.Max(p => p.Result) : 0)}");
                logger.LogInformation($"average result : {(predictedMatch.Any() ? predictedMatch.Average(p => p.Result) : 0)}");

                var filteredPredictedMatch = serviceProvider.GetService <IAggregation>().Filter(similarityResults, sourceSubjects, targetSubjects);
                logger.LogInformation($"# of filtered predicted match : {filteredPredictedMatch.Count()}");
                var evaluation = new Evaluation(filteredPredictedMatch, alignments, serviceProvider.GetRequiredService <ILoggerFactory>());
                logger.LogInformation($"threshold : {threshold}");
                logger.LogInformation($"Precision : {evaluation.Precision}");
                logger.LogInformation($"Recall : {evaluation.Recall}");
                logger.LogInformation($"F-measure : {evaluation.FMeasure}");
            }
        }
Beispiel #19
0
 public OrdersStorage(IAlgo algo, int frequencyQueryMilliseconds, Dispatcher currentDispatcher = null)
     : base(algo, frequencyQueryMilliseconds, currentDispatcher)
 {
 }