private void ApplyRecoloring(RecoloringFunction recoloringFunction, string algorithm)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            int[] coloring = currentGraphEntry.Coloring;

            if (coloring == null)
            {
                textBox1.Text = "Cannot recolor uncolored graph";
            }

            coloring = recoloringFunction(coloring);

            if (uGraph.ValidColoring(coloring))
            {
                currentGraphEntry.Coloring = coloring;
                int[]          colorCount     = Utility.ArrayToCount(coloring);
                ColoringResult coloringResult = new ColoringResult(algorithm, colorCount.Length, colorCount);
                currentGraphEntry.Results.Add(coloringResult);

                UpdateDisplay();
            }
            else
            {
                textBox1.Text = "Bogus Coloring";
            }
        }
        private void NewGraph(int n, int m, int seed, bool isBipartite)
        {
            string str = "Graph: " + n + " " + m + " " + seed + " " + graphCounter;

            graphCounter++;

            GraphParameters gp           = new GraphParameters(n, m, seed, isBipartite);
            UGraph          uGraph       = new UGraph(gp);
            GraphDisplay    graphDisplay = new GraphDisplay(uGraph);

            /*           if (isBipartite)
             *             graphDisplay.BipartiteInit();
             *         else  */
            graphDisplay.CircleInit();

            int[] coloring = Utility.InitIntArray(n, 0);

            GraphEntry ge = new GraphEntry(gp, uGraph, graphDisplay, coloring);

            graphListBox.Items.Add(str);
            graphEntries.Add(ge);



            graphListBox.SetSelected(graphListBox.Items.Count - 1, true);
        }
 public GraphEntry(GraphParameters p, UGraph uGraph, GraphDisplay graphDisplay, int[] coloring)
 {
     Param        = p;
     UGraph       = uGraph;
     GraphDisplay = graphDisplay;
     Coloring     = coloring;
     Results      = new List <ColoringResult>();
 }
        private void OnNormalizeClick(object sender, EventArgs e)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            if (uGraph != null)
            {
                ApplyRecoloring(uGraph.FullNormalize, "Normalize");
            }
        }
        private void OnRecolorSwap(object sender, EventArgs e)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            if (uGraph != null)
            {
                ApplyRecoloring(uGraph.RecolorSwap, "Max-Swap");
            }
        }
        private void OnRandomRecolorClick(object sender, EventArgs e)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            if (uGraph != null)
            {
                ApplyRecoloring(uGraph.RandomRecoloring, "RandomColoring");
            }
        }
        private void OnTwoColorClick(object sender, EventArgs e)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            if (uGraph != null)
            {
                ApplyColoring(uGraph.TwoColor, "2-Col");
            }
        }
        private void OnLDFClick(object sender, EventArgs e)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            if (uGraph != null)
            {
                ApplyColoring(uGraph.LDFColor, "LDF");
            }
        }
 public GraphDisplay(UGraph graph)
 {
     random         = new Random();
     this.graph     = graph;
     colorVector    = CreateColorVector();
     velocityVector = new PointF[graph.NVertices];
     for (int i = 0; i < velocityVector.Length; i++)
     {
         velocityVector[i] = new PointF(0F, 0F);
     }
 }
Beispiel #10
0
        private void OnTestClick(object sender, EventArgs e)
        {
            int n    = (int)vertexUpDown.Value;
            int m    = (int)edgeUpDown.Value;
            int seed = graphCounter;

            NewGraph(n, m, seed, false);

            UGraph uGraph = currentGraphEntry.UGraph;

            if (uGraph != null)
            {
                ApplyColoring(uGraph.LDFColor, "LDF");
            }
        }
Beispiel #11
0
        private void UpdateDisplay()
        {
            int    n      = currentGraphEntry.Param.N;
            int    m      = currentGraphEntry.Param.M;
            UGraph uGraph = currentGraphEntry.UGraph;

            int[]        coloring     = currentGraphEntry.Coloring;
            GraphDisplay graphDisplay = currentGraphEntry.GraphDisplay;

            if (uGraph != null)
            {
                textBox2.Text = currentGraphEntry.UGraph.ToString();
            }
            else
            {
                textBox2.Text = "";
            }

            if (coloring != null)
            {
                int[] colorCount = Utility.ArrayToCount(coloring);
                textBox1.Text = Utility.ArrayToString(colorCount, true);
            }
            else
            {
                textBox1.Text = "";
            }

            statusVertexLabel.Text = "N " + n;
            statusEdgeLabel.Text   = "M " + m;

            if (graphDisplay != null)
            {
                double kineticEnergy = graphDisplay.KineticEnergy / 10000.0;
                statusKineticEnergyLabel.Text = "Kinetic Energy " + kineticEnergy.ToString("F4");

                double potentialEnergy = graphDisplay.PotentialEnergy / 10000.0;
                statusPotentialEnergyLabel.Text = "Potential Energy " + potentialEnergy.ToString("F4");

                statusStrip1.Refresh();
            }

            drawingPanel.Invalidate();
        }
Beispiel #12
0
        private void OnColorCheckClick(object sender, EventArgs e)
        {
            UGraph uGraph = currentGraphEntry.UGraph;

            int[] coloring = currentGraphEntry.Coloring;

            if (coloring == null)
            {
                textBox1.Text = "Coloring is empty";
            }
            else if (uGraph.ValidColoring(coloring))
            {
                textBox1.Text = "Valid coloring";
            }
            else
            {
                textBox1.Text = "Invalid coloring";
            }
        }