// // Private methods // private LongestPath.NodeInfo GetNodeInfo(Node <uint> tree) { var nodeInfo = LongestPath.GetNodeInfo(tree); _output.WriteLine($"MaxIncreasingPathLengthToRoot={nodeInfo.MaxIncPathLenToRoot}"); _output.WriteLine($"MaxDecreasingPathLengthToRoot={nodeInfo.MaxDecPathLenToRoot}"); _output.WriteLine($"MaxPathLength={nodeInfo.MaxPathLen}"); return(nodeInfo); }
public void longestPathTest() { var l = new LongestPath(); Assert.AreEqual(24, l.longestPath("user\r\tpictures\r\tdocuments\r\t\tnotes.txt")); Assert.AreEqual(33, l.longestPath("user\r\tpictures\r\t\tphoto.png\r\t\tcamera\r\tdocuments\r\t\tlectures\r\t\t\tnotes.txt")); Assert.AreEqual(0, l.longestPath("a")); Assert.AreEqual(5, l.longestPath("a.txt")); Assert.AreEqual(8, l.longestPath("a.tar.gz")); Assert.AreEqual(10, l.longestPath("ReadME.TXT")); Assert.AreEqual(25, l.longestPath("file name with space.txt")); Assert.AreEqual(0, l.longestPath("a\r\tb\r\t\tc")); Assert.AreEqual(9, l.longestPath("a\r\tb\r\t\tc.txt")); Assert.AreEqual(12, l.longestPath("dir\r file.txt")); Assert.AreEqual(16, l.longestPath("dir\r\t\tfile.txt")); Assert.AreEqual(20, l.longestPath("dir\r\t\t\tfile.txt\r\tfile2.txt")); Assert.AreEqual(14, l.longestPath("a\r\tb1\r\t\tf1.txt\r\taaaaa\r\t\tf2.txt")); }
protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout) { var layoutData = new HierarchicLayoutData(); var incrementalLayout = SelectedElementsIncrementallyItem; var selection = graphControl.Selection; var selectedElements = selection.SelectedEdges.Any() || selection.SelectedNodes.Any(); if (incrementalLayout && selectedElements) { // configure the mode var ihf = ((HierarchicLayout)layout).CreateIncrementalHintsFactory(); layoutData.IncrementalHints.Delegate = item => { // Return the correct hint type for each model item that appears in one of these sets if (item is INode && selection.IsSelected(item)) { return(ihf.CreateLayerIncrementallyHint(item)); } if (item is IEdge && selection.IsSelected(item)) { return(ihf.CreateSequenceIncrementallyHint(item)); } return(null); }; } if (RankingPolicyItem == LayeringStrategy.Bfs) { layoutData.BfsLayererCoreNodes.Delegate = selection.IsSelected; } if (GridEnabledItem) { var nld = ((HierarchicLayout)layout).NodeLayoutDescriptor; layoutData.NodeLayoutDescriptors.Delegate = node => { var descriptor = new NodeLayoutDescriptor(); descriptor.LayerAlignment = nld.LayerAlignment; descriptor.MinimumDistance = nld.MinimumDistance; descriptor.MinimumLayerHeight = nld.MinimumLayerHeight; descriptor.NodeLabelMode = nld.NodeLabelMode; // anchor nodes on grid according to their alignment within the layer descriptor.GridReference = new YPoint(0.0, (nld.LayerAlignment - 0.5) * node.Layout.Height); descriptor.PortAssignment = this.GridPortAssignmentItem; return(descriptor); }; } if (EdgeDirectednessItem) { layoutData.EdgeDirectedness.Delegate = edge => { if (edge.Style is IArrowOwner && !Equals(((IArrowOwner)edge.Style).TargetArrow, Arrows.None)) { return(1); } return(0); }; } if (EdgeThicknessItem) { layoutData.EdgeThickness.Delegate = edge => { var style = edge.Style as PolylineEdgeStyle; if (style != null) { return(style.Pen.Thickness); } return(1); }; } if (SubComponentsItem) { // layout all siblings with label 'TL' separately with tree layout var treeLayout = new TreeLayout { DefaultNodePlacer = new LeftRightNodePlacer() }; foreach (var listOfNodes in FindSubComponents(graphControl.Graph, "TL")) { layoutData.SubComponents.Add(treeLayout).Items = listOfNodes; } // layout all siblings with label 'HL' separately with hierarchical layout var hierarchicLayout = new HierarchicLayout { LayoutOrientation = LayoutOrientation.LeftToRight }; foreach (var listOfNodes in FindSubComponents(graphControl.Graph, "HL")) { layoutData.SubComponents.Add(hierarchicLayout).Items = listOfNodes; } // layout all siblings with label 'OL' separately with organic layout var organicLayout = new OrganicLayout { PreferredEdgeLength = 100, Deterministic = true }; foreach (var listOfNodes in FindSubComponents(graphControl.Graph, "OL")) { layoutData.SubComponents.Add(organicLayout).Items = listOfNodes; } } if (HighlightCriticalPath) { // highlight the longest path in the graph as critical path // since the longest path algorithm only works for acyclic graphs, // feedback edges and self loops have to be excluded here var feedbackEdgeSetResult = new FeedbackEdgeSet().Run(graphControl.Graph); var longestPath = new LongestPath { SubgraphEdges = { Excludes = { Delegate = edge => feedbackEdgeSetResult.FeedbackEdgeSet.Contains(edge) || edge.IsSelfloop() } } }.Run(graphControl.Graph); if (longestPath.Edges.Any()) { layoutData.CriticalEdgePriorities.Delegate = edge => { if (longestPath.Edges.Contains(edge)) { return(10); } return(1); }; } } if (AutomaticBusRouting) { var allBusNodes = new HashSet <INode>(); foreach (var node in graphControl.Graph.Nodes) { if (!graphControl.Graph.IsGroupNode(node) && !allBusNodes.Contains(node)) { // search for good opportunities for bus structures rooted at this node if (graphControl.Graph.InDegree(node) >= 4) { var busDescriptor = new BusDescriptor(); var busEdges = GetBusEdges(graphControl.Graph, node, allBusNodes, graphControl.Graph.InEdgesAt(node)); if (busEdges.Any()) { layoutData.Buses.Add(busDescriptor).Items = busEdges; } } if (graphControl.Graph.OutDegree(node) >= 4) { var busDescriptor = new BusDescriptor(); var busEdges = GetBusEdges(graphControl.Graph, node, allBusNodes, graphControl.Graph.OutEdgesAt(node)); if (busEdges.Any()) { layoutData.Buses.Add(busDescriptor).Items = busEdges; } } } } } return(layoutData.CombineWith( CreateLabelingLayoutData( graphControl.Graph, LabelPlacementAlongEdgeItem, LabelPlacementSideOfEdgeItem, LabelPlacementOrientationItem, LabelPlacementDistanceItem ) )); }