예제 #1
0
        static void Main(string[] args)
        {
            AlgorithmData algData    = new AlgorithmData();
            var           l_algoList = algData.GetBlocks();

            //Task.Run(async () =>
            //{
            //    // Do any async anything you need here without worry
            //    List<string> l_lsit = new List<string>();
            //    Stopwatch stopwatch = new Stopwatch();
            //    stopwatch.Start();

            //    //Parallel.For(0, 2500, (e) =>
            //    //{
            //    //    ReadFile();
            //    //});

            //    SaveFiles();

            //    //string str = ReadFile1();
            //    //var test = await svcClient.getRateAsync(str);

            //    stopwatch.Stop();
            //    Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            //    Console.ReadKey();
            //}).GetAwaiter().GetResult();
        }
예제 #2
0
        public void VisitAlgorithm(int index, Action <GaleShapleyAlgorithm> galeShapleyMethod,
                                   Action <GeneticAlgorithm> geneticMethod)
        {
            AlgorithmData         data    = Context.Algorithms[index];
            AlgorithmVisitorParam visitor = new AlgorithmVisitorParam((x) => galeShapleyMethod?.Invoke(x),
                                                                      (x) => geneticMethod?.Invoke(x));

            visitor.Visit(data.Element);
        }
예제 #3
0
    private AlgorithmData FindPath(IPathFinder pathFinder)
    {
        AlgorithmData alg = new AlgorithmData();

        float startTime = Time.realtimeSinceStartup;

        alg.path = pathFinder.FindPath(grid, grid[startX, startY], grid[endX, endY], out alg.checkedNodesCount, out alg.name)?.ToList();
        alg.time = (Time.realtimeSinceStartup - startTime) * 1000;

        return(alg);
    }
예제 #4
0
        /// <summary>
        /// Runs the RLHT over the image, skipping lines around uninteresting areas.
        /// </summary>
        /// <param name="Input">Input image segment.</param>
        /// <param name="ImP">Image-specific detection parameters.</param>
        /// <param name="AGD">Algorithm arguments.</param>
        /// <returns></returns>
        internal static HTResult SmartSkipRLHT(double[,] Input, ImageParameters ImP, AlgorithmData AGD)
        {
            /* Compute algorithm parameters */
            int    Height    = Input.GetLength(0);
            int    Width     = Input.GetLength(1);
            double ThetaUnit = Min(Atan2(1, Height), Atan2(1, Width));
            double NTheta    = 2 * PI / ThetaUnit;
            double RhoMax    = Sqrt(Width * Width + Height * Height);

            lock (AGD.HTPool)
                if (AGD.HTPool.Constructor == null)
                {
                    AGD.HTPool.Constructor = () => new double[(int)Round(RhoMax), (int)Round(NTheta)];
                }
            double[,] HTMatrix = AGD.HTPool.Acquire();
            int           NRd = HTMatrix.GetLength(0);
            int           NTh = HTMatrix.GetLength(1);
            int           i, j;
            List <Vector> HoughPowerul = AGD.VPool.Acquire();

            double StrongHoughTh = AGD.StrongHoughThreshold;

            float[] FData = null;

            /* Initialize skip controlling variables */
            int  StrongHoughReset        = 2 * AGD.ScanSkip + 1; /* Counter reset value, minimum to search Skip around found value */
            int  StrongHoughInnerCounter = 0;                    /* Inner loop counter */
            int  StrongHoughOuterCounter = 0;                    /* Outer loop counter */
            bool StrongHough             = false;

            /* For all distances */
            for (i = 0; i < NRd; i++)
            {
                /* Any relevant coordinates? */
                StrongHough = false;
                /* For all angles */
                for (j = 0; j < NTh; j++)
                {
                    /* Compute angle and skip irrelevant angles */
                    double Theta = j * ThetaUnit;
                    if (Theta > PI / 2)
                    {
                        if (Theta < PI)
                        {
                            continue;
                        }
                    }

                    /* Integrate along the line */
                    double Length;
                    if (AGD.SimpleLine)
                    {
                        SimpleLineover(Input, Height, Width, i, Theta, ImP, out HTMatrix[i, j], out Length, ref FData, AGD.LineSkip);
                    }
                    else
                    {
                        Lineover(Input, Height, Width, i, Theta, ImP, out HTMatrix[i, j], out Length);
                    }

                    /* If has a function dependent on the length */
                    if (AGD.StrongValueFunction != null)
                    {
                        StrongHoughTh = AGD.StrongValueFunction(Length);
                    }

                    /* If relevant coordinates */
                    if (Length != 0 && HTMatrix[i, j] > StrongHoughTh)
                    {
                        HoughPowerul.Add(new Vector()
                        {
                            X = i, Y = Theta
                        });

                        /* When new interesting coordinates, jump back and analyze */
                        if (StrongHoughInnerCounter == 0)
                        {
                            if (j > AGD.ScanSkip)
                            {
                                j -= AGD.ScanSkip;
                            }
                            else
                            {
                                j = 0;
                            }
                        }
                        /* Reset counter and notify outer loop */
                        StrongHoughInnerCounter = StrongHoughReset;
                        StrongHough             = true;
                    }
                    /* If no interesting points, skip angles and decrement counter */
                    else
                    {
                        if (StrongHoughInnerCounter == 0)
                        {
                            j += AGD.ScanSkip - 1;
                        }
                        else
                        {
                            StrongHoughInnerCounter--;
                        }
                    }
                }
                /* If no interesting points, skip radii and decrement counter */
                if (!StrongHough)
                {
                    if (StrongHoughOuterCounter == 0)
                    {
                        i += AGD.ScanSkip - 1;
                    }
                    else
                    {
                        StrongHoughOuterCounter--;
                    }
                }
                else
                {
                    /* New interesting coordinates, jump back and analyze */
                    if (StrongHoughOuterCounter == 0)
                    {
                        if (i > AGD.ScanSkip)
                        {
                            i -= AGD.ScanSkip;
                        }
                        else
                        {
                            i = 0;
                        }
                    }
                    /* Reset counter */
                    StrongHoughOuterCounter = StrongHoughReset;
                }
            }
            return(new HTResult()
            {
                StrongPoints = HoughPowerul, HTMatrix = HTMatrix
            });
        }
