public void GetInstanceOfCoreObjects()
        {
            Project p = new Project();
            IEntity ety = new MathNet.Symbolics.Core.Entity("%", new MathIdentifier("Percent", "Test"), InfixNotation.LeftAssociativeInnerOperator, 100, false);

            Signal signal = Binder.CreateSignal();
            Assert.IsNotNull(signal, "A0");
            Assert.AreEqual("MathNet.Symbolics.Core.Signal", signal.GetType().FullName, "A1");
            signal = Binder.GetSpecificInstance<Signal>(new MathIdentifier("Signal", "Core"));
            Assert.IsNotNull(signal, "A2");
            Assert.AreEqual("MathNet.Symbolics.Core.Signal", signal.GetType().FullName, "A3");

            Bus bus = Binder.CreateBus();
            Assert.IsNotNull(bus, "B0");
            Assert.AreEqual("MathNet.Symbolics.Core.Bus", bus.GetType().FullName, "B1");
            bus = Binder.GetSpecificInstance<Bus>(new MathIdentifier("Bus", "Core"));
            Assert.IsNotNull(bus, "B2");
            Assert.AreEqual("MathNet.Symbolics.Core.Bus", bus.GetType().FullName, "B3");

            Port port = Binder.CreatePort(ety);
            Assert.IsNotNull(port, "C0");
            Assert.AreEqual("MathNet.Symbolics.Core.Port", port.GetType().FullName, "C1");
            port = Binder.GetSpecificInstance<Port, IEntity>(new MathIdentifier("Port", "Core"), ety);
            Assert.IsNotNull(port, "C2");
            Assert.AreEqual("MathNet.Symbolics.Core.Port", port.GetType().FullName, "C3");
        }
        public void SystemToExpressionTest()
        {
            Project p = new Project();
            MathSystem s1 = p.CurrentSystem;

            // BUILD SYSTEM 1: sin(x^2)*2
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Square(x); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";
            Signal sinx2t2 = sinx2 * IntegerValue.ConstantTwo;
            s1.AddSignalTree(sinx2t2, true, true);

            // EVALUATE SYSTEM 1 FOR x=1.5
            x.PostNewValue(new RealValue(1.5));
            p.SimulateInstant();
            Assert.AreEqual(0, s1.BusCount, "A0");
            Assert.AreEqual(5, s1.SignalCount, "A1");
            Assert.AreEqual(3, s1.PortCount, "A2");
            Assert.AreEqual("Std.Real(1.55614639377584)", sinx2t2.Value.ToString(), "A3");

            // SERIALIZE SYSTEM 1 TO EXPRESSION
            ExpressionWriter writer = new ExpressionWriter();
            SystemReader reader = new SystemReader(writer);
            reader.ReadSystem(s1);
            string expr = writer.WrittenExpressions.Dequeue();
            Console.WriteLine(expr);

            // ....
        }
예제 #3
0
        public void Parser_SimpleExpressions()
        {
            Project p = new Project();
            // TODO: UNCOMMENT
            //LogObserver lo = new LogObserver(new TextLogWriter(Console.Out));
            //p.AttachLocalObserver(lo);
            MathSystem s = p.CurrentSystem;

            Assert.AreEqual(0, s.SignalCount, "0");

            p.Interpret("signal x;");
            Assert.AreEqual(1, s.SignalCount, "A1");
            Assert.IsTrue(s.ContainsNamedSignal("x"), "A2");

            p.Interpret("x");
            Assert.AreEqual(1, s.SignalCount, "B1");

            p.Interpret("y <- x^2");
            Assert.AreEqual(3, s.SignalCount, "C1");
            Assert.AreEqual("Std.Power", s.LookupNamedSignal("y").DrivenByPort.Entity.EntityId.ToString(), "C2");
            Assert.AreEqual("x", s.LookupNamedSignal("y").DrivenByPort.InputSignals[0].Label, "C3");
            Assert.AreEqual("Std.Integer(2)", s.LookupNamedSignal("y").DrivenByPort.InputSignals[1].Value.ToString(), "C4");

            p.Interpret("instantiate + in a,b out c;");
            Assert.AreEqual(6, s.SignalCount, "D1");
            Assert.AreEqual("Std.Add", s.LookupNamedSignal("c").DrivenByPort.Entity.EntityId.ToString(), "D2");
            Assert.AreEqual("a", s.LookupNamedSignal("c").DrivenByPort.InputSignals[0].Label, "D3");
            Assert.AreEqual("b", s.LookupNamedSignal("c").DrivenByPort.InputSignals[1].Label, "D4");

            p.Interpret("d <- diff(a*b,a);");
            Assert.AreEqual(8, s.SignalCount, "E1");
            Assert.AreEqual("Std.Derive", s.LookupNamedSignal("d").DrivenByPort.Entity.EntityId.ToString(), "E2");
            Assert.AreEqual("Std.Multiply", s.LookupNamedSignal("d").DrivenByPort.InputSignals[0].DrivenByPort.Entity.EntityId.ToString(), "E3");
            Assert.AreEqual("a", s.LookupNamedSignal("d").DrivenByPort.InputSignals[1].Label, "E4");
        }
