Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • pi-v9
2 results

cfunc.c

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ConversionManager.cs 4.48 KiB
    using SparseTransform.DataStructures;
    using SparseTransform.Convert;
    using System.Diagnostics;
    
    namespace SparseTransform
    {
        public class ConversionManager
        {
    
            /// <summary>
            /// Converts Matrix from MatrixMarket format in Dot
            /// </summary>
            /// <param name="MMMatrix">raw MatrixMarket input String</param>
            /// <returns>Dot String </returns>
            public static String Convert2Dot(String MMMatrix)
            {
                MatrixMarketReader reader = new MatrixMarketReader();
                IGraph graph = reader.ReadGraph(MMMatrix);
                DotWriter writer = new DotWriter();
                return writer.Write(graph);
            }
    
    
            /// <summary>
            /// / Partitions as SparseMatrix using graph coloring
            /// </summary>
            /// <param name="MMMatrix">raw MatrixMarket input String</param> 
            /// <param name="textColor">true if color should additionally be represented as text</param>
            /// <returns>Dot String with coloring information</returns>
            public static String Partition2ColoredDot(String MMMatrix, bool textColor = false)
            {
                MatrixMarketReader reader = new MatrixMarketReader();
    
                Stopwatch inWatch = Stopwatch.StartNew();
    
                IGraph graph = reader.ReadGraph(MMMatrix);
    
                inWatch.Stop();
                TimeSpan inTime = inWatch.Elapsed;
    
                Colorer color = new Colorer();
    
                Stopwatch colWatch = Stopwatch.StartNew();
    
                if (graph is AdjacencyGraph)
                {
                    color.StarColor1((AdjacencyGraph)graph);
                }
                else
                {
                    color.PartialD2Color((BipartiteGraph)graph);
                }
    
                colWatch.Stop();
                TimeSpan colTime = colWatch.Elapsed;
    
                ColoredDotWriter writer = new ColoredDotWriter(graph, textColor);
    
                Stopwatch outWatch = Stopwatch.StartNew();
    
                String dotOutput = writer.Write(graph);
    
                outWatch.Stop();
                TimeSpan outTime = outWatch.Elapsed;
    
                string inTimeOutput = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                inTime.Hours, inTime.Minutes, inTime.Seconds,
                inTime.Milliseconds / 10);
    
                string colTimeOutput = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                colTime.Hours, colTime.Minutes, colTime.Seconds,
                colTime.Milliseconds / 10);
    
                string outTimeOutput = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                outTime.Hours, outTime.Minutes, outTime.Seconds,
                outTime.Milliseconds / 10);
    
                Console.WriteLine($"Time elapsed in ConversionManager:\nIn-Transformation:\t{inTimeOutput}\nColoring:\t\t{colTimeOutput}\nOut-Transformation:\t{outTimeOutput}\n");
                return dotOutput;
    
            }
            /// <summary>
            /// Partions SparseMatrix in Seed Matrix
            /// </summary>
            /// <param name="MMMatrix">raw MatrixMarket input String</param>
            /// <returns>Seed Matrix as String</returns>
            public static String Partition2SeedMatrix(String MMMatrix)
            {
                MatrixMarketReader reader = new MatrixMarketReader();
                IGraph graph = reader.ReadGraph(MMMatrix);
                Colorer color = new Colorer();
                if (graph is AdjacencyGraph)
                {
    
                    color.StarColor1((AdjacencyGraph)graph);
    
    
                }
                else
                    color.PartialD2Color((BipartiteGraph)graph);
                DoubleMatrix inputMatrix = reader.ReadMatrix(MMMatrix);
                MatrixMarketWriter writer = new MatrixMarketWriter(true, inputMatrix);
                return writer.Write(graph);
            }
            /// <summary>
            /// Partitions SparseMatricx in CompressedMatrix
            /// </summary>
            /// <param name="MMMatrix">raw MatrixMarket input String</param>
            /// <returns>Compressed Matrix as String</returns>
            public static String Partition2CompressedMatrix(String MMMatrix)
            {
                MatrixMarketReader reader = new MatrixMarketReader();
                IGraph graph = reader.ReadGraph(MMMatrix);
                Colorer color = new Colorer();
                if (graph is AdjacencyGraph)
                {
    
                    color.StarColor1((AdjacencyGraph)graph);
    
    
                }
                else
                    color.PartialD2Color((BipartiteGraph)graph);
                DoubleMatrix inputMatrix = reader.ReadMatrix(MMMatrix);
                MatrixMarketWriter writer = new MatrixMarketWriter(false, inputMatrix);
                return writer.Write(graph);
            }
        }
    }