Exemplo n.º 1
0
 /// <summary>
 /// Write BDD to file "fileName".
 /// </summary>
 /// <param name="bdd">
 /// The bdd.
 /// </param>
 /// <param name="fileName">
 /// The file name.
 /// </param>
 public void Write(BinaryDecisionDiagram bdd, string fileName)
 {
     using (var stream = new FileStream(fileName, FileMode.Create))
     {
         this.Write(bdd, stream);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Write BDD to stream.
        /// </summary>
        /// <param name="bdd">
        /// The bdd.
        /// </param>
        /// <param name="stream">
        /// The stream.
        /// </param>
        public override void Write(BinaryDecisionDiagram bdd, FileStream stream)
        {
            using (var sw = new StreamWriter(stream, Encoding.UTF8, 65536))
            {
                sw.WriteLine("digraph G {");
                sw.WriteLine("0 [shape=box, label=\"0\", style=filled, shape=box, height=0.3, width=0.3];");
                sw.WriteLine("1 [shape=box, label=\"1\", style=filled, shape=box, height=0.3, width=0.3];");

                List <BDDNode> flat = BDDNode.Traverse(bdd.Root).ToList();
                flat = (from f in flat orderby f.Variable select f).Reverse().ToList();

                var fastAccess = new Dictionary <BDDNode, int>();
                for (int i = 0; i < flat.Count; i++)
                {
                    fastAccess.Add(flat[i], i);
                }

                for (int i = 2; i < flat.Count; i++)
                {
                    sw.WriteLine(i + " [label=\"" + flat[i].Variable + "\"];\n" + i + " -> " + fastAccess[flat[i].LowNode] + " [style=dotted];\n" + i + " -> " + fastAccess[flat[i].HighNode] + " [style=filled];");
                }

                sw.WriteLine("}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes a given BDD to a stream.
        /// </summary>
        /// <param name="bdd">
        /// The bdd.
        /// </param>
        /// <param name="stream">
        /// The stream.
        /// </param>
        public override void Write(BinaryDecisionDiagram bdd, FileStream stream)
        {
            var listOfNodes = (from lAssembly in AppDomain.CurrentDomain.GetAssemblies()
                               from lType in lAssembly.GetTypes()
                               where typeof(BDDNode).IsAssignableFrom(lType)
                               select lType).ToArray();
            var setting = new DataContractSerializerSettings {
                PreserveObjectReferences = true, KnownTypes = listOfNodes
            };

            var xmlSettings = new XmlWriterSettings {
                Indent = true
            };

            var serializer = new DataContractSerializer(typeof(BinaryDecisionDiagram), setting);

            using (XmlWriter w = XmlWriter.Create(stream, xmlSettings))
            {
                serializer.WriteObject(XmlWriter.Create(w, xmlSettings), bdd);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Writes BDD to stream.
 /// </summary>
 /// <param name="bdd">
 /// The bdd.
 /// </param>
 /// <param name="stream">
 /// The stream.
 /// </param>
 public abstract void Write(BinaryDecisionDiagram bdd, FileStream stream);