예제 #4
0
        public void Parser_StructuralExpressions()
        {
            Project p = new Project();
            ILibrary l = Service<ILibrary>.Instance;
            MathSystem s = p.CurrentSystem;
            s.AddNamedSignal("w", new RealValue(0.1));
            p.SimulateInstant();

            p.Interpret("define entity Test \"test\" function in x,c out y;");
            Assert.IsTrue(l.ContainsEntity(new MathIdentifier("Test", "Work")),"01");
            Assert.AreEqual("Work.Test", l.LookupEntity("test", 2).EntityId.ToString());

            p.Interpret("instantiate Work.Test in x->a,c->a*b out res1;\nres2 <- test(a*b,b);");
            Assert.AreEqual("Work.Test", s.LookupNamedSignal("res1").DrivenByPort.Entity.EntityId.ToString(),"02");
            Assert.AreEqual("Work.Test", s.LookupNamedSignal("res2").DrivenByPort.Entity.EntityId.ToString(),"03");
            Assert.AreEqual("Std.Multiply", s.LookupNamedSignal("res1").DrivenByPort.InputSignals[1].DrivenByPort.Entity.EntityId.ToString(),"04");
            Assert.AreEqual("Std.Multiply", s.LookupNamedSignal("res2").DrivenByPort.InputSignals[0].DrivenByPort.Entity.EntityId.ToString(),"05");

            p.Interpret("define architecture TestArch Test { y <- x * sin(c) +w; };");
            Assert.IsTrue(l.ContainsEntity(new MathIdentifier("Test", "Work")),"06");

            s.LookupNamedSignal("a").PostNewValue(new RealValue(0.25));
            s.LookupNamedSignal("b").PostNewValue(new RealValue(0.75));
            p.SimulateInstant();
            Signal res1 = s.LookupNamedSignal("res1");
            Signal res2 = s.LookupNamedSignal("res2");
            Assert.AreEqual("Work.TestArch", res1.DrivenByPort.CurrentArchitecture.ArchitectureId.ToString());
            Assert.AreEqual("Work.TestArch", res2.DrivenByPort.CurrentArchitecture.ArchitectureId.ToString());
            Assert.AreEqual(0.1466, Math.Round(RealValue.ConvertFrom(res1.Value).Value, 4));
            Assert.AreEqual(0.2278, Math.Round(RealValue.ConvertFrom(res2.Value).Value, 4));
        }
예제 #5
0
 public NetronController(Project project, DiagramControl netronDiagram)
     : base(project)
 {
     _presentation = netronDiagram;
     _mathBridges = new Dictionary<Guid, Bridge>();
     _netronBridges = new Dictionary<Document, Bridge>();
     Init();
     _presentation.OnEntityAdded += NetronEntityAddedHandler;
     _presentation.OnEntityRemoved += NetronEntityRemovedHandler;
 }