예제 #5
0
        static void Main(string[] args)
        {
            AlgorithmData  algData        = new AlgorithmData();
            AntlrConverter antlrConverter = new AntlrConverter();
            TokenConverter tc             = new TokenConverter();

            try
            {
                ObjectCache      cache        = MemoryCache.Default;
                var              cachedObject = cache["algoList"];
                List <BlockData> l_algoList   = null;
                if (cachedObject == null)
                {
                    l_algoList = algData.GetBlocks();

                    CacheItemPolicy policy = new CacheItemPolicy();
                    cachedObject = l_algoList;
                    cache.Set("algoList", cachedObject, policy);
                }
                else
                {
                    l_algoList = (List <BlockData>)cache.Get("algoList");
                }
                int count = 0;
                List <planFormulaInfo> l_planList = new List <planFormulaInfo>();
                foreach (var item in l_algoList)
                {
                    planFormulaInfo l_plan = null;
                    Console.WriteLine("Totlal count:" + l_algoList.Count());
                    BlockInfo l_blck = null;
                    if (item.planInfo != null)
                    {
                        foreach (var blck in item.planInfo.PlanFormula.ExpContent)
                        {
                            l_blck = antlrConverter.GetBlockInfo(blck.AntlrContent);
                            string l_err = tc.SetAntlr(l_blck);
                            l_plan = SetBlockStatements(l_blck, blck.AntlrContent, item.ruleId);
                            Console.WriteLine(blck.BlockName);
                            if (l_plan != null)
                            {
                                l_planList.Add(l_plan);
                            }
                        }
                    }
                    if (item.pricer != null)
                    {
                        foreach (var blck in item.pricer.PricerAlgorithm.ExpContent)
                        {
                            l_blck          = antlrConverter.GetBlockInfo(blck.AntlrContent);
                            l_blck.IsPricer = true;
                            string l_err = tc.SetAntlr(l_blck);
                            l_plan = SetBlockStatements(l_blck, blck.AntlrContent, item.ruleId);
                            if (l_plan != null)
                            {
                                l_planList.Add(l_plan);
                            }
                            Console.WriteLine(item.pricer.Name + " " + blck.BlockName);
                        }
                    }
                    if (item.formRules != null)
                    {
                        foreach (var blck in item.formRules.blockExponents)
                        {
                            l_blck = antlrConverter.GetBlockInfo(blck.AntlrContent);
                            string l_err = tc.SetAntlr(l_blck);
                            l_plan = SetBlockStatements(l_blck, blck.AntlrContent, item.ruleId);
                            Console.WriteLine(item.formRules.formulaeName + " - " + blck.BlockName);
                            if (l_plan != null)
                            {
                                l_planList.Add(l_plan);
                            }
                        }
                    }
                    count++;

                    Console.WriteLine(count);
                }
                algData.SaveBlock(l_planList);
                Console.WriteLine("Block validation finished");
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Block validation failed");
            }
        }