Esempio n. 1
0
		public bool Arrange(IGraph graph, GridLayoutInfo info)
		{
			return Arrange(graph, info, null);
		}
Esempio n. 2
0
 public bool Arrange(IGraph graph, GridLayoutInfo info)
 {
     return(Arrange(graph, info, null));
 }
Esempio n. 3
0
		public bool Arrange(IGraph graph,
			GridLayoutInfo info, LayoutProgress progress)
		{
			_graph = new Graph(graph);
			_info = info;

			if (_info.RndSeed != 0)
			{
				// Use the randomization seed supplied by the user
				_random = new Random(_info.RndSeed);
			}

			Path path = null;

			// Find the longest path between the start and the end node
			if (_info.StartNode != null && _info.EndNode != null)
			{
				path = PathFinder.FindLongestPath(graph, _info.StartNode, _info.EndNode);
			}
			else
			{
				path = PathFinder.FindLongestPath(graph);
			}

			if (path == null)
				return false;

			// Build path consisting of the corresponding GraphNode-s
			_backbone = new ArrayList();
			foreach (INode inode in path.Nodes)
			{
				foreach (GraphNode node in _graph.Nodes)
				{
					if (node.Node == inode)
					{
						_backbone.Add(node);
						break;
					}
				}
			}

			GraphNode[,] bestGrid = InitGrid();
			float bestEstimation = float.MaxValue;
			int maxShift = Math.Max(4, _gridWidth / 10); 

			// Update progress
			int current = 0;
			int total = CountIterations(maxShift);
			float ffactor = total / 100;
			int factor = 1;
			if (ffactor > 1)
			{
				factor = (int)Math.Floor((double)ffactor);
				total = total / factor + 1;
			}
			if (progress != null)
				progress(current, total);

			while (maxShift > 0)
			{
				for (int iter = 0;
					iter < (maxShift > 2 ?
						_info.Iterations :
						(_info.Iterations / 5 * maxShift * _graph.Nodes.Count));
					++iter)
				{
					// Update progress
					if (progress != null)
					{
						if (current % factor == 0)
							progress(current / factor, total);
						current++;
					}

					GraphNode[,] grid = ScrambleGrid(bestGrid, maxShift, iter);
					float estimation = EvaluateGrid(grid, maxShift);

					if (estimation < bestEstimation)
					{
						bestEstimation = estimation;
						bestGrid = grid;
					}
					else
					{
						ApplyGrid(bestGrid);
					}
				}

				maxShift--;
			}

			PlaceObjects(bestGrid);

			// Update progress
			if (progress != null)
				progress(total, total);

			return true;
		}
Esempio n. 4
0
        public bool Arrange(IGraph graph,
                            GridLayoutInfo info, LayoutProgress progress)
        {
            _graph = new Graph(graph);
            _info  = info;

            if (_info.RndSeed != 0)
            {
                // Use the randomization seed supplied by the user
                _random = new Random(_info.RndSeed);
            }

            Path path = null;

            // Find the longest path between the start and the end node
            if (_info.StartNode != null && _info.EndNode != null)
            {
                path = PathFinder.FindLongestPath(graph, _info.StartNode, _info.EndNode);
            }
            else
            {
                path = PathFinder.FindLongestPath(graph);
            }

            if (path == null)
            {
                return(false);
            }

            // Build path consisting of the corresponding GraphNode-s
            _backbone = new ArrayList();
            foreach (INode inode in path.Nodes)
            {
                foreach (GraphNode node in _graph.Nodes)
                {
                    if (node.Node == inode)
                    {
                        _backbone.Add(node);
                        break;
                    }
                }
            }

            GraphNode[,] bestGrid = InitGrid();
            float bestEstimation = float.MaxValue;
            int   maxShift       = Math.Max(4, _gridWidth / 10);

            // Update progress
            int   current = 0;
            int   total   = CountIterations(maxShift);
            float ffactor = total / 100;
            int   factor  = 1;

            if (ffactor > 1)
            {
                factor = (int)Math.Floor((double)ffactor);
                total  = total / factor + 1;
            }
            if (progress != null)
            {
                progress(current, total);
            }

            while (maxShift > 0)
            {
                for (int iter = 0;
                     iter < (maxShift > 2 ?
                             _info.Iterations :
                             (_info.Iterations / 5 * maxShift * _graph.Nodes.Count));
                     ++iter)
                {
                    // Update progress
                    if (progress != null)
                    {
                        if (current % factor == 0)
                        {
                            progress(current / factor, total);
                        }
                        current++;
                    }

                    GraphNode[,] grid = ScrambleGrid(bestGrid, maxShift, iter);
                    float estimation = EvaluateGrid(grid, maxShift);

                    if (estimation < bestEstimation)
                    {
                        bestEstimation = estimation;
                        bestGrid       = grid;
                    }
                    else
                    {
                        ApplyGrid(bestGrid);
                    }
                }

                maxShift--;
            }

            PlaceObjects(bestGrid);

            // Update progress
            if (progress != null)
            {
                progress(total, total);
            }

            return(true);
        }