예제 #6
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _project = new Project();
            _ctrl = new NetronController(_project, Application.Diagram);

            // attach a system logger (with console output), something
            // we get for free thanks to the channels subsystem (mediator/observer).
            LogObserver lo = new LogObserver(new TextLogWriter(Console.Out));
            _project.AttachLocalObserver(lo);
            _table = _project.Context.Library.Entities;
            UpdateEntities();
            
        }
        public void SystemToSystemCloneTest()
        {
            Project p = new Project();
            MathSystem s1 = p.CurrentSystem;

            // BUILD SYSTEM 1: sin(x^2)
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Square(x); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";
            Signal sinx2t2 = sinx2 * IntegerValue.ConstantTwo;
            s1.AddSignalTree(sinx2t2, true, true);

            // EVALUATE SYSTEM 1 FOR x=1.5
            x.PostNewValue(new RealValue(1.5));
            p.SimulateInstant();
            Assert.AreEqual(0, s1.BusCount, "A0");
            Assert.AreEqual(5, s1.SignalCount, "A1");
            Assert.AreEqual(3, s1.PortCount, "A2");
            Assert.AreEqual("Std.Real(1.55614639377584)", sinx2t2.Value.ToString(), "A3");

            // CLONE SYSTEM 1 TO SYSTEM 2
            /*
             * HINT: would be simpler to just call:
             * MathSystem s2 = s1.Clone();
             */
            SystemWriter writer = new SystemWriter();
            SystemReader reader = new SystemReader(writer);
            reader.ReadSystem(s1);
            IMathSystem s2 = writer.WrittenSystems.Dequeue();

            Assert.AreEqual(0, s2.BusCount, "B0");
            Assert.AreEqual(5, s2.SignalCount, "B1");
            Assert.AreEqual(3, s2.PortCount, "B2");
            Assert.AreEqual("Std.Real(1.55614639377584)", s2.GetOutput(0).Value.ToString(), "B3");

            // EVALUATE SYSTEM 2 FOR x=2.5
            s2.GetInput(0).PostNewValue(new RealValue(2.5));
            p.SimulateInstant();
            Assert.AreEqual("Std.Real(-0.0663584330951136)", s2.GetOutput(0).Value.ToString(), "C0");

            // CHECK SYSTEM 1 STILL ON x=1.5
            Assert.AreEqual("Std.Real(1.5)", x.Value.ToString(), "D0");
            Assert.AreEqual("Std.Real(1.55614639377584)", sinx2t2.Value.ToString(), "D1");
        }
