diff --git a/src/SparseTransform.Tests/Library/ColorerTests.cs b/src/SparseTransform.Tests/Library/ColorerTests.cs index fd253a64e4baa188a0fad71a43a96858ada4474a..9cbcd510e5058b1bf1737104ab414f8b2d37d125 100644 --- a/src/SparseTransform.Tests/Library/ColorerTests.cs +++ b/src/SparseTransform.Tests/Library/ColorerTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; using System.Linq; namespace SparseTransform.Tests.Library; diff --git a/src/SparseTransform.Tests/Library/DataStructures/AdjacencyGraphTests.cs b/src/SparseTransform.Tests/Library/DataStructures/AdjacencyGraphTests.cs index 10593559b2eb4296e0445c2450649ac8790c33ca..7d2c290a354ec874d797fd5ae0e9e12b1f257ab7 100644 --- a/src/SparseTransform.Tests/Library/DataStructures/AdjacencyGraphTests.cs +++ b/src/SparseTransform.Tests/Library/DataStructures/AdjacencyGraphTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; using System.Linq; namespace SparseTransform.Tests.Library.DataStructures; diff --git a/src/SparseTransform.Tests/Library/DataStructures/BipartiteGraphTests.cs b/src/SparseTransform.Tests/Library/DataStructures/BipartiteGraphTests.cs index 4b9ddbeb425455076416fb325f1b972666344156..d8200ec5ba4416798da0e91e8e0beca21bd7e677 100644 --- a/src/SparseTransform.Tests/Library/DataStructures/BipartiteGraphTests.cs +++ b/src/SparseTransform.Tests/Library/DataStructures/BipartiteGraphTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; namespace SparseTransform.Tests.Library.DataStructures; diff --git a/src/SparseTransform.Tests/Library/DataStructures/DoubleMatrixTests.cs b/src/SparseTransform.Tests/Library/DataStructures/DoubleMatrixTests.cs index f7b2be44b20d4ddbd8e2ed55701eaa2d9955f54c..e665bdf34b1aa1010b0ab05feca4b2bfc3ffa739 100644 --- a/src/SparseTransform.Tests/Library/DataStructures/DoubleMatrixTests.cs +++ b/src/SparseTransform.Tests/Library/DataStructures/DoubleMatrixTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; using System.IO; namespace SparseTransform.Tests.Library.DataStructures; diff --git a/src/SparseTransform.Tests/Library/DataStructures/GraphNodeTests.cs b/src/SparseTransform.Tests/Library/DataStructures/GraphNodeTests.cs index d5062347d9887bb1f1a32e1070c3d6b1b205a88e..f3fa58200860b54d85bcd5792b1d36db69910863 100644 --- a/src/SparseTransform.Tests/Library/DataStructures/GraphNodeTests.cs +++ b/src/SparseTransform.Tests/Library/DataStructures/GraphNodeTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; using System; namespace SparseTransform.Tests.Library.DataStructures; diff --git a/src/SparseTransform.Tests/Library/DataStructures/IntegerMatrixTests.cs b/src/SparseTransform.Tests/Library/DataStructures/IntegerMatrixTests.cs index 38882cf7e66f8e22050acd84075087ffe3cb5191..db2eb945685c8e2e7d1a089282963e313a97d815 100644 --- a/src/SparseTransform.Tests/Library/DataStructures/IntegerMatrixTests.cs +++ b/src/SparseTransform.Tests/Library/DataStructures/IntegerMatrixTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; using System.IO; namespace SparseTransform.Tests.Library.DataStructures; diff --git a/src/SparseTransform.Tests/Library/DataStructures/MatrixTests.cs b/src/SparseTransform.Tests/Library/DataStructures/MatrixTests.cs index 8628e8c45b5e75765f382b5669656a96bbdcc642..0ea7509937ee12f69e47bf4f46fd5f9d9065c692 100644 --- a/src/SparseTransform.Tests/Library/DataStructures/MatrixTests.cs +++ b/src/SparseTransform.Tests/Library/DataStructures/MatrixTests.cs @@ -1,5 +1,5 @@ using NUnit.Framework; -using DataStructures; +using SparseTransform.DataStructures; using System; namespace SparseTransform.Tests.Library.DataStructures; diff --git a/src/SparseTransform/Colorer.cs b/src/SparseTransform/Colorer.cs index e738447d28d65d985ae0d8e6154b5c22b57e46cd..68970652de4db0e2b65b629eedce730c6482601a 100644 --- a/src/SparseTransform/Colorer.cs +++ b/src/SparseTransform/Colorer.cs @@ -1,112 +1,115 @@ -using DataStructures; +using SparseTransform.DataStructures; -/// <summary> -/// Colorer class. Contains implementation for all available coloring algorithms. -/// All algorithms are in-place. -/// </summary> -public class Colorer +namespace SparseTransform { /// <summary> - /// Colors the passed bipartite graph in-place using partial distance-2 coloring. + /// Colorer class. Contains implementation for all available coloring algorithms. + /// All algorithms are in-place. /// </summary> - /// <param name="graph">Graph to color</param> - /// <returns><c>true</c> if coloring was successfull</returns> - public bool PartialD2Color(BipartiteGraph graph) + public class Colorer { - // Exact length defined in paper - int[] forbiddenColors = new int[Math.Min(graph.MaxDegreeRight * (graph.MaxDegreeLeft - 1) + 1, graph.GetRightNodeCount())]; - // Make sure the default values are neither (1) potential colors (2) the uncolored value (=0) - Array.Fill(forbiddenColors, -1); - foreach (GraphNode v_i in graph.GetRightNodes()) + /// <summary> + /// Colors the passed bipartite graph in-place using partial distance-2 coloring. + /// </summary> + /// <param name="graph">Graph to color</param> + /// <returns><c>true</c> if coloring was successfull</returns> + public bool PartialD2Color(BipartiteGraph graph) { - foreach (GraphNode w in v_i.Neighbors) + // Exact length defined in paper + int[] forbiddenColors = new int[Math.Min(graph.MaxDegreeRight * (graph.MaxDegreeLeft - 1) + 1, graph.GetRightNodeCount())]; + // Make sure the default values are neither (1) potential colors (2) the uncolored value (=0) + Array.Fill(forbiddenColors, -1); + foreach (GraphNode v_i in graph.GetRightNodes()) { - foreach (GraphNode x in w.Neighbors) + foreach (GraphNode w in v_i.Neighbors) { - if (x.Colored) + foreach (GraphNode x in w.Neighbors) { - forbiddenColors[x.Color - 1] = v_i.Index; + if (x.Colored) + { + forbiddenColors[x.Color - 1] = v_i.Index; + } } } - } - int c = 1; - while (c > 0) - { - if (forbiddenColors[c - 1] != v_i.Index) - { - v_i.Color = c; - c = 0; - } - else + int c = 1; + while (c > 0) { - c++; + if (forbiddenColors[c - 1] != v_i.Index) + { + v_i.Color = c; + c = 0; + } + else + { + c++; + } } } + // Set right since we performed column partitioning + graph.RightColored = true; + return true; } - // Set right since we performed column partitioning - graph.RightColored = true; - return true; - } - /// <summary> - /// Colors the passed adjacency graph in-place using the first star coloring alg from https://doi.org/10.1137/S0036144504444711 - /// </summary> - /// <param name="graph">Graph to color</param> - /// <returns><c>true</c> if coloring was successfull</returns> - public bool StarColor1(AdjacencyGraph graph) - { - // Exact length defined in paper - int[] forbiddenColors = new int[Math.Min(graph.MaxDegree * graph.MaxDegree + 1, graph.GetNodeCount())]; - // Make sure the default values are neither (1) potential colors (2) the uncolored value (=0) - Array.Fill(forbiddenColors, -1); - foreach (GraphNode v_i in graph.GetNodes()) + /// <summary> + /// Colors the passed adjacency graph in-place using the first star coloring alg from https://doi.org/10.1137/S0036144504444711 + /// </summary> + /// <param name="graph">Graph to color</param> + /// <returns><c>true</c> if coloring was successfull</returns> + public bool StarColor1(AdjacencyGraph graph) { - foreach (GraphNode w in v_i.Neighbors) + // Exact length defined in paper + int[] forbiddenColors = new int[Math.Min(graph.MaxDegree * graph.MaxDegree + 1, graph.GetNodeCount())]; + // Make sure the default values are neither (1) potential colors (2) the uncolored value (=0) + Array.Fill(forbiddenColors, -1); + foreach (GraphNode v_i in graph.GetNodes()) { - if (w.Colored) - { - forbiddenColors[w.Color - 1] = v_i.Index; - } - foreach (GraphNode x in w.Neighbors) + foreach (GraphNode w in v_i.Neighbors) { - if (x.Colored) + if (w.Colored) { - if (!w.Colored) - { - forbiddenColors[x.Color - 1] = v_i.Index; - } - else + forbiddenColors[w.Color - 1] = v_i.Index; + } + foreach (GraphNode x in w.Neighbors) + { + if (x.Colored) { - foreach (GraphNode y in x.Neighbors) + if (!w.Colored) + { + forbiddenColors[x.Color - 1] = v_i.Index; + } + else { - if (y.Colored && y != w) + foreach (GraphNode y in x.Neighbors) { - if (y.Color == w.Color) + if (y.Colored && y != w) { - forbiddenColors[x.Color - 1] = v_i.Index; - break; + if (y.Color == w.Color) + { + forbiddenColors[x.Color - 1] = v_i.Index; + break; + } } } } } } } - } - int c = 1; - while (c > 0) - { - if (forbiddenColors[c - 1] != v_i.Index) - { - v_i.Color = c; - c = 0; - } - else + int c = 1; + while (c > 0) { - c++; + if (forbiddenColors[c - 1] != v_i.Index) + { + v_i.Color = c; + c = 0; + } + else + { + c++; + } } } + graph.Colored = true; + return true; } - graph.Colored = true; - return true; } } \ No newline at end of file diff --git a/src/SparseTransform/ConversionManager.cs b/src/SparseTransform/ConversionManager.cs index d1e91081f390a76a30812e24b101c8e1e789c5f2..4084f6e5b5b8e082a723b3e59a4a484820d161c9 100644 --- a/src/SparseTransform/ConversionManager.cs +++ b/src/SparseTransform/ConversionManager.cs @@ -1,4 +1,4 @@ -using DataStructures; +using SparseTransform.DataStructures; using SparseTransform.Convert; namespace SparseTransform diff --git a/src/SparseTransform/Convert/ColoredDotWriter.cs b/src/SparseTransform/Convert/ColoredDotWriter.cs index 49cba0b537c92daec4c494f3a2b65d72ce3a44ef..f38313cc04f98e1fe0691f66a0ef81d5244e16b1 100644 --- a/src/SparseTransform/Convert/ColoredDotWriter.cs +++ b/src/SparseTransform/Convert/ColoredDotWriter.cs @@ -1,4 +1,4 @@ -using DataStructures; +using SparseTransform.DataStructures; namespace SparseTransform.Convert { diff --git a/src/SparseTransform/Convert/DotWriter.cs b/src/SparseTransform/Convert/DotWriter.cs index 50703b1c0e333fef1c9b9f44e69605398f127b3e..f51db7876e092c8fe8575226fd672e1ccdf1a285 100644 --- a/src/SparseTransform/Convert/DotWriter.cs +++ b/src/SparseTransform/Convert/DotWriter.cs @@ -1,5 +1,5 @@ using System.Text; -using DataStructures; +using SparseTransform.DataStructures; namespace SparseTransform.Convert { diff --git a/src/SparseTransform/Convert/IReader.cs b/src/SparseTransform/Convert/IReader.cs index 4728926f3a25ac00718018ddfecea8c44ba25083..c8c061996782e11530279ca2b13620c091202456 100644 --- a/src/SparseTransform/Convert/IReader.cs +++ b/src/SparseTransform/Convert/IReader.cs @@ -1,4 +1,4 @@ -using DataStructures; +using SparseTransform.DataStructures; namespace SparseTransform.Convert { diff --git a/src/SparseTransform/Convert/IWriter.cs b/src/SparseTransform/Convert/IWriter.cs index 29daa63a94acc7a0d44b607448bd46315e7a4439..fdd962467f732fa7420c234261ff62c08d70ee4b 100644 --- a/src/SparseTransform/Convert/IWriter.cs +++ b/src/SparseTransform/Convert/IWriter.cs @@ -1,4 +1,4 @@ -using DataStructures; +using SparseTransform.DataStructures; namespace SparseTransform.Convert { diff --git a/src/SparseTransform/Convert/MatrixMarketReader.cs b/src/SparseTransform/Convert/MatrixMarketReader.cs index 3bc499b03807993137022d6c7fcc21dae7ad0031..051c5efc3525d94882faf3ace4cb3074485a39e0 100644 --- a/src/SparseTransform/Convert/MatrixMarketReader.cs +++ b/src/SparseTransform/Convert/MatrixMarketReader.cs @@ -1,5 +1,5 @@ using Antlr4.Runtime; -using DataStructures; +using SparseTransform.DataStructures; using Transform.Convert; namespace SparseTransform.Convert diff --git a/src/SparseTransform/Convert/MatrixMarketWriter.cs b/src/SparseTransform/Convert/MatrixMarketWriter.cs index 06bbc5f5c418518e515cc059d2adeac18b54ca75..3ba74151d8331d6715bb8bb5536bf7f93850ea7f 100644 --- a/src/SparseTransform/Convert/MatrixMarketWriter.cs +++ b/src/SparseTransform/Convert/MatrixMarketWriter.cs @@ -1,4 +1,4 @@ -using DataStructures; +using SparseTransform.DataStructures; namespace SparseTransform.Convert { diff --git a/src/SparseTransform/DataStructures/AdjacencyGraph.cs b/src/SparseTransform/DataStructures/AdjacencyGraph.cs index f1d593e161034031d932b06a5aa4362fd2771761..75e31d00a441e1ac5981e119b2d0f01b651e747a 100644 --- a/src/SparseTransform/DataStructures/AdjacencyGraph.cs +++ b/src/SparseTransform/DataStructures/AdjacencyGraph.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { /// <summary> /// Represents symmetric matrices as a graph. diff --git a/src/SparseTransform/DataStructures/BipartiteGraph.cs b/src/SparseTransform/DataStructures/BipartiteGraph.cs index b4fb77b6170c7339e7a9cbcff3dd93d3f56a8634..214907dfde4da15dc5ad59c8c7683ccfe734e8c1 100644 --- a/src/SparseTransform/DataStructures/BipartiteGraph.cs +++ b/src/SparseTransform/DataStructures/BipartiteGraph.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { /// <summary> /// General class for representing sparse matrices as graphs. diff --git a/src/SparseTransform/DataStructures/DoubleMatrix.cs b/src/SparseTransform/DataStructures/DoubleMatrix.cs index 2b61de0444a0925658e99066ce58e2ff18c965b5..e103acfbc00e0142468a54fb1ea82745b48309c6 100644 --- a/src/SparseTransform/DataStructures/DoubleMatrix.cs +++ b/src/SparseTransform/DataStructures/DoubleMatrix.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { /// <summary> /// Matrix type that can only store Doubles. diff --git a/src/SparseTransform/DataStructures/GraphNode.cs b/src/SparseTransform/DataStructures/GraphNode.cs index ca03a0b394eef800892f46f55a7af8dc0909c72e..55adc2f03ae1b2aa685ddb73c66f2de4aeccf8aa 100644 --- a/src/SparseTransform/DataStructures/GraphNode.cs +++ b/src/SparseTransform/DataStructures/GraphNode.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { public class GraphNode { diff --git a/src/SparseTransform/DataStructures/IGraph.cs b/src/SparseTransform/DataStructures/IGraph.cs index 4734b03e38247695b1c028a8e494440cbfc4838e..e821e1b50101099a2cbd946810ea92ea00744bdf 100644 --- a/src/SparseTransform/DataStructures/IGraph.cs +++ b/src/SparseTransform/DataStructures/IGraph.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { /// <summary> /// Base interface to be implemented by all graphs. diff --git a/src/SparseTransform/DataStructures/IntegerMatrix.cs b/src/SparseTransform/DataStructures/IntegerMatrix.cs index 4f1b275e987f9f41c563a937cc108ef74fcd4a8f..7d8fd10c7089fafad01fe9e5f9f0ee7816f8bb75 100644 --- a/src/SparseTransform/DataStructures/IntegerMatrix.cs +++ b/src/SparseTransform/DataStructures/IntegerMatrix.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { /// <summary> /// Matrix type that can only store Integers. diff --git a/src/SparseTransform/DataStructures/Matrix.cs b/src/SparseTransform/DataStructures/Matrix.cs index 0d953872e4c17a14c1798809d2c9d72874781ccc..7b3e54e1c3efe5d37c200883192ffe1a7abc36a7 100644 --- a/src/SparseTransform/DataStructures/Matrix.cs +++ b/src/SparseTransform/DataStructures/Matrix.cs @@ -1,4 +1,4 @@ -namespace DataStructures +namespace SparseTransform.DataStructures { /// <summary> /// Generic base type of matrices.