Ejemplo n.º 1
0
        public Symbol(
            double xMin,
            double xMax,
            double yMin,
            double yMax,
            int cast,
            double delta,
            double a   = 0,
            double b   = 0,
            int width  = 640,
            int height = 480
            )
        {
            _xMax   = xMax;
            _xMin   = xMin;
            _yMax   = yMax;
            _yMin   = yMin;
            _cast   = cast;
            _delta  = delta;
            _a      = a;
            _b      = b;
            _width  = width;
            _height = height;

            _rows = (int)((double)(yMax - yMin) / delta);
            _cols = (int)((double)(xMax - xMin) / delta);

            _numberOfCells = _rows * _cols;
            _graph         = new SymbolGraph(_numberOfCells);


            _cast_square = (int)Math.Ceiling(Math.Sqrt((double)_cast));
        }
Ejemplo n.º 2
0
        public List <List <int> > FindStrongConnectedComponents(bool isTopologySort = false)
        {
            List <int> order = TopologySort();

            bool[] used = new bool[_numberOfCells];
            //var used = new List<int>();

            SymbolGraph        tGraph     = TransposeGraph();
            List <List <int> > components = new List <List <int> >();

            Func <int, List <int> > depthFirstSearch = null;



            depthFirstSearch = start =>
            {
                var component = new List <int>();

                Stack <int> stack = new Stack <int>();

                stack.Push(start);

                while (stack.Count != 0)
                {
                    int v = stack.Pop();
                    used[v] = true;
                    component.Add(v);

                    if (tGraph[v] != null)
                    {
                        for (int i = 0; i < tGraph[v].Count; i++)
                        {
                            int g = tGraph[v][i];
                            if (!used[g])
                            {
                                stack.Push(g);
                            }
                        }
                    }
                }
                return(component);
            };

            //Parallel.For(0, _numberOfCells, (i, state) => { used[i] = false; });

            foreach (var v in order)
            {
                if (!used[v] && tGraph.Contains(v))
                {
                    List <int> component = depthFirstSearch(v);

                    if (component.Count > 1 || isTopologySort)
                    {
                        components.Add(component);
                    }
                }
            }

            return(components);
        }
Ejemplo n.º 3
0
        private SymbolGraph TransposeGraph()
        {
            SymbolGraph tGraph = new SymbolGraph(_numberOfCells);

            foreach (KeyValuePair <int, List <int> > i in Graph.keyValuePairs)
            {
                foreach (var v in i.Value)
                {
                    if (!tGraph.Contains(v))
                    {
                        tGraph[v] = new List <int>();
                    }
                    if (!tGraph[v].Contains(i.Key))
                    {
                        tGraph[v].Add(i.Key);
                    }
                }
            }

            return(tGraph);
        }
Ejemplo n.º 4
0
        public List <List <int> > MakeNewGraph(int n, List <List <int> > components)
        {
            int oldCols = _cols;


            //List<int> component = FindMaxComponent(components);
            for (int i = 0; i < n; i++)
            {
                _numberOfCells *= 4;
                _cols          *= 2;
                _delta         *= 0.5;
                _rows          *= 2;
                SymbolGraph graph = new SymbolGraph(_numberOfCells);

                foreach (var component in components)
                {
                    Parallel.ForEach(component, (c) =>
                                     //foreach(var c in component)
                    {
                        int[] cells = NewCoords(c, oldCols);

                        for (int m = 0; m < 4; m++)
                        {
                            double x, y;
                            ReturnInterval(cells[m], out x, out y);

                            for (int l = 0; l < _cast_square - 1; l++)
                            //Parallel.For(0, _cast, (l, state) =>
                            {
                                for (int d = 0; d < _cast_square - 1; d++)
                                {
                                    double xn = x + (double)l * _delta / (double)_cast_square;
                                    double yn = y - (double)d * _delta / (double)_cast_square;


                                    int cell = ReturnCell(xn, yn);

                                    if (cell == -1)
                                    {
                                        continue;
                                    }
                                    if (cell >= _numberOfCells)
                                    {
                                        continue;
                                    }

                                    int oldCell = OldCoordSystem(cell, oldCols);

                                    if (!Graph.Contains(oldCell))
                                    {
                                        continue;
                                    }

                                    if (!graph.Contains(cells[m]))
                                    {
                                        graph[cells[m]] = new List <int>();
                                    }

                                    if (graph[cells[m]] != null && !graph[cells[m]].Contains(cell))
                                    {
                                        graph[cells[m]].Add(cell);
                                    }
                                }
                            }
                        }
                    });
                    _graph = graph;
                }
                ;
                components = FindStrongConnectedComponents();
                oldCols    = _cols;
            }

            return(components);
        }