예제 #8
0
        public void Pattern_CoalescedTreeDeduction()
        {
            Project p = new Project();
            MathSystem s = p.CurrentSystem;

            // sin(x^2)
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Square(x); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";

            TreePattern psinadd = new TreePattern(new EntityCondition(new MathIdentifier("Sine", "Std")));
            Pattern psinadd_add = new Pattern(new EntityCondition(new MathIdentifier("Add", "Std")));
            psinadd.Add(psinadd_add);
            psinadd_add.Group = "add";

            TreePattern psinsqr = new TreePattern(new EntityCondition(new MathIdentifier("Sine", "Std")));
            Pattern psinsqr_sqr = new Pattern(new EntityCondition(new MathIdentifier("Square", "Std")));
            psinsqr.Add(psinsqr_sqr);
            psinsqr.Group = "sin";
            psinsqr_sqr.Group = "sqr";

            // generate coalesced tree
            CoalescedTreeNode root;
            List<CoalescedTreeNode> list = CoalescedTreeNode.CreateRootTree(out root);
            psinadd.MergeToCoalescedTree(new MathIdentifier("SinAdd", "Test"), list);
            psinsqr.MergeToCoalescedTree(new MathIdentifier("SinSqr", "Test"), list);

            // test whether the tree was generated correctly
            Assert.AreEqual(1, root.ConditionAxis.Count, "D01");
            Assert.AreEqual(0, root.PatternAxis.Count, "D02");

            CoalescedTreeNode csin = root.ConditionAxis[0];
            Assert.AreEqual(true, csin.Condition is EntityCondition, "D03");
            Assert.AreEqual(new MathIdentifier("Sine", "Std"), ((EntityCondition)csin.Condition).EntityId, "D04");
            Assert.AreEqual(1, csin.GroupAxis.Count, "D05");
            Assert.AreEqual(0, csin.SubscriptionAxis.Count, "D06");
            Assert.AreEqual("sin", csin.GroupAxis[new MathIdentifier("SinSqr", "Test")], "D07");
            Assert.AreEqual(1, csin.PatternAxis.Count, "D08");
            Assert.AreEqual(1, csin.PatternAxis[0].ChildrenAxis.Count, "D09");
            Assert.AreEqual(true, csin.PatternAxis[0].ChildrenAxis[0].Condition is AlwaysTrueCondition, "D10");

            CoalescedTreeNode cadd = csin.PatternAxis[0].ChildrenAxis[0].ConditionAxis[0];
            Assert.AreEqual(true, cadd.Condition is EntityCondition, "D11");
            Assert.AreEqual(new MathIdentifier("Add", "Std"), ((EntityCondition)cadd.Condition).EntityId, "D12");
            Assert.AreEqual(1, cadd.GroupAxis.Count, "D13");
            Assert.AreEqual(1, cadd.SubscriptionAxis.Count, "D14");
            Assert.AreEqual("add", cadd.GroupAxis[new MathIdentifier("SinAdd", "Test")], "D15");
            Assert.AreEqual(new MathIdentifier("SinAdd", "Test"), cadd.SubscriptionAxis[0], "D16");
            Assert.AreEqual(0, cadd.PatternAxis.Count, "D18");

            CoalescedTreeNode csqr = csin.PatternAxis[0].ChildrenAxis[0].ConditionAxis[1];
            Assert.AreEqual(true, csqr.Condition is EntityCondition, "D19");
            Assert.AreEqual(new MathIdentifier("Square", "Std"), ((EntityCondition)csqr.Condition).EntityId, "D20");
            Assert.AreEqual(1, csqr.GroupAxis.Count, "D21");
            Assert.AreEqual(1, csqr.SubscriptionAxis.Count, "D22");
            Assert.AreEqual("sqr", csqr.GroupAxis[new MathIdentifier("SinSqr", "Test")], "D23");
            Assert.AreEqual(new MathIdentifier("SinSqr", "Test"), csqr.SubscriptionAxis[0], "D24");
            Assert.AreEqual(0, csqr.PatternAxis.Count, "D26");

            // test whether the tree works as expected
            MatchCollection res = Match.MatchAll(sinx2, sinx2.DrivenByPort, root);
            Assert.AreEqual(true, res.Contains(new MathIdentifier("SinSqr", "Test")), "D27");
            Assert.AreEqual(false, res.Contains(new MathIdentifier("SinAdd", "Test")), "D28");

            Match match = res[new MathIdentifier("SinSqr", "Test")];
            Assert.AreEqual(new MathIdentifier("SinSqr", "Test"), match.PatternId, "D29");
            Assert.AreEqual(2, match.GroupCount, "D30");
            Assert.AreEqual(1, match["sin"].Count, "D31");
            Assert.AreEqual(sinx2.InstanceId, match["sin"][0].First.InstanceId, "D32");
            Assert.AreEqual(1, match["sqr"].Count, "D33");
            Assert.AreEqual(x2.InstanceId, match["sqr"][0].First.InstanceId, "D34");
        }
예제 #9
0
        public void Pattern_TreePattern()
        {
            Project p = new Project();
            MathSystem s = p.CurrentSystem;

            // sin(x^2)
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Square(x); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";

            Pattern psimp = new Pattern(new EntityCondition(new MathIdentifier("Sine", "Std")));
            Assert.AreEqual(true, psimp.Match(sinx2, sinx2.DrivenByPort), "B01");
            Assert.AreEqual(false, psimp.Match(x2, x2.DrivenByPort), "B02");

            TreePattern psinsqr = new TreePattern(new EntityCondition(new MathIdentifier("Sine", "Std")));
            psinsqr.Add(new Pattern(new EntityCondition(new MathIdentifier("Square", "Std"))));
            Assert.AreEqual(true, psinsqr.Match(sinx2, sinx2.DrivenByPort), "B03");
            Assert.AreEqual(false, psinsqr.Match(x2, x2.DrivenByPort), "B04");

            TreePattern psinadd = new TreePattern(new EntityCondition(new MathIdentifier("Sine", "Std")));
            psinadd.Add(new Pattern(new EntityCondition(new MathIdentifier("Add", "Std"))));
            Assert.AreEqual(false, psinadd.Match(sinx2, sinx2.DrivenByPort), "B03");
            Assert.AreEqual(false, psinadd.Match(x2, x2.DrivenByPort), "B04");
        }
