Example #1
0
        private void addVariable(object sender, RoutedEventArgs e)
        {
            var newDialog = new FunctionsDialog();

            newDialog.ShowDialog();
            if (newDialog.DialogResult == true)
            {
                booleanFunctions.Add(newDialog.Result, "");
            }

            ReloadFunctions(sender, e);


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

            wiringDiagram.Containing(DotBuilder.Statements.Node.Name(newDialog.Result));


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

            // to render to a file stream

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


            GraphViewer.Source = null;

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            File.Delete(System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png"));
            var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                graphviz.RenderGraph(wiringDiagram, stream);

                var bitmap = new BitmapImage();

                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = stream;
                bitmap.EndInit();
                GraphViewer.Source = bitmap;

                stream.Close();
            }
        }
Example #2
0
        private void removeVariable(object sender, RoutedEventArgs e)
        {
            if (cmbSelectVariable.SelectedItem != null)
            {
                booleanFunctions.Remove(cmbSelectVariable.SelectedItem.ToString());
                cmbSelectVariable.Items.Remove(cmbSelectVariable.SelectedItem);
            }
            else
            {
                MessageBox.Show("Please select a Boolean variable first!");
                return;
            }

            wiringDiagram = Graph.Directed("adiagram");

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

            foreach (string key in booleanFunctions.Keys)
            {
                wiringDiagram.Containing(DotBuilder.Statements.Node.Name(key)); //make sure all variables are displayed

                string value;
                booleanFunctions.TryGetValue(key, out value);
                foreach (string k in booleanFunctions.Keys)
                {
                    if (value.Contains(k))
                    {
                        wiringDiagram.Containing(Edge.Between(k, key).WithAttributesOf(Color.Black));
                    }
                }
            }

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

            // to render to a file stream

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


            GraphViewer.Source = null;

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            File.Delete(System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png"));
            var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                graphviz.RenderGraph(wiringDiagram, stream);

                var bitmap = new BitmapImage();

                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = stream;
                bitmap.EndInit();
                GraphViewer.Source = bitmap;

                stream.Close();
            }
        }
Example #3
0
        public void createAsynchronousGraph()
        {
            int totalStates = Convert.ToInt32(Math.Pow(2.0, Convert.ToDouble(cmbSelectVariable.Items.Count)));

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

            graphToDraw = Graph.Directed("agraph");

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

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

            for (int i = 0; i < totalStates; i++)
            {
                string      binary   = "000000000000000000000" + 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);
            }

            foreach (var state in inputs)   //add all possible states to state graph
            {
                string stateX = "";
                foreach (byte val in state)
                {
                    stateX += val;
                }
                graphToDraw.Containing(DotBuilder.Statements.Node.Name(stateX));
            }

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

            foreach (var state in inputs)
            {
                for (int i = 0; i < state.Count; i++)
                {
                    byte a = state.ElementAt(i);
                    a = Convert.ToByte((Convert.ToInt32(a) + 1) % 2);

                    if (evaluateBoolean(state, i) == a)
                    {
                        string oldState = "";
                        string newState = "";

                        for (int k = 0; k < state.Count; k++)
                        {
                            oldState += state.ElementAt(k);
                            if (k == i)
                            {
                                newState += a;
                            }
                            else
                            {
                                newState += state.ElementAt(k);
                            }
                        }

                        graphToDraw.Containing(Edge.Between(oldState, newState).WithAttributesOf(Color.Black));
                    }
                }
            }
        }
Example #4
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();
        }
Example #5
0
        public void createSynchronousGraph()
        {
            int totalStates = Convert.ToInt32(Math.Pow(2.0, Convert.ToDouble(cmbSelectVariable.Items.Count)));

            if (cmbSelectVariable.Items.Count == 0)
            {
                graphToDraw = null;
                return;
            }
            foreach (var val in booleanFunctions.Values)
            {
                if (val == "")
                {
                    MessageBox.Show("You have entered an empty Boolean function for one or more variables!");
                    graphToDraw = null;
                    return;
                }
            }

            graphToDraw = Graph.Directed("agraph");

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

            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);
            }

            foreach (var state in inputs)   //add all possible states to state graph
            {
                string stateX = "";
                foreach (byte val in state)
                {
                    stateX += val;
                }

                graphToDraw.Containing(DotBuilder.Statements.Node.Name(stateX));
            }

            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++)
                {
                    inputX  += pair.Key.ElementAt(l);
                    outputX += allTruthtables.ElementAt(l)[pair.Key];
                }

                graphToDraw.Containing(Edge.Between(inputX, outputX).WithAttributesOf(Color.Black));
            }
        }