Example #1
0
        private void drawGraph(object sender, RoutedEventArgs e)
        {
            if (graphToDraw is null)
            {
                return;
            }

            // to get the raw dot output
            var dot = graphToDraw.Render();

            //// to render to a file stream

            //var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png);

            //System.GC.Collect();
            //System.GC.WaitForPendingFinalizers();

            //var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "temporary.png");
            //File.Delete(path);

            //using (var stream = new FileStream(path, FileMode.Create))
            //{
            //    graphviz.RenderGraph(graphToDraw, stream);
            //    stream.Close();
            //}

            Bitmap bm = FileDotEngine.Run(dot);

            StateGraph stateGraph = new StateGraph(bm, booleanFunctions);

            stateGraph.Show();
        }
Example #2
0
        private void drawGraphClustering(object sender, RoutedEventArgs e, List <int> indexes, List <string> variables)
        {
            int totalStates = Convert.ToInt32(Math.Pow(2.0, Convert.ToDouble(cmbSelectVariable.Items.Count)));

            if (cmbSelectVariable.Items.Count == 0)
            {
                return;
            }

            graphToDraw = Graph.Directed("agraph");

            graphToDraw.WithGraphAttributesOf(
                RankDir.TB,
                Font.Name("Arial"),
                Font.Size(55))
            .WithNodeAttributesOf(
                Shape.Ellipse,
                Color.Black);

            string attributes = "";

            int last = variables.LastIndexOf(variables.Last());

            while (indexes.Contains(last))
            {
                last--;
            }

            for (int i = 0; i < variables.Count; i++)
            {
                if (!indexes.Contains(i))
                {
                    attributes += variables.ElementAt(i);

                    if (i != last)
                    {
                        attributes += ", ";
                    }
                }
            }

            graphToDraw.WithGraphAttributesOf(
                Label.Set("Graph showing attributes: " + attributes),
                Font.Size(16));

            g = new AdjacencyGraph <string, Edge <string> >();


            List <List <byte> > inputs = new List <List <byte> >();

            for (int i = 0; i < totalStates; i++)
            {
                string      binary   = "00000000000" + Convert.ToString(i, 2);
                string      final    = binary.Substring(binary.Count() - cmbSelectVariable.Items.Count);
                List <byte> newInput = new List <byte>();
                for (int j = 0; j < cmbSelectVariable.Items.Count; j++)
                {
                    newInput.Add(Convert.ToByte(final[j].ToString()));
                }

                inputs.Add(newInput);
            }

            List <Dictionary <List <byte>, byte> > allTruthtables = new List <Dictionary <List <byte>, byte> >();

            for (int k = 0; k < cmbSelectVariable.Items.Count; k++)
            {
                Dictionary <List <byte>, byte> truthTableX = new Dictionary <List <byte>, byte>();
                foreach (List <byte> input in inputs)
                {
                    truthTableX.Add(input, evaluateBoolean(input, k));
                }

                allTruthtables.Add(truthTableX);
            }

            foreach (var pair in allTruthtables.ElementAt(0))
            {
                string inputX  = "";
                string outputX = "";

                for (int l = 0; l < allTruthtables.Count; l++)
                {
                    if (!indexes.Contains(l))
                    {
                        inputX  += pair.Key.ElementAt(l);
                        outputX += allTruthtables.ElementAt(l)[pair.Key];
                    }
                }

                if (!g.ContainsEdge(inputX, outputX))
                {
                    graphToDraw.Containing(Edge.Between(inputX, outputX).WithAttributesOf(Color.Black));
                }

                //*****Code to convert graph for use with QuickGraph library

                string v1   = inputX;
                string v2   = outputX;
                var    edge = new Edge <string>(v1, v2);

                g.AddVerticesAndEdge(edge);
            }

            if (graphToDraw is null)
            {
                return;
            }

            // to get the raw dot output
            var dot = graphToDraw.Render();

            //// to render to a file stream

            //var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png);

            //System.GC.Collect();
            //System.GC.WaitForPendingFinalizers();

            //var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "temporary.png");
            //File.Delete(path);

            //using (var stream = new FileStream(path, FileMode.Create))
            //{
            //    graphviz.RenderGraph(graphToDraw, stream);
            //    stream.Close();
            //}

            Bitmap bm = FileDotEngine.Run(dot);

            StateGraph stateGraph = new StateGraph(bm, booleanFunctions);

            stateGraph.Show();
        }