├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── Sandwych.QuickGraph.sln ├── Shared.props ├── appveyor.yml ├── build.cake ├── build.ps1 ├── build.sh ├── docs ├── .gitignore ├── api │ ├── .gitignore │ └── index.md ├── articles │ ├── intro.md │ └── toc.yml ├── docfx.json ├── index.md └── toc.yml ├── src ├── Directory.Build.props ├── Sandwych.QuickGraph.Core │ ├── AdjacencyGraph.cs │ ├── Algorithms │ │ ├── AlgorithmBase.cs │ │ ├── AlgorithmEventHandler.cs │ │ ├── AlgorithmExtensions.cs │ │ ├── CentralityApproximationAlgorithm.cs │ │ ├── Cliques │ │ │ ├── BronKerboshMaximumCliqueAlgorithm.cs │ │ │ ├── MaximumCliqueAlgorithmBase.cs │ │ │ └── ncliques.pdf │ │ ├── ComputationState.cs │ │ ├── Condensation │ │ │ ├── CondensationGraphAlgorithm.cs │ │ │ ├── CondensedEdge.cs │ │ │ ├── EdgeMergeCondensationGraphAlgorithm.cs │ │ │ └── MergedEdge.cs │ │ ├── ConnectedComponents │ │ │ ├── ConnectedComponentsAlgorithm.cs │ │ │ ├── IncrementalConnectedComponentsAlgorithm.cs │ │ │ ├── StronglyConnectedComponentAlgorithm.cs │ │ │ └── WeaklyConnectedComponentsAlgorithm.cs │ │ ├── Contracts │ │ │ ├── IAlgorithmContract.cs │ │ │ └── IComputationContract.cs │ │ ├── DistanceRelaxers.cs │ │ ├── EulerianTrailAlgorithm.cs │ │ ├── Exploration │ │ │ ├── CloneableVertexGraphExplorerAlgorithm.cs │ │ │ ├── ITransitionFactory.cs │ │ │ └── TransitionFactoryImplicitGraph.cs │ │ ├── IAlgorithm.cs │ │ ├── IComputation.cs │ │ ├── IConnectedComponentAlgorithm.cs │ │ ├── IDistanceRecorderAlgorithm.cs │ │ ├── IDistanceRelaxer.cs │ │ ├── IEdgeColorizerAlgorithm.cs │ │ ├── IEdgePredecessorRecorderAlgorithm.cs │ │ ├── IEndPathEdgeRecorderAlgorithm.cs │ │ ├── ITreeBuilderAlgorithm.cs │ │ ├── IUndirectedTreeBuilderAlgorithm.cs │ │ ├── IUndirectedVertexPredecessorRecorderAlgorithm.cs │ │ ├── IVertexColorizerAlgorithm.cs │ │ ├── IVertexPredecessorRecorderAlgorithm.cs │ │ ├── IVertexTimeStamperAlgorithm.cs │ │ ├── LengauerTarjanDominatorAlgorithm.cs │ │ ├── MaximumBipartiteMatchingAlgorithm.cs │ │ ├── MaximumFlow │ │ │ ├── AllVerticesGraphAugmentorAlgorithm.cs │ │ │ ├── BipartiteToMaximumFlowGraphAugmentorAlgorithm.cs │ │ │ ├── EdmondsKarpMaximumFlowAlgorithm.cs │ │ │ ├── GraphAugmentorAlgorithmBase.cs │ │ │ ├── GraphBalancingAlgorithm.cs │ │ │ ├── MaximumFlowAlgorithmBase.cs │ │ │ ├── MultiSourceSinkGraphAugmentorAlgorithm.cs │ │ │ └── ReverseEdgeAugmentorAlgorithm.cs │ │ ├── MinimumSpanningTree │ │ │ ├── IMinimumSpanningTreeAlgorithm.cs │ │ │ └── KruskalMinimumSpanningTreeAlgorithm.cs │ │ ├── Observers │ │ │ ├── Contracts │ │ │ │ └── IObserverContract.cs │ │ │ ├── DisposableAction.cs │ │ │ ├── EdgePredecessorRecorderObserver.cs │ │ │ ├── EdgeRecorderObserver.cs │ │ │ ├── IObserver.cs │ │ │ ├── UndirectedVertexDistanceRecorderObserver.cs │ │ │ ├── UndirectedVertexPredecessorRecorderObserver.cs │ │ │ ├── VertexDistanceRecorderObserver.cs │ │ │ ├── VertexPredecessorPathRecorderObserver.cs │ │ │ ├── VertexPredecessorRecorderObserver.cs │ │ │ ├── VertexRecorderObserver.cs │ │ │ └── VertexTimeStamperObserver.cs │ │ ├── PageRankAlgorithm.cs │ │ ├── RandomGraphFactory.cs │ │ ├── RandomWalks │ │ │ ├── CyclePoppingRandomTreeAlgorithm.cs │ │ │ ├── IEdgeChain.cs │ │ │ ├── IMarkovEdgeChain.cs │ │ │ ├── MarkovEdgeChainBase.cs │ │ │ ├── NormalizedMarkovEdgeChain.cs │ │ │ ├── RandomWalkAlgorithm.cs │ │ │ ├── RoundRobinEdgeChain.cs │ │ │ ├── VanishingWeightedMarkovEdgeChain.cs │ │ │ ├── WeightedMarkedEdgeChain.cs │ │ │ └── WeightedMarkovEdgeChainBase.cs │ │ ├── RankedShortestPath │ │ │ ├── HoffmanPavleyRankedShortestPathAlgorithm.cs │ │ │ └── RankedShortestPathAlgorithmBase.cs │ │ ├── RootedAlgorithmBase.cs │ │ ├── RootedSearchAlgorithmBase.cs │ │ ├── Search │ │ │ ├── BestFirstFrontierSearchAlgorithm.cs │ │ │ ├── BidirectionalDepthFirstSearchAlgorithm.cs │ │ │ ├── BreadthFirstSearchAlgorithm.cs │ │ │ ├── DepthFirstSearchAlgorithm.cs │ │ │ ├── EdgeDepthFirstSearchAlgorithm.cs │ │ │ ├── ImplicitDepthFirstSearchAlgorithm.cs │ │ │ ├── ImplicitEdgeDepthFirstSearchAlgorithm.cs │ │ │ ├── UndirectedBreathFirstSearchAlgorithm.cs │ │ │ └── UndirectedDepthFirstSearchAlgorithm.cs │ │ ├── Services │ │ │ ├── IAlgorithmComponent.cs │ │ │ ├── IAlgorithmServices.cs │ │ │ ├── ICancelManager.cs │ │ │ └── IService.cs │ │ ├── ShortestPath │ │ │ ├── AStartShortestPathAlgorithm.cs │ │ │ ├── BellmanFordShortestPathAlgorithm.cs │ │ │ ├── DagShortestPathAlgorithm.cs │ │ │ ├── DijkstraShortestPathAlgorithm.cs │ │ │ ├── FloydWarshallAllShortestPathAlgorithm.cs │ │ │ ├── ShortestPathAlgorithmBase.cs │ │ │ ├── UndirectedDijkstraShortestPathAlgorithm.cs │ │ │ └── UndirectedShortestPathAlgorithmBase.cs │ │ ├── TarjanOfflineLeastCommonAncestorAlgorithm.cs │ │ └── TopologicalSort │ │ │ ├── SourceFirstTopologicalSortAlgorithm.cs │ │ │ ├── TopologicalSortAlgorithm.cs │ │ │ ├── UndirectedFirstTopologicalSortAlgorithm.cs │ │ │ └── UndirectedTopologicalSortAlgorithm.cs │ ├── ArrayAdjacencyGraph.cs │ ├── ArrayBidirectionalGraph.cs │ ├── ArrayUndirectedGraph.cs │ ├── BidirectionAdapterGraph.cs │ ├── BidirectionalGraph.cs │ ├── BidirectionalMatrixGraph.cs │ ├── Collections │ │ ├── BinaryHeap.cs │ │ ├── BinaryQueue.cs │ │ ├── EdgeEdgeDictionary.cs │ │ ├── EdgeList.cs │ │ ├── FibonacciHeap.cs │ │ ├── FibonacciQueue.cs │ │ ├── ForestDisjointSet.cs │ │ ├── IDisjointSet.cs │ │ ├── IEdgeList.cs │ │ ├── IPriorityQueue.cs │ │ ├── IQueue.cs │ │ ├── IVertexEdgeDictionary.cs │ │ ├── Queue.cs │ │ ├── SoftHeap.cs │ │ ├── VertexEdgeDictionary.cs │ │ └── VertexList.cs │ ├── CompressedSparseRowGraph.cs │ ├── Contracts │ │ ├── Collections │ │ │ ├── IDisjointSetContract.cs │ │ │ ├── IEdgeListContract.cs │ │ │ └── IVertexEdgeDictionaryContract.cs │ │ ├── DummyContract.cs │ │ ├── EnumerableContract.cs │ │ ├── GraphContract.cs │ │ ├── IBidirectionalGraphContract.cs │ │ ├── IBidirectionalIncidenceGraphContract.cs │ │ ├── ICloneableEdgeContract.cs │ │ ├── IEdgeContract.cs │ │ ├── IEdgeListGraphContract.cs │ │ ├── IEdgeSetContract.cs │ │ ├── IGraphContract.cs │ │ ├── IImplicitGraphContract.cs │ │ ├── IImplicitUndirectedGraphContract.cs │ │ ├── IImplicitVertexSetContract.cs │ │ ├── IIncidenceGraphContract.cs │ │ ├── IMutableBidirectionalGraphContract.cs │ │ ├── IMutableEdgeListGraphContract.cs │ │ ├── IMutableGraphContract.cs │ │ ├── IMutableIncidenceGraphContract.cs │ │ ├── IMutableUndirectedGraphContract.cs │ │ ├── IMutableVertexAndEdgeSetContract.cs │ │ ├── IMutableVertexListGraphContract.cs │ │ ├── IMutableVertexSetContract.cs │ │ ├── IUndirectedEdgeContract.cs │ │ ├── IUndirectedGraphContract.cs │ │ └── IVertexSetContract.cs │ ├── CreateEdgeDelegate.cs │ ├── CreateVertexDelegate.cs │ ├── DelegateBidirectionalIncidenceGraph.cs │ ├── DelegateImplicitGraph.cs │ ├── DelegateImplicitUndirectedGraph.cs │ ├── DelegateIncidenceGraph.cs │ ├── DelegateUndirectedGraph.cs │ ├── DelegateVertexAndEdgeListGraph.cs │ ├── Directory.Build.props │ ├── Edge.cs │ ├── EdgeEdgeEventArgs.cs │ ├── EdgeEventArgs.cs │ ├── EdgeExtensions.cs │ ├── EdgeFactory.cs │ ├── EdgeIdentity.cs │ ├── EdgeListGraph.cs │ ├── EdgePredicate.cs │ ├── Enumerable.cs │ ├── EquatableEdge.cs │ ├── FuncDelegates.cs │ ├── GraphColor.cs │ ├── GraphExtensions.cs │ ├── HashCodeHelper.cs │ ├── IBidirectionalGraph.cs │ ├── IBidirectionalIncidenceGraph.cs │ ├── ICloneableEdge.cs │ ├── IEdge.cs │ ├── IEdgeListAndIncidenceGraph.cs │ ├── IEdgeListGraph.cs │ ├── IEdgeSet.cs │ ├── IGraph.cs │ ├── IHierarchy.cs │ ├── IHyperEdge.cs │ ├── IImplicitGraph.cs │ ├── IImplicitUndirectedGraph.cs │ ├── IImplicitVertexSet.cs │ ├── IIncidenceGraph.cs │ ├── IMutableBidirectionalGraph.cs │ ├── IMutableEdgeListGraph.cs │ ├── IMutableGraph.cs │ ├── IMutableIncidenceGraph.cs │ ├── IMutableUndirectedGraph.cs │ ├── IMutableVertexAndEdgeListGraph.cs │ ├── IMutableVertexAndEdgeSet.cs │ ├── IMutableVertexListGraph.cs │ ├── IMutableVertexSet.cs │ ├── ITagged.cs │ ├── IUndirectedEdge.cs │ ├── IUndirectedGraph.cs │ ├── IVertexAndEdgeListGraph.cs │ ├── IVertexListGraph.cs │ ├── IVertexSet.cs │ ├── IdentifiableEdgeFactory.cs │ ├── IdentifiableVertexFactory.cs │ ├── NegativeCycleGraphException.cs │ ├── NegativeWeightException.cs │ ├── NonAcyclicGraphException.cs │ ├── NonStronglyConnectedGraphException.cs │ ├── ParallelEdgeNotAllowedException.cs │ ├── Predicates │ │ ├── FilteredBidirectionalGraph.cs │ │ ├── FilteredEdgeListGraph.cs │ │ ├── FilteredGraph.cs │ │ ├── FilteredImplicitGraph.cs │ │ ├── FilteredImplicitVertexSetGraph.cs │ │ ├── FilteredIncidenceGraph.cs │ │ ├── FilteredUndirectedGraph.cs │ │ ├── FilteredVertexAndEdgeListGraph.cs │ │ ├── FilteredVertexListGraph.cs │ │ ├── InDictionaryVertexPredicate.cs │ │ ├── IsolatedVertexPredicate.cs │ │ ├── ResidualEdgePrediate.cs │ │ ├── ReversedResidualEdgePredicate.cs │ │ └── SinkVertexPredicate.cs │ ├── QuickGraphException.cs │ ├── ReversedBidirectionalListGraph.cs │ ├── SEdge.cs │ ├── SEquatableEdge.cs │ ├── SEquatableUndirectedEdge.cs │ ├── SReversedEdge.cs │ ├── STaggedEdge.cs │ ├── STaggedEquatableEdge.cs │ ├── STaggedUndirectedEdge.cs │ ├── SUndirectedEdge.cs │ ├── Sandwych.QuickGraph.Core.csproj │ ├── TaggedEdge.cs │ ├── TaggedEquatableEdge.cs │ ├── TaggedUndirectedEdge.cs │ ├── TryFuncDelegates.cs │ ├── UndirectedBidirectionalGraph.cs │ ├── UndirectedEdge.cs │ ├── UndirectedEdgeEventArgs.cs │ ├── UndirectedGraph.cs │ ├── VertexEventArgs.cs │ ├── VertexFactory.cs │ ├── VertexIdentity.cs │ ├── VertexIndexer.cs │ └── VertexPredicate.cs ├── Sandwych.QuickGraph.Data │ ├── DataRelationEdge.cs │ ├── DataSetGraph.cs │ ├── DataSetGraphExtensions.cs │ ├── DataSetGraphPopulatorAlgorithm.cs │ ├── DataSetGraphvizAlgorithm.cs │ └── Sandwych.QuickGraph.Data.csproj ├── Sandwych.QuickGraph.Graphviz │ ├── CondensatedGraphRenderer.cs │ ├── Dot │ │ ├── GraphvizArrow.cs │ │ ├── GraphvizArrowClipping.cs │ │ ├── GraphvizArrowFilling.cs │ │ ├── GraphvizArrowShape.cs │ │ ├── GraphvizClusterMode.cs │ │ ├── GraphvizColor.cs │ │ ├── GraphvizEdge.cs │ │ ├── GraphvizEdgeDirection.cs │ │ ├── GraphvizEdgeExtremity.cs │ │ ├── GraphvizEdgeLabel.cs │ │ ├── GraphvizEdgeStyle.cs │ │ ├── GraphvizFont.cs │ │ ├── GraphvizGraph.cs │ │ ├── GraphvizImageType.cs │ │ ├── GraphvizLabelJustification.cs │ │ ├── GraphvizLabelLocation.cs │ │ ├── GraphvizLayer.cs │ │ ├── GraphvizLayerCollection.cs │ │ ├── GraphvizOutputMode.cs │ │ ├── GraphvizPageDirection.cs │ │ ├── GraphvizPoint.cs │ │ ├── GraphvizRankDirection.cs │ │ ├── GraphvizRatioMode.cs │ │ ├── GraphvizRecord.cs │ │ ├── GraphvizRecordCell.cs │ │ ├── GraphvizRecordCellCollection.cs │ │ ├── GraphvizRecordEscaper.cs │ │ ├── GraphvizSize.cs │ │ ├── GraphvizVertex.cs │ │ ├── GraphvizVertexShape.cs │ │ └── GraphvizVertexStyle.cs │ ├── EdgeMergeCondensatedGraphRenderer.cs │ ├── FormatEdgeEventArgs.cs │ ├── FormatVertexEventArgs.cs │ ├── GraphRendererBase.cs │ ├── GraphvizAlgorithm.cs │ ├── GraphvizExtensions.cs │ ├── IDotEngine.cs │ ├── Sandwych.QuickGraph.Graphviz.csproj │ └── SvgHtmlWrapper.cs └── Sandwych.QuickGraph.Serialization │ ├── DirectedGraphML │ └── Dgml.cs │ ├── DirectedGraphMLAlgorithm.cs │ ├── DirectedGraphMLExtensions.cs │ ├── GraphMLDeserializer.cs │ ├── GraphMLExtensions.cs │ ├── GraphMLSerializer.cs │ ├── GraphMLXmlResolver.cs │ ├── Sandwych.QuickGraph.Serialization.csproj │ ├── SerializationExtensions.cs │ ├── SerializationHelper.cs │ ├── SerializerBase.cs │ ├── XmlSerializableGraphBase.cs │ ├── graphml-structure.xsd │ ├── graphml.dtd │ └── graphml.xsd └── test └── Sandwych.QuickGraph.Tests ├── Algorithms ├── AlgorithmExtensionsTest.cs ├── Condensation │ ├── StronglyConnectedCondensationGraphAlgorithmTest.cs │ └── WeaklyConnectedCondensationGraphTest.cs ├── ConnectedComponents │ ├── ConnectedComponentsAlgorithmTest.cs │ ├── IncrementalConnectedComponentsAlgorithmTest.cs │ └── WeaklyConnectedComponentsAlgorithmTest.cs ├── EulerianTrailAlgorithmTest.cs ├── MaximumBipartiteMatchingAlgorithmTest.cs ├── MaximumFlow │ ├── AllVerticesGraphAugmentorAlgorithmTest.cs │ └── EdmondsKarpMaximumFlowAlgorithmTest.cs ├── MinimumSpanningTree │ └── MinimumSpanningTreeTest.cs ├── RandomWalks │ ├── CyclePoppingRandomTreeAlgorithmTest.cs │ ├── EdgeChainTest.cs │ └── RandomWalkAlgorithmTest.cs ├── RankedShortestPath │ └── HoffmanPavleyRankedShortestPathAlgorithmTest.cs ├── Search │ ├── BestFirstFrontierSearchAlgorithmTest.cs │ ├── BidirectionalDepthFirstSearchAlgorithmTest.cs │ ├── BreadthFirstSearchAlgirthmTest.cs │ ├── DepthFirstSearchAlgorithmTest.cs │ ├── ParallelBreadthFirstSearchAlgirthmTest.cs │ ├── UndirectedBreathFirstSearchAlgorithmTest.cs │ └── UndirectedDepthFirstSearchAlgorithmTest.cs ├── ShortestPath │ ├── AStarShortestPathAlgorithmTest.cs │ ├── BellmanFordShortestPathTest.cs │ ├── DagShortestPathAlgorithmTest.cs │ ├── DijkstraShortestPathAlgorithmTest.cs │ ├── FloydWarshallAllPairShortestPathAlgorithmTest.cs │ └── UndirectedDijkstraShortestPathAlgorithmTest.cs ├── SourceFirstTopologicalSortAlgorithmTest.cs ├── StronglyConnectedComponentsAlgorithmTest.cs ├── TarjanOfflineLeastCommonAncestorAlgorithmTest.cs ├── TopologicalSortAlgorithmTest.cs ├── UndirectedFirstTopologicalSortAlgorithmTest.cs └── UndirectedTopologicalSortAlgorithmTest.cs ├── Collections ├── BinaryHeapTest.cs ├── FibonacciHeapTest.cs ├── ForestDisjointSetTTest.cs └── SoftHeapTTest.cs ├── DataStructureTest.cs ├── DegreeTest.cs ├── EdgeExtensionsTest.cs ├── EdgeListGraphInvariant.cs ├── EdgeTVertexTest.cs ├── Factories ├── AdjacencyGraphFactory.cs ├── ArrayAdjacencyGraphFactory.cs ├── EdgeFactory.cs ├── FibonacciHeapFactory.cs ├── ForestDisjointSetFactory.cs ├── StringVertexFactory.cs └── UndirectedGraphFactory.cs ├── GraphConsoleSerializer.cs ├── GraphDataAttribute.cs ├── MutableVertexAndEdgeListGraphTest.cs ├── Regression ├── DijkstraTest.cs ├── HoffmanPavleyTest.cs └── ShortestPathBellmanFordTest.cs ├── Sandwych.QuickGraph.Tests.csproj ├── Serialization ├── DirectedGraphMLExtensionsTest.cs ├── GraphMLSerializerTest.cs ├── GraphMLSerializerWithArgumentsTest.cs ├── Repro13428.cs ├── SystemSerializationTest.cs ├── TestGraphFactory.cs └── XmlSerializationTest.cs ├── TaggedEdgeTVertexTTagTest.cs ├── TestCategories.cs ├── TestConsole.cs ├── TestHelper.cs ├── UndirectedGraphInvariant.cs └── graphml ├── g.100.1.graphml ├── g.100.3.graphml ├── g.57.26.graphml ├── g.57.27.graphml ├── g.64.18.graphml ├── g.66.6.graphml ├── g.79.7.graphml ├── g.80.6.graphml ├── g.81.16.graphml ├── g.81.9.graphml ├── g.82.1.graphml ├── g.86.3.graphml ├── repro12273.xml └── repro12359.graphml /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | Bin 4 | obj 5 | BenchmarkDotNet.Artifacts 6 | _ReSharper* 7 | *.swp 8 | *.user 9 | *.patch 10 | *.hg 11 | *.sln.cache 12 | desktop.ini 13 | *.ReSharper 14 | *.orig 15 | *.suo 16 | *.itrace.csdef 17 | *.build.csdef 18 | packages 19 | src/*.testsettings 20 | src/TestResults 21 | src/*.vsmdi 22 | artifacts 23 | *.vsp 24 | *.vspx 25 | *.psess 26 | project.lock.json 27 | *.mdb 28 | .vs/ 29 | .vscode/ 30 | .build/ 31 | .testPublish/ 32 | .dotnetcli 33 | *.qgs~ 34 | *.output.csv 35 | /tools 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | sudo: false 3 | dist: trusty 4 | osx_image: none 5 | mono: 5.10.0 6 | dotnet: 2.1.4 7 | os: 8 | - linux 9 | 10 | env: 11 | global: 12 | - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 13 | - DOTNET_CLI_TELEMETRY_OPTOUT: 1 14 | 15 | 16 | branches: 17 | only: 18 | - master 19 | - release 20 | - dev 21 | - /^.*-wip$/ 22 | - /^(.*\/)?ci-.*$/ 23 | 24 | script: 25 | - ./build.sh "-target=Travis" 26 | 27 | cache: 28 | directories: 29 | - .packages 30 | - tools 31 | 32 | notifications: 33 | email: false 34 | -------------------------------------------------------------------------------- /Shared.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Copyright (C) Jonathan "Peli" de Halleux 5 | Peli de Halleux, Wei Li 6 | https://github.com/oldrev/Sandwych.QuickGraph 7 | https://github.com/oldrev/Sandwych.QuickGraph/blob/master/LICENSE.md 8 | netstandard2.0 9 | $(VersionSuffix)-$(BuildNumber) 10 | true 11 | portable 12 | false 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | false 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2017 2 | 3 | init: 4 | - git config --global core.autocrlf true 5 | 6 | install: 7 | - ps: $env:BuildNumber= $env:APPVEYOR_BUILD_NUMBER 8 | - ps: $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = true 9 | - ps: $env:NUGET_XMLDOC_MODE = "skip" 10 | - ps: $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 11 | - ps: $env:CAKE_SETTINGS_SKIPVERIFICATION = true 12 | 13 | build_script: 14 | - ps: .\build.ps1 -Target "Appveyor-Build" 15 | 16 | test_script: 17 | - ps: .\build.ps1 -Target "Appveyor-Test" 18 | 19 | artifacts: 20 | - path: 'src\Sandwych.QuickGraph.Core\**\*.nupkg' 21 | 22 | deploy: 23 | - provider: NuGet 24 | on: 25 | branch: master 26 | server: https://www.nuget.org/api/v2/package 27 | api_key: 28 | secure: DpUsMQuMOcXRXy74iyC+urW4DQE2o0NyNxe22MhXAg9WdMkDikciAhZgbHTkWsNr 29 | skip_symbols: true 30 | artifact: /.*\.nupkg/ 31 | 32 | # Build cache 33 | cache: 34 | - tools -> build.cake 35 | - packages -> build.cake 36 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # folder # 3 | ############### 4 | /**/DROP/ 5 | /**/TEMP/ 6 | /**/packages/ 7 | /**/bin/ 8 | /**/obj/ 9 | _site 10 | -------------------------------------------------------------------------------- /docs/api/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # temp file # 3 | ############### 4 | *.yml 5 | .manifest 6 | -------------------------------------------------------------------------------- /docs/api/index.md: -------------------------------------------------------------------------------- 1 | # PLACEHOLDER 2 | TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*! 3 | -------------------------------------------------------------------------------- /docs/articles/intro.md: -------------------------------------------------------------------------------- 1 | # Add your introductions here! 2 | -------------------------------------------------------------------------------- /docs/articles/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Introduction 2 | href: intro.md 3 | -------------------------------------------------------------------------------- /docs/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "src": "../src/", 7 | "files": [ "**/*.cs" ], 8 | "exclude": [ 9 | "**/obj/**", 10 | "**/bin/**", 11 | "_site/**" 12 | ] 13 | } 14 | ], 15 | "dest": "api", 16 | "disableGitFeatures": false 17 | } 18 | ], 19 | "build": { 20 | "content": [ 21 | { 22 | "files": [ 23 | "api/**.yml", 24 | "api/index.md" 25 | ] 26 | }, 27 | { 28 | "files": [ 29 | "articles/**.md", 30 | "articles/**/toc.yml", 31 | "toc.yml", 32 | "*.md" 33 | ] 34 | } 35 | ], 36 | "resource": [ 37 | { 38 | "files": [ 39 | "images/**" 40 | ] 41 | } 42 | ], 43 | "overwrite": [ 44 | { 45 | "files": [ 46 | "apidoc/**.md" 47 | ], 48 | "exclude": [ 49 | "obj/**", 50 | "_site/**" 51 | ] 52 | } 53 | ], 54 | "dest": "_site", 55 | "globalMetadataFiles": [], 56 | "fileMetadataFiles": [], 57 | "template": [ 58 | "default" 59 | ], 60 | "postProcessors": [], 61 | "noLangKeyword": false, 62 | "keepFileLink": false, 63 | "cleanupCacheHistory": false, 64 | "disableGitFeatures": false 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # This is the **HOMEPAGE**. 2 | Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files. 3 | ## Quick Start Notes: 4 | 1. Add images to the *images* folder if the file is referencing an image. 5 | -------------------------------------------------------------------------------- /docs/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Articles 2 | href: articles/ 3 | - name: Api Documentation 4 | href: api/ 5 | homepage: api/index.md 6 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | graph;topologic;quickgraph 5 | 1.1.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/AlgorithmEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Algorithms 6 | { 7 | public delegate void AlgorithmEventHandler( 8 | IAlgorithm sender, 9 | EventArgs e); 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Cliques/BronKerboshMaximumCliqueAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Algorithms.Services; 6 | 7 | namespace QuickGraph.Algorithms.Cliques 8 | { 9 | // under construction 10 | class BronKerboshMaximumCliqueAlgorithm 11 | : MaximumCliqueAlgorithmBase 12 | where TEdge : IEdge 13 | { 14 | protected BronKerboshMaximumCliqueAlgorithm( 15 | IAlgorithmComponent host, 16 | IUndirectedGraph visitedGraph) 17 | : base(host, visitedGraph) 18 | {} 19 | 20 | protected BronKerboshMaximumCliqueAlgorithm( 21 | IUndirectedGraph visitedGraph) 22 | : base(visitedGraph) 23 | {} 24 | 25 | protected override void InternalCompute() 26 | { 27 | // the currently growing clique; 28 | var R = new List(); 29 | // prospective nodes which are connected to all nodes in R 30 | // and using which R can be expanded 31 | var P = new List(); 32 | // nodes already processed i.e. nodes which were previously in P 33 | // and hence all maximal cliques containing them have already been reported 34 | var X = new List(); 35 | 36 | // An important invariant is that all nodes which are connected to every node 37 | // of R are either in P or X. 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Cliques/MaximumCliqueAlgorithmBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Algorithms.Services; 6 | 7 | namespace QuickGraph.Algorithms.Cliques 8 | { 9 | public abstract class MaximumCliqueAlgorithmBase 10 | : AlgorithmBase> 11 | where TEdge : IEdge 12 | { 13 | protected MaximumCliqueAlgorithmBase(IAlgorithmComponent host, IUndirectedGraph visitedGraph) 14 | : base(host, visitedGraph) 15 | {} 16 | 17 | protected MaximumCliqueAlgorithmBase(IUndirectedGraph visitedGraph) 18 | : base(visitedGraph) 19 | {} 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Cliques/ncliques.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/src/Sandwych.QuickGraph.Core/Algorithms/Cliques/ncliques.pdf -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/ComputationState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | /// 6 | /// The computation state of a graph algorithm 7 | /// 8 | #if !SILVERLIGHT 9 | [Serializable] 10 | #endif 11 | public enum ComputationState 12 | { 13 | /// 14 | /// The algorithm is not running 15 | /// 16 | NotRunning, 17 | /// 18 | /// The algorithm is running 19 | /// 20 | Running, 21 | /// 22 | /// An abort has been requested. The algorithm is still running and will cancel as soon as it checks 23 | /// the cancelation state 24 | /// 25 | PendingAbortion, 26 | /// 27 | /// The computation is finished succesfully. 28 | /// 29 | Finished, 30 | /// 31 | /// The computation was aborted 32 | /// 33 | Aborted 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Condensation/CondensedEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Collections; 4 | 5 | namespace QuickGraph.Algorithms.Condensation 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public sealed class CondensedEdge : Edge 11 | where TEdge : IEdge 12 | where TGraph : IMutableVertexAndEdgeSet, new() 13 | { 14 | private List edges = new List(); 15 | public CondensedEdge(TGraph source, TGraph target) 16 | :base(source,target) 17 | { } 18 | 19 | public IList Edges 20 | { 21 | get { return this.edges; } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Condensation/MergedEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Collections; 4 | 5 | namespace QuickGraph.Algorithms.Condensation 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public sealed class MergedEdge : Edge 11 | where TEdge : IEdge 12 | { 13 | private List edges = new List(); 14 | 15 | public MergedEdge(TVertex source, TVertex target) 16 | :base(source,target) 17 | { } 18 | 19 | public IList Edges 20 | { 21 | get { return this.edges; } 22 | } 23 | 24 | public static MergedEdge Merge( 25 | MergedEdge inEdge, 26 | MergedEdge outEdge 27 | ) 28 | { 29 | MergedEdge newEdge = new MergedEdge( 30 | inEdge.Source, outEdge.Target); 31 | newEdge.edges = new List(inEdge.Edges.Count + outEdge.Edges.Count); 32 | newEdge.edges.AddRange(inEdge.Edges); 33 | newEdge.edges.AddRange(outEdge.edges); 34 | 35 | return newEdge; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Contracts/IAlgorithmContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Algorithms.Contracts 8 | { 9 | [ContractClassFor(typeof(IAlgorithm<>))] 10 | abstract class IAlgorithmContract 11 | : IAlgorithm 12 | { 13 | #region IAlgorithm Members 14 | 15 | TGraph IAlgorithm.VisitedGraph 16 | { 17 | get 18 | { 19 | Contract.Ensures(Contract.Result() != null); 20 | 21 | return default(TGraph); 22 | } 23 | } 24 | 25 | #endregion 26 | 27 | #region IComputation Members 28 | 29 | object IComputation.SyncRoot 30 | { 31 | get { throw new NotImplementedException(); } 32 | } 33 | 34 | ComputationState IComputation.State 35 | { 36 | get { throw new NotImplementedException(); } 37 | } 38 | 39 | void IComputation.Compute() 40 | { 41 | throw new NotImplementedException(); 42 | } 43 | 44 | void IComputation.Abort() 45 | { 46 | throw new NotImplementedException(); 47 | } 48 | 49 | event EventHandler IComputation.StateChanged 50 | { 51 | add { throw new NotImplementedException(); } 52 | remove { throw new NotImplementedException(); } 53 | } 54 | 55 | event EventHandler IComputation.Started 56 | { 57 | add { throw new NotImplementedException(); } 58 | remove { throw new NotImplementedException(); } 59 | } 60 | 61 | event EventHandler IComputation.Finished 62 | { 63 | add { throw new NotImplementedException(); } 64 | remove { throw new NotImplementedException(); } 65 | } 66 | 67 | event EventHandler IComputation.Aborted 68 | { 69 | add { throw new NotImplementedException(); } 70 | remove { throw new NotImplementedException(); } 71 | } 72 | 73 | #endregion 74 | } 75 | } -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Contracts/IComputationContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Algorithms.Contracts 5 | { 6 | [ContractClassFor(typeof(IComputation))] 7 | abstract class IComputationContract 8 | : IComputation 9 | { 10 | #region IComputation Members 11 | object IComputation.SyncRoot 12 | { 13 | get 14 | { 15 | Contract.Ensures(Contract.Result() != null); 16 | return null; 17 | } 18 | } 19 | 20 | ComputationState IComputation.State 21 | { 22 | get 23 | { 24 | Contract.Ensures(Enum.IsDefined(typeof(ComputationState), Contract.Result())); 25 | 26 | return default(ComputationState); 27 | } 28 | } 29 | 30 | void IComputation.Compute() 31 | { 32 | // todo contracts on events 33 | } 34 | 35 | void IComputation.Abort() 36 | { 37 | } 38 | 39 | event EventHandler IComputation.StateChanged 40 | { 41 | add { throw new NotImplementedException(); } 42 | remove { throw new NotImplementedException(); } 43 | } 44 | 45 | event EventHandler IComputation.Started 46 | { 47 | add { throw new NotImplementedException(); } 48 | remove { throw new NotImplementedException(); } 49 | } 50 | 51 | event EventHandler IComputation.Finished 52 | { 53 | add { throw new NotImplementedException(); } 54 | remove { throw new NotImplementedException(); } 55 | } 56 | 57 | event EventHandler IComputation.Aborted 58 | { 59 | add { throw new NotImplementedException(); } 60 | remove { throw new NotImplementedException(); } 61 | } 62 | 63 | #endregion 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Exploration/ITransitionFactory.cs: -------------------------------------------------------------------------------- 1 | #if !SILVERLIGHT 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace QuickGraph.Algorithms.Exploration 6 | { 7 | public interface ITransitionFactory 8 | where TVertex : ICloneable 9 | where TEdge : IEdge 10 | { 11 | bool IsValid(TVertex v); 12 | IEnumerable Apply(TVertex source); 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Algorithms.Services; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Algorithms 6 | { 7 | [ContractClass(typeof(Contracts.IAlgorithmContract<>))] 8 | public interface IAlgorithm : 9 | IComputation 10 | { 11 | TGraph VisitedGraph { get;} 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IComputation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Algorithms 5 | { 6 | [ContractClass(typeof(Contracts.IComputationContract))] 7 | public interface IComputation 8 | { 9 | object SyncRoot { get; } 10 | ComputationState State { get; } 11 | 12 | void Compute(); 13 | void Abort(); 14 | 15 | event EventHandler StateChanged; 16 | event EventHandler Started; 17 | event EventHandler Finished; 18 | event EventHandler Aborted; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IConnectedComponentAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Algorithms 6 | { 7 | public interface IConnectedComponentAlgorithm : IAlgorithm 8 | where TGraph : IGraph 9 | where TEdge : IEdge 10 | { 11 | int ComponentCount { get;} 12 | IDictionary Components { get;} 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IDistanceRecorderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | /// 6 | /// An algorithm that exposes events to compute a distance map between vertices 7 | /// 8 | /// type of the vertices 9 | /// type of the edges 10 | public interface IDistanceRecorderAlgorithm 11 | where TEdge : IEdge 12 | { 13 | event VertexAction InitializeVertex; 14 | event VertexAction DiscoverVertex; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IDistanceRelaxer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Algorithms 6 | { 7 | public interface IDistanceRelaxer 8 | : IComparer 9 | { 10 | double InitialDistance { get;} 11 | double Combine(double distance, double weight); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IEdgeColorizerAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuickGraph.Algorithms 5 | { 6 | public interface IEdgeColorizerAlgorithm 7 | where TEdge : IEdge 8 | { 9 | IDictionary EdgeColors { get;} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IEdgePredecessorRecorderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | public interface IEdgePredecessorRecorderAlgorithm 6 | where TEdge : IEdge 7 | { 8 | event EdgeEdgeAction DiscoverTreeEdge; 9 | event EdgeAction FinishEdge; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IEndPathEdgeRecorderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace QuickGraph.Algorithms 3 | { 4 | public interface IEndPathEdgeRecorderAlgorithm 5 | where TEdge : IEdge 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/ITreeBuilderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | public interface ITreeBuilderAlgorithm 6 | where TEdge : IEdge 7 | { 8 | event EdgeAction TreeEdge; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IUndirectedTreeBuilderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | public interface IUndirectedTreeBuilderAlgorithm 6 | where TEdge : IEdge 7 | { 8 | event UndirectedEdgeAction TreeEdge; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IUndirectedVertexPredecessorRecorderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | public interface IUndirectedVertexPredecessorRecorderAlgorithm 6 | : IUndirectedTreeBuilderAlgorithm 7 | where TEdge : IEdge 8 | { 9 | event VertexAction StartVertex; 10 | event VertexAction FinishVertex; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IVertexColorizerAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuickGraph.Algorithms 5 | { 6 | public interface IVertexColorizerAlgorithm 7 | where TEdge : IEdge 8 | { 9 | GraphColor GetVertexColor(TVertex v); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IVertexPredecessorRecorderAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | public interface IVertexPredecessorRecorderAlgorithm 6 | : ITreeBuilderAlgorithm 7 | where TEdge : IEdge 8 | { 9 | event VertexAction StartVertex; 10 | event VertexAction FinishVertex; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/IVertexTimeStamperAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph.Algorithms 4 | { 5 | public interface IVertexTimeStamperAlgorithm 6 | where TEdge : IEdge 7 | { 8 | event VertexAction DiscoverVertex; 9 | event VertexAction FinishVertex; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/MaximumFlow/AllVerticesGraphAugmentorAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Algorithms.Services; 3 | 4 | namespace QuickGraph.Algorithms.MaximumFlow 5 | { 6 | public sealed class AllVerticesGraphAugmentorAlgorithm 7 | : GraphAugmentorAlgorithmBase> 8 | where TEdge : IEdge 9 | { 10 | public AllVerticesGraphAugmentorAlgorithm( 11 | IMutableVertexAndEdgeSet visitedGraph, 12 | VertexFactory vertexFactory, 13 | EdgeFactory edgeFactory 14 | ) 15 | : this(null, visitedGraph, vertexFactory, edgeFactory) 16 | { } 17 | 18 | public AllVerticesGraphAugmentorAlgorithm( 19 | IAlgorithmComponent host, 20 | IMutableVertexAndEdgeSet visitedGraph, 21 | VertexFactory vertexFactory, 22 | EdgeFactory edgeFactory 23 | ) 24 | :base(host, visitedGraph,vertexFactory,edgeFactory) 25 | {} 26 | 27 | protected override void AugmentGraph() 28 | { 29 | var cancelManager = this.Services.CancelManager; 30 | foreach (var v in this.VisitedGraph.Vertices) 31 | { 32 | if (cancelManager.IsCancelling) break; 33 | 34 | this.AddAugmentedEdge(this.SuperSource, v); 35 | this.AddAugmentedEdge(v, this.SuperSink); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/MaximumFlow/MultiSourceSinkGraphAugmentorAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Algorithms.Services; 3 | 4 | namespace QuickGraph.Algorithms.MaximumFlow 5 | { 6 | public sealed class MultiSourceSinkGraphAugmentorAlgorithm 7 | : GraphAugmentorAlgorithmBase> 8 | where TEdge : IEdge 9 | { 10 | public MultiSourceSinkGraphAugmentorAlgorithm( 11 | IMutableBidirectionalGraph visitedGraph, 12 | VertexFactory vertexFactory, 13 | EdgeFactory edgeFactory) 14 | :this(null, visitedGraph, vertexFactory, edgeFactory) 15 | {} 16 | 17 | public MultiSourceSinkGraphAugmentorAlgorithm( 18 | IAlgorithmComponent host, 19 | IMutableBidirectionalGraph visitedGraph, 20 | VertexFactory vertexFactory, 21 | EdgeFactory edgeFactory) 22 | :base(host, visitedGraph,vertexFactory,edgeFactory) 23 | {} 24 | 25 | protected override void AugmentGraph() 26 | { 27 | var cancelManager = this.Services.CancelManager; 28 | foreach (var v in this.VisitedGraph.Vertices) 29 | { 30 | if (cancelManager.IsCancelling) break; 31 | 32 | // is source 33 | if (this.VisitedGraph.IsInEdgesEmpty(v)) 34 | this.AddAugmentedEdge(this.SuperSource, v); 35 | 36 | // is sink 37 | if (this.VisitedGraph.IsOutEdgesEmpty(v)) 38 | this.AddAugmentedEdge(v,this.SuperSink); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/MinimumSpanningTree/IMinimumSpanningTreeAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Algorithms.MinimumSpanningTree 6 | { 7 | public interface IMinimumSpanningTreeAlgorithm 8 | : IAlgorithm> 9 | , ITreeBuilderAlgorithm 10 | where TEdge : IEdge 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/Contracts/IObserverContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Algorithms.Observers.Contracts 5 | { 6 | [ContractClassFor(typeof(IObserver<>))] 7 | abstract class IObserverContract 8 | : IObserver 9 | { 10 | IDisposable IObserver.Attach(TAlgorithm algorithm) 11 | { 12 | Contract.Requires(algorithm != null); 13 | Contract.Ensures(Contract.Result() != null); 14 | 15 | return default(IDisposable); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/DisposableAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Algorithms.Observers 8 | { 9 | struct DisposableAction 10 | : IDisposable 11 | { 12 | public delegate void Action(); 13 | 14 | Action action; 15 | 16 | public DisposableAction(Action action) 17 | { 18 | Contract.Requires(action != null); 19 | this.action = action; 20 | } 21 | 22 | public void Dispose() 23 | { 24 | var a = this.action; 25 | this.action = null; 26 | if (a != null) 27 | a(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/EdgeRecorderObserver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Algorithms.Observers 6 | { 7 | /// 8 | /// 9 | /// 10 | /// type of a vertex 11 | /// type of an edge 12 | /// 15 | #if !SILVERLIGHT 16 | [Serializable] 17 | #endif 18 | public sealed class EdgeRecorderObserver : 19 | IObserver> 20 | where TEdge : IEdge 21 | { 22 | private readonly IList edges; 23 | 24 | public EdgeRecorderObserver() 25 | :this(new List()) 26 | {} 27 | 28 | public EdgeRecorderObserver(IList edges) 29 | { 30 | Contract.Requires(edges != null); 31 | 32 | this.edges = edges; 33 | } 34 | 35 | public IList Edges 36 | { 37 | get 38 | { 39 | return this.edges; 40 | } 41 | } 42 | 43 | public IDisposable Attach(ITreeBuilderAlgorithm algorithm) 44 | { 45 | algorithm.TreeEdge +=new EdgeAction(RecordEdge); 46 | return new DisposableAction( 47 | () => algorithm.TreeEdge -= new EdgeAction(RecordEdge) 48 | ); 49 | } 50 | 51 | private void RecordEdge(TEdge args) 52 | { 53 | Contract.Requires(args != null); 54 | 55 | this.Edges.Add(args); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/IObserver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Algorithms.Observers 5 | { 6 | /// 7 | /// An algorithm observer 8 | /// 9 | /// type of the algorithm 10 | /// 13 | [ContractClass(typeof(Contracts.IObserverContract<>))] 14 | public interface IObserver 15 | { 16 | /// 17 | /// Attaches to the algorithm events 18 | /// and returns a disposable object that can be used 19 | /// to detach from the events 20 | /// 21 | /// 22 | /// 23 | IDisposable Attach(TAlgorithm algorithm); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/UndirectedVertexPredecessorRecorderObserver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Algorithms.Observers 6 | { 7 | /// 8 | /// 9 | /// 10 | /// type of a vertex 11 | /// type of an edge 12 | /// 15 | #if !SILVERLIGHT 16 | [Serializable] 17 | #endif 18 | public sealed class UndirectedVertexPredecessorRecorderObserver : 19 | IObserver> 20 | where TEdge : IEdge 21 | { 22 | private readonly IDictionary vertexPredecessors; 23 | 24 | public UndirectedVertexPredecessorRecorderObserver() 25 | :this(new Dictionary()) 26 | {} 27 | 28 | public UndirectedVertexPredecessorRecorderObserver( 29 | IDictionary vertexPredecessors) 30 | { 31 | Contract.Requires(vertexPredecessors != null); 32 | 33 | this.vertexPredecessors = vertexPredecessors; 34 | } 35 | 36 | public IDictionary VertexPredecessors 37 | { 38 | get { return this.vertexPredecessors; } 39 | } 40 | 41 | public IDisposable Attach(IUndirectedTreeBuilderAlgorithm algorithm) 42 | { 43 | algorithm.TreeEdge += new UndirectedEdgeAction(TreeEdge); 44 | return new DisposableAction( 45 | () => algorithm.TreeEdge -= new UndirectedEdgeAction(TreeEdge) 46 | ); 47 | } 48 | 49 | void TreeEdge(Object sender, UndirectedEdgeEventArgs e) 50 | { 51 | this.vertexPredecessors[e.Target] = e.Edge; 52 | } 53 | 54 | public bool TryGetPath(TVertex vertex, out IEnumerable path) 55 | { 56 | return EdgeExtensions.TryGetPath(this.VertexPredecessors, vertex, out path); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/VertexPredecessorRecorderObserver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Algorithms.Observers 6 | { 7 | /// 8 | /// 9 | /// 10 | /// type of a vertex 11 | /// type of an edge 12 | /// 15 | #if !SILVERLIGHT 16 | [Serializable] 17 | #endif 18 | public sealed class VertexPredecessorRecorderObserver : 19 | IObserver> 20 | where TEdge : IEdge 21 | { 22 | private readonly Dictionary vertexPredecessors; 23 | 24 | public VertexPredecessorRecorderObserver() 25 | :this(new Dictionary()) 26 | {} 27 | 28 | public VertexPredecessorRecorderObserver( 29 | Dictionary vertexPredecessors) 30 | { 31 | Contract.Requires(vertexPredecessors != null); 32 | 33 | this.vertexPredecessors = vertexPredecessors; 34 | } 35 | 36 | public IDictionary VertexPredecessors 37 | { 38 | get { return this.vertexPredecessors; } 39 | } 40 | 41 | public IDisposable Attach(ITreeBuilderAlgorithm algorithm) 42 | { 43 | algorithm.TreeEdge += new EdgeAction(TreeEdge); 44 | return new DisposableAction( 45 | () => algorithm.TreeEdge -= new EdgeAction(TreeEdge) 46 | ); 47 | } 48 | 49 | void TreeEdge(TEdge e) 50 | { 51 | this.vertexPredecessors[e.Target] = e; 52 | } 53 | 54 | public bool TryGetPath(TVertex vertex, out IEnumerable path) 55 | { 56 | return EdgeExtensions.TryGetPath(this.VertexPredecessors, vertex, out path); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Observers/VertexRecorderObserver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Algorithms.Observers 6 | { 7 | /// 8 | /// 9 | /// 10 | /// type of a vertex 11 | /// type of an edge 12 | /// 15 | #if !SILVERLIGHT 16 | [Serializable] 17 | #endif 18 | public sealed class VertexRecorderObserver : 19 | IObserver> 20 | where TEdge : IEdge 21 | { 22 | private readonly IList vertices; 23 | public VertexRecorderObserver() 24 | : this(new List()) 25 | { } 26 | 27 | public VertexRecorderObserver(IList vertices) 28 | { 29 | Contract.Requires(vertices != null); 30 | 31 | this.vertices = vertices; 32 | } 33 | 34 | public IEnumerable Vertices 35 | { 36 | get 37 | { 38 | return this.vertices; 39 | } 40 | } 41 | 42 | public IDisposable Attach(IVertexTimeStamperAlgorithm algorithm) 43 | { 44 | algorithm.DiscoverVertex += new VertexAction(algorithm_DiscoverVertex); 45 | return new DisposableAction( 46 | () => algorithm.DiscoverVertex -= new VertexAction(algorithm_DiscoverVertex) 47 | ); 48 | } 49 | 50 | void algorithm_DiscoverVertex(TVertex v) 51 | { 52 | this.vertices.Add(v); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/RandomWalks/IEdgeChain.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | namespace QuickGraph.Algorithms.RandomWalks 3 | { 4 | public interface IEdgeChain 5 | where TEdge : IEdge 6 | { 7 | bool TryGetSuccessor(IImplicitGraph g, TVertex u, out TEdge successor); 8 | bool TryGetSuccessor(IEnumerable edges, TVertex u, out TEdge successor); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/RandomWalks/IMarkovEdgeChain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace QuickGraph.Algorithms.RandomWalks 3 | { 4 | public interface IMarkovEdgeChain 5 | : IEdgeChain 6 | where TEdge : IEdge 7 | { 8 | Random Rand { get;set;} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/RandomWalks/MarkovEdgeChainBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuickGraph.Algorithms.RandomWalks 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public abstract class MarkovEdgeChainBase : 10 | IMarkovEdgeChain 11 | where TEdge : IEdge 12 | { 13 | private Random rand = new Random(); 14 | 15 | public Random Rand 16 | { 17 | get 18 | { 19 | return this.rand; 20 | } 21 | set 22 | { 23 | this.rand = value; 24 | } 25 | } 26 | 27 | public abstract bool TryGetSuccessor(IImplicitGraph g, TVertex u, out TEdge successor); 28 | public abstract bool TryGetSuccessor(IEnumerable edges, TVertex u, out TEdge successor); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/RandomWalks/NormalizedMarkovEdgeChain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace QuickGraph.Algorithms.RandomWalks 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public sealed class NormalizedMarkovEdgeChain : 11 | MarkovEdgeChainBase 12 | where TEdge : IEdge 13 | { 14 | public override bool TryGetSuccessor(IImplicitGraph g, TVertex u, out TEdge successor) 15 | { 16 | int outDegree = g.OutDegree(u); 17 | if (outDegree > 0) 18 | { 19 | int index = this.Rand.Next(0, outDegree); 20 | successor = g.OutEdge(u, index); 21 | return true; 22 | } 23 | 24 | successor = default(TEdge); 25 | return false; 26 | } 27 | 28 | public override bool TryGetSuccessor(IEnumerable edges, TVertex u, out TEdge successor) 29 | { 30 | var edgeCount = Enumerable.Count(edges); 31 | 32 | if (edgeCount > 0) 33 | { 34 | int index = this.Rand.Next(0, edgeCount); 35 | successor = Enumerable.ElementAt(edges, index); 36 | return true; 37 | } 38 | 39 | successor = default(TEdge); 40 | return false; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/RandomWalks/RoundRobinEdgeChain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace QuickGraph.Algorithms.RandomWalks 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public sealed class RoundRobinEdgeChain 11 | : IEdgeChain 12 | where TEdge : IEdge 13 | { 14 | private Dictionary outEdgeIndices = new Dictionary(); 15 | 16 | public bool TryGetSuccessor(IImplicitGraph g, TVertex u, out TEdge successor) 17 | { 18 | int outDegree = g.OutDegree(u); 19 | if (outDegree > 0) 20 | { 21 | int index; 22 | if (!outEdgeIndices.TryGetValue(u, out index)) 23 | { 24 | index = 0; 25 | outEdgeIndices.Add(u, index); 26 | } 27 | TEdge e = g.OutEdge(u, index); 28 | this.outEdgeIndices[u] = (++index) % outDegree; 29 | 30 | successor = e; 31 | return true; 32 | } 33 | 34 | successor = default(TEdge); 35 | return false; 36 | } 37 | 38 | public bool TryGetSuccessor(IEnumerable edges, TVertex u, out TEdge successor) 39 | { 40 | var edgeCount = Enumerable.Count(edges); 41 | 42 | if (edgeCount > 0) 43 | { 44 | int index; 45 | if (!outEdgeIndices.TryGetValue(u, out index)) 46 | { 47 | index = 0; 48 | outEdgeIndices.Add(u, index); 49 | } 50 | var e = Enumerable.ElementAt(edges, index); 51 | this.outEdgeIndices[u] = (++index) % edgeCount; 52 | successor = e; 53 | } 54 | successor = default(TEdge); 55 | return false; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/RandomWalks/WeightedMarkedEdgeChain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuickGraph.Algorithms.RandomWalks 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public sealed class WeightedMarkovEdgeChain : 10 | WeightedMarkovEdgeChainBase 11 | where TEdge : IEdge 12 | { 13 | public WeightedMarkovEdgeChain(IDictionary weights) 14 | :base(weights) 15 | {} 16 | 17 | public override bool TryGetSuccessor(IImplicitGraph g, TVertex u, out TEdge successor) 18 | { 19 | // get number of out-edges 20 | int n = g.OutDegree(u); 21 | if (n > 0) 22 | { 23 | // compute out-edge su 24 | double outWeight = GetOutWeight(g, u); 25 | // scale and get next edge 26 | double r = this.Rand.NextDouble() * outWeight; 27 | return TryGetSuccessor(g, u, r, out successor); 28 | } 29 | 30 | successor = default(TEdge); 31 | return false; 32 | } 33 | 34 | public override bool TryGetSuccessor(IEnumerable edges, TVertex u, out TEdge sucessor) 35 | { 36 | // compute out-edge su 37 | double outWeight = GetWeights(edges); 38 | // scale and get next edge 39 | double r = this.Rand.NextDouble() * outWeight; 40 | return TryGetSuccessor(edges, r, out sucessor); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Services/IAlgorithmComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Algorithms.Services 6 | { 7 | public interface IAlgorithmComponent 8 | { 9 | IAlgorithmServices Services { get; } 10 | T GetService() where T : IService; 11 | bool TryGetService(out T service) where T : IService; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Services/IAlgorithmServices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph.Algorithms.Services 7 | { 8 | /// 9 | /// Common services available to algorithm instances 10 | /// 11 | public interface IAlgorithmServices 12 | { 13 | ICancelManager CancelManager { get; } 14 | } 15 | 16 | class AlgorithmServices : 17 | IAlgorithmServices 18 | { 19 | readonly IAlgorithmComponent host; 20 | 21 | public AlgorithmServices(IAlgorithmComponent host) 22 | { 23 | Contract.Requires(host != null); 24 | 25 | this.host = host; 26 | } 27 | 28 | ICancelManager _cancelManager; 29 | public ICancelManager CancelManager 30 | { 31 | get 32 | { 33 | if (this._cancelManager == null) 34 | this._cancelManager = this.host.GetService(); 35 | return this._cancelManager; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Algorithms/Services/IService.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Algorithms.Services 2 | { 3 | /// 4 | /// Interface implemented by graph services 5 | /// 6 | public interface IService 7 | {} 8 | } 9 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/BinaryQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph.Collections 7 | { 8 | #if !SILVERLIGHT 9 | [Serializable] 10 | #endif 11 | public sealed class BinaryQueue : 12 | IPriorityQueue 13 | { 14 | private readonly Func distances; 15 | private readonly BinaryHeap heap; 16 | 17 | public BinaryQueue( 18 | Func distances 19 | ) 20 | : this(distances, Comparer.Default.Compare) 21 | { } 22 | 23 | public BinaryQueue( 24 | Func distances, 25 | Func distanceComparison 26 | ) 27 | { 28 | Contract.Requires(distances != null); 29 | Contract.Requires(distanceComparison != null); 30 | 31 | this.distances = distances; 32 | this.heap = new BinaryHeap(distanceComparison); 33 | } 34 | 35 | public void Update(TVertex v) 36 | { 37 | this.heap.Update(this.distances(v), v); 38 | } 39 | 40 | public int Count 41 | { 42 | get { return this.heap.Count; } 43 | } 44 | 45 | public bool Contains(TVertex value) 46 | { 47 | return this.heap.IndexOf(value) > -1; 48 | } 49 | 50 | public void Enqueue(TVertex value) 51 | { 52 | this.heap.Add(this.distances(value), value); 53 | } 54 | 55 | public TVertex Dequeue() 56 | { 57 | return this.heap.RemoveMinimum().Value; 58 | } 59 | 60 | public TVertex Peek() 61 | { 62 | return this.heap.Minimum().Value; 63 | } 64 | 65 | public TVertex[] ToArray() 66 | { 67 | return this.heap.ToValueArray(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/EdgeEdgeDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | #if !SILVERLIGHT 5 | using System.Runtime.Serialization; 6 | #endif 7 | 8 | namespace QuickGraph.Collections 9 | { 10 | #if !SILVERLIGHT 11 | [Serializable] 12 | #endif 13 | public class EdgeEdgeDictionary 14 | : Dictionary 15 | #if !SILVERLIGHT 16 | , ICloneable 17 | , ISerializable 18 | #endif 19 | where TEdge : IEdge 20 | { 21 | public EdgeEdgeDictionary() 22 | { } 23 | 24 | public EdgeEdgeDictionary(int capacity) 25 | : base(capacity) 26 | { } 27 | 28 | #if !SILVERLIGHT 29 | protected EdgeEdgeDictionary( 30 | SerializationInfo info, StreamingContext context) 31 | : base(info, context) { } 32 | #endif 33 | 34 | public EdgeEdgeDictionary Clone() 35 | { 36 | var clone = new EdgeEdgeDictionary(this.Count); 37 | foreach (var kv in this) 38 | clone.Add(kv.Key, kv.Value); 39 | return clone; 40 | } 41 | 42 | #if !SILVERLIGHT 43 | object ICloneable.Clone() 44 | { 45 | return this.Clone(); 46 | } 47 | #endif 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/EdgeList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Collections 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public sealed class EdgeList 11 | : List 12 | , IEdgeList 13 | #if !SILVERLIGHT 14 | , ICloneable 15 | #endif 16 | where TEdge : IEdge 17 | { 18 | public EdgeList() 19 | { } 20 | 21 | public EdgeList(int capacity) 22 | : base(capacity) 23 | { } 24 | 25 | public EdgeList(EdgeList list) 26 | : base(list) 27 | {} 28 | 29 | public EdgeList Clone() 30 | { 31 | return new EdgeList(this); 32 | } 33 | 34 | IEdgeList IEdgeList.Clone() 35 | { 36 | return this.Clone(); 37 | } 38 | 39 | #if !SILVERLIGHT 40 | object ICloneable.Clone() 41 | { 42 | return this.Clone(); 43 | } 44 | #endif 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/IDisjointSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Collections 6 | { 7 | /// 8 | /// A disjoint-set data structure 9 | /// 10 | /// 11 | [ContractClass(typeof(QuickGraph.Collections.Contracts.IDisjointSetContract<>))] 12 | public interface IDisjointSet 13 | { 14 | /// 15 | /// Gets the current number of sets 16 | /// 17 | int SetCount { get; } 18 | 19 | /// 20 | /// Gets the current number of elements. 21 | /// 22 | int ElementCount { get; } 23 | 24 | /// 25 | /// Creates a new set for the value 26 | /// 27 | /// 28 | void MakeSet(T value); 29 | 30 | /// 31 | /// Finds the set containing the value 32 | /// 33 | /// 34 | /// 35 | T FindSet(T value); 36 | 37 | /// 38 | /// Gets a value indicating if left and right are contained in the same set 39 | /// 40 | /// 41 | /// 42 | /// 43 | bool AreInSameSet(T left, T right); 44 | 45 | /// 46 | /// Merges the sets from the two values 47 | /// 48 | /// 49 | /// 50 | /// true if left and right were unioned, false if they already belong to the same set 51 | bool Union(T left, T right); 52 | 53 | /// 54 | /// Gets a value indicating whether the value is in the data structure 55 | /// 56 | /// 57 | /// 58 | [Pure] 59 | bool Contains(T value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/IEdgeList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Collections 6 | { 7 | /// 8 | /// A cloneable list of edges 9 | /// 10 | /// 11 | /// 12 | [ContractClass(typeof(IEdgeListContract<,>))] 13 | public interface IEdgeList 14 | : IList 15 | #if !SILVERLIGHT 16 | , ICloneable 17 | #endif 18 | where TEdge : IEdge 19 | { 20 | /// 21 | /// Trims excess allocated space 22 | /// 23 | void TrimExcess(); 24 | /// 25 | /// Gets a clone of this list 26 | /// 27 | /// 28 | #if !SILVERLIGHT 29 | new 30 | #endif 31 | IEdgeList Clone(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/IPriorityQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace QuickGraph.Collections 7 | { 8 | public interface IPriorityQueue 9 | : IQueue 10 | { 11 | void Update(T value); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/IQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Collections 6 | { 7 | public interface IQueue 8 | { 9 | int Count { get; } 10 | 11 | bool Contains(T value); 12 | void Enqueue(T value); 13 | T Dequeue(); 14 | T Peek(); 15 | 16 | T[] ToArray(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/IVertexEdgeDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | #if !SILVERLIGHT 4 | using System.Runtime.Serialization; 5 | #endif 6 | using System.Diagnostics.Contracts; 7 | 8 | namespace QuickGraph.Collections 9 | { 10 | /// 11 | /// A dictionary of vertices to a list of edges 12 | /// 13 | /// 14 | /// 15 | [ContractClass(typeof(IVertexEdgeDictionaryContract<,>))] 16 | public interface IVertexEdgeDictionary 17 | : IDictionary> 18 | #if !SILVERLIGHT 19 | , ICloneable 20 | , ISerializable 21 | #endif 22 | where TEdge : IEdge 23 | { 24 | /// 25 | /// Gets a clone of the dictionary. The vertices and edges are not cloned. 26 | /// 27 | /// 28 | #if !SILVERLIGHT 29 | new 30 | #endif 31 | IVertexEdgeDictionary Clone(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/Queue.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Collections 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public sealed class Queue : 10 | System.Collections.Generic.Queue, 11 | IQueue 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/VertexEdgeDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | #if !SILVERLIGHT 5 | using System.Runtime.Serialization; 6 | #endif 7 | 8 | namespace QuickGraph.Collections 9 | { 10 | #if !SILVERLIGHT 11 | [Serializable] 12 | #endif 13 | public sealed class VertexEdgeDictionary 14 | : Dictionary> 15 | , IVertexEdgeDictionary 16 | #if !SILVERLIGHT 17 | , ICloneable 18 | , ISerializable 19 | #endif 20 | where TEdge : IEdge 21 | { 22 | public VertexEdgeDictionary() { } 23 | public VertexEdgeDictionary(int capacity) 24 | : base(capacity) 25 | { } 26 | public VertexEdgeDictionary(IEqualityComparer vertexComparer) 27 | : base(vertexComparer) 28 | { } 29 | public VertexEdgeDictionary(int capacity, IEqualityComparer vertexComparer) 30 | : base(capacity, vertexComparer) 31 | { } 32 | 33 | #if !SILVERLIGHT 34 | public VertexEdgeDictionary( 35 | SerializationInfo info, StreamingContext context) 36 | : base(info, context) { } 37 | #endif 38 | 39 | public VertexEdgeDictionary Clone() 40 | { 41 | var clone = new VertexEdgeDictionary(this.Count); 42 | foreach (var kv in this) 43 | clone.Add(kv.Key, kv.Value.Clone()); 44 | return clone; 45 | } 46 | 47 | IVertexEdgeDictionary IVertexEdgeDictionary.Clone() 48 | { 49 | return this.Clone(); 50 | } 51 | 52 | #if !SILVERLIGHT 53 | object ICloneable.Clone() 54 | { 55 | return this.Clone(); 56 | } 57 | #endif 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Collections/VertexList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | #if !SILVERLIGHT 5 | using System.Runtime.Serialization; 6 | #endif 7 | 8 | namespace QuickGraph.Collections 9 | { 10 | #if !SILVERLIGHT 11 | [Serializable] 12 | #endif 13 | public sealed class VertexList 14 | : List 15 | #if !SILVERLIGHT 16 | , ICloneable 17 | #endif 18 | { 19 | public VertexList() 20 | { } 21 | 22 | public VertexList(int capacity) 23 | : base(capacity) 24 | { } 25 | 26 | public VertexList(VertexList other) 27 | : base(other) 28 | { } 29 | 30 | public VertexList Clone() 31 | { 32 | return new VertexList(this); 33 | } 34 | 35 | #if !SILVERLIGHT 36 | object ICloneable.Clone() 37 | { 38 | return this.Clone(); 39 | } 40 | #endif 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/DummyContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Diagnostics.Contracts 4 | { 5 | /// 6 | /// Ensures that System.Diagnostics.Contracts namespace exists 7 | /// 8 | class DummyContract 9 | {} 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/EnumerableContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | 8 | namespace QuickGraph 9 | { 10 | public static class EnumerableContract 11 | { 12 | [Pure] 13 | public static bool ElementsNotNull(IEnumerable elements) 14 | { 15 | Contract.Requires(elements != null); 16 | #if DEBUG 17 | 18 | return Enumerable.All(elements, e => e != null); 19 | #else 20 | return true; 21 | #endif 22 | } 23 | 24 | [Pure] 25 | public static bool All(int lowerBound, int exclusiveUpperBound, Func predicate) 26 | { 27 | for (int i = lowerBound; i < exclusiveUpperBound; i++) 28 | { 29 | if (!predicate(i)) return false; 30 | } 31 | return true; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/ICloneableEdgeContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Contracts 8 | { 9 | [ContractClassFor(typeof(ICloneableEdge<,>))] 10 | abstract class ICloneableEdgeContract 11 | : ICloneableEdge 12 | where TEdge : IEdge 13 | { 14 | TEdge ICloneableEdge.Clone(TVertex source, TVertex target) 15 | { 16 | Contract.Requires(source != null); 17 | Contract.Requires(target != null); 18 | Contract.Ensures(Contract.Result() != null); 19 | Contract.Ensures(Contract.Result().Source.Equals(source)); 20 | Contract.Ensures(Contract.Result().Target.Equals(target)); 21 | 22 | return default(TEdge); 23 | } 24 | 25 | #region IEdge Members 26 | 27 | TVertex IEdge.Source 28 | { 29 | get { throw new NotImplementedException(); } 30 | } 31 | 32 | TVertex IEdge.Target 33 | { 34 | get { throw new NotImplementedException(); } 35 | } 36 | 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IEdgeContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Contracts 6 | { 7 | [ContractClassFor(typeof(IEdge<>))] 8 | abstract class IEdgeContract 9 | : IEdge 10 | { 11 | [ContractInvariantMethod] 12 | void IEdgeInvariant() 13 | { 14 | IEdge ithis = this; 15 | Contract.Invariant(ithis.Source != null); 16 | Contract.Invariant(ithis.Target != null); 17 | } 18 | 19 | TVertex IEdge.Source 20 | { 21 | get 22 | { 23 | Contract.Ensures(Contract.Result() != null); 24 | return default(TVertex); 25 | } 26 | } 27 | 28 | TVertex IEdge.Target 29 | { 30 | get 31 | { 32 | Contract.Ensures(Contract.Result() != null); 33 | return default(TVertex); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IEdgeListGraphContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Contracts 5 | { 6 | [ContractClassFor(typeof(IEdgeListGraph<,>))] 7 | abstract class IEdgeListGraphContract 8 | : IEdgeListGraph 9 | where TEdge : IEdge 10 | { 11 | #region IGraph Members 12 | bool IGraph.IsDirected 13 | { 14 | get { throw new NotImplementedException(); } 15 | } 16 | 17 | bool IGraph.AllowParallelEdges 18 | { 19 | get { throw new NotImplementedException(); } 20 | } 21 | 22 | #endregion 23 | 24 | #region IEdgeSet Members 25 | 26 | bool IEdgeSet.IsEdgesEmpty 27 | { 28 | get { throw new NotImplementedException(); } 29 | } 30 | 31 | int IEdgeSet.EdgeCount 32 | { 33 | get { throw new NotImplementedException(); } 34 | } 35 | 36 | System.Collections.Generic.IEnumerable IEdgeSet.Edges 37 | { 38 | get { throw new NotImplementedException(); } 39 | } 40 | 41 | bool IEdgeSet.ContainsEdge(TEdge edge) 42 | { 43 | throw new NotImplementedException(); 44 | } 45 | #endregion 46 | 47 | #region IVertexSet Members 48 | 49 | public bool IsVerticesEmpty { 50 | get { throw new NotImplementedException(); } 51 | } 52 | 53 | public int VertexCount { 54 | get { throw new NotImplementedException(); } 55 | } 56 | 57 | public System.Collections.Generic.IEnumerable Vertices { 58 | get { throw new NotImplementedException(); } 59 | } 60 | 61 | #endregion 62 | 63 | #region IImplicitVertexSet Members 64 | 65 | public bool ContainsVertex(TVertex vertex) { 66 | throw new NotImplementedException(); 67 | } 68 | 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IEdgeSetContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | using System.Linq; 6 | 7 | namespace QuickGraph.Contracts 8 | { 9 | [ContractClassFor(typeof(IEdgeSet<,>))] 10 | abstract class IEdgeSetContract 11 | : IEdgeSet 12 | where TEdge : IEdge 13 | { 14 | bool IEdgeSet.IsEdgesEmpty 15 | { 16 | get 17 | { 18 | IEdgeSet ithis = this; 19 | Contract.Ensures(Contract.Result() == (ithis.EdgeCount == 0)); 20 | 21 | return default(bool); 22 | } 23 | } 24 | 25 | int IEdgeSet.EdgeCount 26 | { 27 | get 28 | { 29 | IEdgeSet ithis = this; 30 | Contract.Ensures(Contract.Result() == Enumerable.Count(ithis.Edges)); 31 | 32 | return default(int); 33 | } 34 | } 35 | 36 | IEnumerable IEdgeSet.Edges 37 | { 38 | get 39 | { 40 | Contract.Ensures(Contract.Result>() != null); 41 | Contract.Ensures(Enumerable.All(Contract.Result>(), e => e != null)); 42 | 43 | return default(IEnumerable); 44 | } 45 | } 46 | 47 | [Pure] 48 | bool IEdgeSet.ContainsEdge(TEdge edge) 49 | { 50 | IEdgeSet ithis = this; 51 | Contract.Requires(edge != null); 52 | Contract.Ensures(Contract.Result() == Contract.Exists(ithis.Edges, e => e.Equals(edge))); 53 | 54 | return default(bool); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IGraphContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Contracts 6 | { 7 | [ContractClassFor(typeof(IGraph<,>))] 8 | abstract class IGraphContract 9 | : IGraph 10 | where TEdge : IEdge 11 | { 12 | bool IGraph.IsDirected 13 | { 14 | get { return default(bool); } 15 | } 16 | 17 | bool IGraph.AllowParallelEdges 18 | { 19 | get { return default(bool); } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IImplicitVertexSetContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph.Contracts 7 | { 8 | [ContractClassFor(typeof(IImplicitVertexSet<>))] 9 | abstract class IImplicitVertexSetContract 10 | : IImplicitVertexSet 11 | { 12 | [Pure] 13 | bool IImplicitVertexSet.ContainsVertex(TVertex vertex) 14 | { 15 | IImplicitVertexSet ithis = this; 16 | Contract.Requires(vertex != null); 17 | 18 | return default(bool); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IMutableGraphContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Contracts 6 | { 7 | [ContractClassFor(typeof(IMutableGraph<,>))] 8 | abstract class IMutableGraphContract 9 | : IMutableGraph 10 | where TEdge : IEdge 11 | { 12 | #region IMutableGraph Members 13 | void IMutableGraph.Clear() 14 | { 15 | IMutableGraph ithis = this; 16 | } 17 | #endregion 18 | 19 | #region IGraph Members 20 | 21 | bool IGraph.IsDirected 22 | { 23 | get { throw new NotImplementedException(); } 24 | } 25 | 26 | bool IGraph.AllowParallelEdges 27 | { 28 | get { throw new NotImplementedException(); } 29 | } 30 | 31 | #endregion 32 | 33 | 34 | event EventHandler IMutableGraph.Cleared 35 | { 36 | add { throw new NotImplementedException(); } 37 | remove { throw new NotImplementedException(); } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IUndirectedEdgeContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using System.Collections.Generic; 4 | 5 | namespace QuickGraph.Contracts 6 | { 7 | [ContractClassFor(typeof(IUndirectedEdge<>))] 8 | abstract class IUndirectedEdgeContract 9 | : IUndirectedEdge 10 | { 11 | [ContractInvariantMethod] 12 | void IUndirectedEdgeInvariant() 13 | { 14 | IUndirectedEdge ithis = this; 15 | Contract.Invariant(Comparer.Default.Compare(ithis.Source, ithis.Target) <= 0); 16 | } 17 | 18 | #region IEdge Members 19 | 20 | public TVertex Source { 21 | get { throw new NotImplementedException(); } 22 | } 23 | 24 | public TVertex Target { 25 | get { throw new NotImplementedException(); } 26 | } 27 | 28 | #endregion 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Contracts/IVertexSetContract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | using System.Linq; 6 | 7 | namespace QuickGraph.Contracts 8 | { 9 | [ContractClassFor(typeof(IVertexSet<>))] 10 | abstract class IVertexSetContract 11 | : IVertexSet 12 | { 13 | bool IVertexSet.IsVerticesEmpty 14 | { 15 | get 16 | { 17 | IVertexSet ithis = this; 18 | Contract.Ensures(Contract.Result() == (ithis.VertexCount == 0)); 19 | 20 | return default(bool); 21 | } 22 | } 23 | 24 | int IVertexSet.VertexCount 25 | { 26 | get 27 | { 28 | IVertexSet ithis = this; 29 | Contract.Ensures(Contract.Result() == Enumerable.Count(ithis.Vertices)); 30 | 31 | return default(int); 32 | } 33 | } 34 | 35 | IEnumerable IVertexSet.Vertices 36 | { 37 | get 38 | { 39 | Contract.Ensures(Contract.Result>() != null); 40 | 41 | return default(IEnumerable); 42 | } 43 | } 44 | 45 | #region IImplicitVertexSet Members 46 | 47 | public bool ContainsVertex(TVertex vertex) { 48 | throw new NotImplementedException(); 49 | } 50 | 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/CreateEdgeDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace QuickGraph 3 | { 4 | /// 5 | /// An edge factory delegate 6 | /// 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public delegate TEdge CreateEdgeDelegate( 11 | IVertexListGraph g, 12 | TVertex source, 13 | TVertex target) 14 | where TEdge : IEdge; 15 | } 16 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/CreateVertexDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace QuickGraph 3 | { 4 | /// 5 | /// A vertex factory delegate. 6 | /// 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public delegate TVertex CreateVertexDelegate( 11 | IVertexListGraph g) 12 | where TEdge : IEdge; 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Directory.Build.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Sandwych.QuickGraph.Core 5 | Generic Graph Data Structures and Algorithms for .NET(.NET Standard and .NET Framework) 6 | 7 | Sandwych.QuickGraph is a port of the awesome QuickGraph to .NET Standard, it provides generic directed/undirected graph datastructures and algorithms for .NET. 8 | graph;topologic;quickgraph 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Edge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// The default implementation. 9 | /// 10 | /// The type of the vertex. 11 | #if !SILVERLIGHT 12 | [Serializable] 13 | #endif 14 | [DebuggerDisplay("{Source}->{Target}")] 15 | public class Edge 16 | : IEdge 17 | { 18 | private readonly TVertex source; 19 | private readonly TVertex target; 20 | 21 | /// 22 | /// Initializes a new instance of the class. 23 | /// 24 | /// The source. 25 | /// The target. 26 | public Edge(TVertex source, TVertex target) 27 | { 28 | Contract.Requires(source != null); 29 | Contract.Requires(target != null); 30 | Contract.Ensures(this.Source.Equals(source)); 31 | Contract.Ensures(this.Target.Equals(target)); 32 | 33 | this.source = source; 34 | this.target = target; 35 | } 36 | 37 | /// 38 | /// Gets the source vertex 39 | /// 40 | /// 41 | public TVertex Source 42 | { 43 | get { return this.source; } 44 | } 45 | 46 | /// 47 | /// Gets the target vertex 48 | /// 49 | /// 50 | public TVertex Target 51 | { 52 | get { return this.target; } 53 | } 54 | 55 | /// 56 | /// Returns a that represents the current . 57 | /// 58 | /// 59 | /// A that represents the current . 60 | /// 61 | public override string ToString() 62 | { 63 | return this.Source + "->" + this.Target; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/EdgeEdgeEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | /// 7 | /// The handler for events involving two edges 8 | /// 9 | public delegate void EdgeEdgeAction(TEdge edge, TEdge targetEdge) 10 | where TEdge : IEdge; 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/EdgeEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | /// 7 | /// An event involving an edge. 8 | /// 9 | /// The type of the vertex. 10 | /// The type of the edge. 11 | #if !SILVERLIGHT 12 | [Serializable] 13 | #endif 14 | public class EdgeEventArgs 15 | : EventArgs 16 | where TEdge : IEdge 17 | { 18 | private readonly TEdge edge; 19 | /// 20 | /// Initializes a new instance of the class. 21 | /// 22 | /// The edge. 23 | public EdgeEventArgs(TEdge edge) 24 | { 25 | Contract.Requires(edge != null); 26 | 27 | this.edge = edge; 28 | } 29 | 30 | /// 31 | /// Gets the edge. 32 | /// 33 | /// The edge. 34 | public TEdge Edge 35 | { 36 | get { return this.edge; } 37 | } 38 | } 39 | 40 | /// 41 | /// The handler for events involving edges 42 | /// 43 | /// type of the vertices 44 | /// type of the edges 45 | /// 46 | public delegate void EdgeAction(TEdge e) 47 | where TEdge : IEdge; 48 | } 49 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/EdgeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | /// 6 | /// An edge factory 7 | /// 8 | public delegate TEdge EdgeFactory(TVertex source, TVertex target) 9 | where TEdge : IEdge; 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/EdgeIdentity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace QuickGraph 7 | { 8 | public delegate string EdgeIdentity(TEdge edge) 9 | where TEdge : IEdge; 10 | } 11 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/EdgePredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | [Pure] 7 | public delegate bool EdgePredicate(TEdge e) 8 | where TEdge : IEdge; 9 | } 10 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/EquatableEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics; 6 | 7 | namespace QuickGraph 8 | { 9 | /// 10 | /// An equatable edge implementation 11 | /// 12 | /// type of the vertices 13 | #if !SILVERLIGHT 14 | [Serializable] 15 | #endif 16 | [DebuggerDisplay("{Source}->{Target}")] 17 | public class EquatableEdge 18 | : Edge 19 | , IEquatable> 20 | { 21 | public EquatableEdge(TVertex source, TVertex target) 22 | : base(source, target) 23 | { } 24 | 25 | public bool Equals(EquatableEdge other) 26 | { 27 | return 28 | (object)other != null && 29 | this.Source.Equals(other.Source) && 30 | this.Target.Equals(other.Target); 31 | } 32 | 33 | public override bool Equals(object obj) 34 | { 35 | return this.Equals(obj as EquatableEdge); 36 | } 37 | 38 | public override int GetHashCode() 39 | { 40 | return 41 | HashCodeHelper.Combine(this.Source.GetHashCode(), this.Target.GetHashCode()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/FuncDelegates.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | #if NET20 6 | public delegate void Action(T value); 7 | public delegate void Action(T1 value1, T2 value2); 8 | public delegate TResult Func(); 9 | public delegate TResult Func(T value); 10 | public delegate TResult Func(T1 value1, T2 value2); 11 | public delegate TResult Func(T1 value1, T2 value2, T3 value3); 12 | #endif 13 | } 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/GraphColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | /// 6 | /// Colors used in vertex coloring algorithms 7 | /// 8 | #if !SILVERLIGHT 9 | [Serializable] 10 | #endif 11 | public enum GraphColor : byte 12 | { 13 | /// 14 | /// Usually initial color, 15 | /// 16 | White = 0, 17 | /// 18 | /// Usually intermidiate color, 19 | /// 20 | Gray, 21 | /// 22 | /// Usually finished color 23 | /// 24 | Black 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IBidirectionalGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A directed graph datastructure that is efficient 10 | /// to traverse both in and out edges. 11 | /// 12 | /// The type of the vertex. 13 | /// The type of the edge. 14 | [ContractClass(typeof(IBidirectionalGraphContract<,>))] 15 | public interface IBidirectionalGraph 16 | : IVertexAndEdgeListGraph 17 | , IBidirectionalIncidenceGraph 18 | where TEdge : IEdge 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/ICloneableEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using QuickGraph.Contracts; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// A cloneable edge 9 | /// 10 | /// type of the vertex 11 | /// type of the edge 12 | [ContractClass(typeof(ICloneableEdgeContract<,>))] 13 | public interface ICloneableEdge 14 | : IEdge 15 | where TEdge : IEdge 16 | { 17 | /// 18 | /// Clones the edge content to a different pair of 19 | /// and vertices 20 | /// 21 | /// The source vertex of the new edge 22 | /// The target vertex of the new edge 23 | /// A clone of the edge with new source and target vertices 24 | TEdge Clone(TVertex source, TVertex target); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IEdge.cs: -------------------------------------------------------------------------------- 1 | using QuickGraph.Contracts; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | /// 7 | /// A directed edge 8 | /// 9 | /// type of the vertices 10 | [ContractClass(typeof(IEdgeContract<>))] 11 | public interface IEdge 12 | { 13 | /// 14 | /// Gets the source vertex 15 | /// 16 | TVertex Source { get;} 17 | /// 18 | /// Gets the target vertex 19 | /// 20 | TVertex Target { get;} 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IEdgeListAndIncidenceGraph.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph 2 | { 3 | /// 4 | /// An incidence graph whose edges can be enumerated 5 | /// 6 | /// type of the vertices 7 | /// type of the edges 8 | public interface IEdgeListAndIncidenceGraph 9 | : IEdgeListGraph 10 | , IIncidenceGraph 11 | where TEdge : IEdge 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IEdgeListGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A graph whose edges can be enumerated 10 | /// 11 | /// type of the vertices 12 | /// type of the edges 13 | [ContractClass(typeof(IEdgeListGraphContract<,>))] 14 | public interface IEdgeListGraph 15 | : IGraph 16 | , IEdgeSet 17 | , IVertexSet 18 | where TEdge : IEdge 19 | {} 20 | } 21 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IEdgeSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using QuickGraph.Contracts; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph 8 | { 9 | /// 10 | /// A set of edges 11 | /// 12 | /// The type of the vertex. 13 | /// The type of the edge. 14 | [ContractClass(typeof(IEdgeSetContract<,>))] 15 | public interface IEdgeSet 16 | where TEdge : IEdge 17 | { 18 | /// 19 | /// Gets a value indicating whether there are no edges in this set. 20 | /// 21 | /// 22 | /// true if this set is empty; otherwise, false. 23 | /// 24 | bool IsEdgesEmpty { get; } 25 | /// 26 | /// Gets the edge count. 27 | /// 28 | /// The edge count. 29 | int EdgeCount { get; } 30 | /// 31 | /// Gets the edges. 32 | /// 33 | /// The edges. 34 | IEnumerable Edges { get; } 35 | /// 36 | /// Determines whether the specified edge contains edge. 37 | /// 38 | /// The edge. 39 | /// 40 | /// true if the specified edge contains edge; otherwise, false. 41 | /// 42 | [Pure] 43 | bool ContainsEdge(TEdge edge); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using QuickGraph.Contracts; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// A graph with vertices of type 9 | /// and edges of type 10 | /// 11 | /// type of the vertices 12 | /// type of the edges 13 | [ContractClass(typeof(IGraphContract<,>))] 14 | public interface IGraph 15 | where TEdge : IEdge 16 | { 17 | /// 18 | /// Gets a value indicating if the graph is directed 19 | /// 20 | bool IsDirected { get;} 21 | /// 22 | /// Gets a value indicating if the graph allows parallel edges 23 | /// 24 | bool AllowParallelEdges { get;} 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IHyperEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuickGraph 5 | { 6 | public interface IHyperEdge 7 | { 8 | int EndPointCount { get;} 9 | IEnumerable EndPoints { get;} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IImplicitUndirectedGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | [ContractClass(typeof(IImplicitUndirectedGraphContract<,>))] 9 | public interface IImplicitUndirectedGraph 10 | : IImplicitVertexSet 11 | , IGraph 12 | where TEdge : IEdge 13 | { 14 | [Pure] 15 | EdgeEqualityComparer EdgeEqualityComparer { get; } 16 | 17 | [Pure] 18 | IEnumerable AdjacentEdges(TVertex v); 19 | 20 | [Pure] 21 | int AdjacentDegree(TVertex v); 22 | 23 | [Pure] 24 | bool IsAdjacentEdgesEmpty(TVertex v); 25 | 26 | [Pure] 27 | TEdge AdjacentEdge(TVertex v, int index); 28 | 29 | [Pure] 30 | bool TryGetEdge(TVertex source, TVertex target, out TEdge edge); 31 | 32 | [Pure] 33 | bool ContainsEdge(TVertex source, TVertex target); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IImplicitVertexSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using QuickGraph.Contracts; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// An implicit set of vertices 9 | /// 10 | /// type of the vertices 11 | [ContractClass(typeof(IImplicitVertexSetContract<>))] 12 | public interface IImplicitVertexSet 13 | { 14 | /// 15 | /// Determines whether the specified vertex contains vertex. 16 | /// 17 | /// The vertex. 18 | /// 19 | /// true if the specified vertex contains vertex; otherwise, false. 20 | /// 21 | [Pure] 22 | bool ContainsVertex(TVertex vertex); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IIncidenceGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Contracts; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | [ContractClass(typeof(IIncidenceGraphContract<,>))] 9 | public interface IIncidenceGraph 10 | : IImplicitGraph 11 | where TEdge : IEdge 12 | { 13 | bool ContainsEdge(TVertex source, TVertex target); 14 | bool TryGetEdges( 15 | TVertex source, 16 | TVertex target, 17 | out IEnumerable edges); 18 | bool TryGetEdge( 19 | TVertex source, 20 | TVertex target, 21 | out TEdge edge); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableBidirectionalGraph.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | using QuickGraph.Contracts; 3 | namespace QuickGraph 4 | { 5 | /// 6 | /// A mutable bidirectional directed graph 7 | /// 8 | /// type of the vertices 9 | /// type of the edges 10 | [ContractClass(typeof(IMutableBidirectionalGraphContract<,>))] 11 | public interface IMutableBidirectionalGraph 12 | : IMutableVertexAndEdgeListGraph 13 | , IBidirectionalGraph 14 | where TEdge : IEdge 15 | { 16 | /// 17 | /// Removes in-edges of that match 18 | /// predicate . 19 | /// 20 | /// 21 | /// 22 | /// Number of edges removed 23 | int RemoveInEdgeIf(TVertex v, EdgePredicate edgePredicate); 24 | 25 | /// 26 | /// Clears in-edges of 27 | /// 28 | /// 29 | void ClearInEdges(TVertex v); 30 | 31 | /// 32 | /// Clears in-edges and out-edges of 33 | /// 34 | /// 35 | void ClearEdges(TVertex v); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using QuickGraph.Contracts; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// A mutable graph instance 9 | /// 10 | /// type of the vertices 11 | /// type of the edges 12 | [ContractClass(typeof(IMutableGraphContract<,>))] 13 | public interface IMutableGraph 14 | : IGraph 15 | where TEdge : IEdge 16 | { 17 | /// 18 | /// Clears the vertex and edges 19 | /// 20 | void Clear(); 21 | 22 | /// 23 | /// Called when the graph vertices and edges have been cleared. 24 | /// 25 | event EventHandler Cleared; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableIncidenceGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A mutable incidence graph 10 | /// 11 | /// 12 | /// 13 | [ContractClass(typeof(IMutableIncidenceGraphContract<,>))] 14 | public interface IMutableIncidenceGraph 15 | : IMutableGraph 16 | , IIncidenceGraph 17 | where TEdge : IEdge 18 | { 19 | /// 20 | /// Removes all out edges of 21 | /// where evalutes to true. 22 | /// 23 | /// 24 | /// 25 | /// 26 | int RemoveOutEdgeIf( 27 | TVertex v, 28 | EdgePredicate predicate); 29 | 30 | /// 31 | /// Trims the out edges of vertex 32 | /// 33 | /// 34 | void ClearOutEdges(TVertex v); 35 | 36 | /// 37 | /// Trims excess storage allocated for edges 38 | /// 39 | void TrimEdgeExcess(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableUndirectedGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A mutable indirect graph 10 | /// 11 | /// 12 | /// 13 | [ContractClass(typeof(IMutableUndirectedGraphContract<,>))] 14 | public interface IMutableUndirectedGraph 15 | : IMutableEdgeListGraph 16 | , IMutableVertexSet 17 | , IUndirectedGraph 18 | , IMutableVertexAndEdgeSet 19 | where TEdge : IEdge 20 | { 21 | int RemoveAdjacentEdgeIf(TVertex vertex, EdgePredicate predicate); 22 | void ClearAdjacentEdges(TVertex vertex); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableVertexAndEdgeListGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Contracts; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A mutable vertex and edge list graph 10 | /// 11 | /// 12 | /// 13 | public interface IMutableVertexAndEdgeListGraph 14 | : IMutableVertexListGraph 15 | , IMutableEdgeListGraph 16 | , IMutableVertexAndEdgeSet 17 | , IVertexAndEdgeListGraph 18 | where TEdge : IEdge 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableVertexAndEdgeSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Contracts; 6 | using System.Diagnostics.Contracts; 7 | 8 | namespace QuickGraph 9 | { 10 | /// 11 | /// A mutable vertex and edge set 12 | /// 13 | /// 14 | /// 15 | [ContractClass(typeof(IMutableVertexAndEdgeSetContract<,>))] 16 | public interface IMutableVertexAndEdgeSet 17 | : IEdgeListGraph 18 | , IMutableVertexSet 19 | , IMutableEdgeListGraph 20 | where TEdge : IEdge 21 | { 22 | /// 23 | /// Adds the vertices and edge to the graph. 24 | /// 25 | /// 26 | /// true if the edge was added, otherwise false. 27 | bool AddVerticesAndEdge(TEdge edge); 28 | 29 | /// 30 | /// Adds a set of edges (and it's vertices if necessary) 31 | /// 32 | /// 33 | /// the number of edges added. 34 | int AddVerticesAndEdgeRange(IEnumerable edges); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableVertexListGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A mutable vertex list graph 10 | /// 11 | /// 12 | /// 13 | [ContractClass(typeof(IMutableVertexListGraphContract<,>))] 14 | public interface IMutableVertexListGraph : 15 | IMutableIncidenceGraph, 16 | IMutableVertexSet 17 | where TEdge : IEdge 18 | { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IMutableVertexSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A mutable vertex set 10 | /// 11 | /// 12 | [ContractClass(typeof(IMutableVertexSetContract<>))] 13 | public interface IMutableVertexSet 14 | : IVertexSet 15 | { 16 | event VertexAction VertexAdded; 17 | bool AddVertex(TVertex v); 18 | int AddVertexRange(IEnumerable vertices); 19 | 20 | event VertexAction VertexRemoved; 21 | bool RemoveVertex(TVertex v); 22 | int RemoveVertexIf(VertexPredicate pred); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/ITagged.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// An instance holding a tag 9 | /// 10 | /// 11 | public interface ITagged 12 | { 13 | /// 14 | /// Gets or sets the tag 15 | /// 16 | TTag Tag { get; set; } 17 | 18 | /// 19 | /// Raised when the tag is changed 20 | /// 21 | event EventHandler TagChanged; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IUndirectedEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using QuickGraph.Contracts; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// An undirected edge. 9 | /// 10 | /// 11 | /// Invariant: source must be less or equal to target (using the default comparer) 12 | /// 13 | /// type of the vertices 14 | [ContractClass(typeof(IUndirectedEdgeContract<>))] 15 | public interface IUndirectedEdge 16 | : IEdge 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IUndirectedGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using QuickGraph.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// An undirected graph 10 | /// 11 | /// 12 | /// 13 | [ContractClass(typeof(IUndirectedGraphContract<,>))] 14 | public interface IUndirectedGraph 15 | : IImplicitUndirectedGraph 16 | , IEdgeListGraph 17 | , IGraph 18 | where TEdge : IEdge 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IVertexAndEdgeListGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | /// 6 | /// A directed graph where vertices and edges can be enumerated efficiently. 7 | /// 8 | /// type of the vertices 9 | /// type of the edges 10 | public interface IVertexAndEdgeListGraph 11 | : IVertexListGraph 12 | , IEdgeListGraph 13 | where TEdge : IEdge 14 | {} 15 | } 16 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IVertexListGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuickGraph 5 | { 6 | /// 7 | /// A directed graph datastructure where out-edges can be traversed, 8 | /// i.e. a vertex set + implicit graph. 9 | /// 10 | /// The type of the vertex. 11 | /// The type of the edge. 12 | public interface IVertexListGraph 13 | : IIncidenceGraph 14 | , IVertexSet 15 | where TEdge : IEdge 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IVertexSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | using QuickGraph.Contracts; 6 | 7 | namespace QuickGraph 8 | { 9 | /// 10 | /// A set of vertices 11 | /// 12 | /// type of the vertices 13 | [ContractClass(typeof(IVertexSetContract<>))] 14 | public interface IVertexSet 15 | : IImplicitVertexSet 16 | { 17 | /// 18 | /// Gets a value indicating whether there are no vertices in this set. 19 | /// 20 | /// 21 | /// true if the vertex set is empty; otherwise, false. 22 | /// 23 | bool IsVerticesEmpty { get;} 24 | 25 | /// 26 | /// Gets the vertex count. 27 | /// 28 | /// The vertex count. 29 | int VertexCount { get;} 30 | 31 | /// 32 | /// Gets the vertices. 33 | /// 34 | /// The vertices. 35 | IEnumerable Vertices { get;} 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IdentifiableEdgeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// A factory of identifiable edges. 9 | /// 10 | public delegate TEdge IdentifiableEdgeFactory(TVertex source, TVertex target, string id) 11 | where TEdge: IEdge; 12 | } 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/IdentifiableVertexFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// A factory of identifiable vertices. 9 | /// 10 | public delegate TVertex IdentifiableVertexFactory(string id); 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/NegativeCycleGraphException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public class NegativeCycleGraphException 11 | : QuickGraphException 12 | { 13 | public NegativeCycleGraphException() { } 14 | public NegativeCycleGraphException(string message) : base(message) { } 15 | public NegativeCycleGraphException(string message, Exception inner) : base(message, inner) { } 16 | #if !SILVERLIGHT 17 | protected NegativeCycleGraphException( 18 | System.Runtime.Serialization.SerializationInfo info, 19 | System.Runtime.Serialization.StreamingContext context) 20 | : base(info, context) { } 21 | #endif 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/NegativeWeightException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | #if !SILVERLIGHT 6 | [System.Serializable] 7 | #endif 8 | public class NegativeWeightException 9 | : QuickGraphException 10 | { 11 | public NegativeWeightException() { } 12 | public NegativeWeightException(string message) : base(message) { } 13 | public NegativeWeightException(string message, Exception inner) : base(message, inner) { } 14 | #if !SILVERLIGHT 15 | protected NegativeWeightException( 16 | System.Runtime.Serialization.SerializationInfo info, 17 | System.Runtime.Serialization.StreamingContext context) 18 | : base(info, context) { } 19 | #endif 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/NonAcyclicGraphException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | #if !SILVERLIGHT 6 | [Serializable] 7 | #endif 8 | public class NonAcyclicGraphException 9 | : QuickGraphException 10 | { 11 | public NonAcyclicGraphException() { } 12 | public NonAcyclicGraphException(string message) : base( message ) { } 13 | public NonAcyclicGraphException(string message, System.Exception inner) : base( message, inner ) { } 14 | #if !SILVERLIGHT 15 | protected NonAcyclicGraphException( 16 | System.Runtime.Serialization.SerializationInfo info, 17 | System.Runtime.Serialization.StreamingContext context) : base( info, context ) { } 18 | #endif 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/NonStronglyConnectedGraphException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace QuickGraph 3 | { 4 | /// 5 | /// Exception raised when an algorithm detects a non-strongly connected graph. 6 | /// 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public class NonStronglyConnectedGraphException 11 | : QuickGraphException 12 | { 13 | public NonStronglyConnectedGraphException() { } 14 | public NonStronglyConnectedGraphException(string message) : base( message ) { } 15 | public NonStronglyConnectedGraphException(string message, System.Exception inner) : base( message, inner ) { } 16 | #if !SILVERLIGHT 17 | protected NonStronglyConnectedGraphException( 18 | System.Runtime.Serialization.SerializationInfo info, 19 | System.Runtime.Serialization.StreamingContext context) : base( info, context ) { } 20 | #endif 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/ParallelEdgeNotAllowedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | #if !SILVERLIGHT 6 | [Serializable] 7 | #endif 8 | public class ParallelEdgeNotAllowedException 9 | : QuickGraphException 10 | { 11 | public ParallelEdgeNotAllowedException() { } 12 | public ParallelEdgeNotAllowedException(string message) : base( message ) { } 13 | public ParallelEdgeNotAllowedException(string message, System.Exception inner) : base( message, inner ) { } 14 | #if !SILVERLIGHT 15 | protected ParallelEdgeNotAllowedException( 16 | System.Runtime.Serialization.SerializationInfo info, 17 | System.Runtime.Serialization.StreamingContext context) : base( info, context ) { } 18 | #endif 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/FilteredImplicitGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Predicates 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public class FilteredImplicitGraph 11 | : FilteredImplicitVertexSet 12 | , IImplicitGraph 13 | where TEdge : IEdge 14 | where TGraph : IImplicitGraph 15 | { 16 | public FilteredImplicitGraph( 17 | TGraph baseGraph, 18 | VertexPredicate vertexPredicate, 19 | EdgePredicate edgePredicate 20 | ) 21 | :base(baseGraph,vertexPredicate,edgePredicate) 22 | { } 23 | 24 | [Pure] 25 | public bool IsOutEdgesEmpty(TVertex v) 26 | { 27 | return this.OutDegree(v) == 0; 28 | } 29 | 30 | [Pure] 31 | public int OutDegree(TVertex v) 32 | { 33 | int count =0; 34 | foreach (var edge in this.BaseGraph.OutEdges(v)) 35 | if (this.TestEdge(edge)) 36 | count++; 37 | return count; 38 | } 39 | 40 | [Pure] 41 | public IEnumerable OutEdges(TVertex v) 42 | { 43 | foreach (var edge in this.BaseGraph.OutEdges(v)) 44 | if (this.TestEdge(edge)) 45 | yield return edge; 46 | } 47 | 48 | [Pure] 49 | public bool TryGetOutEdges(TVertex v, out IEnumerable edges) 50 | { 51 | IEnumerable baseEdges; 52 | if (!this.BaseGraph.TryGetOutEdges(v, out baseEdges)) 53 | { 54 | edges = null; 55 | return false; 56 | } 57 | 58 | edges = this.OutEdges(v); 59 | return true; 60 | } 61 | 62 | [Pure] 63 | public TEdge OutEdge(TVertex v, int index) 64 | { 65 | throw new NotSupportedException(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/FilteredImplicitVertexSetGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | namespace QuickGraph.Predicates 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public class FilteredImplicitVertexSet 10 | : FilteredGraph 11 | , IImplicitVertexSet 12 | where TEdge : IEdge 13 | where TGraph : IGraph, IImplicitVertexSet 14 | { 15 | public FilteredImplicitVertexSet( 16 | TGraph baseGraph, 17 | VertexPredicate vertexPredicate, 18 | EdgePredicate edgePredicate 19 | ) 20 | :base(baseGraph,vertexPredicate,edgePredicate) 21 | { } 22 | 23 | [Pure] 24 | public bool ContainsVertex(TVertex vertex) 25 | { 26 | return 27 | this.VertexPredicate(vertex) && 28 | this.BaseGraph.ContainsVertex(vertex); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/FilteredVertexListGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | namespace QuickGraph.Predicates 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public class FilteredVertexListGraph 10 | : FilteredIncidenceGraph 11 | , IVertexListGraph 12 | where TEdge : IEdge 13 | where Graph : IVertexListGraph 14 | { 15 | public FilteredVertexListGraph( 16 | Graph baseGraph, 17 | VertexPredicate vertexPredicate, 18 | EdgePredicate edgePredicate 19 | ) 20 | :base(baseGraph,vertexPredicate,edgePredicate) 21 | { } 22 | 23 | public bool IsVerticesEmpty 24 | { 25 | get 26 | { 27 | foreach (var v in this.BaseGraph.Vertices) 28 | if (this.VertexPredicate(v)) 29 | return false; 30 | return true; 31 | } 32 | } 33 | 34 | public int VertexCount 35 | { 36 | get 37 | { 38 | int count = 0; 39 | foreach (var v in this.BaseGraph.Vertices) 40 | if (this.VertexPredicate(v)) 41 | count++; 42 | return count; 43 | } 44 | } 45 | 46 | public IEnumerable Vertices 47 | { 48 | get 49 | { 50 | foreach (var v in this.BaseGraph.Vertices) 51 | if (this.VertexPredicate(v)) 52 | yield return v; 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/InDictionaryVertexPredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Predicates 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public sealed class InDictionaryVertexPredicate 11 | { 12 | private readonly IDictionary dictionary; 13 | 14 | public InDictionaryVertexPredicate( 15 | IDictionary dictionary) 16 | { 17 | Contract.Requires(dictionary != null); 18 | this.dictionary = dictionary; 19 | } 20 | 21 | [Pure] 22 | public bool Test(TVertex v) 23 | { 24 | Contract.Requires(v != null); 25 | 26 | return this.dictionary.ContainsKey(v); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/IsolatedVertexPredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Predicates 5 | { 6 | /// 7 | /// A vertex predicate that detects vertex with no in or out edges. 8 | /// 9 | /// type of the vertices 10 | /// type of the edges 11 | public sealed class IsolatedVertexPredicate 12 | where TEdge : IEdge 13 | { 14 | private readonly IBidirectionalGraph visitedGraph; 15 | 16 | public IsolatedVertexPredicate(IBidirectionalGraph visitedGraph) 17 | { 18 | Contract.Requires(visitedGraph!=null); 19 | 20 | this.visitedGraph = visitedGraph; 21 | } 22 | 23 | [Pure] 24 | public bool Test(TVertex v) 25 | { 26 | Contract.Requires(v != null); 27 | 28 | return this.visitedGraph.IsInEdgesEmpty(v) 29 | && this.visitedGraph.IsOutEdgesEmpty(v); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/ResidualEdgePrediate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Predicates 6 | { 7 | public sealed class ResidualEdgePredicate 8 | where TEdge : IEdge 9 | { 10 | private readonly IDictionary residualCapacities; 11 | 12 | public ResidualEdgePredicate( 13 | IDictionary residualCapacities) 14 | { 15 | Contract.Requires(residualCapacities != null); 16 | 17 | this.residualCapacities = residualCapacities; 18 | } 19 | 20 | public IDictionary ResidualCapacities 21 | { 22 | get 23 | { 24 | return this.residualCapacities; 25 | } 26 | } 27 | 28 | public bool Test(TEdge e) 29 | { 30 | Contract.Requires(e != null); 31 | return 0 < this.residualCapacities[e]; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/ReversedResidualEdgePredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | namespace QuickGraph.Predicates 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public sealed class ReversedResidualEdgePredicate 10 | where TEdge : IEdge 11 | { 12 | private readonly IDictionary residualCapacities; 13 | private readonly IDictionary reversedEdges; 14 | 15 | public ReversedResidualEdgePredicate( 16 | IDictionary residualCapacities, 17 | IDictionary reversedEdges) 18 | { 19 | Contract.Requires(residualCapacities != null); 20 | Contract.Requires(reversedEdges != null); 21 | 22 | this.residualCapacities = residualCapacities; 23 | this.reversedEdges = reversedEdges; 24 | } 25 | 26 | /// 27 | /// Residual capacities map 28 | /// 29 | public IDictionary ResidualCapacities 30 | { 31 | get 32 | { 33 | return this.residualCapacities; 34 | } 35 | } 36 | 37 | /// 38 | /// Reversed edges map 39 | /// 40 | public IDictionary ReversedEdges 41 | { 42 | get 43 | { 44 | return this.reversedEdges; 45 | } 46 | } 47 | 48 | public bool Test(TEdge e) 49 | { 50 | Contract.Requires(e != null); 51 | return 0 < this.residualCapacities[reversedEdges[e]]; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Predicates/SinkVertexPredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph.Predicates 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public sealed class SinkVertexPredicate 10 | where TEdge : IEdge 11 | { 12 | private readonly IIncidenceGraph visitedGraph; 13 | 14 | public SinkVertexPredicate(IIncidenceGraph visitedGraph) 15 | { 16 | Contract.Requires(visitedGraph != null); 17 | 18 | this.visitedGraph = visitedGraph; 19 | } 20 | 21 | public bool Test(TVertex v) 22 | { 23 | return this.visitedGraph.IsOutEdgesEmpty(v); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/QuickGraphException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | #if !SILVERLIGHT 6 | [Serializable] 7 | #endif 8 | public abstract class QuickGraphException 9 | : Exception 10 | { 11 | protected QuickGraphException() { } 12 | protected QuickGraphException(string message) : base(message) { } 13 | protected QuickGraphException(string message, Exception inner) : base(message, inner) { } 14 | #if !SILVERLIGHT 15 | protected QuickGraphException( 16 | System.Runtime.Serialization.SerializationInfo info, 17 | System.Runtime.Serialization.StreamingContext context) 18 | : base(info, context) { } 19 | #endif 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/SReversedEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Diagnostics.Contracts; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace QuickGraph 7 | { 8 | /// 9 | /// A reversed edge 10 | /// 11 | /// type of the vertices 12 | /// type of the edges 13 | #if !SILVERLIGHT 14 | [Serializable] 15 | #endif 16 | [StructLayout(LayoutKind.Auto)] 17 | [DebuggerDisplay("{Source}<-{Target}")] 18 | public readonly struct SReversedEdge 19 | : IEdge 20 | , IEquatable> 21 | where TEdge : IEdge 22 | { 23 | private readonly TEdge originalEdge; 24 | public SReversedEdge(TEdge originalEdge) 25 | { 26 | Contract.Requires(originalEdge != null); 27 | 28 | this.originalEdge = originalEdge; 29 | } 30 | 31 | public TEdge OriginalEdge 32 | { 33 | get { return this.originalEdge; } 34 | } 35 | 36 | public TVertex Source 37 | { 38 | get { return this.OriginalEdge.Target; } 39 | } 40 | 41 | public TVertex Target 42 | { 43 | get { return this.OriginalEdge.Source; } 44 | } 45 | 46 | [Pure] 47 | public override bool Equals(object obj) 48 | { 49 | if (!(obj is SReversedEdge)) 50 | return false; 51 | 52 | return Equals((SReversedEdge)obj); 53 | } 54 | 55 | [Pure] 56 | public override int GetHashCode() 57 | { 58 | return this.OriginalEdge.GetHashCode() ^ 16777619; 59 | } 60 | 61 | [Pure] 62 | public override string ToString() 63 | { 64 | return String.Format("R({0})", this.OriginalEdge); 65 | } 66 | 67 | [Pure] 68 | public bool Equals(SReversedEdge other) 69 | { 70 | return this.OriginalEdge.Equals(other.OriginalEdge); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/Sandwych.QuickGraph.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard1.6;netstandard2.0;netstandard2.1;net45 5 | QuickGraph 6 | latest 7 | 8 | 9 | 10 | TRACE;SILVERLIGHT 11 | 12 | 13 | 14 | TRACE;DEBUG;SILVERLIGHT 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/TaggedEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public class TaggedEdge 10 | : Edge 11 | , ITagged 12 | { 13 | private TTag tag; 14 | 15 | public TaggedEdge(TVertex source, TVertex target, TTag tag) 16 | :base(source,target) 17 | { 18 | Contract.Ensures(Object.Equals(this.Tag,tag)); 19 | 20 | this.tag = tag; 21 | } 22 | 23 | public event EventHandler TagChanged; 24 | 25 | protected virtual void OnTagChanged(EventArgs e) 26 | { 27 | var eh = this.TagChanged; 28 | if (eh != null) 29 | eh(this, e); 30 | } 31 | 32 | public TTag Tag 33 | { 34 | get { return this.tag; } 35 | set 36 | { 37 | if (!object.Equals(this.tag, value)) 38 | { 39 | this.tag = value; 40 | this.OnTagChanged(EventArgs.Empty); 41 | } 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/TaggedEquatableEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using System.Diagnostics; 4 | 5 | namespace QuickGraph 6 | { 7 | /// 8 | /// An equatable, tagged, edge 9 | /// 10 | /// type of the vertices 11 | /// 12 | #if !SILVERLIGHT 13 | [Serializable] 14 | #endif 15 | [DebuggerDisplay("{Source}->{Target}:{Tag}")] 16 | public class TaggedEquatableEdge 17 | : EquatableEdge 18 | , ITagged 19 | { 20 | private TTag tag; 21 | 22 | public TaggedEquatableEdge(TVertex source, TVertex target, TTag tag) 23 | : base(source, target) 24 | { 25 | Contract.Ensures(Object.Equals(this.Tag, tag)); 26 | 27 | this.tag = tag; 28 | } 29 | 30 | public event EventHandler TagChanged; 31 | 32 | protected virtual void OnTagChanged(EventArgs e) 33 | { 34 | var eh = this.TagChanged; 35 | if (eh != null) 36 | eh(this, e); 37 | } 38 | 39 | public TTag Tag 40 | { 41 | get { return this.tag; } 42 | set 43 | { 44 | if (!object.Equals(this.tag, value)) 45 | { 46 | this.tag = value; 47 | this.OnTagChanged(EventArgs.Empty); 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/TryFuncDelegates.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph 7 | { 8 | [Pure] 9 | public delegate bool TryFunc(T arg, out TResult result); 10 | [Pure] 11 | public delegate bool TryFunc(T1 arg, T2 arg2, out TResult result); 12 | [Pure] 13 | public delegate bool TryFunc(T1 arg, T2 arg2, T3 arg3, out TResult result); 14 | [Pure] 15 | public delegate bool TryFunc(T1 arg, T2 arg2, T3 arg3, T4 arg4, out TResult result); 16 | } 17 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/UndirectedEdgeEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph 6 | { 7 | #if !SILVERLIGHT 8 | [Serializable] 9 | #endif 10 | public class UndirectedEdgeEventArgs 11 | : EdgeEventArgs 12 | where TEdge : IEdge 13 | { 14 | private readonly bool reversed; 15 | 16 | public UndirectedEdgeEventArgs(TEdge edge, bool reversed) 17 | :base(edge) 18 | { 19 | this.reversed = reversed; 20 | } 21 | 22 | public bool Reversed 23 | { 24 | get { return this.reversed; } 25 | } 26 | 27 | public TVertex Source 28 | { 29 | get { return this.reversed ? this.Edge.Target : this.Edge.Source; } 30 | } 31 | 32 | public TVertex Target 33 | { 34 | get { return this.reversed ? this.Edge.Source : this.Edge.Target; } 35 | } 36 | } 37 | 38 | public delegate void UndirectedEdgeAction( 39 | Object sender, 40 | UndirectedEdgeEventArgs e) 41 | where TEdge : IEdge; 42 | } 43 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/VertexEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | #if !SILVERLIGHT 7 | [Serializable] 8 | #endif 9 | public abstract class VertexEventArgs : EventArgs 10 | { 11 | private readonly TVertex vertex; 12 | protected VertexEventArgs(TVertex vertex) 13 | { 14 | Contract.Requires(vertex != null); 15 | this.vertex = vertex; 16 | } 17 | 18 | public TVertex Vertex 19 | { 20 | get { return this.vertex; } 21 | } 22 | } 23 | 24 | public delegate void VertexAction(TVertex vertex); 25 | } 26 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/VertexFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | public delegate TVertex VertexFactory(); 6 | } 7 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/VertexIdentity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph 8 | { 9 | [Pure] 10 | public delegate string VertexIdentity(TVertex v); 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/VertexIndexer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph 8 | { 9 | [Pure] 10 | public delegate int VertexIndexer(TVertex v); 11 | } 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Core/VertexPredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace QuickGraph 5 | { 6 | [Pure] 7 | public delegate bool VertexPredicate(TVertex v); 8 | } 9 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Data/DataRelationEdge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Data; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Data 8 | { 9 | public sealed class DataRelationEdge 10 | : IEdge 11 | { 12 | private readonly DataRelation relation; 13 | public DataRelationEdge(DataRelation relation) 14 | { 15 | Contract.Requires(relation != null); 16 | 17 | this.relation = relation; 18 | } 19 | 20 | public DataRelation Relation 21 | { 22 | get { return this.relation; } 23 | } 24 | 25 | public DataTable Source 26 | { 27 | get { return this.relation.ParentTable;} 28 | } 29 | 30 | public DataTable Target 31 | { 32 | get { return this.relation.ChildTable; } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Data/DataSetGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Data; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Data 8 | { 9 | public class DataSetGraph : 10 | BidirectionalGraph 11 | { 12 | readonly DataSet dataSet; 13 | public DataSet DataSet 14 | { 15 | get { return this.dataSet; } 16 | } 17 | 18 | internal DataSetGraph(DataSet dataSet) 19 | { 20 | Contract.Requires(dataSet != null); 21 | 22 | this.dataSet = dataSet; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Data/DataSetGraphExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Data; 5 | using System.Diagnostics.Contracts; 6 | using QuickGraph.Graphviz; 7 | 8 | namespace QuickGraph.Data 9 | { 10 | public static class DataSetGraphExtensions 11 | { 12 | public static DataSetGraph ToGraph( 13 | #if !NET20 14 | this 15 | #endif 16 | DataSet ds) 17 | { 18 | Contract.Requires(ds != null); 19 | 20 | var g = new DataSetGraph(ds); 21 | var populator = new DataSetGraphPopulatorAlgorithm(g, ds); 22 | populator.Compute(); 23 | 24 | return g; 25 | } 26 | 27 | public static string ToGraphviz( 28 | #if !NET20 29 | this 30 | #endif 31 | DataSetGraph visitedGraph) 32 | { 33 | Contract.Requires(visitedGraph != null); 34 | 35 | var algorithm = new DataSetGraphvizAlgorithm(visitedGraph); 36 | return algorithm.Generate(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Data/DataSetGraphPopulatorAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Data; 5 | using QuickGraph.Algorithms; 6 | using System.Diagnostics.Contracts; 7 | 8 | namespace QuickGraph.Data 9 | { 10 | public sealed class DataSetGraphPopulatorAlgorithm : 11 | AlgorithmBase> 12 | { 13 | private readonly DataSet dataSet; 14 | 15 | public DataSetGraphPopulatorAlgorithm( 16 | IMutableVertexAndEdgeListGraph visitedGraph, 17 | DataSet dataSet 18 | ) 19 | : base(visitedGraph) 20 | { 21 | Contract.Requires(dataSet != null); 22 | 23 | this.dataSet = dataSet; 24 | } 25 | 26 | public DataSet DataSet 27 | { 28 | get { return this.dataSet; } 29 | } 30 | 31 | protected override void InternalCompute() 32 | { 33 | foreach (DataTable table in this.DataSet.Tables) 34 | this.VisitedGraph.AddVertex(table); 35 | 36 | foreach (DataRelation relation in this.DataSet.Relations) 37 | this.VisitedGraph.AddEdge(new DataRelationEdge(relation)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Data/Sandwych.QuickGraph.Data.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0;netstandard2.1;net45 5 | QuickGraph.Data 6 | latest 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/CondensatedGraphRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using QuickGraph.Algorithms.Condensation; 4 | 5 | namespace QuickGraph.Graphviz 6 | { 7 | public class CondensatedGraphRenderer : 8 | GraphRendererBase> 9 | where TEdge : IEdge 10 | where TGraph : IMutableVertexAndEdgeListGraph, new() 11 | { 12 | public CondensatedGraphRenderer( 13 | IVertexAndEdgeListGraph> visitedGraph) 14 | :base(visitedGraph) 15 | {} 16 | 17 | protected override void Initialize() 18 | { 19 | base.Initialize(); 20 | this.Graphviz.FormatVertex+=new FormatVertexEventHandler(Graphviz_FormatVertex); 21 | this.Graphviz.FormatEdge += new FormatEdgeAction>(Graphviz_FormatEdge); 22 | } 23 | 24 | 25 | void Graphviz_FormatVertex(Object sender, FormatVertexEventArgs e) 26 | { 27 | StringWriter sw = new StringWriter(); 28 | sw.WriteLine("{0}-{1}", e.Vertex.VertexCount, e.Vertex.EdgeCount); 29 | foreach (var v in e.Vertex.Vertices) 30 | sw.WriteLine(" {0}", v); 31 | foreach(TEdge edge in e.Vertex.Edges) 32 | sw.WriteLine(" {0}", edge); 33 | e.VertexFormatter.Label = this.Graphviz.Escape(sw.ToString()); 34 | } 35 | 36 | void Graphviz_FormatEdge(object sender, FormatEdgeEventArgs> e) 37 | { 38 | StringWriter sw = new StringWriter(); 39 | sw.WriteLine("{0}", e.Edge.Edges.Count); 40 | foreach (var edge in e.Edge.Edges) 41 | sw.WriteLine(" {0}", edge); 42 | e.EdgeFormatter.Label.Value = this.Graphviz.Escape(sw.ToString()); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizArrowClipping.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizArrowClipping 6 | { 7 | None, 8 | Left, 9 | Right 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizArrowFilling.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizArrowFilling 6 | { 7 | Close, 8 | Open 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizArrowShape.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizArrowShape 6 | { 7 | Box, 8 | Crow, 9 | Diamond, 10 | Dot, 11 | Inv, 12 | None, 13 | Normal, 14 | Tee, 15 | Vee 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizClusterMode.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizClusterMode 6 | { 7 | Local, 8 | Global, 9 | None 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph.Graphviz.Dot 7 | { 8 | public readonly struct GraphvizColor 9 | : IEquatable 10 | { 11 | readonly byte a; 12 | readonly byte r; 13 | readonly byte g; 14 | readonly byte b; 15 | 16 | public GraphvizColor( 17 | byte a, byte r, byte g, byte b) 18 | { 19 | Contract.Requires(a >= 0); 20 | Contract.Requires(r >= 0); 21 | Contract.Requires(g >= 0); 22 | Contract.Requires(b >= 0); 23 | 24 | this.a = a; 25 | this.r = r; 26 | this.g = g; 27 | this.b = b; 28 | } 29 | 30 | public byte A { get { return this.a; } } 31 | public byte R { get { return this.r; } } 32 | public byte G { get { return this.g; } } 33 | public byte B { get { return this.b; } } 34 | 35 | public static GraphvizColor Black 36 | { 37 | get { return new GraphvizColor(0xFF, 0, 0, 0); } 38 | } 39 | 40 | public static GraphvizColor White 41 | { 42 | get { return new GraphvizColor(0xFF, 0xFF, 0xFF, 0xFF); } 43 | } 44 | 45 | public static GraphvizColor LightYellow 46 | { 47 | get { return new GraphvizColor(0xFF, 0xFF, 0xFF, 0xE0); } 48 | } 49 | 50 | public bool Equals(GraphvizColor other) 51 | { 52 | return this.a == other.a && this.r == other.r && this.g == other.g && this.b == other.b; 53 | } 54 | 55 | public override int GetHashCode() 56 | { 57 | return (int)(this.a << 24 | this.r << 16 | this.g << 8 | this.b); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizEdgeDirection.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizEdgeDirection 6 | { 7 | None, 8 | Forward, 9 | Back, 10 | Both 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizEdgeStyle.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizEdgeStyle 6 | { 7 | Unspecified, 8 | Invis, 9 | Dashed, 10 | Dotted, 11 | Bold, 12 | Solid 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizFont.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Diagnostics.Contracts; 5 | 6 | namespace QuickGraph.Graphviz.Dot 7 | { 8 | public sealed class GraphvizFont 9 | { 10 | readonly string name; 11 | readonly float sizeInPoints; 12 | 13 | public string Name { get { return this.name; } } 14 | public float SizeInPoints { get { return this.sizeInPoints; } } 15 | 16 | public GraphvizFont(string name, float sizeInPoints) 17 | { 18 | Contract.Requires(!String.IsNullOrEmpty(name)); 19 | Contract.Requires(sizeInPoints > 0); 20 | 21 | this.name = name; 22 | this.sizeInPoints = sizeInPoints; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizImageType.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | using System.ComponentModel; 5 | 6 | public enum GraphvizImageType 7 | { 8 | /// 9 | /// Client-side imagemaps 10 | /// 11 | Cmap = 6, 12 | Fig = 0, 13 | Gd = 1, 14 | Gd2 = 2, 15 | Gif = 3, 16 | /// 17 | /// HP-GL/2 format 18 | /// 19 | Hpgl = 4, 20 | /// 21 | /// Server-side imagemaps 22 | /// 23 | Imap = 5, 24 | Jpeg = 7, 25 | /// 26 | /// FrameMaker MIF format 27 | /// 28 | Mif = 8, 29 | /// 30 | /// MetaPost 31 | /// 32 | Mp = 9, 33 | /// 34 | /// PCL format 35 | /// 36 | Pcl = 10, 37 | /// 38 | /// PIC format 39 | /// 40 | Pic = 11, 41 | /// 42 | /// plain text format 43 | /// 44 | PlainText = 12, 45 | /// 46 | /// Portable Network Graphics format 47 | /// 48 | Png = 13, 49 | /// 50 | /// Postscript 51 | /// 52 | Ps = 14, 53 | /// 54 | /// PostScript for PDF 55 | /// 56 | Ps2 = 15, 57 | /// 58 | /// Scalable Vector Graphics 59 | /// 60 | Svg = 0x10, 61 | /// 62 | /// Scalable Vector Graphics, gzipped 63 | /// 64 | Svgz = 0x11, 65 | /// 66 | /// VRML 67 | /// 68 | Vrml = 0x12, 69 | /// 70 | /// Visual Thought format 71 | /// 72 | Vtx = 0x13, 73 | /// 74 | /// Wireless BitMap format 75 | /// 76 | Wbmp = 20 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizLabelJustification.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizLabelJustification 6 | { 7 | L, 8 | R, 9 | C 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizLabelLocation.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizLabelLocation 6 | { 7 | T, 8 | B 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizLayer.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | using System.Diagnostics.Contracts; 5 | 6 | public class GraphvizLayer 7 | { 8 | private string name; 9 | 10 | public GraphvizLayer(string name) 11 | { 12 | Contract.Requires(!String.IsNullOrEmpty(name)); 13 | 14 | this.name = name; 15 | } 16 | 17 | public string Name 18 | { 19 | get 20 | { 21 | return this.name; 22 | } 23 | set 24 | { 25 | Contract.Requires(!String.IsNullOrEmpty(value)); 26 | this.name = value; 27 | } 28 | } 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizLayerCollection.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | using System.IO; 5 | using System.Reflection; 6 | using System.Collections.ObjectModel; 7 | using System.Diagnostics.Contracts; 8 | 9 | public class GraphvizLayerCollection : Collection 10 | { 11 | private string m_Separators = ":"; 12 | 13 | public GraphvizLayerCollection() 14 | {} 15 | 16 | public GraphvizLayerCollection(GraphvizLayer[] items) 17 | :base(items) 18 | {} 19 | 20 | public GraphvizLayerCollection(GraphvizLayerCollection items) 21 | :base(items) 22 | {} 23 | 24 | public string ToDot() 25 | { 26 | if (base.Count == 0) 27 | { 28 | return null; 29 | } 30 | using (StringWriter writer = new StringWriter()) 31 | { 32 | writer.Write("layers=\""); 33 | bool flag = false; 34 | foreach (GraphvizLayer layer in this) 35 | { 36 | if (flag) 37 | { 38 | writer.Write(this.Separators); 39 | } 40 | else 41 | { 42 | flag = true; 43 | } 44 | writer.Write(layer.Name); 45 | } 46 | writer.WriteLine("\";"); 47 | writer.WriteLine("layersep=\"{0}\"", this.Separators); 48 | return writer.ToString(); 49 | } 50 | } 51 | 52 | public string Separators 53 | { 54 | get 55 | { 56 | return this.m_Separators; 57 | } 58 | set 59 | { 60 | Contract.Requires(!String.IsNullOrEmpty(value)); 61 | 62 | this.m_Separators = value; 63 | } 64 | } 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizOutputMode.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizOutputMode 6 | { 7 | BreadthFirst, 8 | NodesFirst, 9 | EdgesFirst 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizPageDirection.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizPageDirection 6 | { 7 | BL, 8 | BR, 9 | TL, 10 | TR, 11 | RB, 12 | RT, 13 | LB, 14 | LT 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Graphviz.Dot 6 | { 7 | public sealed class GraphvizPoint 8 | { 9 | readonly int x; 10 | readonly int y; 11 | 12 | public int X { get { return this.x; } } 13 | public int Y { get { return this.y; } } 14 | 15 | public GraphvizPoint(int x, int y) 16 | { 17 | this.x = x; 18 | this.y = y; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizRankDirection.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizRankDirection 6 | { 7 | LR, 8 | TB 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizRatioMode.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizRatioMode 6 | { 7 | Fill, 8 | Compress, 9 | Auto 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizRecord.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | using System.Text; 5 | 6 | public class GraphvizRecord 7 | { 8 | private readonly GraphvizRecordCellCollection cells = new GraphvizRecordCellCollection(); 9 | 10 | public string ToDot() 11 | { 12 | if (this.Cells.Count == 0) 13 | { 14 | return ""; 15 | } 16 | StringBuilder builder = new StringBuilder(); 17 | bool flag = false; 18 | foreach (GraphvizRecordCell cell in this.Cells) 19 | { 20 | if (flag) 21 | { 22 | builder.AppendFormat(" | {0}", cell.ToDot()); 23 | continue; 24 | } 25 | builder.Append(cell.ToDot()); 26 | flag = true; 27 | } 28 | return builder.ToString(); 29 | } 30 | 31 | public override string ToString() 32 | { 33 | return this.ToDot(); 34 | } 35 | 36 | public GraphvizRecordCellCollection Cells 37 | { 38 | get 39 | { 40 | return this.cells; 41 | } 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizRecordCellCollection.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | using System.Reflection; 5 | using System.Collections.ObjectModel; 6 | 7 | public sealed class GraphvizRecordCellCollection : Collection 8 | { 9 | public GraphvizRecordCellCollection() 10 | {} 11 | 12 | public GraphvizRecordCellCollection(GraphvizRecordCell[] items) 13 | :base(items) 14 | {} 15 | 16 | public GraphvizRecordCellCollection(GraphvizRecordCellCollection items) 17 | :base(items) 18 | {} 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizRecordEscaper.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | using System.Text.RegularExpressions; 5 | using System.Diagnostics.Contracts; 6 | 7 | public sealed class GraphvizRecordEscaper 8 | { 9 | private Regex escapeRegExp = new Regex("(?\\n)|(?\\[|\\]|\\||<|>|\"| )", RegexOptions.ExplicitCapture | RegexOptions.Multiline); 10 | 11 | public string Escape(string text) 12 | { 13 | Contract.Requires(text != null); 14 | 15 | return this.escapeRegExp.Replace(text, new System.Text.RegularExpressions.MatchEvaluator(this.MatchEvaluator)); 16 | } 17 | 18 | public string MatchEvaluator(Match m) 19 | { 20 | if (m.Groups["Common"] != null) 21 | { 22 | return string.Format(@"\{0}", m.Value); 23 | } 24 | return @"\n"; 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizSize.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Globalization; 5 | using System.Diagnostics; 6 | using System.Diagnostics.Contracts; 7 | 8 | namespace QuickGraph.Graphviz.Dot 9 | { 10 | [DebuggerDisplay("{Width}x{Height}")] 11 | public readonly struct GraphvizSizeF 12 | { 13 | readonly float height; 14 | readonly float width; 15 | 16 | public float Height 17 | { 18 | get { return this.height; } 19 | } 20 | public float Width 21 | { 22 | get { return this.width; } 23 | } 24 | 25 | public GraphvizSizeF(float width, float height) 26 | { 27 | Contract.Requires(width >= 0); 28 | Contract.Requires(height >= 0); 29 | 30 | this.width = width; 31 | this.height = height; 32 | } 33 | 34 | public bool IsEmpty 35 | { 36 | get { return this.width == 0 || this.height == 0; } 37 | } 38 | 39 | public override string ToString() 40 | { 41 | return string.Format(CultureInfo.InvariantCulture, "{0}x{1}", this.width, this.height); 42 | } 43 | } 44 | 45 | [DebuggerDisplay("{Width}x{Height}")] 46 | public struct GraphvizSize 47 | { 48 | readonly int height; 49 | readonly int width; 50 | 51 | public int Height 52 | { 53 | get { return this.height; } 54 | } 55 | public int Width 56 | { 57 | get { return this.width; } 58 | } 59 | 60 | public GraphvizSize(int width, int height) 61 | { 62 | Contract.Requires(width >= 0); 63 | Contract.Requires(height >= 0); 64 | 65 | this.width = width; 66 | this.height = height; 67 | } 68 | 69 | public bool IsEmpty 70 | { 71 | get { return this.width == 0 || this.height == 0; } 72 | } 73 | 74 | public override string ToString() 75 | { 76 | return string.Format(CultureInfo.InvariantCulture, "{0}x{1}", this.width, this.height); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizVertexShape.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizVertexShape 6 | { 7 | Unspecified, 8 | Box, 9 | Polygon, 10 | Ellipse, 11 | Circle, 12 | Point, 13 | Egg, 14 | Triangle, 15 | Plaintext, 16 | Diamond, 17 | Trapezium, 18 | Parallelogram, 19 | House, 20 | Pentagon, 21 | Hexagon, 22 | Septagon, 23 | Octagon, 24 | DoubleCircle, 25 | DoubleOctagon, 26 | TripleOctagon, 27 | InvTriangle, 28 | InvTrapezium, 29 | InvHouse, 30 | MDiamond, 31 | MSquare, 32 | MCircle, 33 | Rect, 34 | Rectangle, 35 | Record 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Dot/GraphvizVertexStyle.cs: -------------------------------------------------------------------------------- 1 | namespace QuickGraph.Graphviz.Dot 2 | { 3 | using System; 4 | 5 | public enum GraphvizVertexStyle 6 | { 7 | Unspecified, 8 | Filled, 9 | Diagonals, 10 | Rounded, 11 | Invis, 12 | Dashed, 13 | Dotted, 14 | Bold, 15 | Solid 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/EdgeMergeCondensatedGraphRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using QuickGraph.Algorithms.Condensation; 4 | 5 | namespace QuickGraph.Graphviz 6 | { 7 | public class EdgeMergeCondensatedGraphRenderer : 8 | GraphRendererBase> 9 | where TEdge : IEdge 10 | { 11 | public EdgeMergeCondensatedGraphRenderer( 12 | IVertexAndEdgeListGraph> visitedGraph) 13 | :base(visitedGraph) 14 | { } 15 | 16 | protected override void Initialize() 17 | { 18 | base.Initialize(); 19 | this.Graphviz.FormatVertex += new FormatVertexEventHandler(Graphviz_FormatVertex); 20 | this.Graphviz.FormatEdge += new FormatEdgeAction>(Graphviz_FormatEdge); 21 | } 22 | 23 | void Graphviz_FormatEdge(object sender, FormatEdgeEventArgs> e) 24 | { 25 | StringWriter sw = new StringWriter(); 26 | sw.WriteLine("{0}", e.Edge.Edges.Count); 27 | foreach (var edge in e.Edge.Edges) 28 | sw.WriteLine(" {0}", edge); 29 | e.EdgeFormatter.Label.Value = this.Graphviz.Escape(sw.ToString()); 30 | } 31 | 32 | void Graphviz_FormatVertex(Object sender, FormatVertexEventArgs e) 33 | { 34 | e.VertexFormatter.Label = e.Vertex.ToString(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/FormatEdgeEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Graphviz.Dot; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Graphviz 6 | { 7 | public sealed class FormatEdgeEventArgs 8 | : EdgeEventArgs 9 | where TEdge : IEdge 10 | { 11 | private readonly GraphvizEdge edgeFormatter; 12 | 13 | internal FormatEdgeEventArgs(TEdge e, GraphvizEdge edgeFormatter) 14 | : base(e) 15 | { 16 | #if CONTRACTS_BUG 17 | Contract.Requires(edgeFormatter != null); 18 | #endif 19 | this.edgeFormatter = edgeFormatter; 20 | } 21 | 22 | /// 23 | /// Edge formatter 24 | /// 25 | public GraphvizEdge EdgeFormatter 26 | { 27 | get 28 | { 29 | return edgeFormatter; 30 | } 31 | } 32 | } 33 | 34 | public delegate void FormatEdgeAction( 35 | object sender, 36 | FormatEdgeEventArgs e) 37 | where TEdge : IEdge; 38 | } 39 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/FormatVertexEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Graphviz.Dot; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace QuickGraph.Graphviz 6 | { 7 | public sealed class FormatVertexEventArgs 8 | : VertexEventArgs 9 | { 10 | private readonly GraphvizVertex vertexFormatter; 11 | 12 | internal FormatVertexEventArgs(TVertex v, GraphvizVertex vertexFormatter) 13 | : base(v) 14 | { 15 | #if CONTRACTS_BUG 16 | Contract.Requires(vertexFormatter != null); 17 | #endif 18 | this.vertexFormatter = vertexFormatter; 19 | } 20 | 21 | public GraphvizVertex VertexFormatter 22 | { 23 | get 24 | { 25 | return vertexFormatter; 26 | } 27 | } 28 | } 29 | 30 | public delegate void FormatVertexEventHandler( 31 | Object sender, 32 | FormatVertexEventArgs e); 33 | } 34 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/GraphRendererBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Graphviz.Dot; 3 | 4 | namespace QuickGraph.Graphviz 5 | { 6 | public abstract class GraphRendererBase 7 | where TEdge : IEdge 8 | { 9 | private GraphvizAlgorithm graphviz; 10 | 11 | public GraphRendererBase( 12 | IEdgeListGraph visitedGraph) 13 | { 14 | this.graphviz = new GraphvizAlgorithm(visitedGraph); 15 | this.Initialize(); 16 | } 17 | 18 | protected virtual void Initialize() 19 | { 20 | this.graphviz.CommonVertexFormat.Style = GraphvizVertexStyle.Filled; 21 | this.graphviz.CommonVertexFormat.FillColor = GraphvizColor.LightYellow; 22 | this.graphviz.CommonVertexFormat.Font = new GraphvizFont("Tahoma", 8.25F); 23 | this.graphviz.CommonVertexFormat.Shape = GraphvizVertexShape.Box; 24 | 25 | this.graphviz.CommonEdgeFormat.Font = new GraphvizFont("Tahoma", 8.25F); 26 | } 27 | 28 | public GraphvizAlgorithm Graphviz 29 | { 30 | get { return this.graphviz; } 31 | } 32 | 33 | public IEdgeListGraph VisitedGraph 34 | { 35 | get { return this.graphviz.VisitedGraph; } 36 | } 37 | 38 | public string Generate(IDotEngine dot, string fileName) 39 | { 40 | return this.graphviz.Generate(dot, fileName); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/GraphvizExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.IO; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Graphviz 8 | { 9 | /// 10 | /// Helper extensions to render graphs to graphviz 11 | /// 12 | public static class GraphvizExtensions 13 | { 14 | /// 15 | /// Renders a graph to the Graphviz DOT format. 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | public static string ToGraphviz( 22 | #if !NET20 23 | this 24 | #endif 25 | IEdgeListGraph graph 26 | ) 27 | where TEdge : IEdge 28 | { 29 | var algorithm = new GraphvizAlgorithm(graph); 30 | return algorithm.Generate(); 31 | } 32 | 33 | /// 34 | /// Renders a graph to the Graphviz DOT format. 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// delegate that initializes the algorithm 40 | /// 41 | public static string ToGraphviz( 42 | #if !NET20 43 | this 44 | #endif 45 | IEdgeListGraph graph, 46 | Action> initialization 47 | ) 48 | where TEdge : IEdge 49 | { 50 | var algorithm = new GraphvizAlgorithm(graph); 51 | initialization(algorithm); 52 | return algorithm.Generate(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/IDotEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using QuickGraph.Graphviz.Dot; 5 | using System.Diagnostics.Contracts; 6 | 7 | namespace QuickGraph.Graphviz 8 | { 9 | [ContractClass(typeof(IDotEngineContract))] 10 | public interface IDotEngine 11 | { 12 | string Run( 13 | GraphvizImageType imageType, 14 | string dot, 15 | string outputFileName); 16 | } 17 | 18 | [ContractClassFor(typeof(IDotEngine))] 19 | abstract class IDotEngineContract 20 | : IDotEngine 21 | { 22 | #region IDotEngine Members 23 | string IDotEngine.Run(GraphvizImageType imageType, string dot, string outputFileName) 24 | { 25 | Contract.Requires(!String.IsNullOrEmpty(dot)); 26 | Contract.Requires(!String.IsNullOrEmpty(outputFileName)); 27 | Contract.Ensures(!String.IsNullOrEmpty(Contract.Result())); 28 | 29 | return null; 30 | } 31 | #endregion 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Graphviz/Sandwych.QuickGraph.Graphviz.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard1.6;netstandard2.0;netstandard2.1;net45 5 | QuickGraph.Graphviz 6 | latest 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Serialization/GraphMLXmlResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Xml; 5 | using System.Diagnostics.Contracts; 6 | using System.Net; 7 | 8 | namespace QuickGraph.Serialization 9 | { 10 | /// 11 | /// A resolver that loads graphml DTD and XSD schemas 12 | /// from embedded resources. 13 | /// 14 | public sealed class GraphMLXmlResolver 15 | : XmlResolver 16 | { 17 | readonly XmlResolver baseResolver; 18 | 19 | public GraphMLXmlResolver() 20 | :this(new XmlUrlResolver()) 21 | { 22 | } 23 | public GraphMLXmlResolver(XmlResolver baseResolver) 24 | { 25 | Contract.Requires(baseResolver != null); 26 | 27 | this.baseResolver = baseResolver; 28 | } 29 | 30 | public const string GraphMLNamespace = "http://graphml.graphdrawing.org/xmlns"; 31 | 32 | ICredentials _credentials; 33 | public override ICredentials Credentials 34 | { 35 | set 36 | { 37 | this._credentials = value; 38 | } 39 | } 40 | 41 | public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) 42 | { 43 | if (absoluteUri.AbsoluteUri == "http://www.graphdrawing.org/dtds/graphml.dtd") 44 | return typeof(GraphMLExtensions).Assembly.GetManifestResourceStream(typeof(GraphMLExtensions), "graphml.dtd"); 45 | else if (absoluteUri.AbsoluteUri == "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd") 46 | return typeof(GraphMLExtensions).Assembly.GetManifestResourceStream(typeof(GraphMLExtensions), "graphml.xsd"); 47 | else if (absoluteUri.AbsoluteUri == "http://graphml.graphdrawing.org/xmlns/1.0/graphml-structure.xsd") 48 | return typeof(GraphExtensions).Assembly.GetManifestResourceStream(typeof(GraphMLExtensions), "graphml-structure.xsd"); 49 | 50 | return this.baseResolver.GetEntity(absoluteUri, role, ofObjectToReturn); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Serialization/Sandwych.QuickGraph.Serialization.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0;netstandard2.1;net45 5 | QuickGraph.Serialization 6 | latest 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/Sandwych.QuickGraph.Serialization/SerializerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml; 3 | 4 | namespace QuickGraph.Serialization 5 | { 6 | public abstract class SerializerBase 7 | where TEdge :IEdge 8 | { 9 | public bool EmitDocumentDeclaration {get;set;} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/AlgorithmExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Algorithms; 6 | using QuickGraph.Serialization; 7 | using Xunit; 8 | 9 | namespace QuickGraph.Tests.Algorithms 10 | { 11 | public class AlgorithmExtensionsTest 12 | { 13 | [Fact] 14 | public void AdjacencyGraphRoots() 15 | { 16 | var g = new AdjacencyGraph>(); 17 | g.AddVertex("A"); 18 | g.AddVertex("B"); 19 | g.AddVertex("C"); 20 | 21 | g.AddEdge(new Edge("A", "B")); 22 | g.AddEdge(new Edge("B", "C")); 23 | 24 | var roots = g.Roots().ToList(); 25 | Assert.Single(roots); 26 | Assert.Equal("A", roots[0]); 27 | } 28 | 29 | [Theory(Skip = "Bad unit test"), GraphData(Skip = "bad unit test")] 30 | public void AllAdjacencyGraphRoots(AdjacencyGraph> g) 31 | { 32 | Roots(g); 33 | } 34 | 35 | private void Roots(IVertexAndEdgeListGraph> g) 36 | { 37 | var roots = new HashSet(g.Roots()); 38 | foreach (var edge in g.Edges) 39 | Assert.Contains(edge.Target, roots); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/ConnectedComponents/ConnectedComponentsAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Serialization; 4 | using System.Diagnostics.Contracts; 5 | using System.Diagnostics; 6 | using QuickGraph.Algorithms.ConnectedComponents; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | 11 | namespace QuickGraph.Algorithms.ConnectedComponents 12 | { 13 | public class ConnectedComponentsAlgorithmTest 14 | { 15 | [Theory, GraphData(Type = GraphType.UndirectedGraph)] 16 | public void ConnectedComponentsAll(UndirectedGraph> g) 17 | { 18 | while (g.EdgeCount > 0) 19 | { 20 | this.Compute(g); 21 | g.RemoveEdge(Enumerable.First(g.Edges)); 22 | } 23 | } 24 | 25 | private void Compute(IUndirectedGraph g) 26 | where TEdge : IEdge 27 | { 28 | var dfs = new ConnectedComponentsAlgorithm(g); 29 | dfs.Compute(); 30 | if (g.VertexCount == 0) 31 | { 32 | Assert.Equal(0, dfs.ComponentCount); 33 | return; 34 | } 35 | 36 | Assert.True(0 < dfs.ComponentCount); 37 | Assert.True(dfs.ComponentCount <= g.VertexCount); 38 | foreach (var kv in dfs.Components) 39 | { 40 | Assert.True(0 <= kv.Value); 41 | Assert.True(kv.Value < dfs.ComponentCount); 42 | } 43 | 44 | foreach (var vertex in g.Vertices) 45 | foreach (var edge in g.AdjacentEdges(vertex)) 46 | { 47 | Assert.Equal(dfs.Components[edge.Source], dfs.Components[edge.Target]); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/ConnectedComponents/IncrementalConnectedComponentsAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Algorithms; 6 | using Xunit; 7 | 8 | namespace QuickGraph.Tests.Algorithms.ConnectedComponents 9 | { 10 | public class IncrementalConnectedComponentsAlgorithmTest 11 | { 12 | [Fact] 13 | public void IncrementalConnectedComponent() 14 | { 15 | var g = new AdjacencyGraph>(); 16 | g.AddVertexRange(new int[] { 0, 1, 2, 3 }); 17 | var components = AlgorithmExtensions.IncrementalConnectedComponents(g); 18 | 19 | var current = components(); 20 | Assert.Equal(4, current.Key); 21 | 22 | g.AddEdge(new SEquatableEdge(0, 1)); 23 | current = components(); 24 | Assert.Equal(3, current.Key); 25 | 26 | g.AddEdge(new SEquatableEdge(2, 3)); 27 | current = components(); 28 | Assert.Equal(2, current.Key); 29 | 30 | g.AddEdge(new SEquatableEdge(1, 3)); 31 | current = components(); 32 | Assert.Equal(1, current.Key); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/ConnectedComponents/WeaklyConnectedComponentsAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Serialization; 4 | using System.Diagnostics.Contracts; 5 | using System.Diagnostics; 6 | using QuickGraph.Algorithms.ConnectedComponents; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | 10 | namespace QuickGraph.Algorithms.ConnectedComponents 11 | { 12 | public class WeaklyConnectedComponentsAlgorithmTest 13 | { 14 | [Theory, GraphData] 15 | public void WeaklyConnectedComponentsAll(AdjacencyGraph> g) 16 | { 17 | this.Compute(g); 18 | } 19 | 20 | private void Compute(IVertexListGraph g) 21 | where TEdge : IEdge 22 | { 23 | var dfs = 24 | new WeaklyConnectedComponentsAlgorithm(g); 25 | dfs.Compute(); 26 | if (g.VertexCount == 0) 27 | { 28 | Assert.True(dfs.ComponentCount == 0); 29 | return; 30 | } 31 | 32 | Assert.True(0 < dfs.ComponentCount); 33 | Assert.True(dfs.ComponentCount <= g.VertexCount); 34 | foreach (var kv in dfs.Components) 35 | { 36 | Assert.True(0 <= kv.Value); 37 | Assert.True(kv.Value < dfs.ComponentCount); 38 | } 39 | 40 | foreach (var vertex in g.Vertices) 41 | foreach (var edge in g.OutEdges(vertex)) 42 | { 43 | Assert.Equal(dfs.Components[edge.Source], dfs.Components[edge.Target]); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/MaximumFlow/EdmondsKarpMaximumFlowAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using QuickGraph.Algorithms; 2 | using QuickGraph.Serialization; 3 | using System.Threading.Tasks; 4 | using Xunit; 5 | 6 | namespace QuickGraph.Tests.Algorithms.MaximumFlow 7 | { 8 | public class EdmondsKarpMaximumFlowAlgorithmTest 9 | { 10 | [Theory, GraphData] 11 | public void EdmondsKarpMaxFlowAll(AdjacencyGraph> g) 12 | { 13 | if (g.VertexCount > 0) 14 | this.EdmondsKarpMaxFlow(g, (source, target) => new Edge(source, target)); 15 | } 16 | 17 | 18 | private void EdmondsKarpMaxFlow(IMutableVertexAndEdgeListGraph g, 19 | EdgeFactory edgeFactory) 20 | where TEdge : IEdge 21 | { 22 | Assert.True(g.VertexCount > 0); 23 | 24 | foreach (var source in g.Vertices) 25 | foreach (var sink in g.Vertices) 26 | { 27 | if (source.Equals(sink)) continue; 28 | 29 | RunMaxFlowAlgorithm(g, edgeFactory, source, sink); 30 | } 31 | } 32 | 33 | private static double RunMaxFlowAlgorithm(IMutableVertexAndEdgeListGraph g, EdgeFactory edgeFactory, TVertex source, TVertex sink) where TEdge : IEdge 34 | { 35 | TryFunc flowPredecessors; 36 | var flow = AlgorithmExtensions.MaximumFlowEdmondsKarp( 37 | g, 38 | e => 1, 39 | source, sink, 40 | out flowPredecessors, 41 | edgeFactory 42 | ); 43 | 44 | return flow; 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/RandomWalks/EdgeChainTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using QuickGraph.Algorithms.Observers; 5 | using QuickGraph.Serialization; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | 9 | namespace QuickGraph.Algorithms.RandomWalks 10 | { 11 | public class EdgeChainTest 12 | { 13 | [Theory, GraphData] 14 | public void GenerateAll(AdjacencyGraph> g) 15 | { 16 | this.Generate(g); 17 | } 18 | 19 | private void Generate(IVertexListGraph g) 20 | where TEdge : IEdge 21 | { 22 | 23 | foreach (var v in g.Vertices) 24 | { 25 | var walker = new RandomWalkAlgorithm(g); 26 | var vis = new EdgeRecorderObserver(); 27 | using (vis.Attach(walker)) 28 | walker.Generate(v); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/RandomWalks/RandomWalkAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using QuickGraph.Algorithms.Observers; 4 | using QuickGraph.Serialization; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | 8 | namespace QuickGraph.Algorithms.RandomWalks 9 | { 10 | public class RandomWalkAlgorithmTest 11 | { 12 | [Theory, GraphData] 13 | public void RoundRobinAll(AdjacencyGraph> g) 14 | { 15 | this.RoundRobinTest(g); 16 | } 17 | 18 | private void RoundRobinTest(IVertexListGraph g) 19 | where TEdge : IEdge 20 | { 21 | if (g.VertexCount == 0) 22 | return; 23 | 24 | foreach (var root in g.Vertices) 25 | { 26 | var walker = 27 | new RandomWalkAlgorithm(g); 28 | walker.EdgeChain = new NormalizedMarkovEdgeChain(); 29 | walker.Generate(root); 30 | } 31 | } 32 | 33 | private void RoundRobinTestWithVisitor(IVertexListGraph g) 34 | where TEdge : IEdge 35 | { 36 | if (g.VertexCount == 0) 37 | return; 38 | 39 | foreach (var root in g.Vertices) 40 | { 41 | var walker = 42 | new RandomWalkAlgorithm(g); 43 | walker.EdgeChain = new NormalizedMarkovEdgeChain(); 44 | 45 | var vis = new EdgeRecorderObserver(); 46 | using (vis.Attach(walker)) 47 | walker.Generate(root); 48 | } 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/Search/BidirectionalDepthFirstSearchAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Serialization; 4 | using System.Threading.Tasks; 5 | using Xunit; 6 | 7 | namespace QuickGraph.Algorithms.Search 8 | { 9 | public class BidirectionalDepthFirstSearchAlgorithmTest 10 | { 11 | [Theory, GraphData(Type = GraphType.BidirectionalGraph)] 12 | public void ComputeAll(BidirectionalGraph> g) 13 | { 14 | this.Compute(g); 15 | } 16 | 17 | private void Compute(IBidirectionalGraph g) 18 | where TEdge : IEdge 19 | { 20 | var dfs = new BidirectionalDepthFirstSearchAlgorithm(g); 21 | dfs.Compute(); 22 | 23 | // let's make sure 24 | foreach (var v in g.Vertices) 25 | { 26 | Assert.True(dfs.VertexColors.ContainsKey(v)); 27 | Assert.Equal(GraphColor.Black, dfs.VertexColors[v]); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/ShortestPath/BellmanFordShortestPathTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Algorithms; 6 | using QuickGraph.Serialization; 7 | using Xunit; 8 | 9 | namespace QuickGraph.Tests.Algorithms.ShortestPath 10 | { 11 | public class BellmanFordShortestPathTest 12 | { 13 | [Theory, GraphData] 14 | public void AllSamples(AdjacencyGraph> g) 15 | { 16 | if (g.IsVerticesEmpty) 17 | return; 18 | 19 | var testPath = g.ShortestPathsBellmanFord(e => e.Source.Length - e.Target.Length, g.Vertices.First()); 20 | foreach (var i in g.Vertices) 21 | { 22 | IEnumerable> es; 23 | if (testPath(i, out es)) 24 | TestConsole.WriteLine("{0}: {1}", i, es.Count()); 25 | } 26 | } 27 | 28 | [Fact] 29 | public void Sample() 30 | { 31 | var testGraph = new AdjacencyGraph>(); 32 | testGraph.AddVerticesAndEdge(new Edge(1, 2)); 33 | testGraph.AddVerticesAndEdge(new Edge(1, 3)); 34 | testGraph.AddVerticesAndEdge(new Edge(3, 4)); 35 | testGraph.AddVerticesAndEdge(new Edge(1, 4)); 36 | var testPath = testGraph.ShortestPathsBellmanFord(e => e.Source - e.Target, 1); 37 | foreach (var i in testGraph.Vertices) 38 | { 39 | IEnumerable> es; 40 | if (testPath(i, out es)) 41 | TestConsole.WriteLine("{0}: {1}", i, es.Count()); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/SourceFirstTopologicalSortAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using QuickGraph.Serialization; 3 | using QuickGraph.Algorithms.TopologicalSort; 4 | using Xunit; 5 | 6 | namespace QuickGraph.Algorithms 7 | { 8 | public class SourceFirstTopologicalSortAlgorithmTest 9 | { 10 | [Theory, GraphData] 11 | public void SortAll(AdjacencyGraph> g) 12 | { 13 | this.Sort(g); 14 | } 15 | 16 | private void Sort(IVertexAndEdgeListGraph g) 17 | where TEdge : IEdge 18 | { 19 | var topo = new SourceFirstTopologicalSortAlgorithm(g); 20 | try 21 | { 22 | topo.Compute(); 23 | } 24 | catch (NonAcyclicGraphException) 25 | { } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/UndirectedFirstTopologicalSortAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Serialization; 4 | using QuickGraph.Algorithms.TopologicalSort; 5 | using Xunit; 6 | 7 | namespace QuickGraph.Algorithms 8 | { 9 | public class UndirectedFirstTopologicalSortAlgorithmTest 10 | { 11 | [Theory, GraphData(Type = GraphType.UndirectedGraph)] 12 | public void UndirectedFirstTopologicalSortAll(UndirectedGraph> g) 13 | { 14 | this.Compute(g); 15 | } 16 | 17 | private void Compute(IUndirectedGraph g) 18 | where TEdge : IEdge 19 | { 20 | var topo = 21 | new UndirectedFirstTopologicalSortAlgorithm(g); 22 | topo.AllowCyclicGraph = true; 23 | topo.Compute(); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Algorithms/UndirectedTopologicalSortAlgorithmTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using QuickGraph.Serialization; 4 | using QuickGraph.Algorithms.TopologicalSort; 5 | 6 | namespace QuickGraph.Algorithms 7 | { 8 | public partial class UndirectedTopologicalSortAlgorithmTest 9 | { 10 | private void Compute(IUndirectedGraph> g) 11 | { 12 | UndirectedTopologicalSortAlgorithm> topo = 13 | new UndirectedTopologicalSortAlgorithm>(g); 14 | topo.AllowCyclicGraph = true; 15 | topo.Compute(); 16 | 17 | Display(topo); 18 | } 19 | 20 | private void Display(UndirectedTopologicalSortAlgorithm> topo) 21 | { 22 | int index = 0; 23 | foreach (string v in topo.SortedVertices) 24 | TestConsole.WriteLine("{0}: {1}", index++, v); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Collections/ForestDisjointSetTTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Collections/ForestDisjointSetTTest.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Collections/SoftHeapTTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright © MSIT 2008 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Xunit; 6 | using Xunit.Extensions; 7 | 8 | namespace QuickGraph.Collections 9 | { 10 | /// This class contains parameterized unit tests for SoftHeap`2 11 | public class SoftHeapTKeyTValueTest 12 | { 13 | 14 | public static IEnumerable KeysData => new List { 15 | new object[] { new int[] { 1, 2, 3 } }, 16 | new object[] { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 } }, 17 | }; 18 | 19 | //TODO FIXME 20 | //[Theory] 21 | //[MemberData(nameof(KeysData))] 22 | public void Add(IEnumerable keys) 23 | { 24 | Assert.True(keys.All(k => k < int.MaxValue)); 25 | Assert.True(keys.Count() > 0); 26 | 27 | var target = new SoftHeap(1 / 4.0, int.MaxValue); 28 | TestConsole.WriteLine("expected error rate: {0}", target.ErrorRate); 29 | foreach (var key in keys) 30 | { 31 | var count = target.Count; 32 | target.Add(key, key + 1); 33 | Assert.Equal(count + 1, target.Count); 34 | } 35 | 36 | int lastMin = int.MaxValue; 37 | int error = 0; 38 | while (target.Count > 0) 39 | { 40 | var kv = target.DeleteMin(); 41 | if (lastMin < kv.Key) 42 | error++; 43 | lastMin = kv.Key; 44 | Assert.Equal(kv.Key + 1, kv.Value); 45 | } 46 | 47 | TestConsole.WriteLine("error rate: {0}", error / (double)keys.Count()); 48 | Assert.True(error / (double)keys.Count() <= target.ErrorRate); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/DataStructureTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace QuickGraph.Tests 8 | { 9 | public class DataStructureTest 10 | { 11 | [Fact] 12 | public void DisplayLinkedList() 13 | { 14 | var target = new LinkedList(); 15 | target.AddFirst(0); 16 | target.AddFirst(1); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/EdgeExtensionsTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/EdgeExtensionsTest.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/EdgeListGraphInvariant.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | 4 | namespace QuickGraph 5 | { 6 | public static class EdgeListGraphTest 7 | { 8 | public static void Iteration(IEdgeListGraph g) 9 | where E : IEdge 10 | { 11 | int n = g.EdgeCount; 12 | int i = 0; 13 | foreach (E e in g.Edges) 14 | ++i; 15 | } 16 | 17 | public static void Count(IEdgeListGraph g) 18 | where E : IEdge 19 | { 20 | int n = g.EdgeCount; 21 | if (n == 0) 22 | Assert.True(g.IsEdgesEmpty); 23 | 24 | int i = 0; 25 | foreach (E e in g.Edges) 26 | { 27 | e.ToString(); 28 | ++i; 29 | } 30 | Assert.Equal(n, i); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/EdgeTVertexTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/EdgeTVertexTest.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/AdjacencyGraphFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Factories/AdjacencyGraphFactory.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/ArrayAdjacencyGraphFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Factories/ArrayAdjacencyGraphFactory.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/EdgeFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Factories/EdgeFactory.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/FibonacciHeapFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Factories/FibonacciHeapFactory.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/ForestDisjointSetFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Factories/ForestDisjointSetFactory.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/StringVertexFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickGraph.Tests.Factories 6 | { 7 | public sealed class StringVertexFactory 8 | { 9 | private int id = 0; 10 | 11 | public StringVertexFactory() 12 | : this("Super") 13 | { } 14 | 15 | public StringVertexFactory(string prefix) 16 | { 17 | this.Prefix = prefix; 18 | } 19 | 20 | public string Prefix { get; set; } 21 | 22 | public string CreateVertex() 23 | { 24 | return this.Prefix + (++id).ToString(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Factories/UndirectedGraphFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/Factories/UndirectedGraphFactory.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/GraphConsoleSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickGraph 4 | { 5 | public static class GraphConsoleSerializer 6 | { 7 | public static void DisplayGraph(IEdgeListGraph g) 8 | where Edge : IEdge 9 | { 10 | TestConsole.WriteLine("{0} vertices, {1} edges", g.VertexCount, g.EdgeCount); 11 | foreach(var v in g.Vertices) 12 | TestConsole.WriteLine("\t{0}", v); 13 | foreach (var edge in g.Edges) 14 | TestConsole.WriteLine("\t{0}", edge); 15 | } 16 | 17 | public static void DisplayGraph(IVertexListGraph g) 18 | where TEdge : IEdge 19 | { 20 | TestConsole.WriteLine("{0} vertices", g.VertexCount); 21 | foreach(var v in g.Vertices) 22 | foreach (var edge in g.OutEdges(v)) 23 | TestConsole.WriteLine("\t{0}", edge); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/GraphDataAttribute.cs: -------------------------------------------------------------------------------- 1 | using QuickGraph.Serialization; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.IO; 7 | using Xunit.Sdk; 8 | 9 | namespace QuickGraph 10 | { 11 | public enum GraphType 12 | { 13 | AdjacencyGraph, 14 | BidirectionalGraph, 15 | UndirectedGraph 16 | } 17 | 18 | public sealed class GraphDataAttribute : DataAttribute 19 | { 20 | public GraphType Type { get; set; } = GraphType.AdjacencyGraph; 21 | public string FileName { get; set; } = null; 22 | 23 | public override IEnumerable GetData(MethodInfo testMethod) 24 | { 25 | if (string.IsNullOrEmpty(FileName)) 26 | { 27 | foreach (var graphmlFile in TestGraphFactory.GetFileNames()) 28 | { 29 | var g = this.LoadSingleGraph(graphmlFile); 30 | yield return new object[] { g }; 31 | } 32 | } 33 | else 34 | { 35 | var path = Path.Combine("graphml", this.FileName); 36 | yield return new object[] { this.LoadSingleGraph(path) }; 37 | } 38 | } 39 | 40 | private object LoadSingleGraph(string path) 41 | { 42 | switch (this.Type) 43 | { 44 | case GraphType.AdjacencyGraph: return TestGraphFactory.LoadGraph(path); 45 | case GraphType.BidirectionalGraph: return TestGraphFactory.LoadBidirectionalGraph(path); 46 | case GraphType.UndirectedGraph: return TestGraphFactory.LoadUndirectedGraph(path); 47 | default: throw new NotSupportedException(); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Regression/ShortestPathBellmanFordTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Algorithms; 6 | using Xunit; 7 | 8 | namespace QuickGraph.Tests.Regression 9 | { 10 | public class ShortestPathBellmanFordTest 11 | { 12 | [Fact] 13 | public void Repro12901() 14 | { 15 | var graph = new BidirectionalGraph>(); 16 | int vertex = 1; 17 | graph.AddVerticesAndEdge(new Edge(vertex, vertex)); 18 | var pathFinder = AlgorithmExtensions.ShortestPathsBellmanFord>(graph, edge => -1.0, vertex); 19 | IEnumerable> path; 20 | pathFinder(vertex, out path); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Sandwych.QuickGraph.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | false 6 | false 7 | QuickGraph 8 | latest 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Serialization/DirectedGraphMLExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using QuickGraph.Serialization; 6 | using QuickGraph.Serialization.DirectedGraphML; 7 | using System.Xml; 8 | using QuickGraph.Algorithms; 9 | using System.Diagnostics; 10 | using Xunit; 11 | 12 | namespace QuickGraph.Tests.Serialization 13 | { 14 | public class DirectedGraphMLExtensionsTest 15 | { 16 | [Fact] 17 | public void SimpleGraph() 18 | { 19 | int[][] edges = { new int[]{ 1, 2, 3 }, 20 | new int[]{ 2, 3, 1 } }; 21 | edges.ToAdjacencyGraph() 22 | .ToDirectedGraphML() 23 | .WriteXml("simple.dgml"); 24 | 25 | if (Debugger.IsAttached) 26 | { 27 | Process.Start("simple.dgml"); 28 | } 29 | 30 | edges.ToAdjacencyGraph() 31 | .ToDirectedGraphML() 32 | .WriteXml(Console.Out); 33 | } 34 | 35 | [Theory, GraphData] 36 | public void ToDirectedGraphML(AdjacencyGraph> g) 37 | { 38 | var dg = g.ToDirectedGraphML(); 39 | Assert.NotNull(g); 40 | Assert.Equal(dg.Nodes.Length, g.VertexCount); 41 | Assert.Equal(dg.Links.Length, g.EdgeCount); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/Serialization/XmlSerializationTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.XPath; 6 | using System.Xml; 7 | using System.IO; 8 | using QuickGraph.Serialization; 9 | using Xunit; 10 | 11 | namespace QuickGraph.Tests.Serialization 12 | { 13 | public class XmlSerializationTest 14 | { 15 | [Fact] 16 | public void DeserializeFromXml() 17 | { 18 | var doc = new XPathDocument(Path.Combine("graphml", "repro12273.xml")); 19 | var ug = SerializationExtensions.DeserializeFromXml(doc, 20 | "graph", "node", "edge", 21 | nav => new UndirectedGraph>(), 22 | nav => nav.GetAttribute("id", ""), 23 | nav => new TaggedEdge( 24 | nav.GetAttribute("source", ""), 25 | nav.GetAttribute("target", ""), 26 | int.Parse(nav.GetAttribute("weight", "")) 27 | ) 28 | ); 29 | 30 | var ug2 = SerializationExtensions.DeserializeFromXml( 31 | XmlReader.Create(Path.Combine("graphml", "repro12273.xml")), 32 | "graph", "node", "edge", "", 33 | reader => new UndirectedGraph>(), 34 | reader => reader.GetAttribute("id"), 35 | reader => new TaggedEdge( 36 | reader.GetAttribute("source"), 37 | reader.GetAttribute("target"), 38 | int.Parse(reader.GetAttribute("weight")) 39 | ) 40 | ); 41 | 42 | Assert.Equal(ug.VertexCount, ug2.VertexCount); 43 | Assert.Equal(ug.EdgeCount, ug2.EdgeCount); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/TaggedEdgeTVertexTTagTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldrev/Sandwych.QuickGraph/46fc1f64f09f9906e48729469c5dc22596066b01/test/Sandwych.QuickGraph.Tests/TaggedEdgeTVertexTTagTest.cs -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/TestCategories.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace QuickGraph 7 | { 8 | public static class TestCategories 9 | { 10 | public const string LongRunning = "LongRunning"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/TestConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace QuickGraph 7 | { 8 | public static class TestConsole 9 | { 10 | public static bool Logging { get; set; } 11 | public static void WriteLine() 12 | { 13 | if (Logging) 14 | Console.WriteLine(); 15 | } 16 | public static void WriteLine(object o) 17 | { 18 | if (Logging) 19 | Console.WriteLine(o); 20 | } 21 | public static void WriteLine(string text) 22 | { 23 | if (Logging) 24 | Console.WriteLine(text); 25 | } 26 | public static void WriteLine(string text, object arg) 27 | { 28 | if (Logging) 29 | Console.WriteLine(text, arg); 30 | } 31 | public static void WriteLine(string text, object arg1, object arg2) 32 | { 33 | if (Logging) 34 | Console.WriteLine(text, arg1, arg2); 35 | } 36 | public static void WriteLine(string text, params object[] args) 37 | { 38 | if (Logging) 39 | Console.WriteLine(text, args); 40 | } 41 | public static void Write(object o) 42 | { 43 | if (Logging) 44 | Console.Write(o); 45 | } 46 | public static void Write(string text) 47 | { 48 | if (Logging) 49 | Console.Write(text); 50 | } 51 | public static void Write(string text, object arg) 52 | { 53 | if (Logging) 54 | Console.Write(text, arg); 55 | } 56 | public static void Write(string text, params object[] args) 57 | { 58 | if (Logging) 59 | Console.Write(text, args); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/TestHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace QuickGraph.Tests 7 | { 8 | /// 9 | /// A collection of utility methods for unit tests to use 10 | /// 11 | public static class TestHelper 12 | { 13 | /// 14 | /// Create the set of all Edges {(left, right)} 15 | /// such that every element in leftVertices is matched with every element in rightVertices 16 | /// This is especially useful for creating bipartite graphs 17 | /// 18 | /// A collection of vertices 19 | /// A collection of vertices 20 | /// An object to use for creating edges 21 | /// 22 | public static List> CreateAllPairwiseEdges( 23 | IEnumerable leftVertices, IEnumerable rightVertices, 24 | EdgeFactory> edgeFactory) 25 | { 26 | var edges = new List>(); 27 | 28 | foreach (var left in leftVertices) 29 | { 30 | foreach (var right in rightVertices) 31 | { 32 | edges.Add(edgeFactory(left, right)); 33 | } 34 | } 35 | 36 | return edges; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/UndirectedGraphInvariant.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Xunit; 4 | 5 | namespace QuickGraph 6 | { 7 | public partial class UndirectedGraphTest 8 | { 9 | public static void IsAdjacentEdgesEmpty(IUndirectedGraph g) 10 | where E : IEdge 11 | { 12 | foreach (T v in g.Vertices) 13 | { 14 | Assert.Equal( 15 | g.IsAdjacentEdgesEmpty(v), 16 | g.AdjacentDegree(v) == 0); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/Sandwych.QuickGraph.Tests/graphml/repro12273.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | --------------------------------------------------------------------------------