예제 #10
0
        public void Pattern_Conditions()
        {
            Project p = new Project();
            MathSystem s = p.CurrentSystem;

            // sin(x^2)
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Power(x, IntegerValue.ConstantTwo); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";

            AlwaysTrueCondition ctrue = AlwaysTrueCondition.Instance;
            Assert.AreEqual(true, ctrue.FulfillsCondition(x, x.DrivenByPort), "A01");

            EntityCondition centity = new EntityCondition(new MathIdentifier("Sine", "Std"));
            Assert.AreEqual(true, centity.FulfillsCondition(sinx2, sinx2.DrivenByPort), "A02");
            Assert.AreEqual(false, centity.FulfillsCondition(x2, x2.DrivenByPort), "A03");

            //InputSignalsPropertyCondition cinputconst = new InputSignalsPropertyCondition(new MathIdentifier("Constant", "Std"), CombinationMode.AtLeastOne);
            InputSignalsFlagCondition cinputconst = new InputSignalsFlagCondition(StdAspect.ConstantFlag, FlagState.Enabled, CombinationMode.AtLeastOne);
            Assert.AreEqual(true, cinputconst.FulfillsCondition(x2, x2.DrivenByPort), "A04");
            Assert.AreEqual(false, cinputconst.FulfillsCondition(sinx2, sinx2.DrivenByPort), "A05");

            OrCondition cor = new OrCondition(centity, cinputconst);
            Assert.AreEqual(true, cor.FulfillsCondition(x2, x2.DrivenByPort), "A06");
            Assert.AreEqual(true, cor.FulfillsCondition(sinx2, sinx2.DrivenByPort), "A07");
            Assert.AreEqual(false, cor.FulfillsCondition(x, x.DrivenByPort), "A08");

            AndCondition cand = new AndCondition(ctrue, centity);
            Assert.AreEqual(true, cand.FulfillsCondition(sinx2, sinx2.DrivenByPort), "A09");
            Assert.AreEqual(false, cand.FulfillsCondition(x2, x2.DrivenByPort), "A10");
        }
예제 #11
0
        public void Pattern_CoalescedTreeMatching()
        {
            Project p = new Project();
            MathSystem s = p.CurrentSystem;

            // sin(x^2)
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Square(x); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";

            CoalescedTreeNode root = new CoalescedTreeNode(AlwaysTrueCondition.Instance);
            root.Subscribe(new MathIdentifier("A", "Test"));

            CoalescedTreeNode sin = new CoalescedTreeNode(new EntityCondition(new MathIdentifier("Sine", "Std")));
            sin.AddGroup(new MathIdentifier("B", "Test"), "sin");
            root.ConditionAxis.Add(sin);

            CoalescedTreeNode sqr = new CoalescedTreeNode(new EntityCondition(new MathIdentifier("Square", "Std")));
            sqr.AddGroup(new MathIdentifier("B", "Test"), "sqr");
            sqr.Subscribe(new MathIdentifier("B", "Test"));
            CoalescedChildPattern sqrPattern = new CoalescedChildPattern();
            sqrPattern.AddChild(sqr);
            sin.PatternAxis.Add(sqrPattern);

            CoalescedTreeNode tan = new CoalescedTreeNode(new EntityCondition(new MathIdentifier("Tangent", "Std")));
            tan.AddGroup(new MathIdentifier("B", "Test"), "tan");
            tan.Subscribe(new MathIdentifier("C", "Test"));
            root.ConditionAxis.Add(tan);

            MatchCollection res = root.MatchAll(sinx2, sinx2.DrivenByPort, 1);
            Assert.AreEqual(true, res.Contains(new MathIdentifier("A", "Test")), "C01");
            Assert.AreEqual(true, res.Contains(new MathIdentifier("B", "Test")), "C02");
            Assert.AreEqual(false, res.Contains(new MathIdentifier("C", "Test")), "C03");

            Match mA = res[new MathIdentifier("A", "Test")];
            Assert.AreEqual(new MathIdentifier("A", "Test"), mA.PatternId, "C04");
            Assert.AreEqual(0, mA.GroupCount, "C05");

            Match mB = res[new MathIdentifier("B", "Test")];
            Assert.AreEqual(new MathIdentifier("B", "Test"), mB.PatternId, "C06");
            Assert.AreEqual(2, mB.GroupCount, "C07");

            Group mBsqr = mB["sqr"];
            Assert.AreEqual(1, mBsqr.Count, "C08");
            Assert.AreEqual(x2.InstanceId, mBsqr[0].First.InstanceId, "C09");
            Assert.AreEqual(x2.DrivenByPort.InstanceId, mBsqr[0].Second.InstanceId, "C10");

            Group mBsin = mB["sin"];
            Assert.AreEqual(1, mBsin.Count, "C11");
            Assert.AreEqual(sinx2.InstanceId, mBsin[0].First.InstanceId, "C12");
            Assert.AreEqual(sinx2.DrivenByPort.InstanceId, mBsin[0].Second.InstanceId, "C13");
        }
 public void Initialize()
 {
     _p = new Project();
     _f = Service<IFormatter>.Instance;
 }
 public void Cleanup()
 {
     _p = null;
     _f = null;
 }
