view defical-sharp/libsemtd/print.cs @ 1:758381a85d76 default tip

Incorrect printf format.
author Edho Prima Arief <me@myconan.net>
date Mon, 28 Jun 2010 14:52:19 +0700
parents ebed2bd0d300
children
line wrap: on
line source

namespace libsemtd
{
    public partial class Semtd
    {
        private string sep = " | ";
        private string print(int mode)
        {
            return printBasic() + sep +
                printMagicNum(mode) + sep +
                printLabels(mode) + sep +
                printDef(mode) + sep +
                printMisc(mode);
        }
        private string printBasic()
        {
            string ret = "";
            ret += "graph: " + this.graphType +
                sep +
                "edges: " + this.numEdges.ToString() +
                sep +
                "vertices: " + this.numVerMain.ToString() +
                sep +
                "deficiencies: " + this.numVerDef.ToString();
            return ret;
        }
        private string printMagicNum(int mode)
        {
            string ret = "";
            int edgeWeight, edgeLabel;
            edgeLabel = edgeWeight = 0;
            for (int i = 1; i <= this.labelEdgeAbsoluteMax; i++)
            {
                if (this.labelEdgesUsed[i] > 0)
                {
                    edgeWeight = i;
                    edgeLabel = this.numEdges + this.numVerTotal;
                    break;
                }
            }
            if (mode == 1)
            {
                edgeWeight = 2 * (this.numVerTotal) + 2 - edgeWeight;
                edgeLabel = 2 * this.numVerTotal + this.numEdges + 1 - edgeLabel;
            }
            ret += "mnum: " + (edgeWeight + edgeLabel).ToString();
            return ret;
        }
        private string printLabels(int mode)
        {
            string ret = "";
            int[] myLabelVer = new int[this.NumVerMain];
            for (int i = 0; i < this.NumVerMain; i++)
            {
                if (mode == 1)
                {
                    myLabelVer[i] = this.numVerTotal + 1 - this.labelVer[i];
                }
                else
                {
                    myLabelVer[i] = this.labelVer[i];
                }
            }
            if (this.graphType == "doublefan" && myLabelVer[0] > myLabelVer[1])
            {
                int temp = myLabelVer[0];
                myLabelVer[0] = myLabelVer[1];
                myLabelVer[1] = temp;
            }
            int startPath=0;
            int endPath=0;
            switch (graphType)
            {
                case "fan":
                    {
                        startPath = 1;
                        endPath=this.numVerMain-1;
                        break;
                    }
                case "doublefan":
                case "wheel":
                    {
                        startPath = 2;
                        endPath=this.numVerMain-1;
                        break;
                    }
            }
            if (startPath > 0 && myLabelVer[startPath] > myLabelVer[endPath])
            {
                int a = startPath, b = endPath;
                while (a < b)
                {
                    int temp = myLabelVer[a];
                    myLabelVer[a] = myLabelVer[b];
                    myLabelVer[b] = temp;
                    a++; b--;
                }
            }
            for (int i = 0; i < this.numVerMain; i++)
            {
                int myLabel=myLabelVer[i];
                if (i == 0)
                    switch (graphType)
                    {
                        case "wheel":
                            {
                                ret += "c: " + myLabel.ToString()
                                    + sep
                                    + "l: ";
                                break;
                            }
                        case "fan":
                            {
                                ret += "c: " + myLabel.ToString()
                                    + sep
                                    + "p: ";
                                break;
                            }
                        case "doublefan":
                            {
                                ret += "c: " + myLabel.ToString() + ",";
                                break;
                            }
                    }
                else if (i == 1 && this.graphType == "doublefan")
                {
                    ret += myLabel.ToString()
                        + sep
                        + "p: ";
                }
                else if (i == this.numVerMain-1)
                    ret += myLabel.ToString();
                else
                    ret += myLabel.ToString() + ",";
            }
            return ret;
        }
        private string printDef(int mode)
        {
            string ret = "";
            if (this.numVerDef > 0)
            {
                ret += "def: ";
                bool[] labelVerUsed = new bool[this.numVerTotal + 1];
                for (int i = 0; i < this.numVerMain; i++)
                    labelVerUsed[this.labelVer[i]] = true;
                int amountDef = 0;
                for (int i = 1; i <= this.numVerTotal; i++)
                {
                    int myDef;
                    if (!labelVerUsed[i])
                    {
                        if (mode == 1)
                            myDef = this.numVerTotal + 1 - i;
                        else
                            myDef = i;
                        if (amountDef == this.numVerDef - 1)
                        {
                            ret += myDef.ToString();
                            break;
                        }
                        else
                        {
                            ret += myDef.ToString() + ",";
                            amountDef++;
                        }
                    }
                }
            }
            return ret;
        }
        private string printMisc(int mode)
        {
            string ret = "";
            if (this.graphType == "wheel" || this.graphType == "fan" || this.graphType == "doublefan")
            {
                int startPath, endPath;
                startPath = 0;
                switch (this.graphType)
                {
                    case "fan":
                        {
                            startPath = 1;
                            break;
                        }
                    case "wheel":
                    case "doublefan":
                        {
                            startPath = 2;
                            break;
                        }
                }
                endPath = this.numVerMain-1;
                bool isConstant = true;
                for (int i = startPath; i < endPath; i++)
                {
                    if (mode == 0)
                    {
                        if (this.labelVer[i] > this.labelVer[i + 1])
                        {
                            isConstant = false;
                            break;
                        }
                    }
                    else if (mode == 1)
                    {
                        if (this.labelVer[i] < this.labelVer[i + 1])
                        {
                            isConstant = false;
                            break;
                        }
                    }
                }
                if (isConstant)
                    ret += "constant";
            }
            if (mode == 1)
                ret += "dual";
            return ret;
        }
    }
}