예제 #14
0
 protected ControllerBase(Project project)
 {
     _project = project;
 }
예제 #15
0
 public void Initialize()
 {
     this.project = new Project();
 }
        public void SerializeSingleCustomData()
        {
            Project p = new Project();
            Dictionary<Guid, Guid> emptyMappings = new Dictionary<Guid, Guid>();
            Dictionary<Guid, Signal> signals = new Dictionary<Guid, Signal>();
            Dictionary<Guid, Bus> buses = new Dictionary<Guid, Bus>();

            ComplexValue cv = new ComplexValue(Constants.Pi, Constants.E);

            string xml = Serializer.SerializeToString(cv, emptyMappings, emptyMappings);

            ComplexValue ret = Serializer.DeserializeFromString<ComplexValue>(xml, signals, buses);

            Assert.AreEqual(cv.TypeId, ret.TypeId, "B");
            Assert.AreEqual(cv.ToString(), ret.ToString(), "C");
        }
        public void SerializeEmptyCustomDataList()
        {
            Project p = new Project();
            Dictionary<Guid, Guid> emptyMappings = new Dictionary<Guid, Guid>();
            Dictionary<Guid, Signal> signals = new Dictionary<Guid, Signal>();
            Dictionary<Guid, Bus> buses = new Dictionary<Guid, Bus>();

            List<ICustomData> values = new List<ICustomData>();

            string xml = Serializer.SerializeListToString(values, emptyMappings, emptyMappings, "Structures");

            List<ICustomData> ret = Serializer.DeserializeListFromString<ICustomData>(xml, signals, buses, "Structures");

            Assert.AreEqual(0, ret.Count, "A");
        }
예제 #18
0
 protected ControllerBase()
 {
     _project = new Project();
 }
        public void SystemToXmlSerializeTest()
        {
            Project p = new Project();
            MathSystem s1 = p.CurrentSystem;

            // BUILD SYSTEM 1: sin(x^2)*2
            Signal x = Binder.CreateSignal(); x.Label = "x";
            Std.ConstrainAlwaysReal(x);
            Signal x2 = StdBuilder.Square(x); x2.Label = "x2";
            Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2";
            Signal sinx2t2 = sinx2 * IntegerValue.ConstantTwo;
            s1.AddSignalTree(sinx2t2, true, true);

            // EVALUATE SYSTEM 1 FOR x=1.5
            x.PostNewValue(new RealValue(1.5));
            p.SimulateInstant();
            Assert.AreEqual(0, s1.BusCount, "A0");
            Assert.AreEqual(5, s1.SignalCount, "A1");
            Assert.AreEqual(3, s1.PortCount, "A2");
            Assert.AreEqual("Std.Real(1.55614639377584)", sinx2t2.Value.ToString(), "A3");

            // SERIALIZE SYSTEM 1 TO XML
            /*
             * HINT: would be simpler to just call:
             * string s2xml = s1.WriteXml(false);
             */
            StringBuilder sb = new StringBuilder();
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.ConformanceLevel = ConformanceLevel.Document;
                settings.OmitXmlDeclaration = false;
                settings.Indent = true;
                settings.NewLineHandling = NewLineHandling.Entitize;
                settings.Encoding = Config.InternalEncoding;
                XmlWriter xwriter = XmlWriter.Create(sb, settings);
                xwriter.WriteStartElement("Systems");
                XmlSystemWriter writer = new XmlSystemWriter(xwriter);
                SystemReader reader = new SystemReader(writer);
                reader.ReadSystem(s1);
                xwriter.WriteEndElement();
                xwriter.Flush();
                xwriter.Close();
            }
            string s2xml = sb.ToString();
            Console.WriteLine(s2xml);

            // READER XML BACK TO SYSTEM 2
            /*
             * HINT: would be simpler to just call:
             * MathSystem s2 = MathSystem.ReadXml(s2xml, c);
             */
            IMathSystem s2;
            {
                StringReader sr = new StringReader(s2xml);
                XmlReader xreader = XmlReader.Create(sr);
                xreader.ReadToFollowing("Systems");
                xreader.Read();
                SystemWriter writer = new SystemWriter();
                XmlSystemReader reader = new XmlSystemReader(writer);
                reader.ReadSystems(xreader, false);
                xreader.ReadEndElement();
                s2 = writer.WrittenSystems.Dequeue();
            }

            Assert.AreEqual(0, s2.BusCount, "B0");
            Assert.AreEqual(5, s2.SignalCount, "B1");
            Assert.AreEqual(3, s2.PortCount, "B2");
            Assert.AreEqual("Std.Real(1.55614639377584)", s2.GetOutput(0).Value.ToString(), "B3");

            // EVALUATE SYSTEM 2 FOR x=2.5
            s2.GetInput(0).PostNewValue(new RealValue(2.5));
            p.SimulateInstant();
            Assert.AreEqual("Std.Real(-0.0663584330951136)", s2.GetOutput(0).Value.ToString(), "C0"); //-0.0331792165475568
        }
예제 #20
0
 public void Initialize()
 {
     _project = new Project();
 }
예제 #21
0
 public void Cleanup()
 {
     _project = null;
 }
        public void SerializeFilledCustomDataList()
        {
            Project p = new Project();
            Dictionary<Guid, Guid> emptyMappings = new Dictionary<Guid, Guid>();
            Dictionary<Guid, Signal> signals = new Dictionary<Guid, Signal>();
            Dictionary<Guid, Bus> buses = new Dictionary<Guid, Bus>();

            LiteralValue lv = new LiteralValue("test");
            IntegerValue iv = new IntegerValue(42);
            ComplexValue cv = new ComplexValue(Constants.Pi, Constants.E);
            RealValue rv = new RealValue(Constants.TwoInvSqrtPi);

            List<IValueStructure> values = new List<IValueStructure>();
            values.Add(lv);
            values.Add(iv);
            values.Add(cv);
            values.Add(rv);

            string xml = Serializer.SerializeListToString(values, emptyMappings, emptyMappings, "Structures");

            List<IValueStructure> ret = Serializer.DeserializeListFromString<IValueStructure>(xml, signals, buses, "Structures");

            Assert.AreEqual(4, ret.Count, "A");
            Assert.AreEqual(values[0].TypeId, ret[0].TypeId, "B1");
            Assert.AreEqual(values[1].TypeId, ret[1].TypeId, "B2");
            Assert.AreEqual(values[2].TypeId, ret[2].TypeId, "B3");
            Assert.AreEqual(values[3].TypeId, ret[3].TypeId, "B4");
            Assert.AreEqual(values[0].ToString(), ret[0].ToString(), "C1");
            Assert.AreEqual(values[1].ToString(), ret[1].ToString(), "C2");
            Assert.AreEqual(values[2].ToString(), ret[2].ToString(), "C3");
            Assert.AreEqual(values[3].ToString(), ret[3].ToString(), "C4");
        }
예제 #23
0
 public void Cleanup()
 {
     this.project = null;
 }
예제 #24
0
 protected ControllerBase(Context context)
 {
     _project = new Project(context);
 }