diff --git a/Backup/Yttrium.sln b/Backup/Yttrium.sln new file mode 100644 index 0000000..dc6a84b --- /dev/null +++ b/Backup/Yttrium.sln @@ -0,0 +1,335 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium", "src\app\MathNet.Yttrium\Library\Yttrium.csproj", "{CAB86B17-68FA-4081-B687-DB71B74BAF79}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Test", "src\test\MathNet.Yttrium.Test\Yttrium.Test.csproj", "{C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Contracts", "src\app\MathNet.Yttrium\Contracts\Yttrium.Contracts.csproj", "{8966E2C5-B1C9-44BE-8751-45DCCA3D268F}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Microkernel", "src\app\MathNet.Yttrium\Microkernel\Yttrium.Microkernel.csproj", "{D03B156A-D6F3-4F46-AC59-7156681F69B7}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Interpreter.Contracts", "src\app\MathNet.Yttrium\Interpreter.Contracts\Yttrium.Interpreter.Contracts.csproj", "{3A0BF5B0-653C-40BD-8046-ED614D95D3D6}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.Standard", "src\app\MathNet.Yttrium\Packages.Standard\Yttrium.Packages.Standard.csproj", "{7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Contracts", "src\app\MathNet.Yttrium\Conversion.Contracts\Yttrium.Conversion.Contracts.csproj", "{FACEF94F-CB8B-45FA-8664-3B9F043C27E9}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.Helper", "src\app\MathNet.Yttrium\Packages.Helper\Yttrium.Packages.Helper.csproj", "{F1B95DE1-5170-4C65-92A4-CFE69256D6E1}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Library.Contracts", "src\app\MathNet.Yttrium\Library.Contracts\Yttrium.Library.Contracts.csproj", "{70E79678-387A-4AF6-8F64-4271CFE914BE}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Traversing.Contracts", "src\app\MathNet.Yttrium\Traversing.Contracts\Yttrium.Traversing.Contracts.csproj", "{191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Manipulation.Contracts", "src\app\MathNet.Yttrium\Manipulation.Contracts\Yttrium.Manipulation.Contracts.csproj", "{B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Patterns.Toolkit", "src\app\MathNet.Yttrium\Patterns.Toolkit\Yttrium.Patterns.Toolkit.csproj", "{6AAA89AE-90D5-496B-9EBD-5274C662C147}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.SystemBuilder.Toolkit", "src\app\MathNet.Yttrium\SystemBuilder.Toolkit\Yttrium.SystemBuilder.Toolkit.csproj", "{8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Manipulation.Service", "src\app\MathNet.Yttrium\Manipulation.Service\Yttrium.Manipulation.Service.csproj", "{4927027C-5A8B-41ED-B680-84C656A98031}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Traversing.Service", "src\app\MathNet.Yttrium\Traversing.Service\Yttrium.Traversing.Service.csproj", "{90E6DB8F-7BFD-4DB3-B705-468769B718E8}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Library.Service", "src\app\MathNet.Yttrium\Library.Service\Yttrium.Library.Service.csproj", "{C1280263-2D0B-4D42-909D-B750FB52D873}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Builder.Service", "src\app\MathNet.Yttrium\Builder.Service\Yttrium.Builder.Service.csproj", "{55E44945-2BB3-4BDB-8E2D-934C334D73ED}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Service", "src\app\MathNet.Yttrium\Conversion.Service\Yttrium.Conversion.Service.csproj", "{3B927CA1-FD05-4DC0-A065-A45B2B2730EC}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Interpreter.Service", "src\app\MathNet.Yttrium\Interpreter.Service\Yttrium.Interpreter.Service.csproj", "{66210C43-A4BD-4B01-A862-BC5EE789CC6E}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Repository.Contracts", "src\app\MathNet.Yttrium\Repository.Contracts\Yttrium.Repository.Contracts.csproj", "{FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Repository.Service", "src\app\MathNet.Yttrium\Repository.Service\Yttrium.Repository.Service.csproj", "{36E41B54-4992-40AF-ABF9-5F0EE34B8B32}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Toolkit", "src\app\MathNet.Yttrium\Conversion.Toolkit\Yttrium.Conversion.Toolkit.csproj", "{8CD3403D-22BF-4BBD-9F8E-36F0F0201351}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Simulation.Contracts", "src\app\MathNet.Yttrium\Simulation.Contracts\Yttrium.Simulation.Contracts.csproj", "{CFE74A4D-51A2-432C-966A-E29773C55D45}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Simulation.Service", "src\app\MathNet.Yttrium\Simulation.Service\Yttrium.Simulation.Service.csproj", "{A214B5AE-5823-4E97-9809-39CB5FC1C1F2}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Contracts", "src\app\MathNet.Yttrium\Mediator.Contracts\Yttrium.Mediator.Contracts.csproj", "{E623ED40-9B92-40CA-9080-0FC78F668FFE}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Service", "src\app\MathNet.Yttrium\Mediator.Service\Yttrium.Mediator.Service.csproj", "{5ADA1A0C-25A8-4B09-8956-AF0C94575D22}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.PetriNet", "src\app\MathNet.Yttrium\Packages\Yttrium.Packages.PetriNet\Yttrium.Packages.PetriNet.csproj", "{5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Toolkit", "src\app\MathNet.Yttrium\Mediator.Toolkit\Yttrium.Mediator.Toolkit.csproj", "{334D8A1D-1004-4097-ACEE-8B954F911EB2}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Fundament", "src\app\MathNet.Yttrium\Fundament\Yttrium.Fundament.csproj", "{FDD51A32-1C78-4135-A6E8-222B022A01C6}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Formatter.Contracts", "src\app\MathNet.Yttrium\Formatter.Contracts\Yttrium.Formatter.Contracts.csproj", "{92C1E300-20D2-4195-AB4C-1402A9152E25}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Formatter.Service", "src\app\MathNet.Yttrium\Formatter.Service\Yttrium.Formatter.Service.csproj", "{36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Release|Any CPU.Build.0 = Release|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Release|Any CPU.Build.0 = Release|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Release|Any CPU.Build.0 = Release|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Release|Any CPU.Build.0 = Release|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Release|Any CPU.Build.0 = Release|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Release|Any CPU.Build.0 = Release|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Release|Any CPU.Build.0 = Release|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Release|Any CPU.Build.0 = Release|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Release|Any CPU.Build.0 = Release|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Release|Any CPU.Build.0 = Release|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Release|Any CPU.Build.0 = Release|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Release|Any CPU.Build.0 = Release|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Release|Any CPU.Build.0 = Release|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Release|Any CPU.Build.0 = Release|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Release|Any CPU.Build.0 = Release|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Release|Any CPU.Build.0 = Release|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Release|Any CPU.Build.0 = Release|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Release|Any CPU.Build.0 = Release|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Release|Any CPU.Build.0 = Release|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Release|Any CPU.Build.0 = Release|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Release|Any CPU.Build.0 = Release|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Release|Any CPU.Build.0 = Release|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Release|Any CPU.Build.0 = Release|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Release|Any CPU.Build.0 = Release|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Release|Any CPU.Build.0 = Release|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Release|Any CPU.Build.0 = Release|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Release|Any CPU.Build.0 = Release|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Release|Any CPU.Build.0 = Release|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Release|Any CPU.Build.0 = Release|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Release|Any CPU.Build.0 = Release|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} = {F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D} + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} = {F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D} + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD} = {F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D} + EndGlobalSection +EndGlobal diff --git a/Backup/src/app/MathNet.Yttrium/Builder.Service/Builder/Builder.cs b/Backup/src/app/MathNet.Yttrium/Builder.Service/Builder/Builder.cs new file mode 100644 index 0000000..2d3465a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Builder.Service/Builder/Builder.cs @@ -0,0 +1,291 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Builder +{ + public class Builder : IBuilder + { + private readonly ILibrary _library; + + internal Builder() + { + _library = Service.Instance; + } + + #region Building Single-Value Functions + public Signal Function(IEntity entity, Signal argument) + { + Port port = entity.InstantiatePort(argument); + + if(port.InputSignalCount != 1 || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException("1 input and 1 output", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input and " + port.OutputSignalCount.ToString(Config.InternalNumberFormat) + " output"); + + return port[0]; + } + public Signal Function(IEntity entity, Signal argument1, Signal argument2) + { + Port port = entity.InstantiatePort(argument1, argument2); + + if(port.InputSignalCount != 2 || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException("2 input and 1 output", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input and " + port.OutputSignalCount.ToString(Config.InternalNumberFormat) + " output"); + + return port[0]; + } + public Signal Function(IEntity entity, params Signal[] arguments) + { + Port port = entity.InstantiatePort(arguments); + + if(port.InputSignalCount != arguments.Length || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException(arguments.Length.ToString(Config.InternalNumberFormat) + " input and 1 output", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input and " + port.OutputSignalCount.ToString(Config.InternalNumberFormat) + " output"); + + return port[0]; + } + public Signal Function(IEntity entity, IList arguments) + { + Port port = entity.InstantiatePort(arguments); + + if(port.InputSignalCount != arguments.Count || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException(arguments.Count.ToString(Config.InternalNumberFormat) + " input and 1 output", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input and " + port.OutputSignalCount.ToString(Config.InternalNumberFormat) + " output"); + + return port[0]; + } + + public Signal Function(string symbol, Signal argument) + { + return Function(_library.LookupEntity(symbol, 1, 1, 0), argument); + } + public Signal Function(string symbol, Signal argument1, Signal argument2) + { + return Function(_library.LookupEntity(symbol, 2, 1, 0), argument1, argument2); + } + public Signal Function(string symbol, params Signal[] arguments) + { + if(arguments == null) + throw new ArgumentNullException("arguments"); + + return Function(_library.LookupEntity(symbol, arguments.Length, 1, 0), arguments); + } + public Signal Function(string symbol, IList arguments) + { + if(arguments == null) + throw new ArgumentNullException("arguments"); + + return Function(_library.LookupEntity(symbol, arguments.Count, 1, 0), arguments); + } + + public Signal Function(string symbol, InfixNotation notation, Signal argument) + { + return Function(_library.LookupEntity(symbol, notation, 1, 1, 0), argument); + } + public Signal Function(string symbol, InfixNotation notation, Signal argument1, Signal argument2) + { + return Function(_library.LookupEntity(symbol, notation, 2, 1, 0), argument1, argument2); + } + public Signal Function(string symbol, InfixNotation notation, params Signal[] arguments) + { + if(arguments == null) + throw new ArgumentNullException("arguments"); + + return Function(_library.LookupEntity(symbol, notation, arguments.Length, 1, 0), arguments); + } + public Signal Function(string symbol, InfixNotation notation, IList arguments) + { + if(arguments == null) + throw new ArgumentNullException("arguments"); + + return Function(_library.LookupEntity(symbol, notation, arguments.Count, 1, 0), arguments); + } + + public Signal Function(MathIdentifier entityId, Signal argument) + { + return Function(_library.LookupEntity(entityId), argument); + } + public Signal Function(MathIdentifier entityId, Signal argument1, Signal argument2) + { + return Function(_library.LookupEntity(entityId), argument1, argument2); + } + public Signal Function(MathIdentifier entityId, params Signal[] arguments) + { + return Function(_library.LookupEntity(entityId), arguments); + } + public Signal Function(MathIdentifier entityId, IList arguments) + { + return Function(_library.LookupEntity(entityId), arguments); + } + #endregion + + #region Building Multiple-Value Functions + public ReadOnlySignalSet Functions(IEntity entity, Signal argument) + { + Port port = entity.InstantiatePort(argument); + + if(port.InputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException("1 input", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input"); + + return port.OutputSignals; + } + public ReadOnlySignalSet Functions(IEntity entity, Signal argument1, Signal argument2) + { + Port port = entity.InstantiatePort(argument1, argument2); + + if(port.InputSignalCount != 2 || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException("2 input", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input"); + + return port.OutputSignals; + } + public ReadOnlySignalSet Functions(IEntity entity, params Signal[] arguments) + { + Port port = entity.InstantiatePort(arguments); + + if(port.InputSignalCount != arguments.Length || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException(arguments.Length.ToString(Config.InternalNumberFormat) + " input", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input"); + + return port.OutputSignals; + } + public ReadOnlySignalSet Functions(IEntity entity, IList arguments) + { + Port port = entity.InstantiatePort(arguments); + + if(port.InputSignalCount != arguments.Count || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException(arguments.Count.ToString(Config.InternalNumberFormat) + " input", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input"); + + return port.OutputSignals; + } + + public ReadOnlySignalSet Functions(string symbol, Signal argument) + { + return Functions(_library.LookupEntity(symbol, 1, 1, 0), argument); + } + public ReadOnlySignalSet Functions(string symbol, Signal argument1, Signal argument2) + { + return Functions(_library.LookupEntity(symbol, 2, 1, 0), argument1, argument2); + } + public ReadOnlySignalSet Functions(string symbol, params Signal[] arguments) + { + return Functions(_library.LookupEntity(symbol, arguments.Length, 1, 0), arguments); + } + public ReadOnlySignalSet Functions(string symbol, IList arguments) + { + return Functions(_library.LookupEntity(symbol, arguments.Count, 1, 0), arguments); + } + + public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, Signal argument) + { + return Functions(_library.LookupEntity(symbol, notation, 1, 1, 0), argument); + } + public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, Signal argument1, Signal argument2) + { + return Functions(_library.LookupEntity(symbol, notation, 2, 1, 0), argument1, argument2); + } + public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, params Signal[] arguments) + { + return Functions(_library.LookupEntity(symbol, notation, arguments.Length, 1, 0), arguments); + } + public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, IList arguments) + { + return Functions(_library.LookupEntity(symbol, notation, arguments.Count, 1, 0), arguments); + } + + public ReadOnlySignalSet Functions(MathIdentifier entityId, Signal argument) + { + return Functions(_library.LookupEntity(entityId), argument); + } + public ReadOnlySignalSet Functions(MathIdentifier entityId, Signal argument1, Signal argument2) + { + return Functions(_library.LookupEntity(entityId), argument1, argument2); + } + public ReadOnlySignalSet Functions(MathIdentifier entityId, params Signal[] arguments) + { + return Functions(_library.LookupEntity(entityId), arguments); + } + public ReadOnlySignalSet Functions(MathIdentifier entityId, IList arguments) + { + return Functions(_library.LookupEntity(entityId), arguments); + } + #endregion + + #region Basic Encapsulation Multiplexing + public Signal EncapsulateAsVector(params Signal[] inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsVector(IList inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsList(params Signal[] inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsList(IList inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsSet(params Signal[] inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsSet(IList inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsScalar(params Signal[] inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + public Signal EncapsulateAsScalar(IList inner) + { + throw new NotImplementedException(MathNet.Symbolics.Properties.Resources.ex_NotImplementedYet); + } + #endregion + + #region Basic Signal Manipulation + public Port MapSignals(Signal source, Signal target) + { + Port port = _library.LookupEntity(new MathIdentifier("Transport", "Std")).InstantiatePort(new Signal[] { source }, new Signal[] { target }); + + if(port.InputSignalCount != 1 || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException("1 input and 1 output", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input and " + port.OutputSignalCount.ToString(Config.InternalNumberFormat) + " output"); + return port; + } + public Port MapSignalsSynchronized(Signal source, Signal target, Signal clock) + { + Port port = _library.LookupEntity(new MathIdentifier("Sync", "Std")).InstantiatePort(new Signal[] { source, clock }, new Signal[] { target }); + + if(port.InputSignalCount != 2 || port.OutputSignalCount != 1) + throw new MathNet.Symbolics.Exceptions.EntitySignalCountUnexpectedException("2 input and 1 output", port.InputSignalCount.ToString(Config.InternalNumberFormat) + " input and " + port.OutputSignalCount.ToString(Config.InternalNumberFormat) + " output"); + + return port; + } + public Signal Synchronize(Signal signal, Signal clock) + { + return Function(new MathIdentifier("Sync", "Std"), signal, clock); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Builder.Service/BuilderFactory.cs b/Backup/src/app/MathNet.Yttrium/Builder.Service/BuilderFactory.cs new file mode 100644 index 0000000..c6d23cb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Builder.Service/BuilderFactory.cs @@ -0,0 +1,35 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + internal class BuilderFactory : IFactory + { + IBuilder IFactory.GetInstance() + { + return new Builder.Builder(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c1a82f9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Library")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("a56c26f4-8a54-4cf1-b6a2-8476c542263c")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs b/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs new file mode 100644 index 0000000..5b3c3f3 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to A requested feature is not yet implemented.. + /// + internal static string ex_NotImplementedYet { + get { + return ResourceManager.GetString("ex_NotImplementedYet", resourceCulture); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.resx b/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.resx new file mode 100644 index 0000000..757a81f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + A requested feature is not yet implemented. + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj b/Backup/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj new file mode 100644 index 0000000..c1adbbf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj @@ -0,0 +1,90 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {55E44945-2BB3-4BDB-8E2D-934C334D73ED} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Builder.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + Resources.resx + True + True + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Yttrium.Packages.Helper + + + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} + Yttrium.Packages.Standard + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Bus.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Bus.cs new file mode 100644 index 0000000..9cc4ac7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Bus.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public abstract class Bus : ValueNode, IEquatable + { + protected Bus() + : base() + { + } + + protected Bus(IValueStructure initialValue) + : base(initialValue) + { + } + + public bool Equals(Bus other) + { + return base.Equals((Node)other); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/BusSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/BusSet.cs new file mode 100644 index 0000000..1920656 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/BusSet.cs @@ -0,0 +1,118 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public class BusSet : Set, IBusSet + { + public BusSet() : base() { } + public BusSet(IEnumerable initial) : base(initial) { } + public BusSet(params Bus[] initial) : base(initial) { } + protected BusSet(IList innerList) : base(innerList) { } + public BusSet(int initialCount) : base(initialCount) { } + + public static BusSet ConvertFrom(Set set) + { + BusSet ss = set as BusSet; + if(ss == null) + return new BusSet((IList)set); + else + return ss; + } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new BusSet(); + } + protected override ReadOnlySet CreateNewReadOnlyWrapper(IList list) + { + return new ReadOnlyBusSet(list); + } + #endregion + + public new ReadOnlyBusSet AsReadOnly + { // works thanks to the Factory Method pattern/trick + get { return (ReadOnlyBusSet)base.AsReadOnly; } + } + + #region InstanceId Conversion + public InstanceIdSet ConvertAllToInstanceIds() + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Bus b in this) + ids.Add(b.InstanceId); + return ids; + } + public InstanceIdSet ConvertAllToInstanceIds(Converter convert) + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Bus b in this) + ids.Add(convert(b)); + return ids; + } + public static BusSet ConvertAllFromInstanceIds(InstanceIdSet idSet, Converter convert) + { + BusSet bs = new BusSet(); + foreach(Guid id in idSet) + bs.Add(convert(id)); + return bs; + } + #endregion + } + + public class ReadOnlyBusSet : ReadOnlySet, IBusSet + { + public ReadOnlyBusSet(IList list) : base(list) { } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new BusSet(); + } + #endregion + + #region InstanceId Conversion + public InstanceIdSet ConvertAllToInstanceIds() + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Bus b in this) + ids.Add(b.InstanceId); + return ids; + } + public InstanceIdSet ConvertAllToInstanceIds(Converter convert) + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Bus b in this) + ids.Add(convert(b)); + return ids; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IBusSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IBusSet.cs new file mode 100644 index 0000000..27d9da3 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IBusSet.cs @@ -0,0 +1,33 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public interface IBusSet : ISet + { + InstanceIdSet ConvertAllToInstanceIds(Converter convert); + InstanceIdSet ConvertAllToInstanceIds(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IInstanceIdSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IInstanceIdSet.cs new file mode 100644 index 0000000..c20e1cc --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IInstanceIdSet.cs @@ -0,0 +1,31 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public interface IInstanceIdSet : ISet + { + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IPortSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IPortSet.cs new file mode 100644 index 0000000..9794cfd --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/IPortSet.cs @@ -0,0 +1,33 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public interface IPortSet : ISet + { + InstanceIdSet ConvertAllToInstanceIds(Converter convert); + InstanceIdSet ConvertAllToInstanceIds(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs new file mode 100644 index 0000000..436bf36 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public interface ISignalSet : ISet + { + InstanceIdSet ConvertAllToInstanceIds(Converter convert); + InstanceIdSet ConvertAllToInstanceIds(); + void PostNewValues(IEnumerable newValues, IEnumerable delays); + void PostNewValues(IEnumerable newValues, TimeSpan delay); + void PostNewValues(IEnumerable newValues); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/InstanceIdSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/InstanceIdSet.cs new file mode 100644 index 0000000..98c61a1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/InstanceIdSet.cs @@ -0,0 +1,77 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public class InstanceIdSet : Set, IInstanceIdSet + { + public InstanceIdSet() : base() { } + public InstanceIdSet(IEnumerable initial) : base(initial) { } + public InstanceIdSet(params Guid[] initial) : base(initial) { } + protected InstanceIdSet(IList innerList) : base(innerList) { } + public InstanceIdSet(int initialCount) : base(initialCount) { } + + public static InstanceIdSet ConvertFrom(Set set) + { + InstanceIdSet ss = set as InstanceIdSet; + if(ss == null) + return new InstanceIdSet((IList)set); + else + return ss; + } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new InstanceIdSet(); + } + protected override ReadOnlySet CreateNewReadOnlyWrapper(IList list) + { + return new ReadOnlyInstanceIdSet(list); + } + #endregion + + public new ReadOnlyInstanceIdSet AsReadOnly + { // works thanks to the Factory Method pattern/trick + get { return (ReadOnlyInstanceIdSet)base.AsReadOnly; } + } + } + + public class ReadOnlyInstanceIdSet : ReadOnlySet, IInstanceIdSet + { + public ReadOnlyInstanceIdSet(IList list) : base(list) { } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new InstanceIdSet(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/PortSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/PortSet.cs new file mode 100644 index 0000000..cc60c57 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/PortSet.cs @@ -0,0 +1,118 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public class PortSet : Set, IPortSet + { + public PortSet() : base() { } + public PortSet(IEnumerable initial) : base(initial) { } + public PortSet(params Port[] initial) : base(initial) { } + protected PortSet(IList innerList) : base(innerList) { } + public PortSet(int initialCount) : base(initialCount) { } + + public static PortSet ConvertFrom(Set set) + { + PortSet ps = set as PortSet; + if(ps == null) + return new PortSet((IList)set); + else + return ps; + } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new PortSet(); + } + protected override ReadOnlySet CreateNewReadOnlyWrapper(IList list) + { + return new ReadOnlyPortSet(list); + } + #endregion + + public new ReadOnlyPortSet AsReadOnly + { // works thanks to the Factory Method pattern/trick + get { return (ReadOnlyPortSet)base.AsReadOnly; } + } + + #region InstanceId Conversion + public InstanceIdSet ConvertAllToInstanceIds() + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Port p in this) + ids.Add(p.InstanceId); + return ids; + } + public InstanceIdSet ConvertAllToInstanceIds(Converter convert) + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Port p in this) + ids.Add(convert(p)); + return ids; + } + public static PortSet ConvertAllFromInstanceIds(InstanceIdSet idSet, Converter convert) + { + PortSet ps = new PortSet(); + foreach(Guid id in idSet) + ps.Add(convert(id)); + return ps; + } + #endregion + } + + public class ReadOnlyPortSet : ReadOnlySet, IPortSet + { + public ReadOnlyPortSet(IList list) : base(list) { } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new PortSet(); + } + #endregion + + #region InstanceId Conversion + public InstanceIdSet ConvertAllToInstanceIds() + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Port p in this) + ids.Add(p.InstanceId); + return ids; + } + public InstanceIdSet ConvertAllToInstanceIds(Converter convert) + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Port p in this) + ids.Add(convert(p)); + return ids; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Containers/SignalSet.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/SignalSet.cs new file mode 100644 index 0000000..b799657 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Containers/SignalSet.cs @@ -0,0 +1,168 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Numerics; + +namespace MathNet.Symbolics.Backend.Containers +{ + public class SignalSet : Set, ISignalSet + { + public SignalSet() : base() { } + public SignalSet(IEnumerable initial) : base(initial) { } + public SignalSet(params Signal[] initial) : base(initial) { } + protected SignalSet(IList innerList) : base(innerList) { } + public SignalSet(int initialCount) : base(initialCount) { } + + public static SignalSet ConvertFrom(Set set) + { + SignalSet ss = set as SignalSet; + if(ss == null) + return new SignalSet((IList)set); + else + return ss; + } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new SignalSet(); + } + protected override ReadOnlySet CreateNewReadOnlyWrapper(IList list) + { + return new ReadOnlySignalSet(list); + } + #endregion + + public new ReadOnlySignalSet AsReadOnly + { // works thanks to the Factory Method pattern/trick + get { return (ReadOnlySignalSet)base.AsReadOnly; } + } + + #region InstanceId Conversion + public InstanceIdSet ConvertAllToInstanceIds() + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Signal s in this) + ids.Add(s.InstanceId); + return ids; + } + public InstanceIdSet ConvertAllToInstanceIds(Converter convert) + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Signal s in this) + ids.Add(convert(s)); + return ids; + } + public static SignalSet ConvertAllFromInstanceIds(InstanceIdSet idSet, Converter convert) + { + SignalSet ss = new SignalSet(); + foreach(Guid id in idSet) + ss.Add(convert(id)); + return ss; + } + #endregion + + public void PostNewValues(IEnumerable newValues) + { + int idx = 0; + foreach(IValueStructure value in newValues) + base[idx++].PostNewValue(value); + } + + public void PostNewValues(IEnumerable newValues, TimeSpan delay) + { + int idx = 0; + foreach(IValueStructure value in newValues) + base[idx++].PostNewValue(value,delay); + } + + public void PostNewValues(IEnumerable newValues, IEnumerable delays) + { + int idx = 0; + IEnumerator delayEnumerator = delays.GetEnumerator(); + foreach(IValueStructure value in newValues) + { + delayEnumerator.MoveNext(); + base[idx++].PostNewValue(value, delayEnumerator.Current); + } + } + } + + public class ReadOnlySignalSet : ReadOnlySet, ISignalSet + { + public ReadOnlySignalSet(IList list) : base(list) { } + + #region Factory Methods + protected override Set CreateNewSet() + { + return new SignalSet(); + } + #endregion + + #region InstanceId Conversion + public InstanceIdSet ConvertAllToInstanceIds() + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Signal s in this) + ids.Add(s.InstanceId); + return ids; + } + public InstanceIdSet ConvertAllToInstanceIds(Converter convert) + { + InstanceIdSet ids = new InstanceIdSet(); + foreach(Signal s in this) + ids.Add(convert(s)); + return ids; + } + #endregion + + public void PostNewValues(IEnumerable newValues) + { + int idx = 0; + foreach(IValueStructure value in newValues) + base[idx++].PostNewValue(value); + } + + public void PostNewValues(IEnumerable newValues, TimeSpan delay) + { + int idx = 0; + foreach(IValueStructure value in newValues) + base[idx++].PostNewValue(value, delay); + } + + public void PostNewValues(IEnumerable newValues, IEnumerable delays) + { + int idx = 0; + IEnumerator delayEnumerator = delays.GetEnumerator(); + foreach(IValueStructure value in newValues) + { + delayEnumerator.MoveNext(); + base[idx++].PostNewValue(value, delayEnumerator.Current); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusEventArgs.cs new file mode 100644 index 0000000..e007052 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusEventArgs.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class BusEventArgs : EventArgs + { + public BusEventArgs(Bus bus) + { + this.bus = bus; + } + + private readonly Bus bus; + public Bus Bus { get { return bus; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusIndexChangedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusIndexChangedEventArgs.cs new file mode 100644 index 0000000..7c3ff78 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusIndexChangedEventArgs.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class BusIndexChangedEventArgs : EventArgs + { + public BusIndexChangedEventArgs(Bus bus, int indexBefore, int indexAfter) + { + this.bus = bus; + this.indexBefore = indexBefore; + this.indexAfter = indexAfter; + } + + private readonly Bus bus; + public Bus Bus { get { return bus; } } + + private readonly int indexBefore; + public int IndexBefore { get { return indexBefore; } } + + private readonly int indexAfter; + public int IndexAfter { get { return indexAfter; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusIndexEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusIndexEventArgs.cs new file mode 100644 index 0000000..1fa4c67 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusIndexEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class BusIndexEventArgs : EventArgs + { + public BusIndexEventArgs(Bus bus, int index) + { + this.bus = bus; + this.index = index; + } + + private readonly Bus bus; + public Bus Bus { get { return bus; } } + + private readonly int index; + public int Index { get { return index; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusPortIndexEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusPortIndexEventArgs.cs new file mode 100644 index 0000000..1c569b8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/BusPortIndexEventArgs.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class BusPortIndexEventArgs : EventArgs + { + public BusPortIndexEventArgs(Bus bus, Port port, int index) + { + this.bus = bus; + this.port = port; + this.index = index; + } + + private readonly Bus bus; + public Bus Bus { get { return bus; } } + + private readonly Port port; + public Port Port { get { return port; } } + + private readonly int index; + public int Index { get { return index; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/IndexedSignalEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/IndexedSignalEventArgs.cs new file mode 100644 index 0000000..e3450f7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/IndexedSignalEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class IndexedSignalEventArgs : EventArgs + { + public IndexedSignalEventArgs(Signal signal, int index) + { + this.signal = signal; + this.index = index; + } + + private readonly Signal signal; + public Signal Signal { get { return signal; } } + + private readonly int index; + public int Index { get { return index; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodeFlagChangedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodeFlagChangedEventArgs.cs new file mode 100644 index 0000000..1c3491b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodeFlagChangedEventArgs.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class NodeFlagChangedEventArgs : EventArgs + { + private readonly FlagState _oldState; + private readonly FlagState _newState; + private readonly Node _node; + private readonly NodeFlag _flag; + + public NodeFlagChangedEventArgs(Node node, NodeFlag flag, FlagState oldState, FlagState newState) + { + _node = node; + _flag = flag; + _oldState = oldState; + _newState = newState; + } + + public Node Node + { + get { return _node; } + } + + public NodeFlag Flag + { + get { return _flag; } + } + + public object OldState + { + get { return _oldState; } + } + + public object NewState + { + get { return _newState; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodeFlagDirtiedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodeFlagDirtiedEventArgs.cs new file mode 100644 index 0000000..db2ec79 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodeFlagDirtiedEventArgs.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class NodeFlagDirtiedEventArgs : EventArgs + { + private readonly Node _node; + private readonly NodeFlag _flag; + + public NodeFlagDirtiedEventArgs(Node node, NodeFlag flag) + { + _node = node; + _flag = flag; + } + + public Node Node + { + get { return _node; } + } + + public NodeFlag Flag + { + get { return _flag; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodePropertyChangedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodePropertyChangedEventArgs.cs new file mode 100644 index 0000000..f0d0884 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodePropertyChangedEventArgs.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class NodePropertyChangedEventArgs : EventArgs + { + private readonly object _oldValue; + private readonly object _newValue; + private readonly Node _node; + private readonly NodeProperty _property; + + public NodePropertyChangedEventArgs(Node node, NodeProperty property, object oldValue, object newValue) + { + _node = node; + _property = property; + _oldValue = oldValue; + _newValue = newValue; + } + + public Node Node + { + get { return _node; } + } + + public NodeProperty Property + { + get { return _property; } + } + + public object OldValue + { + get { return _oldValue; } + } + + public object NewValue + { + get { return _newValue; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodePropertyDirtiedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodePropertyDirtiedEventArgs.cs new file mode 100644 index 0000000..85aa7bb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/NodePropertyDirtiedEventArgs.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class NodePropertyDirtiedEventArgs : EventArgs + { + private readonly Node _node; + private readonly NodeProperty _property; + + public NodePropertyDirtiedEventArgs(Node node, NodeProperty property) + { + _node = node; + _property = property; + } + + public Node Node + { + get { return _node; } + } + + public NodeProperty Property + { + get { return _property; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortEventArgs.cs new file mode 100644 index 0000000..5f080b9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortEventArgs.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class PortEventArgs : EventArgs + { + public PortEventArgs(Port port) + { + this.port = port; + } + + private readonly Port port; + public Port Port { get { return port; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortIndexChangedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortIndexChangedEventArgs.cs new file mode 100644 index 0000000..f44b735 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortIndexChangedEventArgs.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class PortIndexChangedEventArgs : EventArgs + { + public PortIndexChangedEventArgs(Port port, int indexBefore, int indexAfter) + { + this.port = port; + this.indexBefore = indexBefore; + this.indexAfter = indexAfter; + } + + private readonly Port port; + public Port Port { get { return port; } } + + private readonly int indexBefore; + public int IndexBefore { get { return indexBefore; } } + + private readonly int indexAfter; + public int IndexAfter { get { return indexAfter; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortIndexEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortIndexEventArgs.cs new file mode 100644 index 0000000..06a5e1a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/PortIndexEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class PortIndexEventArgs : EventArgs + { + public PortIndexEventArgs(Port port, int index) + { + this.port = port; + this.index = index; + } + + private readonly Port port; + public Port Port { get { return port; } } + + private readonly int index; + public int Index { get { return index; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalEventArgs.cs new file mode 100644 index 0000000..d301545 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalEventArgs.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class SignalEventArgs : EventArgs + { + public SignalEventArgs(Signal signal) + { + this.signal = signal; + } + + private readonly Signal signal; + public Signal Signal { get { return signal; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalIndexChangedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalIndexChangedEventArgs.cs new file mode 100644 index 0000000..50f2913 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalIndexChangedEventArgs.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class SignalIndexChangedEventArgs : EventArgs + { + public SignalIndexChangedEventArgs(Signal signal, int indexBefore, int indexAfter) + { + this.signal = signal; + this.indexBefore = indexBefore; + this.indexAfter = indexAfter; + } + + private readonly Signal signal; + public Signal Signal { get { return signal; } } + + private readonly int indexBefore; + public int IndexBefore { get { return indexBefore; } } + + private readonly int indexAfter; + public int IndexAfter { get { return indexAfter; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalIndexEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalIndexEventArgs.cs new file mode 100644 index 0000000..dafc37b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalIndexEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class SignalIndexEventArgs : EventArgs + { + public SignalIndexEventArgs(Signal signal, int index) + { + this.signal = signal; + this.index = index; + } + + private readonly Signal signal; + public Signal Signal { get { return signal; } } + + private readonly int index; + public int Index { get { return index; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalPortEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalPortEventArgs.cs new file mode 100644 index 0000000..967a969 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalPortEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class SignalPortEventArgs : EventArgs + { + public SignalPortEventArgs(Signal signal, Port port) + { + this.signal = signal; + this.port = port; + } + + private readonly Signal signal; + public Signal Signal { get { return signal; } } + + private readonly Port port; + public Port Port { get { return port; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalPortIndexEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalPortIndexEventArgs.cs new file mode 100644 index 0000000..8859cd7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SignalPortIndexEventArgs.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public sealed class SignalPortIndexEventArgs : EventArgs + { + public SignalPortIndexEventArgs(Signal signal, Port port, int index) + { + this.signal = signal; + this.port = port; + this.index = index; + } + + private readonly Signal signal; + public Signal Signal { get { return signal; } } + + private readonly Port port; + public Port Port { get { return port; } } + + private readonly int index; + public int Index { get { return index; } } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/SimulationTimeEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SimulationTimeEventArgs.cs new file mode 100644 index 0000000..71df1f9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/SimulationTimeEventArgs.cs @@ -0,0 +1,40 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Events +{ + public class SimulationTimeEventArgs : EventArgs + { + private readonly TimeSpan _timeSpan; + + public SimulationTimeEventArgs(TimeSpan timeSpan) + { + _timeSpan = timeSpan; + } + + public TimeSpan TimeSpan + { + get { return _timeSpan; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/ValueChangedEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/ValueChangedEventArgs.cs new file mode 100644 index 0000000..0615e9c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/ValueChangedEventArgs.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class ValueChangedEventArgs + : EventArgs + { + private readonly TValue _oldValue; + private readonly TValue _newValue; + private readonly THost _host; + + public ValueChangedEventArgs(THost host, TValue oldValue, TValue newValue) + { + _host = host; + _oldValue = oldValue; + _newValue = newValue; + } + + public THost Host + { + get { return _host; } + } + + public TValue OldValue + { + get { return _oldValue; } + } + + public TValue NewValue + { + get { return _newValue; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Events/ValueNodeEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Events/ValueNodeEventArgs.cs new file mode 100644 index 0000000..ecd9f39 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Events/ValueNodeEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class ValueNodeEventArgs : EventArgs + { + private readonly ValueNode _node; + + public ValueNodeEventArgs(ValueNode node) + { + _node = node; + } + + public ValueNode ValueNode + { + get { return _node; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/ArchitectureNotAvailableException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/ArchitectureNotAvailableException.cs new file mode 100644 index 0000000..8eb1f58 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/ArchitectureNotAvailableException.cs @@ -0,0 +1,74 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; +using MathNet.Symbolics.Properties; +using System.Globalization; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class ArchitectureNotAvailableException : YttriumException + { + Port _port; + + public ArchitectureNotAvailableException() + : base() + { + } + + public ArchitectureNotAvailableException(string message) + : base(message) + { + } + + public ArchitectureNotAvailableException(string message, Exception innerException) + : base(message, innerException) + { + } + + public ArchitectureNotAvailableException(Port port) + : base(string.Format(CultureInfo.CurrentCulture, Resources.ex_NotAvailable_Architecture, (port == null ? "N/A" : port.Entity.ToString()))) + { + _port = port; + } + + protected ArchitectureNotAvailableException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + _port = (Port)info.GetValue("port", typeof(Port)); + } + + public Port Port + { + get { return _port; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter=true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("port", _port, typeof(Port)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/CyclicSignalsNotSupportedException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/CyclicSignalsNotSupportedException.cs new file mode 100644 index 0000000..8bd01b1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/CyclicSignalsNotSupportedException.cs @@ -0,0 +1,74 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; +using System.Globalization; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class CyclicSignalsNotSupportedException : YttriumException + { + Signal _signal; + + public CyclicSignalsNotSupportedException() + : base() + { + } + + public CyclicSignalsNotSupportedException(string message) + : base(message) + { + } + + public CyclicSignalsNotSupportedException(string message, Exception innerException) + : base(message, innerException) + { + } + + + public CyclicSignalsNotSupportedException(Signal signal, string operation) + : base(string.Format(CultureInfo.CurrentCulture, MathNet.Symbolics.Properties.Resources.ex_CyclicSignalsNotSupportes, operation)) + { + _signal = signal; + } + + protected CyclicSignalsNotSupportedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + _signal = (Signal)info.GetValue("signal", typeof(Signal)); + } + + public Signal Signal + { + get { return _signal; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("signal", _signal, typeof(Signal)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/DeserializationException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/DeserializationException.cs new file mode 100644 index 0000000..9522791 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/DeserializationException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class DeserializationException : YttriumException + { + public DeserializationException() + : base() + { + } + + public DeserializationException(string message) + : base(message) + { + } + + public DeserializationException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected DeserializationException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/DomainNotAvailableException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/DomainNotAvailableException.cs new file mode 100644 index 0000000..0e07d2b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/DomainNotAvailableException.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; +using System.Globalization; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class DomainNotAvailableException : YttriumException + { + string domain; + + public DomainNotAvailableException() + : base() + { + } + + public DomainNotAvailableException(string domain) + : base(string.Format(CultureInfo.CurrentCulture, MathNet.Symbolics.Properties.Resources.ex_NotAvailable_Domain, domain)) + { + this.domain = domain; + } + + public DomainNotAvailableException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected DomainNotAvailableException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + domain = info.GetString("domain"); + } + + public string Domain + { + get { return domain; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("domain", domain); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntityNotAvailableException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntityNotAvailableException.cs new file mode 100644 index 0000000..8c85b37 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntityNotAvailableException.cs @@ -0,0 +1,73 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; +using System.Globalization; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class EntityNotAvailableException : YttriumException + { + IEntity _entity; + + public EntityNotAvailableException() + : base() + { + } + + public EntityNotAvailableException(string message) + : base(message) + { + } + + public EntityNotAvailableException(IEntity entity) + : base(string.Format(CultureInfo.CurrentCulture, MathNet.Symbolics.Properties.Resources.ex_NotAvailable_Entity, (entity == null ? "N/A" : entity.ToString()))) + { + _entity = entity; + } + + public EntityNotAvailableException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected EntityNotAvailableException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + _entity = (IEntity)info.GetValue("entity", typeof(IEntity)); + } + + public IEntity Entity + { + get { return _entity; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("entity", _entity, typeof(IEntity)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntitySignalCountUnexpectedException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntitySignalCountUnexpectedException.cs new file mode 100644 index 0000000..7cc7496 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntitySignalCountUnexpectedException.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Globalization; +using MathNet.Symbolics.Properties; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class EntitySignalCountUnexpectedException : YttriumException + { + public EntitySignalCountUnexpectedException() + : base() + { + } + + public EntitySignalCountUnexpectedException(string message) + : base(message) + { + } + + public EntitySignalCountUnexpectedException(string message, Exception innerException) + : base(message, innerException) + { + } + + public EntitySignalCountUnexpectedException(string expected, string got) + : base(string.Format(CultureInfo.CurrentCulture, MathNet.Symbolics.Properties.Resources.ex_Entity_Unexpected_SignalCount, expected, got)) + { + } + + protected EntitySignalCountUnexpectedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntitySignalMismatchException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntitySignalMismatchException.cs new file mode 100644 index 0000000..9289780 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/EntitySignalMismatchException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class EntitySignalMismatchException : YttriumException + { + public EntitySignalMismatchException() + : base() + { + } + + public EntitySignalMismatchException(string message) + : base(message) + { + } + + public EntitySignalMismatchException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected EntitySignalMismatchException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/GenericEntityPortNotInstantiableException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/GenericEntityPortNotInstantiableException.cs new file mode 100644 index 0000000..b17751b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/GenericEntityPortNotInstantiableException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class GenericEntityPortNotInstantiableException : YttriumException + { + public GenericEntityPortNotInstantiableException() + : base() + { + } + + public GenericEntityPortNotInstantiableException(string message) + : base(message) + { + } + + public GenericEntityPortNotInstantiableException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected GenericEntityPortNotInstantiableException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/IncompatibleStructureException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/IncompatibleStructureException.cs new file mode 100644 index 0000000..559e226 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/IncompatibleStructureException.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class IncompatibleStructureException : YttriumException + { + private string domain, label; + + public IncompatibleStructureException() + : base() + { + } + + public IncompatibleStructureException(string message) + : base(message) + { + } + + public IncompatibleStructureException(string message, Exception innerException) + : base(message, innerException) + { + } + + public IncompatibleStructureException(string label, string domain) + : base() + { + this.domain = domain; + this.label = label; + } + + protected IncompatibleStructureException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + domain = info.GetString("domain"); + label = info.GetString("label"); + } + + public string Domain + { + get { return domain; } + } + + public string Label + { + get { return label; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("domain", domain, typeof(string)); + info.AddValue("label", label, typeof(string)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/LabelNotAvailableException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/LabelNotAvailableException.cs new file mode 100644 index 0000000..92307f2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/LabelNotAvailableException.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class LabelNotAvailableException : YttriumException + { + private string domain, label; + + public LabelNotAvailableException() + : base() + { + } + + public LabelNotAvailableException(string message) + : base(message) + { + } + + public LabelNotAvailableException(string message, Exception innerException) + : base(message, innerException) + { + } + + public LabelNotAvailableException(string label, string domain) + : base() + { + this.domain = domain; + this.label = label; + } + + protected LabelNotAvailableException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + domain = info.GetString("domain"); + label = info.GetString("label"); + } + + public string Domain + { + get { return domain; } + } + + public string Label + { + get { return label; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("domain", domain, typeof(string)); + info.AddValue("label", label, typeof(string)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/MutualExclusiveStrategyAlreadyActiveException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/MutualExclusiveStrategyAlreadyActiveException.cs new file mode 100644 index 0000000..96d5e17 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/MutualExclusiveStrategyAlreadyActiveException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class MutualExclusiveStrategyAlreadyActiveException : YttriumException + { + public MutualExclusiveStrategyAlreadyActiveException() + : base(MathNet.Symbolics.Properties.Resources.ex_Traversing_Failed_ReserveMutex) + { + } + + public MutualExclusiveStrategyAlreadyActiveException(string message) + : base(message) + { + } + + public MutualExclusiveStrategyAlreadyActiveException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected MutualExclusiveStrategyAlreadyActiveException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/NotFoundException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/NotFoundException.cs new file mode 100644 index 0000000..4994609 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/NotFoundException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class NotFoundException : YttriumException + { + public NotFoundException() + : base(MathNet.Symbolics.Properties.Resources.ex_NotFound) + { + } + + public NotFoundException(string message) + : base(message) + { + } + + public NotFoundException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected NotFoundException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/StructureNotSupportedException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/StructureNotSupportedException.cs new file mode 100644 index 0000000..1457c70 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/StructureNotSupportedException.cs @@ -0,0 +1,72 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class StructureNotSupportedException : YttriumException + { + IValueStructure structure; + + public StructureNotSupportedException() + : base() + { + } + + public StructureNotSupportedException(string message) + : base(message) + { + } + + public StructureNotSupportedException(string message, Exception innerException) + : base(message, innerException) + { + } + + public StructureNotSupportedException(IValueStructure structure) + : base() + { + this.structure = structure; + } + + protected StructureNotSupportedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + structure = (IValueStructure)info.GetValue("structure", typeof(IValueStructure)); + } + + public IValueStructure Structure + { + get { return structure; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("structure", structure, typeof(IValueStructure)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/SymbolNotAvailableException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/SymbolNotAvailableException.cs new file mode 100644 index 0000000..b4bd8b8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/SymbolNotAvailableException.cs @@ -0,0 +1,67 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class SymbolNotAvailableException : YttriumException + { + private string symbol; + + public SymbolNotAvailableException() + : base() + { + } + + public SymbolNotAvailableException(string message, Exception innerException) + : base(message, innerException) + { + } + + public SymbolNotAvailableException(string symbol) + : base() + { + this.symbol = symbol; + } + + protected SymbolNotAvailableException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + symbol = info.GetString("symbol"); + } + + public string Symbol + { + get { return symbol; } + } + + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("symbol", symbol, typeof(string)); + base.GetObjectData(info, context); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/TheoremMismatchException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/TheoremMismatchException.cs new file mode 100644 index 0000000..c7f013a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/TheoremMismatchException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class TheoremMismatchException : YttriumException + { + public TheoremMismatchException() + : base(MathNet.Symbolics.Properties.Resources.ex_Theorem_Mismatch) + { + } + + public TheoremMismatchException(string message) + : base(message) + { + } + + public TheoremMismatchException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected TheoremMismatchException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/YttriumException.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/YttriumException.cs new file mode 100644 index 0000000..95d3fe7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Exceptions/YttriumException.cs @@ -0,0 +1,50 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class YttriumException : Exception + { + public YttriumException() + : base() + { + } + + public YttriumException(string message) + : base(message) + { + } + + public YttriumException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected YttriumException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IArchitecture.cs new file mode 100644 index 0000000..12b2cd4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IArchitecture.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics +{ + public interface IArchitecture + { + MathIdentifier ArchitectureId { get; } + MathIdentifier EntityId { get; } + + bool IsInstance { get; } + bool IsMathematicalOperator { get; } + + Port Port { get; } + bool SupportsPort(Port port); + bool RebindToPortIfSupported(Port newPort); + + void UnregisterArchitecture(); + + ISignalSet ExecuteMathematicalOperator(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IArchitectureFactory.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IArchitectureFactory.cs new file mode 100644 index 0000000..98ca460 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IArchitectureFactory.cs @@ -0,0 +1,32 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics +{ + public interface IArchitectureFactory + { + MathIdentifier EntityId { get;} + bool SupportsPort(Port port); + IArchitecture InstantiateToPort(Port port); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IBuilder.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IBuilder.cs new file mode 100644 index 0000000..2eb41c4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IBuilder.cs @@ -0,0 +1,87 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics +{ + public interface IBuilder + { + #region Building Single-Value Functions + Signal Function(string symbol, InfixNotation notation, params Signal[] arguments); + Signal Function(IEntity entity, Signal argument); + Signal Function(IEntity entity, Signal argument1, Signal argument2); + Signal Function(MathIdentifier entityId, IList arguments); + Signal Function(string symbol, InfixNotation notation, IList arguments); + Signal Function(MathIdentifier entityId, Signal argument); + Signal Function(MathIdentifier entityId, params Signal[] arguments); + Signal Function(MathIdentifier entityId, Signal argument1, Signal argument2); + Signal Function(string symbol, IList arguments); + Signal Function(string symbol, InfixNotation notation, Signal argument); + Signal Function(string symbol, Signal argument1, Signal argument2); + Signal Function(string symbol, params Signal[] arguments); + Signal Function(string symbol, InfixNotation notation, Signal argument1, Signal argument2); + Signal Function(IEntity entity, params Signal[] arguments); + Signal Function(IEntity entity, IList arguments); + Signal Function(string symbol, Signal argument); + #endregion + + #region Building Multiple-Value Functions + ReadOnlySignalSet Functions(IEntity entity, IList arguments); + ReadOnlySignalSet Functions(string symbol, Signal argument); + ReadOnlySignalSet Functions(string symbol, IList arguments); + ReadOnlySignalSet Functions(string symbol, InfixNotation notation, Signal argument); + ReadOnlySignalSet Functions(string symbol, Signal argument1, Signal argument2); + ReadOnlySignalSet Functions(string symbol, params Signal[] arguments); + ReadOnlySignalSet Functions(IEntity entity, params Signal[] arguments); + ReadOnlySignalSet Functions(MathIdentifier entityId, params Signal[] arguments); + ReadOnlySignalSet Functions(MathIdentifier entityId, Signal argument1, Signal argument2); + ReadOnlySignalSet Functions(MathIdentifier entityId, Signal argument); + ReadOnlySignalSet Functions(IEntity entity, Signal argument1, Signal argument2); + ReadOnlySignalSet Functions(IEntity entity, Signal argument); + ReadOnlySignalSet Functions(MathIdentifier entityId, IList arguments); + ReadOnlySignalSet Functions(string symbol, InfixNotation notation, Signal argument1, Signal argument2); + ReadOnlySignalSet Functions(string symbol, InfixNotation notation, params Signal[] arguments); + ReadOnlySignalSet Functions(string symbol, InfixNotation notation, IList arguments); + #endregion + + #region Basic Encapsulation Multiplex + Signal EncapsulateAsList(IList inner); + Signal EncapsulateAsList(params Signal[] inner); + Signal EncapsulateAsScalar(params Signal[] inner); + Signal EncapsulateAsScalar(IList inner); + Signal EncapsulateAsSet(params Signal[] inner); + Signal EncapsulateAsSet(IList inner); + Signal EncapsulateAsVector(IList inner); + Signal EncapsulateAsVector(params Signal[] inner); + #endregion + + #region Basic Signal Manipulation + Port MapSignals(Signal source, Signal target); + Port MapSignalsSynchronized(Signal source, Signal target, Signal clock); + Signal Synchronize(Signal signal, Signal clock); + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IBus_BuilderAdapter.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IBus_BuilderAdapter.cs new file mode 100644 index 0000000..c181b90 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IBus_BuilderAdapter.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Obsolete] + public interface IBus_BuilderAdapter + { + Guid AcceptSystemBuilderBefore(ISystemBuilder builder); + void AcceptSystemBuilderAfter(ISystemBuilder builder, Dictionary signalMappings, Dictionary busMappings); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ICategory.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ICategory.cs new file mode 100644 index 0000000..15289d0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ICategory.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public enum CategoryMembershipLevel + { + Member, + NotMember, + Unknown + } + + public interface ICategory : ICustomData, IEquatable + { + //MathIdentifier AssociatedPropertyId { get;} + + bool EqualsById(ICategory other); + bool EqualsById(MathIdentifier otherCategoryId); + + CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache); + CategoryMembershipLevel IsMember(Port port); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ICustomData.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ICustomData.cs new file mode 100644 index 0000000..669485c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ICustomData.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +namespace MathNet.Symbolics +{ + /// + /// A user defined object storing data, that support storing references of signals, buses and ports. + /// + /// + /// Any class implementing this interface shall also implement a static deserialization factory: + /// private static YourType Deserialize(XmlReader reader, Dictionary signals, Dictionary buses); + /// + public interface ICustomData + { + MathIdentifier TypeId { get;} + + bool ReferencesCoreObjects { get;} + IEnumerable CollectSignals(); + IEnumerable CollectBuses(); + //IEnumerable CollectPorts(); + + void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings); + //void Deserialize(XmlReader reader, IDictionary signals, IDictionary buses); + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ICustomDataPack.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ICustomDataPack.cs new file mode 100644 index 0000000..b56a06a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ICustomDataPack.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.Serialization; +using System.Xml.Serialization; + +namespace MathNet.Symbolics +{ + public interface ICustomDataPack : ISerializable, IXmlSerializable where T : ICustomData + { + // TODO: Redesign, quite pointless right now as a contract interface - should be hidden or generalized + string SerializedXmlFragment { get;} + T Unpack(IDictionary signals, IDictionary buses); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IEntity.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IEntity.cs new file mode 100644 index 0000000..65f413a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IEntity.cs @@ -0,0 +1,60 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public enum InfixNotation : int + { + None = 0, + LeftAssociativeInnerOperator = 1, + RightAssociativeInnerOperator = 2, + PreOperator = 3, + PostOperator = 4 + } + + public interface IEntity : IEquatable + { + MathIdentifier EntityId { get;} + bool EqualsById(IEntity other); + bool EqualsById(MathIdentifier otherEntityId); + + string Symbol { get; } + InfixNotation Notation { get; } + int PrecedenceGroup { get; } + bool IsGeneric { get; } + + string[] InputSignals { get; } + string[] OutputSignals { get; } + string[] Buses { get; } + + IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCount); + + Port InstantiatePort(IList inputSignals, IList outputSignals); + Port InstantiatePort(IList inputSignals, IList outputSignals, IList buses); + Port InstantiatePort(params Signal[] inputSignals); + Port InstantiatePort(IList inputSignals); + Port InstantiateUnboundPort(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IFactory.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IFactory.cs new file mode 100644 index 0000000..b4da51f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IFactory.cs @@ -0,0 +1,75 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IFactory + { + T GetInstance(); + //T GetInstance(params object[] parameters); + } + + /* + * Note: The following list of factories is quite dumb ("WTF"), + * but it greatly simplifies implementing them (compared + * to the object[] approach where you have to check types + * and cast/convert manually). However, let me know if + * you have a better idea! [maybe I should check out + * dependency injection (-> spring.net etc.) ?] + */ + + public interface IFactory : IFactory + { + T GetInstance(T1 p1); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2, T3 p3); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7); + } + public interface IFactory : IFactory + { + T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IIdentifierDictionary.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IIdentifierDictionary.cs new file mode 100644 index 0000000..ba7600e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IIdentifierDictionary.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +namespace MathNet.Symbolics +{ + public interface IIdentifierDictionary : IEnumerable //, IDictionary + { + void Add(MathIdentifier id, T value); + void Remove(MathIdentifier id); + + bool ContainsKey(MathIdentifier id); + + T GetValue(MathIdentifier id); + bool TryGetValue(MathIdentifier id, out T value); + bool TryGetValue(MathIdentifier id, out TSub value) where TSub : T; + + T FindValue(Predicate match); + bool TryFindValue(Predicate match, out T value); + + IEnumerable SelectAll(); + + + string FindDomainOfLabel(string label); + bool TryFindDomainOfLabel(string label, out string domain); + + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IKeyedCollection.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IKeyedCollection.cs new file mode 100644 index 0000000..7af43a9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IKeyedCollection.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IKeyedCollection : ICollection + { + IEqualityComparer Comparer { get; } + TItem this[TKey key] { get; } + TItem this[int index] { get; } + bool Contains(TKey key); + bool Remove(TKey key); + bool TryGetValue(TKey key, out TItem item); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IMathFunction.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IMathFunction.cs new file mode 100644 index 0000000..046947e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IMathFunction.cs @@ -0,0 +1,31 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IMathFunction + { + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IMathSystem.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IMathSystem.cs new file mode 100644 index 0000000..d943c45 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IMathSystem.cs @@ -0,0 +1,114 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics +{ + public interface IMathSystem + { + event EventHandler OutputValueChanged; + + Guid InstanceId { get;} + + int SignalCount { get;} + int BusCount { get;} + int PortCount { get;} + int InputCount { get;} + int OutputCount { get;} + + bool ContainsSignal(Signal signal); + bool ContainsBus(Bus bus); + bool ContainsPort(Port port); + + Signal GetSignal(int index); + Bus GetBus(int index); + Port GetPort(int index); + Signal GetInput(int index); + Signal GetOutput(int index); + + ReadOnlySignalSet GetAllSignals(); + ReadOnlyBusSet GetAllBuses(); + ReadOnlyPortSet GetAllPorts(); + ReadOnlySignalSet GetAllInputs(); + ReadOnlySignalSet GetAllOutputs(); + ReadOnlySignalSet GetAllLeafSignals(); + + void AddSignal(Signal signal); + void AddSignalRange(IEnumerable signals); + void RemoveSignal(Signal signal, bool isolateFromDriver); + void AddBus(Bus bus); + void AddBusRange(IEnumerable buses); + void RemoveBus(Bus bus); + void AddPort(Port port); + void RemovePort(Port port, bool isolate); + void AddSignalTree(Signal signal, bool setAsOutput, bool autoAddInputs); + void AddSignalTree(Signal signal, ICollection border, bool setAsOutput, bool autoAddInputs); + void AddSignalTreeRange(IEnumerable signals, bool setAsOutput, bool autoAddInputs); + void AddSignalTreeRange(IEnumerable signals, ICollection border, bool setAsOutput, bool autoAddInputs); + void AddPortTree(Port port, bool setAsOutput, bool autoAddInputs); + + int PromoteAsInput(Signal signal); + void UnpromoteAsInput(Signal signal); + int PromoteAsOutput(Signal signal); + void UnpromoteAsOutput(Signal signal); + + Signal CreateNamedSignal(string name); + Signal AddNamedSignal(string name, Signal signal); + Signal AddNamedSignal(string name, IValueStructure value); + Signal LookupNamedSignal(string name); + bool TryLookupNamedSignal(string name, out Signal signal); + bool ContainsNamedSignal(string name); + void RemoveNamedSignal(string name); + + Bus CreateNamedBus(string name); + void AddNamedBus(string name, Bus bus); + Bus LookupNamedBus(string name); + bool TryLookupNamedBus(string name, out Bus bus); + bool ContainsNamedBus(string name); + void RemoveNamedBus(string name); + + void PushInputValue(int inputIndex, IValueStructure value); + void PushInputValue(int inputIndex, IValueStructure value, TimeSpan delay); + void PushInputValueRange(IEnumerable values); + void PushInputValueRange(IEnumerable values, TimeSpan delay); + void PushInputValueRange(IEnumerable signalsWithValues); + void PushInputValueRange(IEnumerable signalsWithValues, TimeSpan delay); + + IValueStructure[] Evaluate(params IValueStructure[] inputs); + double[] Evaluate(params double[] inputs); + + bool RemoveUnusedObjects(); + + void AcceptSystemBuilder(ISystemBuilder builder); + + //bool HasSystemMediator; + //void LoadDefaultSystemMediator(); + + void PublishToLibrary(MathIdentifier architectureId, MathIdentifier entityId); + IEntity PublishToLibrary(string label, string symbol); + IEntity PublishToLibraryAnonymous(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IPort_BuilderAdapter.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IPort_BuilderAdapter.cs new file mode 100644 index 0000000..f048af8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IPort_BuilderAdapter.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Obsolete] + public interface IPort_BuilderAdapter + { + Guid AcceptSystemBuilder(ISystemBuilder builder, Dictionary signalMappings, Dictionary busMappings); + //IInstanceIdSet BuilderMapSignals(ISignalSet signals, Dictionary signalMappings); + //IInstanceIdSet BuilderMapBuses(IBusSet buses, Dictionary busMappings); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IPort_CycleAnalysis.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IPort_CycleAnalysis.cs new file mode 100644 index 0000000..6d6e493 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IPort_CycleAnalysis.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Obsolete] + public interface IPort_CycleAnalysis + { + bool TagWasTagged(int tag); + void DeTag(int tag); + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IProperty.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IProperty.cs new file mode 100644 index 0000000..54aa2b7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IProperty.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IProperty : ICustomData, IEquatable + { + bool EqualsById(IProperty other); + bool EqualsById(MathIdentifier otherPropertyId); + + bool StillValidAfterEvent(Signal signal); + bool StillValidAfterDrive(Signal signal); + bool StillValidAfterUndrive(Signal signal); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_BuilderAdapter.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_BuilderAdapter.cs new file mode 100644 index 0000000..2e7de0a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_BuilderAdapter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Obsolete] + public interface ISignal_BuilderAdapter + { + Guid AcceptSystemBuilderBefore(ISystemBuilder builder); + void AcceptSystemBuilderAfter(ISystemBuilder builder, Dictionary signalMappings, Dictionary busMappings); + void BuilderSetValue(IValueStructure structure); + void BuilderAppendProperty(IProperty property); + void BuilderAppendConstraint(IProperty constraint); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_CycleAnalysis.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_CycleAnalysis.cs new file mode 100644 index 0000000..63e4c8d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_CycleAnalysis.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Obsolete] + public interface ISignal_CycleAnalysis + { + int AddCycles(Signal source, int tag); + int RemoveCycles(Signal source, int tag); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_Drive.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_Drive.cs new file mode 100644 index 0000000..be5d3e6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ISignal_Drive.cs @@ -0,0 +1,34 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Obsolete] + public interface ISignal_Drive + { + void DriveSignal(Port source, int outputIndex); + void UndriveSignal(int outputIndex); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ISystemBuilder.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ISystemBuilder.cs new file mode 100644 index 0000000..7efd8fe --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ISystemBuilder.cs @@ -0,0 +1,56 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics +{ + /// + /// A system builder is a concrete builder (writer) conforming with the builder design pattern, + /// building an arbitrary representation of a Math System. + /// System builders are controlled by a director (reader), eg. . + /// + public interface ISystemBuilder + { + void BeginBuildSystem(int inputSignalCount, int outputSignalCount, int busCount); + + Guid BuildSignal(string label, bool hold, bool isSource); + + Guid BuildBus(string label); + + Guid BuildPort(MathIdentifier entityId, InstanceIdSet inputSignals, InstanceIdSet outputSignals, InstanceIdSet buses); + + void AppendSignalValue(Guid iid, ICustomDataPack value); + void AppendSignalProperty(Guid iid, ICustomDataPack property); + void AppendSignalConstraint(Guid iid, ICustomDataPack constraint); + + void AppendSystemInputSignal(Guid iid); + void AppendSystemOutputSignal(Guid iid); + void AppendSystemNamedSignal(Guid iid, string name); + void AppendSystemNamedBus(Guid iid, string name); + + void EndBuildSystem(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/IValueStructure.cs b/Backup/src/app/MathNet.Yttrium/Contracts/IValueStructure.cs new file mode 100644 index 0000000..7dd6a48 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/IValueStructure.cs @@ -0,0 +1,33 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IValueStructure : ICustomData, IEquatable + { + bool EqualsById(IValueStructure other); + bool EqualsById(MathIdentifier otherStructureId); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/MathIdentifier.cs b/Backup/src/app/MathNet.Yttrium/Contracts/MathIdentifier.cs new file mode 100644 index 0000000..83593f0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/MathIdentifier.cs @@ -0,0 +1,108 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Serializable] + public struct MathIdentifier : IEquatable, IComparable + { + private readonly string domain, label; + + public MathIdentifier(string label, string domain) + { + this.domain = domain; + this.label = label; + } + + public string Label + { + get { return label; } + } + + public string Domain + { + get { return domain; } + } + + public MathIdentifier DerivePostfix(string labelPostfix) + { + return new MathIdentifier(label + labelPostfix, domain); + } + public MathIdentifier DerivePrefix(string labelPrefix) + { + return new MathIdentifier(labelPrefix + label, domain); + } + + public bool Equals(string label, string domain) + { + return this.domain == domain && this.label == label; + } + public bool Equals(MathIdentifier other) + { + return domain == other.domain && label == other.label; + } + public override bool Equals(object obj) + { + if(obj != null && obj is MathIdentifier) + return Equals((MathIdentifier)obj); + else + return false; + } + public static bool operator ==(MathIdentifier left, MathIdentifier right) + { + return left.Equals(right); + } + public static bool operator !=(MathIdentifier left, MathIdentifier right) + { + return !left.Equals(right); + } + + public override int GetHashCode() + { + return domain.GetHashCode() ^ label.GetHashCode(); + } + + public int CompareTo(MathIdentifier other) + { + int c = domain.CompareTo(other.domain); + if(c != 0) + return c; + else + return label.CompareTo(other.label); + } + + public override string ToString() + { + return domain + "." + label; + } + + public static MathIdentifier Parse(string value) + { + if(value == null) throw new ArgumentNullException("value"); + string[] parts = value.Split('.'); + return new MathIdentifier(parts[1], parts[0]); + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Node.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Node.cs new file mode 100644 index 0000000..3132143 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Node.cs @@ -0,0 +1,70 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public abstract class Node + : AspectObject, IEquatable + { + private readonly Guid _iid; + private string _label; + + protected Node() + { + _iid = Guid.NewGuid(); + _label = _iid.ToString(); + } + + /// + /// Unique identifier of this instance. + /// + public Guid InstanceId + { + get { return _iid; } + } + + /// + /// The name of this instance. Arbitrary and changeable. + /// + public string Label + { + get { return _label; } + set { _label = value; } + } + + public bool Equals(Node other) + { + return _iid.Equals(other._iid); + } + + public void ClearAllFlagsWhere(FlagKind kind) + { + ClearAllFlagsWhere(delegate(NodeFlag flag) + { + return flag.Kind == kind; + }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/NodeEvent.cs b/Backup/src/app/MathNet.Yttrium/Contracts/NodeEvent.cs new file mode 100644 index 0000000..d835618 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/NodeEvent.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public sealed class NodeEvent + : EventAspect + { + public static NodeEvent Register(MathIdentifier id, Type handlerType, Type ownerType) + { + NodeEvent np = new NodeEvent(id, handlerType, ownerType, null); + return np; + } + + private NodeEvent(MathIdentifier id, Type handlerType, Type ownerType, IdentifierService service) + : base(id, handlerType, ownerType, service) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/NodeEventTrigger.cs b/Backup/src/app/MathNet.Yttrium/Contracts/NodeEventTrigger.cs new file mode 100644 index 0000000..ebccd19 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/NodeEventTrigger.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public sealed class NodeEventTrigger + : EventTrigger + { + private readonly NodeFlag _remoteFlag; + private readonly NodeProperty _remoteProperty; + + /// + /// Creates a trigger that is always activ when its flag or property is set + /// + public NodeEventTrigger(EventTriggerAction action, params NodeEvent[] events) + : base(action, events) + { + } + + /// + /// Creates a trigger that is always active when the other flag is set. + /// + public NodeEventTrigger(EventTriggerAction action, NodeFlag remoteFlag, params NodeEvent[] events) + : base(action, events) + { + _remoteFlag = remoteFlag; + } + + /// + /// Creates a trigger that is always active when the other property is set. + /// + public NodeEventTrigger(EventTriggerAction action, NodeProperty remoteProperty, params NodeEvent[] events) + : base(action, events) + { + _remoteProperty = remoteProperty; + } + + public NodeFlag RemoteFlag + { + get { return _remoteFlag; } + } + public bool RegisterAtRemoteFlag + { + get { return _remoteFlag != null; } + } + + public NodeProperty RemoteProperty + { + get { return _remoteProperty; } + } + public bool RegisterAtRemoteProperty + { + get { return _remoteProperty != null; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/NodeFlag.cs b/Backup/src/app/MathNet.Yttrium/Contracts/NodeFlag.cs new file mode 100644 index 0000000..e2a36bf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/NodeFlag.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics +{ + public enum FlagKind + { + Default = 0, + Constraint + } + + public sealed class NodeFlag + : FlagAspect + { + NodeEvent _dirtiedEvent; + NodeEvent _changedEvent; + NodeEvent _enabledEvent; + NodeEvent _noLongerEnabledEvent; + FlagKind _kind; + + public static NodeFlag Register(MathIdentifier id, Type ownerType, FlagKind kind) + { + NodeEvent dirtiedEvent = NodeEvent.Register + ( + id.DerivePostfix("DirtiedEvent"), + typeof(EventHandler), + ownerType + ); + NodeEvent changedEvent = NodeEvent.Register + ( + id.DerivePostfix("ChangedEvent"), + typeof(EventHandler), + ownerType + ); + NodeEvent enabledEvent = NodeEvent.Register + ( + id.DerivePostfix("EnabledEvent"), + typeof(EventHandler), + ownerType + ); + NodeEvent noLongerEnabledEvent = NodeEvent.Register + ( + id.DerivePostfix("NoLongerEnabledEvent"), + typeof(EventHandler), + ownerType + ); + NodeFlag nf = new NodeFlag(id, ownerType, null, kind, dirtiedEvent, changedEvent, enabledEvent, noLongerEnabledEvent); + return nf; + } + + public static NodeFlag Register(MathIdentifier id, Type ownerType) + { + return Register(id, ownerType, FlagKind.Default); + } + + public static NodeFlag Register(MathIdentifier id, Type ownerType, FlagKind kind, params NodeEventTrigger[] triggers) + { + NodeFlag nf = Register(id, ownerType, kind); + foreach(NodeEventTrigger trigger in triggers) + { + if(trigger.RegisterAtRemoteFlag) + { + trigger.RemoteFlag.AddRemoteEventTrigger(trigger, nf); + continue; + } + if(trigger.RegisterAtRemoteProperty) + { + trigger.RemoteProperty.AddRemoteEventTrigger(trigger, nf); + continue; + } + nf.AddEventFlagTrigger(trigger, nf); + } + return nf; + } + + private NodeFlag(MathIdentifier id, Type ownerType, IdentifierService service, FlagKind kind, + NodeEvent dirtiedEvent, NodeEvent changedEvent, NodeEvent enabledEvent, NodeEvent noLongerEnabledEvent) + : base(id, ownerType, service) + { + _kind = kind; + _dirtiedEvent = dirtiedEvent; + _changedEvent = changedEvent; + _enabledEvent = enabledEvent; + _noLongerEnabledEvent = noLongerEnabledEvent; + } + + protected override void OnFlagChanged(THost host, FlagState oldState, FlagState newState) + { + NodeFlagChangedEventArgs e = new NodeFlagChangedEventArgs(host as Node, this, oldState, newState); + host.RaiseEvent(_changedEvent, e); + if(newState == FlagState.Enabled) + host.RaiseEvent(_enabledEvent, e); + else if(oldState == FlagState.Enabled) + host.RaiseEvent(_noLongerEnabledEvent, e); + } + + protected override void OnFlagDirtied(THost host) + { + NodeFlagDirtiedEventArgs e = new NodeFlagDirtiedEventArgs(host as Node, this); + host.RaiseEvent(_dirtiedEvent, e); + } + + public NodeEvent FlagDirtiedEvent + { + get { return _dirtiedEvent; } + } + + public NodeEvent FlagChangedEvent + { + get { return _changedEvent; } + } + + public NodeEvent FlagEnabledEvent + { + get { return _enabledEvent; } + } + + public NodeEvent FlagNoLongerEnabledEvent + { + get { return _noLongerEnabledEvent; } + } + + public FlagKind Kind + { + get { return _kind; } + } + + internal void AddRemoteEventTrigger(NodeEventTrigger trigger, NodeFlag remoteFlag) + { + base.AddEventFlagTrigger(trigger, remoteFlag); + } + + internal void AddRemoteEventTrigger(NodeEventTrigger trigger, NodeProperty remoteProperty) + { + base.AddEventPropertyTrigger(trigger, remoteProperty); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/NodeProperty.cs b/Backup/src/app/MathNet.Yttrium/Contracts/NodeProperty.cs new file mode 100644 index 0000000..6ec2c3c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/NodeProperty.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics +{ + public sealed class NodeProperty + : PropertyAspect + { + NodeEvent _dirtiedEvent; + NodeEvent _changedEvent; + + public static NodeProperty Register(MathIdentifier id, Type valueType, Type ownerType) + { + NodeEvent dirtiedEvent = NodeEvent.Register + ( + id.DerivePostfix("DirtiedEvent"), + typeof(EventHandler), + ownerType + ); + NodeEvent changedEvent = NodeEvent.Register + ( + id.DerivePostfix("ChangedEvent"), + typeof(EventHandler), + ownerType + ); + NodeProperty np = new NodeProperty(id, valueType, ownerType, null, dirtiedEvent, changedEvent); + return np; + } + + public static NodeProperty Register(MathIdentifier id, Type valueType, Type ownerType, params NodeEventTrigger[] triggers) + { + NodeProperty np = Register(id, valueType, ownerType); + foreach(NodeEventTrigger trigger in triggers) + { + if(trigger.RegisterAtRemoteFlag) + { + trigger.RemoteFlag.AddRemoteEventTrigger(trigger, np); + continue; + } + if(trigger.RegisterAtRemoteProperty) + { + trigger.RemoteProperty.AddRemoteEventTrigger(trigger, np); + continue; + } + np.AddEventPropertyTrigger(trigger, np); + } + return np; + } + + private NodeProperty(MathIdentifier id, Type valueType, Type ownerType, IdentifierService service, + NodeEvent dirtiedEvent, NodeEvent changedEvent) + : base(id, valueType, ownerType, service) + { + _dirtiedEvent = dirtiedEvent; + _changedEvent = changedEvent; + } + + protected override void OnPropertyChanged(THost host, object oldValue, object newValue) + { + NodePropertyChangedEventArgs e = new NodePropertyChangedEventArgs(host as Node, this, oldValue, newValue); + host.RaiseEvent(_changedEvent, e); + } + + protected override void OnPropertyDirtied(THost host) + { + NodePropertyDirtiedEventArgs e = new NodePropertyDirtiedEventArgs(host as Node, this); + host.RaiseEvent(_dirtiedEvent, e); + } + + public NodeEvent PropertyDirtiedEvent + { + get { return _dirtiedEvent; } + } + + public NodeEvent PropertyChangedEvent + { + get { return _changedEvent; } + } + + internal void AddRemoteEventTrigger(NodeEventTrigger trigger, NodeFlag remoteFlag) + { + base.AddEventFlagTrigger(trigger, remoteFlag); + } + + internal void AddRemoteEventTrigger(NodeEventTrigger trigger, NodeProperty remoteProperty) + { + base.AddEventPropertyTrigger(trigger, remoteProperty); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Port.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Port.cs new file mode 100644 index 0000000..98c6713 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Port.cs @@ -0,0 +1,146 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics +{ + /// + /// Represents an Yttrium Port. Ports connect signals by operations defined + /// in interchangeable architectures. + /// + public abstract class Port : Node, IEquatable + { + protected Port() + : base() + { + } + + #region Event Aspects + public static readonly NodeEvent ArchitectureChangedEvent + = NodeEvent.Register(new MathIdentifier("ArchitectureChanged", "Core"), + typeof(EventHandler>), + typeof(Port)); + public event EventHandler> ArchitectureChanged + { + add { AddHandler(ArchitectureChangedEvent, value); } + remove { RemoveHandler(ArchitectureChangedEvent, value); } + } + protected virtual void OnArchitectureChanged(IArchitecture oldArchitecture, IArchitecture newArchitecture) + { + RaiseEvent(ArchitectureChangedEvent, new ValueChangedEventArgs(this, oldArchitecture, newArchitecture)); + } + + public static readonly NodeEvent PortInputTreeChangedEvent + = NodeEvent.Register(new MathIdentifier("PortInputTreeChanged", "Core"), + typeof(EventHandler), + typeof(Port)); + public event EventHandler PortInputTreeChanged + { + add { AddHandler(PortInputTreeChangedEvent, value); } + remove { RemoveHandler(PortInputTreeChangedEvent, value); } + } + protected virtual void OnInputTreeChanged(int index) + { + RaiseEvent(PortInputTreeChangedEvent, new PortIndexEventArgs(this, index)); + } + + public static readonly NodeEvent PortBusChangedEvent + = NodeEvent.Register(new MathIdentifier("PortBusChanged", "Core"), + typeof(EventHandler), + typeof(Port)); + public event EventHandler PortBusChanged + { + add { AddHandler(PortBusChangedEvent, value); } + remove { RemoveHandler(PortBusChangedEvent, value); } + } + protected virtual void OnBusChanged(int index) + { + RaiseEvent(PortBusChangedEvent, new PortIndexEventArgs(this, index)); + } + #endregion + + #region Graph Structure + public abstract int InputSignalCount { get; } + public abstract int OutputSignalCount { get; } + public abstract int BusCount { get; } + public abstract ReadOnlySignalSet InputSignals { get; } + public abstract ReadOnlySignalSet OutputSignals { get; } + public abstract ReadOnlyBusSet Buses { get; } + public abstract Signal this[int outputIndex] { get; } + + public abstract int IndexOfOutputSignal(Signal signal); + + public abstract bool DependsOn(Signal signal); + public abstract bool DependsOn(Port port); + public abstract bool DependsOn(MathIdentifier portEntity); + #endregion + + /// + /// The entity defining this port's interface and (indirectly) its operation. + /// + public abstract IEntity Entity { get; } + + /// + /// The architecture currently attached to this port. Architectures are + /// interchangeable as long as they implement this port's entity. + /// + public abstract IArchitecture CurrentArchitecture { get; } + + public abstract bool HasArchitectureLink { get; } + + /// + /// Checks if the current architecture still matches the bound signals + /// and tries to find a matching architecture if not. + /// + /// True if there's a matching architecture linked after the call. + public abstract bool EnsureArchitectureLink(); + + public abstract void RemoveLinkedArchitecture(); + + public abstract bool IsCompletelyConnected { get; } + + public abstract void AddInputSignalBinding(int index, Signal signal); + public abstract void RemoveInputSignalBinding(int index); + public abstract void ReplaceInputSignalBinding(int index, Signal replacement); + public abstract void AddOutputSignalBinding(int index, Signal signal); + public abstract void RemoveOutputSignalBinding(int index); + public abstract void ReplaceOutputSignalBinding(int index, Signal replacement); + public abstract void AddBusBinding(int index, Bus bus); + public abstract void RemoveBusBinding(int index); + public abstract void ReplaceBusBinding(int index, Bus replacement); + public abstract void RemoveAllBindings(); + public abstract void BindInputSignals(IEnumerable inputSignals); + public abstract void BindBuses(IEnumerable buses); + + public abstract Port CloneWithNewInputs(IList newInputs); + + public bool Equals(Port other) + { + return base.Equals((Node)other); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5ee3819 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("a06a274c-3532-4b0a-a673-b7007fffdcd6")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs new file mode 100644 index 0000000..5da5b49 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs @@ -0,0 +1,198 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.832 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to The operation '{0}' does not support circular systems, that is systems with signals depending upon themselves.. + /// + internal static string ex_CyclicSignalsNotSupportes { + get { + return ResourceManager.GetString("ex_CyclicSignalsNotSupportes", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to deserialize the entity {0}.{1}: entity is generic but no extension is attached.. + /// + internal static string ex_Deserialize_Failed_GenericEntity { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_GenericEntity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to deserialize an item, due to an invalid data file or a usage error. Expected '{0}' but got '{1}' instead. Check the data file for errors and report to the developer.. + /// + internal static string ex_Deserialize_Failed_UnexpectedPosition { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_UnexpectedPosition", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No proper category deserialization method found.. + /// + internal static string ex_Deserialize_Failed_UnsupportedCategory { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_UnsupportedCategory", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No proper structure deserialization method found.. + /// + internal static string ex_Deserialize_Failed_UnsupportedStructure { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_UnsupportedStructure", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The operation expected {0} but got {1} instead. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. + /// + internal static string ex_Entity_Unexpected_SignalCount { + get { + return ResourceManager.GetString("ex_Entity_Unexpected_SignalCount", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No Math.NET Architecture matching the requirements (including supporting the entity '{0}') was found. Maybe an extension module is not loaded yet, or the input signals are not qualified enough.. + /// + internal static string ex_NotAvailable_Architecture { + get { + return ResourceManager.GetString("ex_NotAvailable_Architecture", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The currently loaded context library does not list the demanded domain '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. + /// + internal static string ex_NotAvailable_Domain { + get { + return ResourceManager.GetString("ex_NotAvailable_Domain", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The currently loaded context library does not list the demanded entity '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. + /// + internal static string ex_NotAvailable_Entity { + get { + return ResourceManager.GetString("ex_NotAvailable_Entity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The search for a specific item has returned no result.. + /// + internal static string ex_NotFound { + get { + return ResourceManager.GetString("ex_NotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A requested feature is not yet implemented.. + /// + internal static string ex_NotImplementedYet { + get { + return ResourceManager.GetString("ex_NotImplementedYet", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0}' but got '{1}' around '{2}'.. + /// + internal static string ex_Parsing_Failed_TokenMismatch { + get { + return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0} [{3}]' but got '{1}' around '{2}'.. + /// + internal static string ex_Parsing_Failed_TokenMismatchEx { + get { + return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatchEx", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A theorem was used on a wrong item or a matching theorem was not found. This probably is a programming error, please report to the manufacturer.. + /// + internal static string ex_Theorem_Mismatch { + get { + return ResourceManager.GetString("ex_Theorem_Mismatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A mutual exclusive system traversing strategy is already in use and may not be executed again before the other finishes its operation.. + /// + internal static string ex_Traversing_Failed_ReserveMutex { + get { + return ResourceManager.GetString("ex_Traversing_Failed_ReserveMutex", resourceCulture); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Properties/Resources.resx b/Backup/src/app/MathNet.Yttrium/Contracts/Properties/Resources.resx new file mode 100644 index 0000000..131d9c4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Properties/Resources.resx @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The operation '{0}' does not support circular systems, that is systems with signals depending upon themselves. + + + Failed to deserialize the entity {0}.{1}: entity is generic but no extension is attached. + + + Failed to deserialize an item, due to an invalid data file or a usage error. Expected '{0}' but got '{1}' instead. Check the data file for errors and report to the developer. + + + No proper category deserialization method found. + + + No proper structure deserialization method found. + + + The operation expected {0} but got {1} instead. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty. + + + No Math.NET Architecture matching the requirements (including supporting the entity '{0}') was found. Maybe an extension module is not loaded yet, or the input signals are not qualified enough. + + + The currently loaded context library does not list the demanded domain '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty. + + + The currently loaded context library does not list the demanded entity '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty. + + + The search for a specific item has returned no result. + + + A requested feature is not yet implemented. + + + Parsing failed. Token Mismatch. Expected '{0}' but got '{1}' around '{2}'. + + + Parsing failed. Token Mismatch. Expected '{0} [{3}]' but got '{1}' around '{2}'. + + + A theorem was used on a wrong item or a matching theorem was not found. This probably is a programming error, please report to the manufacturer. + + + A mutual exclusive system traversing strategy is already in use and may not be executed again before the other finishes its operation. + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Signal.cs b/Backup/src/app/MathNet.Yttrium/Contracts/Signal.cs new file mode 100644 index 0000000..4c676bd --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Signal.cs @@ -0,0 +1,217 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics +{ + /// + /// Represents an Yttrium Signal. Signals are the core elements; yttrium is + /// all about signals, their values and their relations to other signals. + /// + public abstract class Signal : ValueNode, IEquatable + { + protected Signal() + : base() + { + } + + protected Signal(IValueStructure initialValue) + : base(initialValue) + { + } + + #region Event Aspects + public static readonly NodeEvent SignalInputTreeChangedEvent + = NodeEvent.Register(new MathIdentifier("SignalInputTreeChanged", "Core"), + typeof(EventHandler), + typeof(Signal)); + public event EventHandler SignalInputTreeChanged + { + add { AddHandler(SignalInputTreeChangedEvent, value); } + remove { RemoveHandler(SignalInputTreeChangedEvent, value); } + } + protected virtual void OnInputTreeChanged() + { + RaiseEvent(SignalInputTreeChangedEvent, new SignalEventArgs(this)); + } + #endregion + + #region Drive State + public abstract bool IsDriven + { + get; + } + + public abstract bool Hold + { + get; + set; + } + + public abstract bool IsSourceSignal + { + get; + set; + } + + /// + /// True if this signal is driven by a port and, if is false, the signal is not being hold. + /// + /// if true, this method returns the same value as the property. + public bool BehavesAsBeingDriven(bool ignoreHold) + { + return IsDriven && (ignoreHold || !Hold); + } + + /// + /// True if this signal is either a source signal or just behaves so because of being hold. + /// + public bool BehavesAsSourceSignal + { + get { return IsSourceSignal || Hold; } + } + #endregion + + #region Graph Structure + public abstract Port DrivenByPort + { + get; + } + + /// + /// True if the signal is driven by a port and this port has the specified entity. + /// + public bool IsDrivenByPortEntity(MathIdentifier entityId) + { + if(!IsDriven) + return false; + return DrivenByPort.Entity.EntityId.Equals(entityId); + } + + /// + /// True if the signal is driven by a port and this port has the specified entity. + /// + public bool IsDrivenByPortEntity(string entityLabel, string entityDomain) + { + if(!IsDriven) + return false; + return DrivenByPort.Entity.EntityId.Equals(entityLabel, entityDomain); + } + + public abstract bool IsCyclic + { + get; + } + + public abstract int Cycles + { + get; + } + + public abstract bool DependsOn(Signal signal); + public abstract bool DependsOn(Port port); + public abstract bool DependsOn(MathIdentifier portEntity); + #endregion + + public abstract bool HasProperty(MathIdentifier propertyId); + + public abstract bool AskForProperty(MathIdentifier propertyType); + + public bool AskForProperty(string propertyLabel, string propertyDomain) + { + return AskForProperty(new MathIdentifier(propertyLabel, propertyDomain)); + } + + public abstract void AddConstraint(IProperty property); + + public abstract void RemoveAllConstraints(); + + #region Operators: Builder Shortcuts + + protected abstract Signal AddSignalCore(Signal summand); + protected abstract Signal NegateSignalCore(); + protected abstract Signal SubtractSignalCore(Signal subtrahend); + protected abstract Signal MultiplySignalCore(Signal multiplier); + protected abstract Signal DivideSignalCore(Signal divisor); + + /// + /// Shortcut for the binary addition operation. + /// + public static Signal operator +(Signal summand1, Signal summand2) + { + if(summand1 == null) throw new ArgumentNullException("summand1"); + return summand1.AddSignalCore(summand2); + } + /// + /// Unary add, just returns the signal (does nothing). + /// + public static Signal operator +(Signal summand) + { + return summand; + } + + /// + /// Shortcut for the binary subtraction operation. + /// + public static Signal operator -(Signal minuend, Signal subtrahend) + { + if(minuend == null) throw new ArgumentNullException("minuend"); + return minuend.SubtractSignalCore(subtrahend); + } + /// + /// Shortcut for the unary subtraction operation. + /// + public static Signal operator -(Signal subtrahend) + { + if(subtrahend == null) throw new ArgumentNullException("subtrahend"); + return subtrahend.NegateSignalCore(); + } + + /// + /// Shortcut for the binary multiplication operation. + /// + public static Signal operator *(Signal multiplicand, Signal multiplier) + { + if(multiplicand == null) throw new ArgumentNullException("multiplicand"); + return multiplicand.MultiplySignalCore(multiplier); + } + + /// + /// Shortcut for the binary division operation. + /// + public static Signal operator /(Signal dividend, Signal divisor) + { + if(dividend == null) throw new ArgumentNullException("dividend"); + return dividend.DivideSignalCore(divisor); + } + #endregion + + public bool Equals(Signal other) + { + return base.Equals((Node)other); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/ValueNode.cs b/Backup/src/app/MathNet.Yttrium/Contracts/ValueNode.cs new file mode 100644 index 0000000..755286f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/ValueNode.cs @@ -0,0 +1,99 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics +{ + public abstract class ValueNode : Node + { + private IValueStructure _presentStructure; // = null; + private bool _hasEvent; // = false; + + #region Event Aspects + public static readonly NodeEvent ValueChangedEvent + = NodeEvent.Register(new MathIdentifier("ValueChanged", "Core"), + typeof(EventHandler), + typeof(ValueNode)); + public event EventHandler ValueChanged + { + add { AddHandler(ValueChangedEvent, value); } + remove { RemoveHandler(ValueChangedEvent, value); } + } + protected virtual void OnValueChanged() + { + RaiseEvent(ValueChangedEvent, new ValueNodeEventArgs(this)); + } + #endregion + + protected ValueNode() + { + } + + protected ValueNode(IValueStructure initialValue) + { + _presentStructure = initialValue; + } + + /// + /// The present value of this node. + /// + public IValueStructure Value + { + get { return _presentStructure; } + } + + public MathIdentifier ValueTypeId + { + get { return _presentStructure.TypeId; } + } + + /// + /// True only in the scheduler process execution phase, and only if the + /// there is an event related to this node, that is it's value has changed. + /// + public bool HasEvent + { + get { return _hasEvent; } + } + + protected void SetHasEvent(bool value) + { + _hasEvent = value; + } + + protected void SetPresentValue(IValueStructure value) + { + //bool different = !(value == null && _presentStructure == null) + // && !(_presentStructure != null && value != null && _presentStructure.Equals(value)); + _presentStructure = value; + //_properties.ValidatePropertiesAfterEvent(this); + } + + public abstract void PostNewValue(IValueStructure newValue); + public abstract void PostNewValue(IValueStructure newValue, TimeSpan delay); + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj new file mode 100644 index 0000000..c639aeb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj @@ -0,0 +1,144 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Resources.resx + True + True + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IConversionRouter.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IConversionRouter.cs new file mode 100644 index 0000000..ad0d6eb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IConversionRouter.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Conversion +{ + public interface IConversionRouter : IValueConverter + { + void AddSourceNeighbor(IConversionRouter routerWeCanConvertFrom, bool lossless, Converter directConvert); + void AddTargetNeighbor(IConversionRouter routerWeCanConvertTo); + bool Propose(IRouteDistance distance, IConversionRouter proposedBy); + void Propose(Dictionary vec, IConversionRouter proposedBy); + void BroadcastDistanceVector(IConversionRouter target); + void BroadcastDistanceVector(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IRouteDistance.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IRouteDistance.cs new file mode 100644 index 0000000..cdaac79 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IRouteDistance.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Conversion +{ + public interface IRouteDistance + { + MathIdentifier CanConvertFrom { get;} + int Cost { get; } + IConversionRouter NextHop { get; } + Converter Convert { get; } + bool Lossless { get; } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IValueConverter.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IValueConverter.cs new file mode 100644 index 0000000..f89b7d0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Conversion/IValueConverter.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Conversion +{ + public interface IValueConverter + { + MathIdentifier TypeIdentifier { get;} + Converter BuildConverterFrom(MathIdentifier id); + object ConvertFrom(ICustomData value); + object ConvertFrom(object value); + bool TryConvertFrom(ICustomData value, out object returnValue); + bool TryConvertFrom(object value, out object returnValue); + bool CanConvertFrom(MathIdentifier id, bool allowLoss); + bool CanConvertFrom(Type type, bool allowLoss); + bool CanConvertLosslessFrom(ICustomData value); + bool CanConvertLossyFrom(ICustomData value); + bool CanConvertLosslessFrom(object value); + bool CanConvertLossyFrom(object value); + + //Type InstanceType { get;} + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5013349 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Conversion Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("bddd577b-cb55-4445-9dfd-6fa76041e5e8")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Yttrium.Conversion.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Yttrium.Conversion.Contracts.csproj new file mode 100644 index 0000000..574908d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Contracts/Yttrium.Conversion.Contracts.csproj @@ -0,0 +1,63 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Conversion.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Service/Conversion/ConversionRouter.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Service/Conversion/ConversionRouter.cs new file mode 100644 index 0000000..5b3fe1d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Service/Conversion/ConversionRouter.cs @@ -0,0 +1,354 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Conversion +{ + public class ConversionRouter : IValueConverter, IConversionRouter + { + private MathIdentifier structureId; + private Dictionary losslessNeighbors, lossyNeighbors; + private Dictionary targetNeighbors; + private Dictionary vector; + + #region Routing Structures + private struct ConversionRoute + { + public ConversionRoute(MathIdentifier canConvertFrom, Converter convert) + { + this.CanConvertFrom = canConvertFrom; + this.Convert = convert; + } + public readonly MathIdentifier CanConvertFrom; + public readonly Converter Convert; + } + + private struct ConversionDistance : IRouteDistance + { + private readonly MathIdentifier _canConvertFrom; + private readonly int _cost; + private readonly IConversionRouter _nextHop; + private readonly Converter _convert; + private readonly bool _lossless; + + public ConversionDistance(MathIdentifier canConvertFrom, int cost, bool lossless, IConversionRouter nextHop, Converter convert) + { + _canConvertFrom = canConvertFrom; + _cost = cost; + _lossless = lossless; + _nextHop = nextHop; + _convert = convert; + } + + public MathIdentifier CanConvertFrom + { + get { return _canConvertFrom; } + } + public int Cost + { + get { return _cost; } + //set { _cost = value; } + } + public IConversionRouter NextHop + { + get { return _nextHop; } + //set { _nextHop = value; } + } + public Converter Convert + { + get { return _convert; } + //set { _convert = value; } + } + public bool Lossless + { + get { return _lossless; } + //set { _lossless = value; } + } + } + #endregion + + public ConversionRouter(MathIdentifier structureId) + { + this.structureId = structureId; + this.losslessNeighbors = new Dictionary(); + this.lossyNeighbors = new Dictionary(); + this.targetNeighbors = new Dictionary(); + this.vector = new Dictionary(); + } + + public MathIdentifier TypeIdentifier + { + get { return structureId; } + } + + #region Routing + public void AddSourceNeighbor(IConversionRouter routerWeCanConvertFrom, bool lossless, Converter directConvert) + { + MathIdentifier id = routerWeCanConvertFrom.TypeIdentifier; + Propose(new ConversionDistance(id, 0, lossless, null, directConvert), routerWeCanConvertFrom); + } + + public void AddTargetNeighbor(IConversionRouter routerWeCanConvertTo) + { + if(!targetNeighbors.ContainsKey(routerWeCanConvertTo.TypeIdentifier)) + { + targetNeighbors.Add(routerWeCanConvertTo.TypeIdentifier, routerWeCanConvertTo); + BroadcastDistanceVector(routerWeCanConvertTo); + } + } + + /// True if the route was better than existing routes. + /// It is expected that we already know the proposing neighbor router proposedBy! + public bool Propose(IRouteDistance distance, IConversionRouter proposedBy) + { + MathIdentifier id = distance.CanConvertFrom; + + // I'm already myself, so I won't accept it whatever you propose :) + if(structureId.Equals(id)) + return false; + + bool knownLosslessProposer = losslessNeighbors.ContainsKey(proposedBy.TypeIdentifier); + bool knownLossyProposer = lossyNeighbors.ContainsKey(proposedBy.TypeIdentifier); + + // does the router propose himself? + if(proposedBy.TypeIdentifier.Equals(id)) + { + if(distance.Cost != 0) + throw new InvalidOperationException("An conversion router strangely thinks he can't reach himself with zero cost."); + + // we didn't know it, or it's better than before, so we add it to the neighbor list + if(distance.Lossless && !knownLosslessProposer) + losslessNeighbors[id] = new ConversionRoute(id, distance.Convert); + else if(!distance.Lossless && !knownLossyProposer) + lossyNeighbors[id] = new ConversionRoute(id, distance.Convert); + else + return false; + + // we also want to add this neighbour to the vector. + vector[id] = new ConversionDistance(id, 1, distance.Lossless, proposedBy, distance.Convert); + + // before we broadcast our vector, we wan't to "subscribe" on this new inbound router + // to receive all his broadcasts. + proposedBy.AddTargetNeighbor(this); + + // now we broadcast (probably we already did this when the router sent any + // broadcasts as a result of AddTargetNeighbor, but we want to be sure) + BroadcastDistanceVector(); + + return true; + } + + if(!(knownLosslessProposer || knownLossyProposer)) + throw new InvalidOperationException("An unknown router strangely proposes some other host without first proposing himself."); + + // apparently he proposes some other host to be routed through himself, + // so we have to combine the poposed cost with those required to reach himself + bool lossless = distance.Lossless && knownLosslessProposer; + int cost = distance.Cost + 1; + + // is the proposed route better, or didn't we even know such a route yet? + IRouteDistance existingDistance; + if(!vector.TryGetValue(id, out existingDistance) + || lossless && !existingDistance.Lossless + || cost < existingDistance.Cost && (lossless || !existingDistance.Lossless)) + { + // then we want to add this route to our vector + + // we have to map the proposed conversion with then one required to convert from him + Converter distanceC = distance.Convert, localC, convert; + if(knownLosslessProposer) + localC = losslessNeighbors[proposedBy.TypeIdentifier].Convert; + else + localC = lossyNeighbors[proposedBy.TypeIdentifier].Convert; + convert = delegate(object v) { return localC(distanceC(v)); }; + + // Add route to vector and broadcast the vector. + vector[id] = new ConversionDistance(id, cost, lossless, proposedBy, convert); + BroadcastDistanceVector(); + + return true; + } + else + return false; + } + public void Propose(Dictionary vec, IConversionRouter proposedBy) + { + foreach(KeyValuePair distance in vec) + Propose(distance.Value, proposedBy); + } + + public void BroadcastDistanceVector(IConversionRouter target) + { + target.Propose(vector, this); + } + public void BroadcastDistanceVector() + { + foreach(KeyValuePair r in targetNeighbors) + r.Value.Propose(vector, this); + } + #endregion + + #region Conversion + public Converter BuildConverterFrom(MathIdentifier id) + { + if(structureId.Equals(id)) + return delegate(object value) { return value; }; + IRouteDistance cd; + if(vector.TryGetValue(id, out cd)) + return cd.Convert; + + throw new NotSupportedException("no route available to convert from " + id.ToString()); + //throw new MathNet.Symbolics.Backend.Exceptions.IncompatibleStructureException(id.Label, id.Domain); + } + + public object ConvertFrom(ICustomData value) + { + MathIdentifier id = value.TypeId; + if(structureId.Equals(id)) + return value; + IRouteDistance cd; + if(vector.TryGetValue(id,out cd)) + return cd.Convert(value); + + throw new NotSupportedException("no route available to convert from " + id.ToString()); + //throw new MathNet.Symbolics.Backend.Exceptions.IncompatibleStructureException(id.Label, id.Domain); + } + + public object ConvertFrom(object value) + { + MathIdentifier id = Service.Instance.LookupArbitraryType(value.GetType()); + if(structureId.Equals(id)) + return value; + IRouteDistance cd; + if(vector.TryGetValue(id, out cd)) + return cd.Convert(value); + + throw new NotSupportedException("no route available to convert from " + id.ToString()); + //throw new MathNet.Symbolics.Backend.Exceptions.IncompatibleStructureException(id.Label, id.Domain); + } + + public bool CanConvertFrom(MathIdentifier id, bool allowLoss) + { + if(structureId.Equals(id)) + return true; + IRouteDistance cd; + if(vector.TryGetValue(id, out cd)) + return cd.Lossless || allowLoss; + return false; + } + public bool CanConvertFrom(Type type, bool allowLoss) + { + MathIdentifier id = Service.Instance.LookupArbitraryType(type); + if(structureId.Equals(id)) + return true; + IRouteDistance cd; + if(vector.TryGetValue(id, out cd)) + return cd.Lossless || allowLoss; + return false; + } + public bool CanConvertLosslessFrom(ICustomData value) + { + return value != null && CanConvertFrom(value.TypeId, false); + } + public bool CanConvertLosslessFrom(object value) + { + return value != null && CanConvertFrom(value.GetType(), false); + } + public bool CanConvertLossyFrom(ICustomData value) + { + return value != null && CanConvertFrom(value.TypeId, true); + } + public bool CanConvertLossyFrom(object value) + { + return value != null && CanConvertFrom(value.GetType(), true); + } + + public bool TryConvertFrom(ICustomData value, out object returnValue) + { + MathIdentifier id = value.TypeId; + if(structureId.Equals(id)) + { + returnValue = value; + return true; + } + IRouteDistance cd; + if(vector.TryGetValue(id, out cd)) + { + returnValue = cd.Convert(value); + return true; + } + returnValue = null; + return false; + } + public bool TryConvertFrom(object value, out object returnValue) + { + MathIdentifier id = Service.Instance.LookupArbitraryType(value.GetType()); + if(structureId.Equals(id)) + { + returnValue = value; + return true; + } + IRouteDistance cd; + if(vector.TryGetValue(id, out cd)) + { + returnValue = cd.Convert(value); + return true; + } + returnValue = null; + return false; + } + #endregion + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("Routing "); sb.AppendLine(structureId.ToString()); + sb.Append("Lossless Neighbours:"); + foreach(MathIdentifier id in losslessNeighbors.Keys) + { sb.Append(' '); sb.Append(id.ToString()); } + sb.AppendLine(); + sb.Append("Lossy Neighbours:"); + foreach(MathIdentifier id in lossyNeighbors.Keys) + { sb.Append(' '); sb.Append(id.ToString()); } + sb.AppendLine(); + sb.Append("From:"); + foreach(KeyValuePair item in vector) + { + sb.Append(' '); sb.Append(item.Key.ToString()); + sb.Append(':'); sb.Append(item.Value.Cost); + sb.Append(':'); sb.Append(item.Value.Lossless); + sb.Append(':'); sb.Append(item.Value.NextHop.TypeIdentifier.ToString()); + } + sb.AppendLine(); + sb.Append("To:"); + foreach(MathIdentifier id in targetNeighbors.Keys) + { sb.Append(' '); sb.Append(id.ToString()); } + sb.AppendLine(); + return sb.ToString(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Service/ConversionFactory.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Service/ConversionFactory.cs new file mode 100644 index 0000000..6eb584a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Service/ConversionFactory.cs @@ -0,0 +1,65 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Reflection; + +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics +{ + internal class ConversionFactory : + IFactory, + IFactory + { + IConversionRouter IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: MathIdentifier"); + } + IConversionRouter IFactory.GetInstance(MathIdentifier p1) + { + return new ConversionRouter(p1); + } + IConversionRouter IFactory.GetInstance(Type p1) + { + PropertyInfo info = p1.GetProperty("TypeIdentifier", typeof(MathIdentifier)); + if(info != null) + { + object id = info.GetValue(null, null); + return new ConversionRouter((MathIdentifier)id); + } + else + { + // map to an arbitrary type, if this type has been registered + ILibrary lib = Service.Instance; + if(lib.ContainsArbitraryType(p1)) + { + MathIdentifier id = lib.LookupArbitraryType(p1); + return new ConversionRouter(id); + } + throw new NotSupportedException("Given type is neither a custom data type nor a registered arbitrary type."); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aaaf432 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Conversion")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("a2b54e1f-ffec-49b5-a1ef-0fb985aa3fbb")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Service/Yttrium.Conversion.Service.csproj b/Backup/src/app/MathNet.Yttrium/Conversion.Service/Yttrium.Conversion.Service.csproj new file mode 100644 index 0000000..b3c5f48 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Service/Yttrium.Conversion.Service.csproj @@ -0,0 +1,74 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Conversion.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Conversion/ValueConverter.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Conversion/ValueConverter.cs new file mode 100644 index 0000000..a04631b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Conversion/ValueConverter.cs @@ -0,0 +1,114 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Conversion +{ + public static class ValueConverter + { + //lazy initialization, since there are no other field members + private static readonly IConversionRouter _router = Binder.GetInstance(typeof(TTarget)); + + //// Explicit static constructor to tell C# compiler + //// not to mark type as beforefieldinit + //static ValueConverter() + //{ + //} + + public static TTarget ConvertFrom(ICustomData value) + { + return (TTarget)_router.ConvertFrom(value); + } + + public static TTarget ConvertFrom(object value) + { + return (TTarget)_router.ConvertFrom(value); + } + + public static TTarget[] ConvertFrom(IList values) + { + TTarget[] res = new TTarget[values.Count]; + for(int i = 0; i < res.Length; i++) + res[i] = (TTarget)_router.ConvertFrom(values[i]); + return res; + } + + public static TTarget ConvertFromValue(ValueNode node) + { + return (TTarget)_router.ConvertFrom(node.Value); + } + public static TTarget[] ConvertFromValue(IList nodes) + { + TTarget[] res = new TTarget[nodes.Count]; + for(int i = 0; i < res.Length; i++) + res[i] = (TTarget)_router.ConvertFrom(nodes[i].Value); + return res; + } + + public static bool CanConvertLosslessFrom(ICustomData value) + { + return _router.CanConvertLosslessFrom(value); + } + + public static bool TryConvertLosslessFrom(ICustomData value, out object returnValue) + { + if(!_router.CanConvertLosslessFrom(value)) + { + returnValue = null; + return false; + } + returnValue = _router.ConvertFrom(value); + return true; + } + + public static IConversionRouter Router + { + get { return _router; } + } + + public static void AddConverterFrom(IConversionRouter sourceRouter, bool lossless, Converter directConvert) + { + _router.AddSourceNeighbor(sourceRouter, lossless, directConvert); + } + + public static void AddConverterTo(IConversionRouter destinationRouter, bool lossless, Converter directConvert) + { + destinationRouter.AddSourceNeighbor(_router, lossless, directConvert); + } + + public static void AddConverterFrom(bool lossless, Converter directConvert) + where TSource : ICustomData + { + // TODO: Modify conversion core to operate directly on typed converters + _router.AddSourceNeighbor(ValueConverter.Router, lossless, delegate(object value) { return directConvert((TSource)value); }); + } + + public static void AddConverterTo(bool lossless, Converter directConvert) + where TDestination : ICustomData + { + // TODO: Modify conversion core to operate directly on typed converters + ValueConverter.Router.AddSourceNeighbor(_router, lossless, delegate(object value) { return directConvert((TTarget)value); }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8cb5d2b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Conversion Toolkit")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("ab6ebc8b-12f0-4d1c-a68d-ba4fd35757c7")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Yttrium.Conversion.Toolkit.csproj b/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Yttrium.Conversion.Toolkit.csproj new file mode 100644 index 0000000..6389141 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Conversion.Toolkit/Yttrium.Conversion.Toolkit.csproj @@ -0,0 +1,65 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Conversion.Toolkit + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/FormattingOptions.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/FormattingOptions.cs new file mode 100644 index 0000000..6a55127 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/FormattingOptions.cs @@ -0,0 +1,34 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Formatter +{ + [Flags] + public enum FormattingOptions : int + { + Default = 0x0, + Compact = 0x1 + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/IFormattableLeaf.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/IFormattableLeaf.cs new file mode 100644 index 0000000..5fa359a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/IFormattableLeaf.cs @@ -0,0 +1,32 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Formatter +{ + public interface IFormattableLeaf + { + string Format(FormattingOptions options, out int precedence); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/IFormatter.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/IFormatter.cs new file mode 100644 index 0000000..2df3fe7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Formatter/IFormatter.cs @@ -0,0 +1,32 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Formatter +{ + public interface IFormatter + { + string Format(Signal signal, FormattingOptions options); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..72f7d97 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Formatter Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("7d9edecc-a237-4533-9e53-1eb98ac3adb7")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Yttrium.Formatter.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Yttrium.Formatter.Contracts.csproj new file mode 100644 index 0000000..50531ad --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Contracts/Yttrium.Formatter.Contracts.csproj @@ -0,0 +1,59 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Formatter.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Service/Formatter/InfixFormatter.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Service/Formatter/InfixFormatter.cs new file mode 100644 index 0000000..56733cb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Service/Formatter/InfixFormatter.cs @@ -0,0 +1,112 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Formatter +{ + internal class InfixFormatter : IFormatter + { + public string Format(Signal signal, FormattingOptions options) + { + LinkedList sequence = new LinkedList(); + sequence.AddFirst("sentinel"); + FormatExpression(signal, sequence, options); + sequence.RemoveFirst(); + + StringBuilder sb = new StringBuilder(8 * sequence.Count); // heuristics + foreach(string token in sequence) + sb.Append(token); + //sb.Replace("+-", "-"); + //sb.Replace("--", "+"); + return sb.ToString(); + } + + /// precedence group + private int FormatExpression(Signal signal, LinkedList sequence, FormattingOptions options) + { + if(signal.BehavesAsSourceSignal) + { + if(signal.Value != null) + { + IFormattableLeaf leaf = signal.Value as IFormattableLeaf; + if(leaf != null) + { + int prec; + sequence.AddLast(leaf.Format(options, out prec)); + return prec; + } + else + { + sequence.AddLast(signal.Value.ToString()); + return -1; + } + } + if(!string.IsNullOrEmpty(signal.Label)) + { + sequence.AddLast(signal.Label); + return -1; + } + sequence.AddLast("signal"); + return -1; + } + + Port port = signal.DrivenByPort; + IEntity entity = port.Entity; + int precedence = entity.PrecedenceGroup; + InfixNotation notation = entity.Notation; + + if(notation == InfixNotation.PreOperator) + sequence.AddLast(entity.Symbol); + else if(notation == InfixNotation.None) + { + sequence.AddLast(entity.Symbol); + sequence.AddLast("("); + } + + bool notFirst = false; + foreach(Signal s in port.InputSignals) + { + if(notFirst) + sequence.AddLast(entity.Symbol); + else + notFirst = true; + + LinkedListNode before = sequence.Last; + int subPrecedence = FormatExpression(s, sequence, options); + if(subPrecedence >= precedence && notation != InfixNotation.None) + { + sequence.AddAfter(before, "("); + sequence.AddLast(")"); + } + } + + if(notation == InfixNotation.PostOperator) + sequence.AddLast(entity.Symbol); + else if(notation == InfixNotation.None) + sequence.AddLast(")"); + + return precedence; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Service/FormatterFactory.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Service/FormatterFactory.cs new file mode 100644 index 0000000..0e1c39c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Service/FormatterFactory.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics +{ + internal class FormatterFactory : IFactory + { + IFormatter IFactory.GetInstance() + { + return new InfixFormatter(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Formatter.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d2a6841 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Formatter")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("01627813-483f-4bd4-b6ff-f78135c97a63")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Formatter.Service/Yttrium.Formatter.Service.csproj b/Backup/src/app/MathNet.Yttrium/Formatter.Service/Yttrium.Formatter.Service.csproj new file mode 100644 index 0000000..9ae1824 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Formatter.Service/Yttrium.Formatter.Service.csproj @@ -0,0 +1,66 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Formatter.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/AspectObject.cs b/Backup/src/app/MathNet.Yttrium/Fundament/AspectObject.cs new file mode 100644 index 0000000..3176a63 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/AspectObject.cs @@ -0,0 +1,543 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public abstract class AspectObject + : IEventAspectHost + where TIdentifier : IEquatable, IComparable + where TProperty : PropertyAspect + where TFlag : FlagAspect + where TEvent : EventAspect + where TObject : AspectObject + { + private Dictionary> _properties; + private Dictionary> _flags; + private Dictionary _handlers; + private Dictionary>> _propertyEventTriggers; + private Dictionary>> _flagEventTriggers; + + // TODO: what we actually need for _handlers is not a list of delegates + // but a list of WeakDelegates (Delegate with WeakReference to it's target). + // Unfortunately the .Net Framework doesn't provide such a thing yet afaik... + + #region Property Aspects + public void SetProperty(TProperty property, object value) + { + //if(!property.IsValidValue(value)) + // throw new ArgumentException(); + if(_properties == null) + { + _properties = new Dictionary>(); + _propertyEventTriggers = new Dictionary>>(); + } + + Dirtyable old; + object oldValue = null; + if(_properties.TryGetValue(property, out old)) + oldValue = old.Value; + else + WirePropertyEventTriggers(property); + + _properties[property] = new Dirtyable(value); + + if(value != oldValue) + property.RaisePropertyChanged((TObject)this, oldValue, value); + } + + public object GetProperty(TProperty property) + { + if(_properties == null) + throw new System.ArgumentOutOfRangeException("property"); + return _properties[property].Value; + } + public object GetProperty(TProperty property, object defaultValue) + { + return GetProperty(property, defaultValue, false); + } + public object GetProperty(TProperty property, object defaultValue, bool acceptDirty) + { + object ret; + if(TryGetProperty(property, out ret, acceptDirty)) + return ret; + return defaultValue; + } + public bool TryGetProperty(TProperty property, out object value) + { + return TryGetProperty(property, out value, false); + } + public bool TryGetProperty(TProperty property, out object value, bool acceptDirty) + { + if(_properties == null) + { + value = null; + return false; + } + Dirtyable obj; + if(_properties.TryGetValue(property, out obj) && (acceptDirty || !obj.IsDirty)) + { + value = obj.Value; + return true; + } + value = null; + return false; + } + + public bool AskForProperty(TProperty property, out object value) + { + return AskForProperty(property, out value, false, false); + } + public bool AskForProperty(TProperty property, out object value, bool acceptDirty, bool forceRefresh) + { + if(forceRefresh) + AutoEvaluateProperty(property); + if(_properties == null) + { + value = null; + return false; + } + Dirtyable obj; + if(_properties.TryGetValue(property, out obj) && (acceptDirty || !obj.IsDirty)) + { + value = obj.Value; + return true; + } + if(!forceRefresh) + AutoEvaluateProperty(property); + if(_properties.TryGetValue(property, out obj) && (acceptDirty || !obj.IsDirty)) + { + value = obj.Value; + return true; + } + value = null; + return false; + } + + public void ClearProperty(TProperty property) + { + if(_properties == null) + return; + + Dirtyable old; + object oldValue = null; + if(_properties.TryGetValue(property, out old)) + { + oldValue = old.Value; + UnwirePropertyEventTriggers(property); + } + + _properties.Remove(property); + + if(oldValue != null) + property.RaisePropertyChanged((TObject)this, oldValue, null); + } + + public void DirtyPropertyIfSet(TProperty property) + { + if(_properties == null) + return; + Dirtyable obj; + if(_properties.TryGetValue(property, out obj) && !obj.IsDirty) + { + obj.IsDirty = true; + _properties[property] = obj; + property.RaisePropertyDirtied((TObject)this); + } + } + + public bool IsPropertySet(TProperty property) + { + return IsPropertySet(property, false); + } + public bool IsPropertySet(TProperty property, bool acceptDirty) + { + if(_properties == null) + return false; + if(acceptDirty) + return _properties.ContainsKey(property); + Dirtyable obj; + return _properties.TryGetValue(property, out obj) && !obj.IsDirty; + } + + public bool IsPropertyDirty(TProperty property) + { + if(_properties == null) + return false; + Dirtyable obj; + return _properties.TryGetValue(property, out obj) && obj.IsDirty; + } + + public void AutoEvaluateProperty(TProperty property) + { + OnAutoEvaluateProperty(property); + } + + protected virtual void OnAutoEvaluateProperty(TProperty property) + { + } + + private void WirePropertyEventTriggers(TProperty property) + { + foreach(KeyValuePair> trigger in property.EventPropertyTriggers) + { + List> list; + if(!_propertyEventTriggers.TryGetValue(trigger.Key, out list)) + { + list = new List>(); + _propertyEventTriggers.Add(trigger.Key, list); + } + list.Add(trigger.Value); + } + } + private void UnwirePropertyEventTriggers(TProperty property) + { + foreach(KeyValuePair> trigger in property.EventPropertyTriggers) + { + List> list; + if(!_propertyEventTriggers.TryGetValue(trigger.Key, out list)) + continue; + list.Remove(trigger.Value); + if(list.Count == 0) + _propertyEventTriggers.Remove(trigger.Key); + } + } + #endregion + + #region Threestate-Flag Aspects + public void SetFlagState(TFlag flag, FlagState state) + { + if(_flags == null) + { + if(state == FlagState.Unknown) + return; + _flags = new Dictionary>(); + _flagEventTriggers = new Dictionary>>(); + } + FlagState oldState = GetFlagState(flag); + if(state == FlagState.Unknown) + { + UnwireFlagEventTriggers(flag); + _flags.Remove(flag); + } + else + { + if(!_flags.ContainsKey(flag)) + WireFlagEventTriggers(flag); + _flags[flag] = new Dirtyable(state == FlagState.Enabled); + } + + if(oldState != state) + flag.RaiseFlagChanged((TObject)this, oldState, state); + } + public void EnableFlag(TFlag flag) + { + if(_flags == null) + { + _flags = new Dictionary>(); + _flagEventTriggers = new Dictionary>>(); + } + FlagState oldState = GetFlagState(flag); + if(!_flags.ContainsKey(flag)) + WireFlagEventTriggers(flag); + _flags[flag] = new Dirtyable(true); + + if(oldState != FlagState.Enabled) + flag.RaiseFlagChanged((TObject)this, oldState, FlagState.Enabled); + } + public void DisableFlag(TFlag flag) + { + if(_flags == null) + { + _flags = new Dictionary>(); + _flagEventTriggers = new Dictionary>>(); + } + FlagState oldState = GetFlagState(flag); + if(!_flags.ContainsKey(flag)) + WireFlagEventTriggers(flag); + _flags[flag] = new Dirtyable(false); + + if(oldState != FlagState.Disabled) + flag.RaiseFlagChanged((TObject)this, oldState, FlagState.Disabled); + } + public void ClearFlag(TFlag flag) + { + if(_flags == null) + return; + FlagState oldState = GetFlagState(flag); + UnwireFlagEventTriggers(flag); + _flags.Remove(flag); + + if(oldState != FlagState.Unknown) + flag.RaiseFlagChanged((TObject)this, oldState, FlagState.Unknown); + } + public void DirtyFlagIfSet(TFlag flag) + { + if(_flags == null) + return; + Dirtyable obj; + if(_flags.TryGetValue(flag, out obj) && !obj.IsDirty) + { + obj.IsDirty = true; + _flags[flag] = obj; + flag.RaiseFlagDirtied((TObject)this); + } + } + public void ClearAllFlagsWhere(Predicate condition) + { + List flags = new List(_flags.Keys); + foreach(TFlag flag in flags) + if(condition(flag)) + ClearFlag(flag); + } + + public FlagState GetFlagState(TFlag flag) + { + if(_flags == null) + return FlagState.Unknown; + Dirtyable ret; + if(_flags.TryGetValue(flag, out ret)) + return ret.Value ? FlagState.Enabled : FlagState.Disabled; + return FlagState.Unknown; + } + + public FlagState AskForFlag(TFlag flag) + { + return AskForFlag(flag, false, false); + } + public FlagState AskForFlag(TFlag flag, bool acceptDirty, bool forceRefresh) + { + if(forceRefresh) + AutoEvaluateFlag(flag); + if(_flags == null) + return FlagState.Unknown; + Dirtyable ret; + if(_flags.TryGetValue(flag, out ret) && (acceptDirty || !ret.IsDirty)) + return ret.Value ? FlagState.Enabled : FlagState.Disabled; + if(!forceRefresh) + AutoEvaluateFlag(flag); + if(_flags.TryGetValue(flag, out ret) && (acceptDirty || !ret.IsDirty)) + return ret.Value ? FlagState.Enabled : FlagState.Disabled; + return FlagState.Unknown; + } + + public bool IsFlagSet(TFlag flag) + { + return IsFlagSet(flag, false); + } + public bool IsFlagSet(TFlag flag, bool acceptDirty) + { + if(_flags == null) + return false; + if(acceptDirty) + return _flags.ContainsKey(flag); + Dirtyable ret; + return _flags.TryGetValue(flag, out ret) && !ret.IsDirty; + } + public bool IsFlagEnabled(TFlag flag) + { + return IsFlagEnabled(flag, false); + } + public bool IsFlagEnabled(TFlag flag, bool acceptDirty) + { + if(_flags == null) + return false; + Dirtyable ret; + return _flags.TryGetValue(flag, out ret) && ret.Value && (acceptDirty || !ret.IsDirty); + } + public bool IsFlagDisabled(TFlag flag) + { + return IsFlagDisabled(flag, false); + } + public bool IsFlagDisabled(TFlag flag, bool acceptDirty) + { + if(_flags == null) + return false; + Dirtyable ret; + return _flags.TryGetValue(flag, out ret) && !ret.Value && (acceptDirty || !ret.IsDirty); + } + public bool IsFlagUnknown(TFlag flag) + { + if(_flags == null) + return true; + return !_flags.ContainsKey(flag); + } + public bool IsFlagDirty(TFlag flag) + { + if(_flags == null) + return false; + Dirtyable obj; + return _flags.TryGetValue(flag, out obj) && obj.IsDirty; + } + + public void AutoEvaluateFlag(TFlag flag) + { + OnAutoEvaluateFlag(flag); + } + + protected virtual void OnAutoEvaluateFlag(TFlag flag) + { + } + + private void WireFlagEventTriggers(TFlag flag) + { + foreach(KeyValuePair> trigger in flag.EventFlagTriggers) + { + List> list; + if(!_flagEventTriggers.TryGetValue(trigger.Key, out list)) + { + list = new List>(); + _flagEventTriggers.Add(trigger.Key, list); + } + list.Add(trigger.Value); + } + } + private void UnwireFlagEventTriggers(TFlag flag) + { + foreach(KeyValuePair> trigger in flag.EventFlagTriggers) + { + List> list; + if(!_flagEventTriggers.TryGetValue(trigger.Key, out list)) + continue; + list.Remove(trigger.Value); + if(list.Count == 0) + _flagEventTriggers.Remove(trigger.Key); + } + } + #endregion + + #region Event Aspects + public void AddHandler(TEvent eventId, Delegate handler) + { + if(!eventId.IsValidHandler(handler)) + throw new ArgumentException(); + if(_handlers == null) + _handlers = new Dictionary(); + Delegate list; + if(_handlers.TryGetValue(eventId, out list)) + _handlers[eventId] = Delegate.Combine(list, handler); + else + _handlers[eventId] = handler; + } + public void RemoveHandler(TEvent eventId, Delegate handler) + { + if(_handlers == null) + return; + Delegate list; + if(_handlers.TryGetValue(eventId, out list)) + { + list = Delegate.Remove(list, handler); + if(list == null || list.GetInvocationList().Length == 0) + _handlers.Remove(eventId); + else + _handlers[eventId] = list; + } + } + public void ClearHandlers(TEvent eventId) + { + if(_handlers == null) + return; + _handlers.Remove(eventId); + } + public bool HasHandler(TEvent eventId) + { + if(_handlers == null) + return false; + return _handlers.ContainsKey(eventId); + } + //public void RaiseEvent(TEvent eventId, EventArgs e) + //{ + // if(_handlers == null) + // return; + // Delegate list; + // if(_handlers.TryGetValue(eventId, out list)) + // { + // list.DynamicInvoke(this, e); + // } + //} + public void RaiseEvent(TEvent eventId, TEventArgs e) + where TEventArgs : EventArgs + { + // Call Event Handlers + if(_handlers != null) + { + Delegate list; + if(_handlers.TryGetValue(eventId, out list)) + { + EventHandler handler = (EventHandler)list; + handler(this, e); + } + } + + // Handle Property Event Triggers + List> propertyTriggers; + if(_propertyEventTriggers != null + && _propertyEventTriggers.TryGetValue(eventId, out propertyTriggers)) + for(int i= propertyTriggers.Count - 1; i>=0; i--) + { + TriggerableEventTrigger trigger = propertyTriggers[i]; + switch(trigger.Action) + { + case EventTriggerAction.Clear: + ClearProperty(trigger.Aspect); + break; + case EventTriggerAction.Dirty: + DirtyPropertyIfSet(trigger.Aspect); + break; + case EventTriggerAction.Reevaluate: + OnAutoEvaluateProperty(trigger.Aspect); + break; + } + } + + // Handle Flag Event Triggers + List> flagTriggers; + if(_flagEventTriggers != null + && _flagEventTriggers.TryGetValue(eventId, out flagTriggers)) + for(int i= flagTriggers.Count - 1; i>=0; i--) + { + TriggerableEventTrigger trigger = flagTriggers[i]; + switch(trigger.Action) + { + case EventTriggerAction.Clear: + ClearFlag(trigger.Aspect); + break; + case EventTriggerAction.Dirty: + DirtyFlagIfSet(trigger.Aspect); + break; + case EventTriggerAction.Disable: + DisableFlag(trigger.Aspect); + break; + case EventTriggerAction.Enable: + EnableFlag(trigger.Aspect); + break; + case EventTriggerAction.Reevaluate: + OnAutoEvaluateFlag(trigger.Aspect); + break; + } + } + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/Dirtyable.cs b/Backup/src/app/MathNet.Yttrium/Fundament/Dirtyable.cs new file mode 100644 index 0000000..5cbcc53 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/Dirtyable.cs @@ -0,0 +1,39 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + internal struct Dirtyable + { + internal T Value; + internal bool IsDirty; + + public Dirtyable(T value) + { + Value = value; + IsDirty = false; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/EventAspect.cs b/Backup/src/app/MathNet.Yttrium/Fundament/EventAspect.cs new file mode 100644 index 0000000..a32c93c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/EventAspect.cs @@ -0,0 +1,71 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IEventAspectHost + where TFriendlyIdentifier : IEquatable, IComparable + where TEvent : EventAspect + { + void RaiseEvent(TEvent eventId, TEventArgs e) + where TEventArgs : EventArgs; + } + + public abstract class EventAspect + : Identifier + where TFriendlyIdentifier : IEquatable, IComparable + where TEvent : EventAspect + { + private Type _handlerType; + private Type _ownerType; + + public EventAspect(TFriendlyIdentifier friendly, Type handlerType, Type ownerType, IdentifierService service) + : base(friendly, service) + { + _handlerType = handlerType; + _ownerType = ownerType; + } + + public Type HandlerType + { + get { return _handlerType; } + } + + public Type OwnerType + { + get { return _ownerType; } + } + + public bool IsValidHandlerType(Type type) + { + return _handlerType.IsAssignableFrom(type); + } + public bool IsValidHandler(Delegate value) + { + return _handlerType.IsInstanceOfType(value); + //return _handlerType.IsAssignableFrom(value.GetType()); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/EventTrigger.cs b/Backup/src/app/MathNet.Yttrium/Fundament/EventTrigger.cs new file mode 100644 index 0000000..ac03d59 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/EventTrigger.cs @@ -0,0 +1,67 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public enum EventTriggerAction + { + /// Do nothing + Nothing = 0, + /// Clear the property or flag + Clear, + /// Disable the flag + Disable, + /// Enable the flag + Enable, + /// Mark the property or flag as dirty + Dirty, + /// Reevaluate the property or flag + Reevaluate + } + + public class EventTrigger + where TIdentifier : IEquatable, IComparable + where TEvent : EventAspect + { + private TEvent[] _events; + private EventTriggerAction _action; + + public EventTrigger(EventTriggerAction action, params TEvent[] events) + { + _action = action; + _events = events; + } + + public EventTriggerAction Action + { + get { return _action; } + } + + public IEnumerable Events + { + get { return _events; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/FlagAspect.cs b/Backup/src/app/MathNet.Yttrium/Fundament/FlagAspect.cs new file mode 100644 index 0000000..f4ffcef --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/FlagAspect.cs @@ -0,0 +1,64 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public enum FlagState + { + Unknown = 0, + Enabled, + Disabled + } + + public abstract class FlagAspect + : TriggerableAspect + where TIdentifier : IEquatable, IComparable + where TEvent : EventAspect + where TFlag : FlagAspect + where TProperty : PropertyAspect + { + + public FlagAspect(TIdentifier friendly, Type ownerType, IdentifierService service) + : base(friendly, ownerType, service) + { + } + + internal void RaiseFlagChanged(THost host, FlagState oldState, FlagState newState) + where THost : IEventAspectHost + { + OnFlagChanged(host, oldState, newState); + } + protected abstract void OnFlagChanged(THost host, FlagState oldState, FlagState newState) + where THost : IEventAspectHost; + + internal void RaiseFlagDirtied(THost host) + where THost : IEventAspectHost + { + OnFlagDirtied(host); + } + protected abstract void OnFlagDirtied(THost host) + where THost : IEventAspectHost; + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/Identifier.cs b/Backup/src/app/MathNet.Yttrium/Fundament/Identifier.cs new file mode 100644 index 0000000..69b5d5a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/Identifier.cs @@ -0,0 +1,85 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public class Identifier + : IEquatable>, + IComparable> + where TFriendlyIdentifier + : IEquatable, + IComparable + { + private TFriendlyIdentifier _friendly; + private Guid _id; + + public Identifier(TFriendlyIdentifier friendly, IdentifierService owner) + { + _friendly = friendly; + _id = Guid.NewGuid(); + if(owner != null) + owner.RegisterIdentifier(this); // should fail if friendly already exists -> construction fails + } + + public TFriendlyIdentifier Friendly + { + get { return _friendly; } + } + + public int CompareTo(Identifier other) + { + return _id.CompareTo(other._id); + } + public bool Equals(Identifier other) + { + if(other == null) + return false; + return _id.Equals(other._id); + } + public override int GetHashCode() + { + return _id.GetHashCode(); + } + public override bool Equals(object obj) + { + Identifier id = obj as Identifier; + if(id == null) + return false; + return Equals(id); + } + public static bool operator ==(Identifier left, Identifier right) + { + if(object.ReferenceEquals(left, right)) + return true; + if((object)left == null || (object)right == null) + return false; + return left.Equals(right); + } + public static bool operator !=(Identifier left, Identifier right) + { + return !(left == right); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/IdentifierDictionary.cs b/Backup/src/app/MathNet.Yttrium/Fundament/IdentifierDictionary.cs new file mode 100644 index 0000000..5e3836d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/IdentifierDictionary.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public class IdentifierDictionary + : Dictionary, TValue> + where TFriendlyIdentifier + : IEquatable, + IComparable + { + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/IdentifierService.cs b/Backup/src/app/MathNet.Yttrium/Fundament/IdentifierService.cs new file mode 100644 index 0000000..c69054a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/IdentifierService.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public interface IdentifierService + where TFriendlyIdentifier : IEquatable, IComparable + { + Identifier LookupIdentifier(TFriendlyIdentifier friendly); + bool TryLookupIdentifier(TFriendlyIdentifier friendly, out Identifier identifier); + bool ContainsIdentifier(TFriendlyIdentifier friendly); + void RegisterIdentifier(Identifier identifier); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Fundament/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..60317db --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Fundament")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("fbdfabfa-39d4-4a8f-a879-134bd6b0590b")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/PropertyAspect.cs b/Backup/src/app/MathNet.Yttrium/Fundament/PropertyAspect.cs new file mode 100644 index 0000000..2e56b29 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/PropertyAspect.cs @@ -0,0 +1,75 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Collections.ObjectModel; + +namespace MathNet.Symbolics +{ + public abstract class PropertyAspect + : TriggerableAspect + where TIdentifier : IEquatable, IComparable + where TEvent : EventAspect + where TFlag : FlagAspect + where TProperty : PropertyAspect + { + private Type _valueType; + + public PropertyAspect(TIdentifier friendly, Type valueType, Type ownerType, IdentifierService service) + : base(friendly, ownerType, service) + { + _valueType = valueType; + } + + public Type ValueType + { + get { return _valueType; } + } + + public bool IsValidValueType(Type type) + { + return _valueType.IsAssignableFrom(type); + } + public bool IsValidValue(object value) + { + return _valueType.IsInstanceOfType(value); + //return _valueType.IsAssignableFrom(value.GetType()); + } + + internal void RaisePropertyChanged(THost host, object oldValue, object newValue) + where THost : IEventAspectHost + { + OnPropertyChanged(host, oldValue, newValue); + } + protected abstract void OnPropertyChanged(THost host, object oldValue, object newValue) + where THost : IEventAspectHost; + + internal void RaisePropertyDirtied(THost host) + where THost : IEventAspectHost + { + OnPropertyDirtied(host); + } + protected abstract void OnPropertyDirtied(THost host) + where THost : IEventAspectHost; + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/TriggerableAspect.cs b/Backup/src/app/MathNet.Yttrium/Fundament/TriggerableAspect.cs new file mode 100644 index 0000000..690a3fa --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/TriggerableAspect.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + internal class TriggerableEventTrigger + where TIdentifier : IEquatable, IComparable + where TEvent : EventAspect + where TFlag : FlagAspect + where TProperty : PropertyAspect + where TAspect : TriggerableAspect + { + private TEvent _event; + private TAspect _aspect; + private EventTriggerAction _action; + + internal TriggerableEventTrigger(TEvent eventId, TAspect aspect, EventTriggerAction action) + { + _event = eventId; + _aspect = aspect; + _action = action; + } + + public TEvent Event + { + get { return _event; } + } + + public TAspect Aspect + { + get { return _aspect; } + } + + public EventTriggerAction Action + { + get { return _action; } + } + } + + internal class TriggerableTriggers + where TIdentifier : IEquatable, IComparable + where TEvent : EventAspect + where TFlag : FlagAspect + where TProperty : PropertyAspect + where TAspect : TriggerableAspect + { + private Dictionary> _eventTriggers; + + private void EnsureInit() + { + if(_eventTriggers == null) + _eventTriggers = new Dictionary>(); + } + + public Dictionary> EventTriggers + { + get + { + EnsureInit(); + return _eventTriggers; + } + } + + public void AddEventTrigger(EventTrigger trigger, TAspect aspect) + { + EnsureInit(); + AddEventTriggerImpl(trigger, aspect); + } + public void AddEventTrigger(IEnumerable> triggers, TAspect aspect) + { + EnsureInit(); + foreach(EventTrigger trigger in triggers) + AddEventTriggerImpl(trigger, aspect); + } + private void AddEventTriggerImpl(EventTrigger trigger, TAspect aspect) + { + EventTriggerAction action = trigger.Action; + foreach(TEvent eventId in trigger.Events) + _eventTriggers.Add(eventId, + new TriggerableEventTrigger(eventId, aspect, action)); + } + } + + public class TriggerableAspect + : Identifier + where TIdentifier : IEquatable, IComparable + where TEvent : EventAspect + where TFlag : FlagAspect + where TProperty : PropertyAspect + { + private Type _ownerType; + TriggerableTriggers _eventFlagTriggers; + TriggerableTriggers _eventPropertyTriggers; + + public TriggerableAspect(TIdentifier friendly, Type ownerType, IdentifierService service) + : base(friendly, service) + { + _ownerType = ownerType; + _eventFlagTriggers = new TriggerableTriggers(); + _eventPropertyTriggers = new TriggerableTriggers(); + } + + public Type OwnerType + { + get { return _ownerType; } + } + + internal Dictionary> EventFlagTriggers + { + get { return _eventFlagTriggers.EventTriggers; } + } + internal Dictionary> EventPropertyTriggers + { + get { return _eventPropertyTriggers.EventTriggers; } + } + + protected void AddEventFlagTrigger(EventTrigger trigger, TFlag flag) + { + _eventFlagTriggers.AddEventTrigger(trigger, flag); + } + protected void AddEventPropertyTrigger(EventTrigger trigger, TProperty property) + { + _eventPropertyTriggers.AddEventTrigger(trigger, property); + } + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Fundament/Yttrium.Fundament.csproj b/Backup/src/app/MathNet.Yttrium/Fundament/Yttrium.Fundament.csproj new file mode 100644 index 0000000..fa094ed --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Fundament/Yttrium.Fundament.csproj @@ -0,0 +1,56 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Fundament + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Exceptions/ParsingException.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Exceptions/ParsingException.cs new file mode 100644 index 0000000..90e8ec0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Exceptions/ParsingException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class ParsingException : YttriumException + { + public ParsingException() + : base() + { + } + + public ParsingException(string message) + : base(message) + { + } + + public ParsingException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected ParsingException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Interpreter/IParser.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Interpreter/IParser.cs new file mode 100644 index 0000000..a86ac4d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Interpreter/IParser.cs @@ -0,0 +1,35 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace MathNet.Symbolics.Interpreter +{ + public interface IParser + { + void Interpret(TextReader reader, IMathSystem system); + void Interpret(string expression, IMathSystem system); + void Interpret(FileInfo file, IMathSystem system); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e178f15 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Interpreter Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("b8223b5a-6b8c-417b-a6fe-47dd2b8fb458")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Yttrium.Interpreter.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Yttrium.Interpreter.Contracts.csproj new file mode 100644 index 0000000..3940b8c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Contracts/Yttrium.Interpreter.Contracts.csproj @@ -0,0 +1,58 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Interpreter.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/EntityStack.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/EntityStack.cs new file mode 100644 index 0000000..3c5a412 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/EntityStack.cs @@ -0,0 +1,136 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Interpreter +{ + // TODO: Replace with .NET 2.0 generic stack + + /// + /// Entity Stack with auto expansion. + /// + public sealed class EntityStack + { + private IEntity[] stack; + private int count; + private int maxSize; + + public EntityStack(int minSize, int maxSize) + { + this.maxSize = maxSize; + // Find first power of 2 >= to requested size + int size; + if(minSize < 0) + { + Init(16); + return; + } + // check for overflow + if(minSize >= (Int32.MaxValue / 2)) + { + Init(Int32.MaxValue); + return; + } + for(size = 2; size < minSize; size *= 2) ; + Init(size); + } + + /// The current count of elements in the stack + public int Count + { + get { return count; } + } + + /// The current size of the stack. + public int Size + { + get { return stack.Length; } + } + + private void Init(int size) + { + stack = new IEntity[size]; + count = 0; + } + + /// Add a new item to the top of the stack. + /// The item to add. + public void Push(IEntity item) + { + if(count == stack.Length) + Expand(); + stack[count++] = item; + } + + /// Returns and removes the item on top of the stack. + /// The item that was on the stack's top. + public IEntity Pop() + { + IEntity token = stack[--count]; + stack[count] = null; //remove reference to allow GC to do its job... + return token; + } + + /// Returns (without removing) the item on top of the stack. + /// The item that is on the stack's top. + public IEntity Peek() + { + return stack[count - 1]; + } + + /// Removes the item on top of the stack and returns the new item on top if the stack + /// The item that now is the stack's top (after removement). + public IEntity PopPeek() + { + stack[--count] = null; //remove reference to allow GC to do its job... + return stack[count - 1]; + } + + /// Removes the item on top of the stack. + public void Remove() + { + stack[--count] = null; //remove reference to allow GC to do its job... + } + + /// Gets items form the stack, starting from the top. Zero Based. + public IEntity this[int index] + { + get { return stack[count - 1 - index]; } + } + + private void Expand() + { + if(maxSize > 0 && stack.Length * 2 > maxSize) + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Maximum token stack size exceeded."); + IEntity[] newStack = new IEntity[stack.Length * 2]; + for(int i = 0; i < stack.Length; i++) + newStack[i] = stack[i]; + stack = newStack; + } + + /// Reset the stack, remove all items. + public void Reset() + { + count = 1; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/Int32Stack.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/Int32Stack.cs new file mode 100644 index 0000000..1bdf2cb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/Int32Stack.cs @@ -0,0 +1,135 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Interpreter +{ + // TODO: Replace with .NET 2.0 generic stack + + /// + /// Int32 Stack with auto expansion. + /// + internal sealed class Int32Stack + { + private int[] stack; + private int count; + private int maxSize; + + public Int32Stack(int minSize, int maxSize) + { + this.maxSize = maxSize; + // Find first power of 2 >= to requested size + int size; + if(minSize < 0) + { + Init(16); + return; + } + // check for overflow + if(minSize >= (Int32.MaxValue / 2)) + { + Init(Int32.MaxValue); + return; + } + for(size = 2; size < minSize; size *= 2) ; + Init(size); + } + + /// The current count of elements in the stack + public int Count + { + get { return count - 1; } + } + + /// The current size of the stack. + public int Size + { + get { return stack.Length - 1; } + } + + private void Init(int size) + { + stack = new int[size]; + stack[0] = 0; + count = 1; + } + + /// Add a new item to the top of the stack. + /// The item to add. + public void Push(int item) + { + if(count == stack.Length) + Expand(); + stack[count++] = item; + } + + /// Returns and removes the item on top of the stack. + /// The item that was on the stack's top. + public int Pop() + { + return stack[--count]; + } + + /// Returns (without removing) the item on top of the stack. + /// The item that is on the stack's top. + public int Peek() + { + return stack[count - 1]; + } + + /// Removes the item on top of the stack and returns the new item on top if the stack + /// The item that now is the stack's top (after removement). + public int PopPeek() + { + count--; + return stack[count - 1]; + } + + /// Removes the item on top of the stack. + public void Remove() + { + count--; + } + + /// Gets items form the stack, starting from the top. Zero Based. + public int this[int index] + { + get { return stack[count - 1 - index]; } + } + + private void Expand() + { + if(maxSize > 0 && stack.Length * 2 > maxSize) + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Maximum marker stack size exceeded."); + int[] newStack = new int[stack.Length * 2]; + for(int i = 0; i < stack.Length; i++) + newStack[i] = stack[i]; + stack = newStack; + } + + /// Reset the stack, remove all items. + public void Reset() + { + count = 1; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerBuffer.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerBuffer.cs new file mode 100644 index 0000000..7c17c85 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerBuffer.cs @@ -0,0 +1,214 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.IO; + +namespace MathNet.Symbolics.Interpreter +{ + /// + /// Circular char fifo/queue buffer with auto expansion. + /// + internal sealed class LexerBuffer + { + private TextReader reader; + private char[] buffer; + private int sizeLessOne; + private int offset; //physical index of front token + private int count; + private int maxSize; + + public LexerBuffer(int minSize, int maxSize, TextReader reader) + { + this.maxSize = maxSize; + this.reader = reader; + Init(minSize); + } + + public int Count + { + get { return count; } + } + + public int Size + { + get { return sizeLessOne + 1; } + } + + /// Fetch a token from the queue by index + /// The index of the token to fetch, where zero is the token at the front of the queue + public char ElementAt(int index) + { + if(count <= index) + RefillBuffer(index - count + 1); + return buffer[(offset + index) & sizeLessOne]; + } + + #region Append and Remove Buffer Content + /// Add token to end of the queue + /// The token to add + private void Append(char token) + { + if(count == buffer.Length) + Expand(); + buffer[(offset + count) & sizeLessOne] = token; + count++; + } + + /// Remove char from the front of the queue + public void RemoveFirst() + { + if(count == 0) + RefillBuffer(1); + offset = (offset + 1) & sizeLessOne; + count--; + } + + /// Remove count of chars from the front of the queue + public void RemoveBlock(int amount) + { + if(count < amount) + RefillBuffer(amount - count); + offset = (offset + amount) & sizeLessOne; + count -= amount; + } + #endregion + + #region Buffer Maintenance + /// Expand the token buffer by doubling its capacity + private void Expand() + { + if(maxSize > 0 && buffer.Length * 2 > maxSize) + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Maximum lexer buffer size exceeded."); + char[] newBuffer = new char[buffer.Length * 2]; + for(int i = 0; i < buffer.Length; i++) + newBuffer[i] = buffer[(offset + i) & sizeLessOne]; + buffer = newBuffer; + sizeLessOne = buffer.Length - 1; + offset = 0; + } + + private void RefillBuffer(int minimumDeltaCount) + { + //This method is that big because we try to read faster + //in large blocks instead of every single character in a loop, + //so we need to handle different buffer states different ... + while(minimumDeltaCount > sizeLessOne + 1 - count) + Expand(); + if(count == 0) + { + offset = 0; + count = reader.Read(buffer, 0, sizeLessOne + 1); + if(count < minimumDeltaCount) + count += reader.ReadBlock(buffer, count, sizeLessOne + 1 - count); + if(count < minimumDeltaCount) + { + FillBufferEof(minimumDeltaCount - count); + return; + } + } + else + { + int tail = (offset + count) & sizeLessOne; + if(tail > offset) + { + int read = reader.Read(buffer, tail, sizeLessOne + 1 - tail); + if(read < minimumDeltaCount && read < sizeLessOne + 1 - tail) + read += reader.ReadBlock(buffer, tail + read, sizeLessOne + 1 - tail - read); + count += read; + if(read < minimumDeltaCount) + { + if(read < sizeLessOne + 1 - tail) + { + FillBufferEof(sizeLessOne + 1 - tail - read); + return; + } + int read2 = reader.Read(buffer, 0, offset); + if(read + read2 < minimumDeltaCount) + read2 += reader.ReadBlock(buffer, read2, offset - read2); + count += read2; + if(read + read2 < minimumDeltaCount) + { + FillBufferEof(minimumDeltaCount - (read + read2)); + return; + } + } + } + else + { + int read = reader.Read(buffer, tail, offset - tail); + if(read < minimumDeltaCount) + read += reader.ReadBlock(buffer, tail + read, offset - tail - read); + count += read; + if(read < minimumDeltaCount) + { + FillBufferEof(minimumDeltaCount - read); + return; + } + } + } + } + private void FillBufferEof(int amount) + { + char eof = char.MaxValue; + for(int i = 0; i < amount; i++) + buffer[(offset + count++) & sizeLessOne] = eof; + } + + private void Init(int minSize) + { + int size; + if(minSize < 0) + { + size = 16; + } + else if(minSize >= (Int32.MaxValue / 2)) + { + size = Int32.MaxValue; + } + else + { + for(size = 2; size < minSize; size *= 2) ; + } + buffer = new char[size]; + sizeLessOne = size - 1; + offset = 0; + count = 0; + } + #endregion + + #region Reset + /// Clear the queue. Replace the current stream with a new one. + public void Reset(TextReader reader) + { + offset = 0; + count = 0; + this.reader = reader; + } + /// Clear the queue. Leaving the previous buffer alone. + public void Reset() + { + offset = 0; + count = 0; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerMarker.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerMarker.cs new file mode 100644 index 0000000..4e565f5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerMarker.cs @@ -0,0 +1,112 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.IO; + +namespace MathNet.Symbolics.Interpreter +{ + internal sealed class LexerMarker + { + private LexerBuffer buffer; + private Int32Stack markers; + + private int markerOffset; // = 0; + private int markerCount; // = 0; + private int consumeOffset; // = 0; + + public LexerMarker(TextReader reader) + { + buffer = new LexerBuffer(16, 4096, reader); + markers = new Int32Stack(16, 4096); + } + + public void Consume() + { + consumeOffset++; + if(markerCount == 0 && consumeOffset > (buffer.Size << 2)) + { + buffer.RemoveBlock(consumeOffset); + consumeOffset = 0; + } + } + + public char LookaheadCharacter(int index) + { + return buffer.ElementAt(consumeOffset + index); + } + + public char LookaheadFistCharacter + { + get { return buffer.ElementAt(consumeOffset); } + } + + #region Marker + public void Mark() + { + if(markerCount++ == 0) + { + buffer.RemoveBlock(consumeOffset); + consumeOffset = 0; + } + markerOffset = consumeOffset; + markers.Push(consumeOffset); + } + + public void CommitMark() + { + markerCount--; + //Returns 0 if the last item was removed. + markerOffset = markers.PopPeek(); + if(markerCount == 0) + { + buffer.RemoveBlock(consumeOffset); + consumeOffset = 0; + } + } + + public void RollbackMark() + { + markerCount--; + consumeOffset = markers.Pop(); + markerOffset = consumeOffset; + } + #endregion + + #region Reset + /// Clear the buffer. Replace the current stream with a new one. + public void Reset(TextReader reader) + { + consumeOffset = 0; + markerOffset = 0; + buffer.Reset(reader); + markers.Reset(); + } + public void Reset() + { + consumeOffset = 0; + markerOffset = 0; + buffer.Reset(); + markers.Reset(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerScanner.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerScanner.cs new file mode 100644 index 0000000..57c096d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerScanner.cs @@ -0,0 +1,456 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Text; +using System.IO; +using System.Globalization; + +using MathNet.Symbolics; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Interpreter +{ + public sealed class LexerScanner + { + private LexerMarker lexer; + private ILibrary library; + private const char eof = char.MaxValue; + + private char executorCharacter, seperatorCharacter; + private EncapsulationFormat listEncapsulation, vectorEncapsulation, setEncapsulation, scalarEncapsulation, literalEncapsulation; + private readonly NumberFormatInfo numberFormat = Config.InternalNumberFormat; + + public LexerScanner(TextReader reader) + { + if(reader == null) + throw new ArgumentNullException("reader"); + + this.lexer = new LexerMarker(reader); + this.library = Service.Instance; + + this.executorCharacter = Config.ExecutorCharacter; + this.seperatorCharacter = Config.SeparatorCharacter; + this.listEncapsulation = Config.ListEncapsulation; + this.vectorEncapsulation = Config.VectorEncapsulation; + this.setEncapsulation = Config.SetEncapsulation; + this.scalarEncapsulation = Config.ScalarEncapsulation; + this.literalEncapsulation = Config.LiteralEncapsulation; + } + + public LexerToken NextToken() + { + char beginChar = lexer.LookaheadFistCharacter; + if(IsWhitespaceCharacter(beginChar)) + { + ScanSkipWhiteSpace(); + beginChar = lexer.LookaheadFistCharacter; + } + if(IsOpeningLiteralCharacter(beginChar)) + return ScanLiteral(); + if(IsNumberCharacter(beginChar)) + return ScanNumber(); + if(IsMarkerCharacter(beginChar)) + return ScanMarkers(); + if(IsBeginTextIdentifierCharacter(beginChar)) + return ScanTextIdentifier(); + if(IsOpeningPunctuationCharacter(beginChar)) + return ScanOpeningPunctuation(); + if(IsClosingPunctuationCharacter(beginChar)) + return ScanClosingPunctuation(); + if(IsSeparatorExecutorCharacter(beginChar)) + return ScanSeparatorExecutor(); + if(IsEndOfLineCharacter(beginChar)) + return ScanEndOfLine(); + if(IsEndOfFileCharacter(beginChar)) + return ScanEndOfFile(); + if(IsSymbolIdentifierCharacter(beginChar)) + return ScanSymbolIdentifier(); + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Lexer Scanner detected unexpected token '" + beginChar + "'"); + } + + #region Scanners + private void ScanSkipWhiteSpace() + { + while(IsWhitespaceCharacter(lexer.LookaheadFistCharacter)) + lexer.Consume(); + } + + private static LexerToken ScanEndOfFile() + { + return new LexerToken(eof.ToString(), TokenTypes.EndOfFile); + } + + private LexerToken ScanEndOfLine() + { + StringBuilder sb = new StringBuilder(); + do + { + while(IsWhitespaceCharacter(lexer.LookaheadFistCharacter)) + lexer.Consume(); + while(IsEndOfLineCharacter(lexer.LookaheadFistCharacter)) + { + sb.Append(lexer.LookaheadFistCharacter); + lexer.Consume(); + } + } + while(IsWhitespaceCharacter(lexer.LookaheadFistCharacter)); + //return new LexerToken("\n",TokenTypes.EndOfLine); + return NextToken(); + } + + private LexerToken ScanSeparatorExecutor() + { + char c = lexer.LookaheadFistCharacter; + lexer.Consume(); + if(c == executorCharacter) + return new LexerToken(executorCharacter.ToString(), TokenTypes.Executor); + return new LexerToken(seperatorCharacter.ToString(), TokenTypes.Separator); + } + + private LexerToken ScanMarkers() + { + if(lexer.LookaheadCharacter(1) == '_' && IsTextIdentifierCharacter(lexer.LookaheadCharacter(2)) + || lexer.LookaheadCharacter(1) != '_' && IsTextIdentifierCharacter(lexer.LookaheadCharacter(1))) + { + char c = lexer.LookaheadFistCharacter; + lexer.Consume(); + LexerToken t = ScanTextIdentifier(); + t.Text = c + t.Text; + //t.Types |= TokenTypes.Marked; + return t; + } + return ScanSymbolIdentifier(); + } + + private LexerToken ScanTextIdentifier() + { + StringBuilder sb = new StringBuilder(); + lexer.Mark(); + bool mathId = false; + while(IsTextIdentifierCharacter(lexer.LookaheadFistCharacter)) + { + sb.Append(lexer.LookaheadFistCharacter); + lexer.Consume(); + } + if(lexer.LookaheadFistCharacter == '.' && IsBeginTextIdentifierCharacter(lexer.LookaheadCharacter(1))) + { + mathId = true; + sb.Append('.'); + lexer.Consume(); + while(IsTextIdentifierCharacter(lexer.LookaheadFistCharacter)) + { + sb.Append(lexer.LookaheadFistCharacter); + lexer.Consume(); + } + } + if(sb.Length == 1 && sb[0] == '_') + { + lexer.RollbackMark(); + return ScanSymbolIdentifier(); + } + else + { + lexer.CommitMark(); + string s = sb.ToString(); + switch(s) + { + case "define": + return new LexerToken(s, TokenTypes.DefineKeyword); + case "instantiate": + return new LexerToken(s, TokenTypes.InstantiateKeyword); + case "signal": + return new LexerToken(s, TokenTypes.SignalKeyword); + case "bus": + return new LexerToken(s, TokenTypes.BusKeyword); + } + if(mathId) + return new LexerToken(s, TokenTypes.MathIdentifier); + else + return new LexerToken(s, TokenTypes.TextIdentifier); + } + } + + private LexerToken ScanLiteral() + { + StringBuilder sb = new StringBuilder(); + lexer.Consume(); + while(true) + { + char c = lexer.LookaheadFistCharacter; + if(IsClosingLiteralCharacter(c)) + { + if(IsClosingLiteralCharacter(lexer.LookaheadCharacter(1))) + { // character de-stuffing: "" -> " + sb.Append(c); + lexer.Consume(); + lexer.Consume(); + continue; + } + else + break; + } + if(c == eof) + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Unexpected end of file. Did you forget to close a literal encapsulation?"); + sb.Append(c); + lexer.Consume(); + } + lexer.Consume(); + return new LexerToken(sb.ToString(), TokenTypes.Literal); + } + + private string ScanIntegerHelper() + { + StringBuilder sb = new StringBuilder(); + while(IsNumberCharacter(lexer.LookaheadFistCharacter)) + { + sb.Append(lexer.LookaheadFistCharacter); + lexer.Consume(); + } + return sb.ToString(); + } + + private LexerToken ScanNumber() + { + string part1 = ScanIntegerHelper(); + if(lexer.LookaheadFistCharacter == numberFormat.NumberDecimalSeparator[0] && IsNumberCharacter(lexer.LookaheadCharacter(1))) + { + lexer.Consume(); + string part2 = ScanIntegerHelper(); + if(lexer.LookaheadFistCharacter == 'e') + { + lexer.Mark(); + lexer.Consume(); + if(IsNumberCharacter(lexer.LookaheadFistCharacter)) + { + string part3 = ScanIntegerHelper(); + lexer.CommitMark(); + return new LexerToken(part1 + numberFormat.NumberDecimalSeparator + part2 + 'e' + part3, TokenTypes.Real); + } + if(lexer.LookaheadFistCharacter == numberFormat.NegativeSign[0] && IsNumberCharacter(lexer.LookaheadCharacter(1))) + { + lexer.Consume(); + string part3 = ScanIntegerHelper(); + lexer.CommitMark(); + return new LexerToken(part1 + numberFormat.NumberDecimalSeparator + part2 + "e" + numberFormat.NegativeSign + part3, TokenTypes.Real); + } + lexer.RollbackMark(); + } + return new LexerToken(part1 + numberFormat.NumberDecimalSeparator + part2, TokenTypes.Real); + } + return new LexerToken(part1, TokenTypes.Integer); + } + + private LexerToken ScanSymbolIdentifier() + { + if(lexer.LookaheadFistCharacter == '<' && lexer.LookaheadCharacter(1) == '-') + { + lexer.Consume(); lexer.Consume(); + return new LexerToken("<-", TokenTypes.Assignment); + } + else if(lexer.LookaheadFistCharacter == '-' && lexer.LookaheadCharacter(1) == '>') + { + lexer.Consume(); lexer.Consume(); + return new LexerToken("->", TokenTypes.Association); + } + + StringBuilder sb = new StringBuilder(); + sb.Append(lexer.LookaheadFistCharacter); + lexer.Consume(); + while(IsSymbolIdentifierCharacter(lexer.LookaheadFistCharacter) + && library.ContainsEntity(sb.ToString() + lexer.LookaheadFistCharacter)) + { + sb.Append(lexer.LookaheadFistCharacter); + lexer.Consume(); + } + //if(sb[0] == '@' || sb[0] == '#') + // return new LexerToken(sb.ToString(),TokenTypes.SymbolIdentifier | TokenTypes.Marked); + return new LexerToken(sb.ToString(), TokenTypes.SymbolIdentifier); + } + + private LexerToken ScanOpeningPunctuation() + { + if(lexer.LookaheadFistCharacter == '<' && lexer.LookaheadCharacter(1) == '-') + { + lexer.Consume(); lexer.Consume(); + return new LexerToken("<-", TokenTypes.Assignment); + } + else if(lexer.LookaheadFistCharacter == '-' && lexer.LookaheadCharacter(1) == '>') + { + lexer.Consume(); lexer.Consume(); + return new LexerToken("->", TokenTypes.Association); + } + + char c = lexer.LookaheadFistCharacter; + lexer.Consume(); + if(c == scalarEncapsulation.Prefix) + return new LexerToken(scalarEncapsulation.Prefix.ToString(), IsSymbolIdentifierCharacter(c) ? TokenTypes.LeftScalar | TokenTypes.SymbolIdentifier : TokenTypes.LeftScalar); + if(c == setEncapsulation.Prefix) + return new LexerToken(setEncapsulation.Prefix.ToString(), TokenTypes.LeftSet); + if(c == vectorEncapsulation.Prefix) + return new LexerToken(vectorEncapsulation.Prefix.ToString(), TokenTypes.LeftVector); + return new LexerToken(listEncapsulation.Prefix.ToString(), TokenTypes.LeftList); + } + + private LexerToken ScanClosingPunctuation() + { + if(lexer.LookaheadFistCharacter == '<' && lexer.LookaheadCharacter(1) == '-') + { + lexer.Consume(); lexer.Consume(); + return new LexerToken("<-", TokenTypes.Assignment); + } + else if(lexer.LookaheadFistCharacter == '-' && lexer.LookaheadCharacter(1) == '>') + { + lexer.Consume(); lexer.Consume(); + return new LexerToken("->", TokenTypes.Association); + } + + char c = lexer.LookaheadFistCharacter; + lexer.Consume(); + if(c == scalarEncapsulation.Postfix) + return new LexerToken(scalarEncapsulation.Postfix.ToString(), IsSymbolIdentifierCharacter(c) ? TokenTypes.RightScalar | TokenTypes.SymbolIdentifier : TokenTypes.RightScalar); + if(c == setEncapsulation.Postfix) + return new LexerToken(setEncapsulation.Postfix.ToString(), TokenTypes.RightSet); + if(c == vectorEncapsulation.Postfix) + return new LexerToken(vectorEncapsulation.Postfix.ToString(), TokenTypes.RightVector); + return new LexerToken(listEncapsulation.Postfix.ToString(), TokenTypes.RightList); + } + #endregion + + #region Selectors + private static bool IsNumberCharacter(char c) + { + //0..9 + return (c >= '0' && c <= '9'); + } + + private static bool IsTextIdentifierCharacter(char c) + {//a..zA..Z0..9_ + return (c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_'); + } + + private static bool IsBeginTextIdentifierCharacter(char c) + {//a..zA..Z_ + return (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_'); + } + + private static bool IsSymbolIdentifierCharacter(char c) + { + UnicodeCategory cat = char.GetUnicodeCategory(c); + switch(cat) + { + case UnicodeCategory.OtherPunctuation: + case UnicodeCategory.CurrencySymbol: + case UnicodeCategory.MathSymbol: + case UnicodeCategory.ModifierLetter: + case UnicodeCategory.ModifierSymbol: + case UnicodeCategory.DashPunctuation: + case UnicodeCategory.ConnectorPunctuation: + case UnicodeCategory.OtherSymbol: + return true; + case UnicodeCategory.LowercaseLetter: + case UnicodeCategory.UppercaseLetter: + return !IsBeginTextIdentifierCharacter(c); + default: + return false; + } + } + + private static bool IsMarkerCharacter(char c) + { + return c == '@' || c == '#'; + } + + private bool IsSeparatorExecutorCharacter(char c) + { + return c == executorCharacter || c == seperatorCharacter; + } + + private bool IsOpeningPunctuationCharacter(char c) + { + return c == listEncapsulation.Prefix || c == vectorEncapsulation.Prefix + || c == setEncapsulation.Prefix || c == scalarEncapsulation.Prefix; + } + + private bool IsClosingPunctuationCharacter(char c) + { + return c == listEncapsulation.Postfix || c == vectorEncapsulation.Postfix + || c == setEncapsulation.Postfix || c == scalarEncapsulation.Postfix; + } + + private bool IsOpeningLiteralCharacter(char c) + { + return c == literalEncapsulation.Prefix; + } + + private bool IsClosingLiteralCharacter(char c) + { + return c == literalEncapsulation.Postfix; + } + + private static bool IsEndOfFileCharacter(char c) + { + return c == eof; + } + + private static bool IsEndOfLineCharacter(char c) + { + return c == '\n' || c == '\r'; + } + + private static bool IsWhitespaceCharacter(char c) + { + return char.IsWhiteSpace(c); + } + //private bool IsSystemTextIdentifier(string s) + //{ + // return s == "define" || s == "instantiate"; + + // //s.Equals("if") || s.Equals("then") || s.Equals("else") + // //|| s.Equals("elseif") || s.Equals("while") || s.Equals("do") + // //|| s.Equals("for") || s.Equals("end"); + //} + #endregion + + #region Reset + /// Clear the buffer. Replace the current stream with a new one. + public void Reset(TextReader reader) + { + if(reader == null) + throw new ArgumentNullException("reader"); + + lexer.Reset(reader); + + this.executorCharacter = Config.ExecutorCharacter; + this.seperatorCharacter = Config.SeparatorCharacter; + this.listEncapsulation = Config.ListEncapsulation; + this.vectorEncapsulation = Config.VectorEncapsulation; + this.setEncapsulation = Config.SetEncapsulation; + this.scalarEncapsulation = Config.ScalarEncapsulation; + this.literalEncapsulation = Config.LiteralEncapsulation; + } + public void Reset() + { + lexer.Reset(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerToken.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerToken.cs new file mode 100644 index 0000000..1995058 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/LexerToken.cs @@ -0,0 +1,113 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Interpreter +{ + [Flags] + public enum TokenTypes : long + { + Unknown = 0x00000000, + System = 0x00000001, + EndOfFile = 0x00000002, + EndOfLine = 0x00000004, + Integer = 0x00000008, + Real = 0x00000010, + Literal = 0x00000020, + + TextIdentifier = 0x00000040, + SystemTextIdentifier = TextIdentifier | System, + SymbolIdentifier = 0x00000080, + SystemSymbolIdentifier = SymbolIdentifier | System, + MathIdentifier = 0x00000100, + + Left = 0x00000200, + Right = 0x00000400, + + ListEncapsulation = 0x00000800, //() + LeftList = ListEncapsulation | Left, + RightList = ListEncapsulation | Right, + + VectorEncapsulation = 0x00001000, //[] + LeftVector = VectorEncapsulation | Left, + RightVector = VectorEncapsulation | Right, + + SetEncapsulation = 0x00002000, //{} + LeftSet = SetEncapsulation | Left, + RightSet = SetEncapsulation | Right, + + ScalarEncapsulation = 0x00004000, //<> + LeftScalar = ScalarEncapsulation | Left, + RightScalar = ScalarEncapsulation | Right, + + Separator = 0x00008000, //, + Executor = 0x00010000, //; + + DefineKeyword = 0x00100000 | SystemTextIdentifier, + InstantiateKeyword = 0x00200000 | SystemTextIdentifier, + SignalKeyword = 0x00400000 | SystemTextIdentifier, + BusKeyword = 0x00800000 | SystemTextIdentifier, + + Assignment = 0x10000000 | SystemSymbolIdentifier, + Association = 0x20000000 | SystemSymbolIdentifier + } + + public sealed class LexerToken + { + private string text; + private TokenTypes types; + + public LexerToken(string text) + { + this.text = text; + //types = TokenTypes.Unknown; //default value + } + + public LexerToken(string text, TokenTypes types) + { + this.text = text; + this.types = types; + } + + public string Text + { + get { return text; } + set { text = value; } + } + + public TokenTypes Types + { + get { return types; } + set { types = value; } + } + + public bool IsType(TokenTypes types) + { + return (this.types & types) == types; + } + + public override string ToString() + { + return "Token '" + text + "' - " + types.ToString(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/Parser.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/Parser.cs new file mode 100644 index 0000000..3f8e1db --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/Parser.cs @@ -0,0 +1,59 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.IO; + +using MathNet.Symbolics; + +namespace MathNet.Symbolics.Interpreter +{ + public class Parser : IParser + { + private ParserScanner scanner; + + public Parser() + { + } + + public void Interpret(TextReader reader, IMathSystem system) + { + if(scanner == null) + scanner = new ParserScanner(reader, system); + else + scanner.Reset(reader, system); + scanner.AllStatements(); + } + + public void Interpret(string expression, IMathSystem system) + { + Interpret(new StringReader(expression), system); + } + + public void Interpret(FileInfo file, IMathSystem system) + { + if(file == null) + throw new ArgumentNullException("file"); + + Interpret(file.OpenText(), system); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserBuffer.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserBuffer.cs new file mode 100644 index 0000000..470a3f5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserBuffer.cs @@ -0,0 +1,170 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.IO; + +namespace MathNet.Symbolics.Interpreter +{ + /// + /// Circular token fifo/queue buffer with auto expansion. + /// + internal sealed class ParserBuffer + { + private LexerScanner scanner; + private LexerToken[] buffer; + private int sizeLessOne; + private int offset; //physical index of front token + private int count; + private int maxSize; + + public ParserBuffer(int minSize, int maxSize, TextReader reader) + { + this.maxSize = maxSize; + scanner = new LexerScanner(reader); + Init(minSize); + } + + public int Count + { + get { return count; } + } + + public int Size + { + get { return sizeLessOne + 1; } + } + + /// Fetch a token from the queue by index + /// The index of the token to fetch, where zero is the token at the front of the queue + public LexerToken ElementAt(int index) + { + if(count <= index) + RefillBuffer(index - count + 1); + return buffer[(offset + index) & sizeLessOne]; + } + + #region Append and Remove Buffer Content + /// Add token to end of the queue + /// The token to add + private void Append(LexerToken token) + { + if(count == buffer.Length) + Expand(); + buffer[(offset + count) & sizeLessOne] = token; + count++; + } + + /// Remove char from the front of the queue + public void RemoveFirst() + { + if(count == 0) + RefillBuffer(1); + offset = (offset + 1) & sizeLessOne; + count--; + } + + /// Remove count of chars from the front of the queue + public void RemoveBlock(int amount) + { + if(count < amount) + RefillBuffer(amount - count); + offset = (offset + amount) & sizeLessOne; + count -= amount; + } + #endregion + + #region Buffer Maintenance + /// Expand the token buffer by doubling its capacity + private void Expand() + { + if(maxSize > 0 && buffer.Length * 2 > maxSize) + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Maximum parser buffer size exceeded."); + LexerToken[] newBuffer = new LexerToken[buffer.Length * 2]; + for(int i = 0; i < buffer.Length; i++) + newBuffer[i] = buffer[(offset + i) & sizeLessOne]; + buffer = newBuffer; + sizeLessOne = buffer.Length - 1; + offset = 0; + } + + private void RefillBuffer(int minimumDeltaCount) + { + while(minimumDeltaCount > sizeLessOne + 1 - count) + Expand(); + if(count == 0) + { + offset = 0; + count = sizeLessOne + 1; + for(int i = 0; i <= sizeLessOne; i++) + buffer[i] = scanner.NextToken(); + } + else + { + int tail = (offset + count) & sizeLessOne; + for(int i = tail; i != offset; i = ((i + 1) & sizeLessOne)) + { + count++; + buffer[i] = scanner.NextToken(); + } + } + } + + private void Init(int minSize) + { + int size; + if(minSize < 0) + { + size = 16; + } + else if(minSize >= (Int32.MaxValue / 2)) + { + size = Int32.MaxValue; + } + else + { + for(size = 2; size < minSize; size *= 2) ; + } + buffer = new LexerToken[size]; + sizeLessOne = size - 1; + offset = 0; + count = 0; + } + #endregion + + #region Reset + /// Clear the queue. Replace the current stream with a new one. + public void Reset(TextReader reader) + { + offset = 0; + count = 0; + scanner.Reset(reader); + } + /// Clear the queue. Leaving the previous buffer alone. + public void Reset() + { + offset = 0; + count = 0; + scanner.Reset(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserMarker.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserMarker.cs new file mode 100644 index 0000000..c9765b0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserMarker.cs @@ -0,0 +1,171 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.IO; +using System.Text; + +namespace MathNet.Symbolics.Interpreter +{ + internal sealed class ParserMarker + { + private ParserBuffer buffer; + private Int32Stack markers; + + private int markerOffset; // = 0; + private int markerCount; // = 0; + private int consumeOffset; // = 0; + + public ParserMarker(TextReader reader) + { + buffer = new ParserBuffer(16, 4096, reader); + markers = new Int32Stack(16, 4096); + } + + #region Consuming + public void Consume() + { + consumeOffset++; + if(markerCount == 0 && consumeOffset > (buffer.Size << 2)) + { + buffer.RemoveBlock(consumeOffset); + consumeOffset = 0; + } + } + + public LexerToken ConsumeGet() + { + LexerToken t = buffer.ElementAt(consumeOffset); + Consume(); + return t; + } + + public void Match(TokenTypes expected) + { + if(!buffer.ElementAt(consumeOffset).IsType(expected)) + throw new Exceptions.ParsingException(string.Format( + Config.UserCulture, Properties.Resources.ex_Parsing_Failed_TokenMismatch, expected.ToString(), buffer.ElementAt(consumeOffset).Text, CurrentTokenNeighbourhood())); + Consume(); + } + public void Match(TokenTypes expected, string content) + { + if(!buffer.ElementAt(consumeOffset).IsType(expected) || !buffer.ElementAt(consumeOffset).Text.Equals(content)) + throw new Exceptions.ParsingException(string.Format( + Config.UserCulture, Properties.Resources.ex_Parsing_Failed_TokenMismatchEx, expected.ToString(), buffer.ElementAt(consumeOffset).Text, CurrentTokenNeighbourhood(), content)); + Consume(); + } + public void Match(string content) + { + if(!buffer.ElementAt(consumeOffset).Text.Equals(content)) + throw new Exceptions.ParsingException(string.Format( + Config.UserCulture, Properties.Resources.ex_Parsing_Failed_TokenMismatch, content, buffer.ElementAt(consumeOffset).Text, CurrentTokenNeighbourhood())); + Consume(); + } + + public LexerToken MatchGet(TokenTypes expected) + { + LexerToken t = buffer.ElementAt(consumeOffset); + if(!t.IsType(expected)) + throw new Exceptions.ParsingException(string.Format( + Config.UserCulture, Properties.Resources.ex_Parsing_Failed_TokenMismatch, expected.ToString(), t.Text, CurrentTokenNeighbourhood())); + Consume(); + return t; + } + private string CurrentTokenNeighbourhood() + { + int start = Math.Max(0, consumeOffset - 4); + int end = consumeOffset + 4; + StringBuilder sb = new StringBuilder(buffer.ElementAt(start).Text); + for(int i = start + 1; i < end; i++) + { + sb.Append(' '); + sb.Append(buffer.ElementAt(i).Text); + } + return sb.ToString(); + } + #endregion + + public bool IsEndOfFile + { + get { return buffer.ElementAt(consumeOffset).IsType(TokenTypes.EndOfFile); } + } + + public LexerToken LookaheadToken(int index) + { + return buffer.ElementAt(consumeOffset + index); + } + + public LexerToken LookaheadFistToken + { + get { return buffer.ElementAt(consumeOffset); } + } + + #region Marker + public void Mark() + { + if(markerCount++ == 0) + { + buffer.RemoveBlock(consumeOffset); + consumeOffset = 0; + } + markerOffset = consumeOffset; + markers.Push(consumeOffset); + } + + public void CommitMark() + { + markerCount--; + //Returns 0 if the last item was removed. + markerOffset = markers.PopPeek(); + if(markerCount == 0) + { + buffer.RemoveBlock(consumeOffset); + consumeOffset = 0; + } + } + + public void RollbackMark() + { + markerCount--; + consumeOffset = markers.Pop(); + markerOffset = consumeOffset; + } + #endregion + + #region Reset + /// Clear the buffer. Replace the current stream with a new one. + public void Reset(TextReader reader) + { + consumeOffset = 0; + markerOffset = 0; + buffer.Reset(reader); + markers.Reset(); + } + public void Reset() + { + consumeOffset = 0; + markerOffset = 0; + buffer.Reset(); + markers.Reset(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserScanner.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserScanner.cs new file mode 100644 index 0000000..347f58c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/ParserScanner.cs @@ -0,0 +1,866 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; + +using MathNet.Symbolics; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Simulation; + +namespace MathNet.Symbolics.Interpreter +{ + public class ParserScanner + { + private ParserMarker tokenizer; + private ILibrary library; + private IBuilder builder; + private IMathSystem system; + + public ParserScanner(TextReader reader, IMathSystem system) + { + if(system == null) + throw new ArgumentNullException("system"); + if(reader == null) + throw new ArgumentNullException("reader"); + + tokenizer = new ParserMarker(reader); + this.system = system; + this.library = Service.Instance; + this.builder = Service.Instance; + } + + #region OLD System Structures + //private bool IsSystemEndStructure(LexerToken token) + //{ + // if(!token.IsType(TokenTypes.SystemTextIdentifier)) + // return false; + // return !(token.Text.Equals("if") || token.Text.Equals("while") || token.Text.Equals("for")); + //} + //private MathExpression ScanSystemStructure() + //{ + // LexerToken ahead = tokenizer.LookaheadFistToken; + // if(ahead.Text == "if") + // return ScanCondition(); + // if(ahead.Text == "while") + // return ScanWhileLoop(); + // if(ahead.Text == "for") + // return ScanForLoop(); + // throw new UnexpectedTokenParserException(ahead); + //} + //private MathCondition ScanCondition() + //{ + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "if"); + // MathCondition condition = ScanSubCondition(); + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "end"); + // return condition; + //} + //private MathCondition ScanSubCondition() + //{ + // MathExpression condition = ScanTerm(); + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "then"); + // MathExpressionCollection trueStatements = ScanMultipleScopes(); + // if(tokenizer.LookaheadFistToken.IsType(TokenTypes.SystemTextIdentifier)) + // { + // if(tokenizer.LookaheadFistToken.Text == "elseif") + // { + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "elseif"); + // MathCondition sub = ScanSubCondition(); + // return new MathCondition(condition, trueStatements, new MathExpressionCollection(new MathExpression[] { sub })); + // } + // if(tokenizer.LookaheadFistToken.Text == "else") + // { + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "else"); + // return new MathCondition(condition, trueStatements, ScanMultipleScopes()); + // } + // } + // return new MathCondition(condition, trueStatements); + //} + //private MathWhileLoop ScanWhileLoop() + //{ + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "while"); + // MathExpression condition = ScanTerm(); + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "do"); + // MathExpressionCollection statements = ScanMultipleScopes(); + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "end"); + // return new MathWhileLoop(condition, statements); + //} + //private MathForLoop ScanForLoop() + //{ + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "for"); + // MathExpression condition = ScanTerm(); + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "do"); + // MathExpressionCollection statements = ScanMultipleScopes(); + // tokenizer.Match(TokenTypes.SystemTextIdentifier, "end"); + // return new MathForLoop(condition, statements); + //} + #endregion + + public void NextStatement() + { + ScanCommand(); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Executor)) + tokenizer.Match(TokenTypes.Executor); + } + + public void AllStatements() + { + while(!tokenizer.IsEndOfFile) + { + ScanCommand(); + if(!tokenizer.LookaheadFistToken.IsType(TokenTypes.Executor)) + break; + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Executor)) + tokenizer.Match(TokenTypes.Executor); + } + } + + private void ScanCommand() + { + LexerToken t = tokenizer.LookaheadFistToken; + if(t.IsType(TokenTypes.DefineKeyword)) + ScanDefine(); + else if(t.IsType(TokenTypes.InstantiateKeyword)) + ScanInstantiate(); + else if(t.IsType(TokenTypes.SignalKeyword)) + ScanSignalDeclaration(); + else if(t.IsType(TokenTypes.BusKeyword)) + ScanBusDeclaration(); + else if(t.IsType(TokenTypes.TextIdentifier) && tokenizer.LookaheadToken(1).IsType(TokenTypes.Assignment)) + ScanSignalAssignment(); + else + ScanSignalExpression(); + } + + #region Define + private void ScanDefine() + { + tokenizer.Match(TokenTypes.DefineKeyword, "define"); + switch(tokenizer.LookaheadFistToken.Text) + { + case "entity": + ScanDefineEntity(); break; + case "architecture": + ScanDefineArchitecture(); break; + default: + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Parser Scanner detected unexpected definition token '" + tokenizer.LookaheadFistToken.Text + "'"); + } + } + + private IEntity ScanDefineEntity() + { + tokenizer.Match(TokenTypes.TextIdentifier, "entity"); + MathIdentifier entityId = ScanEntityMathIdentifierOrLabel(true); + string symbol = ScanLiteral(); + InfixNotation notation; + switch(tokenizer.MatchGet(TokenTypes.TextIdentifier).Text) + { + case "pre": + notation = InfixNotation.PreOperator; break; + case "post": + notation = InfixNotation.PostOperator; break; + case "left": + notation = InfixNotation.LeftAssociativeInnerOperator; break; + case "right": + notation = InfixNotation.RightAssociativeInnerOperator; break; + default: + notation = InfixNotation.None; break; + } + int precedence = -1; + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.Integer)) + precedence = (int)ScanInteger(); + + string[] inputs, outputs, buses; + if(tokenizer.LookaheadFistToken.Text == "in") + { + tokenizer.Match(TokenTypes.TextIdentifier,"in"); + inputs = ScanTextIdentifierList().ToArray(); + } + else + inputs = new string[0]; + if(tokenizer.LookaheadFistToken.Text == "out") + { + tokenizer.Match(TokenTypes.TextIdentifier, "out"); + outputs = ScanTextIdentifierList().ToArray(); + } + else + outputs = new string[0]; + if(tokenizer.LookaheadFistToken.Text == "bus") + { + tokenizer.Match(TokenTypes.TextIdentifier, "bus"); + buses = ScanTextIdentifierList().ToArray(); + } + else + buses = new string[0]; + IEntity entity = new EntityBase(symbol, entityId,notation,precedence, inputs, outputs, buses); + library.AddEntity(entity); + return entity; + } + + private void ScanDefineArchitecture() + { + tokenizer.Match(TokenTypes.TextIdentifier, "architecture"); + MathIdentifier architectureId = ScanEntityMathIdentifierOrLabel(true); + MathIdentifier entityId = ScanEntityMathIdentifierOrLabel(true); + IEntity entity = library.LookupEntity(entityId); + tokenizer.Match("{"); + IMathSystem originalSystem = system; + IMathSystem tempSystem = Binder.CreateSystem(); + system = tempSystem; + while(tokenizer.LookaheadFistToken.Text != "}") + NextStatement(); + foreach(string input in entity.InputSignals) + tempSystem.PromoteAsInput(tempSystem.LookupNamedSignal(input)); + foreach(string output in entity.OutputSignals) + tempSystem.AddSignalTree(tempSystem.LookupNamedSignal(output), tempSystem.GetAllInputs(), true, false); + ReadOnlySignalSet leafs = tempSystem.GetAllLeafSignals(); + foreach(Signal s in leafs) + { + Signal so; + if(originalSystem.TryLookupNamedSignal(s.Label, out so) && so.Value != null) + s.PostNewValue(so.Value); + } + Service.Instance.SimulateInstant(); + system = originalSystem; + tokenizer.Match("}"); + tempSystem.RemoveUnusedObjects(); + tempSystem.PublishToLibrary(architectureId, entity.EntityId); + } + #endregion + + #region Instantiate + private Port ScanInstantiate() + { + tokenizer.Match(TokenTypes.InstantiateKeyword, "instantiate"); + IEntity entity = ScanEntity(); + Signal[] inputs; //= new Signal[entity.InputSignals.Length]; + Signal[] outputs; // = new Signal[entity.OutputSignals.Length]; + Bus[] buses; // = new Bus[entity.Buses.Length]; + if(tokenizer.LookaheadFistToken.Text == "in") + { + tokenizer.Match(TokenTypes.TextIdentifier, "in"); + if(tokenizer.LookaheadToken(1).IsType(TokenTypes.Association)) + { + List associations = ScanSignalExpressionAssociationList(); + inputs = new Signal[entity.InputSignals.Length]; + foreach(SignalAssociation sa in associations) + inputs[Array.IndexOf(entity.InputSignals, sa.Label)] = sa.Association; + } + else + { + List associations = ScanSignalExpressionList(); + inputs = associations.ToArray(); + } + } + else + inputs = new Signal[entity.InputSignals.Length]; + if(tokenizer.LookaheadFistToken.Text == "out") + { + tokenizer.Match(TokenTypes.TextIdentifier, "out"); + if(tokenizer.LookaheadToken(1).IsType(TokenTypes.Association)) + { + List associations = ScanSignalAssociationList(); + outputs = new Signal[entity.OutputSignals.Length]; + foreach(SignalAssociation sa in associations) + outputs[Array.IndexOf(entity.OutputSignals, sa.Label)] = sa.Association; + } + else + { + List associations = ScanSignalList(); + outputs = associations.ToArray(); + } + } + else + outputs = new Signal[entity.OutputSignals.Length]; + if(tokenizer.LookaheadFistToken.Text == "bus") + { + tokenizer.Match(TokenTypes.TextIdentifier, "bus"); + if(tokenizer.LookaheadToken(1).IsType(TokenTypes.Association)) + { + List associations = ScanBusAssociationList(); + buses = new Bus[entity.Buses.Length]; + foreach(BusAssociation ba in associations) + buses[Array.IndexOf(entity.Buses, ba.Label)] = ba.Association; + } + else + { + List associations = ScanBusList(); + buses = associations.ToArray(); + } + } + else + buses = new Bus[entity.Buses.Length]; + Port port = entity.InstantiatePort(inputs, outputs, buses); + system.AddPortTree(port, false, false); + return port; + } + #endregion + + #region Signal Declaration & Assignment + private Signal ScanSignalDeclaration() + { + tokenizer.Match(TokenTypes.SignalKeyword, "signal"); + if(tokenizer.LookaheadToken(1).IsType(TokenTypes.Assignment)) + return ScanSignalAssignment(); + else + { + string name = tokenizer.MatchGet(TokenTypes.TextIdentifier).Text; + return system.CreateNamedSignal(name); + } + } + + private Signal ScanSignalAssignment() + { + string signalName = ScanTextIdentifier(); + tokenizer.Match(TokenTypes.Assignment, "<-"); + Signal s = ScanSignalExpression(); + system.AddSignalTree(s, false, false); + system.AddNamedSignal(signalName, s); + return s; + } + #endregion + + #region Bus Declaration + private Bus ScanBusDeclaration() + { + tokenizer.Match(TokenTypes.BusKeyword, "bus"); + string name = tokenizer.MatchGet(TokenTypes.TextIdentifier).Text; + return system.CreateNamedBus(name); + } + #endregion + + #region Association + private struct SignalAssociation + { + public string Label; + public Signal Association; + } + private struct BusAssociation + { + public string Label; + public Bus Association; + } + private SignalAssociation ScanSignalAssociation() + { + SignalAssociation sa; + sa.Label = ScanTextIdentifier(); + tokenizer.Match(TokenTypes.Association, "->"); + sa.Association = ScanSignal(); + return sa; + } + private List ScanSignalAssociationList() + { + List associations = new List(); + associations.Add(ScanSignalAssociation()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + associations.Add(ScanSignalAssociation()); + } + return associations; + } + private SignalAssociation ScanSignalExpressionAssociation() + { + SignalAssociation sa; + sa.Label = ScanTextIdentifier(); + tokenizer.Match(TokenTypes.Association, "->"); + sa.Association = ScanSignalExpression(); + return sa; + } + private List ScanSignalExpressionAssociationList() + { + List associations = new List(); + associations.Add(ScanSignalExpressionAssociation()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + associations.Add(ScanSignalExpressionAssociation()); + } + return associations; + } + private BusAssociation ScanBusAssociation() + { + BusAssociation ba; + ba.Label = ScanTextIdentifier(); + tokenizer.Match(TokenTypes.Association, "->"); + ba.Association = ScanBus(); + return ba; + } + private List ScanBusAssociationList() + { + List associations = new List(); + associations.Add(ScanBusAssociation()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + associations.Add(ScanBusAssociation()); + } + return associations; + } + #endregion + + #region Left Unary + private bool IsLeftUnary(LexerToken token) + { + return (token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier)) + && library.ContainsEntity(token.Text, InfixNotation.PreOperator); + } + private bool IsRightUnary(LexerToken token) + { + return (token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier)) + && library.ContainsEntity(token.Text, InfixNotation.PostOperator); + } + private Signal ScanLeftUnary() + { + LexerToken token = tokenizer.ConsumeGet(); + Signal s = ScanOperand(); + return builder.Function(token.Text, InfixNotation.PreOperator, s); + } + #endregion + + #region Signal Expression + private bool IsBinary(LexerToken token) + { + return (token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier)) + && (library.ContainsEntity(token.Text, InfixNotation.LeftAssociativeInnerOperator) + || library.ContainsEntity(token.Text, InfixNotation.RightAssociativeInnerOperator)); + } + private static bool IsPrecedenceLeftFirst(IEntity left, IEntity right) + { + if(left.PrecedenceGroup < right.PrecedenceGroup) + return true; + if(left.PrecedenceGroup > right.PrecedenceGroup) + return false; + if(left.Notation == InfixNotation.LeftAssociativeInnerOperator) + return true; + if(right.Notation == InfixNotation.RightAssociativeInnerOperator) + return false; + return true; + } + private Signal ScanSignalExpression() + { + /* + This method is kind of a postfix machine, parsing + infix expressions to postfix expressions (having + regard to precedence) using the operator stack and + evaluates the postfix term to an expression tree + using the expression stack. + */ + + SignalStack expressionStack = new SignalStack(4, 4096); + EntityStack operatorStack = new EntityStack(4, 4096); + + expressionStack.Push(ScanOperand()); + IEntity lastEntity, topEntity; + + while(true) + { + LexerToken ahead = tokenizer.LookaheadFistToken; + if(!(ahead.IsType(TokenTypes.SymbolIdentifier) || ahead.IsType(TokenTypes.TextIdentifier))) + break; + // TODO: Optimize using TryMethods... + if(library.ContainsEntity(ahead.Text,InfixNotation.LeftAssociativeInnerOperator)) + lastEntity = library.LookupEntity(ahead.Text, InfixNotation.LeftAssociativeInnerOperator, 2, 1, 0); + else if(library.ContainsEntity(ahead.Text, InfixNotation.RightAssociativeInnerOperator)) + lastEntity = library.LookupEntity(ahead.Text, InfixNotation.RightAssociativeInnerOperator, 2, 1, 0); + else + break; + tokenizer.Consume(); + + while(operatorStack.Count > 0 && IsPrecedenceLeftFirst(operatorStack.Peek(), lastEntity)) + { + topEntity = operatorStack.Pop(); + Signal swap = expressionStack.Pop(); + Signal s = builder.Function(topEntity, expressionStack.Pop(), swap); + expressionStack.Push(s); + } + + operatorStack.Push(lastEntity); + expressionStack.Push(ScanOperand()); + } + + while(operatorStack.Count > 0) + { + topEntity = operatorStack.Pop(); + Signal swap = expressionStack.Pop(); + Signal s = builder.Function(topEntity, expressionStack.Pop(), swap); + expressionStack.Push(s); + } + + Signal ret = expressionStack.Pop(); + system.AddSignalTree(ret, false, false); + return ret; + } + private List ScanSignalExpressionList() + { + List signals = new List(); + signals.Add(ScanSignalExpression()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + signals.Add(ScanSignalExpression()); + } + return signals; + } + #endregion + + #region Signal Operand + private Signal ScanOperand() + { + Signal expression = ScanOperandPart(); + while(IsRightUnary(tokenizer.LookaheadFistToken)) + { + LexerToken token = tokenizer.ConsumeGet(); + expression = builder.Function(token.Text, InfixNotation.PostOperator, expression); + } + return expression; + } + private Signal ScanOperandPart() + { + LexerToken ahead = tokenizer.LookaheadFistToken; + if(IsBeginningEncapsulation(ahead)) + return ScanEncapsulation(); + if(IsLeftUnary(ahead)) + return ScanLeftUnary(); + if(ahead.IsType(TokenTypes.TextIdentifier) || ahead.IsType(TokenTypes.SymbolIdentifier)) + return ScanIdentifierInExpression(); + if(ahead.IsType(TokenTypes.Integer)) + return ScanIntegerSignal(); + if(ahead.IsType(TokenTypes.Real)) + return ScanRealSignal(); + if(ahead.IsType(TokenTypes.Literal)) + return ScanLiteralSignal(); + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Parser Scanner detected unexpected operand part token '" + ahead.Text + "'"); + } + #endregion + + #region Identifier Expression + /// Scans a Signal or a Function Expression + private Signal ScanIdentifierInExpression() + { + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.TextIdentifier) + && !tokenizer.LookaheadToken(1).IsType(TokenTypes.LeftList)) + return ScanSignal(); + else + return ScanFunction(); + } + + private Signal ScanFunction() + { + LexerToken token = tokenizer.ConsumeGet(); + List a = ScanList(); + IEntity e = ScanEntity(token, InfixNotation.None, a.Count); + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.LeftVector)) + { + tokenizer.Match(TokenTypes.LeftVector); + long idx = ScanInteger(); + tokenizer.Match(TokenTypes.RightVector); + return builder.Functions(e, a)[(int)idx]; + } + else + return builder.Function(e, a); + } + #endregion + + #region Expression Encapsulations + private static bool IsBeginningEncapsulation(LexerToken token) + { + return token.IsType(TokenTypes.Left); + } + private Signal ScanEncapsulation() + { + LexerToken ahead = tokenizer.LookaheadFistToken; + if(ahead.IsType(TokenTypes.LeftList)) + return ScanParenthesisSignal(); + if(ahead.IsType(TokenTypes.LeftVector)) + return ScanVectorSignal(); + if(ahead.IsType(TokenTypes.LeftSet)) + return ScanSetSignal(); + return ScanScalarSignal(); + } + + private Signal ScanVectorSignal() + { + List inner = ScanVector(); + return builder.EncapsulateAsVector(inner.ToArray()); + } + private List ScanVector() + { + List signals; + tokenizer.Match(TokenTypes.LeftVector); + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.RightVector)) + signals = new List(0); + else + signals = ScanSignalExpressionList(); + tokenizer.Match(TokenTypes.RightVector); + return signals; + } + private Signal ScanSetSignal() + { + List inner = ScanSet(); + return builder.EncapsulateAsSet(inner.ToArray()); + } + private List ScanSet() + { + List signals; + tokenizer.Match(TokenTypes.LeftSet); + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.RightSet)) + signals = new List(0); + else + signals = ScanSignalExpressionList(); + tokenizer.Match(TokenTypes.RightSet); + return signals; + } + private Signal ScanScalarSignal() + { + List inner = ScanScalar(); + return builder.EncapsulateAsScalar(inner.ToArray()); + } + private List ScanScalar() + { + List signals; + tokenizer.Match(TokenTypes.LeftScalar); + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.RightScalar)) + signals = new List(0); + else + signals = ScanSignalExpressionList(); + tokenizer.Match(TokenTypes.RightScalar); + return signals; + } + private Signal ScanParenthesisSignal() + { + tokenizer.Match(TokenTypes.LeftList); + Signal s = ScanSignalExpression(); + tokenizer.Match(TokenTypes.RightList); + return s; + } + private List ScanList() + { + List signals; + tokenizer.Match(TokenTypes.LeftList); + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.RightList)) + signals = new List(0); + else + signals = ScanSignalExpressionList(); + tokenizer.Match(TokenTypes.RightList); + return signals; + } + #endregion + + #region Signal + private Signal ScanSignal() + { + string name = ScanTextIdentifier(); + Signal s; + if(!system.TryLookupNamedSignal(name, out s)) + s = system.CreateNamedSignal(name); + return s; + } + private List ScanSignalList() + { + List signals = new List(); + signals.Add(ScanSignal()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + signals.Add(ScanSignal()); + } + return signals; + } + #endregion + + #region Bus + private Bus ScanBus() + { + string name = ScanTextIdentifier(); + return system.LookupNamedBus(name); + } + private List ScanBusList() + { + List buses = new List(); + buses.Add(ScanBus()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + buses.Add(ScanBus()); + } + return buses; + } + #endregion + + #region Identifier + private string ScanTextIdentifier() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.TextIdentifier); + return token.Text; + } + private List ScanTextIdentifierList() + { + List strings = new List(); + strings.Add(ScanTextIdentifier()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + strings.Add(ScanTextIdentifier()); + } + return strings; + } + private MathIdentifier ScanMathIdentifier() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.MathIdentifier); + return MathIdentifier.Parse(token.Text); + } + #endregion + + #region Entity + private string ScanEntitySymbol() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.SymbolIdentifier); + return token.Text; + } + private string ScanEntitySymbolLiteral() + { + return ScanLiteral(); + } + private MathIdentifier ScanEntityMathIdentifierOrLabel(bool defaultToWorkDomain) + { + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.MathIdentifier)) //id + { + LexerToken token = tokenizer.MatchGet(TokenTypes.MathIdentifier); + return MathIdentifier.Parse(token.Text); + } + else //label + { + LexerToken token = tokenizer.MatchGet(TokenTypes.TextIdentifier); + string domain = defaultToWorkDomain ? "Work" : library.FindEntityByLabel(token.Text).Domain; + return new MathIdentifier(token.Text, domain); + } + } + private IEntity ScanEntity() + { + if(tokenizer.LookaheadFistToken.IsType(TokenTypes.Literal)) //symbol + { + LexerToken token = tokenizer.MatchGet(TokenTypes.Literal); + return library.LookupEntities(token.Text)[0]; + } + else if(tokenizer.LookaheadFistToken.IsType(TokenTypes.SymbolIdentifier)) //symbol + { + LexerToken token = tokenizer.MatchGet(TokenTypes.SymbolIdentifier); + return library.LookupEntities(token.Text)[0]; + } + else //label or id + { + MathIdentifier entityId = ScanEntityMathIdentifierOrLabel(false); + return library.LookupEntity(entityId); + } + } + private IEntity ScanEntity(LexerToken token, InfixNotation notation, int inputs) + { + if(token.IsType(TokenTypes.MathIdentifier)) + return library.LookupEntity(MathIdentifier.Parse(token.Text)); + else if(token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol + return library.LookupEntity(token.Text, notation, inputs); + else //textsymbol or label + { + IEntity entity; + if(library.TryLookupEntity(token.Text, notation, inputs, out entity)) + return entity; + else + { + MathIdentifier id = library.FindEntityByLabel(token.Text); + return library.LookupEntity(id); + } + } + } + #endregion + + #region Literal + private string ScanLiteral() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.Literal); + return token.Text; + } + private List ScanLiteralList() + { + List literals = new List(); + literals.Add(ScanLiteral()); + while(tokenizer.LookaheadFistToken.IsType(TokenTypes.Separator)) + { + tokenizer.Match(TokenTypes.Separator); + literals.Add(ScanLiteral()); + } + return literals; + } + private Signal ScanLiteralSignal() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.Literal); + Signal s = LiteralValue.Constant(token.Text); + system.AddSignal(s); + return s; + } + #endregion + + #region Number + private long ScanInteger() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.Integer); + return long.Parse(token.Text, Config.InternalNumberFormat); + } + private Signal ScanIntegerSignal() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.Integer); + Signal s = IntegerValue.ParseConstant(token.Text); + system.AddSignal(s); + return s; + } + private Signal ScanRealSignal() + { + LexerToken token = tokenizer.MatchGet(TokenTypes.Real); + Signal s = RealValue.ParseConstant(token.Text); + system.AddSignal(s); + return s; + } + #endregion + + #region Reset + /// Clear the buffer. Replace the current stream with a new one. + public void Reset(TextReader reader, IMathSystem system) + { + if(system == null) + throw new ArgumentNullException("system"); + if(reader == null) + throw new ArgumentNullException("reader"); + + this.system = system; + tokenizer.Reset(reader); + } + public void Reset() + { + tokenizer.Reset(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/SignalStack.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/SignalStack.cs new file mode 100644 index 0000000..9aa8f20 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Interpreter/SignalStack.cs @@ -0,0 +1,136 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Interpreter +{ + // TODO: Replace with .NET 2.0 generic stack + + /// + /// Expression Stack with auto expansion. + /// + public sealed class SignalStack + { + private Signal[] stack; + private int count; + private int maxSize; + + public SignalStack(int minSize, int maxSize) + { + this.maxSize = maxSize; + // Find first power of 2 >= to requested size + int size; + if(minSize < 0) + { + Init(16); + return; + } + // check for overflow + if(minSize >= (Int32.MaxValue / 2)) + { + Init(Int32.MaxValue); + return; + } + for(size = 2; size < minSize; size *= 2) ; + Init(size); + } + + /// The current count of elements in the stack + public int Count + { + get { return count; } + } + + /// The current size of the stack. + public int Size + { + get { return stack.Length; } + } + + private void Init(int size) + { + stack = new Signal[size]; + count = 0; + } + + /// Add a new item to the top of the stack. + /// The item to add. + public void Push(Signal item) + { + if(count == stack.Length) + Expand(); + stack[count++] = item; + } + + /// Returns and removes the item on top of the stack. + /// The item that was on the stack's top. + public Signal Pop() + { + Signal expression = stack[--count]; + stack[count] = null; //remove reference to allow GC to do its job... + return expression; + } + + /// Returns (without removing) the item on top of the stack. + /// The item that is on the stack's top. + public Signal Peek() + { + return stack[count - 1]; + } + + /// Removes the item on top of the stack and returns the new item on top if the stack + /// The item that now is the stack's top (after removement). + public Signal PopPeek() + { + stack[--count] = null; //remove reference to allow GC to do its job... + return stack[count - 1]; + } + + /// Removes the item on top of the stack. + public void Remove() + { + stack[--count] = null; //remove reference to allow GC to do its job... + } + + /// Gets items form the stack, starting from the top. Zero Based. + public Signal this[int index] + { + get { return stack[count - 1 - index]; } + } + + private void Expand() + { + if(maxSize > 0 && stack.Length * 2 > maxSize) + throw new MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Maximum expression stack size exceeded."); + Signal[] newStack = new Signal[stack.Length * 2]; + for(int i = 0; i < stack.Length; i++) + newStack[i] = stack[i]; + stack = newStack; + } + + /// Reset the stack, remove all items. + public void Reset() + { + count = 1; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/InterpreterFactory.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/InterpreterFactory.cs new file mode 100644 index 0000000..3206f03 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/InterpreterFactory.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Interpreter; + +namespace MathNet.Symbolics +{ + internal class InterpreterFactory : IFactory + { + IParser IFactory.GetInstance() + { + return new Parser(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..50034c7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Interpreter")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("01eded89-49dc-45fe-85b0-e2aef3fb4456")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/Resources.Designer.cs b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6c6f4f7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/Resources.Designer.cs @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0}' but got '{1}' around '{2}'.. + /// + internal static string ex_Parsing_Failed_TokenMismatch { + get { + return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0} [{3}]' but got '{1}' around '{2}'.. + /// + internal static string ex_Parsing_Failed_TokenMismatchEx { + get { + return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatchEx", resourceCulture); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/Resources.resx b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/Resources.resx new file mode 100644 index 0000000..7f80ab1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Properties/Resources.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Parsing failed. Token Mismatch. Expected '{0}' but got '{1}' around '{2}'. + + + Parsing failed. Token Mismatch. Expected '{0} [{3}]' but got '{1}' around '{2}'. + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Yttrium.Interpreter.Service.csproj b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Yttrium.Interpreter.Service.csproj new file mode 100644 index 0000000..d4f8a4d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Interpreter.Service/Yttrium.Interpreter.Service.csproj @@ -0,0 +1,112 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {66210C43-A4BD-4B01-A862-BC5EE789CC6E} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Interpreter.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + Resources.resx + True + True + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6} + Yttrium.Interpreter.Contracts + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Yttrium.Packages.Helper + + + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} + Yttrium.Packages.Standard + + + {CFE74A4D-51A2-432C-966A-E29773C55D45} + Yttrium.Simulation.Contracts + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/CustomDataRef.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/CustomDataRef.cs new file mode 100644 index 0000000..a68fbe0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/CustomDataRef.cs @@ -0,0 +1,76 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Library +{ + public class CustomDataRef : ICustomDataRef + { + private MathIdentifier _typeId; + private Type _instanceType; + private IConversionRouter _router; + private ICustomData _instance; + + public CustomDataRef(Type instanceType, IConversionRouter router) + { + _instanceType = instanceType; + _router = router; + _typeId = router.TypeIdentifier; + } + public CustomDataRef(Type instanceType, IConversionRouter router, ICustomData instance) + { + _instanceType = instanceType; + _router = router; + _typeId = router.TypeIdentifier; + _instance = instance; + } + + public MathIdentifier TypeId + { + get { return _typeId; } + } + + public Type InstanceType + { + get { return _instanceType; } + } + + public IConversionRouter Router + { + get { return _router; } + } + + public bool IsSingleton + { + get { return _instance != null; } + } + + public ICustomData SingletonInstance + { + get { return _instance; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ICustomDataRef.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ICustomDataRef.cs new file mode 100644 index 0000000..abbad7a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ICustomDataRef.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Library +{ + public interface ICustomDataRef + { + MathIdentifier TypeId { get;} + Type InstanceType { get;} + IConversionRouter Router { get; } + bool IsSingleton { get;} + ICustomData SingletonInstance { get;} + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ILibrary.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ILibrary.cs new file mode 100644 index 0000000..cfd7d18 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ILibrary.cs @@ -0,0 +1,130 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + public interface ILibrary + { + //MathNet.Symbolics.Backend.Containers.EntityTable Entities { get; } + //MathNet.Symbolics.Backend.Containers.ArchitectureTable Architectures { get; } + //MathNet.Symbolics.Backend.Containers.TheoremTable Theorems { get; } + //MathNet.Symbolics.Backend.ValueConversion.StructureTable Structures { get; } + + void AddEntity(IEntity entity); + void AddArchitecture(IArchitectureFactory factory); + void AddTheoremType(ITheoremProvider provider); + void AddCustomDataType(ICustomDataRef data); + void AddCustomDataType() where TCustomType : ICustomData; + void AddCustomDataType(TCustomType optionalSingletonInstance) where TCustomType : ICustomData; + void AddArbitraryType(Type type); + + #region Entity Library + bool ContainsEntity(MathIdentifier entityId); + bool TryLookupEntity(MathIdentifier entityId, out IEntity value); + IEntity LookupEntity(MathIdentifier entityId); + + // TODO: Which ones of all those overloads are actually used in real-world code? find out! (and next time use TDD...) + + bool ContainsEntity(string symbol); + bool ContainsEntity(string symbol, InfixNotation notation); + bool ContainsEntity(string symbol, int inputSignals, int outputSignals, int buses); + bool ContainsEntity(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses); + bool ContainsEntity(string symbol, int inputSignals); + bool ContainsEntity(string symbol, InfixNotation notation, int inputSignals); + bool ContainsEntity(string symbol, Predicate match); + + IList LookupEntities(string symbol); + IList LookupEntities(string symbol, InfixNotation notation); + IList LookupEntities(string symbol, int inputSignals); + IList LookupEntities(string symbol, InfixNotation notation, int inputSignals); + IList LookupEntities(string symbol, int inputSignals, int outputSignals, int buses); + IList LookupEntities(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses); + IList LookupEntities(string symbol, Predicate match); + + IEntity LookupEntity(string symbol); + IEntity LookupEntity(string symbol, InfixNotation notation); + IEntity LookupEntity(string symbol, int inputSignals); + IEntity LookupEntity(string symbol, InfixNotation notation, int inputSignals); + IEntity LookupEntity(string symbol, int inputSignals, int outputSignals, int buses); + IEntity LookupEntity(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses); + IEntity LookupEntity(string symbol, Predicate match); + + bool TryLookupEntity(string symbol, InfixNotation notation, int inputSignals, out IEntity entity); + bool TryLookupEntity(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses, out IEntity entity); + bool TryLookupEntity(string symbol, Predicate match, out IEntity entity); + + MathIdentifier FindEntityByLabel(string label); + bool TryFindEntityByLabel(string label, out MathIdentifier id); + + ReadOnlyCollection GetAllEntities(); + #endregion + + #region Architecture Library + bool ContainsArchitecture(Port port); + IArchitectureFactory LookupArchitecture(Port port); + bool TryLookupArchitecture(Port port, out IArchitectureFactory architecture); + #endregion + + #region Theorem Library + bool ContainsTheoremType(MathIdentifier theoremTypeId); + ITheoremProvider LookupTheoremType(MathIdentifier theoremTypeId); + bool TryLookupTheoremType(MathIdentifier theoremTypeId, out ITheoremProvider provider); + #endregion + + #region CustomData Library + bool ContainsCustomDataType(MathIdentifier typeId); + ICustomDataRef LookupCustomDataType(MathIdentifier typeId); + bool TryLookupCustomDataType(MathIdentifier typeId, out ICustomDataRef data); + #endregion + + #region Arbitrary Type Library + bool ContainsArbitraryType(MathIdentifier id); + bool ContainsArbitraryType(Type type); + Type LookupArbitraryType(MathIdentifier id); + MathIdentifier LookupArbitraryType(Type type); + bool TryLookupArbitraryType(MathIdentifier id, out Type type); + #endregion + + #region Theorem Lookup + //bool ContainsTheorem(MathIdentifier theoremId); + //bool TryLookupTheorem(MathIdentifier theoremId, out MathNet.Symbolics.Backend.Theorems.ITheorem theorem); + //bool TryLookupTheorem(MathIdentifier theoremId, out T theorem) where T : MathNet.Symbolics.Backend.Theorems.ITheorem; + //MathNet.Symbolics.Backend.Theorems.ITheorem LookupTheorem(MathIdentifier theoremId); + //bool TryLookupTransformationTheoremType(MathIdentifier transformationTypeId, out MathNet.Symbolics.Backend.Containers.TransformationTheoremTypeTable value); + //MathNet.Symbolics.Backend.Containers.TransformationTheoremTypeTable LookupTransformationTheoremType(MathIdentifier transformationTypeId); + #endregion + + #region Assembly Analysis + //void LoadAssembly(System.Reflection.Assembly assembly); + //void LoadAssemblyManual(System.Reflection.Assembly assembly); + //void LoadPackageManager(MathNet.Symbolics.Backend.Discovery.IPackageManager packageManager); + //void LoadArchitectureServer(MathNet.Symbolics.Backend.Discovery.IArchitectureServer architectureServer); + //void LoadEntityServer(MathNet.Symbolics.Backend.Discovery.IEntityServer entityServer); + //void LoadTheoremServer(MathNet.Symbolics.Backend.Discovery.ITheoremServer theoremServer); + //void LoadStructureServer(MathNet.Symbolics.Backend.Discovery.IStructureServer structureServer); + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/IPackageLoader.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/IPackageLoader.cs new file mode 100644 index 0000000..c82ec88 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/IPackageLoader.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + public interface IPackageLoader + { + void LoadPackage(string domain); + void UnloadPackage(string domain); + void ReloadPackage(string domain); + + void LoadStdPackage(); + void UnloadStdPackage(); + void ReloadStdPackage(); + + void LoadDefaultPackages(); + void UnloadDefaultPackages(); + void ReloadDefaultPackages(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/IPackageManager.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/IPackageManager.cs new file mode 100644 index 0000000..df72403 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/IPackageManager.cs @@ -0,0 +1,30 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion +using System; + +namespace MathNet.Symbolics.Library +{ + public interface IPackageManager + { + string Domain { get;} + void Register(ILibrary library); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ITheoremProvider.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ITheoremProvider.cs new file mode 100644 index 0000000..7b1a29d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Library/ITheoremProvider.cs @@ -0,0 +1,32 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + public interface ITheoremProvider + { + MathIdentifier TheoremTypeId { get;} + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bca93d2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Library Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("592f114f-82ef-44a2-85bf-c6540894d030")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Library.Contracts/Yttrium.Library.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Yttrium.Library.Contracts.csproj new file mode 100644 index 0000000..fb35b7d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Contracts/Yttrium.Library.Contracts.csproj @@ -0,0 +1,70 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Library.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/ArchitectureFactoryCollection.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/ArchitectureFactoryCollection.cs new file mode 100644 index 0000000..3ed9906 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/ArchitectureFactoryCollection.cs @@ -0,0 +1,84 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +using MathNet.Symbolics; + +namespace MathNet.Symbolics.Library +{ + internal sealed class ArchitectureFactoryCollection : KeyedCollection + { + public ArchitectureFactoryCollection() + { + } + + public bool TryGetValue(MathIdentifier entityId, out EntityArchitecturesRelation architectures) + { + architectures = null; + if(!Contains(entityId)) + return false; + architectures = base[entityId]; + return true; + } + + protected override MathIdentifier GetKeyForItem(EntityArchitecturesRelation item) + { + return item.EntityId; + } + + public void Add(IArchitectureFactory architecture) + { + EntityArchitecturesRelation relation; + if(!TryGetValue(architecture.EntityId, out relation)) + { + relation = new EntityArchitecturesRelation(architecture.EntityId); + Add(relation); + } + if(!relation.Architectures.Contains(architecture)) + relation.Architectures.Add(architecture); + } + + public void Remove(IArchitectureFactory architecture) + { + EntityArchitecturesRelation relation; + if(!TryGetValue(architecture.EntityId, out relation)) + return; + int idx = relation.Architectures.IndexOf(architecture); + + // Remove Factory-entry in the table of this entity + if(idx >= 0) + relation.Architectures.RemoveAt(idx); + + // Remove Entity if no more Architecture-entry + if(relation.Architectures.Count == 0) + Remove(relation.EntityId); + } + + + public bool Contains(IEntity entity) + { + return Contains(entity.EntityId); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/CustomDataCollection.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/CustomDataCollection.cs new file mode 100644 index 0000000..6678aae --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/CustomDataCollection.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + internal class CustomDataCollection : KeyedCollection + { + public CustomDataCollection() + { + } + + protected override MathIdentifier GetKeyForItem(ICustomDataRef item) + { + return item.TypeId; + } + + public bool TryGetValue(MathIdentifier typeId, out ICustomDataRef data) + { + data = null; + if(!Contains(typeId)) + return false; + data = base[typeId]; + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/EntityArchitecturesRelation.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/EntityArchitecturesRelation.cs new file mode 100644 index 0000000..a623edf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/EntityArchitecturesRelation.cs @@ -0,0 +1,73 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + internal class EntityArchitecturesRelation + { + private readonly MathIdentifier _entityId; + private readonly List _architectures; + + public EntityArchitecturesRelation(MathIdentifier entityId) + { + _entityId = entityId; + _architectures = new List(); + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public List Architectures + { + get { return _architectures; } + } + + public bool ContainsArchitectureFor(Port port) + { + return _architectures.Exists(delegate(IArchitectureFactory factory) { return factory.SupportsPort(port); }); + } + + public IList LookupArchitecturesFor(Port port) + { + return _architectures.FindAll(delegate(IArchitectureFactory factory) { return factory.SupportsPort(port); }); + } + + public IArchitectureFactory LookupArchitectureFor(Port port) + { + return _architectures.Find(delegate(IArchitectureFactory factory) { return factory.SupportsPort(port); }); + } + + public bool TryLookupArchitectureFor(Port port, out IArchitectureFactory architecture) + { + architecture = _architectures.Find(delegate(IArchitectureFactory factory) { return factory.SupportsPort(port); }); + return architecture != null; + } + + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/EntityCollection.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/EntityCollection.cs new file mode 100644 index 0000000..ea3538a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/EntityCollection.cs @@ -0,0 +1,254 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +using MathNet.Symbolics; + +namespace MathNet.Symbolics.Library +{ + internal sealed class EntityCollection : KeyedCollection + { + private readonly Dictionary> _symbolTable; + + public EntityCollection() + { + _symbolTable = new Dictionary>(128, Config.IdentifierComparer); + } + + public bool TryGetValue(MathIdentifier entityId, out IEntity entity) + { + entity = null; + if(!Contains(entityId)) + return false; + entity = base[entityId]; + return true; + } + + protected override MathIdentifier GetKeyForItem(IEntity item) + { + return item.EntityId; + } + + protected override void InsertItem(int index, IEntity item) + { + base.InsertItem(index, item); + AddSymbolEntry(item); + } + + protected override void RemoveItem(int index) + { + RemoveSymbolEntry(base[index]); + base.RemoveItem(index); + } + + protected override void SetItem(int index, IEntity item) + { + RemoveSymbolEntry(base[index]); + base.SetItem(index, item); + AddSymbolEntry(item); + } + + protected override void ClearItems() + { + base.ClearItems(); + _symbolTable.Clear(); + } + + private void AddSymbolEntry(IEntity entity) + { + List item; + if(!_symbolTable.TryGetValue(entity.Symbol, out item)) + { + item = new List(); + _symbolTable.Add(entity.Symbol, item); + } + if(!item.Contains(entity)) + item.Add(entity); + } + + private void RemoveSymbolEntry(IEntity entity) + { + List item; + if(!_symbolTable.TryGetValue(entity.Symbol, out item)) + return; + int idx = item.IndexOf(entity); + + // Remove Entity-entry in the table of this symbol + if(idx >= 0) + item.RemoveAt(idx); + + // Remove Symbol if no more Entity-entry + if(item.Count == 0) + _symbolTable.Remove(entity.Symbol); + } + + public bool ContainsSymbol(string symbol) + { + return _symbolTable.ContainsKey(symbol); + } + public bool ContainsSymbol(string symbol, InfixNotation notation) + { + List entities; + if(_symbolTable.TryGetValue(symbol, out entities)) + return entities.Exists(delegate(IEntity e) { return e.Notation == notation; }); + return false; + } + public bool ContainsSymbol(string symbol, int inputSignals) + { + List entities; + if(_symbolTable.TryGetValue(symbol, out entities)) + return entities.Exists(delegate(IEntity e) { return e.InputSignals.Length == inputSignals || e.IsGeneric; }); + return false; + } + public bool ContainsSymbol(string symbol, InfixNotation notation, int inputSignals) + { + List entities; + if(_symbolTable.TryGetValue(symbol, out entities)) + return entities.Exists(delegate(IEntity e) { return e.Notation == notation && (e.InputSignals.Length == inputSignals || e.IsGeneric); }); + return false; + } + public bool ContainsSymbol(string symbol, int inputSignals, int outputSignals, int buses) + { + List entities; + if(_symbolTable.TryGetValue(symbol, out entities)) + return entities.Exists(delegate(IEntity e) { return (e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses); }); + return false; + } + public bool ContainsSymbol(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) + { + List entities; + if(_symbolTable.TryGetValue(symbol, out entities)) + return entities.Exists(delegate(IEntity e) { return e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses)); }); + return false; + } + public bool ContainsSymbol(string symbol, Predicate match) + { + List entities; + if(_symbolTable.TryGetValue(symbol, out entities)) + return entities.Exists(match); + return false; + } + + + public IList LookupSymbols(string symbol) + { + return _symbolTable[symbol].AsReadOnly(); + } + public IList LookupSymbols(string symbol, InfixNotation notation) + { + return _symbolTable[symbol].FindAll(delegate(IEntity e) { return e.Notation == notation; }); + } + public IList LookupSymbols(string symbol, int inputSignals) + { + return _symbolTable[symbol].FindAll(delegate(IEntity e) { return e.InputSignals.Length == inputSignals || e.IsGeneric; }); + } + public IList LookupSymbols(string symbol, InfixNotation notation, int inputSignals) + { + return _symbolTable[symbol].FindAll(delegate(IEntity e) { return e.Notation == notation && (e.InputSignals.Length == inputSignals || e.IsGeneric); }); + } + public IList LookupSymbols(string symbol, int inputSignals, int outputSignals, int buses) + { + return _symbolTable[symbol].FindAll(delegate(IEntity e) { return (e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses); }); + } + public IList LookupSymbols(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) + { + return _symbolTable[symbol].FindAll(delegate(IEntity e) { return e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses)); }); + } + public IList LookupSymbols(string symbol, Predicate match) + { + return _symbolTable[symbol].FindAll(match); + } + + + public IEntity LookupSymbol(string symbol) + { + return _symbolTable[symbol][0]; + } + public IEntity LookupSymbol(string symbol, InfixNotation notation) + { + return _symbolTable[symbol].Find(delegate(IEntity e) { return e.Notation == notation; }); + } + public IEntity LookupSymbol(string symbol, int inputSignals) + { + return _symbolTable[symbol].Find(delegate(IEntity e) { return e.InputSignals.Length == inputSignals || e.IsGeneric; }); + } + public IEntity LookupSymbol(string symbol, InfixNotation notation, int inputSignals) + { + return _symbolTable[symbol].Find(delegate(IEntity e) { return e.Notation == notation && (e.InputSignals.Length == inputSignals || e.IsGeneric); }); + } + public IEntity LookupSymbol(string symbol, int inputSignals, int outputSignals, int buses) + { + return _symbolTable[symbol].Find(delegate(IEntity e) { return (e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses); }); + } + public IEntity LookupSymbol(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) + { + return _symbolTable[symbol].Find(delegate(IEntity e) { return e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses)); }); + } + public IEntity LookupSymbol(string symbol, Predicate match) + { + return _symbolTable[symbol].Find(match); + } + + + public bool TryLookupSymbol(string symbol, InfixNotation notation, int inputSignals, out IEntity entity) + { + entity = null; + List list; + if(!_symbolTable.TryGetValue(symbol, out list)) + return false; + entity = list.Find(delegate(IEntity e) { return e.Notation == notation && (e.InputSignals.Length == inputSignals || e.IsGeneric); }); + return entity != null; + } + public bool TryLookupSymbol(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses, out IEntity entity) + { + entity = null; + List list; + if(!_symbolTable.TryGetValue(symbol, out list)) + return false; + entity = list.Find(delegate(IEntity e) { return e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses)); }); + return entity != null; + } + public bool TryLookupSymbol(string symbol, Predicate match, out IEntity entity) + { + entity = null; + List list; + if(!_symbolTable.TryGetValue(symbol, out list)) + return false; + entity = list.Find(match); + return entity != null; + } + + + public bool TryFindDomainOfLabel(string label, out MathIdentifier id) + { + foreach(MathIdentifier mid in Dictionary.Keys) + if(mid.Label.Equals(label)) + { + id = mid; + return true; + } + return false; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/Library.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/Library.cs new file mode 100644 index 0000000..a69da30 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/Library.cs @@ -0,0 +1,300 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Conversion; +using System.Collections.ObjectModel; + +namespace MathNet.Symbolics.Library +{ + public class Library : ILibrary + { + private EntityCollection _entities; + private ArchitectureFactoryCollection _architectures; + private TheoremProviderCollection _theorems; + private CustomDataCollection _customData; + private Dictionary _arbitraryType; + + public Library() + { + _entities = new EntityCollection(); + _architectures = new ArchitectureFactoryCollection(); + _theorems = new TheoremProviderCollection(); + _customData = new CustomDataCollection(); + _arbitraryType = new Dictionary(); + } + + public void AddEntity(IEntity entity) + { + if(entity == null) throw new ArgumentNullException("entity"); + _entities.Add(entity); + } + + public void AddArchitecture(IArchitectureFactory factory) + { + if(factory == null) throw new ArgumentNullException("factory"); + _architectures.Add(factory); + } + + public void AddTheoremType(ITheoremProvider provider) + { + if(provider == null) throw new ArgumentNullException("provider"); + _theorems.Add(provider); + } + + public void AddCustomDataType(ICustomDataRef data) + { + if(data == null) throw new ArgumentNullException("data"); + _customData.Add(data); + } + + public void AddCustomDataType() + where TCustomType : ICustomData + { + _customData.Add(new CustomDataRef(typeof(TCustomType), ValueConverter.Router)); + } + + public void AddCustomDataType(TCustomType optionalSingletonInstance) + where TCustomType : ICustomData + { + _customData.Add(new CustomDataRef(typeof(TCustomType), ValueConverter.Router, optionalSingletonInstance)); + } + + public void AddArbitraryType(Type type) + { + if(type == null) throw new ArgumentNullException("type"); + MathIdentifier id = new MathIdentifier(type.Name, type.Namespace); + if(!_arbitraryType.ContainsKey(id)) + _arbitraryType.Add(id, type); + + } + + #region Entity Library + public bool ContainsEntity(MathIdentifier entityId) + { + return _entities.Contains(entityId); + } + public bool TryLookupEntity(MathIdentifier entityId, out IEntity value) + { + return _entities.TryGetValue(entityId, out value); + } + public IEntity LookupEntity(MathIdentifier entityId) + { + return _entities[entityId]; + } + + + public bool ContainsEntity(string symbol) + { + return _entities.ContainsSymbol(symbol); + } + public bool ContainsEntity(string symbol, InfixNotation notation) + { + return _entities.ContainsSymbol(symbol, notation); + } + public bool ContainsEntity(string symbol, int inputSignals, int outputSignals, int buses) + { + return _entities.ContainsSymbol(symbol, inputSignals, outputSignals, buses); + } + public bool ContainsEntity(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) + { + return _entities.ContainsSymbol(symbol, notation, inputSignals, outputSignals, buses); + } + public bool ContainsEntity(string symbol, int inputSignals) + { + return _entities.ContainsSymbol(symbol, inputSignals); + } + public bool ContainsEntity(string symbol, InfixNotation notation, int inputSignals) + { + return _entities.ContainsSymbol(symbol, notation, inputSignals); + } + public bool ContainsEntity(string symbol, Predicate match) + { + return _entities.ContainsSymbol(symbol, match); + } + + + public IList LookupEntities(string symbol) + { + return _entities.LookupSymbols(symbol); + } + public IList LookupEntities(string symbol, InfixNotation notation) + { + return _entities.LookupSymbols(symbol, notation); + } + public IList LookupEntities(string symbol, int inputSignals, int outputSignals, int buses) + { + return _entities.LookupSymbols(symbol, inputSignals, outputSignals, buses); + } + public IList LookupEntities(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) + { + return _entities.LookupSymbols(symbol, notation, inputSignals, outputSignals, buses); + } + public IList LookupEntities(string symbol, int inputSignals) + { + return _entities.LookupSymbols(symbol, inputSignals); + } + public IList LookupEntities(string symbol, InfixNotation notation, int inputSignals) + { + return _entities.LookupSymbols(symbol, notation, inputSignals); + } + public IList LookupEntities(string symbol, Predicate match) + { + return _entities.LookupSymbols(symbol, match); + } + + + public IEntity LookupEntity(string symbol) + { + return _entities.LookupSymbol(symbol); + } + public IEntity LookupEntity(string symbol, InfixNotation notation) + { + return _entities.LookupSymbol(symbol, notation); + } + public IEntity LookupEntity(string symbol, int inputSignals, int outputSignals, int buses) + { + return _entities.LookupSymbol(symbol, inputSignals, outputSignals, buses); + } + public IEntity LookupEntity(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) + { + return _entities.LookupSymbol(symbol, notation, inputSignals, outputSignals, buses); + } + public IEntity LookupEntity(string symbol, int inputSignals) + { + return _entities.LookupSymbol(symbol, inputSignals); + } + public IEntity LookupEntity(string symbol, InfixNotation notation, int inputSignals) + { + return _entities.LookupSymbol(symbol, notation, inputSignals); + } + public IEntity LookupEntity(string symbol, Predicate match) + { + return _entities.LookupSymbol(symbol, match); + } + + + public bool TryLookupEntity(string symbol, InfixNotation notation, int inputSignals, out IEntity entity) + { + return _entities.TryLookupSymbol(symbol, notation, inputSignals, out entity); + } + public bool TryLookupEntity(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses, out IEntity entity) + { + return _entities.TryLookupSymbol(symbol, notation, inputSignals, outputSignals, buses, out entity); + } + public bool TryLookupEntity(string symbol, Predicate match, out IEntity entity) + { + return _entities.TryLookupSymbol(symbol, match, out entity); + } + + public MathIdentifier FindEntityByLabel(string label) + { + MathIdentifier id; + if(!_entities.TryFindDomainOfLabel(label, out id)) + throw new Exceptions.NotFoundException(); + return id; + // TODO: better exception + } + public bool TryFindEntityByLabel(string label, out MathIdentifier id) + { + return _entities.TryFindDomainOfLabel(label, out id); + } + + public ReadOnlyCollection GetAllEntities() + { + return new ReadOnlyCollection(_entities); + } + #endregion + + #region Architecture Library + public bool ContainsArchitecture(Port port) + { + EntityArchitecturesRelation relation; + return _architectures.TryGetValue(port.Entity.EntityId, out relation) && relation.ContainsArchitectureFor(port); + } + public IArchitectureFactory LookupArchitecture(Port port) + { + return _architectures[port.Entity.EntityId].LookupArchitectureFor(port); + } + public bool TryLookupArchitecture(Port port, out IArchitectureFactory architecture) + { + architecture = null; + EntityArchitecturesRelation relation; + return _architectures.TryGetValue(port.Entity.EntityId, out relation) && relation.TryLookupArchitectureFor(port, out architecture); + } + #endregion + + #region Theorem Library + public bool ContainsTheoremType(MathIdentifier theoremTypeId) + { + return _theorems.Contains(theoremTypeId); + } + public ITheoremProvider LookupTheoremType(MathIdentifier theoremTypeId) + { + return _theorems[theoremTypeId]; + } + public bool TryLookupTheoremType(MathIdentifier theoremTypeId, out ITheoremProvider provider) + { + return _theorems.TryGetValue(theoremTypeId, out provider); + } + #endregion + + #region CustomData Library + public bool ContainsCustomDataType(MathIdentifier typeId) + { + return _customData.Contains(typeId); + } + public ICustomDataRef LookupCustomDataType(MathIdentifier typeId) + { + return _customData[typeId]; + } + public bool TryLookupCustomDataType(MathIdentifier typeId, out ICustomDataRef data) + { + return _customData.TryGetValue(typeId, out data); + } + #endregion + + #region Arbitrary Type Library + public bool ContainsArbitraryType(MathIdentifier id) + { + return _arbitraryType.ContainsKey(id); + } + public bool ContainsArbitraryType(Type type) + { + return _arbitraryType.ContainsValue(type); + } + public Type LookupArbitraryType(MathIdentifier id) + { + return _arbitraryType[id]; + } + public MathIdentifier LookupArbitraryType(Type type) + { + return new MathIdentifier(type.Name, type.Namespace); + } + public bool TryLookupArbitraryType(MathIdentifier id, out Type type) + { + return _arbitraryType.TryGetValue(id, out type); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackageInfo.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackageInfo.cs new file mode 100644 index 0000000..ae4532f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackageInfo.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + internal sealed class PackageInfo + { + internal string domain; + internal Type managerType; + internal bool isdefault; + internal string comment; + + public PackageInfo(string domain, string managerType, string isdefault, string comment) + { + this.domain = domain; + this.managerType = Type.GetType(managerType, true); + this.isdefault = bool.Parse(isdefault); + this.comment = comment; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackageLoader.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackageLoader.cs new file mode 100644 index 0000000..efee71b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackageLoader.cs @@ -0,0 +1,135 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace MathNet.Symbolics.Library +{ + public class PackageLoader : IPackageLoader + { + private static Dictionary _packagesOffline, _packagesOnline; + private ILibrary _library = Service.Instance; + + static PackageLoader() + { + _packagesOffline = new Dictionary(); + _packagesOnline = new Dictionary(); + LoadPackageInfo(); + } + + #region Load Available Package Infos + public static void LoadPackageInfo() + { + IList infos + = System.Configuration.ConfigurationManager.GetSection("yttrium/packages") as IList; + if(infos == null) + { + FileInfo fi = new FileInfo(@"yttrium.packages.config"); + if(fi.Exists) + { + XmlPackagesAdapter xpa = new XmlPackagesAdapter(); + infos = xpa.Load(fi.FullName); + } + } + if(infos != null) + foreach(PackageInfo info in infos) + _packagesOffline.Add(info.domain, info); + } + public static void LoadPackageInfo(string sourceFilename) + { + XmlPackagesAdapter xpa = new XmlPackagesAdapter(); + IList infos = xpa.Load(sourceFilename); + if(infos != null) + foreach(PackageInfo info in infos) + _packagesOffline.Add(info.domain, info); + } + #endregion + + private void LoadPackage(PackageInfo info) + { + _packagesOnline.Add(info.domain, info); + _packagesOffline.Remove(info.domain); + IPackageManager pm = (IPackageManager)info.managerType + .GetConstructor(new Type[] { }) + .Invoke(new object[] { }); + pm.Register(_library); + } + + public void LoadPackage(string domain) + { + PackageInfo info; + if(_packagesOffline.TryGetValue(domain, out info)) + LoadPackage(info); + } + + public void UnloadPackage(string domain) + { + throw new NotImplementedException(); + } + + public void ReloadPackage(string domain) + { + UnloadPackage(domain); + LoadPackage(domain); + } + + public void LoadStdPackage() + { + LoadPackage("Std"); + } + + public void UnloadStdPackage() + { + UnloadPackage("Std"); + } + + public void ReloadStdPackage() + { + UnloadStdPackage(); + LoadStdPackage(); + } + + public void LoadDefaultPackages() + { + List auto = new List(_packagesOffline.Count); + foreach(PackageInfo info in _packagesOffline.Values) + if(info.isdefault) + auto.Add(info); + // note: don't merge these two loops, because LoadPackage changes the two dictionaries + foreach(PackageInfo info in auto) + LoadPackage(info); + } + + public void UnloadDefaultPackages() + { + throw new NotImplementedException(); + } + + public void ReloadDefaultPackages() + { + UnloadDefaultPackages(); + LoadDefaultPackages(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackagesSectionHandler.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackagesSectionHandler.cs new file mode 100644 index 0000000..80769b3 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PackagesSectionHandler.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Configuration; + +namespace MathNet.Symbolics.Library +{ + public sealed class PackagesSectionHandler : IConfigurationSectionHandler + { + public object Create(object parent, object configContext, XmlNode section) + { + XmlPackagesAdapter xpa = new XmlPackagesAdapter(); + return xpa.CompileFromXml(section); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PropertyProviderTable.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PropertyProviderTable.cs new file mode 100644 index 0000000..11ebb36 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/PropertyProviderTable.cs @@ -0,0 +1,110 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +//using System; +//using System.Collections.Generic; +//using System.Text; + +//using MathNet.Symbolics.Core; +//using MathNet.Symbolics.Backend.Theorems; + +//namespace MathNet.Symbolics.Backend.Library +//{ +// public sealed class PropertyProviderTable : IEnumerable +// { +// // TODO: consider a more usable/standardized interface. inherit? + +// private readonly MathIdentifier _propertyTypeId; +// private readonly List _table; + +// public PropertyProviderTable(MathIdentifier propertyTypeId) +// { +// _propertyTypeId = propertyTypeId; +// _table = new List(16); +// } + +// public MathIdentifier ProvidedPropertyId +// { +// get { return _propertyTypeId; } +// } + +// public bool ContainsTheorem(IPropagationTheorem theorem) +// { +// return _table.Contains(theorem); +// } + +// public bool WouldBePropagatedTo(Signal target) +// { +// foreach(IPropagationTheorem theorem in _table) +// if(theorem.WouldBePropagatedTo(target)) +// return true; +// return false; +// } + +// /// true if the property is attached to the signal after this call. +// public bool PropagatePropertyIfApplicable(Signal target) +// { +// if(target.Properties.ContainsProperty(_propertyTypeId)) +// return true; +// foreach(IPropagationTheorem theorem in _table) +// if(theorem.PropagatePropertyIfApplicable(target)) +// return true; +// return false; +// } + +// /// Sets or Removes the property conditioned on the available theorems. +// /// true if the property is attached to the signal after this call. +// public bool UpdateProperty(Signal target) +// { +// if(target == null) +// throw new ArgumentNullException("target"); + +// if(target.Properties.ContainsProperty(_propertyTypeId)) +// { +// if(WouldBePropagatedTo(target)) +// return true; +// else +// { +// target.Properties.RemoveProperty(_propertyTypeId); +// return false; +// } +// } +// else +// return PropagatePropertyIfApplicable(target); +// } + +// public void AddTheorem(IPropagationTheorem theorem) +// { +// _table.Add(theorem); +// } + +// #region Enumeration +// IEnumerator IEnumerable.GetEnumerator() +// { +// return _table.GetEnumerator(); +// } +// System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() +// { +// return _table.GetEnumerator(); +// } +// #endregion +// } +//} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/TheoremProviderCollection.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/TheoremProviderCollection.cs new file mode 100644 index 0000000..5f69b8d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/TheoremProviderCollection.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace MathNet.Symbolics.Library +{ + internal class TheoremProviderCollection : KeyedCollection + { + public TheoremProviderCollection() + { + } + + protected override MathIdentifier GetKeyForItem(ITheoremProvider item) + { + return item.TheoremTypeId; + } + + public bool TryGetValue(MathIdentifier theoremTypeId, out ITheoremProvider provider) + { + provider = null; + if(!Contains(theoremTypeId)) + return false; + provider = base[theoremTypeId]; + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Library/XmlPackagesAdapter.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/XmlPackagesAdapter.cs new file mode 100644 index 0000000..1d4287a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Library/XmlPackagesAdapter.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; +using System.Text; +using System.Configuration; + +namespace MathNet.Symbolics.Library +{ + internal sealed class XmlPackagesAdapter + { + #region Load from different XML sources + public IList Load(string sourceFilename) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(sourceFilename); + + return Load(xmlDoc); + } + + public IList Load(XmlDocument sourceDoc) + { + XmlNode objectsSection = sourceDoc.SelectSingleNode("//yttrium/packages"); + if(objectsSection == null) + return null; // no bindings found + else + return CompileFromXml(objectsSection); + } + #endregion + + #region Compile from XML elements + internal IList CompileFromXml(XmlNode objectsSection) + { + List infos = new List(); + foreach(XmlNode packageDef in objectsSection.SelectNodes("package")) + { + PackageInfo info = + new PackageInfo(GetXmlAttribute(packageDef, "domain", ""), + GetXmlAttribute(packageDef, "manager", ""), + GetXmlAttribute(packageDef, "default", ""), + GetXmlAttribute(packageDef, "comment", "")); + infos.Add(info); + } + return infos; + } + + private string GetXmlAttribute(XmlNode node, string attributeName, string defaultValue) + { + try + { + return node.Attributes[attributeName].Value; + } + catch(IndexOutOfRangeException) + { + return defaultValue; + } + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/LibraryFactory.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/LibraryFactory.cs new file mode 100644 index 0000000..d3d6b91 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/LibraryFactory.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + internal class LibraryFactory : IFactory, IFactory + { + private static Library.ILibrary _lib = new Library.Library(); + + Library.ILibrary IFactory.GetInstance() + { + return _lib; //new Library.Library(); + } + + Library.IPackageLoader IFactory.GetInstance() + { + return new Library.PackageLoader(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Library.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c1a82f9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Library")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("a56c26f4-8a54-4cf1-b6a2-8476c542263c")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/Yttrium.Library.Service.csproj b/Backup/src/app/MathNet.Yttrium/Library.Service/Yttrium.Library.Service.csproj new file mode 100644 index 0000000..abae51b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/Yttrium.Library.Service.csproj @@ -0,0 +1,94 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {C1280263-2D0B-4D42-909D-B750FB52D873} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Library.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351} + Yttrium.Conversion.Toolkit + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + PreserveNewest + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library.Service/yttrium.packages.config b/Backup/src/app/MathNet.Yttrium/Library.Service/yttrium.packages.config new file mode 100644 index 0000000..5adb13e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library.Service/yttrium.packages.config @@ -0,0 +1,18 @@ + + + + +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/Hint.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/Hint.cs new file mode 100644 index 0000000..4454255 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/Hint.cs @@ -0,0 +1,41 @@ +//#region Math.NET Yttrium (GPL) by Christoph Ruegg +//// Math.NET Yttrium, part of the Math.NET Project +//// http://mathnet.opensourcedotnet.info +//// +//// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +//// +//// This program is free software; you can redistribute it and/or modify +//// it under the terms of the GNU General Public License as published by +//// the Free Software Foundation; either version 2 of the License, or +//// (at your option) any later version. +//// +//// This program is distributed in the hope that it will be useful, +//// but WITHOUT ANY WARRANTY; without even the implied warranty of +//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//// GNU General Public License for more details. +//// +//// You should have received a copy of the GNU General Public License +//// along with this program; if not, write to the Free Software +//// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//#endregion + +//using System; +//using System.Collections.Generic; +//using System.Text; + +//namespace MathNet.Symbolics.Backend.Channels +//{ +// public class Hint +// { +// private HintType _type; + +// public Hint() +// { +// } + +// public HintType Type +// { +// get { return _type; } +// } +// } +//} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/HintChannel.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/HintChannel.cs new file mode 100644 index 0000000..3c78a27 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/HintChannel.cs @@ -0,0 +1,32 @@ +//#region Math.NET Yttrium (GPL) by Christoph Ruegg +//// Math.NET Yttrium, part of the Math.NET Project +//// http://mathnet.opensourcedotnet.info +//// +//// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +//// +//// This program is free software; you can redistribute it and/or modify +//// it under the terms of the GNU General Public License as published by +//// the Free Software Foundation; either version 2 of the License, or +//// (at your option) any later version. +//// +//// This program is distributed in the hope that it will be useful, +//// but WITHOUT ANY WARRANTY; without even the implied warranty of +//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//// GNU General Public License for more details. +//// +//// You should have received a copy of the GNU General Public License +//// along with this program; if not, write to the Free Software +//// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//#endregion + +//using System; +//using System.Collections.Generic; +//using System.Text; + +//namespace MathNet.Symbolics.Backend.Channels +//{ +// public class HintChannel : AbstractChannel +// { +// public HintChannel() { } +// } +//} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/HintType.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/HintType.cs new file mode 100644 index 0000000..53b8576 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/HintType.cs @@ -0,0 +1,35 @@ +//#region Math.NET Yttrium (GPL) by Christoph Ruegg +//// Math.NET Yttrium, part of the Math.NET Project +//// http://mathnet.opensourcedotnet.info +//// +//// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +//// +//// This program is free software; you can redistribute it and/or modify +//// it under the terms of the GNU General Public License as published by +//// the Free Software Foundation; either version 2 of the License, or +//// (at your option) any later version. +//// +//// This program is distributed in the hope that it will be useful, +//// but WITHOUT ANY WARRANTY; without even the implied warranty of +//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//// GNU General Public License for more details. +//// +//// You should have received a copy of the GNU General Public License +//// along with this program; if not, write to the Free Software +//// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//#endregion + +//using System; +//using System.Collections.Generic; +//using System.Text; + +//namespace MathNet.Symbolics.Backend.Channels +//{ +// public enum HintType +// { +// Error, +// Warning, +// Information, +// Hint +// } +//} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/LogObserver.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/LogObserver.cs new file mode 100644 index 0000000..35fc42a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Channels/LogObserver.cs @@ -0,0 +1,229 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend.Channels; +using MathNet.Symbolics.Mediator; + +namespace MathNet.Symbolics.Backend.Channels +{ + public enum LogAction + { + SystemChanged, + BeginInitialize, + EndInitialize, + SignalAdded, + SignalRemoved, + BusAdded, + BusRemoved, + PortAdded, + PortRemoved, + InputAdded, + InputRemoved, + OutputAdded, + OutputRemoved, + PortDrivesSignal, + PortUndrivesSignal, + SignalDrivesPort, + SignalUndrivesPort, + BusAttachedToPort, + BusDetachedFromPort + } + + public interface ILogWriter + { + void WriteEntry(DateTime time, Guid systemId, LogAction type, Guid portId, Guid signalId, Guid busId, string entityId, int index); + } + + public class TextLogWriter : ILogWriter + { + private TextWriter _writer; + + public TextLogWriter(TextWriter writer) + { + _writer = writer; + } + + public void WriteEntry(DateTime time, Guid systemId, LogAction type, Guid portId, Guid signalId, Guid busId, string entityId, int index) + { + _writer.WriteLine("{0:s} -> {1:N} : {2,-20} -> P:{3:N} S:{4:N} B:{5:N} {7} {6}", time, systemId, type, portId, signalId, busId, entityId, index); + _writer.Flush(); + } + } + + public class LogObserver : ISystemObserver + { + private ILogWriter _writer; + private Guid _emptyGuid; + private string _emptyId; + private Guid _currentSysId; + + public LogObserver(ILogWriter writer) + { + _writer = writer; + _emptyGuid = Guid.Empty; + _emptyId = string.Empty; + } + + public bool AutoDetachOnSystemChanged + { + get { return false; } + } + + public bool AutoInitialize + { + get { return true; } + } + + public void AttachedToSystem(IMathSystem system) + { + _currentSysId = system.InstanceId; + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SystemChanged, _emptyGuid, _emptyGuid, _emptyGuid, _emptyId, -1); + } + + public void DetachedFromSystem(IMathSystem system) + { + } + + public void BeginInitialize() + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BeginInitialize, _emptyGuid, _emptyGuid, _emptyGuid, _emptyId, -1); + } + + public void EndInitialize() + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.EndInitialize, _emptyGuid, _emptyGuid, _emptyGuid, _emptyId, -1); + } + + public void OnSignalAdded(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + public void OnSignalRemoved(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalRemoved, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + public void OnSignalMoved(Signal signal, int indexBefore, int indexAfter) + { + } + + public void OnBusAdded(Bus bus, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusAdded, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, index); + } + + public void OnBusRemoved(Bus bus, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusRemoved, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, index); + } + + public void OnBusMoved(Bus bus, int indexBefore, int indexAfter) + { + } + + public void OnPortAdded(Port port, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortAdded, port.InstanceId, _emptyGuid, _emptyGuid, port.Entity.EntityId.ToString(), index); + } + + public void OnPortRemoved(Port port, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortRemoved, port.InstanceId, _emptyGuid, _emptyGuid, port.Entity.EntityId.ToString(), index); + } + + public void OnPortMoved(Port port, int indexBefore, int indexAfter) + { + } + + public void OnInputAdded(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.InputAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + public void OnInputRemoved(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.InputRemoved, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + public void OnInputMoved(Signal signal, int indexBefore, int indexAfter) + { + } + + public void OnOutputAdded(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.OutputAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + public void OnOutputRemoved(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.OutputRemoved, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + public void OnOutputMoved(Signal signal, int indexBefore, int indexAfter) + { + } + + public void OnPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortDrivesSignal, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), outputIndex); + } + + public void OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortUndrivesSignal, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), outputIndex); + } + + public void OnSignalDrivesPort(Signal signal, Port port, int inputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalDrivesPort, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), inputIndex); + } + + public void OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalUndrivesPort, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), inputIndex); + } + + public void OnBusAttachedToPort(Bus bus, Port port, int busIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusAttachedToPort, port.InstanceId, _emptyGuid, bus.InstanceId, port.Entity.EntityId.ToString(), busIndex); + } + + public void OnBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusDetachedFromPort, port.InstanceId, _emptyGuid, bus.InstanceId, port.Entity.EntityId.ToString(), busIndex); + } + + public void OnSignalValueChanged(Signal signal) + { + } + + public void OnBusValueChanged(Bus bus) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Containers/IdentifierDictionary.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Containers/IdentifierDictionary.cs new file mode 100644 index 0000000..d4094a9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Containers/IdentifierDictionary.cs @@ -0,0 +1,153 @@ +#region Copyright 2001-2006 Christoph Daniel Rüegg [GPL] +//Math.NET Symbolics: Yttrium, part of Math.NET +//Copyright (c) 2001-2006, Christoph Daniel Rueegg, http://cdrnet.net/. +//All rights reserved. +//This Math.NET package is available under the terms of the GPL. + +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; either version 2 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. + +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Core; +using MathNet.Symbolics.Backend; + +namespace MathNet.Symbolics.Backend.Containers +{ + [Serializable] + public class IdentifierDictionary : Dictionary>, IIdentifierDictionary, IEnumerable + { + private readonly int _labelCapacity; + + public IdentifierDictionary(int domainCapacity, int labelCapacity) + : base(domainCapacity, Config.IdentifierComparer) + { + _labelCapacity = labelCapacity; + } + + public bool ContainsKey(MathIdentifier id) + { + Dictionary inner; + if(!base.TryGetValue(id.Domain, out inner)) + return false; + else + return inner.ContainsKey(id.Label); + } + + public T GetValue(MathIdentifier id) + { + T value; + if(TryGetValue(id, out value)) + return value; + else + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + } + public bool TryGetValue(MathIdentifier id, out T value) + { + Dictionary inner; + if(base.TryGetValue(id.Domain, out inner)) + return inner.TryGetValue(id.Label, out value); + value = default(T); + return false; + } + + public bool TryGetValue(MathIdentifier id, out TSub value) where TSub : T + { + Dictionary inner; + T tmp; + if(base.TryGetValue(id.Domain, out inner) && inner.TryGetValue(id.Label, out tmp)) + { + if(tmp is TSub) + { + value = (TSub)tmp; + return true; + } + } + value = default(TSub); + return false; + } + + public T FindValue(Predicate match) + { + T value; + if(TryFindValue(match, out value)) + return value; + else + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + } + public bool TryFindValue(Predicate match, out T value) + { + foreach(T item in SelectAll()) + if(match(item)) + { + value = item; + return true; + } + value = default(T); + return false; + } + + public string FindDomainOfLabel(string label) + { + string domain; + if(TryFindDomainOfLabel(label, out domain)) + return domain; + else + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + } + public bool TryFindDomainOfLabel(string label, out string domain) + { + foreach(KeyValuePair> inner in this) + if(inner.Value.ContainsKey(label)) + { + domain = inner.Key; + return true; + } + domain = null; + return false; + } + + public IEnumerable SelectAll() + { + foreach(KeyValuePair> inner in this) + foreach(KeyValuePair value in inner.Value) + yield return value.Value; + } + IEnumerator IEnumerable.GetEnumerator() + { + return SelectAll().GetEnumerator(); + } + + public virtual void Add(MathIdentifier id, T value) + { + Dictionary inner; + if(!base.TryGetValue(id.Domain, out inner)) + { + inner = new Dictionary(_labelCapacity, Config.IdentifierComparer); + Add(id.Domain, inner); + } + inner.Add(id.Label, value); + } + + public virtual void Remove(MathIdentifier id) + { + Dictionary inner; + if(base.TryGetValue(id.Domain, out inner)) + inner.Remove(id.Label); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Properties/PropertyBag.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Properties/PropertyBag.cs new file mode 100644 index 0000000..1999a1d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Properties/PropertyBag.cs @@ -0,0 +1,146 @@ +#region Copyright 2001-2006 Christoph Daniel Rüegg [GPL] +//Math.NET Symbolics: Yttrium, part of Math.NET +//Copyright (c) 2001-2006, Christoph Daniel Rueegg, http://cdrnet.net/. +//All rights reserved. +//This Math.NET package is available under the terms of the GPL. + +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; either version 2 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. + +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Reflection; + +using MathNet.Symbolics.Core; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Backend.Properties +{ + // TODO: Redesign (inherit?) + + public class PropertyBag : IEnumerable + { + private readonly List _table; + private readonly IdentifierDictionary _properties; + + public PropertyBag() + { + _table = new List(8); + _properties = new IdentifierDictionary(4, 8); + } + + public int Count + { + get { return _table.Count; } + } + + public IProperty this[int index] + { + get { return _table[index]; } + } + + public bool ContainsProperty(MathIdentifier propertyId) + { + return _properties.ContainsKey(propertyId); + } + + public IProperty LookupProperty(MathIdentifier propertyId) + { + return _properties.GetValue(propertyId); + } + + public bool TryLookupProperty(MathIdentifier propertyId, out IProperty value) + { + return _properties.TryGetValue(propertyId, out value); + } + + public bool TryLookupProperty(MathIdentifier propertyId, out T value) where T : IProperty + { + return _properties.TryGetValue(propertyId, out value); + } + + public void AddProperty(IProperty property) + { + _properties.Add(property.TypeId, property); + _table.Add(property); + } + public void AddPropertyRange(IEnumerable properties) + { + foreach(IProperty property in properties) + AddProperty(property); + } + + public void RemoveProperty(IProperty property) + { + _properties.Remove(property.TypeId); + _table.Remove(property); + } + public void RemoveProperty(MathIdentifier propertyId) + { + IProperty property = _properties.GetValue(propertyId); + _properties.Remove(property.TypeId); + _table.Remove(property); + } + + public void RemoveAllProperties() + { + _table.Clear(); + _properties.Clear(); + } + + public void ValidatePropertiesAfterEvent(Signal signal) + { + for(int i = _table.Count - 1; i >= 0; i--) + { + IProperty property = _table[i]; + if(!property.StillValidAfterEvent(signal)) + RemoveProperty(property); + } + } + + public void ValidatePropertiesAfterDrive(Signal signal) + { + for(int i = _table.Count - 1; i >= 0; i--) + { + IProperty property = _table[i]; + if(!property.StillValidAfterDrive(signal)) + RemoveProperty(property); + } + } + + public void ValidatePropertiesAfterUndrive(Signal signal) + { + for(int i = _table.Count - 1; i >= 0; i--) + { + IProperty property = _table[i]; + if(!property.StillValidAfterUndrive(signal)) + RemoveProperty(property); + } + } + + #region Enumeration + public IEnumerator GetEnumerator() + { + return _table.GetEnumerator(); + } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return _table.GetEnumerator(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Templates/CompoundArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Templates/CompoundArchitecture.cs new file mode 100644 index 0000000..95f4019 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Templates/CompoundArchitecture.cs @@ -0,0 +1,139 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Core; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Backend.Templates +{ + public class CompoundArchitecture : Architecture + { + private IMathSystem system; + private ReadOnlySignalSet inputSignals, outputSignals; + + public CompoundArchitecture(MathIdentifier id, MathIdentifier entityId, Port port, IMathSystem system) + : base(id, entityId, false) + { + this.inputSignals = port.InputSignals; + this.outputSignals = port.OutputSignals; + this.system = system; + this.system.OutputValueChanged += system_OutputValueChanged; + + SetPort(port); + + for(int i = 0; i < inputSignals.Count; i++) + inputSignals[i].ValueChanged += CompoundArchitecture_SignalValueChanged; + system.PushInputValueRange(inputSignals); + } + + void CompoundArchitecture_SignalValueChanged(object sender, ValueNodeEventArgs e) + { + int idx = inputSignals.IndexOf((Signal)e.ValueNode); + system.PushInputValue(idx, inputSignals[idx].Value); + } + + void system_OutputValueChanged(object sender, IndexedSignalEventArgs e) + { + outputSignals[e.Index].PostNewValue(e.Signal.Value); + } + + public override bool SupportsPort(Port port) + { + return port != null && port.InputSignalCount == system.InputCount && port.OutputSignalCount == system.OutputCount && port.BusCount == system.BusCount; + } + + public override void UnregisterArchitecture() + { + foreach(Signal s in inputSignals) + s.ValueChanged -= CompoundArchitecture_SignalValueChanged; + } + + protected override void ReregisterArchitecture(Port oldPort, Port newPort) + { + this.inputSignals = newPort.InputSignals; + this.outputSignals = newPort.OutputSignals; + for(int i = 0; i < inputSignals.Count; i++) + inputSignals[i].ValueChanged += CompoundArchitecture_SignalValueChanged; + system.PushInputValueRange(inputSignals); + } + } + + public sealed class CompoundArchitectureFactory : IArchitectureFactory + { + private readonly string _xml; + private readonly MathIdentifier _architectureId; + private readonly MathIdentifier _entityId; + private readonly int _inputCnt, _outputCnt, _busCnt; + + public CompoundArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId, string xml, int inputCount, int outputCount, int busCount) + { + _architectureId = architectureId; + _entityId = entityId; + _inputCnt = inputCount; + _outputCnt = outputCount; + _busCnt = busCount; + _xml = xml; + } + public CompoundArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId, string xml) + { + _architectureId = architectureId; + _entityId = entityId; + _xml = xml; + IEntity dummy = MathSystem.ReadXmlEntity(xml, new MathIdentifier("Dummy", "Temp"), string.Empty); + _inputCnt = dummy.InputSignals.Length; + _outputCnt = dummy.OutputSignals.Length; + _busCnt = dummy.Buses.Length; + } + public CompoundArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId, MathSystem system) + { + if(system == null) + throw new ArgumentNullException("system"); + + _architectureId = architectureId; + _entityId = entityId; + _inputCnt = system.InputCount; + _outputCnt = system.OutputCount; + _busCnt = system.BusCount; + _xml = system.WriteXml(false); + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public bool SupportsPort(Port port) + { + return port != null && port.InputSignalCount == _inputCnt && port.OutputSignalCount == _outputCnt && port.BusCount == _busCnt; + } + + public IArchitecture InstantiateToPort(Port port) + { + if(port == null) throw new ArgumentNullException("port"); + IMathSystem system = MathSystem.ReadXml(_xml); + return new CompoundArchitecture(_architectureId, _entityId, port, system); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Backend/Templates/CompoundProcess.cs b/Backup/src/app/MathNet.Yttrium/Library/Backend/Templates/CompoundProcess.cs new file mode 100644 index 0000000..d902d09 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Backend/Templates/CompoundProcess.cs @@ -0,0 +1,91 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Core; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Backend.Templates +{ + public class CompoundProcess : Process + { + private MathSystem system; + private int[] inputSignalIndexes, outputSignalIndexes, busIndexes; + private Signal[] inputSignals, outputSignals; + private Bus[] buses; + + /// note: negative indexes are interpreted as internal signal indexes, incremented by one (thus -1 means the internal signal with index zero)! + /// note: negative indexes are interpreted as internal signal indexes, incremented by one (thus -1 means the internal signal with index zero)! + public CompoundProcess(MathSystem system, int[] inputSignalIndexes, int[] outputSignalIndexes, int[] busIndexes) + { + this.system = system; + this.inputSignalIndexes = inputSignalIndexes; + this.outputSignalIndexes = outputSignalIndexes; + this.busIndexes = busIndexes; + + if(inputSignalIndexes.Length != system.InputCount) + throw new ArgumentException("The count of input signal mappings doesn't match the compound process structure.", "inputSignalIndexes"); + if(outputSignalIndexes.Length != system.OutputCount) + throw new ArgumentException("The count of output signal mappings doesn't match the compound process structure.", "outputSignalIndexes"); + if(busIndexes.Length != system.BusCount) + throw new ArgumentException("The count of bus mappings doesn't match the compound process structure.", "busIndexes"); + + this.inputSignals = new Signal[inputSignalIndexes.Length]; + this.outputSignals = new Signal[outputSignalIndexes.Length]; + this.buses = new Bus[busIndexes.Length]; + + this.system.OutputValueChanged += system_OutputValueChanged; + } + + void system_OutputValueChanged(object sender, IndexedSignalEventArgs e) + { + outputSignals[e.Index].PostNewValue(e.Signal.Value); + } + + public override void Register(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + { + for(int i = 0; i < inputSignalIndexes.Length; i++) + { + this.inputSignals[i] = inputSignalIndexes[i] >= 0 ? inputSignals[inputSignalIndexes[i]] : internalSignals[-inputSignalIndexes[i] - 1]; + SenseSignal(this.inputSignals[i]); + } + for(int i = 0; i < outputSignalIndexes.Length; i++) + this.outputSignals[i] = outputSignalIndexes[i] >= 0 ? outputSignals[outputSignalIndexes[i]] : internalSignals[-outputSignalIndexes[i] - 1]; + for(int i = 0; i < busIndexes.Length; i++) + this.buses[i] = buses[busIndexes[i]]; + } + + protected override void Action(bool isInit, Signal origin) + { + if(origin != null) + { + int originIdx = Array.IndexOf(inputSignals, origin); + system.PushInputValue(originIdx, inputSignals[originIdx].Value); + } + else + system.PushInputValueRange(inputSignals); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/Architecture.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/Architecture.cs new file mode 100644 index 0000000..c59524f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/Architecture.cs @@ -0,0 +1,129 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Core +{ + public abstract class Architecture : IArchitecture + { + private MathIdentifier _id; + private bool _isInstance; // = false; + private bool _isMathematicalOperator; + private MathIdentifier _entityId; + private MathNet.Symbolics.Port _port; // = null; + + protected Architecture(MathIdentifier id, MathIdentifier entityId, bool isMathematicalOperator) + { + _id = id; + _entityId = entityId; + _isMathematicalOperator = isMathematicalOperator; + } + + public bool IsInstance + { + get { return _isInstance; } + } + + public bool IsMathematicalOperator + { + get { return _isMathematicalOperator; } + } + + public MathIdentifier ArchitectureId + { + get { return _id; } + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public MathNet.Symbolics.Port Port + { + get { return _port; } + } + + protected void SetPort(MathNet.Symbolics.Port port) + { + if(port == null) throw new ArgumentNullException("port"); + _isInstance = true; + _port = port; + } + + public virtual bool SupportsPort(MathNet.Symbolics.Port port) + { + if(port == null) throw new ArgumentNullException("port"); + return port.Entity.EntityId.Equals(_entityId); + } + + public bool RebindToPortIfSupported(MathNet.Symbolics.Port newPort) + { + if(newPort == null) throw new ArgumentNullException("newPort"); + if(newPort.Equals(_port)) + return true; + if(SupportsPort(newPort)) + { + MathNet.Symbolics.Port oldPort = _port; + UnregisterArchitecture(); + _port = newPort; + ReregisterArchitecture(oldPort, newPort); + return true; + } + return false; + } + + protected abstract void ReregisterArchitecture(MathNet.Symbolics.Port oldPort, MathNet.Symbolics.Port newPort); + + public abstract void UnregisterArchitecture(); + + public virtual ISignalSet ExecuteMathematicalOperator() + { + return _port.OutputSignals; + } + + /*internal Signal AutomaticSimplifyOutput(Signal signal) + { + for(int i = 0; i < port.OutputSignalCount; i++) + { + if(port[i] == signal) + return AutomaticSimplifyOutput(i); + } + return signal; + } + + protected virtual Signal AutomaticSimplifyOutput(int outputIndex) + { + return port[outputIndex]; + }*/ + + public override string ToString() + { + if(_port == null) + return _id.ToString(); + else + return _port.Entity.ToString() + "(" + _id.ToString() + ")"; + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/Bus.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/Bus.cs new file mode 100644 index 0000000..7618391 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/Bus.cs @@ -0,0 +1,135 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Simulation; +using MathNet.Symbolics.Mediator; +using MathNet.Symbolics.AutoEvaluation; + +namespace MathNet.Symbolics.Core +{ + public class Bus : MathNet.Symbolics.Bus, ISchedulable, IBus_BuilderAdapter + { + internal Bus() + : base() + { + Service.Instance.NotifyNewBusCreated(this); + } + + internal Bus(IValueStructure value) + : base(value) + { + Service.Instance.NotifyNewBusCreated(this); + } + + #region Value & Scheduling + /// + /// Request the scheduler to set a new value to this signal in the next delta-timestep. + /// + /// The value is not set immediately. To propagate it to the property + /// you need to simulate the model for at least one cycle or a time instant, by calling + /// or . + public override void PostNewValue(IValueStructure newValue) + { + throw new NotImplementedException(); + } + + /// + /// Request the scheduler to set a new value to this signal with a specified simulation-time delay. + /// + /// The value is not set immediately, To propagate it to the property + /// you need to simulate the model for at least at least the specified delay, by calling + /// . + /// The simulation-time delay. + public override void PostNewValue(IValueStructure newValue, TimeSpan delay) + { + throw new NotImplementedException(); + } + + // TODO: Implement Value Handling + #endregion + + protected override void OnAutoEvaluateFlag(NodeFlag flag) + { + Service.Instance.AutoEvaluateFlag(this, flag); + } + + protected override void OnAutoEvaluateProperty(NodeProperty property) + { + Service.Instance.AutoEvaluateProperty(this, property); + } + + #region System Builder + Guid IBus_BuilderAdapter.AcceptSystemBuilderBefore(ISystemBuilder builder) + { + return builder.BuildBus(Label); + } + void IBus_BuilderAdapter.AcceptSystemBuilderAfter(ISystemBuilder builder, Dictionary signalMappings, Dictionary busMappings) + { + } + #endregion + + //#region Instance Equality + ///// Two buses are equal only if they are the same instance. + //public bool Equals(Bus other) + //{ + // return other != null && _iid.Equals(other.InstanceId); + //} + ///// Two buses are equal only if they are the same instance. + //public override bool Equals(object obj) + //{ + // Bus other = obj as Bus; + // if(other == null) + // return false; + // else + // return _iid.Equals(other._iid); + //} + //public override int GetHashCode() + //{ + // return _iid.GetHashCode(); + //} + //#endregion + + #region ISchedulable Members + + bool ISchedulable.HasEvent + { + get { return HasEvent; } + set { base.SetHasEvent(value); } + } + + IValueStructure ISchedulable.CurrentValue + { + get { return Value; } + set { base.SetPresentValue(value); } + } + + void ISchedulable.NotifyOutputsNewValue() + { + OnValueChanged(); + } + #endregion + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/Entity.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/Entity.cs new file mode 100644 index 0000000..625c56f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/Entity.cs @@ -0,0 +1,213 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Reflection; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; + +namespace MathNet.Symbolics.Core +{ + //public enum InfixNotation : int + //{ + // None = 0, + // LeftAssociativeInnerOperator = 1, + // RightAssociativeInnerOperator = 2, + // PreOperator = 3, + // PostOperator = 4 + //} + + [Serializable] + public class Entity : IEntity, IEquatable + { + private readonly string _symbol; + private readonly MathIdentifier _id; + private readonly InfixNotation _notation; + private readonly int _precedenceGroup; + private readonly bool _isGeneric; // = false; + private readonly string[] _inputSignalLabels; + private readonly string[] _outputSignalLabels; + private readonly string[] _busLabels; + + public Entity(string symbol, string label, string domain, InfixNotation notation, int precedence, bool isGeneric) + : this(symbol, new MathIdentifier(label, domain), notation, precedence, isGeneric, new string[0]) { } + public Entity(string symbol, MathIdentifier id, InfixNotation notation, int precedence, bool isGeneric) + : this(symbol, id, notation, precedence, isGeneric, new string[0]) { } + public Entity(string symbol, string label, string domain, InfixNotation notation, int precedence, bool isGeneric, string[] buses) + : this(symbol, new MathIdentifier(label, domain), notation, precedence, isGeneric, buses) { } + public Entity(string symbol, MathIdentifier id, InfixNotation notation, int precedence, bool isGeneric, string[] buses) + { + _id = id; + _symbol = symbol; + _inputSignalLabels = new string[0]; + _outputSignalLabels = new string[0]; + _busLabels = buses; + _isGeneric = isGeneric; + _notation = notation; + _precedenceGroup = precedence; + } + public Entity(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals) + : this(symbol, label, domain, notation, precedence, inputSignals, outputSignals, new string[0]) { } + public Entity(string symbol, MathIdentifier id, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals) + : this(symbol, id, notation, precedence, inputSignals, outputSignals, new string[0]) { } + public Entity(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals, string[] buses) + : this(symbol, new MathIdentifier(label, domain), notation, precedence, inputSignals, outputSignals, buses) { } + public Entity(string symbol, MathIdentifier id, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals, string[] buses) + { + _id = id; + _symbol = symbol; + _inputSignalLabels = inputSignals; + _outputSignalLabels = outputSignals; + _busLabels = buses; + _notation = notation; + _precedenceGroup = precedence; + } + + public string Symbol + { + get { return _symbol; } + } + + public MathIdentifier EntityId + { + get { return _id; } + } + + public InfixNotation Notation + { + get { return _notation; } + } + + public int PrecedenceGroup + { + get { return _precedenceGroup; } + } + + public bool IsGeneric + { + get { return _isGeneric; } + } + + public string[] InputSignals + { + get { return _inputSignalLabels; } + } + + public string[] OutputSignals + { + get { return _outputSignalLabels; } + } + + public string[] Buses + { + get { return _busLabels; } + } + + public virtual IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCount) + { + return this; + } + + public MathNet.Symbolics.Port InstantiatePort(params MathNet.Symbolics.Signal[] inputSignals) + { + return InstantiatePort(inputSignals, null, null); + } + public MathNet.Symbolics.Port InstantiatePort(IList inputSignals) + { + return InstantiatePort(inputSignals, null, null); + } + public MathNet.Symbolics.Port InstantiatePort(IList inputSignals, IList outputSignals) + { + return InstantiatePort(inputSignals, outputSignals, null); + } + public virtual MathNet.Symbolics.Port InstantiatePort(IList inputSignals, IList outputSignals, IList buses) + { + IEntity entity = this; + + if(_isGeneric) + { + if(inputSignals == null) + throw new MathNet.Symbolics.Exceptions.GenericEntityPortNotInstantiableException(); + entity = CompileGenericEntity(inputSignals.Count, buses != null ? buses.Count : 0, outputSignals != null ? (int?)outputSignals.Count : null); + } + + if(entity.IsGeneric) + throw new MathNet.Symbolics.Exceptions.GenericEntityPortNotInstantiableException(); + + if((inputSignals != null && inputSignals.Count != entity.InputSignals.Length) || (buses != null && buses.Count != entity.Buses.Length)) + throw new MathNet.Symbolics.Exceptions.EntitySignalMismatchException(); + + MathNet.Symbolics.Port port; + if(outputSignals == null) + port = new Port(entity); + else + port = new Port(entity, outputSignals); + if(inputSignals != null) + port.BindInputSignals(inputSignals); + if(buses != null && buses.Count > 0) + port.BindBuses(buses); + port.EnsureArchitectureLink(); //Try to find an architecture already + + return port; + } + public MathNet.Symbolics.Port InstantiateUnboundPort() + { + return InstantiatePort(null, null, new MathNet.Symbolics.Bus[] { }); + } + + public override int GetHashCode() + { + return EntityId.GetHashCode(); + } + + public override string ToString() + { + return EntityId.ToString() + ": '" + _symbol + "'"; + } + + public bool Equals(IEntity other) + { + return other != null && EntityId.Equals(other.EntityId) && _symbol == other.Symbol; // && isGeneric == other.isGeneric + //&& inputSignalLabels.Length == other.inputSignalLabels.Length && outputSignalLabels.Length == other.outputSignalLabels.Length && busLabels.Length == other.busLabels.Length; + } + [Obsolete] + public bool Equals(Entity other) + { + return other != null && EntityId.Equals(other.EntityId) && _symbol == other.Symbol; // && isGeneric == other.isGeneric + //&& inputSignalLabels.Length == other.inputSignalLabels.Length && outputSignalLabels.Length == other.outputSignalLabels.Length && busLabels.Length == other.busLabels.Length; + } + public override bool Equals(object obj) + { + Entity entity = obj as Entity; + return entity != null && Equals(entity); + } + public bool EqualsById(IEntity other) + { + return other != null && EntityId.Equals(other.EntityId); + } + public bool EqualsById(MathIdentifier otherEntityId) + { + return EntityId.Equals(otherEntityId); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/IArchitectureFactory.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/IArchitectureFactory.cs new file mode 100644 index 0000000..8ce0d5e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/IArchitectureFactory.cs @@ -0,0 +1,32 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Core +{ + //public interface IArchitectureFactory + //{ + // MathIdentifier EntityId { get;} + // bool SupportsPort(IPort port); + // Architecture InstantiateToPort(IPort port); + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/Port.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/Port.cs new file mode 100644 index 0000000..e0e9ead --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/Port.cs @@ -0,0 +1,526 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Mediator; +using MathNet.Symbolics.Events; +using MathNet.Symbolics.AutoEvaluation; + +namespace MathNet.Symbolics.Core +{ + /// + /// Represents an Yttrium Port. Ports connect signals by operations defined + /// in interchangeable architectures. + /// + public class Port : MathNet.Symbolics.Port, IPort_BuilderAdapter, IPort_CycleAnalysis + { + private SignalSet _inputSignalSet; + private SignalSet _outputSignalSet; + private BusSet _busSet; + + private readonly IEntity _entity; + private IArchitecture _currentArchitecture; + private int _tag; + private bool _completelyConnected; + + internal Port(IEntity entity) + { + _entity = entity; + + _inputSignalSet = new SignalSet(entity.InputSignals.Length); + _outputSignalSet = new SignalSet(entity.OutputSignals.Length); + _busSet = new BusSet(entity.Buses.Length); + + _completelyConnected = _inputSignalSet.Count == 0 && _busSet.Count == 0; + + Service.Instance.NotifyNewPortCreated(this); + + for(int i = 0; i < _outputSignalSet.Count; i++) + { + _outputSignalSet[i] = new Signal(); + ((ISignal_Drive)_outputSignalSet[i]).DriveSignal(this, i); + } + } + internal Port(IEntity entity, IEnumerable outputSignals) + { + _entity = entity; + + _inputSignalSet = new SignalSet(entity.InputSignals.Length); + _outputSignalSet = new SignalSet(outputSignals); + _busSet = new BusSet(entity.Buses.Length); + + System.Diagnostics.Debug.Assert(_outputSignalSet.Count == entity.OutputSignals.Length); + + Service.Instance.NotifyNewPortCreated(this); + + _completelyConnected = true; + + for(int i = 0; i < _outputSignalSet.Count; i++) + if(_outputSignalSet[i] != null) + ((ISignal_Drive)_outputSignalSet[i]).DriveSignal(this, i); + else + _completelyConnected = false; + + _completelyConnected &= _inputSignalSet.Count == 0 && _busSet.Count == 0; + for(int i = 0; i < _outputSignalSet.Count && _completelyConnected; i++) + _completelyConnected &= _outputSignalSet[i] != null; + } + + /// + /// The entity defining this port's interface and (indirectly) its operation. + /// + public override IEntity Entity + { + get { return _entity; } + } + + /// + /// The architecture currently attached to this port. Architectures are + /// interchangeable as long as they implement this port's entity. + /// + public override IArchitecture CurrentArchitecture + { + get { return _currentArchitecture; } + } + + #region Signal Access + public override MathNet.Symbolics.Signal this[int outputIndex] + { + get { return _outputSignalSet[outputIndex]; } + } + + public override int InputSignalCount + { + get { return _inputSignalSet.Count; } + } + public override int OutputSignalCount + { + get { return _outputSignalSet.Count; } + } + public override int BusCount + { + get { return _busSet.Count; } + } + + public override ReadOnlySignalSet InputSignals + { + get { return _inputSignalSet.AsReadOnly; } + } + public override ReadOnlySignalSet OutputSignals + { + get { return _outputSignalSet.AsReadOnly; } + } + public override ReadOnlyBusSet Buses + { + get { return _busSet.AsReadOnly; } + } + + public override int IndexOfOutputSignal(MathNet.Symbolics.Signal signal) + { + for(int i = 0; i < _outputSignalSet.Count; i++) + if(_outputSignalSet[i] == signal) + return i; + return -1; + } + #endregion + + #region Connected Signals Management + public override bool IsCompletelyConnected + { + get { return _completelyConnected; } + } + + private bool UpdateIsCompletelyConnected() + { + _completelyConnected = true; + for(int i = 0; i < _inputSignalSet.Count && _completelyConnected; i++) + _completelyConnected &= _inputSignalSet[i] != null; + for(int i = 0; i < _outputSignalSet.Count && _completelyConnected; i++) + _completelyConnected &= _outputSignalSet[i] != null; + for(int i = 0; i < _busSet.Count && _completelyConnected; i++) + _completelyConnected &= _busSet[i] != null; + return _completelyConnected; + } + + public override void AddInputSignalBinding(int index, MathNet.Symbolics.Signal signal) + { + if(_inputSignalSet[index] == null) + { + _inputSignalSet[index] = signal; + for(int i = 0; i < _outputSignalSet.Count; i++) + if(_outputSignalSet[i] != null) + ((ISignal_CycleAnalysis)_inputSignalSet[index]).AddCycles(_outputSignalSet[i], Config.Random.Next()); + if(UpdateIsCompletelyConnected()) + LookupAndLinkNewArchitecture(); + } + else + { + _inputSignalSet[index] = signal; + for(int i = 0; i < _outputSignalSet.Count; i++) + if(_outputSignalSet[i] != null) + ((ISignal_CycleAnalysis)_inputSignalSet[index]).AddCycles(_outputSignalSet[i], Config.Random.Next()); + if(_completelyConnected && _currentArchitecture != null && !_currentArchitecture.RebindToPortIfSupported(this)) + LookupAndLinkNewArchitecture(); + } + + OnInputTreeChanged(index); + Service.Instance.NotifySignalDrivesPort(signal, this, index); + } + public override void RemoveInputSignalBinding(int index) + { + MathNet.Symbolics.Signal signal = _inputSignalSet[index]; + _inputSignalSet[index] = null; + _completelyConnected = false; + RemoveLinkedArchitecture(); + if(signal != null) + { + for(int i = 0; i < _outputSignalSet.Count; i++) + if(_outputSignalSet[i] != null) + ((ISignal_CycleAnalysis)signal).RemoveCycles(_outputSignalSet[i], Config.Random.Next()); + + OnInputTreeChanged(index); + Service.Instance.NotifySignalDrivesPortNoLonger(signal, this, index); + } + } + public override void ReplaceInputSignalBinding(int index, MathNet.Symbolics.Signal replacement) + { + // TODO: could be optimized... + RemoveInputSignalBinding(index); + AddInputSignalBinding(index, replacement); + } + + public override void AddOutputSignalBinding(int index, MathNet.Symbolics.Signal signal) + { + if(signal == null) throw new ArgumentNullException("signal"); + if(_outputSignalSet[index] == null) + { + _outputSignalSet[index] = signal; + for(int i = 0; i < _inputSignalSet.Count; i++) + if(_inputSignalSet[i] != null) + ((ISignal_CycleAnalysis)_inputSignalSet[i]).AddCycles(_outputSignalSet[index], Config.Random.Next()); + if(UpdateIsCompletelyConnected()) + LookupAndLinkNewArchitecture(); + } + else + { + _outputSignalSet[index] = signal; + for(int i = 0; i < _inputSignalSet.Count; i++) + if(_inputSignalSet[i] != null) + ((ISignal_CycleAnalysis)_inputSignalSet[i]).AddCycles(_outputSignalSet[index], Config.Random.Next()); + if(_completelyConnected && _currentArchitecture != null && !_currentArchitecture.RebindToPortIfSupported(this)) + LookupAndLinkNewArchitecture(); + } + ((ISignal_Drive)signal).DriveSignal(this, index); + } + public override void RemoveOutputSignalBinding(int index) + { + MathNet.Symbolics.Signal signal = _outputSignalSet[index]; + _outputSignalSet[index] = null; + _completelyConnected = false; + RemoveLinkedArchitecture(); + if(signal != null) + { + for(int i = 0; i < _inputSignalSet.Count; i++) + if(_inputSignalSet[i] != null) + ((ISignal_CycleAnalysis)_inputSignalSet[i]).RemoveCycles(signal, Config.Random.Next()); + ((ISignal_Drive)signal).UndriveSignal(index); + } + } + public override void ReplaceOutputSignalBinding(int index, MathNet.Symbolics.Signal replacement) + { + // TODO: could be optimized... + RemoveOutputSignalBinding(index); + AddOutputSignalBinding(index, replacement); + } + + public override void AddBusBinding(int index, MathNet.Symbolics.Bus bus) + { + if(_busSet[index] == null) + { + _busSet[index] = bus; + if(UpdateIsCompletelyConnected()) + LookupAndLinkNewArchitecture(); + } + else + { + _busSet[index] = bus; + if(_completelyConnected && _currentArchitecture != null && !_currentArchitecture.RebindToPortIfSupported(this)) + LookupAndLinkNewArchitecture(); + } + + OnBusChanged(index); + Service.Instance.NotifyBusAttachedToPort(bus, this, index); + } + public override void RemoveBusBinding(int index) + { + MathNet.Symbolics.Bus bus = _busSet[index]; + _busSet[index] = null; + _completelyConnected = false; + RemoveLinkedArchitecture(); + + if(bus != null) + { + OnBusChanged(index); + Service.Instance.NotifyBusDetachedFromPort(bus, this, index); + } + } + public override void ReplaceBusBinding(int index, MathNet.Symbolics.Bus replacement) + { + // TODO: could be optimized... + RemoveBusBinding(index); + AddBusBinding(index, replacement); + } + + public override void RemoveAllBindings() + { + for(int i = 0; i < _inputSignalSet.Count; i++) + if(_inputSignalSet[i] != null) + RemoveInputSignalBinding(i); + for(int i = 0; i < _outputSignalSet.Count; i++) + if(_outputSignalSet[i] != null) + RemoveOutputSignalBinding(i); + for(int i = 0; i < _busSet.Count; i++) + if(_busSet[i] != null) + RemoveBusBinding(i); + } + #endregion + + #region Signal Binding + + public override void BindInputSignals(IEnumerable inputSignals) + { + for(int i = 0; i < _inputSignalSet.Count; i++) + if(_inputSignalSet[i] != null) + { + Service.Instance.NotifySignalDrivesPortNoLonger(_inputSignalSet[i], this, i); + + _inputSignalSet[i].ValueChanged -= Port_SignalValueChanged; + for(int j = 0; j < _outputSignalSet.Count; j++) + ((ISignal_CycleAnalysis)_inputSignalSet[i]).RemoveCycles(_outputSignalSet[j], Config.Random.Next()); + } + + _inputSignalSet.ReplaceRange(inputSignals); + + for(int i = 0; i < _inputSignalSet.Count; i++) + { + OnInputTreeChanged(i); + if(_inputSignalSet[i] != null) + { + _inputSignalSet[i].ValueChanged += Port_SignalValueChanged; + for(int j = 0; j < _outputSignalSet.Count; j++) + ((ISignal_CycleAnalysis)_inputSignalSet[i]).AddCycles(_outputSignalSet[j], Config.Random.Next()); + + Service.Instance.NotifySignalDrivesPort(_inputSignalSet[i], this, i); + } + } + + if(UpdateIsCompletelyConnected() && _currentArchitecture != null && !_currentArchitecture.RebindToPortIfSupported(this)) + LookupAndLinkNewArchitecture(); + } + + public override void BindBuses(IEnumerable buses) + { + for(int i = 0; i < _busSet.Count; i++) + Service.Instance.NotifyBusDetachedFromPort(_busSet[i], this, i); + + _busSet.ReplaceRange(buses); + + for(int i = 0; i < _busSet.Count; i++) + { + OnBusChanged(i); + Service.Instance.NotifyBusAttachedToPort(_busSet[i], this, i); + } + + if(UpdateIsCompletelyConnected() && _currentArchitecture != null && !_currentArchitecture.RebindToPortIfSupported(this)) + LookupAndLinkNewArchitecture(); + } + + private void Port_SignalValueChanged(object sender, ValueNodeEventArgs e) + { + EnsureArchitectureLink(); + } + #endregion + + #region Architecture Link + + public override bool HasArchitectureLink + { + get { return _currentArchitecture != null; } + } + + /// + /// Checks if the current architecture still matches the bound signals + /// and tries to find a matching architecture if not. + /// + /// True if there's a matching architecture linked after the call. + public override bool EnsureArchitectureLink() + { + bool ok = false; + ILibrary lib = Service.Instance; + + if(_currentArchitecture != null && _currentArchitecture.SupportsPort(this)) + ok = true; + else if(_completelyConnected && lib.ContainsArchitecture(this)) + { + IArchitecture oldArchitecture = _currentArchitecture; + if(_currentArchitecture != null) + { + _currentArchitecture.UnregisterArchitecture(); + _currentArchitecture = null; + } + _currentArchitecture = lib.LookupArchitecture(this).InstantiateToPort(this); + OnArchitectureChanged(oldArchitecture, _currentArchitecture); + ok = true; + } + + return ok && _currentArchitecture.IsInstance; + } + + private bool LookupAndLinkNewArchitecture() + { + ILibrary lib = Service.Instance; + + if(lib.ContainsArchitecture(this)) + { + IArchitecture oldArchitecture = _currentArchitecture; + RemoveLinkedArchitecture(); + _currentArchitecture = lib.LookupArchitecture(this).InstantiateToPort(this); + OnArchitectureChanged(oldArchitecture, _currentArchitecture); + return true; + } + else + return false; + } + + public override void RemoveLinkedArchitecture() + { + if(_currentArchitecture != null) + { + IArchitecture oldArchitecture = _currentArchitecture; + _currentArchitecture.UnregisterArchitecture(); + _currentArchitecture = null; + OnArchitectureChanged(oldArchitecture, null); + } + } + #endregion + + protected override void OnAutoEvaluateFlag(NodeFlag flag) + { + Service.Instance.AutoEvaluateFlag(this, flag); + } + + protected override void OnAutoEvaluateProperty(NodeProperty property) + { + Service.Instance.AutoEvaluateProperty(this, property); + } + + #region Dependency Analysis + public override bool DependsOn(MathNet.Symbolics.Signal signal) + { + return Service.Instance.ExistsSignal(this, signal.Equals, true); + } + public override bool DependsOn(MathNet.Symbolics.Port port) + { + return Service.Instance.ExistsPort(this, port.Equals, true); + } + public override bool DependsOn(MathIdentifier portEntity) + { + return Service.Instance.ExistsPort(this, delegate(MathNet.Symbolics.Port p) { return p.Entity.EntityId.Equals(portEntity); }, true); + } + #endregion + + #region Walk System [To Be Replaced] + + // TODO: Replace with the new Traversing System (will be much easier to use) + + /// Set the tag. + /// True if it was already tagged with this tag. + bool IPort_CycleAnalysis.TagWasTagged(int tag) + { + if(_tag == tag) + return true; + _tag = tag; + return false; + } + /// Remove the tag. + void IPort_CycleAnalysis.DeTag(int tag) + { + if(_tag == tag) + _tag++; + } + #endregion + + public override MathNet.Symbolics.Port CloneWithNewInputs(IList newInputs) + { + return _entity.InstantiatePort(newInputs); + } + + #region System Builder + Guid IPort_BuilderAdapter.AcceptSystemBuilder(ISystemBuilder builder, Dictionary signalMappings, Dictionary busMappings) + { + return builder.BuildPort(_entity.EntityId, + BuilderMapSignals(_inputSignalSet, signalMappings), + BuilderMapSignals(_outputSignalSet, signalMappings), + BuilderMapBuses(_busSet, busMappings)); + } + private InstanceIdSet BuilderMapSignals(SignalSet signals, Dictionary signalMappings) + { + return signals.ConvertAllToInstanceIds(delegate(MathNet.Symbolics.Signal s) { return signalMappings[s.InstanceId]; }); + } + private InstanceIdSet BuilderMapBuses(BusSet buses, Dictionary busMappings) + { + return buses.ConvertAllToInstanceIds(delegate(MathNet.Symbolics.Bus b) { return busMappings[b.InstanceId]; }); + } + #endregion + + #region Instance Equality + /// Two ports are equal only if they are the same instance. + public override bool Equals(object obj) + { + Port other = obj as Port; + if(other == null) + return false; + else + return InstanceId.Equals(other.InstanceId); + } + public override int GetHashCode() + { + return InstanceId.GetHashCode(); + } + #endregion + + public override string ToString() + { + if(_currentArchitecture == null) + return _entity.ToString(); + else + return _currentArchitecture.ToString(); + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/Process.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/Process.cs new file mode 100644 index 0000000..b9733e7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/Process.cs @@ -0,0 +1,104 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Core +{ + public abstract class Process + { + private List sensitiveSignals; + + protected Process() + { + this.sensitiveSignals = new List(8); + } + + private bool paused; // = false; + public bool Paused + { + get { return paused; } + set + { + if(value) + Pause(); + else + Continue(); + } + } + + public abstract void Register(IList inputSignals, IList outputSignals, IList internalSignals, IList buses); + + public virtual void Unregister() + { + foreach(MathNet.Symbolics.Signal signal in sensitiveSignals) + signal.ValueChanged -= signal_SignalValueChanged; + sensitiveSignals.Clear(); + } + + public void Pause() + { + if(paused) + return; + foreach(MathNet.Symbolics.Signal signal in sensitiveSignals) + signal.ValueChanged -= signal_SignalValueChanged; + paused = true; + } + + public void Continue() + { + if(!paused) + return; + foreach(MathNet.Symbolics.Signal signal in sensitiveSignals) + signal.ValueChanged += signal_SignalValueChanged; + paused = false; + } + + public void ForceUpdate() + { + Action(true, null); + } + + protected void SenseSignal(MathNet.Symbolics.Signal signal) + { + signal.ValueChanged += signal_SignalValueChanged; + sensitiveSignals.Add(signal); + } + + protected void StopSenseSignal(MathNet.Symbolics.Signal signal) + { + signal.ValueChanged -= signal_SignalValueChanged; + sensitiveSignals.Remove(signal); + + } + + /// note: may be null if not applicable + protected abstract void Action(bool isInit, MathNet.Symbolics.Signal origin); + + private void signal_SignalValueChanged(object sender, ValueNodeEventArgs e) + { + Action(false, (MathNet.Symbolics.Signal)e.ValueNode); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/Signal.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/Signal.cs new file mode 100644 index 0000000..f0d871f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/Signal.cs @@ -0,0 +1,415 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Xml.XPath; +using System.Reflection; + +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Properties; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Simulation; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Mediator; +using MathNet.Symbolics.SystemBuilder.Toolkit; +using MathNet.Symbolics.AutoEvaluation; + +namespace MathNet.Symbolics.Core +{ + /// + /// Represents an Yttrium Signal. Signals are the core elements; yttrium is + /// all about signals, their values and their relations to other signals. + /// + public class Signal : MathNet.Symbolics.Signal, ISchedulable, ISignal_CycleAnalysis, ISignal_BuilderAdapter, ISignal_Drive + { + private MathNet.Symbolics.Port _drivenByPort; // = null; + private bool _hold; // = false; + private bool _isSourceSignal = true; + private int _cycleCount; // = 0; + + private PropertyBag _properties; + private PropertyBag _constraints; + + internal Signal() + : base() + { + _properties = new PropertyBag(); + _constraints = new PropertyBag(); + + Service.Instance.NotifyNewSignalCreated(this); + } + internal Signal(IValueStructure value) + : base(value) + { + _properties = new PropertyBag(); + _constraints = new PropertyBag(); + + Service.Instance.NotifyNewSignalCreated(this); + } + + #region Value & Scheduling + /// + /// Request the scheduler to set a new value to this signal in the next delta-timestep. + /// + /// The value is not set immediately. To propagate it to the property + /// you need to simulate the model for at least one cycle or a time instant, by calling + /// or . + public override void PostNewValue(IValueStructure newValue) + { + Service.Instance.ScheduleDeltaEvent(this, newValue); + } + + /// + /// Request the scheduler to set a new value to this signal with a specified simulation-time delay. + /// + /// The value is not set immediately, To propagate it to the property + /// you need to simulate the model for at least at least the specified delay, by calling + /// . + /// The simulation-time delay. + public override void PostNewValue(IValueStructure newValue, TimeSpan delay) + { + Service.Instance.ScheduleDelayedEvent(this, newValue, delay); + } + #endregion + + #region Property Bag + public PropertyBag Properties + { + get { return _properties; } + } + + public PropertyBag Constraints + { + get { return _constraints; } + } + + /// Checks whether a property is set. + public override bool HasProperty(MathIdentifier propertyId) + { + return _constraints.ContainsProperty(propertyId) || _properties.ContainsProperty(propertyId); + } + + /// Updates the property accoring to propagation theorems and checks whether it is (or should be) set. + public override bool AskForProperty(MathIdentifier propertyType) + { + if(_constraints.ContainsProperty(propertyType)) + return true; + + //ITheoremProvider provider; + //if(Service.Instance.TryLookupTheoremType(new MathIdentifier("", "TheoremProvider"), out provider)) + //{ + //} + + // TODO: IMPLEMENT, as soons as the new property provider infrastructure is available + + //PropertyProviderTable table; + //if(((Library)_context.Library).Theorems.TryLookupPropertyProvider(propertyType, out table)) + // return table.UpdateProperty(this); + //else + // return Properties.ContainsProperty(propertyType); + return false; + } + + public override void AddConstraint(IProperty property) + { + _constraints.AddProperty(property); + } + + public override void RemoveAllConstraints() + { + _constraints.RemoveAllProperties(); + } + #endregion + + protected override void OnAutoEvaluateFlag(NodeFlag flag) + { + Service.Instance.AutoEvaluateFlag(this, flag); + } + + protected override void OnAutoEvaluateProperty(NodeProperty property) + { + Service.Instance.AutoEvaluateProperty(this, property); + } + + #region Drive State + /// + /// True if this signal is driven by a port (attached to a port output). + /// + public override bool IsDriven + { + get { return _drivenByPort != null; } + } + + + + /// + /// Writeable. True if this signal is either undriven or declared as being a source signal. + /// + public override bool IsSourceSignal + { + get { return _isSourceSignal; } + set + { + _isSourceSignal = value; + if(_drivenByPort == null) + _isSourceSignal = true; + } + } + + /// + /// Writeable. True if the signal should behave as if it weren't driven. + /// + public override bool Hold + { + get { return _hold; } + set { _hold = value; } + } + + /// + /// The port this signal is attached to. + /// + public override MathNet.Symbolics.Port DrivenByPort + { + get { return _drivenByPort; } + } + + void ISignal_Drive.DriveSignal(MathNet.Symbolics.Port source, int outputIndex) + { + if(IsDriven) + Service.Instance.NotifyPortDrivesSignalNoLonger(this, _drivenByPort, _drivenByPort.OutputSignals.IndexOf(this)); + + _drivenByPort = source; + _isSourceSignal = false; + _properties.ValidatePropertiesAfterDrive(this); + + Service.Instance.NotifyPortDrivesSignal(this, source, outputIndex); + } + void ISignal_Drive.UndriveSignal(int outputIndex) + { + if(IsDriven) + Service.Instance.NotifyPortDrivesSignalNoLonger(this, _drivenByPort, outputIndex); + + _drivenByPort = null; + _isSourceSignal = true; + _properties.ValidatePropertiesAfterUndrive(this); + } + #endregion + + #region Operators: Builder Shortcuts + protected override MathNet.Symbolics.Signal AddSignalCore(MathNet.Symbolics.Signal summand) + { + return Std.Add(this, summand); + } + + protected override MathNet.Symbolics.Signal NegateSignalCore() + { + return StdBuilder.Negate(this); + } + + protected override MathNet.Symbolics.Signal SubtractSignalCore(MathNet.Symbolics.Signal subtrahend) + { + return Std.Subtract(this, subtrahend); + } + + protected override MathNet.Symbolics.Signal MultiplySignalCore(MathNet.Symbolics.Signal multiplier) + { + return Std.Multiply(this, multiplier); + } + + protected override MathNet.Symbolics.Signal DivideSignalCore(MathNet.Symbolics.Signal divisor) + { + return Std.Divide(this, divisor); + } + #endregion + + #region Cycle Tracking [TODO: Port to new Traversing System] + public override bool IsCyclic + { + get { return _cycleCount > 0; } + } + public override int Cycles + { + get { return _cycleCount; } + } + + /// needs to be called as soon as soon as it becomes connected through its driven port to an output signal -> run with each output signal as source parameter. + public int AddCycles(MathNet.Symbolics.Signal source, int tag) + { + if(this == source) + { + _cycleCount++; + return 1; + } + if(IsSourceSignal || !IsDriven) + return 0; + else + { + int ret = 0; + if(!((IPort_CycleAnalysis)_drivenByPort).TagWasTagged(tag)) //was not tagged with this tag before. + { + foreach(Signal item in _drivenByPort.InputSignals) + if(item != null) + ret += item.AddCycles(source, tag); + ((IPort_CycleAnalysis)_drivenByPort).DeTag(tag); + } + _cycleCount += ret; + return ret; + } + } + + /// needs to be called as soon as soon as it becomes disconnected through its driven port to an output signal -> run with each output signal as source parameter. + public int RemoveCycles(MathNet.Symbolics.Signal source, int tag) + { + if(this == source) + { + System.Diagnostics.Debug.Assert(_cycleCount >= 1); + _cycleCount--; + return 1; + } + if(IsSourceSignal || !IsDriven) + return 0; + else + { + int ret = 0; + if(!((IPort_CycleAnalysis)_drivenByPort).TagWasTagged(tag)) //was not tagged with this tag before. + { + foreach(Signal item in _drivenByPort.InputSignals) + ret += item.RemoveCycles(source, tag); + ((IPort_CycleAnalysis)_drivenByPort).DeTag(tag); + } + System.Diagnostics.Debug.Assert(_cycleCount >= ret); + _cycleCount -= ret; + return ret; + } + } + #endregion + + #region Dependency Analysis + /// + /// True if the signal depends on a specified signal, and thus posting a new value to the specified signal may influence this signal's value. + /// + public override bool DependsOn(MathNet.Symbolics.Signal signal) + { + return Service.Instance.ExistsSignal(this, signal.Equals, true); + } + /// + /// True if the signal depends on a specified port. + /// + public override bool DependsOn(MathNet.Symbolics.Port port) + { + return Service.Instance.ExistsPort(this, port.Equals, true); + } + /// + /// True if the signal depends on a port with the specified entity. + /// + public override bool DependsOn(MathIdentifier portEntity) + { + return Service.Instance.ExistsPort(this, delegate(MathNet.Symbolics.Port p) { return p.Entity.EntityId.Equals(portEntity); }, true); + } + #endregion + + #region System Builder + Guid ISignal_BuilderAdapter.AcceptSystemBuilderBefore(ISystemBuilder builder) + { + return builder.BuildSignal(Label, _hold, _isSourceSignal); + } + void ISignal_BuilderAdapter.AcceptSystemBuilderAfter(ISystemBuilder builder, Dictionary signalMappings, Dictionary busMappings) + { + Guid guid = signalMappings[InstanceId]; + if(Value != null) + builder.AppendSignalValue(guid, CustomDataPack.Pack(Value, signalMappings, busMappings)); + foreach(IProperty property in _properties) + builder.AppendSignalProperty(guid, CustomDataPack.Pack(property, signalMappings, busMappings)); + foreach(IProperty constraint in _constraints) + builder.AppendSignalConstraint(guid, CustomDataPack.Pack(constraint, signalMappings, busMappings)); + } + void ISignal_BuilderAdapter.BuilderSetValue(IValueStructure structure) + { + SetPresentValue(structure); + } + void ISignal_BuilderAdapter.BuilderAppendProperty(IProperty property) + { + _properties.AddProperty(property); + } + void ISignal_BuilderAdapter.BuilderAppendConstraint(IProperty constraint) + { + _constraints.AddProperty(constraint); + } + #endregion + + //#region Instance Equality + ///// Two signals are equal only if they are the same instance. Use instead if you need to check for equivalent signals. + //public bool Equals(Signal other) + //{ + // return other != null && _iid.Equals(other.InstanceId); + //} + ///// Two signals are equal only if they are the same instance. Use instead if you need to check for equivalent signals. + //public override bool Equals(object obj) + //{ + // Signal other = obj as Signal; + // if(other == null) + // return false; + // else + // return _iid.Equals(other._iid); + //} + //public override int GetHashCode() + //{ + // return _iid.GetHashCode(); + //} + //#endregion + + public override string ToString() + { + string name = string.IsNullOrEmpty(Label) ? "Signal " + InstanceId.ToString() : "Signal " + Label; + if(Value != null) + name += " (" + Value.ToString() + ")"; + string driven = IsDriven ? "driven" : "undriven"; + string cyclic = IsCyclic ? "cyclic" : "noncyclic"; + string hold = Hold ? "hold" : "nonhold"; + return name + " [" + driven + ";" + cyclic + ";" + hold + "]"; + } + + #region ISchedulable Members + + bool ISchedulable.HasEvent + { + get { return HasEvent; } + set { base.SetHasEvent(value); } + } + + IValueStructure ISchedulable.CurrentValue + { + get { return Value; } + set { base.SetPresentValue(value); } + } + + void ISchedulable.NotifyOutputsNewValue() + { + OnValueChanged(); + } + #endregion + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library/Core/ValueStructure.cs b/Backup/src/app/MathNet.Yttrium/Library/Core/ValueStructure.cs new file mode 100644 index 0000000..3b9a5de --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Core/ValueStructure.cs @@ -0,0 +1,104 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Reflection; + +namespace MathNet.Symbolics.Core +{ + public abstract class ValueStructure : IValueStructure + { + public abstract MathIdentifier TypeId { get;} + + #region Equality + public abstract bool Equals(IValueStructure other); + public override bool Equals(object obj) + { + ValueStructure vs = obj as ValueStructure; + if(vs != null) + return Equals(vs); + return false; + } + + public bool EqualsById(IValueStructure other) + { + return other != null && TypeId.Equals(other.TypeId); + } + public bool EqualsById(MathIdentifier otherStructureId) + { + return TypeId.Equals(otherStructureId); + } + #endregion + + public override string ToString() + { + return TypeId.ToString(); + } + + #region Serialization + //protected abstract void InnerSerialize(XmlWriter writer); + //public static void Serialize(XmlWriter writer, ValueStructure value) + //{ + // if(value == null) throw new ArgumentNullException("value"); + // if(writer == null) throw new ArgumentNullException("writer"); + // writer.WriteStartElement("Structure"); + // writer.WriteAttributeString("type", value.GetType().AssemblyQualifiedName); + // value.InnerSerialize(writer); + // writer.WriteEndElement(); + //} + //public static ValueStructure Deserialize(IContext context, XmlReader reader) + //{ + // if(reader == null) throw new ArgumentNullException("reader"); + // reader.ReadToDescendant("Structure"); + // Type type = Type.GetType(reader.GetAttribute("type"), true); + // reader.Read(); + // MethodInfo mi = type.GetMethod("InnerDeserialize", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); + // ValueStructure ret = (ValueStructure)mi.Invoke(null, new object[] { context, reader }); + // return ret; + //} + #endregion + + #region ICustomData Members + public virtual void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + } + //private static ValueStructure Deserialize(XmlReader reader, IDictionary signals, IDictionary buses); + + public virtual bool ReferencesCoreObjects + { + get { return false; } + } + + public virtual IEnumerable CollectSignals() + { + yield break; + //return SingletonProvider>.Instance; + } + public virtual IEnumerable CollectBuses() + { + yield break; + //return SingletonProvider>.Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/CoreFactory.cs b/Backup/src/app/MathNet.Yttrium/Library/CoreFactory.cs new file mode 100644 index 0000000..0e833ff --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/CoreFactory.cs @@ -0,0 +1,79 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Core; + +namespace MathNet.Symbolics +{ + internal class CoreFactory : + IFactory, + IFactory, + IFactory, + IFactory, + IFactory, + IFactory>, + IFactory + { + // Signal + Signal IFactory.GetInstance() + { + return new MathNet.Symbolics.Core.Signal(); + } + Signal IFactory.GetInstance(IValueStructure value) + { + return new MathNet.Symbolics.Core.Signal(value); + } + + // Bus + Bus IFactory.GetInstance() + { + return new MathNet.Symbolics.Core.Bus(); + } + Bus IFactory.GetInstance(IValueStructure value) + { + return new MathNet.Symbolics.Core.Bus(value); + } + + // Port + Port IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: IEntity"); + } + Port IFactory.GetInstance(IEntity entity) + { + return new MathNet.Symbolics.Core.Port(entity); + } + Port IFactory>.GetInstance(IEntity entity, IEnumerable outputSignals) + { + return new MathNet.Symbolics.Core.Port(entity, outputSignals); + } + + // MathSystem + IMathSystem IFactory.GetInstance() + { + return new MathNet.Symbolics.Workplace.MathSystem(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Library/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4b5d03b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium: Computer Algebra Library")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info/")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("231d5800-e307-4377-ab0e-1213b5384ee8")] + +[assembly: AssemblyVersion("2006.6.1.*")] +[assembly: AssemblyFileVersion("2006.6.1.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Library/Properties/Resources.Designer.cs b/Backup/src/app/MathNet.Yttrium/Library/Properties/Resources.Designer.cs new file mode 100644 index 0000000..3f3ef98 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Properties/Resources.resx b/Backup/src/app/MathNet.Yttrium/Library/Properties/Resources.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Library/Workplace/MathFunction.cs b/Backup/src/app/MathNet.Yttrium/Library/Workplace/MathFunction.cs new file mode 100644 index 0000000..bcf519c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Workplace/MathFunction.cs @@ -0,0 +1,114 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Core; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Workplace +{ + public class MathFunction + { + private MathSystem system; + private IEntity entity; + + public MathFunction(IEntity entity, MathSystem system) + { + this.entity = entity; + this.system = system; + } + public MathFunction(IEntity entity) + { + this.entity = entity; + } + public MathFunction(MathSystem system) + { + this.system = system; + } + public MathFunction(Signal outputSignal, params Signal[] inputSignals) + { + this.system = new MathSystem(); + system.AddSignalTree(outputSignal, inputSignals, true, true); + } + + public MathSystem System + { + get { return system; } + } + public bool HasSystem + { + get { return system != null; } + } + + public IEntity Entity + { + get { return entity; } + } + public bool HasEntity + { + get { return entity != null; } + } + + public ReadOnlySignalSet Apply(params Signal[] arguments) + { + BuildEntity(); + return Service.Instance.Functions(entity, arguments); + } + + public IValueStructure[] Evaluate(params IValueStructure[] inputs) + { + BuildSystem(); + return system.Evaluate(inputs); + } + + public double[] Evaluate(params double[] inputs) + { + BuildSystem(); + return system.Evaluate(inputs); + } + + public IEntity BuildEntity() + { + if(!HasEntity) + entity = system.PublishToLibraryAnonymous(); + return entity; + } + + public MathSystem BuildSystem() + { + if(!HasSystem) + { + IEntity localEntity = entity; + if(entity.IsGeneric) + localEntity = entity.CompileGenericEntity(1,0,null); + Signal[] inputs = new Signal[localEntity.InputSignals.Length]; + ReadOnlySignalSet outputs = Service.Instance.Functions(localEntity, inputs); + system = new MathSystem(); + system.AddSignalTreeRange(outputs, true, true); + } + return system; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Workplace/MathSystem.cs b/Backup/src/app/MathNet.Yttrium/Library/Workplace/MathSystem.cs new file mode 100644 index 0000000..25533a7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Workplace/MathSystem.cs @@ -0,0 +1,969 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using System.IO; +using System.Xml; +using System.Xml.XPath; +using System.Xml.Serialization; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Templates; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Backend.Channels; +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Simulation; +using MathNet.Symbolics.Mediator; +using MathNet.Symbolics.Events; +using MathNet.Symbolics.SystemBuilder.Toolkit; + +namespace MathNet.Symbolics.Workplace +{ + public class MathSystem : IMathSystem, ISystemMediatorSource + { + private readonly Guid _iid; + + private readonly SignalSet _inputs; + private readonly SignalSet _outputs; + + private readonly SignalSet _allSignals; + private readonly BusSet _allBuses; + private readonly PortSet _allPorts; + + private Dictionary _namedSignals; + private Dictionary _namedBuses; + + private ISystemMediator _systemMediator; + + public event EventHandler OutputValueChanged; + + public MathSystem() + { + _iid = Config.GenerateInstanceId(); + + _inputs = new SignalSet(); + _outputs = new SignalSet(); + _allSignals = new SignalSet(); + _allBuses = new BusSet(); + _allPorts = new PortSet(); + } + + #region Properties + public bool HasSystemMediator + { + get { return _systemMediator != null; } + } + public ISystemMediator SystemMediator + { + get { return _systemMediator; } + set + { + if(_systemMediator != null) + _systemMediator.UnsubscribeSystem(this); + _systemMediator = value; + if(value != null) + _systemMediator.SubscribeSystem(this); + } + } + + public Guid InstanceId + { + get { return _iid; } + } + #endregion + + #region Readonly Direct Access + #region Count + public int SignalCount + { + get { return _allSignals.Count; } + } + public int BusCount + { + get { return _allBuses.Count; } + } + public int PortCount + { + get { return _allPorts.Count; } + } + public int InputCount + { + get { return _inputs.Count; } + } + public int OutputCount + { + get { return _outputs.Count; } + } + #endregion + #region Contains + public bool ContainsSignal(Signal signal) + { + return _allSignals.Contains(signal); + } + public bool ContainsBus(Bus bus) + { + return _allBuses.Contains(bus); + } + public bool ContainsPort(Port port) + { + return _allPorts.Contains(port); + } + #endregion + #region Get By Index + public Signal GetSignal(int index) + { + return _allSignals[index]; + } + public Bus GetBus(int index) + { + return _allBuses[index]; + } + public Port GetPort(int index) + { + return _allPorts[index]; + } + public Signal GetInput(int index) + { + return _inputs[index]; + } + public Signal GetOutput(int index) + { + return _outputs[index]; + } + #endregion + #region GetAll Readonly Sets + public ReadOnlySignalSet GetAllSignals() + { + return _allSignals.AsReadOnly; + } + public ReadOnlyBusSet GetAllBuses() + { + return _allBuses.AsReadOnly; + } + public ReadOnlyPortSet GetAllPorts() + { + return _allPorts.AsReadOnly; + } + public ReadOnlySignalSet GetAllInputs() + { + return _inputs.AsReadOnly; + } + public ReadOnlySignalSet GetAllOutputs() + { + return _outputs.AsReadOnly; + } + #endregion + public ReadOnlySignalSet GetAllLeafSignals() + { + return new ReadOnlySignalSet(_allSignals.FindAll(delegate(Signal signal) { return signal.BehavesAsSourceSignal; })); // && !inputSignals.Exists(delegate(Signal s) { return signal.DependsOn(s); }); }).AsReadOnly(); + } + #endregion + + #region Private Write Direct Access + private void InternalAddSignal(Signal signal) + { + int idx = _allSignals.Count; + _allSignals.Add(signal); + if(_systemMediator != null) + _systemMediator.NotifySignalAdded(signal, idx); + } + private void InternalRemoveSignal(Signal signal) + { + if(_inputs.Contains(signal)) + InternalRemoveInput(signal); + if(_outputs.Contains(signal)) + InternalRemoveOutput(signal); + int idx = _allSignals.IndexOf(signal); + _allSignals.RemoveAt(idx); + if(_systemMediator != null) + { + _systemMediator.NotifySignalRemoved(signal, idx); + for(int i = idx; i < _allSignals.Count; i++) + _systemMediator.NotifySignalMoved(_allSignals[i], idx + 1, idx); + } + } + private void InternalAddBus(Bus bus) + { + int idx = _allBuses.Count; + _allBuses.Add(bus); + if(_systemMediator != null) + _systemMediator.NotifyBusAdded(bus, idx); + } + private void InternalRemoveBus(Bus bus) + { + int idx = _allBuses.IndexOf(bus); + _allBuses.RemoveAt(idx); + if(_systemMediator != null) + { + _systemMediator.NotifyBusRemoved(bus, idx); + for(int i = idx; i < _allBuses.Count; i++) + _systemMediator.NotifyBusMoved(_allBuses[i], idx + 1, idx); + } + } + private void InternalAddPort(Port port) + { + int idx = _allPorts.Count; + _allPorts.Add(port); + if(_systemMediator != null) + { + _systemMediator.NotifyPortAdded(port, idx); + idx = 0; + foreach(Signal s in port.InputSignals) + if(_allSignals.Contains(s)) + _systemMediator.NotifySignalDrivesPort(s, port, idx++); + idx = 0; + foreach(Signal s in port.OutputSignals) + if(_allSignals.Contains(s)) + _systemMediator.NotifyPortDrivesSignal(s, port, idx++); + idx = 0; + foreach(Bus b in port.Buses) + if(_allBuses.Contains(b)) + _systemMediator.NotifyBusAttachedToPort(b, port, idx++); + } + } + private void InternalRemovePort(Port port) + { + int idx = _allPorts.IndexOf(port); + _allPorts.RemoveAt(idx); + if(_systemMediator != null) + { + _systemMediator.NotifyPortRemoved(port, idx); + for(int i = idx; i < _allPorts.Count; i++) + _systemMediator.NotifyPortMoved(_allPorts[i], idx + 1, idx); + } + } + private void InternalAddInput(Signal signal) + { + int idx = _inputs.Count; + _inputs.Add(signal); + if(_systemMediator != null) + _systemMediator.NotifyInputAdded(signal, idx); + } + private void InternalRemoveInput(Signal signal) + { + int idx = _inputs.IndexOf(signal); + _inputs.RemoveAt(idx); + if(_systemMediator != null) + { + _systemMediator.NotifyInputRemoved(signal, idx); + for(int i = idx; i < _inputs.Count; i++) + _systemMediator.NotifyInputMoved(_inputs[i], idx + 1, idx); + } + } + private void InternalAddOutput(Signal signal) + { + int idx = _outputs.Count; + _outputs.Add(signal); + if(_systemMediator != null) + _systemMediator.NotifyOutputAdded(signal, idx); + } + private void InternalRemoveOutput(Signal signal) + { + int idx = _outputs.IndexOf(signal); + _outputs.RemoveAt(idx); + if(_systemMediator != null) + { + _systemMediator.NotifyOutputRemoved(signal, idx); + for(int i = idx; i < _outputs.Count; i++) + _systemMediator.NotifyOutputMoved(_outputs[i], idx + 1, idx); + } + } + #endregion + + #region System Components + public void AddSignal(Signal signal) + { + if(!_allSignals.Contains(signal)) + InternalAddSignal(signal); + } + public void AddSignalRange(IEnumerable signals) + { + foreach(Signal signal in signals) + if(!_allSignals.Contains(signal)) + InternalAddSignal(signal); + } + public void RemoveSignal(Signal signal, bool isolateFromDriver) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(isolateFromDriver && signal.IsDriven) + signal.DrivenByPort.RemoveOutputSignalBinding(signal.DrivenByPort.OutputSignals.IndexOf(signal)); + if(_allSignals.Contains(signal)) + InternalRemoveSignal(signal); + } + public void AddBus(Bus bus) + { + if(!_allBuses.Contains(bus)) + InternalAddBus(bus); + } + public void AddBusRange(IEnumerable buses) + { + if(buses == null) + throw new ArgumentNullException("buses"); + + foreach(Bus bus in buses) + if(!_allBuses.Contains(bus)) + InternalAddBus(bus); + } + public void RemoveBus(Bus bus) + { + if(_allBuses.Contains(bus)) + InternalRemoveBus(bus); + } + public void AddPort(Port port) + { + if(!_allPorts.Contains(port)) + InternalAddPort(port); + } + public void RemovePort(Port port, bool isolate) + { + if(port == null) + throw new ArgumentNullException("port"); + + if(isolate) + port.RemoveAllBindings(); + if(_allPorts.Contains(port)) + InternalRemovePort(port); + } + public void AddSignalTree(Signal signal, bool setAsOutput, bool autoAddInputs) + { + if(signal == null) + return; + + AddSignal(signal); + if(setAsOutput) + PromoteAsOutput(signal); + + Service.Instance.ForEachSignal(signal, delegate(Signal s) + { + if(!_allSignals.Contains(s)) + { + InternalAddSignal(s); + if(autoAddInputs && !s.IsDriven && !Std.IsConstant(s)) + InternalAddInput(s); + } + return true; + }, true); + + foreach(Signal s in _allSignals) + { + if(s.BehavesAsBeingDriven(false)) + { + Port p = s.DrivenByPort; + if(!_allPorts.Contains(p)) + { + AddBusRange(p.Buses); + InternalAddPort(p); + } + } + } + } + public void AddSignalTree(Signal signal, ICollection border, bool setAsOutput, bool autoAddInputs) + { + if(signal == null) + return; + + AddSignal(signal); + if(setAsOutput) + PromoteAsOutput(signal); + + Service.Instance.ForEachSignal(signal, delegate(Signal s) + { + if(!_allSignals.Contains(s)) + { + InternalAddSignal(s); + if(autoAddInputs && !s.IsDriven && !Std.IsConstant(s)) + InternalAddInput(s); + } + if(border.Contains(s)) + { + PromoteAsInput(s); + return false; + } + return true; + }, true); + + foreach(Signal s in _allSignals) + { + if(s.BehavesAsBeingDriven(false)) + { + Port p = s.DrivenByPort; + if(!_allPorts.Contains(p)) + { + AddBusRange(p.Buses); + InternalAddPort(p); + } + } + } + } + public void AddSignalTreeRange(IEnumerable signals, bool setAsOutput, bool autoAddInputs) + { + foreach(Signal signal in signals) + AddSignalTree(signal, setAsOutput, autoAddInputs); + } + public void AddSignalTreeRange(IEnumerable signals, ICollection border, bool setAsOutput, bool autoAddInputs) + { + foreach(Signal signal in signals) + AddSignalTree(signal, border, setAsOutput, autoAddInputs); + } + + public void AddPortTree(Port port, bool setAsOutput, bool autoAddInputs) + { + AddSignalTreeRange(port.OutputSignals, setAsOutput, autoAddInputs); + } + + /// the input index of the input signal + public int PromoteAsInput(Signal signal) + { + AddSignal(signal); + if(!_inputs.Contains(signal)) + InternalAddInput(signal); + return _inputs.LastIndexOf(signal); + } + public void UnpromoteAsInput(Signal signal) + { + if(_inputs.Contains(signal)) + InternalRemoveInput(signal); + } + + /// the output index of the output signal + public int PromoteAsOutput(Signal signal) + { + if(!_outputs.Contains(signal)) + { + AddSignal(signal); + InternalAddOutput(signal); + RegisterOutputSignal(signal); + } + return _outputs.LastIndexOf(signal); + } + public void UnpromoteAsOutput(Signal signal) + { + if(_outputs.Contains(signal)) + { + UnregisterOutputSignal(signal); + InternalRemoveOutput(signal); + } + } + #endregion + + #region Named Signals + public Signal CreateNamedSignal(string name) + { + Signal s = Binder.CreateSignal(); + AddNamedSignal(name, s); + return s; + } + public Signal AddNamedSignal(string name, Signal signal) + { + if(_namedSignals == null) + _namedSignals = new Dictionary(); + AddSignal(signal); + signal.Label = name; + _namedSignals.Add(name, signal); + return signal; + } + public Signal AddNamedSignal(string name, IValueStructure value) + { + if(_namedSignals == null) + _namedSignals = new Dictionary(); + Signal signal = Binder.CreateSignal(value); + AddSignal(signal); + signal.Label = name; + _namedSignals.Add(name, signal); + return signal; + } + public Signal LookupNamedSignal(string name) + { + if(_namedSignals == null) + throw new KeyNotFoundException(); + return _namedSignals[name]; + } + public bool TryLookupNamedSignal(string name, out Signal signal) + { + if(_namedSignals == null) + { + signal = null; + return false; + } + return _namedSignals.TryGetValue(name, out signal); + } + public bool ContainsNamedSignal(string name) + { + if(_namedSignals == null) + return false; + return _namedSignals.ContainsKey(name); + } + public void RemoveNamedSignal(string name) + { + if(_namedSignals == null) + return; + _namedSignals.Remove(name); + } + #endregion + #region Named Buses + public Bus CreateNamedBus(string name) + { + Bus b = Binder.CreateBus(); + AddNamedBus(name, b); + return b; + } + public void AddNamedBus(string name, Bus bus) + { + if(_namedBuses == null) + _namedBuses = new Dictionary(); + AddBus(bus); + bus.Label = name; + _namedBuses.Add(name, bus); + } + public Bus LookupNamedBus(string name) + { + if(_namedBuses == null) + throw new KeyNotFoundException(); + return _namedBuses[name]; + } + public bool TryLookupNamedBus(string name, out Bus bus) + { + if(_namedBuses == null) + { + bus = null; + return false; + } + return _namedBuses.TryGetValue(name, out bus); + } + public bool ContainsNamedBus(string name) + { + if(_namedBuses == null) + return false; + return _namedBuses.ContainsKey(name); + } + public void RemoveNamedBus(string name) + { + if(_namedBuses == null) + return; + _namedBuses.Remove(name); + } + #endregion + + #region Value Forwarding + #region Input Signals + public void PushInputValue(int inputIndex, IValueStructure value) + { + _inputs[inputIndex].PostNewValue(value); + } + public void PushInputValue(int inputIndex, IValueStructure value, TimeSpan delay) + { + _inputs[inputIndex].PostNewValue(value, delay); + } + public void PushInputValueRange(IEnumerable values) + { + int idx = 0; + foreach(IValueStructure value in values) + _inputs[idx++].PostNewValue(value); + } + public void PushInputValueRange(IEnumerable values, TimeSpan delay) + { + int idx = 0; + foreach(IValueStructure value in values) + _inputs[idx++].PostNewValue(value, delay); + } + public void PushInputValueRange(IEnumerable signalsWithValues) + { + int idx = 0; + foreach(Signal signal in signalsWithValues) + _inputs[idx++].PostNewValue(signal.Value); + } + public void PushInputValueRange(IEnumerable signalsWithValues, TimeSpan delay) + { + int idx = 0; + foreach(Signal signal in signalsWithValues) + _inputs[idx++].PostNewValue(signal.Value, delay); + } + #endregion + #region Output Signals + private void RegisterOutputSignal(Signal s) + { + s.ValueChanged += s_SignalValueChanged; + } + //private void RegisterOutputSignalRange(IEnumerable signals) + //{ + // foreach(Signal s in signals) + // RegisterOutputSignal(s); + //} + + private void UnregisterOutputSignal(Signal s) + { + s.ValueChanged -= s_SignalValueChanged; + } + //private void UnregisterOutputSignalRange(IEnumerable signals) + //{ + // foreach(Signal s in signals) + // UnregisterOutputSignal(s); + //} + + void s_SignalValueChanged(object sender, ValueNodeEventArgs e) + { + EventHandler handler = OutputValueChanged; + if(handler != null && _outputs.Contains((Signal)e.ValueNode)) + handler(this, new IndexedSignalEventArgs((Signal)e.ValueNode, _outputs.IndexOf((Signal)e.ValueNode))); + } + #endregion + #endregion + + #region Evaluation - Systems may be used as "Functions" + public IValueStructure[] Evaluate(params IValueStructure[] inputs) + { + if(inputs == null) + throw new ArgumentNullException("inputs"); + + if(inputs.Length != _inputs.Count) + throw new System.ArgumentException("The count of inputs doesn't match the systems count of input signals.", "inputs"); + + for(int i = 0; i < inputs.Length; i++) + _inputs[i].PostNewValue(inputs[i]); + + Service.Instance.SimulateInstant(); + + IValueStructure[] outputs = new IValueStructure[_outputs.Count]; + for(int i = 0; i < outputs.Length; i++) + outputs[i] = _outputs[i].Value; + return outputs; + } + + public double[] Evaluate(params double[] inputs) + { + if(inputs == null) + throw new ArgumentNullException("inputs"); + + if(inputs.Length != _inputs.Count) + throw new System.ArgumentException("The count of inputs doesn't match the systems count of input signals.", "inputs"); + + for(int i = 0; i < inputs.Length; i++) + _inputs[i].PostNewValue(new RealValue(inputs[i])); + + Service.Instance.SimulateInstant(); + + double[] outputs = new double[_outputs.Count]; + for(int i = 0; i < outputs.Length; i++) + outputs[i] = RealValue.ConvertFrom(_outputs[i].Value).Value; + return outputs; + } + #endregion + + #region System Builder + public void AcceptSystemBuilder(ISystemBuilder builder) + { + Dictionary signalMappings = new Dictionary(); + Dictionary busMappings = new Dictionary(); + + builder.BeginBuildSystem(_inputs.Count, _outputs.Count, _allBuses.Count); + + // Before + foreach(Signal s in _allSignals) + signalMappings.Add(s.InstanceId, ((ISignal_BuilderAdapter)s).AcceptSystemBuilderBefore(builder)); + foreach(Bus b in _allBuses) + busMappings.Add(b.InstanceId, ((IBus_BuilderAdapter)b).AcceptSystemBuilderBefore(builder)); + foreach(Port p in _allPorts) + ((IPort_BuilderAdapter)p).AcceptSystemBuilder(builder, signalMappings, busMappings); + + // After + foreach(Signal s in _allSignals) + ((ISignal_BuilderAdapter)s).AcceptSystemBuilderAfter(builder, signalMappings, busMappings); + + // System Interface + foreach(Signal si in _inputs) + builder.AppendSystemInputSignal(signalMappings[si.InstanceId]); + foreach(Signal so in _outputs) + builder.AppendSystemOutputSignal(signalMappings[so.InstanceId]); + + // Named Signals + if(_namedBuses != null) + foreach(KeyValuePair ns in _namedSignals) + builder.AppendSystemNamedSignal(signalMappings[ns.Value.InstanceId], ns.Key); + if(_namedBuses != null) + foreach(KeyValuePair nb in _namedBuses) + builder.AppendSystemNamedBus(busMappings[nb.Value.InstanceId], nb.Key); + + builder.EndBuildSystem(); + } + #endregion + + #region System Builder Templates: Cloning, Xml IO, Serialization + #region Clone + public IMathSystem Clone() + { + SystemWriter writer = new SystemWriter(); + SystemReader reader = new SystemReader(writer); + reader.ReadSystem(this); + return writer.WrittenSystems.Dequeue(); + } + #endregion + #region Write Xml + public void WriteXml(XmlWriter writer) + { + if(writer == null) + throw new ArgumentNullException("writer"); + + XmlSystemWriter xwriter = new XmlSystemWriter(writer); + SystemReader xreader = new SystemReader(xwriter); + xreader.ReadSystem(this); + writer.Flush(); + } + public string WriteXml(bool xmlFragmentOnly) + { + StringBuilder sb = new StringBuilder(); + XmlWriterSettings settings = new XmlWriterSettings(); + settings.ConformanceLevel = xmlFragmentOnly ? ConformanceLevel.Fragment : ConformanceLevel.Document; + settings.OmitXmlDeclaration = xmlFragmentOnly; + settings.Indent = true; + settings.NewLineHandling = NewLineHandling.Entitize; + settings.Encoding = Config.InternalEncoding; + XmlWriter writer = XmlWriter.Create(sb, settings); + WriteXml(writer); + writer.Close(); + return sb.ToString(); + } + public void WriteXml(FileInfo file) + { + if(file == null) + throw new ArgumentNullException("file"); + + XmlWriter writer = XmlWriter.Create(file.CreateText()); + WriteXml(writer); + writer.Close(); + } + #endregion + #region Read Xml + public static IMathSystem ReadXml(XmlReader reader) + { + SystemWriter xwriter = new SystemWriter(); + XmlSystemReader xreader = new XmlSystemReader(xwriter); + xreader.ReadSystems(reader, false); + return xwriter.WrittenSystems.Dequeue(); + } + public static IMathSystem ReadXml(string xml) + { + StringReader sr = new StringReader(xml); + XmlReader reader = XmlReader.Create(sr); + return ReadXml(reader); + } + public static IMathSystem ReadXml(FileInfo file) + { + if(file == null) + throw new ArgumentNullException("file"); + + XmlReader reader = XmlReader.Create(file.OpenText()); + IMathSystem sys = ReadXml(reader); + reader.Close(); + return sys; + } + #endregion + #region Read Xml -> Build Entity + public static IEntity ReadXmlEntity(XmlReader reader, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) + { + if(reader == null) + throw new ArgumentNullException("reader"); + + reader.ReadToFollowing("System", Config.YttriumNamespace); + int inputCnt = int.Parse(reader.GetAttribute("inputCount"), Config.InternalNumberFormat); + int outputCnt = int.Parse(reader.GetAttribute("outputCount"), Config.InternalNumberFormat); + int busCnt = int.Parse(reader.GetAttribute("busCount"), Config.InternalNumberFormat); + reader.Close(); + + string[] inputSignalLabels = new string[inputCnt]; + for(int i = 0; i < inputCnt; i++) + inputSignalLabels[i] = "In_" + i.ToString(Config.InternalNumberFormat); + + string[] outputSignalLabels = new string[outputCnt]; + for(int i = 0; i < outputCnt; i++) + outputSignalLabels[i] = "Out_" + i.ToString(Config.InternalNumberFormat); + + string[] busLabels = new string[busCnt]; + for(int i = 0; i < busCnt; i++) + busLabels[i] = "Bus_" + i.ToString(Config.InternalNumberFormat); + + return new Core.Entity(symbol, entityId.Label, entityId.Domain, notation, precedence, inputSignalLabels, outputSignalLabels, busLabels); + } + public static IEntity ReadXmlEntity(XmlReader reader, MathIdentifier entityId, string symbol) + { + return ReadXmlEntity(reader, entityId, symbol, InfixNotation.None, -1); + } + public static IEntity ReadXmlEntity(string xml, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) + { + StringReader sr = new StringReader(xml); + XmlReader reader = XmlReader.Create(sr); + return ReadXmlEntity(reader, entityId, symbol, notation, precedence); + } + public static IEntity ReadXmlEntity(string xml, MathIdentifier entityId, string symbol) + { + StringReader sr = new StringReader(xml); + XmlReader reader = XmlReader.Create(sr); + return ReadXmlEntity(reader, entityId, symbol, InfixNotation.None, -1); + } + public static IEntity ReadXmlEntity(FileInfo file, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) + { + if(file == null) + throw new ArgumentNullException("file"); + + XmlReader reader = XmlReader.Create(file.OpenText()); + IEntity entity = ReadXmlEntity(reader, entityId, symbol, notation, precedence); + reader.Close(); + return entity; + } + public static IEntity ReadXmlEntity(FileInfo file, MathIdentifier entityId, string symbol) + { + if(file == null) + throw new ArgumentNullException("file"); + + XmlReader reader = XmlReader.Create(file.OpenText()); + IEntity entity = ReadXmlEntity(reader, entityId, symbol, InfixNotation.None, -1); + reader.Close(); + return entity; + } + #endregion + #endregion + + #region Compound Integration + public IArchitectureFactory BuildArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId) + { + return new CompoundArchitectureFactory(architectureId, entityId, this); + } + public static IArchitectureFactory BuildArchitectureFactory(string xml, MathIdentifier architectureId, MathIdentifier entityId) + { + return new CompoundArchitectureFactory(architectureId, entityId, xml); + } + public static IArchitectureFactory BuildArchitectureFactory(string xml, MathIdentifier architectureId, MathIdentifier entityId, int inputCount, int outputCount, int busCount) + { + return new CompoundArchitectureFactory(architectureId, entityId, xml, inputCount, outputCount, busCount); + } + + public IEntity BuildEntity(MathIdentifier entityId, string symbol) + { + return BuildEntity(entityId, symbol, InfixNotation.None, -1); + } + public IEntity BuildEntity(MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) + { + string[] inputSignalLabels = new string[_inputs.Count]; + for(int i = 0; i < inputSignalLabels.Length; i++) + inputSignalLabels[i] = string.IsNullOrEmpty(_inputs[i].Label) ? "In_" + i.ToString(Config.InternalNumberFormat) : _inputs[i].Label; + + string[] outputSignalLabels = new string[_outputs.Count]; + for(int i = 0; i < outputSignalLabels.Length; i++) + outputSignalLabels[i] = string.IsNullOrEmpty(_outputs[i].Label) ? "Out_" + i.ToString(Config.InternalNumberFormat) : _outputs[i].Label; + + string[] busLabels = new string[_allBuses.Count]; + for(int i = 0; i < busLabels.Length; i++) + busLabels[i] = string.IsNullOrEmpty(_allBuses[i].Label) ? "Bus_" + i.ToString(Config.InternalNumberFormat) : _allBuses[i].Label; + + return new Core.Entity(symbol, entityId.Label, entityId.Domain, notation, precedence, inputSignalLabels, outputSignalLabels, busLabels); + } + + public void PublishToLibrary(MathIdentifier architectureId, MathIdentifier entityId) + { + IArchitectureFactory factory = BuildArchitectureFactory(architectureId, entityId); + Service.Instance.AddArchitecture(factory); + } + public IEntity PublishToLibrary(string label, string symbol) + { + return this.PublishToLibrary("Work", label + "Compound", label, symbol); + } + public IEntity PublishToLibrary(string domain, string architectureLabel, string entityLabel, string entitySymbol) + { + IEntity entity = BuildEntity(new MathIdentifier(entityLabel, domain), entitySymbol); + IArchitectureFactory factory = BuildArchitectureFactory(new MathIdentifier(architectureLabel, domain), entity.EntityId); + ILibrary lib = Service.Instance; + lib.AddEntity(entity); + lib.AddArchitecture(factory); + return entity; + } + public static void PublishToLibrary(string xml, ILibrary library, MathIdentifier architectureId, MathIdentifier entityId) + { + if(library == null) + throw new ArgumentNullException("library"); + + IArchitectureFactory factory = BuildArchitectureFactory(xml, architectureId, entityId); + library.AddArchitecture(factory); + } + public static IEntity PublishToLibrary(string xml, ILibrary library, string label, string symbol) + { + return PublishToLibrary(xml, library, "Work", label + "Compound", label, symbol); + } + public static IEntity PublishToLibrary(string xml, ILibrary library, string domain, string architectureLabel, string entityLabel, string entitySymbol) + { + if(library == null) + throw new ArgumentNullException("library"); + + IEntity entity = ReadXmlEntity(xml, new MathIdentifier(entityLabel, domain), entitySymbol); + IArchitectureFactory factory = BuildArchitectureFactory(xml, new MathIdentifier(architectureLabel, domain), entity.EntityId, entity.InputSignals.Length, entity.OutputSignals.Length, entity.Buses.Length); + library.AddEntity(entity); + library.AddArchitecture(factory); + return entity; + } + + public IEntity PublishToLibraryAnonymous() + { + return this.PublishToLibrary("Anonymous_" + Guid.NewGuid().ToString("N"), "anonymous"); + } + public static IEntity PublishToLibraryAnonymous(string xml, ILibrary library) + { + return PublishToLibrary(xml, library, "Anonymous_" + Guid.NewGuid().ToString("N"), "anonymous"); + } + #endregion + + #region Maintenance + /// True if some objects where removed. + public bool RemoveUnusedObjects() + { + IList signals; + IList ports; + Service.Instance.FindAll(_outputs, false, out signals, out ports); + bool ret = false; + for(int i = _allPorts.Count - 1; i >= 0; i--) + { + Port p = _allPorts[i]; + if(!ports.Contains(p)) + { + p.RemoveAllBindings(); + InternalRemovePort(p); //_allPorts.RemoveAt(i); + ret = true; + } + } + for(int i = _allSignals.Count - 1; i >= 0; i--) + { + Signal s = _allSignals[i]; + if(!signals.Contains(s)) // && !s.IsDriven && !_inputs.Contains(s)) + { + InternalRemoveSignal(s); //_allSignals.RemoveAt(i); + ret = true; + } + } + return ret; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Workplace/Project.cs b/Backup/src/app/MathNet.Yttrium/Library/Workplace/Project.cs new file mode 100644 index 0000000..f791826 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Workplace/Project.cs @@ -0,0 +1,269 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Reflection; + +using MathNet.Symbolics.Core; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Interpreter; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Mediator; +using MathNet.Symbolics.Events; +using MathNet.Symbolics.Simulation; + +namespace MathNet.Symbolics.Workplace +{ + public class Project : IObserver + { + private bool _keepTrack; // = false; + private MathSystem _currentSystem; + private Dictionary _namedSystems; + private List _localObservers; + private IParser _parser; + private IMediator _mediator; + + public event EventHandler SystemLoaded; + + public Project() + { + Service.Instance.LoadDefaultPackages(); + + _namedSystems = new Dictionary(); + _localObservers = new List(); + _parser = Service.Instance; + _mediator = Service.Instance; + MathSystem sys = AddSystem(); + LoadSystem(sys.InstanceId); + } + + #region Properties + public IParser Parser + { + get { return _parser; } + } + + public bool KeepTrack + { + get { return _keepTrack; } + set + { + if(value && !_keepTrack) + { + _mediator.AttachObserver(this); + _keepTrack = true; + } + else if(!value && _keepTrack) + { + _keepTrack = false; + _mediator.DetachObserver(this); + } + } + } + + public MathSystem CurrentSystem + { + get { return _currentSystem; } + //set { currentSystem = value; } + } + #endregion + + #region System Management + public void ImportSystem(MathSystem system) + { + if(!system.HasSystemMediator) + system.SystemMediator = Binder.GetInstance(); + _namedSystems.Add(system.InstanceId, system); + } + public MathSystem AddSystem() + { + MathSystem system = new MathSystem(); + Binder.GetInstance(system); + //system.SystemMediator = Binder.GetInstance(); + _namedSystems.Add(system.InstanceId, system); + return system; + } + public void LoadSystem(int index) + { + + } + public void LoadSystem(Guid iid) + { + UnloadSystem(); + LoadSystem(_namedSystems[iid]); + } + private void LoadSystem(MathSystem system) + { + _currentSystem = system; + + if(!system.HasSystemMediator) + system.SystemMediator = Binder.GetInstance(); + + foreach(ISystemObserver observer in _localObservers) + system.SystemMediator.AttachObserver(observer); + + if(SystemLoaded != null) + SystemLoaded(this, EventArgs.Empty); + } + private void UnloadSystem() + { + if(_currentSystem == null) + return; + + foreach(ISystemObserver observer in _localObservers) + _currentSystem.SystemMediator.DetachObserver(observer); + + _currentSystem = null; + } + public Dictionary Systems + { + get { return _namedSystems; } + } + #endregion + + #region Local Observers + public void AttachLocalObserver(ISystemObserver observer) + { + _localObservers.Add(observer); + if(_currentSystem != null) + _currentSystem.SystemMediator.AttachObserver(observer); + } + public void DetachLocalObserver(ISystemObserver observer) + { + _localObservers.Remove(observer); + if(_currentSystem != null) + _currentSystem.SystemMediator.DetachObserver(observer); + } + #endregion + + //public void PostCommand(MathNet.Symbolics.Backend.Channels.ICommand command) + //{ + // // TODO: UNCOMMENT + // //_currentSystem.SystemMediator.PostCommand(command); + //} + + //public void LoadPackage(Assembly assembly) + //{ + // _context.Library.LoadAssembly(assembly); + //} + //public void LoadPackage(IPackageManager manager) + //{ + // ((Library)_context.Library).LoadPackageManager(manager); + //} + + #region Interpreter + public void Interpret(string expressions) + { + _parser.Interpret(expressions, _currentSystem); + } + public void Interpret(System.IO.TextReader reader) + { + _parser.Interpret(reader, _currentSystem); + } + public void Interpret(System.IO.FileInfo file) + { + _parser.Interpret(file, _currentSystem); + } + #endregion + + #region Simulator + /// True if there were any events available. + public bool SimulateInstant() + { + return Service.Instance.SimulateInstant(); + } + /// The time (in simulation time space) to simulate. + /// + /// Actually simulated time. + /// If this time is smaller than , there were no more events available. + /// + public TimeSpan SimulateFor(TimeSpan timespan) + { + return Service.Instance.SimulateFor(timespan); + } + /// The number of cycles to simulate. + /// Simulated time. + public TimeSpan SimulateFor(int cycles) + { + return Service.Instance.SimulateFor(cycles); + } + #endregion + + #region IObserver Members + + void IObserver.OnNewSignalCreated(Signal signal) + { + _currentSystem.AddSignal(signal); + } + + void IObserver.OnNewPortCreated(Port port) + { + _currentSystem.AddPort(port); + } + + void IObserver.OnNewBusCreated(Bus bus) + { + _currentSystem.AddBus(bus); + } + + void IObserver.OnPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + _currentSystem.AddSignalTree(signal, false, true); + _currentSystem.UnpromoteAsInput(signal); + } + + void IObserver.OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + _currentSystem.PromoteAsInput(signal); + } + + void IObserver.OnSignalDrivesPort(Signal signal, Port port, int inputIndex) + { + _currentSystem.AddSignal(signal); + _currentSystem.AddPortTree(port, false, true); + } + + void IObserver.OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + } + + void IObserver.OnBusAttachedToPort(Bus bus, Port port, int busIndex) + { + _currentSystem.AddBus(bus); + _currentSystem.AddPortTree(port, false, true); + } + + void IObserver.OnBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + } + + void IObserver.OnSignalValueChanged(Signal signal) + { + } + + void IObserver.OnBusValueChanged(Bus bus) + { + } + + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Library/Yttrium.csproj b/Backup/src/app/MathNet.Yttrium/Library/Yttrium.csproj new file mode 100644 index 0000000..7a24275 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Library/Yttrium.csproj @@ -0,0 +1,140 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {CAB86B17-68FA-4081-B687-DB71B74BAF79} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + Designer + ResXFileCodeGenerator + Resources.Designer.cs + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6} + Yttrium.Interpreter.Contracts + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C} + Yttrium.Manipulation.Contracts + + + {E623ED40-9B92-40CA-9080-0FC78F668FFE} + Yttrium.Mediator.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Yttrium.Packages.Helper + + + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} + Yttrium.Packages.Standard + + + {6AAA89AE-90D5-496B-9EBD-5274C662C147} + Yttrium.Patterns.Toolkit + + + {CFE74A4D-51A2-432C-966A-E29773C55D45} + Yttrium.Simulation.Contracts + + + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3} + Yttrium.SystemBuilder.Toolkit + + + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Yttrium.Traversing.Contracts + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluationTheorem.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluationTheorem.cs new file mode 100644 index 0000000..578f6c6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluationTheorem.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.AutoEvaluation +{ + public interface IAutoEvaluationTheorem + where TAspect : Identifier + { + MathIdentifier TheoremId { get;} + Pattern CreatePattern(); + TAspect Aspect { get; } + + void AutoEvaluate(Signal signal, GroupCollection groups); + void AutoEvaluate(Port port, GroupCollection groups); + void AutoEvaluate(Bus bus, GroupCollection groups); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluationTheoremProvider.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluationTheoremProvider.cs new file mode 100644 index 0000000..2980139 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluationTheoremProvider.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace MathNet.Symbolics.AutoEvaluation +{ + public interface IAutoEvaluationTheoremProvider : ITheoremProvider + where TAspect : Identifier + { + IAutoEvaluationTheorem this[MathIdentifier theoremId] { get;} + + IAutoEvaluationTheorem LookupBest(Signal signal, out GroupCollection groups); + IAutoEvaluationTheorem LookupBest(Port port, out GroupCollection groups); + IAutoEvaluationTheorem LookupBest(Bus bus, out GroupCollection groups); + bool TryLookupBest(Signal signal, out IAutoEvaluationTheorem theorem, out GroupCollection groups); + bool TryLookupBest(Port port, out IAutoEvaluationTheorem theorem, out GroupCollection groups); + bool TryLookupBest(Bus bus, out IAutoEvaluationTheorem theorem, out GroupCollection groups); + + void Add(IAutoEvaluationTheorem theorem); + bool Remove(IAutoEvaluationTheorem theorem); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluator.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluator.cs new file mode 100644 index 0000000..af6f747 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/AutoEvaluation/IAutoEvaluator.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.AutoEvaluation +{ + public interface IAutoEvaluator + { + void AutoEvaluateFlag(Signal signal, NodeFlag flag); + void AutoEvaluateFlag(Port port, NodeFlag flag); + void AutoEvaluateFlag(Bus bus, NodeFlag flag); + + void AutoEvaluateProperty(Signal signal, NodeProperty property); + void AutoEvaluateProperty(Port port, NodeProperty property); + void AutoEvaluateProperty(Bus bus, NodeProperty property); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/BasicManipulationVisitor.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/BasicManipulationVisitor.cs new file mode 100644 index 0000000..6daf018 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/BasicManipulationVisitor.cs @@ -0,0 +1,58 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + [System.Diagnostics.DebuggerStepThrough] + public class BasicManipulationVisitor : IManipulationVisitor + { + private EstimatePlan _plan; + private ManipulatePort _port; + private ManipulateSignal _signal; + + public BasicManipulationVisitor(EstimatePlan plan, ManipulatePort port, ManipulateSignal signal) + { + _plan = plan; + _port = port; + _signal = signal; + } + + public ManipulationPlan EstimatePlan(Port port) + { + return _plan(port); + } + + public IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + return _port(port, manipulatedInputs, hasManipulatedInputs); + } + + public Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced) + { + return _signal(original, replacement, isReplaced); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/BasicTransformation.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/BasicTransformation.cs new file mode 100644 index 0000000..00e2435 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/BasicTransformation.cs @@ -0,0 +1,78 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace MathNet.Symbolics.Manipulation +{ + public class BasicTransformation : ITransformationTheorem + { + private readonly MathIdentifier _id; + private readonly MathIdentifier _transformationTypeId; + private ManipulatePort _transform; + private EstimatePlan _plan; + private CreatePattern _pattern; + + public BasicTransformation(MathIdentifier id, MathIdentifier transformationTypeId, CreatePattern pattern, EstimatePlan plan, ManipulatePort transform) + { + _id = id; + _transformationTypeId = transformationTypeId; + _pattern = pattern; + _transform = transform; + _plan = plan; + } + + public MathIdentifier TransformationTypeId + { + get { return _transformationTypeId; } + } + public MathIdentifier TheoremId + { + get { return _id; } + } + + public Pattern CreatePattern() + { + return _pattern(); + } + + public ManipulationPlan EstimatePlan(Port port, GroupCollection groups) + { + return _plan(port); + } + + public IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs, GroupCollection groups) + { + return _transform(port, manipulatedInputs, hasManipulatedInputs); + } + + public Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced) + { + return replacement; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/Delegates.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/Delegates.cs new file mode 100644 index 0000000..eee0a24 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/Delegates.cs @@ -0,0 +1,35 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + public delegate ManipulationPlan EstimatePlan(Port port); + public delegate IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs); + public delegate Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced); + + public delegate void ConfigureTransformation(ITransformationTheorem theorem); +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/IManipulationVisitor.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/IManipulationVisitor.cs new file mode 100644 index 0000000..316ff5c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/IManipulationVisitor.cs @@ -0,0 +1,35 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + public interface IManipulationVisitor + { + ManipulationPlan EstimatePlan(Port port); + IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs); + Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/IManipulator.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/IManipulator.cs new file mode 100644 index 0000000..a28bab6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/IManipulator.cs @@ -0,0 +1,37 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + public interface IManipulator + { + Signal Manipulate(Signal rootSignal, IManipulationVisitor visitor, bool ignoreHold); + SignalSet Manipulate(IEnumerable rootSignals, IManipulationVisitor visitor, bool ignoreHold); + + Signal Substitute(Signal rootSignal, Signal subject, Signal replacement); + SignalSet Substitute(IEnumerable rootSignals, Signal subject, Signal replacement); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformationTheorem.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformationTheorem.cs new file mode 100644 index 0000000..96c5f88 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformationTheorem.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + public delegate Pattern CreatePattern(); + + public interface ITransformationTheorem + { + MathIdentifier TheoremId { get;} + Pattern CreatePattern(); + MathIdentifier TransformationTypeId { get; } + ManipulationPlan EstimatePlan(Port port, GroupCollection groups); + IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs, GroupCollection groups); + Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformationTheoremProvider.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformationTheoremProvider.cs new file mode 100644 index 0000000..aacbc92 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformationTheoremProvider.cs @@ -0,0 +1,44 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace MathNet.Symbolics.Manipulation +{ + public interface ITransformationTheoremProvider : ITheoremProvider + { + ITransformationTheorem Default { get; set;} + ITransformationTheorem this[MathIdentifier theoremId] { get;} + + ITransformationTheorem LookupFirst(Signal output, Port port, out GroupCollection groups); + ITransformationTheorem LookupBest(Signal output, Port port, out GroupCollection groups); + bool TryLookupFirst(Signal output, Port port, out ITransformationTheorem theorem, out GroupCollection groups); + bool TryLookupBest(Signal output, Port port, out ITransformationTheorem theorem, out GroupCollection groups); + + void Add(ITransformationTheorem theorem); + bool Remove(ITransformationTheorem theorem); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformer.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformer.cs new file mode 100644 index 0000000..a8c2aae --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ITransformer.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + public interface ITransformer + { + Signal Transform(Signal signal, MathIdentifier transformationTypeId, bool ignoreHold); + Signal Transform(Signal signal, MathIdentifier transformationTypeId, ConfigureTransformation configure, bool ignoreHold); + SignalSet Transform(IEnumerable signals, MathIdentifier transformationTypeId, bool ignoreHold); + SignalSet Transform(IEnumerable signals, MathIdentifier transformationTypeId, ConfigureTransformation configure, bool ignoreHold); + } +} + diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ManipulationPlan.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ManipulationPlan.cs new file mode 100644 index 0000000..6aa764f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Manipulation/ManipulationPlan.cs @@ -0,0 +1,41 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Manipulation +{ + public enum ManipulationPlan + { + /// Node not analyzed yet. + Unknown, + /// Alter the node if any childs have been altered. + AlterIfChildsAltered, + /// Automatically clone the node if any childs have been altered, using those new childs. + CloneIfChildsAltered, + /// Alter the node, no matter whether any childs have been manipulated. + DoAlter, + /// Don't alter the node, no matter whether any childs have been manipulated. Don't dive any deeper. + DontAlter + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..30040ff --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Manipulation Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("b9a354c6-b0f7-431d-865c-9b404eb29419")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Yttrium.Manipulation.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Yttrium.Manipulation.Contracts.csproj new file mode 100644 index 0000000..f5b0d1b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Contracts/Yttrium.Manipulation.Contracts.csproj @@ -0,0 +1,84 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Manipulation.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {6AAA89AE-90D5-496B-9EBD-5274C662C147} + Yttrium.Patterns.Toolkit + + + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Yttrium.Traversing.Contracts + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluation/AutoEvaluationTheoremProvider.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluation/AutoEvaluationTheoremProvider.cs new file mode 100644 index 0000000..8c394b7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluation/AutoEvaluationTheoremProvider.cs @@ -0,0 +1,161 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace MathNet.Symbolics.AutoEvaluation +{ + public class AutoEvaluationTheoremProvider : KeyedCollection>, IAutoEvaluationTheoremProvider + where TAspect : Identifier + { + private MathIdentifier _aspectId; + + private CoalescedTreeNode _root; + private List _tree; + + public AutoEvaluationTheoremProvider(MathIdentifier aspectId) + { + _aspectId = aspectId; + _tree = CoalescedTreeNode.CreateRootTree(out _root); + } + + public MathIdentifier TheoremTypeId + { + get { return _aspectId; } + } + + public CoalescedTreeNode Root + { + get { return _root; } + } + + protected override MathIdentifier GetKeyForItem(IAutoEvaluationTheorem item) + { + return item.TheoremId; + } + + protected override void InsertItem(int index, IAutoEvaluationTheorem item) + { + base.InsertItem(index, item); + + Pattern pattern = item.CreatePattern(); + pattern.MergeToCoalescedTree(item.TheoremId, _tree); + } + + public bool TryGetValue(MathIdentifier id, out IAutoEvaluationTheorem theorem) + { + theorem = null; + if(!Contains(id)) + return false; + theorem = base[id]; + return true; + } + + #region Pattern Matching + public MatchCollection MatchAll(Signal output, Port port) + { + return _root.MatchAll(output, port, 1); + } + public Match MatchFirst(Signal output, Port port) + { + Match res = _root.MatchFirst(output, port); + if(res == null) + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + return res; + } + public bool TryMatchFirst(Signal output, Port port, out Match match) + { + match = _root.MatchFirst(output, port); + return match != null; + } + public Match MatchBest(Signal output, Port port) + { + Match bestMatch = _root.MatchBest(output, port); + if(bestMatch == null) + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + return bestMatch; + } + public bool TryMatchBest(Signal output, Port port, out Match match) + { + match = _root.MatchBest(output, port); + return match != null; + } + #endregion + + #region Theorem Matching + public IAutoEvaluationTheorem LookupBest(Signal signal, out GroupCollection groups) + { + Match match = MatchBest(signal, signal.DrivenByPort); + groups = match.Groups; + return this[match.PatternId]; + } + public IAutoEvaluationTheorem LookupBest(Port port, out GroupCollection groups) + { + Match match = MatchBest(null, port); + groups = match.Groups; + return this[match.PatternId]; + } + public IAutoEvaluationTheorem LookupBest(Bus bus, out GroupCollection groups) + { + throw new NotImplementedException(); + } + public bool TryLookupBest(Signal signal, out IAutoEvaluationTheorem theorem, out GroupCollection groups) + { + Match match; + if(TryMatchBest(signal, signal.DrivenByPort, out match)) + { + groups = match.Groups; + if(this.TryGetValue(match.PatternId, out theorem)) + return true; + } + groups = null; + theorem = null; + return false; + } + public bool TryLookupBest(Port port, out IAutoEvaluationTheorem theorem, out GroupCollection groups) + { + Match match; + if(TryMatchBest(null, port, out match)) + { + groups = match.Groups; + if(this.TryGetValue(match.PatternId, out theorem)) + return true; + } + groups = null; + theorem = null; + return false; + } + public bool TryLookupBest(Bus bus, out IAutoEvaluationTheorem theorem, out GroupCollection groups) + { + throw new NotImplementedException(); + //groups = null; + //theorem = null; + //return false; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluation/AutoEvaluator.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluation/AutoEvaluator.cs new file mode 100644 index 0000000..c4bbb13 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluation/AutoEvaluator.cs @@ -0,0 +1,139 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace MathNet.Symbolics.AutoEvaluation +{ + public class AutoEvaluator : IAutoEvaluator + { + ILibrary _library; + + public AutoEvaluator() + { + _library = Service.Instance; + } + + private IAutoEvaluationTheoremProvider GetTheoremProvider(NodeFlag flag) + { + ITheoremProvider provider; + if(!_library.TryLookupTheoremType(flag.Friendly.DerivePostfix("FlagTheorem"), out provider)) + return null; + return provider as IAutoEvaluationTheoremProvider; + } + private IAutoEvaluationTheoremProvider GetTheoremProvider(NodeProperty property) + { + ITheoremProvider provider; + if(!_library.TryLookupTheoremType(property.Friendly.DerivePostfix("PropertyTheorem"), out provider)) + return null; + return provider as IAutoEvaluationTheoremProvider; + } + + public void AutoEvaluateFlag(Signal signal, NodeFlag flag) + { + IAutoEvaluationTheoremProvider provider = GetTheoremProvider(flag); + if(provider == null) + return; + + IAutoEvaluationTheorem theorem; + GroupCollection groups; + if(!provider.TryLookupBest(signal, out theorem, out groups)) + return; + + theorem.AutoEvaluate(signal, groups); + } + + public void AutoEvaluateFlag(Port port, NodeFlag flag) + { + IAutoEvaluationTheoremProvider provider = GetTheoremProvider(flag); + if(provider == null) + return; + + IAutoEvaluationTheorem theorem; + GroupCollection groups; + if(!provider.TryLookupBest(port, out theorem, out groups)) + return; + + theorem.AutoEvaluate(port, groups); + } + + public void AutoEvaluateFlag(Bus bus, NodeFlag flag) + { + IAutoEvaluationTheoremProvider provider = GetTheoremProvider(flag); + if(provider == null) + return; + + IAutoEvaluationTheorem theorem; + GroupCollection groups; + if(!provider.TryLookupBest(bus, out theorem, out groups)) + return; + + theorem.AutoEvaluate(bus, groups); + } + + public void AutoEvaluateProperty(Signal signal, NodeProperty property) + { + IAutoEvaluationTheoremProvider provider = GetTheoremProvider(property); + if(provider == null) + return; + + IAutoEvaluationTheorem theorem; + GroupCollection groups; + if(!provider.TryLookupBest(signal, out theorem, out groups)) + return; + + theorem.AutoEvaluate(signal, groups); + } + + public void AutoEvaluateProperty(Port port, NodeProperty property) + { + IAutoEvaluationTheoremProvider provider = GetTheoremProvider(property); + if(provider == null) + return; + + IAutoEvaluationTheorem theorem; + GroupCollection groups; + if(!provider.TryLookupBest(port, out theorem, out groups)) + return; + + theorem.AutoEvaluate(port, groups); + } + + public void AutoEvaluateProperty(Bus bus, NodeProperty property) + { + IAutoEvaluationTheoremProvider provider = GetTheoremProvider(property); + if(provider == null) + return; + + IAutoEvaluationTheorem theorem; + GroupCollection groups; + if(!provider.TryLookupBest(bus, out theorem, out groups)) + return; + + theorem.AutoEvaluate(bus, groups); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluationFactory.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluationFactory.cs new file mode 100644 index 0000000..e63cbc5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/AutoEvaluationFactory.cs @@ -0,0 +1,58 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.AutoEvaluation; + +namespace MathNet.Symbolics +{ + internal class AutoEvaluationFactory : + IFactory, + IFactory, MathIdentifier>, + IFactory, MathIdentifier> + { + IAutoEvaluator IFactory.GetInstance() + { + return new AutoEvaluator(); + } + + IAutoEvaluationTheoremProvider IFactory>.GetInstance() + { + throw new NotSupportedException("expected parameters: MathIdentifier"); + } + IAutoEvaluationTheoremProvider IFactory, MathIdentifier>.GetInstance(MathIdentifier p1) + { + return new AutoEvaluationTheoremProvider(p1); + } + + IAutoEvaluationTheoremProvider IFactory>.GetInstance() + { + throw new NotSupportedException("expected parameters: MathIdentifier"); + } + IAutoEvaluationTheoremProvider IFactory, MathIdentifier>.GetInstance(MathIdentifier p1) + { + return new AutoEvaluationTheoremProvider(p1); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/Manipulator.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/Manipulator.cs new file mode 100644 index 0000000..31fe9ce --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/Manipulator.cs @@ -0,0 +1,378 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Traversing; + +namespace MathNet.Symbolics.Manipulation +{ + public class Manipulator : IManipulator + { + IScanner _scanner; + + public Manipulator() + { + _scanner = Service.Instance; + } + + private class ManipulatorPlanReducer : AbstractScanVisitor + { + Dictionary _plans; + bool _ignoreHold; + + public ManipulatorPlanReducer(Dictionary plans, bool ignoreHold) + { + _plans = plans; + _ignoreHold = ignoreHold; + } + + public override IScanStrategy DefaultStrategy + { + get { throw new NotImplementedException("The method or operation is not implemented."); } + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + // ## DIVE DEEPER ONLY ON UNCERTAIN PORTS + if(_plans[port.InstanceId] != ManipulationPlan.AlterIfChildsAltered + && _plans[port.InstanceId] != ManipulationPlan.CloneIfChildsAltered) + return false; + return base.EnterPort(port, parent, again, root); + } + + public override bool VisitCycle(Port port, Signal target, Signal source) + { + // ## ON CYCLES, TEST WHETHER THE PORT DEPENDS ON ANY ALTERED PORTS AND ADOPT + if(Service.Instance.ExistsPort(port, delegate(Port p) { return _plans[p.InstanceId] == ManipulationPlan.DoAlter; }, _ignoreHold)) + _plans[port.InstanceId] = ManipulationPlan.DoAlter; + else + _plans[port.InstanceId] = ManipulationPlan.DontAlter; + return base.VisitCycle(port, target, source); + } + + public override bool VisitLeaf(Port port, bool again) + { + // ## REMOVE PLANS ON UNCERTAIN PORTS WITHOUT CHILDS + if(_plans[port.InstanceId] == ManipulationPlan.AlterIfChildsAltered + || _plans[port.InstanceId] == ManipulationPlan.CloneIfChildsAltered) + _plans[port.InstanceId] = ManipulationPlan.DontAlter; + return base.VisitLeaf(port, again); + } + + public override bool LeavePort(Port port, Signal parent, bool again, bool root) + { + // ## PROPAGATE "DONT ALTER" AND "DO ALTER" + bool allDont = true; + bool oneDoes = false; + foreach(Signal s in port.InputSignals) + if(s.BehavesAsBeingDriven(_ignoreHold)) + { + allDont = allDont && (_plans[s.DrivenByPort.InstanceId] == ManipulationPlan.DontAlter); + oneDoes = oneDoes || (_plans[s.DrivenByPort.InstanceId] == ManipulationPlan.DoAlter); + } + if(oneDoes) + _plans[port.InstanceId] = ManipulationPlan.DoAlter; + else if(allDont) + _plans[port.InstanceId] = ManipulationPlan.DontAlter; + return base.LeavePort(port, parent, again, root); + } + } + + private class ManipulatorPlanExecutor : AbstractScanVisitor + { + IManipulationVisitor _visitor; + Dictionary _plans; + Dictionary _signalRep; + Dictionary _sentinels; + + public ManipulatorPlanExecutor(Dictionary plans, Dictionary signalReplacements, Dictionary sentinels, IManipulationVisitor visitor) + { + _visitor = visitor; + _plans = plans; + _signalRep = signalReplacements; + _sentinels = sentinels; + } + + public override IScanStrategy DefaultStrategy + { + get { throw new NotImplementedException("The method or operation is not implemented."); } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + // ## DONT DIVE DEEPER ON ALREADY REPLACED SIGNALS + if(_signalRep.ContainsKey(signal.InstanceId)) + return false; + return base.EnterSignal(signal, parent, again, root); + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + // ## DONT DIVE DEEPER ON "DONT ALTER" PORTS + if(_plans[port.InstanceId] == ManipulationPlan.DontAlter) + return false; + return base.EnterPort(port, parent, again, root); + } + + public override bool VisitCycle(Port port, Signal target, Signal source) + { + // ## INSERT DUMMY SENTINEL SIGNALS TO BREAK UP CYCLES + if(!_signalRep.ContainsKey(source.InstanceId)) // not replaced/sentinel yet + { + Signal sentinel = Binder.CreateSignal(source.Value); + sentinel.Label = "Sentinel_" + sentinel.InstanceId.ToString(); + _sentinels.Add(sentinel.InstanceId, source); + _signalRep.Add(source.InstanceId, sentinel); + } + return base.VisitCycle(port, target, source); + } + + public override bool LeavePort(Port port, Signal parent, bool again, bool root) + { + if(_plans[port.InstanceId] == ManipulationPlan.DontAlter) + return true; + + // ## MANIPULATE PORT + bool isManipulated; + SignalSet preManip = BuildManipulatedInputsList(port, out isManipulated); + IEnumerable postManip; + if(_plans[port.InstanceId] == ManipulationPlan.CloneIfChildsAltered) + { + Port newPort = port.CloneWithNewInputs(preManip); + postManip = newPort.OutputSignals; + } + else + postManip = _visitor.ManipulatePort(port, preManip, isManipulated); + + // ## WRITE BACK OUTPUT SIGNAL REPLACEMENTS + ReadOnlySignalSet outputs = port.OutputSignals; + int i = 0; + foreach(Signal rep in postManip) + _signalRep[outputs[i++].InstanceId] = rep; + + return base.LeavePort(port, parent, again, root); + } + + public override bool LeaveSignal(Signal signal, Port parent, bool again, bool root) + { + // ## POST-MANIPULATE (REPLACED) SIGNALS + Signal rep; + if(_signalRep.TryGetValue(signal.InstanceId, out rep)) + _signalRep[signal.InstanceId] = _visitor.ManipulateSignal(signal, rep, !signal.Equals(rep)); + else + _signalRep[signal.InstanceId] = _visitor.ManipulateSignal(signal, signal, false); + + return base.LeaveSignal(signal, parent, again, root); + } + + private SignalSet BuildManipulatedInputsList(Port port, out bool isManipulated) + { + ReadOnlySignalSet inputs = port.InputSignals; + SignalSet manip = new SignalSet(); + isManipulated = false; + foreach(Signal s in inputs) + { + Signal rep; + if(_signalRep.TryGetValue(s.InstanceId, out rep)) + { + if(!s.Equals(rep)) + isManipulated = true; + manip.Add(rep); + } + else + manip.Add(s); + } + return manip; + } + } + + public Signal Manipulate(Signal rootSignal, IManipulationVisitor visitor, bool ignoreHold) + { + IScanStrategy allPathsStrat = Binder.GetSpecificInstance(new MathIdentifier("AllPathsStrategy", "Traversing")); + + Dictionary plans = new Dictionary(); + Dictionary signalReplacements = new Dictionary(); + Dictionary sentinels = new Dictionary(); + + // ## ESTIMATE MANIPULATION PLAN + _scanner.ForEachPort(rootSignal, delegate(Port p) + { + if(!plans.ContainsKey(p.InstanceId)) + plans.Add(p.InstanceId, visitor.EstimatePlan(p)); + return true; + }, ignoreHold); + + // ## OPTIMIZE MANIPULATION PLAN (cycle analysis) + ManipulatorPlanReducer reducer = new ManipulatorPlanReducer(plans, ignoreHold); + allPathsStrat.Traverse(rootSignal, reducer, ignoreHold); + + // ## EXECUTE MANIPULATION + ManipulatorPlanExecutor executor = new ManipulatorPlanExecutor(plans, signalReplacements, sentinels, visitor); + allPathsStrat.Traverse(rootSignal, executor, ignoreHold); + + // ## SELECT NEW SYSTEM + Signal ret; + if(!signalReplacements.TryGetValue(rootSignal.InstanceId, out ret)) + ret = rootSignal; + + // ## FIX SENTINELS ON SELECTED NEW SYSTEM + _scanner.ForEachPort(ret, delegate(Port p) + { + // look for sentinels on all input signals + ReadOnlySignalSet inputs = p.InputSignals; + for(int i = 0; i < inputs.Count; i++) + { + Signal input = inputs[i]; + if(FixSentinel(ref input, sentinels, signalReplacements)) + p.ReplaceInputSignalBinding(i, input); + } + return true; + }, ignoreHold); + FixSentinel(ref ret, sentinels, signalReplacements); + + // ## RETURN SELECTED NEW SYSTEM AS RESULT + return ret; + } + + public SignalSet Manipulate(IEnumerable rootSignals, IManipulationVisitor visitor, bool ignoreHold) + { + IScanStrategy allPathsStrat = Binder.GetSpecificInstance(new MathIdentifier("AllPathsStrategy", "Traversing")); + + Dictionary plans = new Dictionary(); + Dictionary signalReplacements = new Dictionary(); + Dictionary sentinels = new Dictionary(); + + // ## ESTIMATE MANIPULATION PLAN + _scanner.ForEachPort(rootSignals, delegate(Port p) + { + if(!plans.ContainsKey(p.InstanceId)) + plans.Add(p.InstanceId, visitor.EstimatePlan(p)); + return true; + }, ignoreHold); + + // ## OPTIMIZE MANIPULATION PLAN (cycle analysis) + ManipulatorPlanReducer reducer = new ManipulatorPlanReducer(plans, ignoreHold); + allPathsStrat.Traverse(rootSignals, reducer, ignoreHold); + + // ## EXECUTE MANIPULATION + ManipulatorPlanExecutor executor = new ManipulatorPlanExecutor(plans, signalReplacements, sentinels, visitor); + allPathsStrat.Traverse(rootSignals, executor, ignoreHold); + + // ## SELECT NEW SYSTEM + SignalSet ret = new SignalSet(); + foreach(Signal root in rootSignals) + { + Signal r; + if(!signalReplacements.TryGetValue(root.InstanceId, out r)) + r = root; + ret.Add(r); + } + + // ## FIX SENTINELS ON SELECTED NEW SYSTEM + _scanner.ForEachPort(ret, delegate(Port p) + { + // look for sentinels on all input signals + ReadOnlySignalSet inputs = p.InputSignals; + for(int i = 0; i < inputs.Count; i++) + { + Signal input = inputs[i]; + if(FixSentinel(ref input, sentinels, signalReplacements)) + p.ReplaceInputSignalBinding(i, input); + } + return true; + }, ignoreHold); + + for(int i = 0; i < ret.Count; i++) + { + Signal r = ret[i]; + if(FixSentinel(ref r, sentinels, signalReplacements)) + ret[i] = r; + } + + // ## RETURN SELECTED NEW SYSTEM AS RESULT + return ret; + } + + private bool FixSentinel(ref Signal signal, Dictionary sentinels, Dictionary signalReplacements) + { + bool ret = false; + while(sentinels.ContainsKey(signal.InstanceId)) // is a sentinel + { + ret = true; + Signal original = sentinels[signal.InstanceId]; + Signal final; + if(signalReplacements.TryGetValue(original.InstanceId, out final) && !signal.Equals(final)) + signal = final; // sentinel was replaced -> replace with replacement + else + signal = original; // sentinel was not replaced -> replace with original + } + return ret; // is not a sentinel + } + + + #region Substitute Template + public Signal Substitute(Signal rootSignal, Signal subject, Signal replacement) + { + IManipulationVisitor visitor = CreateSubstituteVisitor(subject, replacement); + return Manipulate(rootSignal, visitor, false); + } + public SignalSet Substitute(IEnumerable rootSignals, Signal subject, Signal replacement) + { + IManipulationVisitor visitor = CreateSubstituteVisitor(subject, replacement); + return Manipulate(rootSignals, visitor, false); + } + private IManipulationVisitor CreateSubstituteVisitor(Signal subject, Signal replacement) + { + return new BasicManipulationVisitor( + delegate(Port p) + { // ## ESTIMATE PLAN + if(p.InputSignals.Contains(subject)) + return ManipulationPlan.DoAlter; + else + return ManipulationPlan.CloneIfChildsAltered; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { // ## MANIPULATE PORT + + /* NOTE: manipulatedInputs could contain sentinels, that's why + * we use the original port inputs instead. */ + + ISignalSet inputs = port.InputSignals; + for(int i = 0; i < inputs.Count; i++) + if(subject.Equals(inputs[i])) + manipulatedInputs[i] = replacement; + return port.CloneWithNewInputs(manipulatedInputs).OutputSignals; + }, + delegate(Signal original, Signal replaced, bool isReplaced) + { // ## POST-MANIPULATE SIGNAL + if(subject.Equals(replaced)) + return replacement; + else + return replaced; + }); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/TransformationManipulationVisitor.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/TransformationManipulationVisitor.cs new file mode 100644 index 0000000..ab26d3e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/TransformationManipulationVisitor.cs @@ -0,0 +1,90 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Traversing; + +namespace MathNet.Symbolics.Manipulation +{ + /// + /// Apply a transformation theorem using the manipulation subsystem. + /// + public class TransformationManipulationVisitor : IManipulationVisitor + { + ITransformationTheoremProvider _transformations; + ConfigureTransformation _configure; + + public TransformationManipulationVisitor(ITransformationTheoremProvider transformations) + { + _transformations = transformations; + } + public TransformationManipulationVisitor(ITransformationTheoremProvider transformations, ConfigureTransformation configure) + { + _transformations = transformations; + _configure = configure; + } + + public ManipulationPlan EstimatePlan(Port port) + { + ITransformationTheorem trans; + GroupCollection groups; + if(_transformations.TryLookupBest(null, port, out trans, out groups)) + { + if(_configure != null) + _configure(trans); + return trans.EstimatePlan(port, groups); + } + else + return ManipulationPlan.CloneIfChildsAltered; + } + + public IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + ITransformationTheorem trans; + GroupCollection groups; + if(_transformations.TryLookupBest(null, port, out trans, out groups)) + { + if(_configure != null) + _configure(trans); + return trans.ManipulatePort(port, manipulatedInputs, hasManipulatedInputs, groups); + } + else + throw new MathNet.Symbolics.Exceptions.TheoremMismatchException(); + } + + public Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced) + { + ITransformationTheorem trans = _transformations.Default; + if(trans != null) + { + if(_configure != null) + _configure(trans); + return trans.ManipulateSignal(original, replacement, isReplaced); + } + return replacement; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/TransformationTheoremProvider.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/TransformationTheoremProvider.cs new file mode 100644 index 0000000..5b3caa5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/TransformationTheoremProvider.cs @@ -0,0 +1,159 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace MathNet.Symbolics.Manipulation +{ + public class TransformationTheoremProvider : KeyedCollection, ITransformationTheoremProvider + { + private MathIdentifier _transformationTypeId; + private ITransformationTheorem _default; + + private CoalescedTreeNode _root; + private List _tree; + + public TransformationTheoremProvider(MathIdentifier transformationTypeId) + { + _transformationTypeId = transformationTypeId; + _tree = CoalescedTreeNode.CreateRootTree(out _root); + } + + public MathIdentifier TheoremTypeId + { + get { return _transformationTypeId; } + } + + public ITransformationTheorem Default + { + get { return _default; } + set { _default = value; } + } + + public CoalescedTreeNode Root + { + get { return _root; } + } + + protected override MathIdentifier GetKeyForItem(ITransformationTheorem item) + { + return item.TheoremId; + } + + protected override void InsertItem(int index, ITransformationTheorem item) + { + base.InsertItem(index, item); + + Pattern pattern = item.CreatePattern(); + pattern.MergeToCoalescedTree(item.TheoremId, _tree); + + if(_default == null) + _default = item; + } + + public bool TryGetValue(MathIdentifier id, out ITransformationTheorem theorem) + { + theorem = null; + if(!Contains(id)) + return false; + theorem = base[id]; + return true; + } + + #region Pattern Matching + public MatchCollection MatchAll(Signal output, Port port) + { + return _root.MatchAll(output, port, 1); + } + public Match MatchFirst(Signal output, Port port) + { + Match res = _root.MatchFirst(output, port); + if(res == null) + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + return res; + } + public bool TryMatchFirst(Signal output, Port port, out Match match) + { + match = _root.MatchFirst(output, port); + return match != null; + } + public Match MatchBest(Signal output, Port port) + { + Match bestMatch = _root.MatchBest(output, port); + if(bestMatch == null) + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + return bestMatch; + } + public bool TryMatchBest(Signal output, Port port, out Match match) + { + match = _root.MatchBest(output, port); + return match != null; + } + #endregion + + #region Theorem Matching + public ITransformationTheorem LookupFirst(Signal output, Port port, out GroupCollection groups) + { + Match match = MatchFirst(output, port); + groups = match.Groups; + return this[match.PatternId]; + } + public ITransformationTheorem LookupBest(Signal output, Port port, out GroupCollection groups) + { + Match match = MatchBest(output, port); + groups = match.Groups; + return this[match.PatternId]; + } + public bool TryLookupFirst(Signal output, Port port, out ITransformationTheorem theorem, out GroupCollection groups) + { + Match match; + if(TryMatchFirst(output, port, out match)) + { + groups = match.Groups; + if(this.TryGetValue(match.PatternId, out theorem)) + return true; + } + groups = null; + theorem = null; + return false; + } + public bool TryLookupBest(Signal output, Port port, out ITransformationTheorem theorem, out GroupCollection groups) + { + Match match; + if(TryMatchBest(output, port, out match)) + { + groups = match.Groups; + if(this.TryGetValue(match.PatternId, out theorem)) + return true; + } + groups = null; + theorem = null; + return false; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/Transformer.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/Transformer.cs new file mode 100644 index 0000000..4a5938e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Manipulation/Transformer.cs @@ -0,0 +1,70 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Manipulation +{ + public class Transformer : ITransformer + { + Manipulator _manipulator; + ILibrary _library; + + public Transformer() + { + _manipulator = new Manipulator(); + _library = Service.Instance; + } + + public Signal Transform(Signal signal, MathIdentifier transformationTypeId, bool ignoreHold) + { + ITransformationTheoremProvider provider = (ITransformationTheoremProvider)_library.LookupTheoremType(transformationTypeId); + TransformationManipulationVisitor visitor = new TransformationManipulationVisitor(provider); + return _manipulator.Manipulate(signal, visitor, ignoreHold); + } + + public Signal Transform(Signal signal, MathIdentifier transformationTypeId, ConfigureTransformation configure, bool ignoreHold) + { + ITransformationTheoremProvider provider = (ITransformationTheoremProvider)_library.LookupTheoremType(transformationTypeId); + TransformationManipulationVisitor visitor = new TransformationManipulationVisitor(provider, configure); + return _manipulator.Manipulate(signal, visitor, ignoreHold); + } + + public SignalSet Transform(IEnumerable signals, MathIdentifier transformationTypeId, bool ignoreHold) + { + ITransformationTheoremProvider provider = (ITransformationTheoremProvider)_library.LookupTheoremType(transformationTypeId); + TransformationManipulationVisitor visitor = new TransformationManipulationVisitor(provider); + return _manipulator.Manipulate(signals, visitor, ignoreHold); + } + + public SignalSet Transform(IEnumerable signals, MathIdentifier transformationTypeId, ConfigureTransformation configure, bool ignoreHold) + { + ITransformationTheoremProvider provider = (ITransformationTheoremProvider)_library.LookupTheoremType(transformationTypeId); + TransformationManipulationVisitor visitor = new TransformationManipulationVisitor(provider, configure); + return _manipulator.Manipulate(signals, visitor, ignoreHold); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/ManipulationFactory.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/ManipulationFactory.cs new file mode 100644 index 0000000..5d1e991 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/ManipulationFactory.cs @@ -0,0 +1,55 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Manipulation; + +namespace MathNet.Symbolics +{ + internal class ManipulationFactory : + IFactory, IFactory, + IFactory + { + IManipulator IFactory.GetInstance() + { + return new Manipulator(); + } + + ITransformer IFactory.GetInstance() + { + return new Transformer(); + } + + ITransformationTheoremProvider IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: MathIdentifier"); + } + ITransformationTheoremProvider IFactory.GetInstance(MathIdentifier p1) + { + return new TransformationTheoremProvider(p1); + } + + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f1b59db --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Manipulation")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("b9a354c6-b0f7-431d-865c-9b404eb29419")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Yttrium.Manipulation.Service.csproj b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Yttrium.Manipulation.Service.csproj new file mode 100644 index 0000000..12b00bb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Manipulation.Service/Yttrium.Manipulation.Service.csproj @@ -0,0 +1,88 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {4927027C-5A8B-41ED-B680-84C656A98031} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Manipulation.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C} + Yttrium.Manipulation.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {6AAA89AE-90D5-496B-9EBD-5274C662C147} + Yttrium.Patterns.Toolkit + + + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Yttrium.Traversing.Contracts + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Exceptions/CommandException.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Exceptions/CommandException.cs new file mode 100644 index 0000000..e655204 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Exceptions/CommandException.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class CommandException : YttriumException + { + public CommandException() + : base() + { + } + + public CommandException(string message) + : base(message) + { + } + + public CommandException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected CommandException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/CommandReference.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/CommandReference.cs new file mode 100644 index 0000000..5cd9e13 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/CommandReference.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Security.Permissions; +using System.Text; +using System.Xml; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public struct CommandReference : ISerializable, IEquatable + { + private readonly Guid _instanceId; + private readonly int _index; + + public CommandReference(Guid instanceId, int index) + { + _instanceId = instanceId; + _index = index; + } + + public Guid InstanceId + { + get { return _instanceId; } + } + + public int Index + { + get { return _index; } + } + + #region Full Serialization + private CommandReference(SerializationInfo info, StreamingContext context) + { + _index = info.GetInt32("Index"); + _instanceId = new Guid(info.GetString("InstanceId")); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("Index", _index); + info.AddValue("InstanceId", _instanceId); + } + #endregion + #region Partial Serialization + public void Serialize(string name, SerializationInfo info) + { + info.AddValue(name + "Index", _index); + info.AddValue(name + "InstanceId", _instanceId); + } + public static CommandReference Deserialize(string name, SerializationInfo info) + { + int idx = info.GetInt32(name + "Index"); + Guid iid = new Guid(info.GetString(name + "InstanceId")); + return new CommandReference(iid, idx); + } + public void Serialize(string name, XmlWriter writer) + { + writer.WriteElementString(name + "Index", _index.ToString()); + writer.WriteElementString(name + "InstanceId", _instanceId.ToString()); + } + public static CommandReference Deserialize(string name, XmlReader reader) + { + int idx = int.Parse(reader.ReadElementString(name + "Index")); + Guid iid = new Guid(reader.ReadElementString(name + "InstanceId")); + return new CommandReference(iid, idx); + } + #endregion + + #region IEquatable Members + public bool Equals(CommandReference other) + { + return _index.Equals(other._index) && _instanceId.Equals(other._instanceId); + } + public override bool Equals(object obj) + { + if(!(obj is CommandReference)) + throw new ArgumentException(); + return Equals((CommandReference)obj); + } + public static bool operator==(CommandReference a, CommandReference b) + { + return a.Equals(b); + } + public static bool operator !=(CommandReference a, CommandReference b) + { + return !a.Equals(b); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ICommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ICommand.cs new file mode 100644 index 0000000..2e49879 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ICommand.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.Serialization; +using System.Xml.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + public interface ICommand : ISerializable, IXmlSerializable + { + IMathSystem System { get; set;} + void Execute(); + bool Done { get;} + event EventHandler Executed; + //void Unexecute(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ILogWriter.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ILogWriter.cs new file mode 100644 index 0000000..a75d7d6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ILogWriter.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Mediator +{ + public interface ILogWriter + { + void WriteEntry(DateTime time, Guid systemId, LogAction type, Guid portId, Guid signalId, Guid busId, string entityId, int? index1); + } + + public enum LogAction + { + SystemChanged, + BeginInitialize, + EndInitialize, + SignalAdded, + SignalRemoved, + BusAdded, + BusRemoved, + PortAdded, + PortRemoved, + InputAdded, + InputRemoved, + OutputAdded, + OutputRemoved, + PortDrivesSignal, + PortUndrivesSignal, + SignalDrivesPort, + SignalUndrivesPort, + BusAttachedToPort, + BusDetachedFromPort, + SignalValueChanged, + BusValueChanged + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/IMediator.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/IMediator.cs new file mode 100644 index 0000000..34ed060 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/IMediator.cs @@ -0,0 +1,60 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Mediator +{ + public interface IMediator + { + void AttachObserver(IObserver observer); + void DetachObserver(IObserver observer); + + void NotifyNewSignalCreated(Signal signal); + event EventHandler NewSignalCreated; + void NotifyNewPortCreated(Port port); + event EventHandler NewPortCreated; + void NotifyNewBusCreated(Bus bus); + event EventHandler NewBusCreated; + + void NotifyPortDrivesSignal(Signal signal, Port port, int outputIndex); + event EventHandler PortDrivesSignal; + void NotifyPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex); + event EventHandler PortDrivesSignalNoLonger; + void NotifySignalDrivesPort(Signal signal, Port port, int inputIndex); + event EventHandler SignalDrivesPort; + void NotifySignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex); + event EventHandler SignalDrivesPortNoLonger; + void NotifyBusAttachedToPort(Bus bus, Port port, int busIndex); + event EventHandler BusAttachedToPort; + void NotifyBusDetachedFromPort(Bus bus, Port port, int busIndex); + event EventHandler BusDetachedFromPort; + + void NotifySignalValueChanged(Signal signal); + event EventHandler SignalValueChanged; + void NotifyBusValueChanged(Bus bus); + event EventHandler BusValueChanged; + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/IObserver.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/IObserver.cs new file mode 100644 index 0000000..f4807ed --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/IObserver.cs @@ -0,0 +1,44 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Mediator +{ + public interface IObserver + { + void OnNewSignalCreated(Signal signal); + void OnNewPortCreated(Port port); + void OnNewBusCreated(Bus bus); + + void OnPortDrivesSignal(Signal signal, Port port, int outputIndex); + void OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex); + void OnSignalDrivesPort(Signal signal, Port port, int inputIndex); + void OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex); + void OnBusAttachedToPort(Bus bus, Port port, int busIndex); + void OnBusDetachedFromPort(Bus bus, Port port, int busIndex); + + void OnSignalValueChanged(Signal signal); + void OnBusValueChanged(Bus bus); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemMediator.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemMediator.cs new file mode 100644 index 0000000..aad71f0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemMediator.cs @@ -0,0 +1,94 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Mediator +{ + public interface ISystemMediator + { + void AttachObserver(ISystemObserver observer); + void DetachObserver(ISystemObserver observer); + + void SubscribeSystem(IMathSystem system); + void UnsubscribeSystem(IMathSystem system); + IMathSystem CurrentSystem { get; } + + void PostCommand(ICommand command); + + void NotifySignalAdded(Signal signal, int index); + event EventHandler SignalAdded; + void NotifySignalRemoved(Signal signal, int index); + event EventHandler SignalRemoved; + void NotifySignalMoved(Signal signal, int indexBefore, int indexAfter); + event EventHandler SignalMoved; + + void NotifyBusAdded(Bus bus, int index); + event EventHandler BusAdded; + void NotifyBusRemoved(Bus bus, int index); + event EventHandler BusRemoved; + void NotifyBusMoved(Bus bus, int indexBefore, int indexAfter); + event EventHandler BusMoved; + + void NotifyPortAdded(Port port, int index); + event EventHandler PortAdded; + void NotifyPortRemoved(Port port, int index); + event EventHandler PortRemoved; + void NotifyPortMoved(Port port, int indexBefore, int indexAfter); + event EventHandler PortMoved; + + void NotifyInputAdded(Signal signal, int index); + event EventHandler InputAdded; + void NotifyInputRemoved(Signal signal, int index); + event EventHandler InputRemoved; + void NotifyInputMoved(Signal signal, int indexBefore, int indexAfter); + event EventHandler InputMoved; + + void NotifyOutputAdded(Signal signal, int index); + event EventHandler OutputAdded; + void NotifyOutputRemoved(Signal signal, int index); + event EventHandler OutputRemoved; + void NotifyOutputMoved(Signal signal, int indexBefore, int indexAfter); + event EventHandler OutputMoved; + + void NotifyPortDrivesSignal(Signal signal, Port port, int outputIndex); + event EventHandler PortDrivesSignal; + void NotifyPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex); + event EventHandler PortDrivesSignalNoLonger; + void NotifySignalDrivesPort(Signal signal, Port port, int inputIndex); + event EventHandler SignalDrivesPort; + void NotifySignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex); + event EventHandler SignalDrivesPortNoLonger; + void NotifyBusAttachedToPort(Bus bus, Port port, int busIndex); + event EventHandler BusAttachedToPort; + void NotifyBusDetachedFromPort(Bus bus, Port port, int busIndex); + event EventHandler BusDetachedFromPort; + + //void NotifySignalValueChanged(Signal signal); + event EventHandler SignalValueChanged; + //void NotifyBusValueChanged(Bus bus); + event EventHandler BusValueChanged; + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemMediatorSource.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemMediatorSource.cs new file mode 100644 index 0000000..b49ae83 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemMediatorSource.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Mediator +{ + public interface ISystemMediatorSource + { + bool HasSystemMediator { get; } + ISystemMediator SystemMediator { get; set; } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemObserver.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemObserver.cs new file mode 100644 index 0000000..812fd85 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Mediator/ISystemObserver.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Mediator +{ + public interface ISystemObserver + { + bool AutoDetachOnSystemChanged { get;} + bool AutoInitialize { get;} + + void AttachedToSystem(IMathSystem system); + void DetachedFromSystem(IMathSystem system); + void BeginInitialize(); + void EndInitialize(); + + void OnSignalAdded(Signal signal, int index); + void OnSignalRemoved(Signal signal, int index); + void OnSignalMoved(Signal signal, int indexBefore, int indexAfter); + + void OnBusAdded(Bus bus, int index); + void OnBusRemoved(Bus bus, int index); + void OnBusMoved(Bus bus, int indexBefore, int indexAfter); + + void OnPortAdded(Port port, int index); + void OnPortRemoved(Port port, int index); + void OnPortMoved(Port port, int indexBefore, int indexAfter); + + void OnInputAdded(Signal signal, int index); + void OnInputRemoved(Signal signal, int index); + void OnInputMoved(Signal signal, int indexBefore, int indexAfter); + + void OnOutputAdded(Signal signal, int index); + void OnOutputRemoved(Signal signal, int index); + void OnOutputMoved(Signal signal, int indexBefore, int indexAfter); + + void OnPortDrivesSignal(Signal signal, Port port, int outputIndex); + void OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex); + void OnSignalDrivesPort(Signal signal, Port port, int inputIndex); + void OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex); + void OnBusAttachedToPort(Bus bus, Port port, int busIndex); + void OnBusDetachedFromPort(Bus bus, Port port, int busIndex); + + void OnSignalValueChanged(Signal signal); + void OnBusValueChanged(Bus bus); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ab863f9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Mediator Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("bddbef1b-97cc-460e-9231-536c9be0cebd")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Yttrium.Mediator.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Yttrium.Mediator.Contracts.csproj new file mode 100644 index 0000000..d947369 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Contracts/Yttrium.Mediator.Contracts.csproj @@ -0,0 +1,65 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {E623ED40-9B92-40CA-9080-0FC78F668FFE} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Mediator.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/Channel.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/Channel.cs new file mode 100644 index 0000000..fd29b1b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/Channel.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Mediator +{ + public class Channel + { + private Queue _queue; + private bool _enabled; + + /// + /// Thrown if a new entry is available and the queue has been empty. + /// + public event EventHandler EntryAvailable; + + public Channel() + { + _queue = new Queue(); + _enabled = false; + } + + public bool Enabled + { + get { return _enabled; } + set + { + _enabled = value; + } + } + + public bool AcceptsNewEntries + { + get { return _enabled; } + } + + + public bool HasEntries + { + [System.Diagnostics.DebuggerStepThrough] + get { return _queue.Count > 0; } + } + + [System.Diagnostics.DebuggerStepThrough] + public void PushEntry(EntryType entry) + { + if(_enabled) + { + _queue.Enqueue(entry); + // notify if a new _first_ entry is available. + if(_queue.Count == 1 && EntryAvailable != null) + EntryAvailable(this, EventArgs.Empty); + } + } + + [System.Diagnostics.DebuggerStepThrough] + public EntryType PopEntry() + { + return _queue.Dequeue(); + } + + [System.Diagnostics.DebuggerStepThrough] + public EntryType PeekEntry() + { + return _queue.Peek(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/Mediator.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/Mediator.cs new file mode 100644 index 0000000..d8f7568 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/Mediator.cs @@ -0,0 +1,170 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Events; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Mediator +{ + public class Mediator : IMediator + { + private static Mediator _instance = new Mediator(); + public static Mediator Instance + { + get { return _instance; } + } + + private List _observers; + + public Mediator() + { + _observers = new List(); + } + + public void AttachObserver(IObserver observer) + { + _observers.Add(observer); + } + public void DetachObserver(IObserver observer) + { + _observers.Remove(observer); + } + + #region Units Constructed & Deconstructed + public event EventHandler NewSignalCreated; + public void NotifyNewSignalCreated(Signal signal) + { + foreach(IObserver observer in _observers) + observer.OnNewSignalCreated(signal); + EventHandler handler = NewSignalCreated; + if(handler != null) + handler(this, new SignalEventArgs(signal)); + } + + public event EventHandler NewPortCreated; + public void NotifyNewPortCreated(Port port) + { + foreach(IObserver observer in _observers) + observer.OnNewPortCreated(port); + EventHandler handler = NewPortCreated; + if(handler != null) + handler(this, new PortEventArgs(port)); + } + + public event EventHandler NewBusCreated; + public void NotifyNewBusCreated(Bus bus) + { + foreach(IObserver observer in _observers) + observer.OnNewBusCreated(bus); + EventHandler handler = NewBusCreated; + if(handler != null) + handler(this, new BusEventArgs(bus)); + } + #endregion + + #region Port <-> Signal|Bus Connections + public event EventHandler PortDrivesSignal; + public void NotifyPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + foreach(IObserver observer in _observers) + observer.OnPortDrivesSignal(signal, port, outputIndex); + EventHandler handler = PortDrivesSignal; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, outputIndex)); + } + + public event EventHandler PortDrivesSignalNoLonger; + public void NotifyPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + foreach(IObserver observer in _observers) + observer.OnPortDrivesSignalNoLonger(signal, port, outputIndex); + EventHandler handler = PortDrivesSignalNoLonger; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, outputIndex)); + } + + public event EventHandler SignalDrivesPort; + public void NotifySignalDrivesPort(Signal signal, Port port, int inputIndex) + { + foreach(IObserver observer in _observers) + observer.OnSignalDrivesPort(signal, port, inputIndex); + EventHandler handler = SignalDrivesPort; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, inputIndex)); + } + + public event EventHandler SignalDrivesPortNoLonger; + public void NotifySignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + foreach(IObserver observer in _observers) + observer.OnSignalDrivesPortNoLonger(signal, port, inputIndex); + EventHandler handler = SignalDrivesPortNoLonger; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, inputIndex)); + } + + public event EventHandler BusAttachedToPort; + public void NotifyBusAttachedToPort(Bus bus, Port port, int busIndex) + { + foreach(IObserver observer in _observers) + observer.OnBusAttachedToPort(bus, port, busIndex); + EventHandler handler = BusAttachedToPort; + if(handler != null) + handler(this, new BusPortIndexEventArgs(bus, port, busIndex)); + } + + public event EventHandler BusDetachedFromPort; + public void NotifyBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + foreach(IObserver observer in _observers) + observer.OnBusDetachedFromPort(bus, port, busIndex); + EventHandler handler = BusDetachedFromPort; + if(handler != null) + handler(this, new BusPortIndexEventArgs(bus, port, busIndex)); + } + #endregion + + #region ValueNode State + public event EventHandler SignalValueChanged; + public void NotifySignalValueChanged(Signal signal) + { + foreach(IObserver observer in _observers) + observer.OnSignalValueChanged(signal); + EventHandler handler = SignalValueChanged; + if(handler != null) + handler(this, new SignalEventArgs(signal)); + } + + public event EventHandler BusValueChanged; + public void NotifyBusValueChanged(Bus bus) + { + foreach(IObserver observer in _observers) + observer.OnBusValueChanged(bus); + EventHandler handler = BusValueChanged; + if(handler != null) + handler(this, new BusEventArgs(bus)); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/SystemMediator.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/SystemMediator.cs new file mode 100644 index 0000000..5726f18 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Mediator/SystemMediator.cs @@ -0,0 +1,484 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Events; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Mediator +{ + public class SystemMediator : ISystemMediator, IObserver + { + private List _observers; + private IMathSystem _system; + private Channel _commands; + + public event EventHandler SystemChanged; + + public SystemMediator() + { + _commands = new Channel(); + _commands.EntryAvailable += EntryAvailableHandler; + _commands.Enabled = true; + _observers = new List(); + } + + #region Observer Infrastructure + public void AttachObserver(ISystemObserver observer) + { + if(_observers.Contains(observer)) + return; + _observers.Add(observer); + if(_system != null) + { + observer.AttachedToSystem(_system); + if(observer.AutoInitialize) + InitializeObserverWithCurrentSystem(observer); + } + } + public void DetachObserver(ISystemObserver observer) + { + if(!_observers.Contains(observer)) + return; + _observers.Remove(observer); + if(_system != null) + observer.DetachedFromSystem(_system); + } + + private void InitializeObserverWithCurrentSystem(ISystemObserver observer) + { + if(_system == null) + return; + + observer.BeginInitialize(); + + ReadOnlySignalSet allSignals = _system.GetAllSignals(); + for(int i = 0; i < allSignals.Count; i++) + observer.OnSignalAdded(allSignals[i], i); + + ReadOnlyBusSet allBuses = _system.GetAllBuses(); + for(int i = 0; i < allBuses.Count; i++) + observer.OnBusAdded(allBuses[i], i); + + ReadOnlyPortSet allPorts = _system.GetAllPorts(); + for(int i = 0; i < allPorts.Count; i++) + observer.OnPortAdded(allPorts[i], i); + + for(int i = 0; i < allSignals.Count; i++) + { + Signal s = allSignals[i]; + if(s.IsDriven && allPorts.Contains(s.DrivenByPort)) + observer.OnPortDrivesSignal(s, s.DrivenByPort, s.DrivenByPort.OutputSignals.IndexOf(s)); + } + for(int i = 0; i < allPorts.Count; i++) + { + Port p = allPorts[i]; + for(int j = 0; j < p.InputSignalCount; j++) + { + Signal s = p.InputSignals[j]; + if(allSignals.Contains(s)) + observer.OnSignalDrivesPort(s, p, j); + } + } + + ReadOnlySignalSet inputs = _system.GetAllInputs(); + for(int i = 0; i < inputs.Count; i++) + observer.OnInputAdded(inputs[i], i); + + ReadOnlySignalSet outputs = _system.GetAllOutputs(); + for(int i = 0; i < outputs.Count; i++) + observer.OnOutputAdded(outputs[i], i); + + observer.EndInitialize(); + } + #endregion + + #region System Subscription + public IMathSystem CurrentSystem + { + get { return _system; } + } + public void SubscribeSystem(IMathSystem system) + { + if(_system != null && _system.InstanceId == system.InstanceId) + return; // already subscribed + if(_system != null) + throw new InvalidOperationException("There's already a system subscribed."); + _system = system; + foreach(ISystemObserver observer in _observers) + { + observer.AttachedToSystem(system); + if(observer.AutoInitialize) + InitializeObserverWithCurrentSystem(observer); + } + Mediator.Instance.AttachObserver(this); + if(SystemChanged != null) + SystemChanged(this, EventArgs.Empty); + } + + public void UnsubscribeSystem(IMathSystem system) + { + if(_system == null) + return; // wasn't registered, no matter (might be programming error, but doesn't help anyone to throw; more robust this way. + //throw new InvalidOperationException("There's no system subscribed."); + Mediator.Instance.DetachObserver(this); + for(int i = _observers.Count - 1; i >= 0; i--) + { + if(_observers[i].AutoDetachOnSystemChanged) + DetachObserver(_observers[i]); + else + _observers[i].DetachedFromSystem(system); + } + _system = null; + } + #endregion + + #region Signal/Bus/Port Indices + public event EventHandler SignalAdded; + public void NotifySignalAdded(Signal signal, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnSignalAdded(signal, index); + EventHandler handler = SignalAdded; + if(handler != null) + handler(this, new SignalIndexEventArgs(signal, index)); + } + + public event EventHandler SignalRemoved; + public void NotifySignalRemoved(Signal signal, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnSignalRemoved(signal, index); + EventHandler handler = SignalRemoved; + if(handler != null) + handler(this, new SignalIndexEventArgs(signal, index)); + } + + public event EventHandler SignalMoved; + public void NotifySignalMoved(Signal signal, int indexBefore, int indexAfter) + { + foreach(ISystemObserver observer in _observers) + observer.OnSignalMoved(signal, indexBefore, indexAfter); + EventHandler handler = SignalMoved; + if(handler != null) + handler(this, new SignalIndexChangedEventArgs(signal, indexBefore, indexAfter)); + } + + public event EventHandler BusAdded; + public void NotifyBusAdded(Bus bus, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnBusAdded(bus, index); + EventHandler handler = BusAdded; + if(handler != null) + handler(this, new BusIndexEventArgs(bus, index)); + } + + public event EventHandler BusRemoved; + public void NotifyBusRemoved(Bus bus, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnBusRemoved(bus, index); + EventHandler handler = BusRemoved; + if(handler != null) + handler(this, new BusIndexEventArgs(bus, index)); + } + + public event EventHandler BusMoved; + public void NotifyBusMoved(Bus bus, int indexBefore, int indexAfter) + { + foreach(ISystemObserver observer in _observers) + observer.OnBusMoved(bus, indexBefore, indexAfter); + EventHandler handler = BusMoved; + if(handler != null) + handler(this, new BusIndexChangedEventArgs(bus, indexBefore, indexAfter)); + } + + + public event EventHandler PortAdded; + public void NotifyPortAdded(Port port, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnPortAdded(port, index); + EventHandler handler = PortAdded; + if(handler != null) + handler(this, new PortIndexEventArgs(port, index)); + } + + public event EventHandler PortRemoved; + public void NotifyPortRemoved(Port port, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnPortRemoved(port, index); + EventHandler handler = PortRemoved; + if(handler != null) + handler(this, new PortIndexEventArgs(port, index)); + } + + public event EventHandler PortMoved; + public void NotifyPortMoved(Port port, int indexBefore, int indexAfter) + { + foreach(ISystemObserver observer in _observers) + observer.OnPortMoved(port, indexBefore, indexAfter); + EventHandler handler = PortMoved; + if(handler != null) + handler(this, new PortIndexChangedEventArgs(port, indexBefore, indexAfter)); + } + #endregion + + #region Input/Output Indices + public event EventHandler InputAdded; + public void NotifyInputAdded(Signal signal, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnInputAdded(signal, index); + EventHandler handler = InputAdded; + if(handler != null) + handler(this, new SignalIndexEventArgs(signal, index)); + } + + public event EventHandler InputRemoved; + public void NotifyInputRemoved(Signal signal, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnInputRemoved(signal, index); + EventHandler handler = InputRemoved; + if(handler != null) + handler(this, new SignalIndexEventArgs(signal, index)); + } + + public event EventHandler InputMoved; + public void NotifyInputMoved(Signal signal, int indexBefore, int indexAfter) + { + foreach(ISystemObserver observer in _observers) + observer.OnInputMoved(signal, indexBefore, indexAfter); + EventHandler handler = InputMoved; + if(handler != null) + handler(this, new SignalIndexChangedEventArgs(signal, indexBefore, indexAfter)); + } + + + public event EventHandler OutputAdded; + public void NotifyOutputAdded(Signal signal, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnOutputAdded(signal, index); + EventHandler handler = OutputAdded; + if(handler != null) + handler(this, new SignalIndexEventArgs(signal, index)); + } + + public event EventHandler OutputRemoved; + public void NotifyOutputRemoved(Signal signal, int index) + { + foreach(ISystemObserver observer in _observers) + observer.OnOutputRemoved(signal, index); + EventHandler handler = OutputRemoved; + if(handler != null) + handler(this, new SignalIndexEventArgs(signal, index)); + } + + public event EventHandler OutputMoved; + public void NotifyOutputMoved(Signal signal, int indexBefore, int indexAfter) + { + foreach(ISystemObserver observer in _observers) + observer.OnOutputMoved(signal, indexBefore, indexAfter); + EventHandler handler = OutputMoved; + if(handler != null) + handler(this, new SignalIndexChangedEventArgs(signal, indexBefore, indexAfter)); + } + #endregion + + #region Port <-> Signal|Bus Connections + public event EventHandler PortDrivesSignal; + public void NotifyPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + foreach(ISystemObserver observer in _observers) + observer.OnPortDrivesSignal(signal, port, outputIndex); + EventHandler handler = PortDrivesSignal; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, outputIndex)); + } + + public event EventHandler PortDrivesSignalNoLonger; + public void NotifyPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + foreach(ISystemObserver observer in _observers) + observer.OnPortDrivesSignalNoLonger(signal, port, outputIndex); + EventHandler handler = PortDrivesSignalNoLonger; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, outputIndex)); + } + + public event EventHandler SignalDrivesPort; + public void NotifySignalDrivesPort(Signal signal, Port port, int inputIndex) + { + foreach(ISystemObserver observer in _observers) + observer.OnSignalDrivesPort(signal, port, inputIndex); + EventHandler handler = SignalDrivesPort; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, inputIndex)); + } + + public event EventHandler SignalDrivesPortNoLonger; + public void NotifySignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + foreach(ISystemObserver observer in _observers) + observer.OnSignalDrivesPortNoLonger(signal, port, inputIndex); + EventHandler handler = SignalDrivesPortNoLonger; + if(handler != null) + handler(this, new SignalPortIndexEventArgs(signal, port, inputIndex)); + } + + public event EventHandler BusAttachedToPort; + public void NotifyBusAttachedToPort(Bus bus, Port port, int busIndex) + { + foreach(ISystemObserver observer in _observers) + observer.OnBusAttachedToPort(bus, port, busIndex); + EventHandler handler = BusAttachedToPort; + if(handler != null) + handler(this, new BusPortIndexEventArgs(bus, port, busIndex)); + } + + public event EventHandler BusDetachedFromPort; + public void NotifyBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + foreach(ISystemObserver observer in _observers) + observer.OnBusDetachedFromPort(bus, port, busIndex); + EventHandler handler = BusDetachedFromPort; + if(handler != null) + handler(this, new BusPortIndexEventArgs(bus, port, busIndex)); + } + #endregion + + #region ValueNode State + public event EventHandler SignalValueChanged; + public void NotifySignalValueChanged(Signal signal) + { + foreach(ISystemObserver observer in _observers) + observer.OnSignalValueChanged(signal); + EventHandler handler = SignalValueChanged; + if(handler != null) + handler(this, new SignalEventArgs(signal)); + } + + public event EventHandler BusValueChanged; + public void NotifyBusValueChanged(Bus bus) + { + foreach(ISystemObserver observer in _observers) + observer.OnBusValueChanged(bus); + EventHandler handler = BusValueChanged; + if(handler != null) + handler(this, new BusEventArgs(bus)); + } + #endregion + + #region IObserver Members + void IObserver.OnNewSignalCreated(Signal signal) + { + } + + void IObserver.OnNewPortCreated(Port port) + { + } + + void IObserver.OnNewBusCreated(Bus bus) + { + } + + void IObserver.OnPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + if(_system.ContainsSignal(signal) && _system.ContainsPort(port)) + NotifyPortDrivesSignal(signal, port, outputIndex); + } + + void IObserver.OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + if(_system.ContainsSignal(signal) && _system.ContainsPort(port)) + NotifyPortDrivesSignalNoLonger(signal, port, outputIndex); + } + + void IObserver.OnSignalDrivesPort(Signal signal, Port port, int inputIndex) + { + if(_system.ContainsSignal(signal) && _system.ContainsPort(port)) + NotifySignalDrivesPort(signal, port, inputIndex); + } + + void IObserver.OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + + if(_system.ContainsSignal(signal) && _system.ContainsPort(port)) + NotifySignalDrivesPortNoLonger(signal, port, inputIndex); + } + + void IObserver.OnBusAttachedToPort(Bus bus, Port port, int busIndex) + { + if(_system.ContainsBus(bus) && _system.ContainsPort(port)) + NotifyBusAttachedToPort(bus, port, busIndex); + } + + void IObserver.OnBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + if(_system.ContainsBus(bus) && _system.ContainsPort(port)) + NotifyBusDetachedFromPort(bus, port, busIndex); + } + + void IObserver.OnSignalValueChanged(Signal signal) + { + if(_system.ContainsSignal(signal)) + NotifySignalValueChanged(signal); + } + + void IObserver.OnBusValueChanged(Bus bus) + { + if(_system.ContainsBus(bus)) + NotifyBusValueChanged(bus); + } + + #endregion + + #region Command Infrastructure + //public CommandChannel Commands + //{ + // get { return _commands; } + //} + + [System.Diagnostics.DebuggerStepThrough] + public void PostCommand(ICommand command) + { + _commands.PushEntry(command); + } + + [System.Diagnostics.DebuggerStepThrough] + private void EntryAvailableHandler(object sender, EventArgs e) + { + while(_commands.HasEntries) + { + ICommand cmd = _commands.PopEntry(); + cmd.System = _system; + cmd.Execute(); + } + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Service/MediatorFactory.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Service/MediatorFactory.cs new file mode 100644 index 0000000..fd26031 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Service/MediatorFactory.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Mediator; + +namespace MathNet.Symbolics +{ + internal class MediatorFactory : + IFactory, + IFactory, + IFactory + { + //private static IMediator _mediator = new Mediator.Mediator(); + + IMediator IFactory.GetInstance() + { + return Mediator.Mediator.Instance; + //return _mediator; + } + + public ISystemMediator GetInstance() + { + return new SystemMediator(); + } + + public ISystemMediator GetInstance(IMathSystem p1) + { + ISystemMediatorSource source = p1 as ISystemMediatorSource; + if(source == null) + { + SystemMediator sm = new SystemMediator(); + sm.SubscribeSystem(p1); + return sm; + } + if(source.HasSystemMediator) + return source.SystemMediator; + else + { + SystemMediator sm = new SystemMediator(); + source.SystemMediator = sm; + sm.SubscribeSystem(p1); // probably redundant, but doesn't matter (subscribe is robust). + return sm; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0188505 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Mediator")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("2521d438-6245-4c6e-889c-7d598ee0fb08")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Service/Yttrium.Mediator.Service.csproj b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Yttrium.Mediator.Service.csproj new file mode 100644 index 0000000..875a667 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Service/Yttrium.Mediator.Service.csproj @@ -0,0 +1,72 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Mediator.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {E623ED40-9B92-40CA-9080-0FC78F668FFE} + Yttrium.Mediator.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/BusDrivePortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/BusDrivePortCommand.cs new file mode 100644 index 0000000..805bd79 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/BusDrivePortCommand.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class BusDrivePortCommand : ObjectModel.PortBusIndexCommand + { + public BusDrivePortCommand() { } + protected BusDrivePortCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Port port, Bus bus, int index) + { + if(port.Buses[index] != bus) + port.AddBusBinding(index, bus); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/BusUndrivePortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/BusUndrivePortCommand.cs new file mode 100644 index 0000000..190e482 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/BusUndrivePortCommand.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class BusUndrivePortCommand : ObjectModel.PortIndexCommand + { + public BusUndrivePortCommand() { } + protected BusUndrivePortCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Port port, int index) + { + if(port.Buses[index] != null) + port.RemoveBusBinding(index); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/LogObserver.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/LogObserver.cs new file mode 100644 index 0000000..78c757f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/LogObserver.cs @@ -0,0 +1,268 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace MathNet.Symbolics.Mediator +{ + public class TextLogWriter : ILogWriter + { + private TextWriter _writer; + + public TextLogWriter(TextWriter writer) + { + _writer = writer; + } + + public void WriteEntry(DateTime time, Guid systemId, LogAction type, Guid portId, Guid signalId, Guid busId, string entityId, int? index1) + { + _writer.WriteLine("{0:s} -> {1:N} : {2,-20} -> P:{3:N} S:{4:N} B:{5:N} {7} {6}", time, systemId, type, portId, signalId, busId, entityId, index1.ToString() ?? "N/A"); + _writer.Flush(); + } + } + + public class LogObserver : IObserver + { + private ILogWriter _writer; + private Guid _emptyGuid; + private string _emptyId; + + public LogObserver(ILogWriter writer) + { + _writer = writer; + _emptyGuid = Guid.Empty; + _emptyId = string.Empty; + } + + void IObserver.OnNewSignalCreated(Signal signal) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.SignalAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, null); + } + + void IObserver.OnNewPortCreated(Port port) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.PortAdded, port.InstanceId, _emptyGuid, _emptyGuid, port.Entity.EntityId.ToString(), null); + } + + void IObserver.OnNewBusCreated(Bus bus) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.BusAdded, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, null); + } + + void IObserver.OnPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.PortDrivesSignal, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), outputIndex); + } + + void IObserver.OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.PortUndrivesSignal, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), outputIndex); + } + + void IObserver.OnSignalDrivesPort(Signal signal, Port port, int inputIndex) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.SignalDrivesPort, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), inputIndex); + } + + void IObserver.OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.SignalUndrivesPort, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), inputIndex); + } + + void IObserver.OnBusAttachedToPort(Bus bus, Port port, int busIndex) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.BusAttachedToPort, port.InstanceId, _emptyGuid, bus.InstanceId, port.Entity.EntityId.ToString(), busIndex); + } + + void IObserver.OnBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.BusDetachedFromPort, port.InstanceId, _emptyGuid, bus.InstanceId, port.Entity.EntityId.ToString(), busIndex); + } + + void IObserver.OnSignalValueChanged(Signal signal) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.SignalValueChanged, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, null); + } + + void IObserver.OnBusValueChanged(Bus bus) + { + _writer.WriteEntry(DateTime.Now, _emptyGuid, LogAction.BusValueChanged, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, null); + } + } + + public class LogSystemObserver : ISystemObserver + { + private ILogWriter _writer; + private Guid _emptyGuid; + private string _emptyId; + private Guid _currentSysId; + + public LogSystemObserver(ILogWriter writer) + { + _writer = writer; + _emptyGuid = Guid.Empty; + _emptyId = string.Empty; + } + + public bool AutoDetachOnSystemChanged + { + get { return false; } + } + + public bool AutoInitialize + { + get { return true; } + } + + public void AttachedToSystem(IMathSystem system) + { + _currentSysId = system.InstanceId; + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SystemChanged, _emptyGuid, _emptyGuid, _emptyGuid, _emptyId, null); + } + + public void DetachedFromSystem(IMathSystem system) + { + } + + void ISystemObserver.BeginInitialize() + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BeginInitialize, _emptyGuid, _emptyGuid, _emptyGuid, _emptyId, null); + } + + void ISystemObserver.EndInitialize() + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.EndInitialize, _emptyGuid, _emptyGuid, _emptyGuid, _emptyId, null); + } + + void ISystemObserver.OnSignalAdded(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + void ISystemObserver.OnSignalRemoved(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalRemoved, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + void ISystemObserver.OnSignalMoved(Signal signal, int indexBefore, int indexAfter) + { + } + + void ISystemObserver.OnBusAdded(Bus bus, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusAdded, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, index); + } + + void ISystemObserver.OnBusRemoved(Bus bus, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusRemoved, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, index); + } + + void ISystemObserver.OnBusMoved(Bus bus, int indexBefore, int indexAfter) + { + } + + void ISystemObserver.OnPortAdded(Port port, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortAdded, port.InstanceId, _emptyGuid, _emptyGuid, port.Entity.EntityId.ToString(), index); + } + + void ISystemObserver.OnPortRemoved(Port port, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortRemoved, port.InstanceId, _emptyGuid, _emptyGuid, port.Entity.EntityId.ToString(), index); + } + + void ISystemObserver.OnPortMoved(Port port, int indexBefore, int indexAfter) + { + } + + void ISystemObserver.OnInputAdded(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.InputAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + void ISystemObserver.OnInputRemoved(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.InputRemoved, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + void ISystemObserver.OnInputMoved(Signal signal, int indexBefore, int indexAfter) + { + } + + void ISystemObserver.OnOutputAdded(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.OutputAdded, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + void ISystemObserver.OnOutputRemoved(Signal signal, int index) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.OutputRemoved, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, index); + } + + void ISystemObserver.OnOutputMoved(Signal signal, int indexBefore, int indexAfter) + { + } + + void ISystemObserver.OnPortDrivesSignal(Signal signal, Port port, int outputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortDrivesSignal, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), outputIndex); + } + + void ISystemObserver.OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.PortUndrivesSignal, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), outputIndex); + } + + void ISystemObserver.OnSignalDrivesPort(Signal signal, Port port, int inputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalDrivesPort, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), inputIndex); + } + + void ISystemObserver.OnSignalDrivesPortNoLonger(Signal signal, Port port, int inputIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalUndrivesPort, port.InstanceId, signal.InstanceId, _emptyGuid, port.Entity.EntityId.ToString(), inputIndex); + } + + void ISystemObserver.OnBusAttachedToPort(Bus bus, Port port, int busIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusAttachedToPort, port.InstanceId, _emptyGuid, bus.InstanceId, port.Entity.EntityId.ToString(), busIndex); + } + + void ISystemObserver.OnBusDetachedFromPort(Bus bus, Port port, int busIndex) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusDetachedFromPort, port.InstanceId, _emptyGuid, bus.InstanceId, port.Entity.EntityId.ToString(), busIndex); + } + + void ISystemObserver.OnSignalValueChanged(Signal signal) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.SignalValueChanged, _emptyGuid, signal.InstanceId, _emptyGuid, _emptyId, null); + } + + void ISystemObserver.OnBusValueChanged(Bus bus) + { + _writer.WriteEntry(DateTime.Now, _currentSysId, LogAction.BusValueChanged, _emptyGuid, _emptyGuid, bus.InstanceId, _emptyId, null); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewBusCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewBusCommand.cs new file mode 100644 index 0000000..495f6ed --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewBusCommand.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class NewBusCommand : ObjectModel.NewCommand + { + public NewBusCommand() { } + protected NewBusCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override CommandReference Action() + { + int idx = System.BusCount; + Bus b = Binder.CreateBus(); + Guid iid = b.InstanceId; + System.AddBus(b); + return new CommandReference(iid, idx); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewPortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewPortCommand.cs new file mode 100644 index 0000000..d1831a5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewPortCommand.cs @@ -0,0 +1,113 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class NewPortCommand : ObjectModel.NewCommand + { + private MathIdentifier _entityId; + private int _inputCnt, _busCnt; + private int? _outputCnt; + + public NewPortCommand() { } + + public MathIdentifier EntityId + { + get { return _entityId; } + set { _entityId = value; } + } + public int NumberOfInputs + { + get { return _inputCnt; } + set { _inputCnt = value; } + } + public int NumberOfBuses + { + get { return _busCnt; } + set { _busCnt = value; } + } + public int? NumberOfOutputs + { + get { return _outputCnt; } + set { _outputCnt = value; } + } + + protected override CommandReference Action() + { + int idx = System.PortCount; + IEntity e = Service.Instance.LookupEntity(_entityId); + if(e.IsGeneric) + e = e.CompileGenericEntity(_inputCnt, _busCnt, _outputCnt); + Port p = e.InstantiateUnboundPort(); + Guid iid = p.InstanceId; + System.AddSignalRange(p.OutputSignals); + System.AddPort(p); + return new CommandReference(iid, idx); + } + + #region Serialization + protected NewPortCommand(SerializationInfo info, StreamingContext context) + : base(info, context) + { + _entityId = MathIdentifier.Parse(info.GetString("entityId")); + _inputCnt = info.GetInt32("inputCount"); + _busCnt = info.GetInt32("busCount"); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("entityId", _entityId.ToString()); + info.AddValue("inputCount", _inputCnt); + info.AddValue("busCount", _busCnt); + } + public override void ReadXml(XmlReader reader) + { + reader.ReadStartElement("NewPortCommand", Config.YttriumNamespace); + base.ReadXml(reader); + _entityId = MathIdentifier.Parse(reader.ReadElementString("EntityId")); + _inputCnt = int.Parse(reader.ReadElementString("InputCount")); + _busCnt = int.Parse(reader.ReadElementString("BusCount")); + reader.ReadEndElement(); + } + public override void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("NewPortCommand", Config.YttriumNamespace); + base.WriteXml(writer); + writer.WriteElementString("EntityId", _entityId.ToString()); + writer.WriteElementString("InputCount", _inputCnt.ToString()); + writer.WriteElementString("BusCount", _busCnt.ToString()); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewSignalCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewSignalCommand.cs new file mode 100644 index 0000000..c4ca839 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/NewSignalCommand.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class NewSignalCommand : ObjectModel.NewCommand + { + public NewSignalCommand() { } + protected NewSignalCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override CommandReference Action() + { + int idx = System.SignalCount; + Signal s = Binder.CreateSignal(); + Guid iid = s.InstanceId; + System.AddSignal(s); + return new CommandReference(iid, idx); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/AbstractCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/AbstractCommand.cs new file mode 100644 index 0000000..5300aa2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/AbstractCommand.cs @@ -0,0 +1,64 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class AbstractCommand : CommandBase, ICommand + { + protected AbstractCommand() { } + + protected abstract void Action(); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Action(); + EndExecute(); + } + + #region Serialization + protected AbstractCommand(SerializationInfo info, StreamingContext context) + { + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + } + public virtual void ReadXml(XmlReader reader) + { + } + public virtual void WriteXml(XmlWriter writer) + { + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/BusCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/BusCommand.cs new file mode 100644 index 0000000..ab14988 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/BusCommand.cs @@ -0,0 +1,81 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class BusCommand : CommandBase, ICommand + { + private CommandReference _busRef; + + protected BusCommand() { } + + public CommandReference BusReference + { + get { return _busRef; } + set { _busRef = value; } + } + + protected abstract void Action(Bus bus); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Bus bus = GetVerifyBus(_busRef); + Action(bus); + EndExecute(); + } + + #region Serialization + protected BusCommand(SerializationInfo info, StreamingContext context) + { + _busRef = CommandReference.Deserialize("bus", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + _busRef.Serialize("bus", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("BusCommand", Config.YttriumNamespace); + _busRef = CommandReference.Deserialize("Bus", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("BusCommand", Config.YttriumNamespace); + _busRef.Serialize("Bus", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/CommandBase.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/CommandBase.cs new file mode 100644 index 0000000..ef28f10 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/CommandBase.cs @@ -0,0 +1,108 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; +using System.Reflection; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + public abstract class CommandBase + { + private bool _done; + private IMathSystem _system; + + public event EventHandler Executed; + + protected CommandBase() + { + } + + public IMathSystem System + { + [System.Diagnostics.DebuggerStepThrough] + get { return _system; } + [System.Diagnostics.DebuggerStepThrough] + set { _system = value; } + } + + public bool Done + { + get { return _done; } + } + + /// true if and only if the command should continue executing. + [System.Diagnostics.DebuggerStepThrough] + public bool BeginExecute() + { + return !_done; + } + + [System.Diagnostics.DebuggerStepThrough] + public void EndExecute() + { + _done = true; + if(Executed != null) + Executed(this, EventArgs.Empty); + } + + [System.Diagnostics.DebuggerStepThrough] + protected Signal GetVerifySignal(CommandReference signalReference) + { + Signal signal = System.GetSignal(signalReference.Index); + LazyVerify(signal.InstanceId, signalReference.InstanceId); + return signal; + } + + [System.Diagnostics.DebuggerStepThrough] + protected Bus GetVerifyBus(CommandReference busReference) + { + Bus bus = System.GetBus(busReference.Index); + LazyVerify(bus.InstanceId, busReference.InstanceId); + return bus; + } + + [System.Diagnostics.DebuggerStepThrough] + protected Port GetVerifyPort(CommandReference portReference) + { + Port port = System.GetPort(portReference.Index); + LazyVerify(port.InstanceId, portReference.InstanceId); + return port; + } + + [System.Diagnostics.DebuggerStepThrough] + protected void LazyVerify(Guid found, Guid target) + { + if(!(Guid.Empty.Equals(target) || found.Equals(target))) + throw new MathNet.Symbolics.Exceptions.CommandException("Command Failed: InstanceId mismatch."); + } + + public System.Xml.Schema.XmlSchema GetSchema() + { + throw new NotImplementedException(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/NewCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/NewCommand.cs new file mode 100644 index 0000000..ee30387 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/NewCommand.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class NewCommand : CommandBase, ICommand + { + private CommandReference _ref; + + protected NewCommand() { } + + public CommandReference NewReference + { + get { return _ref; } + set { _ref = value; } + } + + protected abstract CommandReference Action(); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + _ref = Action(); + EndExecute(); + } + + #region Serialization + protected NewCommand(SerializationInfo info, StreamingContext context) + { + _ref = CommandReference.Deserialize("new", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + _ref.Serialize("new", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("NewCommand", Config.YttriumNamespace); + _ref = CommandReference.Deserialize("New", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("NewCommand", Config.YttriumNamespace); + _ref.Serialize("New", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortBusCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortBusCommand.cs new file mode 100644 index 0000000..490f0d5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortBusCommand.cs @@ -0,0 +1,91 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class PortBusCommand : CommandBase, ICommand + { + private CommandReference _busRef,_portRef; + + protected PortBusCommand() { } + + public CommandReference BusReference + { + get { return _busRef; } + set { _busRef = value; } + } + public CommandReference PortReference + { + get { return _portRef; } + set { _portRef = value; } + } + + protected abstract void Action(Port port, Bus bus); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Bus bus = GetVerifyBus(_busRef); + Port port = GetVerifyPort(_portRef); + Action(port, bus); + EndExecute(); + } + + #region Serialization + protected PortBusCommand(SerializationInfo info, StreamingContext context) + { + _portRef = CommandReference.Deserialize("port", info); + _busRef = CommandReference.Deserialize("bus", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + _portRef.Serialize("port", info); + _busRef.Serialize("bus", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("PortBusCommand", Config.YttriumNamespace); + _portRef = CommandReference.Deserialize("Port", reader); + _busRef = CommandReference.Deserialize("Bus", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("PortBusCommand", Config.YttriumNamespace); + _portRef.Serialize("Port", writer); + _busRef.Serialize("Bus", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortBusIndexCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortBusIndexCommand.cs new file mode 100644 index 0000000..116b841 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortBusIndexCommand.cs @@ -0,0 +1,102 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class PortBusIndexCommand : CommandBase, ICommand + { + private CommandReference _busRef, _portRef; + private int _index; + + protected PortBusIndexCommand() { } + + public int Index + { + get { return _index; } + set { _index = value; } + } + + public CommandReference BusReference + { + get { return _busRef; } + set { _busRef = value; } + } + public CommandReference PortReference + { + get { return _portRef; } + set { _portRef = value; } + } + + protected abstract void Action(Port port, Bus bus, int index); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Bus bus = GetVerifyBus(_busRef); + Port port = GetVerifyPort(_portRef); + Action(port, bus, _index); + EndExecute(); + } + + #region Serialization + protected PortBusIndexCommand(SerializationInfo info, StreamingContext context) + { + _index = info.GetInt32("idx"); + _portRef = CommandReference.Deserialize("port", info); + _busRef = CommandReference.Deserialize("bus", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("idx", _index); + _portRef.Serialize("port", info); + _busRef.Serialize("bus", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("PortBusIndexCommand", Config.YttriumNamespace); + _index = int.Parse(reader.ReadElementString("Index")); + _portRef = CommandReference.Deserialize("Port", reader); + _busRef = CommandReference.Deserialize("Bus", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("PortBusIndexCommand", Config.YttriumNamespace); + writer.WriteElementString("Index", _index.ToString()); + _portRef.Serialize("Port", writer); + _busRef.Serialize("Bus", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortCommand.cs new file mode 100644 index 0000000..d109d24 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortCommand.cs @@ -0,0 +1,81 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class PortCommand : CommandBase, ICommand + { + private CommandReference _portRef; + + protected PortCommand() { } + + public CommandReference PortReference + { + get { return _portRef; } + set { _portRef = value; } + } + + protected abstract void Action(Port port); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Port port = GetVerifyPort(_portRef); + Action(port); + EndExecute(); + } + + #region Serialization + protected PortCommand(SerializationInfo info, StreamingContext context) + { + _portRef = CommandReference.Deserialize("port", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + _portRef.Serialize("port", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("PortCommand", Config.YttriumNamespace); + _portRef = CommandReference.Deserialize("Port", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("PortCommand", Config.YttriumNamespace); + _portRef.Serialize("Port", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortIndexCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortIndexCommand.cs new file mode 100644 index 0000000..c5083c9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortIndexCommand.cs @@ -0,0 +1,92 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class PortIndexCommand : CommandBase, ICommand + { + private CommandReference _portRef; + private int _index; + + protected PortIndexCommand() { } + + public int Index + { + get { return _index; } + set { _index = value; } + } + + public CommandReference PortReference + { + get { return _portRef; } + set { _portRef = value; } + } + + protected abstract void Action(Port port, int index); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Port port = GetVerifyPort(_portRef); + Action(port, _index); + EndExecute(); + } + + #region Serialization + protected PortIndexCommand(SerializationInfo info, StreamingContext context) + { + _index = info.GetInt32("idx"); + _portRef = CommandReference.Deserialize("port", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("idx", _index); + _portRef.Serialize("port", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("PortIndexCommand", Config.YttriumNamespace); + _index = int.Parse(reader.ReadElementString("Index")); + _portRef = CommandReference.Deserialize("Port", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("PortIndexCommand", Config.YttriumNamespace); + writer.WriteElementString("Index", _index.ToString()); + _portRef.Serialize("Port", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortSignalCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortSignalCommand.cs new file mode 100644 index 0000000..4ff9a25 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortSignalCommand.cs @@ -0,0 +1,91 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class PortSignalCommand : CommandBase, ICommand + { + private CommandReference _signalRef, _portRef; + + protected PortSignalCommand() { } + + public CommandReference SignalReference + { + get { return _signalRef; } + set { _signalRef = value; } + } + public CommandReference PortReference + { + get { return _portRef; } + set { _portRef = value; } + } + + protected abstract void Action(Port port, Signal signal); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Signal signal = GetVerifySignal(_signalRef); + Port port = GetVerifyPort(_portRef); + Action(port, signal); + EndExecute(); + } + + #region Serialization + protected PortSignalCommand(SerializationInfo info, StreamingContext context) + { + _portRef = CommandReference.Deserialize("port", info); + _signalRef = CommandReference.Deserialize("signal", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + _portRef.Serialize("port", info); + _signalRef.Serialize("signal", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("PortSignalCommand", Config.YttriumNamespace); + _portRef = CommandReference.Deserialize("Port", reader); + _signalRef = CommandReference.Deserialize("Signal", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("PortSignalCommand", Config.YttriumNamespace); + _portRef.Serialize("Port", writer); + _signalRef.Serialize("Signal", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortSignalIndexCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortSignalIndexCommand.cs new file mode 100644 index 0000000..728d8d6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/PortSignalIndexCommand.cs @@ -0,0 +1,102 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class PortSignalIndexCommand : CommandBase, ICommand + { + private CommandReference _signalRef, _portRef; + private int _index; + + protected PortSignalIndexCommand() { } + + public int Index + { + get { return _index; } + set { _index = value; } + } + + public CommandReference SignalReference + { + get { return _signalRef; } + set { _signalRef = value; } + } + public CommandReference PortReference + { + get { return _portRef; } + set { _portRef = value; } + } + + protected abstract void Action(Port port, Signal signal, int index); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Signal signal = GetVerifySignal(_signalRef); + Port port = GetVerifyPort(_portRef); + Action(port, signal, _index); + EndExecute(); + } + + #region Serialization + protected PortSignalIndexCommand(SerializationInfo info, StreamingContext context) + { + _index = info.GetInt32("idx"); + _portRef = CommandReference.Deserialize("port", info); + _signalRef = CommandReference.Deserialize("signal", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("idx", _index); + _portRef.Serialize("port", info); + _signalRef.Serialize("signal", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("PortSignalIndexCommand", Config.YttriumNamespace); + _index = int.Parse(reader.ReadElementString("Index")); + _portRef = CommandReference.Deserialize("Port", reader); + _signalRef = CommandReference.Deserialize("Signal", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("PortSignalIndexCommand", Config.YttriumNamespace); + writer.WriteElementString("Index", _index.ToString()); + _portRef.Serialize("Port", writer); + _signalRef.Serialize("Signal", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/SignalCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/SignalCommand.cs new file mode 100644 index 0000000..24bc82b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/ObjectModel/SignalCommand.cs @@ -0,0 +1,81 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator.ObjectModel +{ + [Serializable] + public abstract class SignalCommand : CommandBase, ICommand + { + private CommandReference _signalRef; + + protected SignalCommand() { } + + public CommandReference SignalReference + { + get { return _signalRef; } + set { _signalRef = value; } + } + + protected abstract void Action(Signal signal); + + [System.Diagnostics.DebuggerStepThrough] + public void Execute() + { + if(!BeginExecute()) + return; + Signal signal = GetVerifySignal(_signalRef); + Action(signal); + EndExecute(); + } + + #region Serialization + protected SignalCommand(SerializationInfo info, StreamingContext context) + { + _signalRef = CommandReference.Deserialize("signal", info); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + _signalRef.Serialize("signal", info); + } + public virtual void ReadXml(XmlReader reader) + { + reader.ReadStartElement("SignalCommand", Config.YttriumNamespace); + _signalRef = CommandReference.Deserialize("Signal", reader); + reader.ReadEndElement(); + } + public virtual void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("SignalCommand", Config.YttriumNamespace); + _signalRef.Serialize("Signal", writer); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/PortDriveSignalCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/PortDriveSignalCommand.cs new file mode 100644 index 0000000..2cd32bf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/PortDriveSignalCommand.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class PortDriveSignalCommand : ObjectModel.PortSignalIndexCommand + { + public PortDriveSignalCommand() { } + protected PortDriveSignalCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Port port, Signal signal, int index) + { + if(port.OutputSignals[index] != signal) + port.AddOutputSignalBinding(index, signal); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/PortUndriveSignalCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/PortUndriveSignalCommand.cs new file mode 100644 index 0000000..4faf629 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/PortUndriveSignalCommand.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class PortUndriveSignalCommand : ObjectModel.PortIndexCommand + { + public PortUndriveSignalCommand() { } + protected PortUndriveSignalCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Port port, int index) + { + if(port.OutputSignals[index] != null) + port.RemoveOutputSignalBinding(index); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemoveBusCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemoveBusCommand.cs new file mode 100644 index 0000000..ce4789c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemoveBusCommand.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class RemoveBusCommand : ObjectModel.BusCommand + { + public RemoveBusCommand() { } + protected RemoveBusCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Bus bus) + { + System.RemoveBus(bus); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemovePortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemovePortCommand.cs new file mode 100644 index 0000000..06419e7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemovePortCommand.cs @@ -0,0 +1,78 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class RemovePortCommand : ObjectModel.PortCommand + { + private bool _isolate; + + public RemovePortCommand() { } + + public bool Isolate + { + get { return _isolate; } + set { _isolate = value; } + } + + protected override void Action(Port port) + { + System.RemovePort(port, _isolate); + } + + #region Serialization + protected RemovePortCommand(SerializationInfo info, StreamingContext context) + : base(info, context) + { + _isolate = bool.Parse(info.GetString("isolate")); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("isolate", _isolate.ToString()); + } + public override void ReadXml(XmlReader reader) + { + reader.ReadStartElement("RemovePortCommand", Config.YttriumNamespace); + base.ReadXml(reader); + _isolate = bool.Parse(reader.ReadElementString("Isolate")); + reader.ReadEndElement(); + } + public override void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("RemovePortCommand", Config.YttriumNamespace); + base.WriteXml(writer); + writer.WriteElementString("Isolate", _isolate.ToString()); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemoveSignalCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemoveSignalCommand.cs new file mode 100644 index 0000000..2cdad73 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/RemoveSignalCommand.cs @@ -0,0 +1,78 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class RemoveSignalCommand : ObjectModel.SignalCommand + { + private bool _isolate; + + public RemoveSignalCommand() { } + + public bool Isolate + { + get { return _isolate; } + set { _isolate = value; } + } + + protected override void Action(Signal signal) + { + System.RemoveSignal(signal, _isolate); + } + + #region Serialization + protected RemoveSignalCommand(SerializationInfo info, StreamingContext context) + : base(info, context) + { + _isolate = bool.Parse(info.GetString("isolate")); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("isolate", _isolate.ToString()); + } + public override void ReadXml(XmlReader reader) + { + reader.ReadStartElement("RemoveSignalCommand", Config.YttriumNamespace); + base.ReadXml(reader); + _isolate = bool.Parse(reader.ReadElementString("Isolate")); + reader.ReadEndElement(); + } + public override void WriteXml(XmlWriter writer) + { + writer.WriteStartElement("RemoveSignalCommand", Config.YttriumNamespace); + base.WriteXml(writer); + writer.WriteElementString("Isolate", _isolate.ToString()); + writer.WriteEndElement(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/SignalDrivePortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/SignalDrivePortCommand.cs new file mode 100644 index 0000000..a93292d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/SignalDrivePortCommand.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class SignalDrivePortCommand : ObjectModel.PortSignalIndexCommand + { + public SignalDrivePortCommand() { } + protected SignalDrivePortCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Port port, Signal signal, int index) + { + if(port.InputSignals[index] != signal) + port.AddInputSignalBinding(index, signal); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/SignalUndrivePortCommand.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/SignalUndrivePortCommand.cs new file mode 100644 index 0000000..b19f63a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Mediator/SignalUndrivePortCommand.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Mediator +{ + [Serializable] + public class SignalUndrivePortCommand : ObjectModel.PortIndexCommand + { + public SignalUndrivePortCommand() { } + protected SignalUndrivePortCommand(SerializationInfo info, StreamingContext context) : base(info, context) { } + + protected override void Action(Port port, int index) + { + if(port.InputSignals[index] != null) + port.RemoveInputSignalBinding(index); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..804c788 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Properties/AssemblyInfo.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Mediator Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("bd634e87-2ee0-4691-93fd-d7fb147d4a82")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Yttrium.Mediator.Toolkit.csproj b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Yttrium.Mediator.Toolkit.csproj new file mode 100644 index 0000000..f80b9dc --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Mediator.Toolkit/Yttrium.Mediator.Toolkit.csproj @@ -0,0 +1,96 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {334D8A1D-1004-4097-ACEE-8B954F911EB2} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Mediator.Toolkit + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {E623ED40-9B92-40CA-9080-0FC78F668FFE} + Yttrium.Mediator.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Binder.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Binder.cs new file mode 100644 index 0000000..36befd7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Binder.cs @@ -0,0 +1,221 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Configuration; + +using MathNet.Symbolics.Kernel; + +namespace MathNet.Symbolics +{ + public static class Binder + { + private static readonly Mapper _mapper = new Mapper(); + + private static readonly IFactory _cacheSignal; + private static readonly IFactory _cacheSignal2; + private static readonly IFactory _cacheBus; + private static readonly IFactory _cacheBus2; + private static readonly IFactory _cachePort; + private static readonly IFactory> _cachePort2; + private static readonly IFactory _cacheSystem; + + static Binder() + { + LoadBindings(); + _cacheSignal = _mapper.GetFactory(); + _cacheSignal2 = _mapper.GetFactory(); + _cacheBus = _mapper.GetFactory(); + _cacheBus2 = _mapper.GetFactory(); + _cachePort = _mapper.GetFactory(); + _cachePort2 = _mapper.GetFactory>(); + _cacheSystem = _mapper.GetFactory(); + } + + #region Loading Bindings + public static void LoadBindings() + { + IList bindings + = System.Configuration.ConfigurationManager.GetSection("yttrium/objects") as IList; + if(bindings == null) + { + FileInfo fi = new FileInfo("yttrium.mapping.config"); + if(fi.Exists) + { + XmlMappingAdapter xma = new XmlMappingAdapter(); + bindings = xma.Load(fi.FullName); + } + } + if(bindings != null) + _mapper.ImportBindings(bindings); + } + public static void LoadBindings(string sourceFileName) + { + XmlMappingAdapter xma = new XmlMappingAdapter(); + IList bindings = xma.Load(sourceFileName); + if(bindings != null) + _mapper.ImportBindings(bindings); + } + #endregion + + #region get arbitrary instances + public static T GetSpecificInstance(MathIdentifier id) + { + IFactory factory = _mapper.GetFactory(id); + return factory.GetInstance(); + } + public static T GetInstance() + { + IFactory factory = _mapper.GetFactory(); + return factory.GetInstance(); + } + + //public static T GetSpecificInstance(MathIdentifier id, params object[] parameters) + //{ + // IFactory factory = _mapper.GetFactory(id); + // return factory.GetInstance(parameters); + //} + //public static T GetInstance(params object[] parameters) + //{ + // IFactory factory = _mapper.GetFactory(); + // return factory.GetInstance(parameters); + //} + + #region Parametrized + + /* + * Note: The following list of factories is quite dumb ("WTF"), + * but it greatly simplifies implementing them and makes it + * type-safe once you have your factory (compared to the object[] + * approach where you have to check types and cast/convert manually). + * + * However, let me know if you have a better idea! + * + * [maybe I should check out dependency injection (-> spring.net etc.) ?] + */ + + public static T GetInstance(T1 p1) + { + return _mapper.GetFactory().GetInstance(p1); + } + public static T GetInstance(T1 p1, T2 p2) + { + return _mapper.GetFactory().GetInstance(p1, p2); + } + public static T GetInstance(T1 p1, T2 p2, T3 p3) + { + return _mapper.GetFactory().GetInstance(p1, p2, p3); + } + public static T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4) + { + return _mapper.GetFactory().GetInstance(p1, p2, p3, p4); + } + public static T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) + { + return _mapper.GetFactory().GetInstance(p1, p2, p3, p4, p5); + } + public static T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6) + { + return _mapper.GetFactory().GetInstance(p1, p2, p3, p4, p5, p6); + } + public static T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7) + { + return _mapper.GetFactory().GetInstance(p1, p2, p3, p4, p5, p6, p7); + } + public static T GetInstance(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8) + { + return _mapper.GetFactory().GetInstance(p1, p2, p3, p4, p5, p6, p7, p8); + } + + public static T GetSpecificInstance(MathIdentifier id, T1 p1) + { + return _mapper.GetFactory(id).GetInstance(p1); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2) + { + return _mapper.GetFactory(id).GetInstance(p1, p2); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2, T3 p3) + { + return _mapper.GetFactory(id).GetInstance(p1, p2, p3); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2, T3 p3, T4 p4) + { + return _mapper.GetFactory(id).GetInstance(p1, p2, p3, p4); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) + { + return _mapper.GetFactory(id).GetInstance(p1, p2, p3, p4, p5); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6) + { + return _mapper.GetFactory(id).GetInstance(p1, p2, p3, p4, p5, p6); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7) + { + return _mapper.GetFactory(id).GetInstance(p1, p2, p3, p4, p5, p6, p7); + } + public static T GetSpecificInstance(MathIdentifier id, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8) + { + return _mapper.GetFactory(id).GetInstance(p1, p2, p3, p4, p5, p6, p7, p8); + } + #endregion + #endregion + + #region get special instances + public static Signal CreateSignal() + { + return _cacheSignal.GetInstance(); + } + public static Signal CreateSignal(IValueStructure value) + { + return _cacheSignal2.GetInstance(value); + } + + public static Bus CreateBus() + { + return _cacheBus.GetInstance(); + } + public static Bus CreateBus(IValueStructure value) + { + return _cacheBus2.GetInstance(value); + } + + public static Port CreatePort(IEntity entity) + { + return _cachePort.GetInstance(entity); + } + + public static Port CreatePort(IEntity entity, IEnumerable outputSignals) + { + return _cachePort2.GetInstance(entity, outputSignals); + } + + public static IMathSystem CreateSystem() + { + return _cacheSystem.GetInstance(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Config.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Config.cs new file mode 100644 index 0000000..46d1f65 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Config.cs @@ -0,0 +1,145 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Globalization; +using System.Configuration; +using MathNet.Numerics.RandomSources; + +//using log4net; + +namespace MathNet.Symbolics +{ + // TODO: Does the log really belong into this config class? rather not -> move it to a seperate static Log class + + public static class Config + { + //private static ILog log; + + //static Config() + //{ + // //log4net.Config.XmlConfigurator.Configure(); + // //log = LogManager.GetLogger("yttrium"); + //} + + private static RandomSource _randomSource = new SystemRandomSource(); + + public static string YttriumNamespace + { + get { return @"http://www.cdrnet.net/projects/nmath/symbolics/yttrium/system/0.50/"; } + } + + public static Guid GenerateInstanceId() + { + return Guid.NewGuid(); + } + + public static Encoding InternalEncoding + { + get { return Encoding.Unicode; } + } + + public static CultureInfo UserCulture + { + get { return CultureInfo.CurrentCulture; } + } + + public static CultureInfo InternalCulture + { + get { return CultureInfo.InvariantCulture; } + } + + public static NumberFormatInfo InternalNumberFormat + { + get { return NumberFormatInfo.InvariantInfo; } + } + + public static StringComparer IdentifierComparer + { + get { return StringComparer.InvariantCulture; } + } + + //internal static Configuration LoadMappingConfig() + //{ + // ExeConfigurationFileMap mappingFileMap = new ExeConfigurationFileMap(); + // mappingFileMap.ExeConfigFilename = @"yttrium.mapping.config"; + // return ConfigurationManager.OpenMappedExeConfiguration(mappingFileMap, ConfigurationUserLevel.None); + //} + + public static RandomSource Random + { + get { return _randomSource; } + } + + #region Format Settings + private static char separatorCharacter = ','; + public static char SeparatorCharacter + { + get { return separatorCharacter; } + set { separatorCharacter = value; } + } + + private static char executorCharacter = ';'; + public static char ExecutorCharacter + { + get { return executorCharacter; } + set { executorCharacter = value; } + } + + private static EncapsulationFormat listEncapsulation = new EncapsulationFormat('(', ')'); + public static EncapsulationFormat ListEncapsulation + { + get { return listEncapsulation; } + set { listEncapsulation = value; } + } + + private static EncapsulationFormat vectorEncapsulation = new EncapsulationFormat('[', ']'); + public static EncapsulationFormat VectorEncapsulation + { + get { return vectorEncapsulation; } + set { vectorEncapsulation = value; } + } + + private static EncapsulationFormat setEncapsulation = new EncapsulationFormat('{', '}'); + public static EncapsulationFormat SetEncapsulation + { + get { return setEncapsulation; } + set { setEncapsulation = value; } + } + + private static EncapsulationFormat scalarEncapsulation = new EncapsulationFormat('<', '>'); + public static EncapsulationFormat ScalarEncapsulation + { + get { return scalarEncapsulation; } + set { scalarEncapsulation = value; } + } + + private static EncapsulationFormat literalEncapsulation = new EncapsulationFormat('"', '"'); + public static EncapsulationFormat LiteralEncapsulation + { + get { return literalEncapsulation; } + set { literalEncapsulation = value; } + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/EncapsulationFormat.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/EncapsulationFormat.cs new file mode 100644 index 0000000..656cc33 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/EncapsulationFormat.cs @@ -0,0 +1,83 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + [Serializable] + public struct EncapsulationFormat : IEquatable + { + private readonly char prefix, postfix; + private readonly bool distinguishable; + + public EncapsulationFormat(char prefix, char postfix) + { + this.prefix = prefix; + this.postfix = postfix; + this.distinguishable = prefix != postfix; + } + + public char Prefix + { + get { return prefix; } + } + public char Postfix + { + get { return postfix; } + } + public bool Distinguishable + { + get { return distinguishable; } + } + + #region IEquatable Members + public bool Equals(EncapsulationFormat other) + { + return prefix == other.prefix && postfix == other.postfix; + } + + public override bool Equals(object obj) + { + if(!(obj is EncapsulationFormat)) + throw new ArgumentException(); + return Equals((EncapsulationFormat)obj); + } + + public override int GetHashCode() + { + return prefix.GetHashCode() ^ postfix.GetHashCode(); + } + + public static bool operator ==(EncapsulationFormat x, EncapsulationFormat y) + { + return x.Equals(y); + } + + public static bool operator !=(EncapsulationFormat x, EncapsulationFormat y) + { + return !x.Equals(y); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Events/MathContextEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Events/MathContextEventArgs.cs new file mode 100644 index 0000000..d519fe8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Events/MathContextEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Events +{ + public class MathContextEventArgs : EventArgs + { + private readonly Guid _iid; + + public MathContextEventArgs(Guid instanceId) + { + _iid = instanceId; + } + + public Guid InstanceId + { + get { return _iid; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Exceptions/MicrokernelException.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Exceptions/MicrokernelException.cs new file mode 100644 index 0000000..f6fdd0f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Exceptions/MicrokernelException.cs @@ -0,0 +1,50 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class MicrokernelException : YttriumException + { + public MicrokernelException() + : base() + { + } + + public MicrokernelException(string message) + : base(message) + { + } + + public MicrokernelException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected MicrokernelException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/Mapper.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/Mapper.cs new file mode 100644 index 0000000..65e082d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/Mapper.cs @@ -0,0 +1,278 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Reflection; + +using MathNet.Symbolics.Exceptions; +using MathNet.Symbolics.Properties; + +namespace MathNet.Symbolics.Kernel +{ + internal sealed class Mapper + { + private Dictionary _factoryById; + private Dictionary _factoryByType; + + internal Mapper() + { + _factoryById = new Dictionary(); + _factoryByType = new Dictionary(); + } + + private object LookupFactory(Type type) + { + string typeName = type.FullName; + object factory; + + if(!_factoryByType.TryGetValue(typeName, out factory)) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingUnknownType, typeName)); + + return factory; + } + + private object LookupFactory(MathIdentifier id) + { + object factory; + + if(!_factoryById.TryGetValue(id, out factory)) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingUnknownId, id.ToString())); + + return factory; + } + + #region Type-Safe Accessors + public IFactory GetFactory(MathIdentifier id) + { + return (IFactory)LookupFactory(id); + } + + public IFactory GetFactory() + { + return (IFactory)LookupFactory(typeof(T)); + } + + #region Parametrized + + /* + * Note: The following list of factories is quite dumb ("WTF"), + * but it greatly simplifies implementing them and makes it + * type-safe once you have your factory (compared to the object[] + * approach where you have to check types and cast/convert manually). + * + * However, let me know if you have a better idea! + * + * [maybe I should check out dependency injection (-> spring.net etc.) ?] + */ + + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory() + { + IFactory factory = LookupFactory(typeof(T)) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + public IFactory GetFactory(MathIdentifier id) + { + IFactory factory = LookupFactory(id) as IFactory; + if(factory == null) + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingWrongTypeParameters, typeof(T).FullName)); + return factory; + } + #endregion + #endregion + + public void AddBinding(IFactory factory, MathIdentifier id) + { + _factoryById[id] = factory; + _factoryByType[typeof(T).FullName] = factory; + } + public void AddBinding(object factory, Type contractType, MathIdentifier id) + { + _factoryById[id] = factory; + _factoryByType[contractType.FullName] = factory; + } + + internal void ImportBindings(IEnumerable bindings) + { + Dictionary factoryCache = new Dictionary(); + + foreach(RawBinding binding in bindings) + { + MathIdentifier id = MathIdentifier.Parse(binding.id); + Type contractType; + try + { + contractType = Type.GetType(binding.contractType, true); + } + catch(TypeLoadException e) + {// usually a bad practice to repack exceptions, + // but since TypeLoadException isn't that helpful, this will help the users more: + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingContractLoadFailed, binding.comment, binding.id, binding.contractType), e); + } + object factory; + if(!factoryCache.TryGetValue(binding.factoryType, out factory)) + { + Type factoryType; + try + { + factoryType = Type.GetType(binding.factoryType, true); + } + catch(TypeLoadException e) + { + // usually a bad practice to repack exceptions, + // but since TypeLoadException isn't that helpful, this will help the users more: + throw new MicrokernelException( + string.Format(Config.UserCulture, Resources.BindingFactoryLoadFailed, binding.comment, binding.id, binding.factoryType), e); + } + //if(factoryType == null) + // continue; + ConstructorInfo ctor = factoryType.GetConstructor(new Type[] { }); + if(ctor == null) + continue; + factory = ctor.Invoke(new object[] { }); + factoryCache.Add(binding.factoryType, factory); + } + AddBinding(factory, contractType, id); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/MappingsSectionHandler.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/MappingsSectionHandler.cs new file mode 100644 index 0000000..e714bbf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/MappingsSectionHandler.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; +using System.Text; +using System.Configuration; + +namespace MathNet.Symbolics.Kernel +{ + public sealed class MappingsSectionHandler : IConfigurationSectionHandler + { + public object Create(object parent, object configContext, XmlNode section) + { + XmlMappingAdapter xma = new XmlMappingAdapter(); + return xma.CompileFromXml(section); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/RawBinding.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/RawBinding.cs new file mode 100644 index 0000000..3380350 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/RawBinding.cs @@ -0,0 +1,43 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Kernel +{ + internal sealed class RawBinding + { + internal string id; + internal string contractType; + internal string factoryType; + internal string comment; + + public RawBinding(string id, string contractType, string factoryType, string comment) + { + this.id = id; + this.contractType = contractType; + this.factoryType = factoryType; + this.comment = comment; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/XmlMappingAdapter.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/XmlMappingAdapter.cs new file mode 100644 index 0000000..87226a2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Kernel/XmlMappingAdapter.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; +using System.Text; +using System.Configuration; + +namespace MathNet.Symbolics.Kernel +{ + internal sealed class XmlMappingAdapter + { + #region Load from different XML sources + public IList Load(string sourceFilename) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(sourceFilename); + + return Load(xmlDoc); + } + + public IList Load(XmlDocument sourceDoc) + { + XmlNode objectsSection = sourceDoc.SelectSingleNode("//yttrium/objects"); + if(objectsSection == null) + return null; // no bindings found + else + return CompileFromXml(objectsSection); + } + #endregion + + #region Compile from XML elements + internal IList CompileFromXml(XmlNode objectsSection) + { + List bindings = new List(); + foreach(XmlNode bindingDef in objectsSection.SelectNodes("object")) + { + RawBinding binding = + new RawBinding(GetXmlAttribute(bindingDef, "id", ""), + GetXmlAttribute(bindingDef, "contract", ""), + GetXmlAttribute(bindingDef, "factory", ""), + GetXmlAttribute(bindingDef, "comment", "")); + bindings.Add(binding); + } + return bindings; + } + + private string GetXmlAttribute(XmlNode node, string attributeName, string defaultValue) + { + try + { + return node.Attributes[attributeName].Value; + } + catch(ArgumentOutOfRangeException) + { + return defaultValue; + } + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/MathContext.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/MathContext.cs new file mode 100644 index 0000000..60675c6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/MathContext.cs @@ -0,0 +1,141 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +using MathNet.Symbolics.Properties; + +namespace MathNet.Symbolics +{ + // TODO: Consider a better design that would allow customization (by inheritance). + + /// + /// Provides a context stack for each thread. You may use this to track an execution path + /// e.g. for a mediator/obeserver pattern by means of the provided InstanceId. + /// + /// + /// To inject a new context into the current execution path use the following pattern: + /// + /// using(MathContext ctx = MathContext.Create()) + /// { + /// // ... + /// } + /// + /// + public class MathContext : IDisposable + { + [ThreadStatic] + private static Stack _perThreadStack; + + private static MathContext _root = new MathContext(null, null); + + public static event EventHandler ContextExpired; + + public static MathContext Current + { + get + { + if(_perThreadStack == null) + { + _perThreadStack = new Stack(); + _perThreadStack.Push(_root); + } + return _perThreadStack.Peek(); + } + } + + public static Guid CurrentInstanceId + { + get { return Current.InstanceId; } + } + + public static MathContext Root + { + get { return _root; } + } + + public static MathContext Create() + { + if(_perThreadStack == null) + { + _perThreadStack = new Stack(); + _perThreadStack.Push(_root); + } + MathContext ctx = new MathContext(_perThreadStack.Peek(), _perThreadStack); + _perThreadStack.Push(ctx); + return ctx; + } + + private MathContext _parent; + private Stack _localStack; + private Guid _iid; + + private MathContext(MathContext parent, Stack stack) + { + _parent = parent; + _localStack = stack; + _iid = Guid.NewGuid(); + } + + protected virtual void Dispose(bool disposing) + { + if(disposing) // we only clean up managed resources + { + if(_root == null) + return; // root context + if(!_localStack.Pop()._iid.Equals(_iid)) + throw new Exceptions.MicrokernelException(Resources.ContextIllegalState); + EventHandler handler = ContextExpired; + if(handler != null) + handler(null, new Events.MathContextEventArgs(_iid)); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + public Guid InstanceId + { + get { return _iid; } + } + + public bool HasParent + { + get { return _parent != null; } + } + + public MathContext ParentContext + { + get { return _parent; } + } + + public bool IsRoot + { + get { return _iid.Equals(_root._iid); } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Persistence/Serializer.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Persistence/Serializer.cs new file mode 100644 index 0000000..eb8a269 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Persistence/Serializer.cs @@ -0,0 +1,199 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.Reflection; +using System.IO; + +namespace MathNet.Symbolics.Persistence +{ + public static class Serializer + { + // TODO: Consider using the CustomDataRefs in the Library, so we don't have to relay on GetType-reflection any more. + + #region Single CustomData <-> XmlWriter/Reader + public static void Serialize(ICustomData value, XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + if(value == null) throw new ArgumentNullException("value"); + if(writer == null) throw new ArgumentNullException("writer"); + if(signalMappings == null) throw new ArgumentNullException("signalMappings"); + if(busMappings == null) throw new ArgumentNullException("busMappings"); + + writer.WriteStartElement("CustomData"); + writer.WriteAttributeString("type", TypeToDescription(value.GetType())); + value.Serialize(writer, signalMappings, busMappings); + writer.WriteEndElement(); + } + + public static T Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) where T : ICustomData + { + if(reader == null) throw new ArgumentNullException("reader"); + if(signals == null) throw new ArgumentNullException("signals"); + if(buses == null) throw new ArgumentNullException("buses"); + + if(!reader.IsStartElement("CustomData")) + reader.ReadToDescendant("CustomData"); + Type type = DescriptionToType(reader.GetAttribute("type")); + reader.Read(); + + MethodInfo mi = type.GetMethod("Deserialize", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); + T ret = (T)mi.Invoke(null, new object[] { reader, signals, buses }); + + if(reader.LocalName=="CustomData" && reader.NodeType == XmlNodeType.EndElement) + reader.ReadEndElement(); + + return ret; + } + #endregion + #region Multiple CustomData <-> XmlWriter/Reader + /// Omitted if null, but required when working with more than one data item directly in the xml root. + public static void SerializeList(IEnumerable values, XmlWriter writer, IDictionary signalMappings, IDictionary busMappings, string parentXmlNode) where T : ICustomData + { + bool withRoot = !string.IsNullOrEmpty(parentXmlNode); + if(withRoot) + writer.WriteStartElement(parentXmlNode); + + foreach(ICustomData cd in values) + Serialize(cd, writer, signalMappings, busMappings); + + if(withRoot) + writer.WriteEndElement(); + } + + /// Omitted if null, but required when working with more than one data item directly in the xml root. + public static List DeserializeList(XmlReader reader, IDictionary signals, IDictionary buses, string parentXmlNode) where T : ICustomData + { + List cd = new List(); + + bool withRoot = !string.IsNullOrEmpty(parentXmlNode); + if(withRoot && !reader.IsStartElement(parentXmlNode)) + reader.ReadToDescendant(parentXmlNode); + + while(reader.IsStartElement("CustomData") || reader.ReadToDescendant("CustomData")) + cd.Add(Deserialize(reader, signals, buses)); + + if(withRoot && reader.LocalName == parentXmlNode && reader.NodeType == XmlNodeType.EndElement) + reader.ReadEndElement(); + + return cd; + } + #endregion + #region Single CustomData <-> string + public static string SerializeToString(ICustomData value, IDictionary signalMappings, IDictionary busMappings) + { + StringBuilder sb = new StringBuilder(); + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Config.InternalEncoding; + settings.Indent = false; + settings.ConformanceLevel = ConformanceLevel.Fragment; + settings.NewLineHandling = NewLineHandling.Entitize; + settings.OmitXmlDeclaration = true; + XmlWriter writer = XmlWriter.Create(sb, settings); + + Serialize(value, writer, signalMappings, busMappings); + + writer.Flush(); + writer.Close(); + return sb.ToString(); + } + + public static T DeserializeFromString(string xml, IDictionary signals, IDictionary buses) where T : ICustomData + { + StringReader sr = new StringReader(xml); + XmlReader reader = XmlReader.Create(sr); + + T ret = Deserialize(reader, signals, buses); + + reader.Close(); + sr.Close(); + return ret; + } + #endregion + #region Multiple CustomData <-> string + /// Omitted if null, but required when working with more than one data item directly in the xml root. + public static string SerializeListToString(IEnumerable values, IDictionary signalMappings, IDictionary busMappings, string parentXmlNode) where T : ICustomData + { + StringBuilder sb = new StringBuilder(); + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Config.InternalEncoding; + settings.Indent = false; + settings.ConformanceLevel = ConformanceLevel.Fragment; + settings.NewLineHandling = NewLineHandling.Entitize; + settings.OmitXmlDeclaration = true; + XmlWriter writer = XmlWriter.Create(sb, settings); + + SerializeList(values, writer, signalMappings, busMappings, parentXmlNode); + + //bool withRoot = !string.IsNullOrEmpty(parentXmlNode); + //if(withRoot) + // writer.WriteStartElement(parentXmlNode); + + //foreach(ICustomData cd in values) + // Serialize(cd, writer, signalMappings, busMappings); + + //if(withRoot) + // writer.WriteEndElement(); + + writer.Flush(); + writer.Close(); + return sb.ToString(); + } + + /// Omitted if null, but required when working with more than one data item directly in the xml root. + public static List DeserializeListFromString(string xml, IDictionary signals, IDictionary buses, string parentXmlNode) where T : ICustomData + { + //List cd = new List(); + + StringReader sr = new StringReader(xml); + XmlReader reader = XmlReader.Create(sr); + + List cd = DeserializeList(reader, signals, buses, parentXmlNode); + + //bool withRoot = !string.IsNullOrEmpty(parentXmlNode); + //if(withRoot && !reader.IsStartElement(parentXmlNode)) + // reader.ReadToDescendant(parentXmlNode); + + //while(reader.IsStartElement("CustomData") || reader.ReadToDescendant("CustomData")) + // cd.Add(Deserialize(context, reader, signals, buses)); + + //if(withRoot && reader.LocalName == parentXmlNode && reader.NodeType == XmlNodeType.EndElement) + // reader.ReadEndElement(); + + return cd; + } + #endregion + + public static string TypeToDescription(Type type) + { + if(type == null) + throw new ArgumentNullException("type"); + return type.AssemblyQualifiedName; + } + + public static Type DescriptionToType(string description) + { + return Type.GetType(description, true); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a38b6f7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Microkernel")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("aae56af8-d9c5-4648-8ed9-65a06341f43c")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.Designer.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6dcdaf4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.Designer.cs @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Failed to load the contract for the Math.NET Yttrium module {0} ({1}). It was expected at: '{2}'. You may want to check the mapping configuration file (usually yttrium.mapping.config).. + /// + internal static string BindingContractLoadFailed { + get { + return ResourceManager.GetString("BindingContractLoadFailed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to load the factory for the Math.NET Yttrium module {0} ({1}). It was expected at: '{2}'. You may want to check the mapping configuration file (usually yttrium.mapping.config).. + /// + internal static string BindingFactoryLoadFailed { + get { + return ResourceManager.GetString("BindingFactoryLoadFailed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unknown binding id {0}. Can't get a factory.. + /// + internal static string BindingUnknownId { + get { + return ResourceManager.GetString("BindingUnknownId", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unknown binding type {0}. Can't get a factory.. + /// + internal static string BindingUnknownType { + get { + return ResourceManager.GetString("BindingUnknownType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wrong type parameters. Can't get a factory for type {0}.. + /// + internal static string BindingWrongTypeParameters { + get { + return ResourceManager.GetString("BindingWrongTypeParameters", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to MathContext stack in illegal state. This indicates a programming error, please report.. + /// + internal static string ContextIllegalState { + get { + return ResourceManager.GetString("ContextIllegalState", resourceCulture); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.de.resx b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.de.resx new file mode 100644 index 0000000..321d598 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.de.resx @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Der Vertrag für das Yttrium Modul {0} ({1}) konnte nicht geladen werden. Er wurde unter '{2}' erwartet. Ãœberprüfen sie die Abbildungskonfiguration (üblicherweise yttrium.mapping.config). + comment, id, contract type + + + Die Factory für das Yttrium Modul {0} ({1}) konnte nicht geladen werden. Er wurde unter '{2}' erwartet. Ãœberprüfen sie die Abbildungskonfiguration (üblicherweise yttrium.mapping.config). + comment, id, factory type + + + Unbekannte Bindungs-ID {0}. Es wurde keine Factory gefunden. + mathid + + + Unbekannter Bindungstyp {0}. Es wurde keine Factory gefunden. + type name + + + Falsche Typenparameter. Für den Typ {0} wurde keine Factory gefunden. + type name + + + MathContext hat einen ungültigen Zustand festgestellt. Dies deutet auf einen Programmierfehler hin, bitte melden Sie das Vorkommen den Entwicklern. + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.resx b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.resx new file mode 100644 index 0000000..1551777 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Properties/Resources.resx @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Failed to load the contract for the Math.NET Yttrium module {0} ({1}). It was expected at: '{2}'. You may want to check the mapping configuration file (usually yttrium.mapping.config). + comment, id, contract type + + + Failed to load the factory for the Math.NET Yttrium module {0} ({1}). It was expected at: '{2}'. You may want to check the mapping configuration file (usually yttrium.mapping.config). + comment, id, factory type + + + Unknown binding id {0}. Can't get a factory. + mathid + + + Unknown binding type {0}. Can't get a factory. + type name + + + Wrong type parameters. Can't get a factory for type {0}. + type name + + + MathContext stack in illegal state. This indicates a programming error, please report. + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Service.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Service.cs new file mode 100644 index 0000000..2a39fff --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Service.cs @@ -0,0 +1,47 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics +{ + public static class Service + { + //lazy initialization, since there are no other field members + private static readonly T _instance = Binder.GetInstance(); + + // Explicit static constructor to tell C# compiler + // not to mark type as beforefieldinit + static Service() + { + } + + public static T Instance + { + get + { + return _instance; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/BindingSingletonProvider.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/BindingSingletonProvider.cs new file mode 100644 index 0000000..12bffe7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/BindingSingletonProvider.cs @@ -0,0 +1,47 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Utils +{ + public static class BindingSingletonProvider + { + //lazy initialization, since there are no other field members + private static readonly T _instance = Binder.GetInstance(); + + // Explicit static constructor to tell C# compiler + // not to mark type as beforefieldinit + static BindingSingletonProvider() + { + } + + public static T Instance + { + get + { + return _instance; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/EmptyIterator.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/EmptyIterator.cs new file mode 100644 index 0000000..a75fa9a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/EmptyIterator.cs @@ -0,0 +1,67 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace MathNet.Symbolics.Utils +{ + public sealed class EmptyIterator : IEnumerable, IEnumerator + { + public EmptyIterator() + { + } + + public IEnumerator GetEnumerator() + { + return this; + } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return this; + } + + public bool MoveNext() + { + return false; + } + + public T Current + { + get { return default(T); } + } + object System.Collections.IEnumerator.Current + { + get { return null; } + } + + public void Reset() + { + } + + public void Dispose() + { + GC.SuppressFinalize(this); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/SingletonProvider.cs b/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/SingletonProvider.cs new file mode 100644 index 0000000..b1a4c53 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Utils/SingletonProvider.cs @@ -0,0 +1,47 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Utils +{ + public static class SingletonProvider where T : new() + { + //lazy initialization, since there are no other field members + private static readonly T _instance = new T(); + + // Explicit static constructor to tell C# compiler + // not to mark type as beforefieldinit + static SingletonProvider() + { + } + + public static T Instance + { + get + { + return _instance; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/Yttrium.Microkernel.csproj b/Backup/src/app/MathNet.Yttrium/Microkernel/Yttrium.Microkernel.csproj new file mode 100644 index 0000000..507fccc --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/Yttrium.Microkernel.csproj @@ -0,0 +1,97 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Microkernel + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + PreserveNewest + + + + + Designer + ResXFileCodeGenerator + Resources.Designer.cs + + + Designer + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Microkernel/yttrium.mapping.config b/Backup/src/app/MathNet.Yttrium/Microkernel/yttrium.mapping.config new file mode 100644 index 0000000..c4b8119 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Microkernel/yttrium.mapping.config @@ -0,0 +1,81 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ArbitraryGenericEntity.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ArbitraryGenericEntity.cs new file mode 100644 index 0000000..64b102f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ArbitraryGenericEntity.cs @@ -0,0 +1,62 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + [Serializable] + public class ArbitraryGenericEntity : EntityBase + { + public ArbitraryGenericEntity(string symbol, string label, string domain) + : base(symbol, label, domain, InfixNotation.None, -1, true) { } + public ArbitraryGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence) + : base(symbol, label, domain, notation, precedence, true) { } + + public ArbitraryGenericEntity(string symbol, string label, string domain, string[] buses) + : base(symbol, label, domain, InfixNotation.None, -1, true, buses) { } + public ArbitraryGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] buses) + : base(symbol, label, domain, notation, precedence, true, buses) { } + + public override IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCount) + { + string lbl = EntityId.Label; + string prefixIn = lbl + "_in_"; + string prefixOut = lbl + "_out_"; + + if(!outputSignalsCount.HasValue) + throw new ArgumentNullException("outputSignalsCount"); + + string[] newInputLabels = new string[inputSignalsCount]; + string[] newOutputLabels = new string[inputSignalsCount]; + + for(int i = 0; i < inputSignalsCount; i++) + { + string nr = i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo).PadLeft(3, '0'); + newInputLabels[i] = prefixIn + nr; + newOutputLabels[i] = prefixOut + nr; + } + + return new EntityBase(Symbol, EntityId, Notation, PrecedenceGroup, newInputLabels, newOutputLabels, Buses); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ArchitectureBase.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ArchitectureBase.cs new file mode 100644 index 0000000..35548c6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ArchitectureBase.cs @@ -0,0 +1,128 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public abstract class ArchitectureBase : IArchitecture + { + private MathIdentifier _id; + private bool _isInstance; // = false; + private bool _isMathematicalOperator; + private MathIdentifier _entityId; + private Port _port; // = null; + + protected ArchitectureBase(MathIdentifier id, MathIdentifier entityId, bool isMathematicalOperator) + { + _id = id; + _entityId = entityId; + _isMathematicalOperator = isMathematicalOperator; + } + + public bool IsInstance + { + get { return _isInstance; } + } + + public bool IsMathematicalOperator + { + get { return _isMathematicalOperator; } + } + + public MathIdentifier ArchitectureId + { + get { return _id; } + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public Port Port + { + get { return _port; } + } + + protected void SetPort(Port port) + { + if(port == null) throw new ArgumentNullException("port"); + _isInstance = true; + _port = port; + } + + public virtual bool SupportsPort(Port port) + { + if(port == null) throw new ArgumentNullException("port"); + return port.Entity.EntityId.Equals(_entityId); + } + + public bool RebindToPortIfSupported(Port newPort) + { + if(newPort == null) throw new ArgumentNullException("newPort"); + if(newPort.Equals(_port)) + return true; + if(SupportsPort(newPort)) + { + Port oldPort = _port; + UnregisterArchitecture(); + _port = newPort; + ReregisterArchitecture(oldPort, newPort); + return true; + } + return false; + } + + protected abstract void ReregisterArchitecture(Port oldPort, Port newPort); + + public abstract void UnregisterArchitecture(); + + public virtual ISignalSet ExecuteMathematicalOperator() + { + return _port.OutputSignals; + } + + /*internal Signal AutomaticSimplifyOutput(Signal signal) + { + for(int i = 0; i < port.OutputSignalCount; i++) + { + if(port[i] == signal) + return AutomaticSimplifyOutput(i); + } + return signal; + } + + protected virtual Signal AutomaticSimplifyOutput(int outputIndex) + { + return port[outputIndex]; + }*/ + + public override string ToString() + { + if(_port == null) + return _id.ToString(); + else + return _port.Entity.ToString() + "(" + _id.ToString() + ")"; + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CategoryBase.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CategoryBase.cs new file mode 100644 index 0000000..f30d684 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CategoryBase.cs @@ -0,0 +1,178 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Reflection; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + // TODO: DECISION: Categories (and Category Membership) vs. Properties + + public abstract class CategoryBase : ICategory, IEquatable + { + private MathIdentifier _id; + + protected CategoryBase(string label, string domain) + : this(new MathIdentifier(label, domain)) { } + protected CategoryBase(MathIdentifier id) + { + _id = id; + } + + public abstract CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache); + public abstract CategoryMembershipLevel IsMember(Port port); + + protected bool TryGetCachedMembership(Signal signal, out CategoryMembershipLevel membership) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + // TODO: uncomment and fix + + //IProperty p; + //if(((Signal)signal).Properties.TryLookupProperty(AssociatedPropertyId, out p)) + //{ + // CategoryMembershipProperty property = p as CategoryMembershipProperty; + // if(property != null) + // { + // membership = property.CategoryMembership; + // return true; + // } + //} + membership = CategoryMembershipLevel.Unknown; + return false; + } + + protected CategoryMembershipLevel EvaluateJointChildMembership(IList signals) + { + if(signals.Count == 0) + return CategoryMembershipLevel.Unknown; + CategoryMembershipLevel membership = CategoryMembershipLevel.Member; + foreach(Signal s in signals) + { + CategoryMembershipLevel ret = IsMember(s, false); + if(ret == CategoryMembershipLevel.NotMember) + return CategoryMembershipLevel.NotMember; + if(ret == CategoryMembershipLevel.Unknown) + membership = CategoryMembershipLevel.Unknown; + } + return membership; + } + + public MathIdentifier TypeId + { + get { return _id; } + } + public MathIdentifier AssociatedPropertyId + { + get { return _id; } //propertyId; + } + + ///// Adds a category membership property to the signal + ///// If true the property will stay attached (but updated) when the membership changes. If false the property will be removed. If the new state is unknown, the property is removed in both cases. + //public CategoryMembershipProperty TagSignal(Signal signal, bool sticky) + //{ + // return TagSignal(signal, IsMember(signal, false), sticky); + //} + //protected CategoryMembershipProperty TagSignal(Signal signal, CategoryMembershipLevel membership, bool sticky) + //{ + // if(signal == null) + // throw new ArgumentNullException("signal"); + + // CategoryMembershipProperty property = new CategoryMembershipProperty(this, membership, sticky); + // ((Signal)signal).Properties.AddProperty(property); + // return property; + //} + + public virtual bool Equals(CategoryBase other) + { + return _id.Equals(other._id); + } + + //#region Serialization + //protected abstract void InnerSerialize(XmlWriter writer); + //public static void Serialize(XmlWriter writer, CategoryBase category) + //{ + // if(writer == null) + // throw new ArgumentNullException("writer"); + + // writer.WriteStartElement("Category", Context.YttriumNamespace); + // writer.WriteAttributeString("type", category.GetType().AssemblyQualifiedName); + // category.InnerSerialize(writer); + // writer.WriteEndElement(); + //} + //public static CategoryBase Deserialize(IContext context, XmlReader reader) + //{ + // if(reader == null) + // throw new ArgumentNullException("reader"); + + // reader.ReadStartElement("Category", Context.YttriumNamespace); + // Type type = Type.GetType(reader.GetAttribute("type"), true); + // MethodInfo mi = type.GetMethod("InnerDeserialize", BindingFlags.Static); + // Category ret = (Category)mi.Invoke(null, new object[] { context, reader }); + // reader.ReadEndElement(); + // return ret; + //} + //#endregion + + // SEE MICROKERNEL SERIALIZER + public virtual void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + } + //private static Property Deserialize(IContext context, XmlReader reader, IDictionary signals, IDictionary buses); + + public bool EqualsById(ICategory other) + { + return _id.Equals(other.TypeId); + } + + public bool EqualsById(MathIdentifier otherCategoryId) + { + return _id.Equals(otherCategoryId); + } + + public virtual bool ReferencesCoreObjects + { + get { return false; } + } + + public virtual IEnumerable CollectSignals() + { + yield break; + } + + public virtual IEnumerable CollectBuses() + { + yield break; + } + + public bool Equals(ICategory other) + { + CategoryBase cb = other as CategoryBase; + if(cb == null) + return false; + else + return Equals(cb); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CategoryMembershipProperty.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CategoryMembershipProperty.cs new file mode 100644 index 0000000..25dfbf2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CategoryMembershipProperty.cs @@ -0,0 +1,159 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Reflection; +using System.Collections.Generic; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + // TODO: DECISION: Categories (and Category Membership) vs. Properties + + public class CategoryMembershipProperty : PropertyBase + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("CategoryMembership", "Std"); + private readonly bool _isSticky; + private readonly ICategory _category; + private CategoryMembershipLevel _categoryMembership; + + /// If true the property will stay attached (but updated) when the membership changes. If false the property will be removed. If the new state is unknown, the property is removed in both cases. + public CategoryMembershipProperty(ICategory category, CategoryMembershipLevel categoryMembership, bool sticky) + { + _category = category; + _categoryMembership = categoryMembership; + _isSticky = sticky; + } + + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + + public bool IsSticky + { + get { return _isSticky; } + } + + public ICategory Category + { + get { return _category; } + } + + public CategoryMembershipLevel CategoryMembership + { + get { return _categoryMembership; } + } + + #region Property Member + public override bool StillValidAfterEvent(Signal signal) + { + CategoryMembershipLevel newMembership = _category.IsMember(signal, true); + if(newMembership == CategoryMembershipLevel.Unknown) + { + _categoryMembership = newMembership; + return false; + } + if(_categoryMembership != newMembership) + { + _categoryMembership = newMembership; + if(_isSticky) + return true; + else + return false; + } + return true; + } + + public override bool StillValidAfterDrive(Signal signal) + { + CategoryMembershipLevel newMembership = _category.IsMember(signal, true); + if(newMembership == CategoryMembershipLevel.Unknown) + { + _categoryMembership = newMembership; + return false; + } + if(_categoryMembership != newMembership) + { + _categoryMembership = newMembership; + if(_isSticky) + return true; + else + return false; + } + return true; + } + + public override bool StillValidAfterUndrive(Signal signal) + { + return true; + } + + #endregion + + public override bool Equals(IProperty other) + { + CategoryMembershipProperty cmp = other as CategoryMembershipProperty; + if(cmp == null) + return false; + return _isSticky == cmp._isSticky && _category.Equals(cmp._category) + && _categoryMembership.Equals(cmp._categoryMembership); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + // writer.WriteElementString("Sticky", _isSticky.ToString()); + // writer.WriteElementString("Membership", _categoryMembership.ToString()); + // Category.Serialize(writer, _category); + //} + //private static CategoryMembershipProperty InnerDeserialize(IContext context, XmlReader reader) + //{ + // bool sticky = bool.Parse(reader.ReadElementString("Sticky")); + // ECategoryMembership membership = (ECategoryMembership)Enum.Parse(typeof(ECategoryMembership), reader.ReadElementString("Membership")); + // Category category = Category.Deserialize(context, reader); + // return new CategoryMembershipProperty(category, membership, sticky); + //} + + // SEE MICROKERNEL SERIALIZER + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteElementString("Sticky", _isSticky.ToString()); + writer.WriteElementString("Membership", _categoryMembership.ToString()); + Persistence.Serializer.Serialize(_category, writer, signalMappings, busMappings); + //Category.Serialize(writer, _category); + } + private static CategoryMembershipProperty Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + bool sticky = bool.Parse(reader.ReadElementString("Sticky")); + CategoryMembershipLevel membership = (CategoryMembershipLevel)Enum.Parse(typeof(CategoryMembershipLevel), reader.ReadElementString("Membership")); + ICategory category = Persistence.Serializer.Deserialize(reader, signals, buses); + //Category.Deserialize(context, reader); + return new CategoryMembershipProperty(category, membership, sticky); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CompoundArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CompoundArchitecture.cs new file mode 100644 index 0000000..5f8c2bf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CompoundArchitecture.cs @@ -0,0 +1,135 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + //public class CompoundArchitecture : ArchitectureBase + //{ + // private IMathSystem system; + // private SignalSet inputSignals, outputSignals; + + // public CompoundArchitecture(MathIdentifier id, MathIdentifier entityId, Port port, IMathSystem system) + // : base(id, entityId, false) + // { + // this.inputSignals = port.InputSignals; + // this.outputSignals = port.OutputSignals; + // this.system = system; + // this.system.OutputValueChanged += system_OutputValueChanged; + + // SetPort(port); + + // for(int i = 0; i < inputSignals.Count; i++) + // inputSignals[i].ValueChanged += CompoundArchitecture_SignalValueChanged; + // system.PushInputValueRange(inputSignals); + // } + + // void CompoundArchitecture_SignalValueChanged(object sender, SignalEventArgs e) + // { + // int idx = inputSignals.IndexOf(e.Signal); + // system.PushInputValue(idx, inputSignals[idx].Value); + // } + + // void system_OutputValueChanged(object sender, MathNet.Symbolics.Backend.Events.IndexedSignalEventArgs e) + // { + // outputSignals[e.Index].PostNewValue(e.Signal.Value); + // } + + // public override bool SupportsPort(Port port) + // { + // return port != null && port.InputSignalCount == system.InputCount && port.OutputSignalCount == system.OutputCount && port.BusCount == system.BusCount; + // } + + // public override void UnregisterArchitecture() + // { + // foreach(Signal s in inputSignals) + // s.ValueChanged -= CompoundArchitecture_SignalValueChanged; + // } + + // protected override void ReregisterArchitecture(Port oldPort, Port newPort) + // { + // this.inputSignals = newPort.InputSignals; + // this.outputSignals = newPort.OutputSignals; + // for(int i = 0; i < inputSignals.Count; i++) + // inputSignals[i].ValueChanged += CompoundArchitecture_SignalValueChanged; + // system.PushInputValueRange(inputSignals); + // } + //} + + //public sealed class CompoundArchitectureFactory : IArchitectureFactory + //{ + // private readonly string _xml; + // private readonly MathIdentifier _architectureId; + // private readonly MathIdentifier _entityId; + // private readonly int _inputCnt, _outputCnt, _busCnt; + + // public CompoundArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId, string xml, int inputCount, int outputCount, int busCount) + // { + // _architectureId = architectureId; + // _entityId = entityId; + // _inputCnt = inputCount; + // _outputCnt = outputCount; + // _busCnt = busCount; + // _xml = xml; + // } + // public CompoundArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId, string xml) + // { + // _architectureId = architectureId; + // _entityId = entityId; + // _xml = xml; + // IEntity dummy = MathSystem.ReadXmlEntity(xml, new MathIdentifier("Dummy", "Temp"), string.Empty); + // _inputCnt = dummy.InputSignals.Length; + // _outputCnt = dummy.OutputSignals.Length; + // _busCnt = dummy.Buses.Length; + // } + // public CompoundArchitectureFactory(MathIdentifier architectureId, MathIdentifier entityId, IMathSystem system) + // { + // if(system == null) + // throw new ArgumentNullException("system"); + + // _architectureId = architectureId; + // _entityId = entityId; + // _inputCnt = system.InputCount; + // _outputCnt = system.OutputCount; + // _busCnt = system.BusCount; + // _xml = system.WriteXml(false); + // } + + // public MathIdentifier EntityId + // { + // get { return _entityId; } + // } + + // public bool SupportsPort(Port port) + // { + // return port != null && port.InputSignalCount == _inputCnt && port.OutputSignalCount == _outputCnt && port.BusCount == _busCnt; + // } + + // public IArchitecture InstantiateToPort(Port port) + // { + // if(port == null) throw new ArgumentNullException("port"); + // MathSystem system = MathSystem.ReadXml(_xml, port.Context); + // return new CompoundArchitecture(_architectureId, _entityId, port, system); + // } + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CompoundProcess.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CompoundProcess.cs new file mode 100644 index 0000000..4d73200 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/CompoundProcess.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + //public class CompoundProcess : ProcessBase + //{ + // private IMathSystem system; + // private int[] inputSignalIndexes, outputSignalIndexes, busIndexes; + // private Signal[] inputSignals, outputSignals; + // private Bus[] buses; + + // /// note: negative indexes are interpreted as internal signal indexes, incremented by one (thus -1 means the internal signal with index zero)! + // /// note: negative indexes are interpreted as internal signal indexes, incremented by one (thus -1 means the internal signal with index zero)! + // public CompoundProcess(IMathSystem system, int[] inputSignalIndexes, int[] outputSignalIndexes, int[] busIndexes) + // { + // this.system = system; + // this.inputSignalIndexes = inputSignalIndexes; + // this.outputSignalIndexes = outputSignalIndexes; + // this.busIndexes = busIndexes; + + // if(inputSignalIndexes.Length != system.InputCount) + // throw new ArgumentException("The count of input signal mappings doesn't match the compound process structure.", "inputSignalIndexes"); + // if(outputSignalIndexes.Length != system.OutputCount) + // throw new ArgumentException("The count of output signal mappings doesn't match the compound process structure.", "outputSignalIndexes"); + // if(busIndexes.Length != system.BusCount) + // throw new ArgumentException("The count of bus mappings doesn't match the compound process structure.", "busIndexes"); + + // this.inputSignals = new Signal[inputSignalIndexes.Length]; + // this.outputSignals = new Signal[outputSignalIndexes.Length]; + // this.buses = new Bus[busIndexes.Length]; + + // this.system.OutputValueChanged += system_OutputValueChanged; + // } + + // void system_OutputValueChanged(object sender, IndexedSignalEventArgs e) + // { + // outputSignals[e.Index].PostNewValue(e.Signal.Value); + // } + + // public override void Register(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + // { + // for(int i = 0; i < inputSignalIndexes.Length; i++) + // { + // this.inputSignals[i] = inputSignalIndexes[i] >= 0 ? inputSignals[inputSignalIndexes[i]] : internalSignals[-inputSignalIndexes[i] - 1]; + // SenseSignal(this.inputSignals[i]); + // } + // for(int i = 0; i < outputSignalIndexes.Length; i++) + // this.outputSignals[i] = outputSignalIndexes[i] >= 0 ? outputSignals[outputSignalIndexes[i]] : internalSignals[-outputSignalIndexes[i] - 1]; + // for(int i = 0; i < busIndexes.Length; i++) + // this.buses[i] = buses[busIndexes[i]]; + // } + + // protected override void Action(bool isInit, Signal origin) + // { + // if(origin != null) + // { + // int originIdx = Array.IndexOf(inputSignals, origin); + // system.PushInputValue(originIdx, inputSignals[originIdx].Value); + // } + // else + // system.PushInputValueRange(inputSignals); + // } + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/EntityBase.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/EntityBase.cs new file mode 100644 index 0000000..62af043 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/EntityBase.cs @@ -0,0 +1,213 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Reflection; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + //public enum InfixNotation : int + //{ + // None = 0, + // LeftAssociativeInnerOperator = 1, + // RightAssociativeInnerOperator = 2, + // PreOperator = 3, + // PostOperator = 4 + //} + + [Serializable] + public class EntityBase : IEntity, IEquatable + { + private readonly string _symbol; + private readonly MathIdentifier _id; + private readonly InfixNotation _notation; + private readonly int _precedenceGroup; + private readonly bool _isGeneric; // = false; + private readonly string[] _inputSignalLabels; + private readonly string[] _outputSignalLabels; + private readonly string[] _busLabels; + + public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, bool isGeneric) + : this(symbol, new MathIdentifier(label, domain), notation, precedence, isGeneric, new string[0]) { } + public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, bool isGeneric) + : this(symbol, id, notation, precedence, isGeneric, new string[0]) { } + public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, bool isGeneric, string[] buses) + : this(symbol, new MathIdentifier(label, domain), notation, precedence, isGeneric, buses) { } + public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, bool isGeneric, string[] buses) + { + _id = id; + _symbol = symbol; + _inputSignalLabels = new string[0]; + _outputSignalLabels = new string[0]; + _busLabels = buses; + _isGeneric = isGeneric; + _notation = notation; + _precedenceGroup = precedence; + } + public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals) + : this(symbol, label, domain, notation, precedence, inputSignals, outputSignals, new string[0]) { } + public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals) + : this(symbol, id, notation, precedence, inputSignals, outputSignals, new string[0]) { } + public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals, string[] buses) + : this(symbol, new MathIdentifier(label, domain), notation, precedence, inputSignals, outputSignals, buses) { } + public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals, string[] buses) + { + _id = id; + _symbol = symbol; + _inputSignalLabels = inputSignals; + _outputSignalLabels = outputSignals; + _busLabels = buses; + _notation = notation; + _precedenceGroup = precedence; + } + + public string Symbol + { + get { return _symbol; } + } + + public MathIdentifier EntityId + { + get { return _id; } + } + + public InfixNotation Notation + { + get { return _notation; } + } + + public int PrecedenceGroup + { + get { return _precedenceGroup; } + } + + public bool IsGeneric + { + get { return _isGeneric; } + } + + public string[] InputSignals + { + get { return _inputSignalLabels; } + } + + public string[] OutputSignals + { + get { return _outputSignalLabels; } + } + + public string[] Buses + { + get { return _busLabels; } + } + + public virtual IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCount) + { + return this; + } + + public Port InstantiatePort(params Signal[] inputSignals) + { + return InstantiatePort(inputSignals, null, null); + } + public Port InstantiatePort(IList inputSignals) + { + return InstantiatePort(inputSignals, null, null); + } + public Port InstantiatePort(IList inputSignals, IList outputSignals) + { + return InstantiatePort(inputSignals, outputSignals, null); + } + public virtual Port InstantiatePort(IList inputSignals, IList outputSignals, IList buses) + { + IEntity entity = this; + + if(_isGeneric) + { + if(inputSignals == null) + throw new Exceptions.GenericEntityPortNotInstantiableException(); + entity = CompileGenericEntity(inputSignals.Count, buses != null ? buses.Count : 0, outputSignals != null ? (int?)outputSignals.Count : null); + } + + if(entity.IsGeneric) + throw new Exceptions.GenericEntityPortNotInstantiableException(); + + if((inputSignals != null && inputSignals.Count != entity.InputSignals.Length) || (buses != null && buses.Count != entity.Buses.Length)) + throw new Exceptions.EntitySignalMismatchException(); + + Port port; + if(outputSignals == null) + port = Binder.CreatePort(entity); + else + port = Binder.CreatePort(entity, outputSignals); + if(inputSignals != null) + port.BindInputSignals(inputSignals); + if(buses != null && buses.Count > 0) + port.BindBuses(buses); + port.EnsureArchitectureLink(); //Try to find an architecture already + + return port; + } + public Port InstantiateUnboundPort() + { + return InstantiatePort(null, null, new Bus[] { }); + } + + public override int GetHashCode() + { + return EntityId.GetHashCode(); + } + + public override string ToString() + { + return EntityId.ToString() + ": '" + _symbol + "'"; + } + + public bool Equals(IEntity other) + { + return other != null && EntityId.Equals(other.EntityId) && _symbol == other.Symbol; // && isGeneric == other.isGeneric + //&& inputSignalLabels.Length == other.inputSignalLabels.Length && outputSignalLabels.Length == other.outputSignalLabels.Length && busLabels.Length == other.busLabels.Length; + } + [Obsolete] + public bool Equals(EntityBase other) + { + return other != null && EntityId.Equals(other.EntityId) && _symbol == other.Symbol; // && isGeneric == other.isGeneric + //&& inputSignalLabels.Length == other.inputSignalLabels.Length && outputSignalLabels.Length == other.outputSignalLabels.Length && busLabels.Length == other.busLabels.Length; + } + public override bool Equals(object obj) + { + IEntity entity = obj as IEntity; + return entity != null && Equals(entity); + } + public bool EqualsById(IEntity other) + { + return other != null && EntityId.Equals(other.EntityId); + } + public bool EqualsById(MathIdentifier otherEntityId) + { + return EntityId.Equals(otherEntityId); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericArchitecture.cs new file mode 100644 index 0000000..559d465 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericArchitecture.cs @@ -0,0 +1,66 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public class GenericArchitecture : ArchitectureBase + { + private ProcessBase[] _processes; + private Signal[] _internalSignals; + private Predicate _portSupport; + + public GenericArchitecture(MathIdentifier id, MathIdentifier entityId, bool isMathematicalOperator, Port port, Predicate portSupport, int internalSignalCount, params ProcessBase[] processes) + : base(id, entityId, isMathematicalOperator) + { + _processes = processes; + _portSupport = portSupport; + _internalSignals = new Signal[internalSignalCount]; + for(int i = 0; i < _internalSignals.Length; i++) + _internalSignals[i] = Binder.CreateSignal(); + + //System.Diagnostics.Debug.Assert(SupportsPort(port)); + SetPort(port); + + for(int i = 0; i < processes.Length; i++) + processes[i].Register(port.InputSignals, port.OutputSignals, _internalSignals, port.Buses); + } + + public override bool SupportsPort(Port port) + { + return _portSupport(port); + } + + public override void UnregisterArchitecture() + { + foreach(ProcessBase process in _processes) + process.Unregister(); + } + + protected override void ReregisterArchitecture(Port oldPort, Port newPort) + { + for(int i = 0; i < _processes.Length; i++) + _processes[i].Register(newPort.InputSignals, newPort.OutputSignals, _internalSignals, newPort.Buses); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericArchitectureFactory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericArchitectureFactory.cs new file mode 100644 index 0000000..683a8e5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericArchitectureFactory.cs @@ -0,0 +1,104 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public delegate ProcessBase[] GenerateProcesses(Port port); + public delegate int GenerateInternalSignalCount(Port port); + + public abstract class GenericArchitectureFactory : IArchitectureFactory + { + #region Sub Types + private struct ArchitectureItem + { + public ArchitectureItem(MathIdentifier id, bool isMathematicalOperator, Predicate portSupport, GenerateProcesses processGenerator, GenerateInternalSignalCount internalSignals) + { + this.Id = id; + this.IsMathematicalOperator = isMathematicalOperator; + this.PortSupport = portSupport; + this.ProcessGenerator = processGenerator; + this.InternalSignals = internalSignals; + } + + public MathIdentifier Id; + public bool IsMathematicalOperator; + public Predicate PortSupport; + public GenerateProcesses ProcessGenerator; + public GenerateInternalSignalCount InternalSignals; + } + #endregion + + private List _items; + private MathIdentifier _entityId; + + protected GenericArchitectureFactory(MathIdentifier entityId) + { + _entityId = entityId; + _items = new List(4); + } + + protected void AddArchitecture(MathIdentifier id, Predicate portSupport, GenerateProcesses processGenerator) + { + _items.Add(new ArchitectureItem(id, false, portSupport, processGenerator, delegate(Port port) { return 0; })); + } + protected void AddArchitecture(MathIdentifier id, Predicate portSupport, GenerateProcesses processGenerator, GenerateInternalSignalCount internalSignals) + { + _items.Add(new ArchitectureItem(id, false, portSupport, processGenerator, internalSignals)); + } + protected void AddArchitecture(MathIdentifier id, bool isMathematicalOperator, Predicate portSupport, GenerateProcesses processGenerator, GenerateInternalSignalCount internalSignals) + { + _items.Add(new ArchitectureItem(id, isMathematicalOperator, portSupport, processGenerator, internalSignals)); + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public bool SupportsPort(Port port) + { + if(!port.Entity.EntityId.Equals(_entityId)) + return false; + + foreach(ArchitectureItem item in _items) + { + if(item.PortSupport(port)) + return true; + } + + return false; + } + + public IArchitecture InstantiateToPort(Port port) + { + foreach(ArchitectureItem item in _items) + { + if(item.PortSupport(port)) + return new GenericArchitecture(item.Id, _entityId, item.IsMathematicalOperator,port,item.PortSupport,item.InternalSignals(port),item.ProcessGenerator(port)); + } + throw new MathNet.Symbolics.Exceptions.ArchitectureNotAvailableException(port); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericFunctionProcess.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericFunctionProcess.cs new file mode 100644 index 0000000..7b27dc3 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericFunctionProcess.cs @@ -0,0 +1,158 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + /// + /// A process for functions mapping a set of inputs to one output, which is mapped to several signals. + /// + public abstract class GenericFunctionProcess : ProcessBase + { + private readonly bool[] inInput, inInternal, outOutput, outInternal; + private readonly int inCount, outCount; // = 0; + private readonly Signal[] inputs, outputs; + + protected GenericFunctionProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + if(inInput == null) + throw new ArgumentNullException("inInput"); + if(inInternal == null) + throw new ArgumentNullException("inInternal"); + if(outOutput == null) + throw new ArgumentNullException("outOutput"); + if(outInternal == null) + throw new ArgumentNullException("outInternal"); + + this.inInput = inInput; + this.inInternal = inInternal; + this.outOutput = outOutput; + this.outInternal = outInternal; + + //count mapped signals + for(int i = 0; i < inInput.Length; i++) + if(inInput[i]) inCount++; + for(int i = 0; i < inInternal.Length; i++) + if(inInternal[i]) inCount++; + for(int i = 0; i < outOutput.Length; i++) + if(outOutput[i]) outCount++; + for(int i = 0; i < outInternal.Length; i++) + if(outInternal[i]) outCount++; + + inputs = new Signal[inCount]; + outputs = new Signal[outCount]; + } + protected GenericFunctionProcess(int firstInput, int lastInput, int output) + { + inInput = new bool[lastInput + 1]; + for(int i = firstInput; i <= lastInput; i++) + inInput[i] = true; + + outOutput = new bool[output + 1]; + outOutput[output] = true; + + inInternal = new bool[] { }; + outInternal = new bool[] { }; + + inCount = lastInput-firstInput+1; + outCount = 1; + + inputs = new Signal[inCount]; + outputs = new Signal[outCount]; + } + protected GenericFunctionProcess(int firstInput, int lastInput, int firstOutput, int lastOutput) + { + inInput = new bool[lastInput + 1]; + for(int i = firstInput; i <= lastInput; i++) + inInput[i] = true; + + outOutput = new bool[lastOutput + 1]; + for(int i = firstOutput; i <= lastOutput; i++) + outOutput[i] = true; + + inInternal = new bool[] { }; + outInternal = new bool[] { }; + + inCount = lastInput - firstInput + 1; + outCount = lastOutput - firstOutput + 1; + + inputs = new Signal[inCount]; + outputs = new Signal[outCount]; + } + + protected int InCount + { + get { return inCount; } + } + protected int OutCount + { + get { return outCount; } + } + protected Signal[] Inputs + { + get { return inputs; } + } + protected Signal[] Outputs + { + get { return outputs; } + } + + public override void Register(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + { + int inputIndex = 0, outputIndex = 0; + for(int i = 0; i < inputSignals.Count && iArchitecture Builder Constructor + protected GenericMathOpArchitecture(MathIdentifier entityId) : base(entityId, entityId, true) { } + /// Architecture Builder Constructor + protected GenericMathOpArchitecture(MathIdentifier id, MathIdentifier entityId) : base(id, entityId, true) { } + + /// Port Instance Constructor + protected GenericMathOpArchitecture(MathIdentifier entityId, Port port) : this(entityId, entityId, port) { } + /// Port Instance Constructor + protected GenericMathOpArchitecture(MathIdentifier id, MathIdentifier entityId, Port port) + : base(id, entityId, true) + { + if(port == null) throw new ArgumentNullException("port"); + //System.Diagnostics.Debug.Assert(SupportsPort(port)); + SetPort(port); + + //for(int i = 0; i < port.OutputSignalCount; i++) + // port.OutputSignals[i].PostNewValue(UndefinedSymbol.Instance); + } + + public abstract IArchitecture InstantiateToPort(Port port); + + public override void UnregisterArchitecture() { } + protected override void ReregisterArchitecture(Port oldPort, Port newPort) { } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericParallelProcess.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericParallelProcess.cs new file mode 100644 index 0000000..90d2495 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericParallelProcess.cs @@ -0,0 +1,67 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public abstract class GenericParallelProcess : ProcessBase + { + private readonly int count, firstInput, firstOutput; + private readonly bool inputIsInternal, outputIsInternal; + private readonly Signal[] inputs, outputs; + + protected GenericParallelProcess(int firstInput, int firstOutput, int count, bool inputIsInternal, bool outputIsInternal) + { + this.firstInput = firstInput; + this.firstOutput = firstOutput; + this.count = count; + this.inputIsInternal = inputIsInternal; + this.outputIsInternal = outputIsInternal; + + inputs = new Signal[count]; + outputs = new Signal[count]; + } + + public override void Register(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + { + for(int i = 0; i < count; i++) + { + inputs[i] = inputIsInternal ? internalSignals[firstInput + i] : inputSignals[firstInput + i]; + outputs[i] = outputIsInternal ? internalSignals[firstOutput + i] : outputSignals[firstOutput + i]; + SenseSignal(inputs[i]); + } + + ForceUpdate(); + } + + protected override void Action(bool isInit, Signal origin) + { + for(int i = 0; i < count; i++) + if(inputs[i].HasEvent || isInit) + Process(inputs[i], outputs[i]); + } + + protected abstract void Process(Signal input, Signal output); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericPropagationTheorem.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericPropagationTheorem.cs new file mode 100644 index 0000000..0b4a9f9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericPropagationTheorem.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + //public delegate bool ImpliesProperty(Signal signal); + //public delegate void BuildProperty(Signal signal); + + //public class GenericPropagationTheorem : IPropagationTheorem + //{ + // private readonly MathIdentifier id; + // private readonly MathIdentifier providedPropertyId; + // private readonly ImpliesProperty impliesProperty; + // private readonly BuildProperty buildProperty; + + // public GenericPropagationTheorem(MathIdentifier id, MathIdentifier providedPropertyId, ImpliesProperty impliesProperty, BuildProperty buildProperty) + // { + // this.id = id; + // this.providedPropertyId = providedPropertyId; + // this.impliesProperty = impliesProperty; + // this.buildProperty = buildProperty; + // } + + // public bool WouldBePropagatedTo(Signal target) + // { + // return impliesProperty(target); + // } + + // public bool PropagatePropertyIfApplicable(Signal target) + // { + // if(target == null) throw new ArgumentNullException("target"); + // if(!target.HasProperty(providedPropertyId) && WouldBePropagatedTo(target)) + // buildProperty(target); + // return target.HasProperty(providedPropertyId); + // } + + // public MathIdentifier PropertyTypeId + // { + // get { return providedPropertyId; } + // } + // public MathIdentifier TheoremId + // { + // get { return id; } + // } + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericSimpleArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericSimpleArchitecture.cs new file mode 100644 index 0000000..1b850d5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericSimpleArchitecture.cs @@ -0,0 +1,90 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public abstract class GenericSimpleArchitecture : ArchitectureBase, IArchitectureFactory + { + private Signal[] _internalSignals; + private SignalSet _sensedSignals; + + /// Architecture Builder Constructor + protected GenericSimpleArchitecture(MathIdentifier entityId, bool isMathematicalOperator) : base(entityId, entityId, isMathematicalOperator) { } + + /// Port Instance Constructor + protected GenericSimpleArchitecture(MathIdentifier entityId, bool isMathematicalOperator, Port port, int internalSignalCount) + : base(entityId, entityId, isMathematicalOperator) + { + _internalSignals = new Signal[internalSignalCount]; + for(int i = 0; i < _internalSignals.Length; i++) + _internalSignals[i] = Binder.CreateSignal(); + + //System.Diagnostics.Debug.Assert(SupportsPort(port)); + SetPort(port); + _sensedSignals = new SignalSet(); + SenseSignals(port.InputSignals, _internalSignals, port.Buses, port.OutputSignals); + Action(port.InputSignals, port.OutputSignals, _internalSignals, port.Buses); + } + + #region Signal Sensing + protected abstract void SenseSignals(IList inputSignals, IList internalSignals, IList buses, IList outputSignals); + + protected void SenseSignal(Signal signal) + { + _sensedSignals.Add(signal); + signal.ValueChanged += signal_SignalValueChanged; + } + + protected void StopSenseSignal(Signal signal) + { + signal.ValueChanged -= signal_SignalValueChanged; + _sensedSignals.Remove(signal); + } + + private void signal_SignalValueChanged(object sender, EventArgs e) + { + Action(Port.InputSignals, Port.OutputSignals, _internalSignals, Port.Buses); + } + #endregion + + protected abstract void Action(IList inputSignals, IList outputSignals, IList internalSignals, IList buses); + + public abstract IArchitecture InstantiateToPort(Port port); + + public override void UnregisterArchitecture() + { + foreach(Signal signal in _sensedSignals) + signal.ValueChanged -= signal_SignalValueChanged; + _sensedSignals.Clear(); + } + + protected override void ReregisterArchitecture(Port oldPort, Port newPort) + { + SenseSignals(newPort.InputSignals, _internalSignals, newPort.Buses, newPort.OutputSignals); + Action(newPort.InputSignals, newPort.OutputSignals, _internalSignals, newPort.Buses); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericStdFunctionProcess.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericStdFunctionProcess.cs new file mode 100644 index 0000000..daacb21 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericStdFunctionProcess.cs @@ -0,0 +1,90 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public delegate IValueStructure DefaultValue(); + public delegate T ProcessAction(T accumulation, T item); + public delegate T ConvertFrom(IValueStructure value); + + /// + /// A process for standard functions mapping a set of inputs to one output, which is mapped to several signals. + /// + public class GenericStdFunctionProcess : GenericFunctionProcess where T : IValueStructure + { + private DefaultValue defaultValue; + private ProcessAction processAction; + private ConvertFrom convertFrom; + + public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction processAction, ConvertFrom convertFrom, bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + : base(inInput, inInternal, outOutput, outInternal) + { + this.defaultValue = defaultValue; + this.processAction = processAction; + this.convertFrom = convertFrom; + } + public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction processAction, bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + : base(inInput, inInternal, outOutput, outInternal) + { + this.defaultValue = defaultValue; + this.processAction = processAction; + this.convertFrom = delegate(IValueStructure value) { return (T)value; }; + } + public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction processAction, ConvertFrom convertFrom, int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) + { + this.defaultValue = defaultValue; + this.processAction = processAction; + this.convertFrom = convertFrom; + } + public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction processAction, int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) + { + this.defaultValue = defaultValue; + this.processAction = processAction; + this.convertFrom = delegate(IValueStructure value) { return (T)value; }; + } + public GenericStdFunctionProcess(DefaultValue defaultValue, ConvertFrom convertFrom, ProcessAction processAction, int count) + : base(0, count > 0 ? count-1 : 0, 0) + { + this.defaultValue = defaultValue; + this.processAction = processAction; + this.convertFrom = convertFrom; + } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(defaultValue()); + else + { + T item = convertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + item = processAction(item,convertFrom(Inputs[i].Value)); + PublishToOutputs(item); + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericStdParallelProcess.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericStdParallelProcess.cs new file mode 100644 index 0000000..a499295 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/GenericStdParallelProcess.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public delegate Tout ProcessItem(Tin item); + + public class GenericStdParallelProcess : GenericParallelProcess + where Tin : IValueStructure + where Tout : IValueStructure + { + private ProcessItem processItem; + private ConvertFrom convertFrom; + + public GenericStdParallelProcess(ProcessItem processItem, ConvertFrom convertFrom, int firstInput, int firstOutput, int count, bool inputIsInternal, bool outputIsInternal) + : base(firstInput, firstOutput, count, inputIsInternal, outputIsInternal) + { + this.processItem = processItem; + this.convertFrom = convertFrom; + } + public GenericStdParallelProcess(ProcessItem processItem, int firstInput, int firstOutput, int count, bool inputIsInternal, bool outputIsInternal) + : base(firstInput, firstOutput, count, inputIsInternal, outputIsInternal) + { + this.processItem = processItem; + this.convertFrom = delegate(IValueStructure value) { return (Tin)value; }; + } + public GenericStdParallelProcess(ProcessItem processItem, ConvertFrom convertFrom, int count) + : base(0, 0, count, false, false) + { + this.processItem = processItem; + this.convertFrom = convertFrom; + } + public GenericStdParallelProcess(ProcessItem processItem, int count) + : base(0, 0, count, false, false) + { + this.processItem = processItem; + this.convertFrom = delegate(IValueStructure value) { return (Tin)value; }; + } + + + protected override void Process(Signal input, Signal output) + { + output.PostNewValue(processItem(convertFrom(input.Value))); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/NaryToOneGenericEntity.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/NaryToOneGenericEntity.cs new file mode 100644 index 0000000..491ca27 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/NaryToOneGenericEntity.cs @@ -0,0 +1,61 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + [Serializable] + public class NaryToOneGenericEntity : EntityBase + { + public NaryToOneGenericEntity(string symbol, string label, string domain) + : base(symbol, label, domain, InfixNotation.None, -1, true) { } + public NaryToOneGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence) + : base(symbol, label, domain, notation, precedence, true) { } + + //protected override Entity CompileGenericEntity(Signal[] inputSignals, Bus[] buses) + public override IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCount) + { + string lbl = EntityId.Label; + string prefixIn = lbl + "_in_"; + + if(outputSignalsCount.HasValue && !outputSignalsCount.Value.Equals(1)) + throw new ArgumentException("Unexpected argument value", "outputSignalsCount"); + + string[] newInputLabels = new string[inputSignalsCount]; + string[] newOutputLabels = new string[] { lbl + "_out" }; + + for(int i = 0; i < inputSignalsCount; i++) + { + string nr = i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo).PadLeft(3, '0'); + newInputLabels[i] = prefixIn + nr; + } + + return new EntityBase(Symbol, EntityId, Notation, PrecedenceGroup, newInputLabels, newOutputLabels, Buses); + } + + //public override bool Equals(Entity other) + //{ + // return base.Equals(other) && other is NaryToOneGenericEntity; + //} + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/NearlySymmetricGenericEntity.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/NearlySymmetricGenericEntity.cs new file mode 100644 index 0000000..95de645 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/NearlySymmetricGenericEntity.cs @@ -0,0 +1,100 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + [Serializable] + public class NearlySymmetricGenericEntity : EntityBase + { + private int additionalInputs, additionalOutputs; + + public NearlySymmetricGenericEntity(string symbol, string label, string domain, int additionalInputs, int additionalOutputs) + : this(symbol, label, domain, InfixNotation.None, -1, additionalInputs, additionalOutputs) { } + public NearlySymmetricGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence, int additionalInputs, int additionalOutputs) + : base(symbol, label, domain, notation, precedence, true) + { + this.additionalInputs = additionalInputs; + this.additionalOutputs = additionalOutputs; + } + + public NearlySymmetricGenericEntity(string symbol, string label, string domain, int additionalInputs, int additionalOutputs, string[] buses) + : this(symbol, label, domain, InfixNotation.None, -1, additionalInputs, additionalOutputs, buses) { } + public NearlySymmetricGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence, int additionalInputs, int additionalOutputs, string[] buses) + : base(symbol, label, domain, notation, precedence, true, buses) + { + this.additionalInputs = additionalInputs; + this.additionalOutputs = additionalOutputs; + } + + //protected override Entity CompileGenericEntity(Signal[] inputSignals, Bus[] buses) + public override IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCnt) + { + int signalCnt = inputSignalsCount - additionalInputs; + int outputSignalsCount = signalCnt + additionalOutputs; + + if(outputSignalsCnt.HasValue && !outputSignalsCnt.Value.Equals(outputSignalsCount)) + throw new ArgumentException("Unexpected argument value", "outputSignalsCnt"); + + string[] newInputLabels = new string[inputSignalsCount]; + string[] newOutputLabels = new string[outputSignalsCount]; + + string lbl = EntityId.Label; + string prefixIn = lbl + "_in_"; + string prefixOut = lbl + "_out_"; + + for(int i = 0; i < signalCnt; i++) + { + string nr = i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo).PadLeft(3, '0'); + newInputLabels[i] = prefixIn + nr; + newOutputLabels[i] = prefixOut + nr; + } + + prefixIn = lbl + "_additionalin_"; + prefixOut = lbl + "_additionalout_"; + + for(int i = 0; i < newInputLabels.Length - signalCnt; i++) + { + string nr = i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo).PadLeft(3, '0'); + newInputLabels[i + signalCnt] = prefixIn + nr; + } + for(int i = 0; i < newOutputLabels.Length - signalCnt; i++) + { + string nr = i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo).PadLeft(3, '0'); + newOutputLabels[i + signalCnt] = prefixOut + nr; + } + + return new EntityBase(Symbol, EntityId, Notation, PrecedenceGroup, newInputLabels, newOutputLabels, Buses); + } + + //public override bool Equals(Entity other) + //{ + // if(!base.Equals(other)) + // return false; + // NearlySymmetricGenericEntity nsge = other as NearlySymmetricGenericEntity; + // if(nsge == null) + // return false; + // return additionalInputs == nsge.additionalInputs && additionalOutputs == nsge.additionalOutputs; + //} + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ProcessBase.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ProcessBase.cs new file mode 100644 index 0000000..3f1b36b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ProcessBase.cs @@ -0,0 +1,104 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public abstract class ProcessBase + { + private List sensitiveSignals; + + protected ProcessBase() + { + this.sensitiveSignals = new List(8); + } + + private bool paused; // = false; + public bool Paused + { + get { return paused; } + set + { + if(value) + Pause(); + else + Continue(); + } + } + + public abstract void Register(IList inputSignals, IList outputSignals, IList internalSignals, IList buses); + + public virtual void Unregister() + { + foreach(Signal signal in sensitiveSignals) + signal.ValueChanged -= signal_SignalValueChanged; + sensitiveSignals.Clear(); + } + + public void Pause() + { + if(paused) + return; + foreach(Signal signal in sensitiveSignals) + signal.ValueChanged -= signal_SignalValueChanged; + paused = true; + } + + public void Continue() + { + if(!paused) + return; + foreach(Signal signal in sensitiveSignals) + signal.ValueChanged += signal_SignalValueChanged; + paused = false; + } + + public void ForceUpdate() + { + Action(true, null); + } + + protected void SenseSignal(Signal signal) + { + signal.ValueChanged += signal_SignalValueChanged; + sensitiveSignals.Add(signal); + } + + protected void StopSenseSignal(Signal signal) + { + signal.ValueChanged -= signal_SignalValueChanged; + sensitiveSignals.Remove(signal); + + } + + /// note: may be null if not applicable + protected abstract void Action(bool isInit, Signal origin); + + private void signal_SignalValueChanged(object sender, ValueNodeEventArgs e) + { + Action(false, (Signal)e.ValueNode); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/PropertyBase.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/PropertyBase.cs new file mode 100644 index 0000000..5eba2c0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/PropertyBase.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Reflection; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public abstract class PropertyBase : IProperty + { + public abstract MathIdentifier TypeId { get;} + + public abstract bool StillValidAfterEvent(Signal signal); + public abstract bool StillValidAfterDrive(Signal signal); + public abstract bool StillValidAfterUndrive(Signal signal); + + public virtual bool ReferencesCoreObjects + { + get { return false; } + } + + public virtual IEnumerable CollectSignals() + { + yield break; + //return SingletonProvider>.Instance; + } + public virtual IEnumerable CollectBuses() + { + yield break; + //return SingletonProvider>.Instance; + } + + #region Equality + public abstract bool Equals(IProperty other); + public override bool Equals(object obj) + { + IProperty vs = obj as IProperty; + if(vs != null) + return Equals(vs); + return false; + } + + public bool EqualsById(IProperty other) + { + return other != null && TypeId.Equals(other.TypeId); + } + + public bool EqualsById(MathIdentifier otherPropertyId) + { + return TypeId.Equals(otherPropertyId); + } + #endregion + + public override string ToString() + { + return TypeId.ToString(); + } + + // SEE MICROKERNEL SERIALIZER + public virtual void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + } + //private static Property Deserialize(IContext context, XmlReader reader, IDictionary signals, IDictionary buses); + + + + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/SymmetricGenericEntity.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/SymmetricGenericEntity.cs new file mode 100644 index 0000000..c596de0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/SymmetricGenericEntity.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + [Serializable] + public class SymmetricGenericEntity : EntityBase + { + public SymmetricGenericEntity(string symbol, string label, string domain) + : base(symbol, label, domain, InfixNotation.None, -1, true) { } + public SymmetricGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence) + : base(symbol, label, domain, notation, precedence, true) { } + + public SymmetricGenericEntity(string symbol, string label, string domain, string[] buses) + : base(symbol, label, domain, InfixNotation.None, -1, true, buses) { } + public SymmetricGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] buses) + : base(symbol, label, domain, notation, precedence, true, buses) { } + + //protected override Entity CompileGenericEntity(Signal[] inputSignals, Bus[] buses) + public override IEntity CompileGenericEntity(int inputSignalsCount, int busesCount, int? outputSignalsCount) + { + string lbl = EntityId.Label; + string prefixIn = lbl + "_in_"; + string prefixOut = lbl + "_out_"; + + if(outputSignalsCount.HasValue && !outputSignalsCount.Value.Equals(inputSignalsCount)) + throw new ArgumentException("Unexpected argument value", "outputSignalsCount"); + + string[] newInputLabels = new string[inputSignalsCount]; + string[] newOutputLabels = new string[inputSignalsCount]; + + for(int i = 0; i < inputSignalsCount; i++) + { + string nr = i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo).PadLeft(3, '0'); + newInputLabels[i] = prefixIn + nr; + newOutputLabels[i] = prefixOut + nr; + } + + return new EntityBase(Symbol, EntityId, Notation, PrecedenceGroup, newInputLabels, newOutputLabels, Buses); + } + + //public override bool Equals(Entity other) + //{ + // return base.Equals(other) && other is SymmetricGenericEntity; + //} + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ValueStructureBase.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ValueStructureBase.cs new file mode 100644 index 0000000..f001a96 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/ObjectModel/ValueStructureBase.cs @@ -0,0 +1,88 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Reflection; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.ObjectModel +{ + public abstract class ValueStructureBase : IValueStructure + { + public abstract MathIdentifier TypeId { get;} + + public virtual bool ReferencesCoreObjects + { + get { return false; } + } + + public virtual IEnumerable CollectSignals() + { + yield break; + //return SingletonProvider>.Instance; + } + public virtual IEnumerable CollectBuses() + { + yield break; + //return SingletonProvider>.Instance; + } + + #region Equality + public abstract bool Equals(IValueStructure other); + public override bool Equals(object obj) + { + IValueStructure vs = obj as IValueStructure; + if(vs != null) + return Equals(vs); + return false; + } + + public bool EqualsById(IValueStructure other) + { + return other != null && TypeId.Equals(other.TypeId); + } + public bool EqualsById(MathIdentifier otherStructureId) + { + return TypeId.Equals(otherStructureId); + } + #endregion + + protected string FormatBase(string value, FormattingOptions options) + { + if((options & FormattingOptions.Compact) == FormattingOptions.Compact) + return value; + else + return TypeId.ToString() + "(" + value + ")"; + } + + public override string ToString() + { + return TypeId.ToString(); + } + + public virtual void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + } + //private static ValueStructure Deserialize(IContext context, XmlReader reader, IDictionary signals, IDictionary buses); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Packages.Helper/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ecabc55 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Package Helper")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("682863fd-7d37-414c-b1ab-3e034cda233f")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Helper/Yttrium.Packages.Helper.csproj b/Backup/src/app/MathNet.Yttrium/Packages.Helper/Yttrium.Packages.Helper.csproj new file mode 100644 index 0000000..939cf2b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Helper/Yttrium.Packages.Helper.csproj @@ -0,0 +1,98 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Library + Properties + MathNet.Symbolics.Packages + MathNet.Yttrium.Packages.Helper + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C} + Yttrium.Manipulation.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..482e984 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Properties/AssemblyInfo.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Standard Package")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2006, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("371f54d3-8f28-4d11-8c7f-a862503c3fab")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Algebra/AutoSimplifyArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Algebra/AutoSimplifyArchitecture.cs new file mode 100644 index 0000000..5041eda --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Algebra/AutoSimplifyArchitecture.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Manipulation; + +namespace MathNet.Symbolics.Packages.Standard.Algebra +{ + /// input 1..n: signals to derive; input n+1: variable; output 1..n: derived signals. + //[EntityImplementation("AutoSimplify", "Std")] + public class AutoSimplifyArchitecture : GenericMathOpArchitecture + { + private static readonly MathIdentifier _entityId = new MathIdentifier("AutoSimplify", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public AutoSimplifyArchitecture() : base(_entityId) { } + public AutoSimplifyArchitecture(Port port) : base(_entityId, port) { } + + public override ISignalSet ExecuteMathematicalOperator() + { + int cnt = Port.OutputSignalCount; + SignalSet ret = new SignalSet(); + for(int i = 0; i < cnt; i++) + ret.Add(Std.AutoSimplify(Port.InputSignals[i])); + return ret; + } + + public override bool SupportsPort(Port port) + { + return port != null && port.IsCompletelyConnected; + } + + public override IArchitecture InstantiateToPort(Port port) + { + return new AutoSimplifyArchitecture(port); + } + + public static void RegisterTheorems(ILibrary library) + { + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(new MathIdentifier("GenericMathOpAutoSimplify", "Std"), + delegate() + { + return new Pattern(new ArchitectureCondition(delegate(IArchitecture a) { return a.IsMathematicalOperator; })); + }, + delegate(Port port) + { + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(hasManipulatedInputs) + port = port.Entity.InstantiatePort(manipulatedInputs); + if(port.HasArchitectureLink && port.CurrentArchitecture.IsMathematicalOperator) + return port.CurrentArchitecture.ExecuteMathematicalOperator(); + else + return port.OutputSignals; + })); + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Algebra/AutoSimplifyTransformation.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Algebra/AutoSimplifyTransformation.cs new file mode 100644 index 0000000..b96583b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Algebra/AutoSimplifyTransformation.cs @@ -0,0 +1,108 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Algebra +{ + public delegate Pattern CreatePattern(); + + public class AutoSimplifyTransformation : ITransformationTheorem + { + private static readonly MathIdentifier _transformationTypeId = new MathIdentifier("AutoSimplify", "Std"); + private static ITransformationTheoremProvider _provider; + + public static ITransformationTheoremProvider Provider + { + get + { + if(_provider == null) + { + ITheoremProvider tp; + if(Service.Instance.TryLookupTheoremType(_transformationTypeId, out tp)) + _provider = (ITransformationTheoremProvider)tp; + else + { + _provider = Binder.GetInstance(_transformationTypeId); + Service.Instance.AddTheoremType(_provider); + } + } + return _provider; + } + } + + private readonly MathIdentifier _id; + private ManipulatePort _simplify; + private EstimatePlan _plan; + private CreatePattern _pattern; + + public AutoSimplifyTransformation(MathIdentifier supportedEntityId, EstimatePlan plan, ManipulatePort simplify) + : this(supportedEntityId.DerivePostfix("AutoSimplify"), delegate() { return new Pattern(new EntityCondition(supportedEntityId)); }, plan, simplify) { } + public AutoSimplifyTransformation(MathIdentifier id, CreatePattern pattern, EstimatePlan plan, ManipulatePort simplify) + { + _id = id; + _pattern = pattern; + _simplify = simplify; + _plan = plan; + } + + public static MathIdentifier TransformationTypeIdentifier + { + get { return _transformationTypeId; } + } + public MathIdentifier TransformationTypeId + { + get { return _transformationTypeId; } + } + public MathIdentifier TheoremId + { + get { return _id; } + } + + public Pattern CreatePattern() + { + return _pattern(); + } + + public ManipulationPlan EstimatePlan(Port port, GroupCollection groups) + { + return _plan(port); + } + + public IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs, GroupCollection groups) + { + return _simplify(port, manipulatedInputs, hasManipulatedInputs); + } + + public Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced) + { + return replacement; + } + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicExpressionCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicExpressionCategory.cs new file mode 100644 index 0000000..f5a960f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicExpressionCategory.cs @@ -0,0 +1,136 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; +using System.Collections.Generic; + +namespace MathNet.Symbolics.Packages.Standard +{ + /// + /// Category of all algebraic expressions. + /// + /// + /// An algebraic expression is constructed using integers, symbols, + /// function forms and the algebraic operators (+,-,*,/,^,!). + /// + public class AlgebraicExpressionCategory : CategoryBase + { + protected AlgebraicExpressionCategory() + : base("AlgebraicExpression", "Std") + { + } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.IsCyclic) + return CategoryMembershipLevel.NotMember; + + CategoryMembershipLevel membership; + if(ignoreCache) + membership = CategoryMembershipLevel.Unknown; + else + if(TryGetCachedMembership(signal, out membership)) + return membership; + + if(signal.BehavesAsSourceSignal) //Symbol (maybe we should apply harder constraints here..) + return CategoryMembershipLevel.Member; + + Port port = signal.DrivenByPort; + if(port.IsCompletelyConnected) + return IsMember(port); + else + return CategoryMembershipLevel.NotMember; + } + + public override CategoryMembershipLevel IsMember(Port port) + { + for(int i = 0; i < port.OutputSignalCount; i++) + if(port.OutputSignals[i].IsCyclic) + return CategoryMembershipLevel.NotMember; + + CategoryMembershipLevel childMembership; + IEntity entity = port.Entity; + + if(port.BusCount != 0) + return CategoryMembershipLevel.NotMember; + + childMembership = EvaluateJointChildMembership(port.InputSignals); + if(childMembership == CategoryMembershipLevel.NotMember) + return CategoryMembershipLevel.NotMember; + + MathIdentifier id = entity.EntityId; + + if(id.Equals("Add", "Std") || id.Equals("Subtract", "Std") || id.Equals("Multiply", "Std") + || id.Equals("Divide", "Std") || id.Equals("Power", "Std") || id.Equals("Factorial", "Std")) + { + if(childMembership == CategoryMembershipLevel.Member) + return CategoryMembershipLevel.Member; + else //CategoryMembershipLevel.Unknown + return CategoryMembershipLevel.Unknown; + } + else + return CategoryMembershipLevel.NotMember; + } + + #region Singleton + private static AlgebraicExpressionCategory _instance; + public static AlgebraicExpressionCategory Instance + { + get + { + if(_instance == null) + _instance = new AlgebraicExpressionCategory(); + return _instance; + } + } + #endregion + + public static bool IsAlgebraicExpressionMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.Member); + } + public static bool IsNotAlgebraicExpressionMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.NotMember); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //protected static AlgebraicExpressionCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static AlgebraicExpressionCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicStructure.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicStructure.cs new file mode 100644 index 0000000..e5bbf16 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicStructure.cs @@ -0,0 +1,175 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +namespace MathNet.Symbolics.Packages.Standard +{ + [Flags, System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames")] + public enum EAlgebraicStructure : int + { + AdditiveClose = 0x0001, + AdditiveAssociative = 0x0002, + AdditiveIdentityElement = 0x0004, + AdditiveInverseElement = 0x0008, + AdditiveCommutative = 0x0010, + MultiplicativeClose = 0x0020, + MultiplicativeAssociative = 0x0040, + MultiplicativeIdentityElement = 0x0080, + MultiplicativeInverseElement = 0x0100, + MultiplicativeCommutative = 0x0200, + DistributiveMultiplicativeOverAdditive = 0x0400, + DistributiveAdditiveOverMultiplicative = 0x0800, + Complement = 0x1000, + + Semigroup = AdditiveClose | AdditiveAssociative, + Monoid = Semigroup | AdditiveIdentityElement, + Group = Monoid | AdditiveInverseElement, + + AbelianSemigroup = Semigroup | AdditiveCommutative, + AbelianMonoid = Monoid | AdditiveCommutative, + AbelianGroup = Group | AdditiveCommutative, + + Ring = AbelianGroup | MultiplicativeClose | MultiplicativeAssociative | DistributiveMultiplicativeOverAdditive, + RingWithUnity = Ring | MultiplicativeIdentityElement, + CommutativeRing = Ring | MultiplicativeCommutative, + CommutativeRingWithUnity = RingWithUnity | MultiplicativeCommutative, + SkewField = RingWithUnity | MultiplicativeInverseElement, //aka Division Algebra + Field = SkewField | MultiplicativeCommutative, + + Semiring = AbelianSemigroup | MultiplicativeClose | MultiplicativeAssociative | DistributiveMultiplicativeOverAdditive, + CommutativeSemiring = Semiring | MultiplicativeCommutative, + + BooleanAlgebra = CommutativeSemiring | AdditiveIdentityElement | MultiplicativeIdentityElement | DistributiveAdditiveOverMultiplicative | Complement + } + + public interface IAlgebraicAdditiveClose + where T : IValueStructure //, IAlgebraicAdditiveClose + { + T Add(T other); + } + public interface IAlgebraicMultiplicativeClose + where T : IValueStructure //, IAlgebraicMultiplicativeClose + { + T Multiply(T other); + T PositiveIntegerPower(int exponent); + } + public interface IAlgebraicAdditiveIdentityElement + { + bool IsAdditiveIdentity { get;} + IValueStructure AdditiveIdentity { get;} + } + public interface IAlgebraicMultiplicativeIdentityElement + { + bool IsMultiplicativeIdentity { get;} + IValueStructure MultiplicativeIdentity { get;} + } + public interface IAlgebraicDivisionExtension + { + TExtension Divide(T other); + TExtension Invert(); + TExtension IntegerPower(int exponent); + } + + public interface IAlgebraicSemigroup : IAlgebraicAdditiveClose + where T : IValueStructure //, IAlgebraicSemigroup + { + } + + public interface IAlgebraicMonoid : IAlgebraicSemigroup, IAlgebraicAdditiveIdentityElement + where T : IValueStructure //, IAlgebraicMonoid + { + } + + public interface IAlgebraicGroup : IAlgebraicMonoid + where T : IValueStructure //, IAlgebraicGroup + { + T Subtract(T other); + T Negate(); + } + + public interface IAlgebraicAbelianGroup : IAlgebraicGroup + where T : IValueStructure //, IAlgebraicAbelianGroup + { + } + + public interface IAlgebraicSemiring : IAlgebraicSemigroup, IAlgebraicMultiplicativeClose + where T : IValueStructure //, IAlgebraicSemiring + { + } + + public interface IAlgebraicRing : IAlgebraicAbelianGroup, IAlgebraicMultiplicativeClose + where T : IValueStructure //, IAlgebraicRing + { + } + + public interface IAlgebraicRingWithUnity : IAlgebraicRing, IAlgebraicMultiplicativeIdentityElement + where T : IValueStructure //, IAlgebraicRingWithUnity + { + } + + public interface IAlgebraicCommutativeRingWithUnity : IAlgebraicRingWithUnity + where T : IValueStructure //, IAlgebraicCommutativeRingWithUnity + { + } + + public interface IAlgebraicSkewField : IAlgebraicRingWithUnity, IAlgebraicIntegralDomain + where T : IValueStructure //, IAlgebraicSkewField + { + //T Divide(T other); + //T Invert(); + } + + public interface IAlgebraicField : IAlgebraicSkewField, IAlgebraicCommutativeRingWithUnity + where T : IValueStructure //, IAlgebraicField + { + } + + public interface IAlgebraicBooleanAlgebra : IAlgebraicSemiring, IAlgebraicAdditiveIdentityElement, IAlgebraicMultiplicativeIdentityElement + where T : IValueStructure //, IAlgebraicBooleanAlgebra + { + T Complement(); + } + + public interface IAlgebraicDomain : IAlgebraicRingWithUnity + where T : IValueStructure //, IAlgebraicDomain + { + + } + + public interface IAlgebraicIntegralDomain : IAlgebraicDomain, IAlgebraicCommutativeRingWithUnity, IAlgebraicDivisionExtension + where T : IValueStructure //, IAlgebraicIntegralDomain + { + + } + + /// + /// A vector space of elements TElement over a field TScalar. + /// + /// Type of the vector elements. + /// Type of the scalars. + public interface IAlgebraicVectorSpace : IAlgebraicAbelianGroup + where TElement : IValueStructure, IAlgebraicAbelianGroup + where TScalar : IValueStructure, IAlgebraicField + { + TElement Scale(TScalar scalar); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicStructureCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicStructureCategory.cs new file mode 100644 index 0000000..ac518b6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/AlgebraicStructureCategory.cs @@ -0,0 +1,172 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard +{ + public class AlgebraicStructureCategory : CategoryBase + { + private readonly IEntity _additiveEntity; + private readonly IEntity _multiplicativeEntity; // = null; + private EAlgebraicStructure _structure; + + public AlgebraicStructureCategory(EAlgebraicStructure structure, IEntity additive, IEntity multiplicative) + : base("AlgebraicStructure" + "_" + additive.EntityId.ToString() + "_" + multiplicative.EntityId.ToString() + "_" + structure.ToString().Replace(',', '-'), "Std") + { + _structure = structure; + _additiveEntity = additive; + _multiplicativeEntity = multiplicative; + } + public AlgebraicStructureCategory(EAlgebraicStructure structure, IEntity additive) + : base("AlgebraicStructure" + "_" + additive.EntityId.ToString() + "__" + structure.ToString().Replace(',', '-'), "Std") + { + _structure = structure; + _additiveEntity = additive; + } + + + public EAlgebraicStructure Structure + { + get { return _structure; } + } + + public IEntity AdditiveEntity + { + get { return _additiveEntity; } + } + + public IEntity MultiplicativeEntity + { + get { return _multiplicativeEntity; } + } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + CategoryMembershipLevel membership; + if(ignoreCache) + membership = CategoryMembershipLevel.Unknown; + else + if(TryGetCachedMembership(signal, out membership)) + return membership; + + if(signal.BehavesAsSourceSignal) + return CategoryMembershipLevel.Unknown; + + Port port = signal.DrivenByPort; + return IsMember(port); + } + + public override CategoryMembershipLevel IsMember(Port port) + { + if(port == null) + throw new ArgumentNullException("port"); + + CategoryMembershipLevel childMembership; + IEntity entity = port.Entity; + + if(port.BusCount != 0) + return CategoryMembershipLevel.NotMember; + + childMembership = EvaluateJointChildMembership(port.InputSignals); + if(childMembership == CategoryMembershipLevel.NotMember) + return CategoryMembershipLevel.NotMember; + + if(entity.EqualsById(_additiveEntity)) + { + if((_structure & EAlgebraicStructure.AdditiveClose) == EAlgebraicStructure.AdditiveClose && childMembership == CategoryMembershipLevel.Member) + return CategoryMembershipLevel.Member; + else //CategoryMembershipLevel.Unknown + return CategoryMembershipLevel.Unknown; + } + else if(entity.EqualsById(_multiplicativeEntity)) + { + if((_structure & EAlgebraicStructure.MultiplicativeClose) == EAlgebraicStructure.MultiplicativeClose && childMembership == CategoryMembershipLevel.Member) + return CategoryMembershipLevel.Member; + else //CategoryMembershipLevel.Unknown + return CategoryMembershipLevel.Unknown; + } + else + return CategoryMembershipLevel.NotMember; + } + + public override bool Equals(CategoryBase other) + { + if(!base.Equals(other)) + return false; + AlgebraicStructureCategory asc = other as AlgebraicStructureCategory; + if(asc == null) + return false; + return _structure.Equals(asc._structure) && _additiveEntity.Equals(asc._additiveEntity) && _multiplicativeEntity.Equals(asc._multiplicativeEntity); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + // writer.WriteElementString("Structure", _structure.ToString()); + // writer.WriteElementString("AdditiveEntity", _additiveEntity.EntityId.ToString()); + // if(_multiplicativeEntity != null) + // writer.WriteElementString("MultiplicativeEntity", _multiplicativeEntity.EntityId.ToString()); + //} + //protected static AlgebraicStructureCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // if(context == null) + // throw new ArgumentNullException("context"); + + // EAlgebraicStructure structure = (EAlgebraicStructure)Enum.Parse(typeof(EAlgebraicStructure), reader.ReadElementString("Structure")); + // IEntity ae = context.Library.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("AdditiveEntity"))); + // if(reader.IsStartElement("MultiplicativeEntity")) + // { + // IEntity me = context.Library.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("MultiplicativeEntity"))); + // return new AlgebraicStructureCategory(structure, ae, me); + // } + // return new AlgebraicStructureCategory(structure, ae); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteElementString("Structure", _structure.ToString()); + writer.WriteElementString("AdditiveEntity", _additiveEntity.EntityId.ToString()); + if(_multiplicativeEntity != null) + writer.WriteElementString("MultiplicativeEntity", _multiplicativeEntity.EntityId.ToString()); + } + private static AlgebraicStructureCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + EAlgebraicStructure structure = (EAlgebraicStructure)Enum.Parse(typeof(EAlgebraicStructure), reader.ReadElementString("Structure")); + IEntity ae = Service.Instance.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("AdditiveEntity"))); + if(reader.IsStartElement("MultiplicativeEntity")) + { + IEntity me = Service.Instance.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("MultiplicativeEntity"))); + return new AlgebraicStructureCategory(structure, ae, me); + } + return new AlgebraicStructureCategory(structure, ae); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Analysis/AlgebraicDerivativeArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Analysis/AlgebraicDerivativeArchitecture.cs new file mode 100644 index 0000000..f86c17f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Analysis/AlgebraicDerivativeArchitecture.cs @@ -0,0 +1,68 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Analysis +{ + /// input 1..n: signals to derive; input n+1: variable; output 1..n: derived signals. + //[EntityImplementation("Derive", "Std")] + public class AlgebraicDerivativeArchitecture : GenericMathOpArchitecture + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Derive", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public AlgebraicDerivativeArchitecture() : base(_entityId) { } + public AlgebraicDerivativeArchitecture(Port port) : base(_entityId, port) { } + + public override ISignalSet ExecuteMathematicalOperator() + { + int cnt = Port.OutputSignalCount; + SignalSet ret = new SignalSet(); + Signal variable = Port.InputSignals[cnt]; + for(int i = 0; i < cnt; i++) + ret.Add(Std.Derive(Port.InputSignals[i], variable)); + return ret; + } + + public override bool SupportsPort(Port port) + { + if(port == null) + throw new ArgumentNullException("port"); + + return port.IsCompletelyConnected; + //return port.BusCount == 0 && port.InputSignalCount == port.OutputSignalCount + 1; + } + + public override IArchitecture InstantiateToPort(Port port) + { + return new AlgebraicDerivativeArchitecture(port); + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Analysis/DerivativeTransformation.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Analysis/DerivativeTransformation.cs new file mode 100644 index 0000000..83987b0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Analysis/DerivativeTransformation.cs @@ -0,0 +1,138 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Manipulation; + +namespace MathNet.Symbolics.Packages.Standard.Analysis +{ + public delegate ManipulationPlan EstimateDerivePlan(Port port, Signal variable); + public delegate IEnumerable Derive(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs); + + public class DerivativeTransformation : ITransformationTheorem + { + private static readonly MathIdentifier _transformationTypeId = new MathIdentifier("Derive", "Std"); + private static ITransformationTheoremProvider _provider; + + public static ITransformationTheoremProvider Provider + { + get + { + if(_provider == null) + { + ITheoremProvider tp; + if(Service.Instance.TryLookupTheoremType(_transformationTypeId, out tp)) + _provider = (ITransformationTheoremProvider)tp; + else + { + _provider = Binder.GetInstance(_transformationTypeId); + Service.Instance.AddTheoremType(_provider); + } + } + return _provider; + } + } + + private readonly MathIdentifier _id; + private MathIdentifier _supportedEntityId; + private Derive _derive; + private EstimateDerivePlan _plan; + private Signal _variable; + + public DerivativeTransformation(MathIdentifier supportedEntityId, Derive derive) + : this(supportedEntityId.DerivePostfix("Derivative"), supportedEntityId, DefaultEstimate, derive) { } + public DerivativeTransformation(MathIdentifier supportedEntityId, EstimateDerivePlan plan, Derive derive) + : this(supportedEntityId.DerivePostfix("Derivative"), supportedEntityId, plan, derive) { } + public DerivativeTransformation(MathIdentifier id, MathIdentifier supportedEntityId, EstimateDerivePlan plan, Derive derive) + { + _id = id; + _supportedEntityId = supportedEntityId; + _derive = derive; + _plan = plan; + } + + public Signal Variable + { + get { return _variable; } + set { _variable = value; } + } + + public static MathIdentifier TransformationTypeIdentifier + { + get { return _transformationTypeId; } + } + public MathIdentifier TransformationTypeId + { + get { return _transformationTypeId; } + } + public MathIdentifier TheoremId + { + get { return _id; } + } + + public Pattern CreatePattern() + { + return new Pattern(new EntityCondition(_supportedEntityId)); + } + + public ManipulationPlan EstimatePlan(Port port, GroupCollection groups) + { + return _plan(port, _variable); + } + + public IEnumerable ManipulatePort(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs, GroupCollection groups) + { + return _derive(port, manipulatedInputs, _variable, hasManipulatedInputs); + } + + private static ManipulationPlan DefaultEstimate(Port port, Signal variable) + { + return ManipulationPlan.DoAlter; + } + + public Signal ManipulateSignal(Signal original, Signal replacement, bool isReplaced) + { + if(original == null) + throw new ArgumentNullException("original"); + + if(!isReplaced) + { + if(_variable.Equals(original)) + return IntegerValue.ConstantOne; + if(original.IsSourceSignal) + return IntegerValue.ConstantZero; + if(original.Hold) + { + Port p = Service.Instance.LookupEntity(new MathIdentifier("Derive", "Std")).InstantiatePort(original, _variable); + return p.OutputSignals[0]; + } + } + return replacement; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/AbsoluteArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/AbsoluteArchitectures.cs new file mode 100644 index 0000000..1c5562c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/AbsoluteArchitectures.cs @@ -0,0 +1,65 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class AbsoluteArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Absolute", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public AbsoluteArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(IntegerValue value) { return value.Absolute(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RationalValue value) { return value.Absolute(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Absolute(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(ComplexValue.Absolute, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/Accumulator.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/Accumulator.cs new file mode 100644 index 0000000..0be9dbe --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/Accumulator.cs @@ -0,0 +1,208 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Packages.Standard.Structures; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + internal interface IAccumulator + { + IValueStructure Value { get; } + IAccumulator Add(IValueStructure operand); + IAccumulator Subtract(IValueStructure operand); + IAccumulator Multiply(IValueStructure operand); + IAccumulator Divide(IValueStructure operand); + IAccumulator Negate(); + IAccumulator Invert(); + IAccumulator IntegerPower(int exponent); + IAccumulator IntegerPower(IValueStructure exponent); + } + + internal class Accumulator : + IAccumulator + where T : IAlgebraicIntegralDomain, IValueStructure //IAlgebraicCommutativeRingWithUnity + where TDivision : IAlgebraicIntegralDomain, IValueStructure + { + private T _value; + + public Accumulator(T value) + { + _value = value; + } + + public IValueStructure Value + { + get { return _value; } + } + + public IAccumulator Add(IValueStructure operand) + { + object other; + if(ValueConverter.TryConvertLosslessFrom(operand, out other)) + { + _value = _value.Add((T)other); + return this; + } + else + { + IAccumulator acc = Escalate(operand.TypeId, _value, false); + return acc.Add(operand); + } + } + + public IAccumulator Subtract(IValueStructure operand) + { + object other; + if(ValueConverter.TryConvertLosslessFrom(operand, out other)) + { + _value = _value.Subtract((T)other); + return this; + } + else + { + IAccumulator acc = Escalate(operand.TypeId, _value, false); + return acc.Subtract(operand); + } + } + + public IAccumulator Negate() + { + _value = _value.Negate(); + return this; + } + + public IAccumulator Multiply(IValueStructure operand) + { + object other; + if(ValueConverter.TryConvertLosslessFrom(operand, out other)) + { + _value = _value.Multiply((T)other); + return this; + } + else + { + IAccumulator acc = Escalate(operand.TypeId, _value, false); + return acc.Multiply(operand); + } + } + + public IAccumulator Divide(IValueStructure operand) + { + object other; + if(ValueConverter.TryConvertLosslessFrom(operand, out other)) + { + TDivision res = _value.Divide((T)other); + if(_value is IAlgebraicDivisionExtension) + { + _value = (T)(object)res; + return this; + } + return Escalate(res); + } + else + { + IAccumulator acc = Escalate(operand.TypeId, _value, true); + return acc.Divide(operand); + } + } + + public IAccumulator Invert() + { + TDivision res = _value.Invert(); + if(_value is IAlgebraicDivisionExtension) + { + _value = (T)(object)res; + return this; + } + return Escalate(res); + } + + public IAccumulator IntegerPower(int exponent) + { + if(exponent >= 0) + { + _value = _value.PositiveIntegerPower(exponent); + return this; + } + TDivision res = _value.IntegerPower(exponent); + if(_value is IAlgebraicDivisionExtension) + { + _value = (T)(object)res; + return this; + } + return Escalate(res); + } + + public IAccumulator IntegerPower(IValueStructure operand) + { + object other; + if(ValueConverter.TryConvertLosslessFrom(operand, out other)) + return IntegerPower((int)((IntegerValue)other).Value); + if(ValueConverter.TryConvertLosslessFrom(operand, out other)) + { + RationalValue rv = (RationalValue)other; + if(rv.IsInteger) + return IntegerPower((int)rv.NumeratorValue); + } + throw new NotSupportedException(); + } + + private static IAccumulator Escalate(MathIdentifier structure, IValueStructure value, bool requireField) + { + if(structure.Equals(IntegerValue.TypeIdentifier)) + { + if(requireField) + return Escalate(value); + else + return Escalate(value); + } + if(structure.Equals(RationalValue.TypeIdentifier)) + return Escalate(value); + if(structure.Equals(RealValue.TypeIdentifier)) + return Escalate(value); + if(structure.Equals(ComplexValue.TypeIdentifier)) + return Escalate(value); + + throw new NotSupportedException(); + } + + private static IAccumulator Escalate(IValueStructure value) + where TStructure : IAlgebraicIntegralDomain, IValueStructure + where TStructureDivision : IAlgebraicIntegralDomain, IValueStructure + { + object val; + if(ValueConverter.TryConvertLosslessFrom(value, out val)) + return new Accumulator((TStructure)val); + else + throw new NotSupportedException(); + } + + public static IAccumulator Create(IValueStructure value) + { + return Escalate(value.TypeId, value, false); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/AdditionArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/AdditionArchitectures.cs new file mode 100644 index 0000000..06fe641 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/AdditionArchitectures.cs @@ -0,0 +1,192 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + // TODO: Finally upgrade to the new generic design (maybe add to the documentation...) + public class AdditionArchitectures : IArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Add", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public AdditionArchitectures() + { + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public bool SupportsPort(Port port) + { + if(port == null || !port.Entity.EqualsById(_entityId)) + return false; + + if(IntegerValueCategory.IsIntegerValueMember(port)) + return true; + + if(RationalValueCategory.IsRationalValueMember(port)) + return true; + + if(RealValueCategory.IsRealValueMember(port)) + return true; + + if(ComplexValueCategory.IsComplexValueMember(port)) + return true; + + if(IsVector(port)) //DUMMY + return true; + + return false; + } + + private static bool IsVector(Port port) + { + return false; //DUMMY + } + + public IArchitecture InstantiateToPort(Port port) + { + if(IntegerValueCategory.IsIntegerValueMember(port)) + return new GenericArchitecture(EntityId.DerivePrefix("Integer"), EntityId, false, port, IntegerValueCategory.IsIntegerValueMember, 0, new ProcessBase[] { new IntegerValue.AddProcess(0, port.InputSignalCount - 1, 0) }); + + if(RationalValueCategory.IsRationalValueMember(port)) + return new GenericArchitecture(EntityId.DerivePrefix("Rational"), EntityId, false, port, RationalValueCategory.IsRationalValueMember, 0, new ProcessBase[] { new RationalValue.AddProcess(0, port.InputSignalCount - 1, 0) }); + + if(RealValueCategory.IsRealValueMember(port)) + return new GenericArchitecture(EntityId.DerivePrefix("Real"), EntityId, false, port, RealValueCategory.IsRealValueMember, 0, new ProcessBase[] { new RealValue.AddProcess(0, port.InputSignalCount - 1, 0) }); + + if(ComplexValueCategory.IsComplexValueMember(port)) + return new GenericArchitecture(EntityId.DerivePrefix("Complex"), EntityId, false, port, RealValueCategory.IsRealValueMember, 0, new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return ComplexValue.Zero; }, ComplexValue.ConvertFrom, ComplexValue.Add, port.InputSignalCount) }); + + if(IsVector(port)) + return new GenericArchitecture(EntityId.DerivePrefix("Vector"), EntityId, false, port, IsVector, 0, new ProcessBase[] { }); //DUMMY + + throw new MathNet.Symbolics.Exceptions.ArchitectureNotAvailableException(port); + } + + public static bool CollectSummands(ISignalSet signals) + { + bool changed = false; + for(int i = 0; i < signals.Count; i++) + { + Signal s = signals[i]; + if(!s.BehavesAsBeingDriven(false)) + continue; + + Port p = s.DrivenByPort; + if(p.Entity.EntityId.Equals(AdditionArchitectures.EntityIdentifier)) + { + signals.RemoveAt(i); + ISignalSet inputs = p.InputSignals; + for(int j = 0; j < inputs.Count; j++) + signals.Insert(i + j, inputs[j]); + i--; + changed = true; + continue; + } + + if(p.Entity.EntityId.Equals(SubtractionArchitectures.EntityIdentifier)) + { + ISignalSet inputs = p.InputSignals; + signals[i] = inputs[0]; + i--; + for(int j = 1; j < inputs.Count; j++) + signals.Insert(i + j, Std.Negate(inputs[j])); + changed = true; + continue; + } + } + return changed; + } + + public static bool SimplifySummands(ISignalSet signals) + { + bool changed = CollectSummands(signals); + if(signals.Count < 2) + return changed; + IAccumulator acc = null; + for(int i = signals.Count - 1; i >= 0; i--) + { + Signal s = signals[i]; + if(Std.IsConstantComplex(s)) + { + if(acc == null) + acc = Accumulator.Create(IntegerValue.AdditiveIdentity); + signals.RemoveAt(i); + changed = true; + acc = acc.Add(s.Value); + } + } + if(acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity)) + { + signals.Insert(0, Std.DefineConstant(acc.Value)); + } + return changed; + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + return new SignalSet(Std.Add(manipulatedInputs)); + })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + // TODO + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(SimplifySummands(manipulatedInputs) || hasManipulatedInputs) + { + if(manipulatedInputs.Count == 0) + return new SignalSet(IntegerValue.ConstantAdditiveIdentity); + if(manipulatedInputs.Count == 1) + return manipulatedInputs; + return new SignalSet(StdBuilder.Add(manipulatedInputs)); + } + else + return port.OutputSignals; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/DivisionArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/DivisionArchitectures.cs new file mode 100644 index 0000000..799fdfd --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/DivisionArchitectures.cs @@ -0,0 +1,203 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class DivisionArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Divide", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public DivisionArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new IntegerValue.DivideProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new RationalValue.DivideProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new RealValue.DivideProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return ComplexValue.One; }, ComplexValue.ConvertFrom, ComplexValue.Divide, port.InputSignalCount) }; }); + } + + public static bool CollectFactors(ISignalSet signals) + { + bool changed = false; + for(int i = 0; i < signals.Count; i++) + { + Signal s = signals[i]; + if(!s.BehavesAsBeingDriven(false)) + continue; + + Port p = s.DrivenByPort; + if(p.Entity.EntityId.Equals(MultiplicationArchitectures.EntityIdentifier)) + { + signals.RemoveAt(i); + ISignalSet inputs = p.InputSignals; + for(int j = 0; j < inputs.Count; j++) + signals.Insert(i + j, (i == 0 && j != 0) ? Std.Invert(inputs[j]) : inputs[j]); + i--; + changed = true; + continue; + } + + if(p.Entity.EntityId.Equals(DivisionArchitectures.EntityIdentifier)) + { + ISignalSet inputs = p.InputSignals; + signals[i] = inputs[0]; + i--; + for(int j = 1; j < inputs.Count; j++) + signals.Insert(i + j, (i == 0) ? inputs[j] : Std.Invert(inputs[j])); + changed = true; + continue; + } + } + return changed; + } + + public static bool SimplifyFactorsForceMultiplication(ISignalSet signals) + { + bool changed = CollectFactors(signals); + if(signals.Count < 2) + return changed; + + for(int i = 1; i < signals.Count; i++) + signals[i] = Std.Invert(signals[i]); + Signal product = Std.Multiply(signals); + + signals.Clear(); + signals.Add(product); + return true; + } + + public static bool SimplifyFactors(ISignalSet signals) + { + bool changed = CollectFactors(signals); + if(signals.Count < 2) + return changed; + IAccumulator acc = null; + for(int i = signals.Count - 1; i > 0; i--) //don't touch first item! + { + Signal s = signals[i]; + if(Std.IsConstantComplex(s)) + { + if(acc == null) + acc = Accumulator.Create(IntegerValue.MultiplicativeIdentity); + signals.RemoveAt(i); + changed = true; + + if(Std.IsConstantAdditiveIdentity(s)) + { + signals.Clear(); + signals.Add(UndefinedSymbol.Constant); + return true; + } + acc = acc.Multiply(s.Value); + } + } + if(acc != null && !acc.Value.Equals(IntegerValue.MultiplicativeIdentity)) + { + Signal first = signals[0]; + if(Std.IsConstantComplex(first)) + { + acc = acc.Divide(first.Value).Invert(); + signals[0] = Std.DefineConstant(acc.Value); + changed = true; + } + else + { + signals.Insert(1, Std.DefineConstant(acc.Value)); + } + } + return changed; + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + int cnt = manipulatedInputs.Count - 1; + + Signal[] multiplySignals = new Signal[cnt]; + Signal[] addSignals = new Signal[cnt]; + + for(int i = 0; i < cnt; i++) + multiplySignals[i] = port.InputSignals[i + 1]; + Signal left = Std.Divide(manipulatedInputs[0], multiplySignals); + + for(int i = 0; i < cnt; i++) + { + for(int j = 0; j < cnt; j++) + multiplySignals[j] = i == j ? StdBuilder.Square(port.InputSignals[j + 1]) : port.InputSignals[j + 1]; + Signal num = port.InputSignals[0] * manipulatedInputs[i + 1]; + addSignals[i] = Std.Divide(num, multiplySignals); + } + + return new SignalSet(Std.Subtract(left, addSignals)); + })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + // TODO + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(SimplifyFactorsForceMultiplication(manipulatedInputs) || hasManipulatedInputs) + { + if(manipulatedInputs.Count == 0) + return new SignalSet(IntegerValue.ConstantMultiplicativeIdentity); + if(manipulatedInputs.Count == 1) + return manipulatedInputs; + return new SignalSet(StdBuilder.Divide(manipulatedInputs)); + } + else + return port.OutputSignals; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/ExponentialArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/ExponentialArchitectures.cs new file mode 100644 index 0000000..84b98d7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/ExponentialArchitectures.cs @@ -0,0 +1,67 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class ExponentialArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Exponential", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public ExponentialArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Exponential(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(ComplexValue.Exponential, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + SignalSet outputs = new SignalSet(); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add(manipulatedInputs[i] * port.OutputSignals[i]); + return outputs; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/InvertArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/InvertArchitectures.cs new file mode 100644 index 0000000..1fa967a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/InvertArchitectures.cs @@ -0,0 +1,76 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class InvertArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Invert", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public InvertArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(IntegerValue value) { return value.Invert(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RationalValue value) { return value.Invert(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Invert(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(ComplexValue.Invert, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + SignalSet outputs = new SignalSet(); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add(-(manipulatedInputs[i] / StdBuilder.Square(port.InputSignals[i]))); + return outputs; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/MultiplicationArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/MultiplicationArchitectures.cs new file mode 100644 index 0000000..6130818 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/MultiplicationArchitectures.cs @@ -0,0 +1,169 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class MultiplicationArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Multiply", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public MultiplicationArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new IntegerValue.MultiplyProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new RationalValue.MultiplyProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new RealValue.MultiplyProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return ComplexValue.One; }, ComplexValue.ConvertFrom, ComplexValue.Multiply, port.InputSignalCount) }; }); + } + + public static bool CollectFactors(ISignalSet signals) + { + bool changed = false; + for(int i = 0; i < signals.Count; i++) + { + Signal s = signals[i]; + if(!s.BehavesAsBeingDriven(false)) + continue; + + Port p = s.DrivenByPort; + if(p.Entity.EntityId.Equals(MultiplicationArchitectures.EntityIdentifier)) + { + signals.RemoveAt(i); + ISignalSet inputs = p.InputSignals; + for(int j = 0; j < inputs.Count; j++) + signals.Insert(i + j, inputs[j]); + i--; + changed = true; + continue; + } + + if(p.Entity.EntityId.Equals(DivisionArchitectures.EntityIdentifier)) + { + ISignalSet inputs = p.InputSignals; + signals[i] = inputs[0]; + i--; + for(int j = 1; j < inputs.Count; j++) + signals.Insert(i + j, Std.Invert(inputs[j])); + changed = true; + continue; + } + } + return changed; + } + + public static bool SimplifyFactors(ISignalSet signals) + { + bool changed = CollectFactors(signals); + if(signals.Count < 2) + return changed; + IAccumulator acc = null; + for(int i = signals.Count - 1; i >= 0; i--) + { + Signal s = signals[i]; + if(Std.IsConstantComplex(s)) + { + if(Std.IsAdditiveIdentity(s)) + { + signals.Clear(); + signals.Add(s); + return true; + } + if(acc == null) + acc = Accumulator.Create(IntegerValue.MultiplicativeIdentity); + signals.RemoveAt(i); + changed = true; + acc = acc.Multiply(s.Value); + } + } + if(acc != null && !acc.Value.Equals(IntegerValue.MultiplicativeIdentity)) + { + signals.Insert(0, Std.DefineConstant(acc.Value)); + } + return changed; + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + int cnt = manipulatedInputs.Count; + Signal[] addSignals = new Signal[cnt]; + Signal[] multiplySignals = new Signal[cnt]; + for(int i = 0; i < cnt; i++) + { + for(int j = 0; j < cnt; j++) + multiplySignals[j] = i == j ? manipulatedInputs[j] : port.InputSignals[j]; + addSignals[i] = Std.Multiply(multiplySignals); + } + return new SignalSet(Std.Add(addSignals)); + })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + // TODO + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(SimplifyFactors(manipulatedInputs) || hasManipulatedInputs) + { + if(manipulatedInputs.Count == 0) + return new SignalSet(IntegerValue.ConstantMultiplicativeIdentity); + if(manipulatedInputs.Count == 1) + return manipulatedInputs; + return new SignalSet(StdBuilder.Multiply(manipulatedInputs)); + } + else + return port.OutputSignals; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/NaturalLogarithmArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/NaturalLogarithmArchitectures.cs new file mode 100644 index 0000000..7057ea2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/NaturalLogarithmArchitectures.cs @@ -0,0 +1,67 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class NaturalLogarithmArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("NaturalLogarithm", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public NaturalLogarithmArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.NaturalLogarithm(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(ComplexValue.NaturalLogarithm, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + SignalSet outputs = new SignalSet(); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add(manipulatedInputs[i] / port.InputSignals[i]); + return outputs; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/NegateArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/NegateArchitectures.cs new file mode 100644 index 0000000..6ce4ceb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/NegateArchitectures.cs @@ -0,0 +1,96 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class NegateArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Negate", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public NegateArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(IntegerValue value) { return value.Negate(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RationalValue value) { return value.Negate(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Negate(); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(ComplexValue.Negate, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + return StdBuilder.Negate(manipulatedInputs); + })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + // TODO + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(manipulatedInputs.Count == 0) + return new SignalSet(IntegerValue.ConstantAdditiveIdentity); + if(manipulatedInputs.Count == 1) + { + Signal s = manipulatedInputs[0]; + if(Std.IsConstantAdditiveIdentity(s)) + return new SignalSet(s); + return new SignalSet(Std.Negate(s)); + } + if(hasManipulatedInputs) + return new SignalSet(StdBuilder.Negate(manipulatedInputs)); + return port.OutputSignals; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/PowerArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/PowerArchitectures.cs new file mode 100644 index 0000000..db7edd7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/PowerArchitectures.cs @@ -0,0 +1,205 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class PowerArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Power", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public PowerArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return IntegerValue.One; }, IntegerValue.ConvertFrom, delegate(IntegerValue acc, IntegerValue item) { return acc.Power(item); }, port.InputSignalCount) }; }); + + AddArchitecture(new MathIdentifier("RationalPowerIntegerRadix", "Std"), + delegate(Port port) { return RationalValue.CanConvertLosslessFrom(port.InputSignals[0].Value) && IntegerValue.CanConvertLosslessFrom(port.InputSignals[1].Value); }, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return IntegerValue.One; }, RationalValue.ConvertFrom, delegate(RationalValue acc, RationalValue item) { return acc.Power(item.Numerator); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return IntegerValue.One; }, RealValue.ConvertFrom, delegate(RealValue acc, RealValue item) { return acc.Power(item); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return ComplexValue.One; }, ComplexValue.ConvertFrom, ComplexValue.Power, port.InputSignalCount) }; }); + } + + public static bool CollectOperands(ISignalSet signals) + { + bool changed = false; + while(signals.Count > 0 && signals[0].IsDrivenByPortEntity(PowerArchitectures.EntityIdentifier)) + { + } + return changed; + } + + public static bool SimplifyOperands(ISignalSet signals) + { + if(signals.Count < 2) + return false; + + bool changed = false; + Signal radix = signals[0]; + + if(Std.IsConstantAdditiveIdentity(radix) && Std.IsConstant(signals[1])) + { + if(Std.IsAlwaysNegative(signals[1])) + { + signals.Clear(); + signals.Add(UndefinedSymbol.Constant); + return true; + } + signals.Clear(); + signals.Add(radix); + return true; + } + if(Std.IsConstantMultiplicativeIdentity(radix)) + { + signals.Clear(); + signals.Add(radix); + return true; + } + + // Evaluate all but the first two operands -> nonnegative integers + IntegerValue value = null; + for(int i = signals.Count - 1; i > 1; i--) + { + Signal s = signals[i]; + if(!Std.IsConstantNonnegativeInteger(s)) + { + if(changed) + { + if(!value.IsMultiplicativeIdentity) + signals.Add(Std.DefineConstant(value)); + return true; + } + return false; + } + signals.RemoveAt(i); + value = ValueConverter.ConvertFrom(s.Value).PositiveIntegerPower((int)value.Value); + changed = true; + } + + // Evaluate the second operand -> integer (can also be negative) + Signal exponent = signals[1]; + if(!Std.IsConstantInteger(exponent)) + { + if(changed) + { + if(!value.IsMultiplicativeIdentity) + signals.Add(Std.DefineConstant(value)); + return true; + } + return false; + } + IntegerValue exponentValue = ValueConverter.ConvertFrom(exponent.Value); + if(changed) + exponentValue = exponentValue.PositiveIntegerPower((int)value.Value); + + // Special case: first operand is a power + if(radix.IsDrivenByPortEntity(PowerArchitectures.EntityIdentifier) + && radix.DrivenByPort.InputSignalCount == 2 + && Std.IsConstantInteger(radix.DrivenByPort.InputSignals[1])) + { + exponentValue = exponentValue.Multiply(ValueConverter.ConvertFrom(radix.DrivenByPort.InputSignals[1].Value)); + signals[0] = radix = radix.DrivenByPort.InputSignals[0]; + changed = true; + } + + // Evaluate the first operand + if(!Std.IsConstantComplex(radix)) + { + if(changed) + { + if(!exponentValue.IsMultiplicativeIdentity) + signals[1] = Std.DefineConstant(exponentValue); + else + signals.RemoveAt(1); + return true; + } + return false; + } + IAccumulator acc = Accumulator.Create(radix.Value); + acc = acc.IntegerPower((int)exponentValue.Value); + + signals.Clear(); + signals.Add(Std.DefineConstant(acc.Value)); + return true; + } + + public static void RegisterTheorems(ILibrary library) + { + //Analysis.DerivativeTransformation.Provider.Add( + // new Analysis.DerivativeTransformation(_entityId, + // delegate(Port port, Signal[] derivedInputSignals) + // { + // Signal innerA = derivedInputSignals[1] * StdBuilder.NaturalLogarithm(port.InputSignals[0]); + // Signal innerB = (port.InputSignals[1] * derivedInputSignals[0]) / port.InputSignals[0]; + // return port.OutputSignals[0] * (innerA + innerB); + // })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + // TODO + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(SimplifyOperands(manipulatedInputs) || hasManipulatedInputs) + { + if(manipulatedInputs.Count == 0) + return new SignalSet(IntegerValue.ConstantMultiplicativeIdentity); + if(manipulatedInputs.Count == 1) + return manipulatedInputs; + if(Std.IsConstantMultiplicativeIdentity(manipulatedInputs[0])) + return new SignalSet(manipulatedInputs[0]); + if(Std.IsConstantMultiplicativeIdentity(manipulatedInputs[1])) + return new SignalSet(manipulatedInputs[0]); + if(Std.IsConstantAdditiveIdentity(manipulatedInputs[1])) + return new SignalSet(IntegerValue.ConstantOne); + return new SignalSet(StdBuilder.Power(manipulatedInputs)); + } + else + return port.OutputSignals; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SelfBuildingExample.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SelfBuildingExample.cs new file mode 100644 index 0000000..7fc0759 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SelfBuildingExample.cs @@ -0,0 +1,60 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + //TODO: remove this dummy (maybe add to documentation instead...) + //[EntityImplementation("Example", "Std")] + public class SelfBuildingExample : ArchitectureBase, IArchitectureFactory + { + public SelfBuildingExample() : base(new MathIdentifier("Example", "Std"), new MathIdentifier("Example", "Std"), false) { } + private SelfBuildingExample(Port port) + : base(new MathIdentifier("Example", "Std"), new MathIdentifier("Example", "Std"), false) + { + SetPort(port); + // init processes here, or whatever you want to do ... + } + + public override bool SupportsPort(Port port) + { + return false; + } + + public IArchitecture InstantiateToPort(Port port) + { + return new SelfBuildingExample(port); + } + + public override void UnregisterArchitecture() + { + // remove here your signal event handlers ... + } + + protected override void ReregisterArchitecture(Port oldPort, Port newPort) + { + // add here your signal event handlers again ... + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SquareArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SquareArchitectures.cs new file mode 100644 index 0000000..7fd06de --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SquareArchitectures.cs @@ -0,0 +1,76 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class SquareArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Square", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public SquareArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(IntegerValue value) { return value.Multiply(value); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RationalValue value) { return value.Multiply(value); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Multiply(value); }, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(ComplexValue.Square, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + Signal two = IntegerValue.ConstantTwo; + SignalSet outputs = new SignalSet(); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add(Std.Multiply(two, port.InputSignals[i], manipulatedInputs[i])); + return outputs; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SubtractionArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SubtractionArchitectures.cs new file mode 100644 index 0000000..43159fb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Arithmetics/SubtractionArchitectures.cs @@ -0,0 +1,179 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard.Arithmetics +{ + public class SubtractionArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Subtract", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public SubtractionArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Integer"), + IntegerValueCategory.IsIntegerValueMember, + delegate(Port port) { return new ProcessBase[] { new IntegerValue.SubtractProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Rational"), + RationalValueCategory.IsRationalValueMember, + delegate(Port port) { return new ProcessBase[] { new RationalValue.SubtractProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new RealValue.SubtractProcess(0, port.InputSignalCount - 1, 0) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdFunctionProcess(delegate() { return ComplexValue.Zero; }, ComplexValue.ConvertFrom, ComplexValue.Subtract, port.InputSignalCount) }; }); + } + + public static bool CollectSummands(ISignalSet signals) + { + bool changed = false; + for(int i = 0; i < signals.Count; i++) + { + Signal s = signals[i]; + if(!s.BehavesAsBeingDriven(false)) + continue; + + Port p = s.DrivenByPort; + if(p.Entity.EntityId.Equals(AdditionArchitectures.EntityIdentifier)) + { + signals.RemoveAt(i); + ISignalSet inputs = p.InputSignals; + for(int j = 0; j < inputs.Count; j++) + signals.Insert(i + j, (i == 0 && j != 0) ? Std.Negate(inputs[j]) : inputs[j]); + i--; + changed = true; + continue; + } + + if(p.Entity.EntityId.Equals(SubtractionArchitectures.EntityIdentifier)) + { + ISignalSet inputs = p.InputSignals; + signals[i] = inputs[0]; + i--; + for(int j = 1; j < inputs.Count; j++) + signals.Insert(i + j, (i == 0) ? inputs[j] : Std.Negate(inputs[j])); + changed = true; + continue; + } + } + return changed; + } + + public static bool SimplifySummandsForceAddition(ISignalSet signals) + { + bool changed = CollectSummands(signals); + if(signals.Count < 2) + return changed; + + for(int i = 1; i < signals.Count; i++) + signals[i] = Std.Negate(signals[i]); + Signal sum = Std.Add(signals); + + signals.Clear(); + signals.Add(sum); + return true; + } + + public static bool SimplifySummands(ISignalSet signals) + { + bool changed = CollectSummands(signals); + if(signals.Count < 2) + return changed; + IAccumulator acc = null; + for(int i = signals.Count - 1; i > 0; i--) //don't touch first item! + { + Signal s = signals[i]; + if(Std.IsConstantComplex(s)) + { + if(acc == null) + acc = Accumulator.Create(IntegerValue.AdditiveIdentity); + signals.RemoveAt(i); + changed = true; + acc = acc.Add(s.Value); + } + } + if(acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity)) + { + Signal first = signals[0]; + if(Std.IsConstantComplex(first)) + { + acc = acc.Subtract(first.Value).Negate(); + signals[0] = Std.DefineConstant(acc.Value); + changed = true; + } + else + { + signals.Insert(1, Std.DefineConstant(acc.Value)); + } + } + return changed; + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + return new SignalSet(Std.Subtract(manipulatedInputs)); + })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + // TODO + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + if(SimplifySummandsForceAddition(manipulatedInputs) || hasManipulatedInputs) + { + if(manipulatedInputs.Count == 0) + return new SignalSet(IntegerValue.ConstantAdditiveIdentity); + if(manipulatedInputs.Count == 1) + return manipulatedInputs; + return new SignalSet(StdBuilder.Subtract(manipulatedInputs)); + } + else + return port.OutputSignals; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/ClockArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/ClockArchitecture.cs new file mode 100644 index 0000000..d6688cb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/ClockArchitecture.cs @@ -0,0 +1,102 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Flow +{ + //[EntityImplementation("Clock", "Std")] + public class ClockArchitecture : GenericSimpleArchitecture + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Clock", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + private TimeSpan[] periods; + + public ClockArchitecture() : base(_entityId, false) { } + public ClockArchitecture(Port port) : base(_entityId, false, port, 0) { } + + protected override void SenseSignals(IList inputSignals, IList internalSignals, IList buses, IList outputSignals) + { + periods = new TimeSpan[inputSignals.Count]; + for(int i = 0; i < periods.Length; i++) + { + SenseSignal(inputSignals[i]); + SenseSignal(outputSignals[i]); + if(UpdatePeriods(i,inputSignals[i])) + PostDelayedClock(i,outputSignals[i]); + } + } + + /// true if an event shall be posted. + private bool UpdatePeriods(int index, Signal inputSignal) + { + if(RealValue.CanConvertLosslessFrom(inputSignal.Value)) + { + periods[index] = TimeSpan.FromSeconds(1.0 / RealValue.ConvertFrom(inputSignal.Value).Value); + return true; + } + else + { + periods[index] = TimeSpan.Zero; + return false; + } + } + + private void PostDelayedClock(int index, Signal outputSignal) + { + TimeSpan p = periods[index]; + if(p.Equals(TimeSpan.Zero)) + return; + ToggleValue tv = outputSignal.Value as ToggleValue; + if(tv == null) + tv = ToggleValue.InitialToggle; + outputSignal.PostNewValue(tv.Toggle(), p); + } + + protected override void Action(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + { + int cnt = inputSignals.Count; + for(int i = 0; i < cnt; i++) + if(inputSignals[i].HasEvent && UpdatePeriods(i, inputSignals[i]) || outputSignals[i].HasEvent) + PostDelayedClock(i, outputSignals[i]); + } + + public override bool SupportsPort(Port port) + { + return port.BusCount == 0 && port.InputSignalCount == port.OutputSignalCount + && port.InputSignals.TrueForAll(Std.IsAlwaysReal); + } + + public override IArchitecture InstantiateToPort(Port port) + { + return new ClockArchitecture(port); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/SyncArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/SyncArchitecture.cs new file mode 100644 index 0000000..12fdf7b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/SyncArchitecture.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Flow +{ + /// + /// Clocked Register, the clock is the last input signal. + /// + //[EntityImplementation("Sync", "Std")] + public class SyncArchitecture : ArchitectureBase, IArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Sync", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public SyncArchitecture() : base(_entityId, _entityId, false) { } + public SyncArchitecture(Port port) + : base(_entityId, _entityId, false) + { + //System.Diagnostics.Debug.Assert(SupportsPort(port)); + SetPort(port); + + port.InputSignals[port.InputSignalCount-1].ValueChanged += SyncArchitecture_SignalValueChanged; + } + + void SyncArchitecture_SignalValueChanged(object sender, EventArgs e) + { + for(int i = 0; i < Port.OutputSignals.Count; i++) + Port.OutputSignals[i].PostNewValue(Port.InputSignals[i].Value); + } + + public override bool SupportsPort(Port port) + { + if(port == null) + throw new ArgumentNullException("port"); + + return port.BusCount == 0 && port.InputSignalCount == port.OutputSignalCount+1; + } + + public override void UnregisterArchitecture() + { + Port.InputSignals[Port.InputSignalCount - 1].ValueChanged -= SyncArchitecture_SignalValueChanged; + } + + protected override void ReregisterArchitecture(Port oldPort, Port newPort) + { + newPort.InputSignals[newPort.InputSignalCount - 1].ValueChanged += SyncArchitecture_SignalValueChanged; + } + + public IArchitecture InstantiateToPort(Port port) + { + return new SyncArchitecture(port); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/SystemPipeline.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/SystemPipeline.cs new file mode 100644 index 0000000..2d1b443 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/SystemPipeline.cs @@ -0,0 +1,31 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.Standard.Flow +{ + public class SystemPipeline + { + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/TransportArchitecture.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/TransportArchitecture.cs new file mode 100644 index 0000000..0c4ad61 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Flow/TransportArchitecture.cs @@ -0,0 +1,93 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Flow +{ + //[EntityImplementation("Transport", "Std")] + public class TransportArchitecture : GenericSimpleArchitecture + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Transport", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public TransportArchitecture() : base(_entityId, false) { } + public TransportArchitecture(Port port) : base(_entityId, false, port, 0) { } + + protected override void SenseSignals(IList inputSignals, IList internalSignals, IList buses, IList outputSignals) + { + for(int i = 0; i < inputSignals.Count; i++) + SenseSignal(inputSignals[i]); + } + + protected override void Action(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + { + for(int i = 0; i < inputSignals.Count; i++) + if(inputSignals[i].HasEvent) + outputSignals[i].PostNewValue(inputSignals[i].Value); + } + + public override bool SupportsPort(Port port) + { + if(port == null) + throw new ArgumentNullException("port"); + + return port.BusCount == 0 && port.InputSignalCount == port.OutputSignalCount; + } + + public override IArchitecture InstantiateToPort(Port port) + { + return new TransportArchitecture(port); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + return new SignalSet(manipulatedInputs); + })); + + Algebra.AutoSimplifyTransformation.Provider.Add( + new Algebra.AutoSimplifyTransformation(_entityId, + delegate(Port port) + { + return ManipulationPlan.DoAlter; + }, + delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) + { + return new SignalSet(manipulatedInputs); + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/GeneralizedPolynomial.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/GeneralizedPolynomial.cs new file mode 100644 index 0000000..77e6b33 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/GeneralizedPolynomial.cs @@ -0,0 +1,175 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard.Analysis; +using MathNet.Symbolics.Packages.Standard.Algebra; +using MathNet.Symbolics.Packages.Standard.Arithmetics; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard +{ + public static class GeneralizedPolynomial + { + #region Classification + private static bool IsMonomialFactor(Signal signal, Signal[] generalizedVariables) + { + if(Array.Exists(generalizedVariables, signal.Equals)) + return true; + if(!Array.Exists(generalizedVariables, signal.DependsOn)) + return true; + if(signal.IsDrivenByPortEntity("Power", "Std")) + { + Signal b = signal.DrivenByPort.InputSignals[0]; + Signal e = signal.DrivenByPort.InputSignals[1]; + if(Array.Exists(generalizedVariables, b.Equals) && Std.IsAlwaysPositiveInteger(e)) + return true; + } + return false; + } + public static bool IsMonomial(Signal signal, Signal[] generalizedVariables) + { + if(signal.IsDrivenByPortEntity("Multiply", "Std")) + return signal.DrivenByPort.InputSignals.TrueForAll(delegate(Signal s) { return IsMonomialFactor(s, generalizedVariables); }); + else + return IsMonomialFactor(signal, generalizedVariables); + } + public static bool IsPolynomial(Signal signal, Signal[] generalizedVariables) + { + if(!signal.IsDrivenByPortEntity("Add", "Std")) + return IsMonomial(signal, generalizedVariables); + if(Array.Exists(generalizedVariables, signal.Equals)) + return true; + return signal.DrivenByPort.InputSignals.TrueForAll(delegate(Signal s) { return IsMonomial(s, generalizedVariables); }); + } + #endregion + + #region Variables + public static Signal[] PolynomialVariables(Signal signal) + { + List variables = new List(); + ISignalSet monomials; + if(signal.IsDrivenByPortEntity("Add", "Std")) + monomials = signal.DrivenByPort.InputSignals; + else + monomials = new SignalSet(signal); + for(int i = 0; i < monomials.Count; i++) + { + ISignalSet factors; + if(monomials[i].IsDrivenByPortEntity("Multiply", "Std")) + factors = monomials[i].DrivenByPort.InputSignals; + else + factors = new SignalSet(monomials[i]); + for(int j = 0; j < factors.Count; j++) + { + if(Std.IsAlwaysRational(factors[j])) + continue; + if(factors[j].IsDrivenByPortEntity("Power", "Std")) + { + Signal b = factors[j].DrivenByPort.InputSignals[0]; + if(Std.IsAlwaysPositiveInteger(factors[j].DrivenByPort.InputSignals[1])) + { + if(!variables.Contains(b)) + variables.Add(b); + } + else + { + if(!variables.Contains(signal)) + variables.Add(signal); + } + } + else + if(!variables.Contains(factors[j])) + variables.Add(factors[j]); + } + } + return variables.ToArray(); + } + #endregion + + #region Degree + public static IValueStructure MonomialDegree(Signal signal, Signal[] generalizedVariables) + { + if(Std.IsConstantAdditiveIdentity(signal)) + return NegativeInfinitySymbol.Instance; + if(Array.Exists(generalizedVariables, signal.Equals)) + return IntegerValue.One; + if(!Array.Exists(generalizedVariables, signal.DependsOn)) + return IntegerValue.Zero; + ISignalSet factors; + long deg = 0; + if(signal.IsDrivenByPortEntity("Multiply", "Std")) + factors = signal.DrivenByPort.InputSignals; + else + factors = new SignalSet(signal); + for(int i = 0; i < factors.Count; i++) + { + if(Array.Exists(generalizedVariables, factors[i].Equals)) + deg++; + else if(factors[i].IsDrivenByPortEntity("Power", "Std")) + { + Signal b = signal.DrivenByPort.InputSignals[0]; + Signal e = signal.DrivenByPort.InputSignals[1]; + IntegerValue v; + if(Array.Exists(generalizedVariables, b.Equals) && (v = e.Value as IntegerValue) != null && v.Value > 0) + deg += v.Value; + } + } + return new IntegerValue(deg); + } + public static IValueStructure PolynomialDegree(Signal signal, Signal[] generalizedVariables) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.IsDrivenByPortEntity("Add", "Std")) + { + IntegerValue d = IntegerValue.Zero; + ISignalSet inputs = signal.DrivenByPort.InputSignals; + for(int i = 0; i < inputs.Count; i++) + { + IValueStructure f = MonomialDegree(inputs[i], generalizedVariables); + if(f is UndefinedSymbol) + return f; + else if(!(f is NegativeInfinitySymbol)) + d = d.Max((IntegerValue)f); + } + return d; + } + else return MonomialDegree(signal, generalizedVariables); + } + public static IValueStructure PolynomialTotalDegree(Signal signal) + { + Signal[] variables = PolynomialVariables(signal); + if(variables.Length == 0) + return UndefinedSymbol.Instance; + return PolynomialDegree(signal, variables); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/AndArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/AndArchitectures.cs new file mode 100644 index 0000000..a8e1743 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/AndArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class AndArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("And", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public AndArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Logic"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateAndProcess(0, port.InputSignalCount - 1, 0) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NandArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NandArchitectures.cs new file mode 100644 index 0000000..ddee9d0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NandArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class NandArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Nand", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public NandArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Logic"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateNandProcess(0, port.InputSignalCount - 1, 0) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NorArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NorArchitectures.cs new file mode 100644 index 0000000..6054342 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NorArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class NorArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Nor", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public NorArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Logic"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateNorProcess(0, port.InputSignalCount - 1, 0) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NotArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NotArchitectures.cs new file mode 100644 index 0000000..7fed88b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/NotArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class NotArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Not", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public NotArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Logic"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateNotProcess(0, 0, port.InputSignalCount, false, false) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/OrArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/OrArchitectures.cs new file mode 100644 index 0000000..255d5b0 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/OrArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class OrArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Or", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public OrArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Logic"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateOrProcess(0, port.InputSignalCount - 1, 0) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/XnorArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/XnorArchitectures.cs new file mode 100644 index 0000000..247057a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/XnorArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class XnorArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Xnor", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public XnorArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Logic"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateXnorProcess(0, port.InputSignalCount - 1, 0) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/XorArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/XorArchitectures.cs new file mode 100644 index 0000000..f64d5b8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Logic/XorArchitectures.cs @@ -0,0 +1,45 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Logic +{ + public class XorArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Xor", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public XorArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("LogicValue"), + LogicValueCategory.IsLogicValueMember, + delegate(Port port) { return new ProcessBase[] { LogicValue.CreateXorProcess(0, port.InputSignalCount - 1, 0) }; }); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Polynomial.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Polynomial.cs new file mode 100644 index 0000000..0266efd --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Polynomial.cs @@ -0,0 +1,461 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard.Analysis; +using MathNet.Symbolics.Packages.Standard.Algebra; +using MathNet.Symbolics.Packages.Standard.Arithmetics; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard +{ + public static class Polynomial + { + #region Classification + /// + /// Checks whether a signal is a single variable monomial, e.g. '2*x^3' + /// + /// is assumed to be automatic simplified + public static bool IsMonomial(Signal signal, Signal variable) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(Std.IsAlwaysRational(signal)) + return true; + if(signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0])) + signal = signal.DrivenByPort.InputSignals[1]; + if(signal.Equals(variable)) + return true; + if(signal.IsDrivenByPortEntity("Power", "Std")) + { + Signal b = signal.DrivenByPort.InputSignals[0]; + Signal e = signal.DrivenByPort.InputSignals[1]; + if(b.Equals(variable) && Std.IsAlwaysPositiveInteger(e)) + return true; + } + return false; + } + + /// + /// Checks whether a signal is a single variable polynomial, e.g. '3*x^2+4*x-1' + /// + /// is assumed to be automatic simplified. + public static bool IsPolynomial(Signal signal, Signal variable) + { + if(signal.IsDrivenByPortEntity("Add", "Std")) + return signal.DrivenByPort.InputSignals.TrueForAll(delegate(Signal s) { return IsMonomial(s, variable); }); + else + return IsMonomial(signal, variable); + } + + /// + /// Checks whether a signal is a single variable rational, a fraction of polynomials. + /// + /// is assumed to be automatic simplified. + public static bool IsRational(Signal signal, Signal variable) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.IsDrivenByPortEntity("Divide", "Std")) + return IsPolynomial(Std.Numerator(signal), variable) && IsPolynomial(Std.Denominator(signal), variable); + else + return IsPolynomial(signal, variable); + } + #endregion + + #region Degree + /// + /// Evaluates the degree of the single-variable monomial . + /// + /// + /// if is not a single-variable monomial. + /// if is zero. + /// Otherwise an representing the asked degree. + /// + /// is assumed to be automatic simplified. + public static IValueStructure MonomialDegree(Signal signal, Signal variable) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(Std.IsConstantAdditiveIdentity(signal)) + return NegativeInfinitySymbol.Instance; + if(Std.IsAlwaysRational(signal)) + return IntegerValue.Zero; + if(signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0])) + signal = signal.DrivenByPort.InputSignals[1]; + if(signal.Equals(variable)) + return IntegerValue.One; + if(signal.IsDrivenByPortEntity("Power", "Std")) + { + Signal b = signal.DrivenByPort.InputSignals[0]; + Signal e = signal.DrivenByPort.InputSignals[1]; + if(b.Equals(variable) && Std.IsAlwaysPositiveInteger(e)) + return e.Value; + } + return UndefinedSymbol.Instance; + } + + /// + /// Evaluates the degree of the single-variable polynomial . + /// + /// + /// if is not a single-variable polynomial. + /// if is zero. + /// Otherwise an representing the asked degree. + /// + /// is assumed to be automatic simplified. + public static IValueStructure PolynomialDegree(Signal signal, Signal variable) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.IsDrivenByPortEntity("Add", "Std")) + { + IntegerValue d = IntegerValue.Zero; + ISignalSet inputs = signal.DrivenByPort.InputSignals; + for(int i = 0; i < inputs.Count; i++) + { + IValueStructure f = MonomialDegree(inputs[i], variable); + if(f is UndefinedSymbol) + return f; + else if(!(f is NegativeInfinitySymbol)) + d = d.Max((IntegerValue)f); + } + return d; + } + else + return MonomialDegree(signal, variable); + } + #endregion + + #region Coefficients + /// + /// Returns the coefficient factor in the monomial + /// + /// + /// Constant UndefinedSymbol if is not a single-variable monomial. + /// Otherwise the coefficient factor of the term. + /// + /// + /// is assumed to be automatic simplified. + public static Signal MonomialCoefficient(Signal signal, Signal variable, out IValueStructure degree) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(Std.IsConstantAdditiveIdentity(signal)) + { + degree = NegativeInfinitySymbol.Instance; + return signal; + } + if(Std.IsAlwaysRational(signal)) + { + degree = IntegerValue.Zero; + return signal; + } + Signal coeff = IntegerValue.ConstantOne; + if(signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0])) + { + coeff = signal.DrivenByPort.InputSignals[0]; + signal = signal.DrivenByPort.InputSignals[1]; + } + if(signal.Equals(variable)) + { + degree = IntegerValue.One; + return coeff; + } + if(signal.IsDrivenByPortEntity("Power", "Std")) + { + Signal b = signal.DrivenByPort.InputSignals[0]; + Signal e = signal.DrivenByPort.InputSignals[1]; + if(b.Equals(variable) && Std.IsAlwaysPositiveInteger(e)) + { + degree = e.Value; + return coeff; + } + } + degree = UndefinedSymbol.Instance; + return UndefinedSymbol.Constant; + } + + /// + /// Returns the coefficient u[exponent] of x^exponent in the polynomial + /// + /// + /// Constant UndefinedSymbol if is not a single-variable polynomial. + /// Constant if there's no summand with the given exponent. + /// Otherwise the sum of all coefficient factors of the term with the given exponent. + /// + /// is assumed to be automatic simplified. + public static Signal PolynomialCoefficient(Signal signal, Signal variable, int exponent) + { + IValueStructure vs; + Signal c = MonomialCoefficient(signal, variable, out vs); + if(!(vs is UndefinedSymbol)) + { + IntegerValue iv = vs as IntegerValue; + if(iv == null || iv.Value == exponent) + return c; + else + return IntegerValue.ConstantZero; + } + if(signal.IsDrivenByPortEntity("Add", "Std")) + { + ISignalSet inputs = signal.DrivenByPort.InputSignals; + List coeffs = new List(4); + for(int i = 0; i < inputs.Count; i++) + { + c = MonomialCoefficient(inputs[i], variable, out vs); + IntegerValue iv = vs as IntegerValue; + if(iv != null && iv.Value == exponent) + coeffs.Add(c); + } + return Std.Add(coeffs); + } + return UndefinedSymbol.Constant; + } + + public static Signal PolynomialLeadingCoefficient(Signal signal, Signal variable) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + IValueStructure degree = PolynomialDegree(signal, variable); + IntegerValue iv = degree as IntegerValue; + if(iv != null) + return PolynomialCoefficient(signal, variable, (int)iv.Value); + if(degree is NegativeInfinitySymbol) + return IntegerValue.ConstantZero; + return UndefinedSymbol.Constant; + } + + /// + /// Extracts all coefficients of the polynomial . + /// + /// A signal array [c0,c1,c2,..] where ci ist the coefficient of x^i. + public static Signal[] PolynomialCoefficients(Signal signal, Signal variable) + { + IValueStructure vs; + SortedList polynom = new SortedList(); + + Signal c = MonomialCoefficient(signal, variable, out vs); + if(!(vs is UndefinedSymbol)) + { + IntegerValue iv = vs as IntegerValue; + if(iv != null) + polynom.Add(iv.Value, c); + else + return new Signal[] { IntegerValue.ConstantZero }; + } + else if(signal.IsDrivenByPortEntity("Add", "Std")) + { + ISignalSet inputs = signal.DrivenByPort.InputSignals; + for(int i = 0; i < inputs.Count; i++) + { + c = MonomialCoefficient(inputs[i], variable, out vs); + IntegerValue iv = vs as IntegerValue; + if(iv != null) + if(!polynom.ContainsKey(iv.Value)) + polynom.Add(iv.Value, c); + else + polynom[iv.Value] = Std.Add(polynom[iv.Value], c); + } + } + if(polynom.Keys.Count == 0) + return new Signal[] { }; + long deg = polynom.Keys[polynom.Keys.Count - 1]; + Signal[] ret = new Signal[deg + 1]; + Signal zero = IntegerValue.ConstantZero; + for(int i = 0; i < ret.Length; i++) + if(polynom.ContainsKey(i)) + ret[i] = polynom[i]; + else + ret[i] = zero; + return ret; + } + + /// + /// The height of a polynomial is the maxium of the absolute values of its coefficients. + /// + public static IValueStructure PolynomialHeight(Signal signal, Signal variable) + { + Signal[] coefficients = PolynomialCoefficients(signal, variable); + if(coefficients.Length == 0) + return UndefinedSymbol.Instance; + RationalValue max = RationalValue.ConvertFrom(coefficients[0].Value).Absolute(); + for(int i = 1; i < coefficients.Length; i++) + { + RationalValue next = RationalValue.ConvertFrom(coefficients[i].Value).Absolute(); + if(next > max) + max = next; + } + return max; + } + #endregion + + #region Construction + public static Signal ConstructPolynomial(Signal variable, params TCoeff[] coefficients) + where TCoeff : IAlgebraicRingWithUnity, IValueStructure + { + Signal zero = null; + Signal[] summands = new Signal[coefficients.Length]; + for(int i = 0; i < summands.Length; i++) + { + TCoeff c = coefficients[i]; + if(c.IsAdditiveIdentity) + { + if(zero == null) + zero = Std.DefineConstant(c); + summands[i] = zero; + continue; + } + + Signal coeff = Std.DefineConstant(c); + + if(i == 0) + summands[0] = coeff; + else if(i == 1) + { + if(c.IsMultiplicativeIdentity) + summands[1] = variable; + else + summands[1] = StdBuilder.Multiply(coeff, variable); + } + else + { + if(c.IsMultiplicativeIdentity) + summands[i] = StdBuilder.Power(variable, IntegerValue.Constant(i)); + else + summands[i] = StdBuilder.Multiply(coeff, StdBuilder.Power(variable, IntegerValue.Constant(i))); + } + } + return Std.Add(summands); + } + + public static Signal ConstructPolynomial(Signal variable, params Signal[] coefficients) + { + Signal[] summands = new Signal[coefficients.Length]; + for(int i = 0; i < summands.Length; i++) + { + Signal coeff = coefficients[i]; + if(Std.IsConstantAdditiveIdentity(coeff)) + { + summands[i] = coeff; + continue; + } + + if(i == 0) + summands[0] = coeff; + else if(i == 1) + { + if(Std.IsConstantMultiplicativeIdentity(coeff)) + summands[1] = variable; + else + summands[1] = StdBuilder.Multiply(coeff, variable); + } + else + { + if(Std.IsConstantMultiplicativeIdentity(coeff)) + summands[i] = StdBuilder.Power(variable, IntegerValue.Constant(i)); + else + summands[i] = StdBuilder.Multiply(coeff, StdBuilder.Power(variable, IntegerValue.Constant(i))); + } + } + return Std.Add(summands); + } + #endregion + + #region Polynomial Division + /// + /// This method manipulates the nummerator array. If you need to keep this unchanged then + /// copy it yourself and provide the copy to this method call. + /// + public static TCoeff[] PolynomialDivision(TCoeff[] numerator, TCoeff[] denominator, out TCoeff[] remainder) + where TCoeff : IAlgebraicField, IValueStructure + { + TCoeff[] B = denominator; + TCoeff[] R = numerator; + + int degB = B.Length - 1; + TCoeff lcB = B[degB]; + TCoeff[] Q = new TCoeff[R.Length - degB]; + + for(int delta = R.Length - 1 - degB; delta >= 0; delta--) + { + int degR = degB + delta; + if(R[degR].IsAdditiveIdentity) + { + Q[delta] = R[degR]; + continue; + } + TCoeff T = R[degR].Divide(lcB); + Q[delta] = T; + R[degB + delta] = (TCoeff)lcB.AdditiveIdentity; + for(int i = delta; i < degB + delta; i++) + R[i] = R[i].Subtract(B[i - delta].Multiply(T)); + } + + remainder = new TCoeff[Q.Length]; + for(int i = 0; i < remainder.Length; i++) + remainder[i] = R[i]; + return Q; + } + + public static Signal PolynomialDivision(Signal numerator, Signal denominator, Signal variable, out Signal remainder) + { + Signal[] R = PolynomialCoefficients(numerator, variable); + Signal[] B = PolynomialCoefficients(denominator, variable); + + int degB = B.Length - 1; + Signal lcB = B[degB]; + Signal[] Q = new Signal[R.Length - degB]; + + for(int delta = R.Length - 1 - degB; delta >= 0; delta--) + { + int degR = degB + delta; + if(Std.IsConstantAdditiveIdentity(R[degR])) + { + Q[delta] = R[degR]; + continue; + } + Signal T = Std.Divide(R[degR], lcB); + Q[delta] = T; + R[degB + delta] = IntegerValue.ConstantZero; + for(int i = delta; i < degB + delta; i++) + R[i] = Std.Subtract(R[i], Std.Multiply(B[i - delta], T)); + } + + remainder = ConstructPolynomial(variable, R); + return ConstructPolynomial(variable, Q); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/IntegerSetProperty.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/IntegerSetProperty.cs new file mode 100644 index 0000000..1cd7cc7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/IntegerSetProperty.cs @@ -0,0 +1,97 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Properties +{ + public sealed class IntegerSetProperty : PropertyBase + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("IntegerSet", "Std"); + private IntegerSetProperty() { } + + #region Singleton + private static IntegerSetProperty _instance; + public static IntegerSetProperty Instance + { + get + { + if(_instance == null) + _instance = new IntegerSetProperty(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public override bool StillValidAfterEvent(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return false; + return IntegerValue.CanConvertLosslessFrom(signal.Value); + } + public override bool StillValidAfterDrive(Signal signal) + { + return false; + } + public override bool StillValidAfterUndrive(Signal signal) + { + return true; + } + + public override bool Equals(IProperty other) + { + return other is IntegerSetProperty; + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //private static IntegerSetProperty InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static IntegerSetProperty Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/PositiveIntegerSetProperty.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/PositiveIntegerSetProperty.cs new file mode 100644 index 0000000..857cc01 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/PositiveIntegerSetProperty.cs @@ -0,0 +1,100 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Properties +{ + /// + /// Property restricting a signal to be an integer > 0, that is one of 1,2,3,... + /// + public sealed class PositiveIntegerSetProperty : PropertyBase + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("PositiveIntegerSet", "Std"); + private PositiveIntegerSetProperty() { } + + #region Singleton + private static PositiveIntegerSetProperty _instance; + public static PositiveIntegerSetProperty Instance + { + get + { + if(_instance == null) + _instance = new PositiveIntegerSetProperty(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public override bool StillValidAfterEvent(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return false; + return IntegerValue.CanConvertLosslessFrom(signal.Value) && IntegerValue.ConvertFrom(signal.Value).Value >= 0; + } + public override bool StillValidAfterDrive(Signal signal) + { + return false; + } + public override bool StillValidAfterUndrive(Signal signal) + { + return true; + } + + public override bool Equals(IProperty other) + { + return other is PositiveIntegerSetProperty; + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //private static PositiveIntegerSetProperty InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static PositiveIntegerSetProperty Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/RationalSetProperty.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/RationalSetProperty.cs new file mode 100644 index 0000000..6c685a4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/RationalSetProperty.cs @@ -0,0 +1,97 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Properties +{ + public sealed class RationalSetProperty : PropertyBase + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("RationalSet","Std"); + private RationalSetProperty() { } + + #region Singleton + private static RationalSetProperty _instance; + public static RationalSetProperty Instance + { + get + { + if(_instance == null) + _instance = new RationalSetProperty(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public override bool StillValidAfterEvent(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return false; + return RationalValue.CanConvertLosslessFrom(signal.Value); + } + public override bool StillValidAfterDrive(Signal signal) + { + return false; + } + public override bool StillValidAfterUndrive(Signal signal) + { + return true; + } + + public override bool Equals(IProperty other) + { + return other is RationalSetProperty; + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //private static RationalSetProperty InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static RationalSetProperty Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/RealSetProperty.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/RealSetProperty.cs new file mode 100644 index 0000000..bd1b797 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Properties/RealSetProperty.cs @@ -0,0 +1,97 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Properties +{ + public sealed class RealSetProperty : PropertyBase + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("RealSet", "Std"); + private RealSetProperty() { } + + #region Singleton + private static RealSetProperty _instance; + public static RealSetProperty Instance + { + get + { + if(_instance == null) + _instance = new RealSetProperty(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public override bool StillValidAfterEvent(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return false; + return RealValue.CanConvertLosslessFrom(signal.Value); + } + public override bool StillValidAfterDrive(Signal signal) + { + return false; + } + public override bool StillValidAfterUndrive(Signal signal) + { + return true; + } + + public override bool Equals(IProperty other) + { + return other is RealSetProperty; + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //private static RealSetProperty InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static RealSetProperty Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Std.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Std.cs new file mode 100644 index 0000000..21f55f4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Std.cs @@ -0,0 +1,623 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard.Analysis; +using MathNet.Symbolics.Packages.Standard.Algebra; +using MathNet.Symbolics.Packages.Standard.Arithmetics; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Conversion; + +namespace MathNet.Symbolics.Packages.Standard +{ + /// + /// Standard Package Operations & Transformations. + /// + /// + /// Use StdBuilder instead if you only want to map operations to a set + /// of signals but not actually execute them (now). + /// + public static class Std + { + private static ITransformer _transformer = Service.Instance; + + #region Simplification + public static Signal AutoSimplify(Signal signal) + { + return _transformer.Transform(signal, AutoSimplifyTransformation.TransformationTypeIdentifier, false); + } + public static SignalSet AutoSimplify(IEnumerable signals) + { + return _transformer.Transform(signals, AutoSimplifyTransformation.TransformationTypeIdentifier, false); + } + #endregion + + #region Algebra + /// + /// Separates factors in a product that depend on x from those that do not. + /// + /// + /// A signal array [a,b], where a is the product of the factors not + /// depending on x, and b the product of those depending on x. + /// + /// is assumed to be automatic simplified + public static Signal[] SeparateFactors(Signal product, Signal x) + { + SignalSet freePart = new SignalSet(); + SignalSet dependentPart = new SignalSet(); + if(product.IsDrivenByPortEntity("Multiply", "Std")) + { + ISignalSet factors = product.DrivenByPort.InputSignals; + foreach(Signal s in factors) + { + if(s.DependsOn(x)) + dependentPart.Add(s); + else + freePart.Add(s); + } + } + else if(product.DependsOn(x)) + dependentPart.Add(product); + else + freePart.Add(product); + Signal freeSignal = Multiply(freePart); + Signal dependentSignal = Multiply(dependentPart); + return new Signal[] { freeSignal, dependentSignal }; + } + + public static Signal Numerator(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.IsDrivenByPortEntity("Divide", "Std")) + return signal.DrivenByPort.InputSignals[0]; + return signal; + } + + public static Signal Denominator(Signal signal) + { + if(signal.IsDrivenByPortEntity("Divide", "Std") && signal.DrivenByPort.InputSignalCount > 1) + { + if(signal.DrivenByPort.InputSignals.Count == 2) + return signal.DrivenByPort.InputSignals[1]; + + List factors = new List(); + ISignalSet inputs = signal.DrivenByPort.InputSignals; + for(int i = 1; i < inputs.Count; i++) //all but first element + factors.Add(inputs[i]); + return Multiply(factors); + } + return IntegerValue.ConstantOne; + } + #endregion + + #region Trigonometry + /// + /// Substitutes all instances of Tangent, Cotangent, Secant and Cosecant + /// by their representation using Sine and Cosine. + /// + public static Signal TrigonometricSubstitute(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return _transformer.Transform(signal, new MathIdentifier("TrigonometricSubstitute", "Std"), false); + } + public static SignalSet TrigonometricSubstitute(IEnumerable signals) + { + return _transformer.Transform(signals, new MathIdentifier("TrigonometricSubstitute", "Std"), false); + } + + //public static Signal TrigonometricSimplify(IContext context, Signal signal) + //{ + // Signal v = TrigonometricSubstitute(context, signal); + // Signal w = Rationalize_expression(context, v); + // Signal n = Contract_trig(Expand_trig(context, Numerator(w))); + // Signal d = Contract_trig(Expand_trig(context, Denominator(w))); + // if(d = 0) + // return undefined; + // else + // return n / d; + //} + #endregion + + #region Analysis + public static Signal Derive(Signal signal, Signal variable) + { + return _transformer.Transform(signal, DerivativeTransformation.TransformationTypeIdentifier, delegate(ITransformationTheorem theorem) + { + DerivativeTransformation dt = (DerivativeTransformation)theorem; + dt.Variable = variable; + }, false); + } + public static SignalSet Derive(IEnumerable signals, Signal variable) + { + return _transformer.Transform(signals, DerivativeTransformation.TransformationTypeIdentifier, delegate(ITransformationTheorem theorem) + { + DerivativeTransformation dt = (DerivativeTransformation)theorem; + dt.Variable = variable; + }, false); + } + #endregion + + #region Arithmetics + /// + /// Adds a set of signals and tries to automatically simplify the term. + /// WARNING: This method may change the contents of the signals paramerer. + /// Pass signals.AsReadOnly instead of signals if you pass + /// a writeable signal set that must not be changed. + /// + public static Signal Add(ISignalSet signals) + { + if(signals.IsReadOnly) + signals = new SignalSet(signals); + AdditionArchitectures.SimplifySummands(signals); + if(signals.Count == 0) + return IntegerValue.ConstantAdditiveIdentity; + if(signals.Count == 1) + return signals[0]; + return StdBuilder.Add(signals); + } + public static Signal Add(params Signal[] signals) + { + return Add(new SignalSet(signals)); + } + public static Signal Add(IEnumerable signals) + { + return Add(new SignalSet(signals)); + } + public static Signal Add(Signal signal, IEnumerable signals) + { + SignalSet set = new SignalSet(signal); + set.AddRange(signals); + return Add(set); + } + + /// + /// Substracts a set of signals (from the first signal) and tries to automatically simplify the term. + /// WARNING: This method may change the contents of the signals paramerer. + /// Pass signals.AsReadOnly instead of signals if you pass + /// a writeable signal set that must not be changed. + /// + public static Signal Subtract(ISignalSet signals) + { + if(signals.IsReadOnly) + signals = new SignalSet(signals); + SubtractionArchitectures.SimplifySummandsForceAddition(signals); + if(signals.Count == 0) + return IntegerValue.ConstantAdditiveIdentity; + if(signals.Count == 1) + return signals[0]; + return StdBuilder.Subtract(signals); + } + public static Signal Subtract(params Signal[] signals) + { + return Subtract(new SignalSet(signals)); + } + public static Signal Subtract(IEnumerable signals) + { + return Subtract(new SignalSet(signals)); + } + public static Signal Subtract(Signal signal, IEnumerable signals) + { + SignalSet set = new SignalSet(signal); + set.AddRange(signals); + return Subtract(set); + } + + /// + /// Multiplies a set of signals and tries to automatically simplify the term. + /// WARNING: This method may change the contents of the signals paramerer. + /// Pass signals.AsReadOnly instead of signals if you pass + /// a writeable signal set that must not be changed. + /// + public static Signal Multiply(ISignalSet signals) + { + if(signals.IsReadOnly) + signals = new SignalSet(signals); + MultiplicationArchitectures.SimplifyFactors(signals); + if(signals.Count == 0) + return IntegerValue.ConstantMultiplicativeIdentity; + if(signals.Count == 1) + return signals[0]; + return StdBuilder.Multiply(signals); + } + public static Signal Multiply(params Signal[] signals) + { + return Multiply(new SignalSet(signals)); + } + public static Signal Multiply(IEnumerable signals) + { + return Multiply(new SignalSet(signals)); + } + public static Signal Multiply(Signal signal, IEnumerable signals) + { + SignalSet set = new SignalSet(signal); + set.AddRange(signals); + return Multiply(set); + } + + /// + /// Divides a set of signals (from the first signal) and tries to automatically simplify the term. + /// WARNING: This method may change the contents of the signals paramerer. + /// Pass signals.AsReadOnly instead of signals if you pass + /// a writeable signal set that must not be changed. + /// + public static Signal Divide(ISignalSet signals) + { + if(signals.IsReadOnly) + signals = new SignalSet(signals); + DivisionArchitectures.SimplifyFactorsForceMultiplication(signals); + if(signals.Count == 0) + return IntegerValue.ConstantMultiplicativeIdentity; + if(signals.Count == 1) + return signals[0]; + return StdBuilder.Divide(signals); + } + public static Signal Divide(params Signal[] signals) + { + return Divide(new SignalSet(signals)); + } + public static Signal Divide(IEnumerable signals) + { + return Divide(new SignalSet(signals)); + } + public static Signal Divide(Signal signal, IEnumerable signals) + { + SignalSet set = new SignalSet(signal); + set.AddRange(signals); + return Divide(set); + } + + /// + /// Raises a signals (the first signal) to powers and tries to automatically simplify the term. + /// WARNING: This method may change the contents of the signals paramerer. + /// Pass signals.AsReadOnly instead of signals if you pass + /// a writeable signal set that must not be changed. + /// + public static Signal Power(ISignalSet signals) + { + if(signals.IsReadOnly) + signals = new SignalSet(signals); + PowerArchitectures.SimplifyOperands(signals); + if(signals.Count == 0) + return IntegerValue.ConstantMultiplicativeIdentity; + if(signals.Count == 1) + return signals[0]; + return StdBuilder.Power(signals); + } + public static Signal Power(params Signal[] signals) + { + return Power(new SignalSet(signals)); + } + public static Signal Power(IEnumerable signals) + { + return Power(new SignalSet(signals)); + } + public static Signal Power(Signal signal, IEnumerable signals) + { + SignalSet set = new SignalSet(signal); + set.AddRange(signals); + return Power(set); + } + + public static Signal Negate(Signal signal) + { + return Multiply(IntegerValue.ConstantMinusOne, signal); + } + + public static Signal Invert(Signal signal) + { + return Power(signal, IntegerValue.ConstantMinusOne); + } + #endregion + + #region Signal Properties + //public static Signal Constant(IContext context, ValueStructure value) + //{ + // Signal s = new Signal(context, value); + // s.Label = "Constant_" + value.ToString(); + // s.AddConstraint(Properties.ConstantSignalProperty.Instance); + // return s; + //} + + public static bool IsConstant(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return signal.AskForFlag(StdAspect.ConstantFlag) == FlagState.Enabled; + //return signal.AskForProperty("Constant", "Std"); + } + public static void DefineConstant(Signal signal) + { + signal.EnableFlag(StdAspect.ConstantFlag); + } + public static Signal DefineConstant(IValueStructure value) + { + Signal s = Binder.CreateSignal(value); + s.Label = s.Value.ToString() + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + return s; + } + + public static bool IsUndefined(ValueNode signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return signal.Value is MathNet.Symbolics.Packages.Standard.Structures.UndefinedSymbol; + } + public static bool IsConstantUndefined(Signal signal) + { + return IsConstant(signal) && IsUndefined(signal); + } + + /// Evaluates whether the signal is zero (0). + public static bool IsAdditiveIdentity(ValueNode signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + IAlgebraicAdditiveIdentityElement monoid = signal.Value as IAlgebraicAdditiveIdentityElement; + return monoid != null && monoid.IsAdditiveIdentity; + } + /// Evaluates whether the signal is always zero (0). + public static bool IsConstantAdditiveIdentity(Signal signal) + { + return IsConstant(signal) && IsAdditiveIdentity(signal); + } + + /// Evaluates whether the signal is one (1). + public static bool IsMultiplicativeIdentity(ValueNode signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + IAlgebraicMultiplicativeIdentityElement ring = signal.Value as IAlgebraicMultiplicativeIdentityElement; + return ring != null && ring.IsMultiplicativeIdentity; + } + /// Evaluates whether the signal is always one (1). + public static bool IsConstantMultiplicativeIdentity(Signal signal) + { + return IsConstant(signal) && IsMultiplicativeIdentity(signal); + } + + //public static bool IsConstantZero(Signal signal) + //{ + // return IsConstant(signal) && (signal.Value.ToString() == "0"); + //} + //public static bool IsConstantOne(Signal signal) + //{ + // return IsConstant(signal) && (signal.Value.ToString() == "1"); + //} + + /// + /// Whether the signal is restricted to be > 0 + /// + public static bool IsAlwaysPositive(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return signal.IsFlagEnabled(StdAspect.PositiveWithoutZeroConstraingFlag) + || IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value) && RealValue.ConvertFrom(signal.Value).Value > 0d; + } + public static void ConstrainAlwaysPositive(Signal signal) + { + signal.EnableFlag(StdAspect.PositiveWithoutZeroConstraingFlag); + } + + /// + /// Whether the signal is restricted to be < 0 + /// + public static bool IsAlwaysNegative(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return signal.IsFlagEnabled(StdAspect.NegativeWithoutZeroConstraingFlag) + || IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value) && RealValue.ConvertFrom(signal.Value).Value < 0d; + } + public static void ConstrainAlwaysNegative(Signal signal) + { + signal.EnableFlag(StdAspect.NegativeWithoutZeroConstraingFlag); + } + + /// + /// Whether the signal is restricted to be >= 0 + /// + public static bool IsAlwaysNonnegative(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return signal.IsFlagEnabled(StdAspect.PositiveOrZeroConstraintFlag) + || IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value) && RealValue.ConvertFrom(signal.Value).Value >= 0d; + } + public static void ConstrainAlwaysNonnegative(Signal signal) + { + signal.EnableFlag(StdAspect.PositiveOrZeroConstraintFlag); + } + + /// + /// Whether the signal is restricted to be <= 0 + /// + public static bool IsAlwaysNonpositive(Signal signal) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + return signal.IsFlagEnabled(StdAspect.NegativeOrZeroConstraintFlag) + || IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value) && RealValue.ConvertFrom(signal.Value).Value <= 0d; + } + public static void ConstrainAlwaysNonpositive(Signal signal) + { + signal.EnableFlag(StdAspect.NegativeOrZeroConstraintFlag); + } + + /// + /// Whether the signal is restricted to be an integer, that is one of ...,-3,-2,-1,0,1,2,3,... + /// + public static bool IsAlwaysInteger(Signal signal) + { + return signal.IsFlagEnabled(StdAspect.IntegerConstraintFlag) + || IsConstantInteger(signal); + } + public static bool IsConstantInteger(Signal signal) + { + return IsConstant(signal) && IntegerValue.CanConvertLosslessFrom(signal.Value); + } + public static void ConstrainAlwaysInteger(Signal signal) + { + signal.EnableFlag(StdAspect.IntegerConstraintFlag); + } + + /// + /// Whether the signal is restricted to be a rational. + /// + public static bool IsAlwaysRational(Signal signal) + { + return signal.IsFlagEnabled(StdAspect.RationalConstraintFlag) + || IsConstantRational(signal); + } + public static bool IsConstantRational(Signal signal) + { + return IsConstant(signal) && RationalValue.CanConvertLosslessFrom(signal.Value); + } + public static void ConstrainAlwaysRational(Signal signal) + { + signal.EnableFlag(StdAspect.RationalConstraintFlag); + } + + /// + /// Whether the signal is restricted to be a real. + /// + public static bool IsAlwaysReal(Signal signal) + { + return signal.IsFlagEnabled(StdAspect.RealConstraintFlag) + || IsConstantReal(signal); + } + public static bool IsConstantReal(Signal signal) + { + return IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value); + } + public static void ConstrainAlwaysReal(Signal signal) + { + signal.EnableFlag(StdAspect.RealConstraintFlag); + } + + /// + /// Whether the signal is restricted to be a complex (of real parts). + /// + public static bool IsAlwaysComplex(Signal signal) + { + return signal.IsFlagEnabled(StdAspect.ComplexConstraintFlag) + || IsConstantComplex(signal); + } + public static bool IsConstantComplex(Signal signal) + { + return IsConstant(signal) && ComplexValue.CanConvertLosslessFrom(signal.Value); + } + public static void ConstrainAlwaysComplex(Signal signal) + { + signal.EnableFlag(StdAspect.ComplexConstraintFlag); + } + + /// + /// Whether the signal is restricted to be an integer > 0, that is one of 1,2,3,... + /// + public static bool IsAlwaysPositiveInteger(Signal signal) + { + return IsAlwaysInteger(signal) && IsAlwaysPositive(signal); + } + public static bool IsConstantPositiveInteger(Signal signal) + { + return IsConstantInteger(signal) && IsAlwaysPositive(signal); + } + public static void ConstrainAlwaysPositiveInteger(Signal signal) + { + ConstrainAlwaysInteger(signal); + ConstrainAlwaysPositive(signal); + } + + /// + /// Whether the signal is restricted to be an integer < 0, that is one of -1,-2,-3,... + /// + public static bool IsAlwaysNegativeInteger(Signal signal) + { + return IsAlwaysInteger(signal) && IsAlwaysNegative(signal); + } + public static bool IsConstantNegativeInteger(Signal signal) + { + return IsConstantInteger(signal) && IsAlwaysNegative(signal); + } + public static void ConstrainAlwaysNegativeInteger(Signal signal) + { + ConstrainAlwaysInteger(signal); + ConstrainAlwaysNegative(signal); + } + + /// + /// Whether the signal is restricted to be an integer >= 0, that is one of 0,1,2,3,... + /// + public static bool IsAlwaysNonnegativeInteger(Signal signal) + { + return IsAlwaysInteger(signal) && IsAlwaysNonnegative(signal); + } + public static bool IsConstantNonnegativeInteger(Signal signal) + { + return IsConstantInteger(signal) && IsAlwaysNonnegative(signal); + } + public static void ConstrainAlwaysNonnegativeInteger(Signal signal) + { + ConstrainAlwaysInteger(signal); + ConstrainAlwaysNonnegative(signal); + } + + /// + /// Whether the signal is restricted to be an integer <= 0, that is one of 0,-1,-2,-3,... + /// + public static bool IsAlwaysNonpositiveInteger(Signal signal) + { + return IsAlwaysInteger(signal) && IsAlwaysNonpositive(signal); + } + public static bool IsConstantNonpositiveInteger(Signal signal) + { + return IsConstantInteger(signal) && IsAlwaysNonpositive(signal); + } + public static void ConstrainAlwaysNonpositiveInteger(Signal signal) + { + ConstrainAlwaysInteger(signal); + ConstrainAlwaysNonpositive(signal); + } + + + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdAspect.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdAspect.cs new file mode 100644 index 0000000..73ad846 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdAspect.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.Standard +{ + public static class StdAspect + { + /// + /// Flag indicating that the signal is constant (hence e.g. its derivative is zero). + /// + public static readonly NodeFlag ConstantFlag = + NodeFlag.Register(new MathIdentifier("Constant", "Std"), typeof(StdAspect)); + + /// + /// Flag indicating that the signal is constrained to always have integer values. + /// + public static readonly NodeFlag IntegerConstraintFlag = + NodeFlag.Register(new MathIdentifier("IntegerConstraint", "Std"), typeof(StdAspect), FlagKind.Constraint); + + /// + /// Flag indicating that the signal is constrained to always have rational values. + /// + public static readonly NodeFlag RationalConstraintFlag = + NodeFlag.Register(new MathIdentifier("RationalConstraint", "Std"), typeof(StdAspect), FlagKind.Constraint, + new NodeEventTrigger(EventTriggerAction.Enable, IntegerConstraintFlag, IntegerConstraintFlag.FlagEnabledEvent), + new NodeEventTrigger(EventTriggerAction.Dirty, IntegerConstraintFlag.FlagChangedEvent, IntegerConstraintFlag.FlagDirtiedEvent)); + + /// + /// Flag indicating that the signal is constrained to always have real values. + /// + public static readonly NodeFlag RealConstraintFlag = + NodeFlag.Register(new MathIdentifier("RealConstraint", "Std"), typeof(StdAspect), FlagKind.Constraint, + new NodeEventTrigger(EventTriggerAction.Enable, RationalConstraintFlag, RationalConstraintFlag.FlagEnabledEvent), + new NodeEventTrigger(EventTriggerAction.Dirty, RationalConstraintFlag.FlagChangedEvent, RationalConstraintFlag.FlagDirtiedEvent)); + + /// + /// Flag indicating that the signal is constrained to always have complex values (of real parts). + /// + public static readonly NodeFlag ComplexConstraintFlag = + NodeFlag.Register(new MathIdentifier("ComplexConstraint", "Std"), typeof(StdAspect), FlagKind.Constraint, + new NodeEventTrigger(EventTriggerAction.Enable, RealConstraintFlag, RealConstraintFlag.FlagEnabledEvent), + new NodeEventTrigger(EventTriggerAction.Dirty, RealConstraintFlag.FlagChangedEvent, RealConstraintFlag.FlagDirtiedEvent)); + + /// + /// Flag indicating that the signal is constrained to always be >= 0. + /// + public static readonly NodeFlag PositiveOrZeroConstraintFlag = + NodeFlag.Register(new MathIdentifier("PositiveOrZero", "Std"), typeof(StdAspect), FlagKind.Constraint); + + /// + /// Flag indicating that the signal is constrained to always be > 0. + /// + public static readonly NodeFlag PositiveWithoutZeroConstraingFlag = + NodeFlag.Register(new MathIdentifier("PositiveWithoutZero", "Std"), typeof(StdAspect), FlagKind.Constraint, + new NodeEventTrigger(EventTriggerAction.Enable, PositiveOrZeroConstraintFlag, PositiveOrZeroConstraintFlag.FlagEnabledEvent), + new NodeEventTrigger(EventTriggerAction.Dirty, PositiveOrZeroConstraintFlag.FlagChangedEvent)); + + /// + /// Flag indicating that the signal is constrained to always be <= 0. + /// + public static readonly NodeFlag NegativeOrZeroConstraintFlag = + NodeFlag.Register(new MathIdentifier("NegativeOrZero", "Std"), typeof(StdAspect), FlagKind.Constraint); + + /// + /// Flag indicating that the signal is constrained to always be < 0. + /// + public static readonly NodeFlag NegativeWithoutZeroConstraingFlag = + NodeFlag.Register(new MathIdentifier("NegativeWithoutZero", "Std"), typeof(StdAspect), FlagKind.Constraint, + new NodeEventTrigger(EventTriggerAction.Enable, NegativeOrZeroConstraintFlag, NegativeOrZeroConstraintFlag.FlagEnabledEvent), + new NodeEventTrigger(EventTriggerAction.Dirty, NegativeOrZeroConstraintFlag.FlagChangedEvent)); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdBuilder.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdBuilder.cs new file mode 100644 index 0000000..bb11bf4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdBuilder.cs @@ -0,0 +1,252 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend.Containers; + +using MathNet.Symbolics.Packages.Standard.Arithmetics; +using MathNet.Symbolics.Packages.Standard.Trigonometry; +using MathNet.Symbolics.Packages.Standard.Analysis; +using MathNet.Symbolics.Packages.Standard.Algebra; + +namespace MathNet.Symbolics.Packages.Standard +{ + /// + /// Standard Package Builder, Maps available operations to the given signals. + /// + /// + /// A Package Builder only maps operations on signals, but does not "execute" them. + /// For example, if you have two signals a=x and b=sin(x) and apply + /// them to c=StdBuilder.Derive(b,a), you'll get a new signal c=diff(sin(x),x) + /// and not cos(x) as you may expect. Use Std instead of StdBuilder + /// if you want to actually transform the signals. + /// + public static class StdBuilder + { + private static IBuilder _builder = Service.Instance; + + #region Arithmetics + public static Signal Add(Signal summand1, Signal summand2) + { + return _builder.Function(AdditionArchitectures.EntityIdentifier, summand1, summand2); + } + public static Signal Add(params Signal[] op) + { + return _builder.Function(AdditionArchitectures.EntityIdentifier, op); + } + public static Signal Add(IList op) + { + return _builder.Function(AdditionArchitectures.EntityIdentifier, op); + } + + public static Signal Negate(Signal subtrahend) + { + return _builder.Function(NegateArchitectures.EntityIdentifier, subtrahend); + } + public static ReadOnlySignalSet Negate(params Signal[] op) + { + return _builder.Functions(NegateArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Negate(IList op) + { + return _builder.Functions(NegateArchitectures.EntityIdentifier, op); + } + + public static Signal Subtract(Signal minuend, Signal subtrahend) + { + return _builder.Function(SubtractionArchitectures.EntityIdentifier, minuend, subtrahend); + } + public static Signal Subtract(params Signal[] op) + { + return _builder.Function(SubtractionArchitectures.EntityIdentifier, op); + } + public static Signal Subtract(IList op) + { + return _builder.Function(SubtractionArchitectures.EntityIdentifier, op); + } + + public static Signal Multiply(Signal multiplicand, Signal multiplier) + { + return _builder.Function(MultiplicationArchitectures.EntityIdentifier, multiplicand, multiplier); + } + public static Signal Multiply(params Signal[] op) + { + return _builder.Function(MultiplicationArchitectures.EntityIdentifier, op); + } + public static Signal Multiply(IList op) + { + return _builder.Function(MultiplicationArchitectures.EntityIdentifier, op); + } + + public static Signal Invert(Signal divisor) + { + return _builder.Function(InvertArchitectures.EntityIdentifier, divisor); + } + public static ReadOnlySignalSet Invert(params Signal[] op) + { + return _builder.Functions(InvertArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Invert(IList op) + { + return _builder.Functions(InvertArchitectures.EntityIdentifier, op); + } + + public static Signal Divide(Signal dividend, Signal divisor) + { + return _builder.Function(DivisionArchitectures.EntityIdentifier, dividend, divisor); + } + public static Signal Divide(params Signal[] op) + { + return _builder.Function(DivisionArchitectures.EntityIdentifier, op); + } + public static Signal Divide(IList op) + { + return _builder.Function(DivisionArchitectures.EntityIdentifier, op); + } + + public static Signal Exponential(Signal exponent) + { + return _builder.Function(ExponentialArchitectures.EntityIdentifier, exponent); + } + public static Signal NaturalLogarithm(Signal exponent) + { + return _builder.Function(NaturalLogarithmArchitectures.EntityIdentifier, exponent); + } + + public static Signal Power(Signal radix, Signal exponent) + { + return _builder.Function(PowerArchitectures.EntityIdentifier, radix, exponent); + } + public static Signal Power(params Signal[] op) + { + return _builder.Function(PowerArchitectures.EntityIdentifier, op); + } + public static Signal Power(IList op) + { + return _builder.Function(PowerArchitectures.EntityIdentifier, op); + } + + public static Signal Square(Signal radix) + { + return _builder.Function(SquareArchitectures.EntityIdentifier, radix); + } + public static ReadOnlySignalSet Square(params Signal[] op) + { + return _builder.Functions(SquareArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Square(IList op) + { + return _builder.Functions(SquareArchitectures.EntityIdentifier, op); + } + + public static Signal Absolute(Signal signal) + { + return _builder.Function(AbsoluteArchitectures.EntityIdentifier, signal); + } + public static ReadOnlySignalSet Absolute(params Signal[] op) + { + return _builder.Functions(AbsoluteArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Absolute(IList op) + { + return _builder.Functions(AbsoluteArchitectures.EntityIdentifier, op); + } + + public static Signal Factorial(Signal signal) + { + return _builder.Function("!", InfixNotation.PostOperator, signal); + } + + #endregion + + #region Trigonometry + public static Signal Sine(Signal op) + { + return _builder.Function(SineArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Sine(IList op) + { + return _builder.Functions(SineArchitectures.EntityIdentifier, op); + } + public static Signal Cosine(Signal op) + { + return _builder.Function(CosineArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Cosine(IList op) + { + return _builder.Functions(CosineArchitectures.EntityIdentifier, op); + } + public static Signal Tangent(Signal op) + { + return _builder.Function(TangentArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Tangent(IList op) + { + return _builder.Functions(TangentArchitectures.EntityIdentifier, op); + } + public static Signal Cotangent(Signal op) + { + return _builder.Function(CotangentArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Cotangent(IList op) + { + return _builder.Functions(CotangentArchitectures.EntityIdentifier, op); + } + public static Signal Secant(Signal op) + { + return _builder.Function(SecantArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Secant(IList op) + { + return _builder.Functions(SecantArchitectures.EntityIdentifier, op); + } + public static Signal Cosecant(Signal op) + { + return _builder.Function(CosecantArchitectures.EntityIdentifier, op); + } + public static ReadOnlySignalSet Cosecant(IList op) + { + return _builder.Functions(CosecantArchitectures.EntityIdentifier, op); + } + #endregion + + #region Analysis + public static Signal Derive(Signal signal, Signal variable) + { + return _builder.Function(AlgebraicDerivativeArchitecture.EntityIdentifier, signal, variable); + } + public static Signal Derive(params Signal[] signals) + { + return _builder.Function(AlgebraicDerivativeArchitecture.EntityIdentifier, signals); + } + public static Signal Derive(IList signals) + { + return _builder.Function(AlgebraicDerivativeArchitecture.EntityIdentifier, signals); + } + #endregion + + #region Algebra + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdPackageManager.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdPackageManager.cs new file mode 100644 index 0000000..44af99e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/StdPackageManager.cs @@ -0,0 +1,236 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard +{ + //[PackageManager("Std")] + //[EntityServer] + //[ArchitectureServer] + //[TheoremServer] + //[StructureServer] + public class StdPackageManager : IPackageManager + { + public StdPackageManager() + { + } + + public string Domain + { + get { return "Std"; } + } + + public void Register(ILibrary library) + { + RegisterEntities(library); + RegisterArchitectures(library); + RegisterTheorems(library); + RegisterStructures(library); + } + + public void RegisterEntities(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + #region Arithmetics + library.AddEntity(new NaryToOneGenericEntity("+", "Add", "Std", InfixNotation.LeftAssociativeInnerOperator, 60)); + library.AddEntity(new NaryToOneGenericEntity("-", "Subtract", "Std", InfixNotation.LeftAssociativeInnerOperator, 60)); + library.AddEntity(new NaryToOneGenericEntity("*", "Multiply", "Std", InfixNotation.LeftAssociativeInnerOperator, 50)); + library.AddEntity(new NaryToOneGenericEntity("/", "Divide", "Std", InfixNotation.LeftAssociativeInnerOperator, 50)); + library.AddEntity(new SymmetricGenericEntity("-", "Negate", "Std", InfixNotation.PreOperator, 20)); + library.AddEntity(new SymmetricGenericEntity("inv", "Invert", "Std")); + library.AddEntity(new SymmetricGenericEntity("abs", "Absolute", "Std")); + library.AddEntity(new SymmetricGenericEntity("exp", "Exponential", "Std")); + library.AddEntity(new SymmetricGenericEntity("ln", "NaturalLogarithm", "Std")); + library.AddEntity(new SymmetricGenericEntity("sqr", "Square", "Std")); + library.AddEntity(new EntityBase("^", "Power", "Std", InfixNotation.RightAssociativeInnerOperator, 19, new string[] { "Power_base", "Power_radix" }, new string[] { "Power_out" })); + library.AddEntity(new EntityBase("!", "Factorial", "Std", InfixNotation.PostOperator, 45, new string[] { "Factorial_in" }, new string[] { "Factorial_out" })); + #endregion + #region Trigonometry + library.AddEntity(new SymmetricGenericEntity("sin", "Sine", "Std")); + library.AddEntity(new SymmetricGenericEntity("cos", "Cosine", "Std")); + library.AddEntity(new SymmetricGenericEntity("tan", "Tangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("cot", "Cotangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("sec", "Secant", "Std")); + library.AddEntity(new SymmetricGenericEntity("csc", "Cosecant", "Std")); + library.AddEntity(new SymmetricGenericEntity("asin", "InverseSine", "Std")); + library.AddEntity(new SymmetricGenericEntity("acos", "InverseCosine", "Std")); + library.AddEntity(new SymmetricGenericEntity("atan", "InverseTangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("acot", "InverseCotangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("asec", "InverseSecant", "Std")); + library.AddEntity(new SymmetricGenericEntity("acsc", "InverseCosecant", "Std")); + library.AddEntity(new SymmetricGenericEntity("sinh", "HyperbolicSine", "Std")); + library.AddEntity(new SymmetricGenericEntity("cosh", "HyperbolicCosine", "Std")); + library.AddEntity(new SymmetricGenericEntity("tanh", "HyperbolicTangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("coth", "HyperbolicCotangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("sech", "HyperbolicSecant", "Std")); + library.AddEntity(new SymmetricGenericEntity("csch", "HyperbolicCosecant", "Std")); + library.AddEntity(new SymmetricGenericEntity("asinh", "InverseHyperbolicSine", "Std")); + library.AddEntity(new SymmetricGenericEntity("acosh", "InverseHyperbolicCosine", "Std")); + library.AddEntity(new SymmetricGenericEntity("atanh", "InverseHyperbolicTangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("acoth", "InverseHyperbolicCotangent", "Std")); + library.AddEntity(new SymmetricGenericEntity("asech", "InverseHyperbolicSecant", "Std")); + library.AddEntity(new SymmetricGenericEntity("acsch", "InverseHyperbolicCosecant", "Std")); + #endregion + #region Logic + library.AddEntity(new NaryToOneGenericEntity("and", "And", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new NaryToOneGenericEntity("nand", "Nand", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new NaryToOneGenericEntity("or", "Or", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new NaryToOneGenericEntity("nor", "Nor", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new NaryToOneGenericEntity("xor", "Xor", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new NaryToOneGenericEntity("xnor", "Xnor", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new NaryToOneGenericEntity("imp", "Imply", "Std", InfixNotation.LeftAssociativeInnerOperator, 250)); + library.AddEntity(new SymmetricGenericEntity("not", "Not", "Std", InfixNotation.PreOperator, 250)); + #endregion + #region Algebra & Analysis + library.AddEntity(new NearlySymmetricGenericEntity("diff", "Derive", "Std", 1, 0)); + library.AddEntity(new SymmetricGenericEntity("asimplify", "AutoSimplify", "Std")); + #endregion + #region Flow + library.AddEntity(new SymmetricGenericEntity("<-", "Transport", "Std")); + library.AddEntity(new NearlySymmetricGenericEntity("$", "Sync", "Std", 1, 0)); + library.AddEntity(new SymmetricGenericEntity("clk", "Clock", "Std")); + #endregion + } + + public void RegisterArchitectures(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + #region Arithmetics + library.AddArchitecture(new Arithmetics.AdditionArchitectures()); + library.AddArchitecture(new Arithmetics.SubtractionArchitectures()); + library.AddArchitecture(new Arithmetics.MultiplicationArchitectures()); + library.AddArchitecture(new Arithmetics.DivisionArchitectures()); + library.AddArchitecture(new Arithmetics.NegateArchitectures()); + library.AddArchitecture(new Arithmetics.InvertArchitectures()); + library.AddArchitecture(new Arithmetics.AbsoluteArchitectures()); + library.AddArchitecture(new Arithmetics.ExponentialArchitectures()); + library.AddArchitecture(new Arithmetics.NaturalLogarithmArchitectures()); + library.AddArchitecture(new Arithmetics.SquareArchitectures()); + library.AddArchitecture(new Arithmetics.PowerArchitectures()); + #endregion + #region Trigonometry + library.AddArchitecture(new Trigonometry.SineArchitectures()); + library.AddArchitecture(new Trigonometry.CosineArchitectures()); + library.AddArchitecture(new Trigonometry.TangentArchitectures()); + library.AddArchitecture(new Trigonometry.CotangentArchitectures()); + library.AddArchitecture(new Trigonometry.SecantArchitectures()); + library.AddArchitecture(new Trigonometry.CosecantArchitectures()); + library.AddArchitecture(new Trigonometry.HyperbolicSineArchitectures()); + library.AddArchitecture(new Trigonometry.HyperbolicCosineArchitectures()); + library.AddArchitecture(new Trigonometry.HyperbolicTangentArchitectures()); + library.AddArchitecture(new Trigonometry.HyperbolicCotangentArchitectures()); + library.AddArchitecture(new Trigonometry.HyperbolicSecantArchitectures()); + library.AddArchitecture(new Trigonometry.HyperbolicCosecantArchitectures()); + #endregion + #region Logic + library.AddArchitecture(new Logic.AndArchitectures()); + library.AddArchitecture(new Logic.NandArchitectures()); + library.AddArchitecture(new Logic.OrArchitectures()); + library.AddArchitecture(new Logic.NorArchitectures()); + library.AddArchitecture(new Logic.XorArchitectures()); + library.AddArchitecture(new Logic.XnorArchitectures()); + library.AddArchitecture(new Logic.NotArchitectures()); + #endregion + #region Algebra & Analysis + library.AddArchitecture(new Analysis.AlgebraicDerivativeArchitecture()); + library.AddArchitecture(new Algebra.AutoSimplifyArchitecture()); + #endregion + #region Flow + library.AddArchitecture(new Flow.TransportArchitecture()); + library.AddArchitecture(new Flow.SyncArchitecture()); + library.AddArchitecture(new Flow.ClockArchitecture()); + #endregion + } + + public void RegisterTheorems(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + #region Arithmetics + Arithmetics.AdditionArchitectures.RegisterTheorems(library); + Arithmetics.SubtractionArchitectures.RegisterTheorems(library); + Arithmetics.MultiplicationArchitectures.RegisterTheorems(library); + Arithmetics.DivisionArchitectures.RegisterTheorems(library); + Arithmetics.NegateArchitectures.RegisterTheorems(library); + Arithmetics.InvertArchitectures.RegisterTheorems(library); + Arithmetics.AbsoluteArchitectures.RegisterTheorems(library); + Arithmetics.ExponentialArchitectures.RegisterTheorems(library); + Arithmetics.NaturalLogarithmArchitectures.RegisterTheorems(library); + Arithmetics.SquareArchitectures.RegisterTheorems(library); + Arithmetics.PowerArchitectures.RegisterTheorems(library); + #endregion + #region Trigonometry + Trigonometry.SineArchitectures.RegisterTheorems(library); + Trigonometry.CosineArchitectures.RegisterTheorems(library); + Trigonometry.TangentArchitectures.RegisterTheorems(library); + Trigonometry.CotangentArchitectures.RegisterTheorems(library); + Trigonometry.SecantArchitectures.RegisterTheorems(library); + Trigonometry.CosecantArchitectures.RegisterTheorems(library); + Trigonometry.HyperbolicSineArchitectures.RegisterTheorems(library); + Trigonometry.HyperbolicCosineArchitectures.RegisterTheorems(library); + Trigonometry.HyperbolicTangentArchitectures.RegisterTheorems(library); + Trigonometry.HyperbolicCotangentArchitectures.RegisterTheorems(library); + Trigonometry.HyperbolicSecantArchitectures.RegisterTheorems(library); + Trigonometry.HyperbolicCosecantArchitectures.RegisterTheorems(library); + #endregion + #region Flow + Flow.TransportArchitecture.RegisterTheorems(library); + #endregion + #region Other + Algebra.AutoSimplifyArchitecture.RegisterTheorems(library); + #endregion + } + + public void RegisterStructures(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + Packages.Standard.Structures.IntegerValue.Register(library); + Packages.Standard.Structures.RationalValue.Register(library); + Packages.Standard.Structures.RealValue.Register(library); + Packages.Standard.Structures.ComplexValue.Register(library); + + Packages.Standard.Structures.LiteralValue.Register(library); + Packages.Standard.Structures.LogicValue.Register(library); + Packages.Standard.Structures.ToggleValue.Register(library); + + Packages.Standard.Structures.UndefinedSymbol.Register(library); + Packages.Standard.Structures.NegativeInfinitySymbol.Register(library); + Packages.Standard.Structures.PositiveInfinitySymbol.Register(library); + Packages.Standard.Structures.ComplexInfinitySymbol.Register(library); + + Packages.Standard.Structures.VectorValue.Register(library); + Packages.Standard.Structures.VectorValue.Register(library); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexInfinitySymbol.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexInfinitySymbol.cs new file mode 100644 index 0000000..72c16a7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexInfinitySymbol.cs @@ -0,0 +1,130 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// symbol: complex infinity + public sealed class ComplexInfinitySymbol : ValueStructureBase, IEquatable, IComparable + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("ComplexInfinity", "Std"); + private ComplexInfinitySymbol() { } + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(Instance); + //library.AddCustomDataType(new CustomDataRef(typeof(ComplexInfinitySymbol), ValueConverter.Router, Instance)); + ValueConverter.AddConverterFrom(false, ConvertFrom); + ValueConverter.AddConverterFrom(false, ConvertFrom); + } + //public static ComplexInfinitySymbol ConvertFrom(IValueStructure value) + //{ + // return Instance; + //} + public static ComplexInfinitySymbol ConvertFrom(NegativeInfinitySymbol value) { return Instance; } + public static explicit operator ComplexInfinitySymbol(NegativeInfinitySymbol value) { return Instance; } + public static ComplexInfinitySymbol ConvertFrom(PositiveInfinitySymbol value) { return Instance; } + public static explicit operator ComplexInfinitySymbol(PositiveInfinitySymbol value) { return Instance; } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Singleton + private static ComplexInfinitySymbol _instance; + public static ComplexInfinitySymbol Instance + { + get + { + if(_instance == null) + _instance = new ComplexInfinitySymbol(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public static Signal Constant + { + get + { + MathIdentifier id = _customTypeId.DerivePostfix("Constant"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Binder.CreateSignal(Instance); + ret.Label = "ComplexInfinity"; + ret.EnableFlag(StdAspect.ConstantFlag); + //ret.AddConstraint(Properties.ConstantSignalProperty.Instance); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public override bool Equals(IValueStructure other) + { + return other is ComplexInfinitySymbol; + } + public bool Equals(ComplexInfinitySymbol other) + { + return true; + } + public int CompareTo(ComplexInfinitySymbol other) + { + return 0; + } + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + //} + //private static ComplexInfinitySymbol InnerDeserialize(IContext context, XmlReader reader) + //{ + // return ComplexInfinitySymbol._instance; + //} + private static ComplexInfinitySymbol Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return ComplexInfinitySymbol._instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexValue.cs new file mode 100644 index 0000000..44304c9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexValue.cs @@ -0,0 +1,519 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Numerics; +using MathNet.Symbolics.Packages.Standard.Trigonometry; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// complex numbers with signed real components + public class ComplexValue : ValueStructureBase, IEquatable, IComparable, IAlgebraicField, IFormattableLeaf + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Complex", "Std"); + private readonly Complex _dataValue; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + //library.AddCustomDataType(new CustomDataRef(typeof(ComplexValue), ValueConverter.Router)); + ValueConverter.AddConverterFrom(true, ConvertFrom); + ValueConverter.AddConverterFrom(true, ConvertFrom); + ValueConverter.AddConverterFrom(true, ConvertFrom); + ValueConverter.AddConverterTo(ValueConverter.Router, false, + delegate(object value) { return new RealValue(((ComplexValue)value).RealValue); }); + } + public static ComplexValue ConvertFrom(ICustomData value) + { + return (ComplexValue)ValueConverter.ConvertFrom(value); + } + public static ComplexValue ConvertFrom(IntegerValue value) { return new ComplexValue(value); } + public static explicit operator ComplexValue(IntegerValue value) { return new ComplexValue(value); } + public static ComplexValue ConvertFrom(RationalValue value) { return new ComplexValue(value); } + public static explicit operator ComplexValue(RationalValue value) { return new ComplexValue(value); } + public static ComplexValue ConvertFrom(RealValue value) { return new ComplexValue(value); } + public static explicit operator ComplexValue(RealValue value) { return new ComplexValue(value); } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public ComplexValue() + { + } + public ComplexValue(Complex value) + { + _dataValue = value; + } + public ComplexValue(double realValue) + { + _dataValue.Real = realValue; + } + public ComplexValue(double realValue, double imagValue) + { + _dataValue = Complex.FromRealImaginary(realValue, imagValue); + } + public ComplexValue(IntegerValue realValue) + { + _dataValue.Real = realValue.ToDouble(); + } + public ComplexValue(RationalValue realValue) + { + _dataValue.Real = realValue.ToDouble(); + } + public ComplexValue(RealValue realValue) + { + _dataValue.Real = realValue.Value; + } + public ComplexValue(RealValue realValue, RealValue imagValue) + { + _dataValue = Complex.FromRealImaginary(realValue.Value, imagValue.Value); + } + #endregion + + public Complex Value + { + get { return _dataValue; } + } + public double RealValue + { + get { return _dataValue.Real; } + } + public double ImaginaryValue + { + get { return _dataValue.Imag; } + } + public double Modulus + { + get { return _dataValue.Modulus; } + } + public double ModulusSquared + { + get { return _dataValue.ModulusSquared; } + } + public double Argument + { + get { return _dataValue.Argument; } + } + public bool IsZero + { + get { return _dataValue.IsZero; } + } + public bool IsReal + { + get { return _dataValue.IsReal; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Function Implementations + #region Arithmetic Function + public static ComplexValue Add(ComplexValue summand1, ComplexValue summand2) { return summand1.Add(summand2); } + public ComplexValue Add(ComplexValue summand) + { + return new ComplexValue(_dataValue + summand._dataValue); + } + public static ComplexValue Subtract(ComplexValue minuend, ComplexValue subtrahend) { return minuend.Subtract(subtrahend); } + public ComplexValue Subtract(ComplexValue subtrahend) + { + return new ComplexValue(_dataValue - subtrahend._dataValue); + } + public static ComplexValue Negate(ComplexValue subtrahend) { return subtrahend.Negate(); } + public ComplexValue Negate() + { + return new ComplexValue(-_dataValue); + } + public static ComplexValue Conjugate(ComplexValue complex) { return complex.Conjugate(); } + public ComplexValue Conjugate() + { + return new ComplexValue(_dataValue.Conjugate); + } + public static ComplexValue Multiply(ComplexValue multiplicand, ComplexValue multiplier) { return multiplicand.Multiply(multiplier); } + public ComplexValue Multiply(ComplexValue multiplier) + { + return new ComplexValue(_dataValue * multiplier._dataValue); + } + public static ComplexValue Divide(ComplexValue dividend, ComplexValue divisor) { return dividend.Divide(divisor); } + public ComplexValue Divide(ComplexValue divisor) + { + //if(op.IsZero) + // return ComplexInfinitySymbol.Symbol; + return new ComplexValue(_dataValue / divisor._dataValue); + } + public static ComplexValue Invert(ComplexValue divisor) { return divisor.Invert(); } + public ComplexValue Invert() + { + //if(IsZero) + // return ComplexInfinitySymbol.Symbol; + double mod2 = _dataValue.ModulusSquared; + return new ComplexValue(_dataValue.Real / mod2, -_dataValue.Imag / mod2); + } + public static RealValue Absolute(ComplexValue complex) { return complex.Absolute(); } + public RealValue Absolute() + { + return new RealValue(_dataValue.Modulus); + } + public ComplexValue Scale(ComplexValue scalar) + { + return Multiply(scalar); + } + #endregion + #region Exponential Functions + public static ComplexValue Exponential(ComplexValue exponent) { return exponent.Exponential(); } + public ComplexValue Exponential() + { + return new ComplexValue(_dataValue.Exponential()); + } + public static ComplexValue NaturalLogarithm(ComplexValue antilogarithm) { return antilogarithm.NaturalLogarithm(); } + public ComplexValue NaturalLogarithm() + { + return new ComplexValue(_dataValue.NaturalLogarithm()); + } + public static ComplexValue Power(ComplexValue radix, ComplexValue exponent) { return radix.Power(exponent); } + public ComplexValue Power(ComplexValue exponent) + { + return new ComplexValue(_dataValue.Power(exponent.Value)); + } + public ComplexValue PositiveIntegerPower(int exponent) + { + return new ComplexValue(_dataValue.Power(exponent)); + } + public ComplexValue IntegerPower(int exponent) + { + return new ComplexValue(_dataValue.Power(exponent)); + } + public static ComplexValue Root(ComplexValue radicand, ComplexValue rootexponent) { return radicand.Root(rootexponent); } + public ComplexValue Root(ComplexValue rootexponent) + { + return new ComplexValue(_dataValue.Root(rootexponent.Value)); + } + public static ComplexValue Square(ComplexValue radix) { return radix.Square(); } + public ComplexValue Square() + { + return new ComplexValue(_dataValue.Square()); + } + public static ComplexValue SquareRoot(ComplexValue radicand) { return radicand.SquareRoot(); } + public ComplexValue SquareRoot() + { + return new ComplexValue(_dataValue.SquareRoot()); + } + #endregion + #region Trigonometric Functions + /// Trigonometric Sine (Sinus) of an angle in radians + public ComplexValue Sine() + { + return new ComplexValue(_dataValue.Sine()); + } + /// Trigonometric Cosine (Cosinus) of an angle in radians + public ComplexValue Cosine() + { + return new ComplexValue(_dataValue.Cosine()); + } + /// Trigonometric Tangent (Tangens) of an angle in radians + public ComplexValue Tangent() + { + return new ComplexValue(_dataValue.Tangent()); + } + /// Trigonometric Cotangent (Cotangens) of an angle in radians + public ComplexValue Cotangent() + { + return new ComplexValue(_dataValue.Cotangent()); + } + /// Trigonometric Secant (Sekans) of an angle in radians + public ComplexValue Secant() + { + return new ComplexValue(_dataValue.Secant()); + } + /// Trigonometric Cosecant (Cosekans) of an angle in radians + public ComplexValue Cosecant() + { + return new ComplexValue(_dataValue.Cosecant()); + } + #endregion + #region Trigonometric Inverse Functions + /// Trigonometric Arcus Sine (Arkussinus) in radians + public ComplexValue InverseSine() + { + return new ComplexValue(_dataValue.InverseSine()); + } + /// Trigonometric Arcus Cosine (Arkuscosinus) in radians + public ComplexValue InverseCosine() + { + return new ComplexValue(_dataValue.InverseCosine()); + } + /// Trigonometric Arcus Tangent (Arkustangens) in radians + public ComplexValue InverseTangent() + { + return new ComplexValue(_dataValue.InverseTangent()); + } + /// Trigonometric Arcus Cotangent (Arkuscotangens) in radians + public ComplexValue InverseCotangent() + { + return new ComplexValue(_dataValue.InverseCotangent()); + } + /// Trigonometric Arcus Secant (Arkussekans) in radians + public ComplexValue InverseSecant() + { + return new ComplexValue(_dataValue.InverseSecant()); + } + /// Trigonometric Arcus Cosecant (Arkuscosekans) in radians + public ComplexValue InverseCosecant() + { + return new ComplexValue(_dataValue.InverseCosecant()); + } + #endregion + #region Hyperbolic Functions + /// Trigonometric Hyperbolic Sine (Sinus hyperbolicus) + public ComplexValue HyperbolicSine() + { + return new ComplexValue(_dataValue.HyperbolicSine()); + } + /// Trigonometric Hyperbolic Cosine (Cosinus hyperbolicus) + public ComplexValue HyperbolicCosine() + { + return new ComplexValue(_dataValue.HyperbolicCosine()); + } + /// Trigonometric Hyperbolic Tangent (Tangens hyperbolicus) + public ComplexValue HyperbolicTangent() + { + return new ComplexValue(_dataValue.HyperbolicTangent()); + } + /// Trigonometric Hyperbolic Cotangent (Cotangens hyperbolicus) + public ComplexValue HyperbolicCotangent() + { + return new ComplexValue(_dataValue.HyperbolicCotangent()); + } + /// Trigonometric Hyperbolic Secant (Sekans hyperbolicus) + public ComplexValue HyperbolicSecant() + { + return new ComplexValue(_dataValue.HyperbolicSecant()); + } + /// Trigonometric Hyperbolic Cosecant (Cosekans hyperbolicus) + public ComplexValue HyperbolicCosecant() + { + return new ComplexValue(_dataValue.HyperbolicCosecant()); + } + #endregion + #region Hyperbolic Area Functions + /// Trigonometric Hyperbolic Area Sine (Areasinus hyperbolicus) + public ComplexValue InverseHyperbolicSine() + { + return new ComplexValue(_dataValue.InverseHyperbolicSine()); + } + /// Trigonometric Hyperbolic Area Cosine (Areacosinus hyperbolicus) + public ComplexValue InverseHyperbolicCosine() + { + return new ComplexValue(_dataValue.InverseHyperbolicCosine()); + } + /// Trigonometric Hyperbolic Area Tangent (Areatangens hyperbolicus) + public ComplexValue InverseHyperbolicTangent() + { + return new ComplexValue(_dataValue.InverseHyperbolicTangent()); + } + /// Trigonometric Hyperbolic Area Cotangent (Areacotangens hyperbolicus) + public ComplexValue InverseHyperbolicCotangent() + { + return new ComplexValue(_dataValue.InverseHyperbolicCotangent()); + } + /// Trigonometric Hyperbolic Area Secant (Areasekans hyperbolicus) + public ComplexValue InverseHyperbolicSecant() + { + return new ComplexValue(_dataValue.InverseHyperbolicSecant()); + } + /// Trigonometric Hyperbolic Area Cosecant (Areacosekans hyperbolicus) + public ComplexValue InverseHyperbolicCosecant() + { + return new ComplexValue(_dataValue.InverseHyperbolicCosecant()); + } + #endregion + #endregion + + #region Constants + public static Signal Constant(Complex value) + { + return Constant(value, value.ToString()); + } + public static Signal Constant(Complex value, string name) + { + Signal s = Binder.CreateSignal(new ComplexValue(value)); + s.Label = name + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + //s.AddConstraint(Properties.ConstantSignalProperty.Instance); + return s; + } + + public static ComplexValue I + { + get { return new ComplexValue(Complex.I); } //TODO: Think about Singleton like design... + } + + public static ComplexValue Zero + { + get { return new ComplexValue(Complex.Zero); } //TODO: Think about Singleton like design... + } + + public static ComplexValue One + { + get { return new ComplexValue(Complex.One); } //TODO: Think about Singleton like design... + } + + public static ComplexValue AdditiveIdentity + { + get { return new ComplexValue(Complex.Zero); } //TODO: Think about Singleton like design... + } + + public static ComplexValue MultiplicativeIdentity + { + get { return new ComplexValue(Complex.One); } //TODO: Think about Singleton like design... + } + #endregion + + public bool Equals(RealValue other) + { + return other != null && _dataValue.IsReal && _dataValue.Real == other.Value; + } + public bool Equals(RationalValue other) + { + return other != null && _dataValue.IsReal && _dataValue.Real == other.ToDouble(); + } + public bool Equals(IntegerValue other) + { + return other != null && _dataValue.IsReal && _dataValue.Real == other.ToDouble(); + } + public override bool Equals(IValueStructure other) + { + IntegerValue integerValue = other as IntegerValue; + if(integerValue != null) + return Equals(integerValue); + + RationalValue rationalValue = other as RationalValue; + if(rationalValue != null) + return Equals(rationalValue); + + RealValue realValue = other as RealValue; + if(realValue != null) + return Equals(realValue); + + ComplexValue complexValue = other as ComplexValue; + if(complexValue != null) + return Equals(complexValue); + + return other == this; + } + public bool Equals(ComplexValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public int CompareTo(ComplexValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region IAlgebraicMultiplicativeIdentityElement Members + public bool IsMultiplicativeIdentity + { + get { return _dataValue.IsOne; } + } + IValueStructure IAlgebraicMultiplicativeIdentityElement.MultiplicativeIdentity + { + get { return MultiplicativeIdentity; } + } + #endregion + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get { return _dataValue.IsZero; } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // writer.WriteElementString("Real", _dataValue.Real.ToString(Config.InternalNumberFormat)); + // writer.WriteElementString("Imag", _dataValue.Imag.ToString(Config.InternalNumberFormat)); + //} + //private static ComplexValue InnerDeserialize(IContext context, XmlReader reader) + //{ + // return new ComplexValue(double.Parse(reader.ReadElementString("Real"), Config.InternalNumberFormat), + // double.Parse(reader.ReadElementString("Imag"), Config.InternalNumberFormat)); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteElementString("Real", _dataValue.Real.ToString(Config.InternalNumberFormat)); + writer.WriteElementString("Imag", _dataValue.Imag.ToString(Config.InternalNumberFormat)); + } + private static ComplexValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new ComplexValue(double.Parse(reader.ReadElementString("Real"), Config.InternalNumberFormat), + double.Parse(reader.ReadElementString("Imag"), Config.InternalNumberFormat)); + } + #endregion + + #region Formatting + private string FormatImpl(out int precedence) + { + if(!_dataValue.IsReal && !_dataValue.IsImaginary) + precedence = 60; + else if(_dataValue.IsReal) + precedence = -1; + else + precedence = 50; + + System.Globalization.NumberFormatInfo format = System.Globalization.NumberFormatInfo.InvariantInfo; + return _dataValue.ToString(format); + } + public override string ToString() + { + int precedence; + return FormatBase(FormatImpl(out precedence), FormattingOptions.Default); + } + string IFormattableLeaf.Format(FormattingOptions options, out int precedence) + { + return FormatBase(FormatImpl(out precedence), options); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexValueCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexValueCategory.cs new file mode 100644 index 0000000..553bd73 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ComplexValueCategory.cs @@ -0,0 +1,94 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// + /// The category C: set of all complex numbers. + /// + public class ComplexValueCategory : CategoryBase + { + protected ComplexValueCategory() + : base("ComplexValueExpression", "Std") { } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return CategoryMembershipLevel.Unknown; + if(signal.Value is ComplexValue || signal.Value is RealValue || signal.Value is RationalValue || signal.Value is IntegerValue) + return CategoryMembershipLevel.Member; + return CategoryMembershipLevel.NotMember; + } + + public override CategoryMembershipLevel IsMember(Port port) + { + return EvaluateJointChildMembership(port.InputSignals); + } + + #region Singleton + private static ComplexValueCategory _instance; + public static ComplexValueCategory Instance + { + get + { + if(_instance == null) + _instance = new ComplexValueCategory(); + return _instance; + } + } + #endregion + + public static bool IsComplexValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.Member); + } + public static bool IsNotRealValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.NotMember); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //protected static ComplexValueCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static ComplexValueCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/IntegerValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/IntegerValue.cs new file mode 100644 index 0000000..362addf --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/IntegerValue.cs @@ -0,0 +1,480 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// signed integer + public class IntegerValue : ValueStructureBase, IEquatable, IComparable, IAlgebraicIntegralDomain, IFormattableLeaf + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Integer", "Std"); + private readonly long _dataValue; // = 0; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + library.AddArbitraryType(typeof(long)); + ValueConverter.AddConverterFrom(ValueConverter.Router, true, + delegate(object value) { return new IntegerValue((long)value); }); + ValueConverter.AddConverterTo(ValueConverter.Router, true, + delegate(object value) { return ((IntegerValue)value).Value; }); + + //library.AddCustomDataType(new CustomDataRef(typeof(IntegerValue), ValueConverter.Router)); + } + public static IntegerValue ConvertFrom(ICustomData value) + { + return (IntegerValue)ValueConverter.ConvertFrom(value); + } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public IntegerValue() + { + //this.dataValue = 0; + } + public IntegerValue(long value) + { + _dataValue = value; + } + #endregion + + #region Basic Operation Processes + internal class AddProcess : GenericFunctionProcess + { + public AddProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public AddProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(IntegerValue.AdditiveIdentity); + else + { + IntegerValue sum = (IntegerValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + { + IntegerValue integer = (IntegerValue)Inputs[i].Value; + sum = sum.Add(integer); + } + PublishToOutputs(sum); + } + } + } + internal class SubtractProcess : GenericFunctionProcess + { + public SubtractProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public SubtractProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(IntegerValue.AdditiveIdentity); + else + { + IntegerValue sum = (IntegerValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + { + IntegerValue integer = (IntegerValue)Inputs[i].Value; + sum = sum.Subtract(integer); + } + PublishToOutputs(sum); + } + } + } + internal class MultiplyProcess : GenericFunctionProcess + { + public MultiplyProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public MultiplyProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(IntegerValue.MultiplicativeIdentity); + else + { + IntegerValue product = (IntegerValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + { + IntegerValue integer = (IntegerValue)Inputs[i].Value; + product = product.Multiply(integer); + } + PublishToOutputs(product); + } + } + } + internal class DivideProcess : GenericFunctionProcess + { + public DivideProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public DivideProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RationalValue.MultiplicativeIdentity); + else + { + RationalValue product = new RationalValue((IntegerValue)Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + IntegerValue integer = (IntegerValue)Inputs[i].Value; + product = product.Divide(integer); + } + PublishToOutputs(product); + } + } + } + #endregion + + public long Value + { + get { return _dataValue; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Operator Implementations + public static bool operator <(IntegerValue left, IntegerValue right) + { + return left._dataValue < right._dataValue; + } + public static bool operator >(IntegerValue left, IntegerValue right) + { + return left._dataValue > right._dataValue; + } + #endregion + + #region Direct Function Implementations + #region Arithmetic Operations + public IntegerValue Add(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new IntegerValue(_dataValue + op._dataValue); + } + public IntegerValue Subtract(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new IntegerValue(_dataValue - op._dataValue); + } + public IntegerValue Negate() + { + return new IntegerValue(-_dataValue); + } + public IntegerValue Multiply(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new IntegerValue(_dataValue * op._dataValue); + } + public RationalValue Divide(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue(_dataValue, op._dataValue); + } + public RationalValue Invert() + { + return new RationalValue(1, _dataValue); + } + + public IntegerValue PositiveIntegerPower(int op) + { + if(op == 1) + return this; + if(op == 0) + return _dataValue == 0 ? IntegerValue.Zero : IntegerValue.One; + return new IntegerValue(MathNet.Numerics.Fn.IntPow(_dataValue, (uint)op)); + } + public RationalValue IntegerPower(int op) + { + if(op == 1) + return new RationalValue(this); + if(op == 0) + return _dataValue == 0 ? RationalValue.Zero : RationalValue.One; + if(op > 1) + return new RationalValue(MathNet.Numerics.Fn.IntPow(_dataValue, (uint)op), 1); + return new RationalValue(1, MathNet.Numerics.Fn.IntPow(_dataValue, (uint)-op)); + } + public IntegerValue Power(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + // TODO: get rid of this + return new IntegerValue((long)Math.Round(Math.Pow(_dataValue, op._dataValue))); + } + public IntegerValue Absolute() + { + return (_dataValue < 0) ? new IntegerValue(-_dataValue) : this; + } + public IntegerValue Max(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return (_dataValue >= op._dataValue) ? this : op; + } + public IntegerValue Min(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return (_dataValue <= op._dataValue) ? this : op; + } + #endregion + #endregion + + #region Constants + public static Signal ParseConstant(string value) + { + return Constant(long.Parse(value, Config.InternalNumberFormat)); + } + public static Signal Constant(long value) + { + Signal s = Binder.CreateSignal(new IntegerValue(value)); + s.Label = s.Value.ToString() + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + //s.AddConstraint(Properties.ConstantSignalProperty.Instance); + return s; + } + + public static Signal ConstantZero + { + get + { + MathIdentifier id = new MathIdentifier("IntegerValueConstantZero", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(0); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static Signal ConstantOne + { + get + { + MathIdentifier id = new MathIdentifier("IntegerValueConstantOne", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(1); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static Signal ConstantTwo + { + get + { + MathIdentifier id = new MathIdentifier("IntegerValueConstantTwo", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(2); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static Signal ConstantMinusOne + { + get + { + MathIdentifier id = new MathIdentifier("IntegerValueConstantMinusOne", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(-1); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static Signal ConstantAdditiveIdentity + { + get { return ConstantZero; } + } + + public static Signal ConstantMultiplicativeIdentity + { + get { return ConstantOne; } + } + + public static IntegerValue Zero + { + get { return new IntegerValue(0); } //TODO: Think about Singleton like design... + } + + public static IntegerValue One + { + get { return new IntegerValue(1); } //TODO: Think about Singleton like design... + } + + public static IntegerValue AdditiveIdentity + { + get { return new IntegerValue(0); } //TODO: Think about Singleton like design... + } + + public static IntegerValue MultiplicativeIdentity + { + get { return new IntegerValue(1); } //TODO: Think about Singleton like design... + } + #endregion + + public double ToDouble() + { + return (double)_dataValue; + } + + public override bool Equals(IValueStructure other) + { + IntegerValue integerValue = other as IntegerValue; + if(integerValue != null) + return Equals(integerValue); + + RationalValue rationalValue = other as RationalValue; + if(rationalValue != null) + return rationalValue.Equals(this); + + RealValue realValue = other as RealValue; + if(realValue != null) + return realValue.Equals(this); + + return other == this; + } + public bool Equals(IntegerValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public int CompareTo(IntegerValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region IAlgebraicMultiplicativeIdentityElement Members + public bool IsMultiplicativeIdentity + { + get { return _dataValue == 1; } + } + IValueStructure IAlgebraicMultiplicativeIdentityElement.MultiplicativeIdentity + { + get { return MultiplicativeIdentity; } + } + #endregion + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get { return _dataValue == 0; } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // writer.WriteString(_dataValue.ToString(Config.InternalNumberFormat)); + //} + //private static IntegerValue InnerDeserialize(IContext context, XmlReader reader) + //{ + // return new IntegerValue(long.Parse(reader.ReadString(), Config.InternalNumberFormat)); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteString(_dataValue.ToString(Config.InternalNumberFormat)); + } + private static IntegerValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new IntegerValue(long.Parse(reader.ReadString(), Config.InternalNumberFormat)); + } + #endregion + + #region Formatting + public override string ToString() + { + IFormatProvider format = System.Globalization.NumberFormatInfo.InvariantInfo; + return FormatBase(_dataValue.ToString(format), FormattingOptions.Default); + } + string IFormattableLeaf.Format(FormattingOptions options, out int precedence) + { + precedence = _dataValue < 0 ? 20 : -1; + IFormatProvider format = System.Globalization.NumberFormatInfo.InvariantInfo; + return FormatBase(_dataValue.ToString(format), options); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/IntegerValueCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/IntegerValueCategory.cs new file mode 100644 index 0000000..0ec5663 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/IntegerValueCategory.cs @@ -0,0 +1,94 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// + /// The category Z: ordered set of all signed integers + /// + public class IntegerValueCategory : CategoryBase + { + protected IntegerValueCategory() + : base("IntegerValueExpression", "Std") { } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return CategoryMembershipLevel.Unknown; + if(signal.Value is IntegerValue) + return CategoryMembershipLevel.Member; + return CategoryMembershipLevel.NotMember; + } + + public override CategoryMembershipLevel IsMember(Port port) + { + return EvaluateJointChildMembership(port.InputSignals); + } + + #region Singleton + private static IntegerValueCategory _instance; + public static IntegerValueCategory Instance + { + get + { + if(_instance == null) + _instance = new IntegerValueCategory(); + return _instance; + } + } + #endregion + + public static bool IsIntegerValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.Member); + } + public static bool IsNotIntegerValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.NotMember); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //public static IntegerValueCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static IntegerValueCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LiteralValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LiteralValue.cs new file mode 100644 index 0000000..6f90552 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LiteralValue.cs @@ -0,0 +1,192 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// string literal + public class LiteralValue : ValueStructureBase, IEquatable, IComparable, IFormattableLeaf + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Literal", "Std"); + private readonly string _dataValue; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + //library.AddCustomDataType(new CustomDataRef(typeof(LiteralValue), ValueConverter.Router)); + ValueConverter.AddConverterFrom(true, ConvertFrom); + } + public static LiteralValue ConvertFrom(ICustomData value) + { + return (LiteralValue)ValueConverter.ConvertFrom(value); + } + public static LiteralValue ConvertFrom(IntegerValue value) { return new LiteralValue(value.ToString()); } + public static explicit operator LiteralValue(IntegerValue value) { return new LiteralValue(value.ToString()); } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public LiteralValue() + { + _dataValue = string.Empty; + } + public LiteralValue(string value) + { + _dataValue = value; + } + #endregion + + public string Value + { + get { return _dataValue; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Function Implementations + public LiteralValue Concatenate(LiteralValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new LiteralValue(_dataValue + op._dataValue); + } + #endregion + + #region Constants + public static Signal ParseConstant(string value) + { + if(value == null) + throw new ArgumentNullException("value"); + + return Constant(value.Trim()); + } + public static Signal Constant(string value) + { + Signal s = Binder.CreateSignal(new LiteralValue(value)); + s.Label = s.Value.ToString() + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + //s.AddConstraint(Properties.ConstantSignalProperty.Instance); + return s; + } + + public static Signal ConstantEmpty + { + get + { + MathIdentifier id = new MathIdentifier("LiteralValueConstantEmpty", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(string.Empty); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static LiteralValue Empty + { + get { return new LiteralValue(string.Empty); } //TODO: Think about Singleton like design... + } + #endregion + + public override bool Equals(IValueStructure other) + { + LiteralValue literalValue = other as LiteralValue; + if(literalValue != null) + return Equals(literalValue); + + return other == this; + } + public bool Equals(LiteralValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public int CompareTo(LiteralValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // writer.WriteString(_dataValue); + //} + //private static LiteralValue InnerDeserialize(IContext context, XmlReader reader) + //{ + // return new LiteralValue(reader.ReadString()); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteString(_dataValue); + } + private static LiteralValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new LiteralValue(reader.ReadString()); + } + #endregion + + #region Formatting + private string FormatImpl() + { + // character-stuffing + return "\"" + _dataValue.Replace("\"","\"\"") + "\""; + } + public override string ToString() + { + return FormatBase(FormatImpl(), FormattingOptions.Default); + } + string IFormattableLeaf.Format(FormattingOptions options, out int precedence) + { + precedence = -1; + return FormatBase(FormatImpl(), options); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LogicValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LogicValue.cs new file mode 100644 index 0000000..fdfe361 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LogicValue.cs @@ -0,0 +1,557 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + public enum ELogicX01 + { + Unknown, + True, + False + } + + public enum ELogicIeee1164 + { + Uninitialized, + ForcingUnknown, + ForcingZero, + ForcingOne, + HighImpedance, + WeakUnknown, + WeakZero, + WeakOne, + DoNotCare + } + + /// logic value - X01 subset of IEEE 1164 standard (aka MVL-9) + public class LogicValue : ValueStructureBase, IEquatable, IComparable, IAlgebraicBooleanAlgebra, IFormattableLeaf + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Logic", "Std"); + private readonly ELogicX01 _dataValue; // = ELogicX01.Uninitialized; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + //library.AddCustomDataType(new CustomDataRef(typeof(LogicValue), ValueConverter.Router)); + ValueConverter.AddConverterFrom(ValueConverter.Router, false, + delegate(object value) { return new LogicValue(((IntegerValue)value).Value == 0 ? ELogicX01.False : ELogicX01.True); }); + } + public static LogicValue ConvertFrom(ICustomData value) + { + return (LogicValue)ValueConverter.ConvertFrom(value); + } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + protected LogicValue() + { + _dataValue = ELogicX01.Unknown; + } + protected LogicValue(ELogicX01 value) + { + _dataValue = value; + } + #endregion + + #region Basic Operation Processes + // ### AND ### + public static ProcessBase CreateAndProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.True; }, + delegate(LogicValue accu, LogicValue item) { return accu.And(item); }, + inInput, inInternal, outOutput, outInternal); + } + public static ProcessBase CreateAndProcess(int firstInput, int lastInput, int output) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.True; }, + delegate(LogicValue accu, LogicValue item) { return accu.And(item); }, + firstInput, lastInput, output); + } + // ### NAND ### + public static ProcessBase CreateNandProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.False; }, + delegate(LogicValue accu, LogicValue item) { return accu.Nand(item); }, + inInput, inInternal, outOutput, outInternal); + } + public static ProcessBase CreateNandProcess(int firstInput, int lastInput, int output) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.False; }, + delegate(LogicValue accu, LogicValue item) { return accu.Nand(item); }, + firstInput, lastInput, output); + } + // ### OR ### + public static ProcessBase CreateOrProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.False; }, + delegate(LogicValue accu, LogicValue item) { return accu.Or(item); }, + inInput, inInternal, outOutput, outInternal); + } + public static ProcessBase CreateOrProcess(int firstInput, int lastInput, int output) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.False; }, + delegate(LogicValue accu, LogicValue item) { return accu.Or(item); }, + firstInput, lastInput, output); + } + // ### NOR ### + public static ProcessBase CreateNorProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.True; }, + delegate(LogicValue accu, LogicValue item) { return accu.Nor(item); }, + inInput, inInternal, outOutput, outInternal); + } + public static ProcessBase CreateNorProcess(int firstInput, int lastInput, int output) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.True; }, + delegate(LogicValue accu, LogicValue item) { return accu.Nor(item); }, + firstInput, lastInput, output); + } + // ### XOR ### + public static ProcessBase CreateXorProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.Unknown; }, + delegate(LogicValue accu, LogicValue item) { return accu.Xor(item); }, + inInput, inInternal, outOutput, outInternal); + } + public static ProcessBase CreateXorProcess(int firstInput, int lastInput, int output) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.Unknown; }, + delegate(LogicValue accu, LogicValue item) { return accu.Xor(item); }, + firstInput, lastInput, output); + } + // ### XNOR ### + public static ProcessBase CreateXnorProcess(bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.Unknown; }, + delegate(LogicValue accu, LogicValue item) { return accu.Xnor(item); }, + inInput, inInternal, outOutput, outInternal); + } + public static ProcessBase CreateXnorProcess(int firstInput, int lastInput, int output) + { + return new GenericStdFunctionProcess( + delegate() { return LogicValue.Unknown; }, + delegate(LogicValue accu, LogicValue item) { return accu.Xnor(item); }, + firstInput, lastInput, output); + } + // ### NOT ### + public static ProcessBase CreateNotProcess(int firstInput, int firstOutput, int count, bool inputIsInternal, bool outputIsInternal) + { + return new GenericStdParallelProcess( + delegate(LogicValue item) { return item.Not(); }, + firstInput, firstOutput, count, inputIsInternal, outputIsInternal); + } + + #region OLD Implementations (commented out) + /* + public class AndProcess : GenericFunctionProcess + { + public AndProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public AndProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action() + { + if(Inputs.Length == 0) + PublishToOutputs(LogicValue.True); + else + { + LogicValue lv = (LogicValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + lv = lv.And((LogicValue)Inputs[i].Value); + PublishToOutputs(lv); + } + } + } + public class NandProcess : GenericFunctionProcess + { + public NandProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public NandProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action() + { + if(Inputs.Length == 0) + PublishToOutputs(LogicValue.False); + else + { + LogicValue lv = (LogicValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + lv = lv.Nand((LogicValue)Inputs[i].Value); + PublishToOutputs(lv); + } + } + } + public class OrProcess : GenericFunctionProcess + { + public OrProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public OrProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action() + { + if(Inputs.Length == 0) + PublishToOutputs(LogicValue.False); + else + { + LogicValue lv = (LogicValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + lv = lv.Or((LogicValue)Inputs[i].Value); + PublishToOutputs(lv); + } + } + } + public class NorProcess : GenericFunctionProcess + { + public NorProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public NorProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action() + { + if(Inputs.Length == 0) + PublishToOutputs(LogicValue.True); + else + { + LogicValue lv = (LogicValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + lv = lv.Nor((LogicValue)Inputs[i].Value); + PublishToOutputs(lv); + } + } + } + public class XorProcess : GenericFunctionProcess + { + public XorProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public XorProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action() + { + if(Inputs.Length == 0) + PublishToOutputs(LogicValue.Unknown); + else + { + LogicValue lv = (LogicValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + lv = lv.Xor((LogicValue)Inputs[i].Value); + PublishToOutputs(lv); + } + } + } + public class XnorProcess : GenericFunctionProcess + { + public XnorProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public XnorProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action() + { + if(Inputs.Length == 0) + PublishToOutputs(LogicValue.Unknown); + else + { + LogicValue lv = (LogicValue)Inputs[0].Value; + for(int i = 1; i < Inputs.Length; i++) + lv = lv.Xnor((LogicValue)Inputs[i].Value); + PublishToOutputs(lv); + } + } + } + */ + #endregion + #endregion + + public ELogicX01 Value + { + get { return _dataValue; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Logic Operations + public LogicValue And(LogicValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + if(_dataValue == ELogicX01.False || op._dataValue == ELogicX01.False) + return LogicValue.False; + if(_dataValue == ELogicX01.Unknown || op._dataValue == ELogicX01.Unknown) + return LogicValue.Unknown; + else + return LogicValue.True; + } + public LogicValue Nand(LogicValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + if(_dataValue == ELogicX01.False || op._dataValue == ELogicX01.False) + return LogicValue.True; + if(_dataValue == ELogicX01.Unknown || op._dataValue == ELogicX01.Unknown) + return LogicValue.Unknown; + else + return LogicValue.False; + } + public LogicValue Or(LogicValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + if(_dataValue == ELogicX01.True || op._dataValue == ELogicX01.True) + return LogicValue.True; + if(_dataValue == ELogicX01.Unknown || op._dataValue == ELogicX01.Unknown) + return LogicValue.Unknown; + else + return LogicValue.False; + } + public LogicValue Nor(LogicValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + if(_dataValue == ELogicX01.True || op._dataValue == ELogicX01.True) + return LogicValue.False; + if(_dataValue == ELogicX01.Unknown || op._dataValue == ELogicX01.Unknown) + return LogicValue.Unknown; + else + return LogicValue.True; + } + public LogicValue Xor(LogicValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + if(_dataValue == ELogicX01.Unknown || op._dataValue == ELogicX01.Unknown) + return LogicValue.Unknown; + if(_dataValue == op._dataValue) + return LogicValue.False; + else + return LogicValue.True; + } + public LogicValue Xnor(LogicValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + if(_dataValue == ELogicX01.Unknown || op._dataValue == ELogicX01.Unknown) + return LogicValue.Unknown; + if(_dataValue == op._dataValue) + return LogicValue.True; + else + return LogicValue.False; + } + public LogicValue Not() + { + if(_dataValue == ELogicX01.True) + return LogicValue.False; + if(_dataValue == ELogicX01.False) + return LogicValue.True; + else + return LogicValue.Unknown; + } + #endregion + + #region Arithmetic Operations + public LogicValue Add(LogicValue op) + { + return Or(op); + } + public LogicValue Multiply(LogicValue op) + { + return And(op); + } + public LogicValue PositiveIntegerPower(int op) + { + if(op > 0) + return this; + + if(op == 0) + return LogicValue.Zero; + + throw new NotSupportedException(); + } + #endregion + + #region Static Templates + private static readonly LogicValue logicTrue = new LogicValue(ELogicX01.True); + public static LogicValue True + { + get { return logicTrue; } + } + public static LogicValue One + { + get { return logicTrue; } + } + public static LogicValue MultiplicativeIdentity + { + get { return logicTrue; } + } + private static readonly LogicValue logicFalse = new LogicValue(ELogicX01.False); + public static LogicValue False + { + get { return logicFalse; } + } + public static LogicValue Zero + { + get { return logicFalse; } + } + public static LogicValue AdditiveIdentity + { + get { return logicFalse; } + } + private static readonly LogicValue logicUnknown = new LogicValue(ELogicX01.Unknown); + public static LogicValue Unknown + { + get { return logicUnknown; } + } + #endregion + + public override bool Equals(IValueStructure other) + { + LogicValue logicValue = other as LogicValue; + if(logicValue != null) + return Equals(logicValue); + + return other == this; + } + public bool Equals(LogicValue other) + { + return other != null && _dataValue == other._dataValue; + } + public int CompareTo(LogicValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region IAlgebraicMultiplicativeIdentityElement Members + public bool IsMultiplicativeIdentity + { + get { return _dataValue == ELogicX01.True ; } + } + IValueStructure IAlgebraicMultiplicativeIdentityElement.MultiplicativeIdentity + { + get { return MultiplicativeIdentity; } + } + #endregion + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get { return _dataValue == ELogicX01.False; } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + #region IAlgebraicBooleanAlgebra Members + public LogicValue Complement() + { + return Not(); + } + #endregion + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // writer.WriteString(_dataValue.ToString()); + //} + //private static LogicValue InnerDeserialize(IContext context, System.Xml.XmlReader reader) + //{ + // return new LogicValue((ELogicX01)Enum.Parse(typeof(ELogicX01), reader.ReadString())); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteString(_dataValue.ToString()); + } + private static LogicValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new LogicValue((ELogicX01)Enum.Parse(typeof(ELogicX01), reader.ReadString())); + } + #endregion + + #region Formatting + private string FormatImpl() + { + switch(_dataValue) + { + case ELogicX01.True: + return "1"; + case ELogicX01.False: + return "0"; + default: + return "X"; + } + } + public override string ToString() + { + return FormatBase(FormatImpl(), FormattingOptions.Default); + } + string IFormattableLeaf.Format(FormattingOptions options, out int precedence) + { + precedence = -1; + return FormatBase(FormatImpl(), options); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LogicValueCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LogicValueCategory.cs new file mode 100644 index 0000000..51b8ff4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/LogicValueCategory.cs @@ -0,0 +1,91 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + public class LogicValueCategory : CategoryBase + { + protected LogicValueCategory() + : base("LogicValueExpression", "Std") { } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return CategoryMembershipLevel.Unknown; + if(signal.Value is LogicValue) + return CategoryMembershipLevel.Member; + return CategoryMembershipLevel.NotMember; + } + + public override CategoryMembershipLevel IsMember(Port port) + { + return EvaluateJointChildMembership(port.InputSignals); + } + + #region Singleton + private static LogicValueCategory _instance; + public static LogicValueCategory Instance + { + get + { + if(_instance == null) + _instance = new LogicValueCategory(); + return _instance; + } + } + #endregion + + public static bool IsLogicValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.Member); + } + public static bool IsNotLogicValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.NotMember); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //protected static LogicValueCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static LogicValueCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/MatrixValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/MatrixValue.cs new file mode 100644 index 0000000..cbc2494 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/MatrixValue.cs @@ -0,0 +1,455 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + + +using MathNet.Symbolics.Backend; + + +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + //public sealed class MatrixValue : AbstractValueStructure, IEquatable>, IComparable> + // where T : ValueStructure, IEquatable, IComparable + //{ + // private readonly T[,] dataValue; + + // #region Conversion + // public static explicit operator ComplexValue(IntegerValue value) + // { + // return new ComplexValue(value); + // } + // public static explicit operator ComplexValue(RationalValue value) + // { + // return new ComplexValue(value); + // } + // public static explicit operator ComplexValue(RealValue value) + // { + // return new ComplexValue(value); + // } + // public static ComplexValue ConvertFrom(ValueStructure value) + // { + // ComplexValue cov = value as ComplexValue; + // if(cov != null) + // return cov; + + // RealValue rev = value as RealValue; + // if(rev != null) + // return new ComplexValue(rev); + + // RationalValue rav = value as RationalValue; + // if(rav != null) + // return new ComplexValue(rav); + + // IntegerValue inv = value as IntegerValue; + // if(inv != null) + // return new ComplexValue(inv); + + // throw new MathNet.Symbolics.Backend.Exceptions.StructureNotSupportedException(value); + // } + // public static bool IsConvertibleFrom(ValueStructure value) + // { + // return value != null && (value is ComplexValue || value is RealValue || value is RationalValue || value is IntegerValue); + // } + // #endregion + + // public MatrixValue() + // { + // } + // public MatrixValue(T[,] value) + // { + // dataValue = value; + // } + // public MatrixValue(IntegerValue realValue) + // { + // dataValue.Real = realValue.ToDouble(); + // } + // public MatrixValue(RationalValue realValue) + // { + // dataValue.Real = realValue.ToDouble(); + // } + // public MatrixValue(RealValue realValue) + // { + // dataValue.Real = realValue.Value; + // } + // public MatrixValue(RealValue realValue, RealValue imagValue) + // { + // dataValue = Complex.FromRealImaginary(realValue.Value, imagValue.Value); + // } + + // public Complex Value + // { + // get { return dataValue; } + // } + // public double RealValue + // { + // get { return dataValue.Real; } + // } + // public double ImaginaryValue + // { + // get { return dataValue.Imag; } + // } + // public double Modulus + // { + // get { return dataValue.Modulus; } + // } + // public double ModulusSquared + // { + // get { return dataValue.ModulusSquared; } + // } + // public double Argument + // { + // get { return dataValue.Argument; } + // } + // public bool IsZero + // { + // get { return dataValue.IsZero; } + // } + // public bool IsReal + // { + // get { return dataValue.IsReal; } + // } + + // #region Direct Function Implementations + // #region Arithmetic Function + // public static ComplexValue Add(ComplexValue summand1, ComplexValue summand2) { return summand1.Add(summand2); } + // public ComplexValue Add(ComplexValue summand) + // { + // return new ComplexValue(dataValue + summand.dataValue); + // } + // public static ComplexValue Subtract(ComplexValue minuend, ComplexValue subtrahend) { return minuend.Subtract(subtrahend); } + // public ComplexValue Subtract(ComplexValue subtrahend) + // { + // return new ComplexValue(dataValue - subtrahend.dataValue); + // } + // public static ComplexValue Negate(ComplexValue subtrahend) { return subtrahend.Negate(); } + // public ComplexValue Negate() + // { + // return new ComplexValue(-dataValue); + // } + // public static ComplexValue Conjugate(ComplexValue complex) { return complex.Conjugate(); } + // public ComplexValue Conjugate() + // { + // return new ComplexValue(dataValue.Conjugate); + // } + // public static ComplexValue Multiply(ComplexValue multiplicand, ComplexValue multiplier) { return multiplicand.Multiply(multiplier); } + // public ComplexValue Multiply(ComplexValue multiplier) + // { + // return new ComplexValue(dataValue * multiplier.dataValue); + // } + // public static ComplexValue Divide(ComplexValue dividend, ComplexValue divisor) { return dividend.Divide(divisor); } + // public ComplexValue Divide(ComplexValue divisor) + // { + // //if(op.IsZero) + // // return ComplexInfinitySymbol.Symbol; + // return new ComplexValue(dataValue / divisor.dataValue); + // } + // public static ComplexValue Invert(ComplexValue divisor) { return divisor.Invert(); } + // public ComplexValue Invert() + // { + // //if(IsZero) + // // return ComplexInfinitySymbol.Symbol; + // double mod2 = dataValue.ModulusSquared; + // return new ComplexValue(dataValue.Real / mod2, -dataValue.Imag / mod2); + // } + // public static RealValue Absolute(ComplexValue complex) { return complex.Absolute(); } + // public RealValue Absolute() + // { + // return new RealValue(dataValue.Modulus); + // } + // #endregion + // #region Exponential Functions + // public static ComplexValue Exponential(ComplexValue exponent) { return exponent.Exponential(); } + // public ComplexValue Exponential() + // { + // return new ComplexValue(dataValue.Exp()); + // } + // public static ComplexValue NaturalLogarithm(ComplexValue antilogarithm) { return antilogarithm.NaturalLogarithm(); } + // public ComplexValue NaturalLogarithm() + // { + // return new ComplexValue(dataValue.Ln()); + // } + // public static ComplexValue Power(ComplexValue radix, ComplexValue exponent) { return radix.Power(exponent); } + // public ComplexValue Power(ComplexValue exponent) + // { + // return new ComplexValue(dataValue.Pow(exponent.Value)); + // } + // public static ComplexValue Root(ComplexValue radicand, ComplexValue rootexponent) { return radicand.Root(rootexponent); } + // public ComplexValue Root(ComplexValue rootexponent) + // { + // return new ComplexValue(dataValue.Root(rootexponent.Value)); + // } + // public static ComplexValue Square(ComplexValue radix) { return radix.Square(); } + // public ComplexValue Square() + // { + // return new ComplexValue(dataValue.Square()); + // } + // public static ComplexValue SquareRoot(ComplexValue radicand) { return radicand.SquareRoot(); } + // public ComplexValue SquareRoot() + // { + // return new ComplexValue(dataValue.Sqrt()); + // } + // #endregion + // #region Trigonometric Functions + // /// Trigonometric Sine (Sinus) of an angle in radians + // public ComplexValue Sine() + // { + // return new ComplexValue(dataValue.Sin()); + // } + // /// Trigonometric Cosine (Cosinus) of an angle in radians + // public ComplexValue Cosine() + // { + // return new ComplexValue(dataValue.Cos()); + // } + // /// Trigonometric Tangent (Tangens) of an angle in radians + // public ComplexValue Tangent() + // { + // return new ComplexValue(dataValue.Tan()); + // } + // /// Trigonometric Cotangent (Cotangens) of an angle in radians + // public ComplexValue Cotangent() + // { + // return new ComplexValue(dataValue.Cot()); + // } + // /// Trigonometric Secant (Sekans) of an angle in radians + // public ComplexValue Secant() + // { + // return new ComplexValue(dataValue.Sec()); + // } + // /// Trigonometric Cosecant (Cosekans) of an angle in radians + // public ComplexValue Cosecant() + // { + // return new ComplexValue(dataValue.Csc()); + // } + // #endregion + // #region Trigonometric Inverse Functions + // /// Trigonometric Arcus Sine (Arkussinus) in radians + // public ComplexValue InverseSine() + // { + // return new ComplexValue(dataValue.Asin()); + // } + // /// Trigonometric Arcus Cosine (Arkuscosinus) in radians + // public ComplexValue InverseCosine() + // { + // return new ComplexValue(dataValue.Acos()); + // } + // /// Trigonometric Arcus Tangent (Arkustangens) in radians + // public ComplexValue InverseTangent() + // { + // return new ComplexValue(dataValue.Atan()); + // } + // /// Trigonometric Arcus Cotangent (Arkuscotangens) in radians + // public ComplexValue InverseCotangent() + // { + // return new ComplexValue(dataValue.Acot()); + // } + // /// Trigonometric Arcus Secant (Arkussekans) in radians + // public ComplexValue InverseSecant() + // { + // return new ComplexValue(dataValue.Asec()); + // } + // /// Trigonometric Arcus Cosecant (Arkuscosekans) in radians + // public ComplexValue InverseCosecant() + // { + // return new ComplexValue(dataValue.Acsc()); + // } + // #endregion + // #region Hyperbolic Functions + // /// Trigonometric Hyperbolic Sine (Sinus hyperbolicus) + // public ComplexValue HyperbolicSine() + // { + // return new ComplexValue(dataValue.Sinh()); + // } + // /// Trigonometric Hyperbolic Cosine (Cosinus hyperbolicus) + // public ComplexValue HyperbolicCosine() + // { + // return new ComplexValue(dataValue.Cosh()); + // } + // /// Trigonometric Hyperbolic Tangent (Tangens hyperbolicus) + // public ComplexValue HyperbolicTangent() + // { + // return new ComplexValue(dataValue.Tanh()); + // } + // /// Trigonometric Hyperbolic Cotangent (Cotangens hyperbolicus) + // public ComplexValue HyperbolicCotangent() + // { + // return new ComplexValue(dataValue.Coth()); + // } + // /// Trigonometric Hyperbolic Secant (Sekans hyperbolicus) + // public ComplexValue HyperbolicSecant() + // { + // return new ComplexValue(dataValue.Sech()); + // } + // /// Trigonometric Hyperbolic Cosecant (Cosekans hyperbolicus) + // public ComplexValue HyperbolicCosecant() + // { + // return new ComplexValue(dataValue.Csch()); + // } + // #endregion + // #region Hyperbolic Area Functions + // /// Trigonometric Hyperbolic Area Sine (Areasinus hyperbolicus) + // public ComplexValue InverseHyperbolicSine() + // { + // return new ComplexValue(dataValue.Asinh()); + // } + // /// Trigonometric Hyperbolic Area Cosine (Areacosinus hyperbolicus) + // public ComplexValue InverseHyperbolicCosine() + // { + // return new ComplexValue(dataValue.Acosh()); + // } + // /// Trigonometric Hyperbolic Area Tangent (Areatangens hyperbolicus) + // public ComplexValue InverseHyperbolicTangent() + // { + // return new ComplexValue(dataValue.Atanh()); + // } + // /// Trigonometric Hyperbolic Area Cotangent (Areacotangens hyperbolicus) + // public ComplexValue InverseHyperbolicCotangent() + // { + // return new ComplexValue(dataValue.Acoth()); + // } + // /// Trigonometric Hyperbolic Area Secant (Areasekans hyperbolicus) + // public ComplexValue InverseHyperbolicSecant() + // { + // return new ComplexValue(dataValue.Asech()); + // } + // /// Trigonometric Hyperbolic Area Cosecant (Areacosekans hyperbolicus) + // public ComplexValue InverseHyperbolicCosecant() + // { + // return new ComplexValue(dataValue.Acsch()); + // } + // #endregion + // #endregion + + // #region Constants + // public static Signal Constant(IContext context, Complex value) + // { + // return Constant(context, value, value.ToString()); + // } + // public static Signal Constant(IContext context, Complex value, string name) + // { + // Signal s = new Signal(context, new ComplexValue(value)); + // s.Label = name + "_Constant"; + // s.AddConstraint(Properties.ConstantSignalProperty.Instance); + // return s; + // } + + // public static ComplexValue I + // { + // get { return new ComplexValue(Complex.I); } //TODO: Think about Singleton like design... + // } + + // public static ComplexValue Zero + // { + // get { return new ComplexValue(Complex.Zero); } //TODO: Think about Singleton like design... + // } + + // public static ComplexValue One + // { + // get { return new ComplexValue(Complex.One); } //TODO: Think about Singleton like design... + // } + + // public static ComplexValue AdditiveIdentity + // { + // get { return new ComplexValue(Complex.Zero); } //TODO: Think about Singleton like design... + // } + + // public static ComplexValue MultiplicativeIdentity + // { + // get { return new ComplexValue(Complex.One); } //TODO: Think about Singleton like design... + // } + // #endregion + + // public override string ToString() + // { + // return dataValue.ToString(); + // } + + // public bool Equals(RealValue other) + // { + // return dataValue.IsReal && dataValue.Real == other.Value; + // } + // public bool Equals(RationalValue other) + // { + // return dataValue.IsReal && dataValue.Real == other.ToDouble(); + // } + // public bool Equals(IntegerValue other) + // { + // return dataValue.IsReal && dataValue.Real == other.ToDouble(); + // } + // public override bool Equals(ValueStructure other) + // { + // IntegerValue integerValue = other as IntegerValue; + // if(integerValue != null) + // return Equals(integerValue); + + // RationalValue rationalValue = other as RationalValue; + // if(rationalValue != null) + // return Equals(rationalValue); + + // RealValue realValue = other as RealValue; + // if(realValue != null) + // return Equals(realValue); + + // ComplexValue complexValue = other as ComplexValue; + // if(complexValue != null) + // return Equals(complexValue); + + // return other == this; + // } + // public bool Equals(ComplexValue other) + // { + // return dataValue.Equals(other.dataValue); + // } + // public int CompareTo(ComplexValue other) + // { + // return dataValue.CompareTo(other.dataValue); + // } + // public override int GetHashCode() + // { + // return dataValue.GetHashCode(); + // } + + // #region IAlgebraicRingWithUnity Members + // public bool IsMultiplicativeIdentity + // { + // get { return dataValue.IsOne; } + // } + // ValueStructure IAlgebraicRingWithUnity.MultiplicativeIdentity + // { + // get { return MultiplicativeIdentity; } + // } + // #endregion + // #region IAlgebraicMonoid Members + // public bool IsAdditiveIdentity + // { + // get { return dataValue.IsZero; } + // } + // ValueStructure IAlgebraicMonoid.AdditiveIdentity + // { + // get { return AdditiveIdentity; } + // } + // #endregion + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/NegativeInfinitySymbol.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/NegativeInfinitySymbol.cs new file mode 100644 index 0000000..ef8ca4b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/NegativeInfinitySymbol.cs @@ -0,0 +1,124 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// symbol: negative real infinity + public sealed class NegativeInfinitySymbol : ValueStructureBase, IEquatable, IComparable + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("NegativeInfinity", "Std"); + private NegativeInfinitySymbol() { } + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(Instance); + //library.AddCustomDataType(new CustomDataRef(typeof(NegativeInfinitySymbol), ValueConverter.Router, Instance)); + } + //public static NegativeInfinitySymbol ConvertFrom(IValueStructure value) + //{ + // return Instance; + //} + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Singleton + private static NegativeInfinitySymbol _instance; + public static NegativeInfinitySymbol Instance + { + get + { + if(_instance == null) + _instance = new NegativeInfinitySymbol(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public static Signal Constant + { + get + { + MathIdentifier id = _customTypeId.DerivePostfix("Constant"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Binder.CreateSignal(Instance); + ret.Label = "NegativeInfinity"; + ret.EnableFlag(StdAspect.ConstantFlag); + //ret.AddConstraint(Properties.ConstantSignalProperty.Instance); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public override bool Equals(IValueStructure other) + { + return other is NegativeInfinitySymbol; + } + public bool Equals(NegativeInfinitySymbol other) + { + return true; + } + public int CompareTo(NegativeInfinitySymbol other) + { + return 0; + } + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + //} + //private static NegativeInfinitySymbol InnerDeserialize(IContext context, XmlReader reader) + //{ + // return NegativeInfinitySymbol._instance; + //} + private static NegativeInfinitySymbol Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return NegativeInfinitySymbol._instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/PositiveInfinitySymbol.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/PositiveInfinitySymbol.cs new file mode 100644 index 0000000..3b72c26 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/PositiveInfinitySymbol.cs @@ -0,0 +1,124 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// symbol: positive real infinity + public sealed class PositiveInfinitySymbol : ValueStructureBase, IEquatable, IComparable + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("PositiveInfinity", "Std"); + private PositiveInfinitySymbol() { } + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(Instance); + } + //public static PositiveInfinitySymbol ConvertFrom(IValueStructure value) + //{ + // return Instance; + //} + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Singleton + private static PositiveInfinitySymbol _instance; + public static PositiveInfinitySymbol Instance + { + get + { + if(_instance == null) + _instance = new PositiveInfinitySymbol(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public static Signal Constant + { + get + { + MathIdentifier id = _customTypeId.DerivePostfix("Constant"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Binder.CreateSignal(Instance); + ret.Label = "PositiveInfinity"; + ret.EnableFlag(StdAspect.ConstantFlag); + //ret.AddConstraint(Properties.ConstantSignalProperty.Instance); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public override bool Equals(IValueStructure other) + { + return other is PositiveInfinitySymbol; + } + public bool Equals(PositiveInfinitySymbol other) + { + return true; + } + public int CompareTo(PositiveInfinitySymbol other) + { + return 0; + } + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + //} + //private static PositiveInfinitySymbol InnerDeserialize(IContext context, System.Xml.XmlReader reader) + //{ + // return PositiveInfinitySymbol._instance; + //} + private static PositiveInfinitySymbol Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return PositiveInfinitySymbol._instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RationalValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RationalValue.cs new file mode 100644 index 0000000..35cda60 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RationalValue.cs @@ -0,0 +1,526 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Numerics; +using MathNet.Symbolics.Packages.Standard.Trigonometry; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// signed rational (fraction) + public class RationalValue : ValueStructureBase, IEquatable, IComparable, IAlgebraicField, IFormattableLeaf + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Rational", "Std"); + private readonly long _numeratorValue; // = 0; + private readonly long _denominatorValue = 1; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + //library.AddCustomDataType(new CustomDataRef(typeof(RationalValue), ValueConverter.Router)); + ValueConverter.AddConverterFrom(true, ConvertFromInteger); + ValueConverter.AddConverterTo(ValueConverter.Router, false, + delegate(object value) + { + RationalValue rv = (RationalValue)value; + return new IntegerValue(rv._numeratorValue / rv._denominatorValue); + }); + } + public static RationalValue ConvertFrom(ICustomData value) + { + return (RationalValue)ValueConverter.ConvertFrom(value); + } + public static RationalValue ConvertFromInteger(IntegerValue value) { return new RationalValue(value); } + public static explicit operator RationalValue(IntegerValue value) { return new RationalValue(value); } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public RationalValue() + { + //this.dataValue = 0; + //this.denominatorValue = 1; + } + public RationalValue(long numerator, long denominator) + { + if(denominator < 0) + { + denominator = -denominator; + numerator = -numerator; + } + + long gcd = Fn.Gcd(numerator, denominator); + + _numeratorValue = numerator / gcd; + _denominatorValue = denominator / gcd; + } + public RationalValue(IntegerValue value) + { + if(value == null) + throw new ArgumentNullException("value"); + + _numeratorValue = value.Value; + _denominatorValue = 1; + } + #endregion + + #region Basic Operation Processes + internal class AddProcess : GenericFunctionProcess + { + public AddProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public AddProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RationalValue.AdditiveIdentity); + else + { + RationalValue sum = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RationalValue integer = ConvertFrom(Inputs[i].Value); + sum = sum.Add(integer); + } + PublishToOutputs(sum); + } + } + } + internal class SubtractProcess : GenericFunctionProcess + { + public SubtractProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public SubtractProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RationalValue.AdditiveIdentity); + else + { + RationalValue sum = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RationalValue integer = ConvertFrom(Inputs[i].Value); + sum = sum.Subtract(integer); + } + PublishToOutputs(sum); + } + } + } + internal class MultiplyProcess : GenericFunctionProcess + { + public MultiplyProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public MultiplyProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RationalValue.MultiplicativeIdentity); + else + { + RationalValue product = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RationalValue integer = ConvertFrom(Inputs[i].Value); + product = product.Multiply(integer); + } + PublishToOutputs(product); + } + } + } + internal class DivideProcess : GenericFunctionProcess + { + public DivideProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public DivideProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RationalValue.MultiplicativeIdentity); + else + { + RationalValue product = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RationalValue integer = ConvertFrom(Inputs[i].Value); + product = product.Divide(integer); + } + PublishToOutputs(product); + } + } + } + #endregion + + public IntegerValue Numerator + { + get { return new IntegerValue(_numeratorValue); } + } + public IntegerValue Denominator + { + get { return new IntegerValue(_denominatorValue); } + } + public long NumeratorValue + { + get { return _numeratorValue; } + } + public long DenominatorValue + { + get { return _denominatorValue; } + } + + public bool IsUnitFraction + { + get { return _numeratorValue == 1; } + } + + public bool IsInteger + { + get { return _denominatorValue == 1; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Operator Implementations + public static bool operator <(RationalValue left, RationalValue right) + { + return left.ToDouble() < right.ToDouble(); + } + public static bool operator >(RationalValue left, RationalValue right) + { + return left.ToDouble() > right.ToDouble(); + } + #endregion + + #region Direct Function Implementations + #region Arithmetic Function + public RationalValue Add(RationalValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue( + _numeratorValue * op._denominatorValue + _denominatorValue * op._numeratorValue, + _denominatorValue * op._denominatorValue); + } + public RationalValue Subtract(RationalValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue( + _numeratorValue * op._denominatorValue - _denominatorValue * op._numeratorValue, + _denominatorValue * op._denominatorValue); + } + public RationalValue Negate() + { + return new RationalValue( + -_numeratorValue, + _denominatorValue); + } + public RationalValue Multiply(RationalValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue( + _numeratorValue * op._numeratorValue, + _denominatorValue * op._denominatorValue); + } + public RationalValue Multiply(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue( + _numeratorValue * op.Value, + _denominatorValue); + } + public RationalValue Divide(RationalValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue( + _numeratorValue * op._denominatorValue, + _denominatorValue * op._numeratorValue); + } + public RationalValue Divide(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RationalValue( + _numeratorValue, + _denominatorValue * op.Value); + } + public RationalValue Invert() + { + return new RationalValue( + _denominatorValue, + _numeratorValue); + } + public RationalValue Absolute() + { + return (_numeratorValue < 0) ? new RationalValue(-_numeratorValue, _denominatorValue) : this; + } + public RationalValue PositiveIntegerPower(int op) + { + if(op == 1) + return this; + if(op == 0) + return IsAdditiveIdentity ? RationalValue.Zero : RationalValue.One; + return new RationalValue(MathNet.Numerics.Fn.IntPow(_numeratorValue, (uint)op), + MathNet.Numerics.Fn.IntPow(_denominatorValue, (uint)op)); + } + public RationalValue IntegerPower(int op) + { + if(op == 1) + return this; + if(op == 0) + return IsAdditiveIdentity ? RationalValue.Zero : RationalValue.One; + if(op > 1) + return new RationalValue(MathNet.Numerics.Fn.IntPow(_numeratorValue, (uint)op), + MathNet.Numerics.Fn.IntPow(_denominatorValue, (uint)op)); + return new RationalValue(MathNet.Numerics.Fn.IntPow(_numeratorValue, (uint)(-op)), + MathNet.Numerics.Fn.IntPow(_denominatorValue, (uint)(-op))); + } + public RationalValue Power(IntegerValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return IntegerPower((int)op.Value); + } + public RealValue Power(RationalValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + //if(op.IsInteger) + // return Power(op.Numerator); + + return new RealValue(Math.Pow(ToDouble(), op.ToDouble())); + } + public RationalValue Scale(RationalValue scalar) + { + return Multiply(scalar); + } + #endregion + #region Trigonometric Functions + /// The principal argument (in radians) of the complex number x+I*y + /// y + /// x + public RealValue ReverseTangent() + { + return new RealValue(Trig.InverseTangentFromRational(_numeratorValue, _denominatorValue)); + } + #endregion + #endregion + + #region Constants + public static Signal Constant(long numerator, long denominator) + { + Signal s = Binder.CreateSignal(new RationalValue(numerator, denominator)); + s.Label = s.Value.ToString() + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + //s.AddConstraint(Properties.ConstantSignalProperty.Instance); + return s; + } + + public static Signal ConstantHalf + { + get + { + MathIdentifier id = new MathIdentifier("RationalValueConstantHalf", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(1, 2); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static RationalValue Zero + { + get { return new RationalValue(0, 1); } //TODO: Think about Singleton like design... + } + + public static RationalValue One + { + get { return new RationalValue(1, 1); } //TODO: Think about Singleton like design... + } + + public static RationalValue AdditiveIdentity + { + get { return new RationalValue(0, 1); } //TODO: Think about Singleton like design... + } + + public static RationalValue MultiplicativeIdentity + { + get { return new RationalValue(1, 1); } //TODO: Think about Singleton like design... + } + + public static RationalValue Half + { + get { return new RationalValue(1, 2); } //TODO: Think about Singleton like design... + } + #endregion + + public double ToDouble() + { + return ((double)_numeratorValue) / ((double)_denominatorValue); + } + + public bool Equals(IntegerValue other) + { + return other != null && _numeratorValue == other.Value && _denominatorValue == 1; + } + public override bool Equals(IValueStructure other) + { + IntegerValue integerValue = other as IntegerValue; + if(integerValue != null) + return Equals(integerValue); + + RationalValue rationalValue = other as RationalValue; + if(rationalValue != null) + return Equals(rationalValue); + + RealValue realValue = other as RealValue; + if(realValue != null) + return realValue.Equals(this); + + return other == this; + } + public bool Equals(RationalValue other) + { + return other != null && _numeratorValue.Equals(other._numeratorValue) && _denominatorValue.Equals(other._denominatorValue); + } + public int CompareTo(RationalValue other) + { + return ToDouble().CompareTo(other.ToDouble()); + } + public override int GetHashCode() + { + return _numeratorValue.GetHashCode() ^ _denominatorValue.GetHashCode(); + } + + #region IAlgebraicMultiplicativeIdentityElement Members + public bool IsMultiplicativeIdentity + { + get { return _numeratorValue == 1 && _denominatorValue == 1; } + } + IValueStructure IAlgebraicMultiplicativeIdentityElement.MultiplicativeIdentity + { + get { return MultiplicativeIdentity; } + } + #endregion + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get { return _numeratorValue == 0 && !double.IsInfinity(_denominatorValue); } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // writer.WriteElementString("Numerator", _numeratorValue.ToString(Config.InternalNumberFormat)); + // writer.WriteElementString("Denominator", _denominatorValue.ToString(Config.InternalNumberFormat)); + //} + //private static RationalValue InnerDeserialize(IContext context, System.Xml.XmlReader reader) + //{ + // return new RationalValue(long.Parse(reader.ReadElementString("Numerator"), Config.InternalNumberFormat), + // long.Parse(reader.ReadElementString("Denominator"), Config.InternalNumberFormat)); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteElementString("Numerator", _numeratorValue.ToString(Config.InternalNumberFormat)); + writer.WriteElementString("Denominator", _denominatorValue.ToString(Config.InternalNumberFormat)); + } + private static RationalValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new RationalValue(long.Parse(reader.ReadElementString("Numerator"), Config.InternalNumberFormat), + long.Parse(reader.ReadElementString("Denominator"), Config.InternalNumberFormat)); + } + #endregion + + #region Formatting + private string FormatImpl(out int precedence) + { + IFormatProvider format = System.Globalization.NumberFormatInfo.InvariantInfo; + if(IsInteger) + { + precedence = -1; + return _numeratorValue.ToString(format); + } + else + { + precedence = 50; + return _numeratorValue.ToString(format) + "/" + _denominatorValue.ToString(format); + } + } + public override string ToString() + { + int precedence; + return FormatBase(FormatImpl(out precedence), FormattingOptions.Default); + } + string IFormattableLeaf.Format(FormattingOptions options, out int precedence) + { + return FormatBase(FormatImpl(out precedence), options); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RationalValueCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RationalValueCategory.cs new file mode 100644 index 0000000..f2d28de --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RationalValueCategory.cs @@ -0,0 +1,97 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// + /// The category Q: set of all signed rational numbers (fractions) + /// + public class RationalValueCategory : CategoryBase + { + protected RationalValueCategory() + : base("RationalValueExpression", "Std") { } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return CategoryMembershipLevel.Unknown; + if(signal.Value is RationalValue || signal.Value is IntegerValue) + return CategoryMembershipLevel.Member; + return CategoryMembershipLevel.NotMember; + } + + public override CategoryMembershipLevel IsMember(Port port) + { + if(port == null) + throw new ArgumentNullException("port"); + + return EvaluateJointChildMembership(port.InputSignals); + } + + #region Singleton + private static RationalValueCategory _instance; + public static RationalValueCategory Instance + { + get + { + if(_instance == null) + _instance = new RationalValueCategory(); + return _instance; + } + } + #endregion + + public static bool IsRationalValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.Member); + } + public static bool IsNotRationalValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.NotMember); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //protected static RationalValueCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static RationalValueCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealMatrixValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealMatrixValue.cs new file mode 100644 index 0000000..7829a5f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealMatrixValue.cs @@ -0,0 +1,441 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Trigonometry; +using MathNet.Numerics.LinearAlgebra; + +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + ///// signed real numbers + //public class RealMatrixValue : AbstractValueStructure, IEquatable //, IComparable + //{ + // private static readonly MathIdentifier _customTypeId = new MathIdentifier("RealMatrix", "Std"); + // private readonly Matrix _dataValue; + + // #region Conversion + // public static explicit operator RealMatrixValue(RealValue value) + // { + // return new RealMatrixValue(value.Value); + // } + // public static explicit operator RealMatrixValue(IntegerValue value) + // { + // return new RealMatrixValue(value.ToDouble()); + // } + // public static explicit operator RealMatrixValue(RationalValue value) + // { + // return new RealMatrixValue(value.ToDouble()); + // } + // public static RealMatrixValue ConvertFrom(ValueStructure value) + // { + // RealMatrixValue remv = value as RealMatrixValue; + // if(remv != null) + // return remv; + + // RealValue rev = value as RealValue; + // if(rev != null) + // return new RealMatrixValue(rev.Value); + + // RationalValue rav = value as RationalValue; + // if(rav != null) + // return new RealMatrixValue(rav.ToDouble()); + + // IntegerValue inv = value as IntegerValue; + // if(inv != null) + // return new RealMatrixValue(inv.ToDouble()); + + // throw new MathNet.Symbolics.Backend.Exceptions.StructureNotSupportedException(value); + // } + // public static bool IsConvertibleFrom(ValueStructure value) + // { + // return value != null && (value is RealMatrixValue || value is RealValue || value is RationalValue || value is IntegerValue); + // } + // #endregion + + // public RealMatrixValue() + // { + // _dataValue = new Matrix(0, 0); + // } + // public RealMatrixValue(Matrix value) + // { + // _dataValue = value; + // } + // public RealMatrixValue(double[,] value) + // { + // _dataValue = new Matrix(value); + // } + // public RealMatrixValue(double[] value, int numberOfRows) + // { + // _dataValue = new Matrix(value, numberOfRows); + // } + // public RealMatrixValue(int numberOfRows, int numberOfColumns, double value) + // { + // _dataValue = new Matrix(numberOfRows, numberOfColumns, value); + // } + // public RealMatrixValue(double value) + // { + // _dataValue = new Matrix(1, 1, value); + // } + // public RealMatrixValue(RealValue value) + // { + // _dataValue = new Matrix(1, 1, value.Value); + // } + + // public Matrix Value + // { + // get { return _dataValue; } + // } + + // public static MathIdentifier TypeIdentifier + // { + // get { return _customTypeId; } + // } + // public override MathIdentifier StructureId + // { + // get { return _customTypeId; } + // } + + // #region Direct Function Implementations + // #region Arithmetic Function + // public RealMatrixValue Add(RealMatrixValue op) + // { + // return new RealMatrixValue(_dataValue + op._dataValue); + // } + // public RealMatrixValue Subtract(RealMatrixValue op) + // { + // return new RealMatrixValue(_dataValue - op._dataValue); + // } + // public RealMatrixValue Negate() + // { + // Matrix m = _dataValue.Clone(); + // m.UnaryMinus(); + // return new RealMatrixValue(m); + // } + // public RealMatrixValue Multiply(RealValue op) + // { + // return new RealMatrixValue(op.Value * _dataValue); + // } + // public RealMatrixValue Multiply(RealMatrixValue op) + // { + // return new RealMatrixValue(_dataValue * op._dataValue); + // } + // public RealMatrixValue Invert() + // { + // return new RealMatrixValue(_dataValue.Inverse()); + // } + // public RealValue Absolute() + // { + // return new RealValue(_dataValue.Norm2()); + // } + // #endregion + // #region Norm, Rank, Condition + // public RealValue Norm1() + // { + // return new RealValue(_dataValue.Norm1()); + // } + // public RealValue Norm2() + // { + // return new RealValue(_dataValue.Norm2()); + // } + // public RealValue NormF() + // { + // return new RealValue(_dataValue.NormF()); + // } + // public RealValue NormInf() + // { + // return new RealValue(_dataValue.NormInf()); + // } + // public RealValue Condition() + // { + // return new RealValue(_dataValue.Condition()); + // } + // public IntegerValue Rank() + // { + // return new IntegerValue(_dataValue.Rank()); + // } + // public RealValue Determinant() + // { + // return new RealValue(_dataValue.Determinant()); + // } + // #endregion + // #region Exponential Functions + // //public RealValue Exponential() + // //{ + // // return new RealValue(Math.Exp(dataValue)); + // //} + // //public RealValue NaturalLogarithm() + // //{ + // // return new RealValue(Math.Log(dataValue)); + // //} + // //public RealValue Power(RealValue op) + // //{ + // // return new RealValue(Math.Pow(dataValue, op.dataValue)); + // //} + // //public RealValue Root(RealValue op) + // //{ + // // return new RealValue(Math.Pow(dataValue, 1 / op.Value)); + // //} + // //public RealValue Square() + // //{ + // // return new RealValue(dataValue * dataValue); + // //} + // //public RealValue SquareRoot() + // //{ + // // return new RealValue(Math.Sqrt(dataValue)); + // //} + // #endregion + // #region Trigonometric Functions + // ///// Trigonometric Sine (Sinus) of an angle in radians + // //public RealValue Sine() + // //{ + // // return new RealValue(Trig.Sine(dataValue)); + // //} + // ///// Trigonometric Cosine (Cosinus) of an angle in radians + // //public RealValue Cosine() + // //{ + // // return new RealValue(Trig.Cosine(dataValue)); + // //} + // ///// Trigonometric Tangent (Tangens) of an angle in radians + // //public RealValue Tangent() + // //{ + // // return new RealValue(Trig.Tangent(dataValue)); + // //} + // ///// Trigonometric Cotangent (Cotangens) of an angle in radians + // //public RealValue Cotangent() + // //{ + // // return new RealValue(Trig.Cotangent(dataValue)); + // //} + // ///// Trigonometric Secant (Sekans) of an angle in radians + // //public RealValue Secant() + // //{ + // // return new RealValue(Trig.Secant(dataValue)); + // //} + // ///// Trigonometric Cosecant (Cosekans) of an angle in radians + // //public RealValue Cosecant() + // //{ + // // return new RealValue(Trig.Cosecant(dataValue)); + // //} + // #endregion + // #region Trigonometric Inverse Functions + // ///// Trigonometric Arcus Sine (Arkussinus) in radians + // //public RealValue InverseSine() + // //{ + // // return new RealValue(Trig.InverseSine(dataValue)); + // //} + // ///// Trigonometric Arcus Cosine (Arkuscosinus) in radians + // //public RealValue InverseCosine() + // //{ + // // return new RealValue(Trig.InverseCosine(dataValue)); + // //} + // ///// Trigonometric Arcus Tangent (Arkustangens) in radians + // //public RealValue InverseTangent() + // //{ + // // return new RealValue(Trig.InverseTangent(dataValue)); + // //} + // ///// Trigonometric Arcus Cotangent (Arkuscotangens) in radians + // //public RealValue InverseCotangent() + // //{ + // // return new RealValue(Trig.InverseCotangent(dataValue)); + // //} + // ///// Trigonometric Arcus Secant (Arkussekans) in radians + // //public RealValue InverseSecant() + // //{ + // // return new RealValue(Trig.InverseSecant(dataValue)); + // //} + // ///// Trigonometric Arcus Cosecant (Arkuscosekans) in radians + // //public RealValue InverseCosecant() + // //{ + // // return new RealValue(Trig.InverseCosecant(dataValue)); + // //} + // #endregion + // #region Hyperbolic Functions + // ///// Trigonometric Hyperbolic Sine (Sinus hyperbolicus) + // //public RealValue HyperbolicSine() + // //{ + // // return new RealValue(Trig.HyperbolicSine(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Cosine (Cosinus hyperbolicus) + // //public RealValue HyperbolicCosine() + // //{ + // // return new RealValue(Trig.HyperbolicCosine(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Tangent (Tangens hyperbolicus) + // //public RealValue HyperbolicTangent() + // //{ + // // return new RealValue(Trig.HyperbolicTangent(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Cotangent (Cotangens hyperbolicus) + // //public RealValue HyperbolicCotangent() + // //{ + // // return new RealValue(Trig.HyperbolicCotangent(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Secant (Sekans hyperbolicus) + // //public RealValue HyperbolicSecant() + // //{ + // // return new RealValue(Trig.HyperbolicSecant(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Cosecant (Cosekans hyperbolicus) + // //public RealValue HyperbolicCosecant() + // //{ + // // return new RealValue(Trig.HyperbolicCosecant(dataValue)); + // //} + // #endregion + // #region Hyperbolic Area Functions + // ///// Trigonometric Hyperbolic Area Sine (Areasinus hyperbolicus) + // //public RealValue InverseHyperbolicSine() + // //{ + // // return new RealValue(Trig.InverseHyperbolicSine(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Area Cosine (Areacosinus hyperbolicus) + // //public RealValue InverseHyperbolicCosine() + // //{ + // // return new RealValue(Trig.InverseHyperbolicCosine(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Area Tangent (Areatangens hyperbolicus) + // //public RealValue InverseHyperbolicTangent() + // //{ + // // return new RealValue(Trig.InverseHyperbolicTangent(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Area Cotangent (Areacotangens hyperbolicus) + // //public RealValue InverseHyperbolicCotangent() + // //{ + // // return new RealValue(Trig.InverseHyperbolicCotangent(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Area Secant (Areasekans hyperbolicus) + // //public RealValue InverseHyperbolicSecant() + // //{ + // // return new RealValue(Trig.InverseHyperbolicSecant(dataValue)); + // //} + // ///// Trigonometric Hyperbolic Area Cosecant (Areacosekans hyperbolicus) + // //public RealValue InverseHyperbolicCosecant() + // //{ + // // return new RealValue(Trig.InverseHyperbolicCosecant(dataValue)); + // //} + // #endregion + // #endregion + + // #region Constants + // //public static Signal ParseConstant(IContext context, string value) + // //{ + // // return Constant(context, double.Parse(value, context.NumberFormat), value.Trim()); + // //} + // public static Signal Constant(IContext context, Matrix value, string name) + // { + // Signal s = new Signal(context, new RealMatrixValue(value)); + // s.Label = name + "_Constant"; + // s.AddConstraint(Properties.ConstantSignalProperty.Instance); + // return s; + // } + + // public static RealMatrixValue Empty + // { + // get { return new RealMatrixValue(0, 0, 0d); } //TODO: Think about Singleton like design... + // } + + // public static RealMatrixValue MultiplicativeIdentity(int dimension) + // { + // return new RealMatrixValue(Matrix.Identity(dimension, dimension)); + // } + + // public static RealMatrixValue AdditiveIdentityIdentity(int dimension) + // { + // return new RealMatrixValue(new Matrix(dimension, dimension, 0d)); + // } + // #endregion + + // public override string ToString() + // { + // return base.ToString() + "(" + _dataValue.ToString() + ")"; + // } + + // public bool Equals(RealValue other) + // { + // return _dataValue.RowCount == 1 && _dataValue.ColumnCount == 1 && _dataValue[0,0] == other.Value; + // } + // public bool Equals(RationalValue other) + // { + // return _dataValue.RowCount == 1 && _dataValue.ColumnCount == 1 && _dataValue[0, 0] == other.ToDouble(); + // } + // public bool Equals(IntegerValue other) + // { + // return _dataValue.RowCount == 1 && _dataValue.ColumnCount == 1 && _dataValue[0, 0] == other.ToDouble(); + // } + // public override bool Equals(ValueStructure other) + // { + // IntegerValue integerValue = other as IntegerValue; + // if(integerValue != null) + // return Equals(integerValue); + + // RationalValue rationalValue = other as RationalValue; + // if(rationalValue != null) + // return Equals(rationalValue); + + // RealValue realValue = other as RealValue; + // if(realValue != null) + // return Equals(realValue); + + // RealMatrixValue realMatrixValue = other as RealMatrixValue; + // if(realMatrixValue != null) + // return Equals(realMatrixValue); + + // return other == this; + // } + // public bool Equals(RealMatrixValue other) + // { + // return _dataValue.Equals(other._dataValue); + // } + // //public int CompareTo(RealMatrixValue other) + // //{ + // // return dataValue.CompareTo(other.dataValue); + // //} + // public override int GetHashCode() + // { + // return _dataValue.GetHashCode(); + // } + + // #region Serialization TODO + // public override ExtensionTypeXml Serialize(IContext context) + // { + // throw new NotImplementedException(); + + // //ExtensionTypeXml xml = new ExtensionTypeXml(); + // //Type t = typeof(RealMatrixValue); + // //xml.QualifiedName = t.AssemblyQualifiedName; + // //XmlDocument doc = new XmlDocument(); + // //XmlElement el = doc.CreateElement("Value"); + // //el.InnerText = dataValue.ToString(); + // //xml.Any = new XmlElement[] { el }; + // //return xml; + // } + // public static new RealMatrixValue Deserialize(ExtensionTypeXml xml, IContext context) + // { + // throw new NotImplementedException(); + + // //return new RealMatrixValue(Matrix.Parse(xml.Any[0].InnerText, context.NumberFormat)); + // } + // #endregion + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealValue.cs new file mode 100644 index 0000000..a20d3ea --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealValue.cs @@ -0,0 +1,599 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Xml; + +using MathNet.Numerics; +using MathNet.Symbolics.Packages.Standard.Trigonometry; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; +using MathNet.Symbolics.Formatter; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// signed real numbers + public class RealValue : ValueStructureBase, IEquatable, IComparable, IAlgebraicField, IFormattableLeaf + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Real", "Std"); + private readonly double _dataValue; // = 0; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + library.AddArbitraryType(typeof(double)); + //library.AddCustomDataType(new CustomDataRef(typeof(RealValue), ValueConverter.Router)); + ValueConverter.AddConverterFrom(true, ConvertFrom); + ValueConverter.AddConverterFrom(true, ConvertFrom); + ValueConverter.AddConverterTo(ValueConverter.Router, false, + delegate(object value) { return new IntegerValue((long)Math.Round(((RealValue)value).Value, 0)); }); + ValueConverter.AddConverterFrom(ValueConverter.Router, true, + delegate(object value) { return new RealValue((double)value); }); + ValueConverter.AddConverterTo(ValueConverter.Router, true, + delegate(object value) { return ((RealValue)value).Value; }); + } + public static RealValue ConvertFrom(ICustomData value) + { + return (RealValue)ValueConverter.ConvertFrom(value); + } + public static RealValue ConvertFrom(IntegerValue value) { return new RealValue(value); } + public static explicit operator RealValue(IntegerValue value) { return new RealValue(value); } + public static RealValue ConvertFrom(RationalValue value) { return new RealValue(value); } + public static explicit operator RealValue(RationalValue value) { return new RealValue(value); } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public RealValue() + { + //this.dataValue = 0; + } + public RealValue(double value) + { + _dataValue = value; + } + public RealValue(IntegerValue value) + { + if(value == null) + throw new ArgumentNullException("value"); + + _dataValue = (double)value.Value; + } + public RealValue(RationalValue value) + { + if(value == null) + throw new ArgumentNullException("value"); + + _dataValue = (double)value.NumeratorValue / (double)value.DenominatorValue; + } + #endregion + + #region Basic Operation Processes + internal class AddProcess : GenericFunctionProcess + { + public AddProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public AddProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RealValue.AdditiveIdentity); + else + { + RealValue sum = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RealValue integer = ConvertFrom(Inputs[i].Value); + sum = sum.Add(integer); + } + PublishToOutputs(sum); + } + } + } + internal class SubtractProcess : GenericFunctionProcess + { + public SubtractProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public SubtractProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RealValue.AdditiveIdentity); + else + { + RealValue sum = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RealValue integer = ConvertFrom(Inputs[i].Value); + sum = sum.Subtract(integer); + } + PublishToOutputs(sum); + } + } + } + internal class MultiplyProcess : GenericFunctionProcess + { + public MultiplyProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public MultiplyProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RealValue.MultiplicativeIdentity); + else + { + RealValue product = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RealValue integer = ConvertFrom(Inputs[i].Value); + product = product.Multiply(integer); + } + PublishToOutputs(product); + } + } + } + internal class DivideProcess : GenericFunctionProcess + { + public DivideProcess(bool[] summandInput, bool[] summandInternal, bool[] outOutput, bool[] outInternal) + : base(summandInput, summandInternal, outOutput, outInternal) { } + public DivideProcess(int firstInput, int lastInput, int output) + : base(firstInput, lastInput, output) { } + + protected override void Action(bool isInit, Signal origin) + { + if(Inputs.Length == 0) + PublishToOutputs(RealValue.MultiplicativeIdentity); + else + { + RealValue product = ConvertFrom(Inputs[0].Value); + for(int i = 1; i < Inputs.Length; i++) + { + RealValue integer = ConvertFrom(Inputs[i].Value); + product = product.Divide(integer); + } + PublishToOutputs(product); + } + } + } + #endregion + + public double Value + { + get { return _dataValue; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Function Implementations + #region Arithmetic Function + public RealValue Add(RealValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RealValue(_dataValue + op._dataValue); + } + public RealValue Subtract(RealValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RealValue(_dataValue - op._dataValue); + } + public RealValue Negate() + { + return new RealValue(-_dataValue); + } + public RealValue Multiply(RealValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RealValue(_dataValue * op._dataValue); + } + public RealValue Divide(RealValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RealValue(_dataValue / op._dataValue); + } + public RealValue Invert() + { + return new RealValue(1d / _dataValue); + } + public RealValue Absolute() + { + return (_dataValue < 0) ? new RealValue(-_dataValue) : this; + } + public RealValue Scale(RealValue scalar) + { + return Multiply(scalar); + } + #endregion + #region Exponential Functions + public RealValue Exponential() + { + return new RealValue(Math.Exp(_dataValue)); + } + public RealValue NaturalLogarithm() + { + return new RealValue(Math.Log(_dataValue)); + } + public RealValue PositiveIntegerPower(int op) + { + return new RealValue(Math.Pow(_dataValue, op)); + } + public RealValue IntegerPower(int op) + { + return new RealValue(Math.Pow(_dataValue, op)); + } + public RealValue Power(RealValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RealValue(Math.Pow(_dataValue, op._dataValue)); + } + public RealValue Root(RealValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new RealValue(Math.Pow(_dataValue, 1 / op._dataValue)); + } + public RealValue Square() + { + return new RealValue(_dataValue * _dataValue); + } + public RealValue SquareRoot() + { + return new RealValue(Math.Sqrt(_dataValue)); + } + #endregion + #region Trigonometric Functions + /// Trigonometric Sine (Sinus) of an angle in radians + public RealValue Sine() + { + return new RealValue(Trig.Sine(_dataValue)); + } + /// Trigonometric Cosine (Cosinus) of an angle in radians + public RealValue Cosine() + { + return new RealValue(Trig.Cosine(_dataValue)); + } + /// Trigonometric Tangent (Tangens) of an angle in radians + public RealValue Tangent() + { + return new RealValue(Trig.Tangent(_dataValue)); + } + /// Trigonometric Cotangent (Cotangens) of an angle in radians + public RealValue Cotangent() + { + return new RealValue(Trig.Cotangent(_dataValue)); + } + /// Trigonometric Secant (Sekans) of an angle in radians + public RealValue Secant() + { + return new RealValue(Trig.Secant(_dataValue)); + } + /// Trigonometric Cosecant (Cosekans) of an angle in radians + public RealValue Cosecant() + { + return new RealValue(Trig.Cosecant(_dataValue)); + } + #endregion + #region Trigonometric Inverse Functions + /// Trigonometric Arcus Sine (Arkussinus) in radians + public RealValue InverseSine() + { + return new RealValue(Trig.InverseSine(_dataValue)); + } + /// Trigonometric Arcus Cosine (Arkuscosinus) in radians + public RealValue InverseCosine() + { + return new RealValue(Trig.InverseCosine(_dataValue)); + } + /// Trigonometric Arcus Tangent (Arkustangens) in radians + public RealValue InverseTangent() + { + return new RealValue(Trig.InverseTangent(_dataValue)); + } + /// Trigonometric Arcus Cotangent (Arkuscotangens) in radians + public RealValue InverseCotangent() + { + return new RealValue(Trig.InverseCotangent(_dataValue)); + } + /// Trigonometric Arcus Secant (Arkussekans) in radians + public RealValue InverseSecant() + { + return new RealValue(Trig.InverseSecant(_dataValue)); + } + /// Trigonometric Arcus Cosecant (Arkuscosekans) in radians + public RealValue InverseCosecant() + { + return new RealValue(Trig.InverseCosecant(_dataValue)); + } + #endregion + #region Hyperbolic Functions + /// Trigonometric Hyperbolic Sine (Sinus hyperbolicus) + public RealValue HyperbolicSine() + { + return new RealValue(Trig.HyperbolicSine(_dataValue)); + } + /// Trigonometric Hyperbolic Cosine (Cosinus hyperbolicus) + public RealValue HyperbolicCosine() + { + return new RealValue(Trig.HyperbolicCosine(_dataValue)); + } + /// Trigonometric Hyperbolic Tangent (Tangens hyperbolicus) + public RealValue HyperbolicTangent() + { + return new RealValue(Trig.HyperbolicTangent(_dataValue)); + } + /// Trigonometric Hyperbolic Cotangent (Cotangens hyperbolicus) + public RealValue HyperbolicCotangent() + { + return new RealValue(Trig.HyperbolicCotangent(_dataValue)); + } + /// Trigonometric Hyperbolic Secant (Sekans hyperbolicus) + public RealValue HyperbolicSecant() + { + return new RealValue(Trig.HyperbolicSecant(_dataValue)); + } + /// Trigonometric Hyperbolic Cosecant (Cosekans hyperbolicus) + public RealValue HyperbolicCosecant() + { + return new RealValue(Trig.HyperbolicCosecant(_dataValue)); + } + #endregion + #region Hyperbolic Area Functions + /// Trigonometric Hyperbolic Area Sine (Areasinus hyperbolicus) + public RealValue InverseHyperbolicSine() + { + return new RealValue(Trig.InverseHyperbolicSine(_dataValue)); + } + /// Trigonometric Hyperbolic Area Cosine (Areacosinus hyperbolicus) + public RealValue InverseHyperbolicCosine() + { + return new RealValue(Trig.InverseHyperbolicCosine(_dataValue)); + } + /// Trigonometric Hyperbolic Area Tangent (Areatangens hyperbolicus) + public RealValue InverseHyperbolicTangent() + { + return new RealValue(Trig.InverseHyperbolicTangent(_dataValue)); + } + /// Trigonometric Hyperbolic Area Cotangent (Areacotangens hyperbolicus) + public RealValue InverseHyperbolicCotangent() + { + return new RealValue(Trig.InverseHyperbolicCotangent(_dataValue)); + } + /// Trigonometric Hyperbolic Area Secant (Areasekans hyperbolicus) + public RealValue InverseHyperbolicSecant() + { + return new RealValue(Trig.InverseHyperbolicSecant(_dataValue)); + } + /// Trigonometric Hyperbolic Area Cosecant (Areacosekans hyperbolicus) + public RealValue InverseHyperbolicCosecant() + { + return new RealValue(Trig.InverseHyperbolicCosecant(_dataValue)); + } + #endregion + #endregion + + #region Constants + public static Signal ParseConstant(string value) + { + if(value == null) + throw new ArgumentNullException("value"); + + return Constant(double.Parse(value, Config.InternalNumberFormat), value.Trim()); + } + public static Signal Constant(double value) + { + return Constant(value, value.ToString(Config.InternalNumberFormat)); + } + public static Signal Constant(double value, string name) + { + Signal s = Binder.CreateSignal(new RealValue(value)); + s.Label = name + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + //s.AddConstraint(Properties.ConstantSignalProperty.Instance); + return s; + } + + public static Signal ConstantPI + { + get + { + MathIdentifier id = new MathIdentifier("RealValueConstantPI", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(Math.PI, "PI"); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static Signal ConstantE + { + get + { + MathIdentifier id = new MathIdentifier("RealValueConstantE", "Std"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Constant(Math.E, "E"); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public static RealValue PI + { + get { return new RealValue(Math.PI); } //TODO: Think about Singleton like design... + } + + public static RealValue E + { + get { return new RealValue(Math.E); } //TODO: Think about Singleton like design... + } + + public static RealValue Zero + { + get { return new RealValue(0); } //TODO: Think about Singleton like design... + } + + public static RealValue One + { + get { return new RealValue(1); } //TODO: Think about Singleton like design... + } + + public static RealValue AdditiveIdentity + { + get { return new RealValue(0); } //TODO: Think about Singleton like design... + } + + public static RealValue MultiplicativeIdentity + { + get { return new RealValue(1); } //TODO: Think about Singleton like design... + } + #endregion + + public bool Equals(RationalValue other) + { + return other != null && _dataValue == other.ToDouble(); + } + public bool Equals(IntegerValue other) + { + return other != null && _dataValue == (double)other.Value; + } + public override bool Equals(IValueStructure other) + { + IntegerValue integerValue = other as IntegerValue; + if(integerValue != null) + return Equals(integerValue); + + RationalValue rationalValue = other as RationalValue; + if(rationalValue != null) + return Equals(rationalValue); + + RealValue realValue = other as RealValue; + if(realValue != null) + return Equals(realValue); + + return other == this; + } + public bool Equals(RealValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public int CompareTo(RealValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region IAlgebraicMultiplicativeIdentityElement Members + public bool IsMultiplicativeIdentity + { + get { return _dataValue == 1d; } + } + IValueStructure IAlgebraicMultiplicativeIdentityElement.MultiplicativeIdentity + { + get { return MultiplicativeIdentity; } + } + #endregion + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get { return _dataValue == 0d; } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // writer.WriteString(_dataValue.ToString(Config.InternalNumberFormat)); + //} + //private static RealValue InnerDeserialize(IContext context, XmlReader reader) + //{ + // return new RealValue(double.Parse(reader.ReadString(), Config.InternalNumberFormat)); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteString(_dataValue.ToString(Config.InternalNumberFormat)); + } + private static RealValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new RealValue(double.Parse(reader.ReadString(), Config.InternalNumberFormat)); + } + #endregion + + #region Formatting + public override string ToString() + { + IFormatProvider format = System.Globalization.NumberFormatInfo.InvariantInfo; + return FormatBase(_dataValue.ToString(format), FormattingOptions.Default); + } + string IFormattableLeaf.Format(FormattingOptions options, out int precedence) + { + precedence = -1; + IFormatProvider format = System.Globalization.NumberFormatInfo.InvariantInfo; + return FormatBase(_dataValue.ToString(format), options); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealValueCategory.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealValueCategory.cs new file mode 100644 index 0000000..a23e300 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/RealValueCategory.cs @@ -0,0 +1,94 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// + /// The category R: set of all signed real numbers. + /// + public class RealValueCategory : CategoryBase + { + protected RealValueCategory() + : base("RealValueExpression", "Std") { } + + public override CategoryMembershipLevel IsMember(Signal signal, bool ignoreCache) + { + if(signal == null) + throw new ArgumentNullException("signal"); + + if(signal.Value == null) + return CategoryMembershipLevel.Unknown; + if(signal.Value is RealValue || signal.Value is RationalValue || signal.Value is IntegerValue) + return CategoryMembershipLevel.Member; + return CategoryMembershipLevel.NotMember; + } + + public override CategoryMembershipLevel IsMember(Port port) + { + return EvaluateJointChildMembership(port.InputSignals); + } + + #region Singleton + private static RealValueCategory _instance; + public static RealValueCategory Instance + { + get + { + if(_instance == null) + _instance = new RealValueCategory(); + return _instance; + } + } + #endregion + + public static bool IsRealValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.Member); + } + public static bool IsNotRealValueMember(Port port) + { + return (Instance.IsMember(port) == CategoryMembershipLevel.NotMember); + } + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + //} + //protected static RealValueCategory InnerDeserialize(IContext context, XmlReader reader) + //{ + // return Instance; + //} + private static RealValueCategory Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return Instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ToggleValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ToggleValue.cs new file mode 100644 index 0000000..f82fdd1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/ToggleValue.cs @@ -0,0 +1,149 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + public sealed class ToggleValue : ValueStructureBase, IEquatable, IComparable + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Toggle", "Std"); + private readonly bool _dataValue; // = false; + private static ToggleValue _toggleA, _toggleB; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + //library.AddCustomDataType(new CustomDataRef(typeof(ToggleValue), ValueConverter.Router)); + ValueConverter.AddConverterFrom(ValueConverter.Router, false, + delegate(object value) { return ((IntegerValue)value).Value == 0 ? _toggleB : _toggleA; }); + ValueConverter.AddConverterTo(ValueConverter.Router, true, + delegate(object value) { return ((ToggleValue)value)._dataValue ? IntegerValue.Zero : IntegerValue.One; }); + } + + public static ToggleValue ConvertFrom(ICustomData value) + { + return (ToggleValue)ValueConverter.ConvertFrom(value); + } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + public static ToggleValue InitialToggle + { + get + { + if(_toggleA == null) + { + _toggleA = new ToggleValue(false); + _toggleB = new ToggleValue(true); + } + return _toggleA; + } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + private ToggleValue(bool value) + { + _dataValue = value; + } + + public ToggleValue Toggle() + { + return _dataValue ? _toggleA : _toggleB; + } + + public override string ToString() + { + return base.ToString() + (_dataValue ? "(B)" : "(A)"); + } + + public override bool Equals(IValueStructure other) + { + ToggleValue toggleValue = other as ToggleValue; + if(toggleValue != null) + return Equals(toggleValue); + + return other == this; + } + public bool Equals(ToggleValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public int CompareTo(ToggleValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + // if(_dataValue) + // writer.WriteString("B"); + // else + // writer.WriteString("A"); + //} + //private static ToggleValue InnerDeserialize(IContext context, XmlReader reader) + //{ + // if(reader.ReadString().Equals("B")) + // return InitialToggle.Toggle(); + // else + // return InitialToggle; + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + if(_dataValue) + writer.WriteString("B"); + else + writer.WriteString("A"); + } + private static ToggleValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + if(reader.ReadString().Equals("B")) + return InitialToggle.Toggle(); + else + return InitialToggle; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/UndefinedSymbol.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/UndefinedSymbol.cs new file mode 100644 index 0000000..12a033f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/UndefinedSymbol.cs @@ -0,0 +1,124 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Repository; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// symbol: undefined + public sealed class UndefinedSymbol : ValueStructureBase, IEquatable, IComparable + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Undefined", "Std"); + private UndefinedSymbol() { } + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(Instance); + //library.AddCustomDataType(new CustomDataRef(typeof(UndefinedSymbol), ValueConverter.Router, Instance)); + } + //public static UndefinedSymbol ConvertFrom(IValueStructure value) + //{ + // return Instance; + //} + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Singleton + private static UndefinedSymbol _instance; + public static UndefinedSymbol Instance + { + get + { + if(_instance == null) + _instance = new UndefinedSymbol(); + return _instance; + } + } + #endregion + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + public static Signal Constant + { + get + { + MathIdentifier id = _customTypeId.DerivePostfix("Constant"); + Signal ret; + if(Service.Instance.TryGetValue(id, out ret)) + return ret; + else + { + ret = Binder.CreateSignal(Instance); + ret.Label = "Undefined"; + ret.EnableFlag(StdAspect.ConstantFlag); + //ret.AddConstraint(Properties.ConstantSignalProperty.Instance); + Service.Instance.Add(id, ret); + return ret; + } + } + } + + public override bool Equals(IValueStructure other) + { + return other is UndefinedSymbol; + } + public bool Equals(UndefinedSymbol other) + { + return true; + } + public int CompareTo(UndefinedSymbol other) + { + return 0; + } + + #region Serialization + //protected override void InnerSerialize(System.Xml.XmlWriter writer) + //{ + //} + //private static UndefinedSymbol InnerDeserialize(IContext context, XmlReader reader) + //{ + // return UndefinedSymbol._instance; + //} + private static UndefinedSymbol Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return UndefinedSymbol._instance; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/VectorValue.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/VectorValue.cs new file mode 100644 index 0000000..45ea011 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Structures/VectorValue.cs @@ -0,0 +1,279 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Xml; +using System.Collections.Generic; +using System.Text; + +using MathNet.Numerics; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Trigonometry; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Structures +{ + /// vectors with arbitrary components + public class VectorValue : ValueStructureBase, IEquatable>, IAlgebraicVectorSpace, TScalar> + where TScalar : IValueStructure, IAlgebraicField + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Vector", "Std").DerivePrefix(typeof(TScalar).Name); + private readonly TScalar[] _dataValue; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType>(); + //library.AddCustomDataType(new CustomDataRef(typeof(VectorValue), ValueConverter>.Router)); + } + public static VectorValue ConvertFrom(ICustomData value) + { + return (VectorValue)ValueConverter>.ConvertFrom(value); + } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter>.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public VectorValue() + { + _dataValue = new TScalar[0]; + } + public VectorValue(TScalar[] value) + { + _dataValue = value; + } + public VectorValue(IList values) + { + _dataValue = new TScalar[values.Count]; + values.CopyTo(_dataValue,0); + } + #endregion + + public TScalar[] Value + { + get { return _dataValue; } + } + public TScalar this[int index] + { + get { return _dataValue[index]; } + } + public int Count + { + get { return _dataValue.Length; } + } + //public double Norm + //{ + // get { return _dataValue.Modulus; } + //} + //public double NormSquared + //{ + // get { return _dataValue.ModulusSquared; } + //} + //public bool IsZero + //{ + // get { return _dataValue.IsZero; } + //} + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Function Implementations + #region Arithmetic Function + public static VectorValue Add(VectorValue summand1, VectorValue summand2) { return summand1.Add(summand2); } + public VectorValue Add(VectorValue summand) + { + int max = Math.Max(Count, summand.Count); + int min = Math.Min(Count, summand.Count); + TScalar[] otherValue = summand._dataValue; + TScalar[] value = new TScalar[max]; + + if(Count > summand.Count) + Array.Copy(_dataValue,min,value,min,max-min); + else + Array.Copy(otherValue, min, value, min, max - min); + for(int i = 0; i < min; i++) + value[i] = _dataValue[i].Add(otherValue[i]); + + return new VectorValue(value); + } + public static VectorValue Subtract(VectorValue minuend, VectorValue subtrahend) { return minuend.Subtract(subtrahend); } + public VectorValue Subtract(VectorValue subtrahend) + { + int max = Math.Max(Count, subtrahend.Count); + int min = Math.Min(Count, subtrahend.Count); + TScalar[] otherValue = subtrahend._dataValue; + TScalar[] value = new TScalar[max]; + + if(Count > subtrahend.Count) + Array.Copy(_dataValue, min, value, min, max - min); + else + for(int i = min; i < max; i++) + value[i] = otherValue[i].Negate(); + for(int i = 0; i < min; i++) + value[i] = _dataValue[i].Subtract(otherValue[i]); + + return new VectorValue(value); + } + public static VectorValue Negate(VectorValue subtrahend) { return subtrahend.Negate(); } + public VectorValue Negate() + { + TScalar[] value = new TScalar[_dataValue.Length]; + + for(int i = 0; i < _dataValue.Length; i++) + value[i] = _dataValue[i].Negate(); + + return new VectorValue(value); + } + //public static TScalar Norm(VectorValue value) { return value.Norm(); } + //public TScalar Norm() + //{ + // if(Count == 0) + // return ???; + + // ... + + // return new RealValue(_dataValue.Modulus); + //} + public VectorValue Scale(TScalar scalar) + { + TScalar[] value = new TScalar[_dataValue.Length]; + + for(int i = 0; i < _dataValue.Length; i++) + value[i] = _dataValue[i].Multiply(scalar); + + return new VectorValue(value); + } + #endregion + #endregion + + #region Constants + public static Signal Constant(TScalar[] value) + { + return Constant(value, value.ToString()); + } + public static Signal Constant(TScalar[] value, string name) + { + Signal s = Binder.CreateSignal(new VectorValue(value)); + s.Label = name + "_Constant"; + s.EnableFlag(StdAspect.ConstantFlag); + //s.AddConstraint(Properties.ConstantSignalProperty.Instance); + return s; + } + + public static VectorValue Zero + { + get { return new VectorValue(); } //TODO: Think about Singleton like design... + } + + public static VectorValue AdditiveIdentity + { + get { return new VectorValue(); } //TODO: Think about Singleton like design... + } + #endregion + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append('['); + for(int i=0;i<_dataValue.Length;i++) + { + if(i>0) + sb.Append(','); + sb.Append(_dataValue[i].ToString()); + } + sb.Append(']'); + return sb.ToString(); + } + + public override bool Equals(IValueStructure other) + { + VectorValue vectorValue = other as VectorValue; + if(vectorValue != null) + return Equals(vectorValue); + + return other == this; + } + public bool Equals(VectorValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get + { + for(int i = 0; i < _dataValue.Length; i++) + if(!_dataValue[i].IsAdditiveIdentity) + return false; + return true; + } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + + #region Serialization + //protected override void InnerSerialize(XmlWriter writer) + //{ + // writer.WriteElementString("Count", _dataValue.Length.ToString()); + // for(int i = 0; i < _dataValue.Length; i++) + // ValueStructure.Serialize(writer,_dataValue[i]); + //} + //private static VectorValue InnerDeserialize(IContext context, XmlReader reader) + //{ + // int cnt = int.Parse(reader.ReadElementString("Count")); + // TScalar[] values = new TScalar[cnt]; + // for(int i = 0; i < cnt; i++) + // values[i] = (TScalar)ValueStructure.Deserialize(context, reader); + // return new VectorValue(values); + //} + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + Persistence.Serializer.SerializeList(_dataValue, writer, signalMappings, busMappings, "Components"); + } + private static VectorValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + List values = Persistence.Serializer.DeserializeList(reader, signals, buses, "Components"); + return new VectorValue(values); + } + #endregion + + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/TimeCurves/Curve.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/TimeCurves/Curve.cs new file mode 100644 index 0000000..c08e9a1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/TimeCurves/Curve.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.Standard.TimeCurves +{ + public class Curve + { + + private class CurveSegment + { + public Curve Segment; + public TimeSpan Begin; + public IValueStructure Offset; + + + public CurveSegment(Curve segment, TimeSpan begin, IValueStructure offset) + { + this.Segment = segment; + this.Begin = begin; + this.Offset = offset; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/TimeCurves/CurveSegment.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/TimeCurves/CurveSegment.cs new file mode 100644 index 0000000..8884b36 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/TimeCurves/CurveSegment.cs @@ -0,0 +1,38 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Packages.Standard.TimeCurves +{ + public class CurveSegment where T : IValueStructure, IAlgebraicCommutativeRingWithUnity + { + private TimeSpan _timeOffset; + private T _valueOffset; + private T _slopePerSecond; + + public CurveSegment(TimeSpan timeOffset, T valueOffset, T slopePerSecond) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CosecantArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CosecantArchitectures.cs new file mode 100644 index 0000000..e09cc7e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CosecantArchitectures.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class CosecantArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Cosecant", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public CosecantArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Cosecant(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.Cosecant(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + Signal[] outputs = new Signal[manipulatedInputs.Count]; + ReadOnlySignalSet cotangents = StdBuilder.Cotangent(port.InputSignals); + for(int i = 0; i < outputs.Length; i++) + outputs[i] = Std.Multiply(port.OutputSignals[i], cotangents[i], manipulatedInputs[i]); + return StdBuilder.Negate(outputs); + })); + + MathIdentifier typeId = new MathIdentifier("TrigonometricSubstitute", "Std"); + ITheoremProvider basicProvider; + if(!library.TryLookupTheoremType(typeId, out basicProvider)) + { + basicProvider = Binder.GetInstance(typeId); + library.AddTheoremType(basicProvider); + } + ((ITransformationTheoremProvider)basicProvider).Add( + new BasicTransformation(_entityId.DerivePostfix("TrigonometricSubstitute"), typeId, + delegate() { return new Pattern(new EntityCondition(_entityId)); }, + delegate(Port port) { return ManipulationPlan.DoAlter; }, + delegate(Port port, SignalSet transformedInputs, bool hasTransformedInputs) + { + return StdBuilder.Invert(StdBuilder.Sine(transformedInputs)); + //Signal[] ret = new Signal[transformedInputs.Count]; + //for(int i = 0; i < ret.Length; i++) + // ret[i] = Std.Invert(Std.Sine(transformedInputs[i])); + //return ret; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CosineArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CosineArchitectures.cs new file mode 100644 index 0000000..b57f239 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CosineArchitectures.cs @@ -0,0 +1,69 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class CosineArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Cosine", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public CosineArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Cosine(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.Cosine(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + Signal[] outputs = new Signal[manipulatedInputs.Count]; + ReadOnlySignalSet sines = StdBuilder.Sine(port.InputSignals); + for(int i = 0; i < outputs.Length; i++) + outputs[i] = sines[i] * manipulatedInputs[i]; + return StdBuilder.Negate(outputs); + })); + + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CotangentArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CotangentArchitectures.cs new file mode 100644 index 0000000..4f340b8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/CotangentArchitectures.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class CotangentArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Cotangent", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public CotangentArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Cotangent(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.Cotangent(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + Signal[] outputs = new Signal[manipulatedInputs.Count]; + ReadOnlySignalSet squares = StdBuilder.Square(port.OutputSignals); + Signal one = IntegerValue.ConstantOne; + for(int i = 0; i < outputs.Length; i++) + outputs[i] = (one + squares[i]) * manipulatedInputs[i]; + return StdBuilder.Negate(outputs); + })); + + MathIdentifier typeId = new MathIdentifier("TrigonometricSubstitute", "Std"); + ITheoremProvider basicProvider; + if(!library.TryLookupTheoremType(typeId, out basicProvider)) + { + basicProvider = Binder.GetInstance(typeId); + library.AddTheoremType(basicProvider); + } + ((ITransformationTheoremProvider)basicProvider).Add( + new BasicTransformation(_entityId.DerivePostfix("TrigonometricSubstitute"), typeId, + delegate() { return new Pattern(new EntityCondition(_entityId)); }, + delegate(Port port) { return ManipulationPlan.DoAlter; }, + delegate(Port port, SignalSet transformedInputs, bool hasTransformedInputs) + { + Signal[] ret = new Signal[transformedInputs.Count]; + for(int i = 0; i < ret.Length; i++) + ret[i] = StdBuilder.Cosine(transformedInputs[i]) / StdBuilder.Sine(transformedInputs[i]); + return ret; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCosecantArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCosecantArchitectures.cs new file mode 100644 index 0000000..f28284d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCosecantArchitectures.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class HyperbolicCosecantArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("HyperbolicCosecant", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public HyperbolicCosecantArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.HyperbolicCosecant(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.HyperbolicCosecant(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCosineArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCosineArchitectures.cs new file mode 100644 index 0000000..75984a7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCosineArchitectures.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class HyperbolicCosineArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("HyperbolicCosine", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public HyperbolicCosineArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.HyperbolicCosine(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.HyperbolicCosine(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCotangentArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCotangentArchitectures.cs new file mode 100644 index 0000000..a779bd4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicCotangentArchitectures.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class HyperbolicCotangentArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("HyperbolicCotangent", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public HyperbolicCotangentArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.HyperbolicCotangent(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.HyperbolicCotangent(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicSecantArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicSecantArchitectures.cs new file mode 100644 index 0000000..86e9b58 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicSecantArchitectures.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class HyperbolicSecantArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("HyperbolicSecant", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public HyperbolicSecantArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.HyperbolicSecant(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.HyperbolicSecant(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicSineArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicSineArchitectures.cs new file mode 100644 index 0000000..7363f66 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicSineArchitectures.cs @@ -0,0 +1,58 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class HyperbolicSineArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("HyperbolicSine", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public HyperbolicSineArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.HyperbolicSine(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.HyperbolicSine(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicTangentArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicTangentArchitectures.cs new file mode 100644 index 0000000..3b76954 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/HyperbolicTangentArchitectures.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class HyperbolicTangentArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("HyperbolicTangent", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public HyperbolicTangentArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.HyperbolicTangent(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.HyperbolicTangent(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/SecantArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/SecantArchitectures.cs new file mode 100644 index 0000000..36ae4c4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/SecantArchitectures.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class SecantArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Secant", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public SecantArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Secant(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.Secant(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + ReadOnlySignalSet tangents = StdBuilder.Tangent(port.InputSignals); + SignalSet outputs = new SignalSet(); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add(Std.Multiply(port.OutputSignals[i], tangents[i], manipulatedInputs[i])); + return outputs; + })); + + MathIdentifier typeId = new MathIdentifier("TrigonometricSubstitute", "Std"); + ITheoremProvider basicProvider; + if(!library.TryLookupTheoremType(typeId, out basicProvider)) + { + basicProvider = Binder.GetInstance(typeId); + library.AddTheoremType(basicProvider); + } + ((ITransformationTheoremProvider)basicProvider).Add( + new BasicTransformation(_entityId.DerivePostfix("TrigonometricSubstitute"), typeId, + delegate() { return new Pattern(new EntityCondition(_entityId)); }, + delegate(Port port) { return ManipulationPlan.DoAlter; }, + delegate(Port port, SignalSet transformedInputs, bool hasTransformedInputs) + { + return StdBuilder.Invert(StdBuilder.Cosine(transformedInputs)); + //Signal[] ret = new Signal[transformedInputs.Length]; + //for(int i = 0; i < ret.Length; i++) + // ret[i] = StdBuilder.Invert(StdBuilder.Cosine(port.Context, transformedInputs[i])); + //return ret; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/SineArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/SineArchitectures.cs new file mode 100644 index 0000000..5a1c0fb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/SineArchitectures.cs @@ -0,0 +1,69 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class SineArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Sine", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public SineArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Sine(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.Sine(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + SignalSet outputs = new SignalSet(); + ReadOnlySignalSet cosines = StdBuilder.Cosine(port.InputSignals); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add(cosines[i] * manipulatedInputs[i]); + return outputs; + })); + + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/TangentArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/TangentArchitectures.cs new file mode 100644 index 0000000..f4de6b1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Standard/Trigonometry/TangentArchitectures.cs @@ -0,0 +1,89 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Patterns.Toolkit; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.Standard.Trigonometry +{ + public class TangentArchitectures : GenericArchitectureFactory + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Tangent", "Std"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public TangentArchitectures() + : base(_entityId) + { + AddArchitecture(EntityId.DerivePrefix("Real"), + RealValueCategory.IsRealValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(RealValue value) { return value.Tangent(); }, RealValue.ConvertFrom, port.InputSignalCount) }; }); + + AddArchitecture(EntityId.DerivePrefix("Complex"), + ComplexValueCategory.IsComplexValueMember, + delegate(Port port) { return new ProcessBase[] { new GenericStdParallelProcess(delegate(ComplexValue value) { return value.Tangent(); }, ComplexValue.ConvertFrom, port.InputSignalCount) }; }); + } + + public static void RegisterTheorems(ILibrary library) + { + Analysis.DerivativeTransformation.Provider.Add( + new Analysis.DerivativeTransformation(_entityId, + delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) + { + ReadOnlySignalSet squares = StdBuilder.Square(port.OutputSignals); + Signal one = IntegerValue.ConstantOne; + SignalSet outputs = new SignalSet(); + for(int i = 0; i < manipulatedInputs.Count; i++) + outputs.Add((one + squares[i]) * manipulatedInputs[i]); + return outputs; + })); + + MathIdentifier typeId = new MathIdentifier("TrigonometricSubstitute", "Std"); + ITheoremProvider basicProvider; + if(!library.TryLookupTheoremType(typeId, out basicProvider)) + { + basicProvider = Binder.GetInstance(typeId); + library.AddTheoremType(basicProvider); + } + ((ITransformationTheoremProvider)basicProvider).Add( + new BasicTransformation(_entityId.DerivePostfix("TrigonometricSubstitute"), typeId, + delegate() { return new Pattern(new EntityCondition(_entityId)); }, + delegate(Port port) { return ManipulationPlan.DoAlter; }, + delegate(Port port, SignalSet transformedInputs, bool hasTransformedInputs) + { + Signal[] ret = new Signal[transformedInputs.Count]; + for(int i = 0; i < ret.Length; i++) + ret[i] = StdBuilder.Sine(transformedInputs[i]) / StdBuilder.Cosine(transformedInputs[i]); + return ret; + })); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages.Standard/Yttrium.Packages.Standard.csproj b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Yttrium.Packages.Standard.csproj new file mode 100644 index 0000000..e388b47 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages.Standard/Yttrium.Packages.Standard.csproj @@ -0,0 +1,177 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} + Library + Properties + MathNet.Symbolics.Packages + MathNet.Yttrium.Packages.Standard + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351} + Yttrium.Conversion.Toolkit + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C} + Yttrium.Manipulation.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Yttrium.Packages.Helper + + + {6AAA89AE-90D5-496B-9EBD-5274C662C147} + Yttrium.Patterns.Toolkit + + + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257} + Yttrium.Repository.Contracts + + + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Yttrium.Traversing.Contracts + + + + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/PetriNetPackageManager.cs b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/PetriNetPackageManager.cs new file mode 100644 index 0000000..a746adc --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/PetriNetPackageManager.cs @@ -0,0 +1,82 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Packages.ObjectModel; + +namespace MathNet.Symbolics.Packages.PetriNet +{ + public class PetriNetPackageManager : IPackageManager + { + public PetriNetPackageManager() + { + } + + public string Domain + { + get { return "PetriNet"; } + } + + public void Register(ILibrary library) + { + RegisterEntities(library); + RegisterArchitectures(library); + RegisterTheorems(library); + RegisterStructures(library); + } + + public void RegisterEntities(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + library.AddEntity(new ArbitraryGenericEntity("|", "Transition", "PetriNet")); + } + + public void RegisterArchitectures(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + library.AddArchitecture(new TransitionArchitectures()); + } + + public void RegisterTheorems(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + TransitionArchitectures.RegisterTheorems(library); + } + + public void RegisterStructures(ILibrary library) + { + if(library == null) + throw new ArgumentNullException("library"); + + TokenValue.Register(library); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/PetriNetScheduler.cs b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/PetriNetScheduler.cs new file mode 100644 index 0000000..8ca7617 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/PetriNetScheduler.cs @@ -0,0 +1,196 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Numerics.RandomSources; +using MathNet.Symbolics.Simulation; + +namespace MathNet.Symbolics.Packages.PetriNet +{ + public class PetriNetScheduler : IScheduler + { + private List _schedulablesWithEvent; + private List _deltaEvents; + private Timeline _timeline; + private ScheduleStore _schedule; + private SchedulerPhase _phase = SchedulerPhase.Idle; + private TimeSpan _simulationTime; + private RandomSource _random; + + public event EventHandler SimulationTimeProgress; + + public PetriNetScheduler() + { + _schedulablesWithEvent = new List(128); + _deltaEvents = new List(128); + _timeline = new Timeline(); + _schedule = new ScheduleStore(); + _simulationTime = TimeSpan.Zero; + _random = new SystemRandomSource(); + } + + public TimeSpan SimulationTime + { + get { return _simulationTime; } + } + + public void ResetSimulationTime() + { + _simulationTime = TimeSpan.Zero; + } + + public bool SimulateInstant() + { + TimeSpan instant = TimeSpan.FromTicks(1); + return instant <= SimulateFor(instant); + } + + public TimeSpan SimulateFor(TimeSpan timespan) + { + TimeSpan simulatedTimeTotal = TimeSpan.Zero; + TimeSpan simulatedTimePhase = TimeSpan.Zero; + + while(simulatedTimeTotal < timespan) + { + simulatedTimePhase = RunSignalAssignmentPhase(true); + + if(simulatedTimePhase == TimeSpan.MinValue) + return simulatedTimeTotal; + + RunProcessExecutionPhase(); + simulatedTimeTotal += simulatedTimePhase; + } + while(_deltaEvents.Count > 0) + { + RunSignalAssignmentPhase(false); + RunProcessExecutionPhase(); + } + + return simulatedTimeTotal; + } + + public TimeSpan SimulateFor(int cycles) + { + TimeSpan simulatedTimeTotal = TimeSpan.Zero; + TimeSpan simulatedTimePhase = TimeSpan.Zero; + + for(int i = 0; i < cycles; i++) + { + simulatedTimePhase = RunSignalAssignmentPhase(true); + + if(simulatedTimePhase == TimeSpan.MinValue) + return simulatedTimeTotal; + + RunProcessExecutionPhase(); + simulatedTimeTotal += simulatedTimePhase; + } + + return simulatedTimeTotal; + } + + private void RunProcessExecutionPhase() + { + _phase = SchedulerPhase.ProcessExecution; + foreach(ISchedulable item in _schedulablesWithEvent) + item.HasEvent = true; + foreach(ISchedulable item in _schedulablesWithEvent) + item.NotifyOutputsNewValue(); + foreach(ISchedulable item in _schedulablesWithEvent) + item.HasEvent = false; + _schedulablesWithEvent.Clear(); + _phase = SchedulerPhase.Idle; + } + + /// + /// The simulated time. + /// TimeSpan.Zero if no time progress was achieved due to delta events. + /// TimeSpan.MinValue if no events were available. + /// + private TimeSpan RunSignalAssignmentPhase(bool progressTime) + { + _phase = SchedulerPhase.SignalAssignment; + TimeSpan simulatedTime = TimeSpan.Zero; + + while(progressTime && _deltaEvents.Count == 0) + { + TimeSpan timespan; + if(_timeline.TryNextEventTime(out timespan)) + { + _schedule.ProgressTime(timespan, this); + OnSimulationTimeProgress(timespan); + simulatedTime += timespan; + } + else + { + _phase = SchedulerPhase.Idle; + return TimeSpan.MinValue; + // TODO: check, why MinValue? + } + } + + if(_deltaEvents.Count > 0) + { + int index = _random.Next(_deltaEvents.Count); + SchedulerEventItem item = _deltaEvents[index]; + _deltaEvents.RemoveAt(index); + + ISchedulable subject = item.Subject; + if(subject.CurrentValue == null || !subject.CurrentValue.Equals(item.Value)) + { + item.Subject.CurrentValue = item.Value; + _schedulablesWithEvent.Add(item.Subject); + } + } + + _phase = SchedulerPhase.Idle; + return simulatedTime; + } + + + public void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value) + { + _deltaEvents.Add(new SchedulerEventItem(subject, value, TimeSpan.Zero)); + } + + public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) + { + if(delay < TimeSpan.Zero) + return; + if(delay == TimeSpan.Zero) + ScheduleDeltaEvent(subject, value); + else + { + _schedule.ScheduleDelayedEvent(subject, value, delay); + _timeline.InsertTime(delay); + } + } + + private void OnSimulationTimeProgress(TimeSpan timespan) + { + EventHandler handler = SimulationTimeProgress; + if(handler != null) + handler(this, new SimulationTimeEventArgs(timespan)); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..46dcf85 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Yttrium.Packages.PetriNet")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Luzern")] +[assembly: AssemblyProduct("Yttrium.Packages.PetriNet")] +[assembly: AssemblyCopyright("Copyright © Luzern 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e3a0d1f3-3508-423c-b868-ed3e2cabea92")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/TokenValue.cs b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/TokenValue.cs new file mode 100644 index 0000000..dd4257a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/TokenValue.cs @@ -0,0 +1,202 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Conversion; +using System.Xml; + +namespace MathNet.Symbolics.Packages.PetriNet +{ + public class TokenValue : ValueStructureBase, IEquatable, IComparable, IAlgebraicAbelianGroup + { + private static readonly MathIdentifier _customTypeId = new MathIdentifier("Token", "PetriNet"); + private readonly long _dataValue; // = 0; + + #region Conversion & Conversion Routing + public static void Register(ILibrary library) + { + library.AddCustomDataType(); + ValueConverter.AddConverterFrom(true, ConvertFrom); + ValueConverter.AddConverterTo(ValueConverter.Router, true, + delegate(object value) + { + return new IntegerValue(((TokenValue)value).Value); + }); + } + public static TokenValue ConvertFrom(ICustomData value) + { + return (TokenValue)ValueConverter.ConvertFrom(value); + } + public static TokenValue ConvertFrom(IntegerValue value) { return new TokenValue(value.Value); } + public static explicit operator TokenValue(IntegerValue value) { return new TokenValue(value.Value); } + public static bool CanConvertLosslessFrom(ICustomData value) + { + return ValueConverter.Router.CanConvertLosslessFrom(value); + } + #endregion + + #region Constructors + public TokenValue() + { + //this.dataValue = 0; + } + public TokenValue(long value) + { + _dataValue = value; + } + #endregion + + public long Value + { + get { return _dataValue; } + } + + public static MathIdentifier TypeIdentifier + { + get { return _customTypeId; } + } + public override MathIdentifier TypeId + { + get { return _customTypeId; } + } + + #region Direct Function Implementations + public TokenValue Add(TokenValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new TokenValue(_dataValue + op._dataValue); + } + public TokenValue Subtract(TokenValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return new TokenValue(_dataValue - op._dataValue); + } + public TokenValue Negate() + { + return new TokenValue(-_dataValue); + } + public TokenValue Increment() + { + return new TokenValue(_dataValue + 1); + } + public TokenValue Decrement() + { + return new TokenValue(_dataValue - 1); + } + public TokenValue Absolute() + { + return (_dataValue < 0) ? new TokenValue(-_dataValue) : this; + } + public TokenValue Max(TokenValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return (_dataValue >= op._dataValue) ? this : op; + } + public TokenValue Min(TokenValue op) + { + if(op == null) + throw new ArgumentNullException("op"); + + return (_dataValue <= op._dataValue) ? this : op; + } + #endregion + + #region Constants + public static TokenValue Zero + { + get { return new TokenValue(0); } //TODO: Think about Singleton like design... + } + + public static TokenValue One + { + get { return new TokenValue(1); } //TODO: Think about Singleton like design... + } + + public static TokenValue AdditiveIdentity + { + get { return new TokenValue(0); } //TODO: Think about Singleton like design... + } + #endregion + + public override string ToString() + { + return base.ToString() + "(" + _dataValue.ToString(System.Globalization.NumberFormatInfo.InvariantInfo) + ")"; + } + + public bool Equals(TokenValue other) + { + return other != null && _dataValue.Equals(other._dataValue); + } + public override bool Equals(IValueStructure other) + { + TokenValue integerValue = other as TokenValue; + if(integerValue != null) + return Equals(integerValue); + + return false; + } + + public int CompareTo(TokenValue other) + { + return _dataValue.CompareTo(other._dataValue); + } + public override int GetHashCode() + { + return _dataValue.GetHashCode(); + } + + #region IAlgebraicAdditiveIdentityElement Members + public bool IsAdditiveIdentity + { + get { return _dataValue == 0; } + } + IValueStructure IAlgebraicAdditiveIdentityElement.AdditiveIdentity + { + get { return AdditiveIdentity; } + } + #endregion + + #region Serialization + public override void Serialize(XmlWriter writer, IDictionary signalMappings, IDictionary busMappings) + { + writer.WriteString(_dataValue.ToString(Config.InternalNumberFormat)); + } + private static TokenValue Deserialize(XmlReader reader, IDictionary signals, IDictionary buses) + { + return new TokenValue(long.Parse(reader.ReadString(), Config.InternalNumberFormat)); + } + #endregion + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/TransitionArchitectures.cs b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/TransitionArchitectures.cs new file mode 100644 index 0000000..1320669 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/TransitionArchitectures.cs @@ -0,0 +1,83 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Packages.ObjectModel; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.Packages.PetriNet +{ + public class TransitionArchitectures : GenericSimpleArchitecture + { + private static readonly MathIdentifier _entityId = new MathIdentifier("Transition", "PetriNet"); + public static MathIdentifier EntityIdentifier + { + get { return _entityId; } + } + + public TransitionArchitectures() : base(_entityId, false) { } + public TransitionArchitectures(Port port) : base(_entityId, false, port, 0) { } + + protected override void SenseSignals(IList inputSignals, IList internalSignals, IList buses, IList outputSignals) + { + for(int i = 0; i < inputSignals.Count; i++) + SenseSignal(inputSignals[i]); + } + + protected override void Action(IList inputSignals, IList outputSignals, IList internalSignals, IList buses) + { + foreach(Signal input in inputSignals) + { + TokenValue token = input.Value as TokenValue; + if(token == null || token.Value < 1) + return; + } + + // apparently all nodes ok, so we fire: + + foreach(Signal input in inputSignals) + input.PostNewValue(((TokenValue)input.Value).Decrement()); + foreach(Signal output in outputSignals) + output.PostNewValue(((output.Value as TokenValue) ?? TokenValue.Zero).Increment()); + } + + public override bool SupportsPort(Port port) + { + if(port == null) + throw new ArgumentNullException("port"); + + // all inputs must be empty or of type TokenValue + return !port.InputSignals.Exists(delegate(Signal s) { return (s.Value as TokenValue) == null; }); + } + + public override IArchitecture InstantiateToPort(Port port) + { + return new TransitionArchitectures(port); + } + + public static void RegisterTheorems(ILibrary library) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/Yttrium.Packages.PetriNet.csproj b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/Yttrium.Packages.PetriNet.csproj new file mode 100644 index 0000000..bd8ece1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Packages/Yttrium.Packages.PetriNet/Yttrium.Packages.PetriNet.csproj @@ -0,0 +1,100 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD} + Library + Properties + MathNet.Symbolics.Packages.PetriNet + MathNet.Yttrium.Packages.PetriNet + + + true + full + false + ..\..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351} + Yttrium.Conversion.Toolkit + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Yttrium.Packages.Helper + + + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} + Yttrium.Packages.Standard + + + {CFE74A4D-51A2-432C-966A-E29773C55D45} + Yttrium.Simulation.Contracts + + + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2} + Yttrium.Simulation.Service + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/AlwaysTrueCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/AlwaysTrueCondition.cs new file mode 100644 index 0000000..8e6de12 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/AlwaysTrueCondition.cs @@ -0,0 +1,69 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class AlwaysTrueCondition : Condition + { + private static AlwaysTrueCondition _instance; + + private AlwaysTrueCondition() {} + + public static AlwaysTrueCondition Instance + { + get + { + if(_instance == null) + _instance = new AlwaysTrueCondition(); + return _instance; + } + } + + public override int Score + { + get { return 0; } + } + + public override bool FulfillsCondition(Signal output, Port port) + { + return true; + } + + public override bool Equals(Condition other) + { + return other is AlwaysTrueCondition; + } + + protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List children) + { + children.Add(parent); + } + + protected override bool CouldMergeToCoalescedTreeNode(Condition condition) + { + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/AndCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/AndCondition.cs new file mode 100644 index 0000000..b196397 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/AndCondition.cs @@ -0,0 +1,92 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class AndCondition : Condition + { + private IEnumerable _conditions; + + public AndCondition(IEnumerable conditions) + { + _conditions = conditions; + } + public AndCondition(params Condition[] conditions) + { + _conditions = conditions; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + foreach(Condition c in _conditions) + if(!c.FulfillsCondition(output, port)) + return false; + return true; + } + + public override bool Equals(Condition other) + { + AndCondition ot = other as AndCondition; + if(ot == null) + return false; + return IteratorEquals(_conditions.GetEnumerator(), ot._conditions.GetEnumerator()); + } + + protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List children) + { + List conditions = new List(_conditions); + CoalescedTreeNode localParent = parent; + while(conditions.Count > 0) + { + bool found = false; + foreach(CoalescedTreeNode child in localParent.ConditionAxis) + { + if(conditions.Contains(child.Condition)) + { + conditions.Remove(child.Condition); + localParent = child; + found = true; + } + } + if(!found) + { + CoalescedTreeNode node = new CoalescedTreeNode(conditions[conditions.Count - 1]); + conditions.RemoveAt(conditions.Count - 1); + localParent.ConditionAxis.Add(node); + localParent = node; + } + } + children.Add(localParent); + } + + protected override bool CouldMergeToCoalescedTreeNode(Condition condition) + { + foreach(Condition c in _conditions) + if(c.Equals(condition)) + return true; + return false; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/ArchitectureCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/ArchitectureCondition.cs new file mode 100644 index 0000000..678b78b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/ArchitectureCondition.cs @@ -0,0 +1,53 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class ArchitectureCondition : Condition + { + private Predicate _match; + + public ArchitectureCondition(Predicate match) + { + _match = match; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + if(port == null) + return false; + + return port.HasArchitectureLink && _match(port.CurrentArchitecture); + } + + public override bool Equals(Condition other) + { + ArchitectureCondition ot = other as ArchitectureCondition; + if(ot == null) + return false; + return _match.Equals(ot._match); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CoalescedChildPattern.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CoalescedChildPattern.cs new file mode 100644 index 0000000..a29cdf8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CoalescedChildPattern.cs @@ -0,0 +1,82 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + /// + /// + /// + /// The type of the subscriptions attached to the nodes (e.g. ITransformationTheorem). + public class CoalescedChildPattern + { + private List _childAxis; + + public CoalescedChildPattern() + { + _childAxis = new List(4); + } + + public void AddChild(CoalescedTreeNode node) + { + _childAxis.Add(node); + } + + public IList ChildrenAxis + { + get { return _childAxis; } + } + + public MatchCollection MatchAll(Port port, int score) + { + int newScore = score + 3; + + ISignalSet inputs = port.InputSignals; + if(_childAxis.Count != inputs.Count) + return new MatchCollection(); + + // Exact, Ordered Matching + List list = new List(_childAxis.Count); + for(int i = 0; i < _childAxis.Count; i++) + list.Add(_childAxis[i].MatchAll(inputs[i], inputs[i].DrivenByPort, newScore)); + + return MatchCollection.CombineIntersect(list); //CombineAnd(list); + } + + public Match MatchFirst(Port port) + { + ISignalSet inputs = port.InputSignals; + if(_childAxis.Count != inputs.Count) + return null; + + // Exact, Ordered Matching + List list = new List(_childAxis.Count); + for(int i = 0; i < _childAxis.Count; i++) + list.Add(_childAxis[i].MatchAll(inputs[i], inputs[i].DrivenByPort, 3)); + + return MatchCollection.CombineIntersectFirst(list); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CoalescedTreeNode.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CoalescedTreeNode.cs new file mode 100644 index 0000000..4b44d29 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CoalescedTreeNode.cs @@ -0,0 +1,215 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + /// + /// A 4D tree of coalesced patterns, useful to find all patterns of a given type and matching a signal/port tree, in an efficient manner. + /// + public class CoalescedTreeNode + { + private Condition _condition; + private List _subscriptionAxis; + private Dictionary _groupAxis; + private List _conditionAxis; + private List _patternAxis; + + public CoalescedTreeNode(Condition condition) + { + _condition = condition; + _subscriptionAxis = new List(4); + _groupAxis = new Dictionary(4); + _conditionAxis = new List(4); + _patternAxis = new List(4); + } + + public static List CreateRootTree() + { + CoalescedTreeNode root = new CoalescedTreeNode(AlwaysTrueCondition.Instance); + List list = new List(); + list.Add(root); + return list; + } + public static List CreateRootTree(out CoalescedTreeNode root) + { + root = new CoalescedTreeNode(AlwaysTrueCondition.Instance); + List list = new List(); + list.Add(root); + return list; + } + + public Condition Condition + { + get { return _condition; } + } + + public IList ConditionAxis + { + get { return _conditionAxis; } + } + + public IList PatternAxis + { + get { return _patternAxis; } + } + + public IDictionary GroupAxis + { + get { return _groupAxis; } + } + + public IList SubscriptionAxis + { + get { return _subscriptionAxis; } + } + + public void Subscribe(MathIdentifier patternId) + { + _subscriptionAxis.Add(patternId); + } + + public void Unsubscribe(MathIdentifier patternId) + { + _subscriptionAxis.Remove(patternId); + } + + public void AddGroup(MathIdentifier patternId, string label) + { + _groupAxis.Add(patternId, label); + } + + public void RemoveGroup(MathIdentifier patternId) + { + _groupAxis.Remove(patternId); + } + + /// Null, if no match was found. + public Match MatchFirst(Signal output, Port port) + { + // 1. Trial: Try Local Subscriptions + if(_subscriptionAxis.Count > 0) + { + Match m = new Match(_subscriptionAxis[0], 1 + _condition.Score); + + // Check Group Axis + string label; + if(_groupAxis.TryGetValue(m.PatternId, out label)) + m.AppendGroup(label, new Tuple(output, port)); + + return m; + } + + // 2. Trial: Follow Condition Axis + foreach(CoalescedTreeNode condition in _conditionAxis) + { + Match m = condition.MatchFirst(output, port); + + if(m != null) + { + // Check Group Axis + string label; + if(_groupAxis.TryGetValue(m.PatternId, out label)) + m.AppendGroup(label, new Tuple(output, port)); + + return m; + } + } + + // 3. Trial: Follow Pattern Axis. + foreach(CoalescedChildPattern pattern in _patternAxis) + { + Match m = pattern.MatchFirst(port); + + if(m != null) + { + // Check Group Axis + string label; + if(_groupAxis.TryGetValue(m.PatternId, out label)) + m.AppendGroup(label, new Tuple(output, port)); + + return m; + } + } + + // No match found + return null; + } + + public MatchCollection MatchAll(Signal output, Port port, int score) + { + int newScore = score + _condition.Score; + + // Check Node Condition + if(!_condition.FulfillsCondition(output, port)) + return new MatchCollection(); + + List matches = new List(); + + // Follow Condition Axis + foreach(CoalescedTreeNode condition in _conditionAxis) + matches.Add(condition.MatchAll(output, port, newScore)); + + // Follow Pattern Axis + foreach(CoalescedChildPattern pattern in _patternAxis) + matches.Add(pattern.MatchAll(port, newScore)); + + // Combine Matches + MatchCollection res = MatchCollection.CombineUnion(matches); + + // Check Subscription Axis + foreach(MathIdentifier id in _subscriptionAxis) + if(!res.Contains(id)) + res.Add(new Match(id, newScore)); + + // Check Group Axis + foreach(KeyValuePair group in _groupAxis) + { + Match m; + if(res.TryGetValue(group.Key, out m)) + m.AppendGroup(group.Value, new Tuple(output, port)); + } + + return res; + } + + public Match MatchBest(Signal output, Port port) + { + MatchCollection res = MatchAll(output, port, 1); + Match bestMatch = null; + int bestScore = -1; + foreach(Match m in res) + if(m.Score > bestScore) + { + bestMatch = m; + bestScore = m.Score; + } + if(bestScore == -1) + return null; + return bestMatch; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CombinationMode.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CombinationMode.cs new file mode 100644 index 0000000..fb4b44f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/CombinationMode.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public enum CombinationMode + { + None, + All, + One, + AtLeastOne, + AtMostOne + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Condition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Condition.cs new file mode 100644 index 0000000..fb9a38a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Condition.cs @@ -0,0 +1,110 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public abstract class Condition : IEquatable + { + public abstract bool FulfillsCondition(Signal output, Port port); + public abstract bool Equals(Condition other); + + /// A list of nodes we have to subscribe to for matching the parent condition. + /// A list of nodes you'll have to subscribe to for matching this condition. + public IList MergeToCoalescedTree(IList parents) + { + List res = new List(); + foreach(CoalescedTreeNode parent in parents) + MergeToCoalescedTreeNode(parent, res); + return res; + } + + public IList MergeToCoalescedTree() + { + List res = new List(); + CoalescedTreeNode sentinel = new CoalescedTreeNode(AlwaysTrueCondition.Instance); + MergeToCoalescedTreeNode(sentinel, res); + return res; + } + + protected virtual void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List children) + { + CoalescedTreeNode child; + if(!TryGetExistingNode(parent, this, out child)) + { + child = new CoalescedTreeNode(this); + parent.ConditionAxis.Add(child); + } + children.Add(child); + } + + public virtual int Score + { + get { return 1; } + } + + public bool CouldMergeToCoalescedTree(CoalescedTreeNode node) + { + if(node == null) + throw new ArgumentNullException("node"); + + if(node.Condition.Equals(AlwaysTrueCondition.Instance)) + return true; + return CouldMergeToCoalescedTreeNode(node.Condition); + } + + protected virtual bool CouldMergeToCoalescedTreeNode(Condition condition) + { + return Equals(condition); + } + + protected bool IteratorEquals(IEnumerator a, IEnumerator b) + { + while(true) + { + if(a.MoveNext()) + { + if(!(b.MoveNext() && a.Current.Equals(b.Current))) + return false; + } + else // EOF(a) + return !b.MoveNext(); + } + } + + protected bool TryGetExistingNode(CoalescedTreeNode parent, Condition condition, out CoalescedTreeNode node) + { + foreach(CoalescedTreeNode child in parent.ConditionAxis) + { + if(Equals(child.Condition)) + { + node = child; + return true; + } + } + node = null; + return false; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/EntityCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/EntityCondition.cs new file mode 100644 index 0000000..7d9f349 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/EntityCondition.cs @@ -0,0 +1,62 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class EntityCondition : Condition + { + private MathIdentifier _entityId; + + public EntityCondition(MathIdentifier entityId) + { + _entityId = entityId; + } + [Obsolete("Use MathIdentifiers directly",false)] + public EntityCondition(string entityLabel, string entityDomain) + { + _entityId = new MathIdentifier(entityLabel, entityDomain); + } + + public MathIdentifier EntityId + { + get { return _entityId; } + } + + public override bool FulfillsCondition(Signal output, Port port) + { + if(port == null) + return false; + return _entityId.Equals(port.Entity.EntityId); + } + + public override bool Equals(Condition other) + { + EntityCondition ot = other as EntityCondition; + if(ot == null) + return false; + return _entityId.Equals(ot._entityId); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Group.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Group.cs new file mode 100644 index 0000000..005ff1c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Group.cs @@ -0,0 +1,51 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class Group : Collection> + { + private string _label; + public Group(string label) + : base() + { + _label = label; + } + + public string Label + { + get { return _label; } + } + + public void AddRange(IEnumerable> range) + { + foreach(Tuple item in range) + Add(item); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/GroupCollection.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/GroupCollection.cs new file mode 100644 index 0000000..989a1e3 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/GroupCollection.cs @@ -0,0 +1,82 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class GroupCollection : KeyedCollection + { + public GroupCollection() + : base() + { + } + + protected override string GetKeyForItem(Group group) + { + return group.Label; + } + + public bool TryGetValue(string label, out Group group) + { + if(Dictionary == null) + { + group = null; + return false; + } + return Dictionary.TryGetValue(label, out group); + } + + public void Append(string label, Tuple value) + { + Group group; + if(!TryGetValue(label, out group)) + { + group = new Group(label); + Add(group); + } + group.Add(value); + } + public void Append(string label, IEnumerable> values) + { + Group group; + if(!TryGetValue(label, out group)) + { + group = new Group(label); + Add(group); + } + group.AddRange(values); + } + public void Append(Group group) + { + Group localGroup; + if(!TryGetValue(group.Label, out localGroup)) + Add(group); + else + localGroup.AddRange(group); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/InputSignalsFlagCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/InputSignalsFlagCondition.cs new file mode 100644 index 0000000..47c5b87 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/InputSignalsFlagCondition.cs @@ -0,0 +1,87 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class InputSignalsFlagCondition : Condition + { + private NodeFlag _flag; + private FlagState _state; + private CombinationMode _mode; + + public InputSignalsFlagCondition(NodeFlag flag, FlagState state, CombinationMode mode) + { + _flag = flag; + _state = state; + _mode = mode; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + if(port == null) + return false; + + int cnt = 0; + switch(_mode) + { + case CombinationMode.All: + foreach(Signal s in port.InputSignals) + if(s.GetFlagState(_flag) != _state) + return false; + return true; + case CombinationMode.None: + foreach(Signal s in port.InputSignals) + if(s.GetFlagState(_flag) == _state) + return false; + return true; + case CombinationMode.AtLeastOne: + foreach(Signal s in port.InputSignals) + if(s.GetFlagState(_flag) == _state) + return true; + return false; + case CombinationMode.One: + foreach(Signal s in port.InputSignals) + if(s.GetFlagState(_flag) == _state) + cnt++; + return cnt == 1; + case CombinationMode.AtMostOne: + foreach(Signal s in port.InputSignals) + if((s.GetFlagState(_flag) == _state) && cnt++ > 0) + return false; + return true; + default: + throw new NotSupportedException("Pattern Condition doesn't support mode " + _mode.ToString()); + } + } + + public override bool Equals(Condition other) + { + InputSignalsFlagCondition ot = other as InputSignalsFlagCondition; + if(ot == null) + return false; + return _flag.Equals(ot._flag) && (_state == ot._state) && _mode.Equals(ot._mode); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/InputSignalsPropertyCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/InputSignalsPropertyCondition.cs new file mode 100644 index 0000000..825adac --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/InputSignalsPropertyCondition.cs @@ -0,0 +1,85 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class InputSignalsPropertyCondition : Condition + { + private MathIdentifier _propertyType; + private CombinationMode _mode; + + public InputSignalsPropertyCondition(MathIdentifier propertyType, CombinationMode mode) + { + _propertyType = propertyType; + _mode = mode; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + if(port == null) + return false; + + int cnt = 0; + switch(_mode) + { + case CombinationMode.All: + foreach(Signal s in port.InputSignals) + if(!s.HasProperty(_propertyType)) + return false; + return true; + case CombinationMode.None: + foreach(Signal s in port.InputSignals) + if(s.HasProperty(_propertyType)) + return false; + return true; + case CombinationMode.AtLeastOne: + foreach(Signal s in port.InputSignals) + if(s.HasProperty(_propertyType)) + return true; + return false; + case CombinationMode.One: + foreach(Signal s in port.InputSignals) + if(s.HasProperty(_propertyType)) + cnt++; + return cnt == 1; + case CombinationMode.AtMostOne: + foreach(Signal s in port.InputSignals) + if(s.HasProperty(_propertyType) && cnt++ > 0) + return false; + return true; + default: + throw new NotSupportedException("Pattern Condition doesn't support mode " + _mode.ToString()); + } + } + + public override bool Equals(Condition other) + { + InputSignalsPropertyCondition ot = other as InputSignalsPropertyCondition; + if(ot == null) + return false; + return _propertyType.Equals(ot._propertyType) && _mode.Equals(ot._mode); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Match.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Match.cs new file mode 100644 index 0000000..7da88b6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Match.cs @@ -0,0 +1,163 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Numerics; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class Match : IEnumerable + { + private MathIdentifier _patternId; + private GroupCollection _groups; + private int _score; + + public Match(MathIdentifier patternId, int score) + { + _patternId = patternId; + _groups = new GroupCollection(); + _score = score; + } + + #region Static Match Helpers + public static MatchCollection MatchAll(Signal output, Port port, CoalescedTreeNode tree) + { + if(tree == null) + throw new ArgumentNullException("tree"); + + return tree.MatchAll(output, port, 1); + } + public static Match MatchFirst(Signal output, Port port, CoalescedTreeNode tree) + { + if(tree == null) + throw new ArgumentNullException("tree"); + + Match res = tree.MatchFirst(output, port); + if(res == null) + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + return res; + } + public static bool TryMatchFirst(Signal output, Port port, CoalescedTreeNode tree, out Match match) + { + if(tree == null) + throw new ArgumentNullException("tree"); + + match = tree.MatchFirst(output, port); + return match != null; + } + public static Match MatchBest(Signal output, Port port, CoalescedTreeNode tree) + { + if(tree == null) + throw new ArgumentNullException("tree"); + + MatchCollection res = tree.MatchAll(output, port, 1); + Match bestMatch = null; + int bestScore = -1; + foreach(Match m in res) + if(m.Score > bestScore) + { + bestMatch = m; + bestScore = m.Score; + } + if(bestScore == -1) + throw new MathNet.Symbolics.Exceptions.NotFoundException(); + return bestMatch; + } + public static bool TryMatchBest(Signal output, Port port, CoalescedTreeNode tree, out Match match) + { + if(tree == null) + throw new ArgumentNullException("tree"); + + MatchCollection res = tree.MatchAll(output, port, 1); + Match bestMatch = null; + int bestScore = -1; + foreach(Match m in res) + if(m.Score > bestScore) + { + bestMatch = m; + bestScore = m.Score; + } + match = bestMatch; + return bestScore != -1; + } + #endregion + + public MathIdentifier PatternId + { + get { return _patternId; } + } + + public int Score + { + get { return _score; } + } + + public void MergeWithMatch(Match match) + { + if(match.Score > _score) + _score = match.Score; + foreach(Group group in match) + AppendGroup(group); + } + + public Group this[string groupLabel] + { + get { return _groups[groupLabel]; } + } + + public int GroupCount + { + get { return _groups.Count; } + } + + public GroupCollection Groups + { + get { return _groups; } + } + + public void AppendGroup(string label, Tuple value) + { + _groups.Append(label, value); + } + public void AppendGroup(string label, IList> values) + { + _groups.Append(label, values); + } + public void AppendGroup(Group group) + { + _groups.Append(group); + } + + #region IEnumerable Members + public IEnumerator GetEnumerator() + { + return _groups.GetEnumerator(); + } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return _groups.GetEnumerator(); + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/MatchCollection.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/MatchCollection.cs new file mode 100644 index 0000000..87d86f5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/MatchCollection.cs @@ -0,0 +1,152 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class MatchCollection : KeyedCollection + { + public MatchCollection() + : base() + { + } + + protected override MathIdentifier GetKeyForItem(Match item) + { + return item.PatternId; + } + + public bool TryGetValue(MathIdentifier id, out Match match) + { + if(Dictionary == null) + { + match = null; + return false; + } + return Dictionary.TryGetValue(id, out match); + } + + public static MatchCollection CombineUnion(IList matchesList) + { + if(matchesList.Count == 0) + return new MatchCollection(); + if(matchesList.Count == 1) + return matchesList[0]; + + MatchCollection res = matchesList[matchesList.Count - 1]; + matchesList.RemoveAt(matchesList.Count - 1); + + foreach(MatchCollection matches in matchesList) + { + foreach(Match match in matches) + { + /* + * If a match was already added by another chid, + * copy over its captured groups to the existing match. + * Otherwise copy over the whole match. + */ + Match m; + if(res.TryGetValue(match.PatternId, out m)) + m.MergeWithMatch(match); + else + res.Add(match); + } + } + + return res; + } + + ///// + ///// Combines Match lists from a list of children (inputs). To match the parent node, + ///// every match must succeed on every single child (intersection, logical AND). + ///// Labeled groups of the children are merged. + ///// + public static MatchCollection CombineIntersect(IList matchesList) + { + if(matchesList.Count == 1) + return matchesList[0]; + MatchCollection res = new MatchCollection(); + if(matchesList.Count == 0) + return res; + MatchCollection lastMatches = matchesList[matchesList.Count - 1]; + matchesList.RemoveAt(matchesList.Count - 1); + foreach(Match lastMatch in lastMatches) + { + bool suitable = true; + foreach(MatchCollection matches in matchesList) + { + // Ensure AND + Match match; + if(!matches.TryGetValue(lastMatch.PatternId, out match)) + { + suitable = false; + break; + } + // Merge Groups + lastMatch.MergeWithMatch(match); + } + if(suitable) + res.Add(lastMatch); + } + return res; + } + + public static Match CombineIntersectFirst(IList matchesList) + { + if(matchesList.Count == 0) + return null; + if(matchesList.Count == 1) + { + MatchCollection d = matchesList[0]; + if(d.Count > 0) + return d[0]; + else + return null; + + } + MatchCollection lastMatches = matchesList[matchesList.Count - 1]; + matchesList.RemoveAt(matchesList.Count - 1); + foreach(Match lastMatch in lastMatches) + { + bool suitable = true; + foreach(MatchCollection matches in matchesList) + { + // Ensure AND + Match match; + if(!matches.TryGetValue(lastMatch.PatternId, out match)) + { + suitable = false; + break; + } + // Merge Groups + lastMatch.MergeWithMatch(match); + } + if(suitable) + return lastMatch; + } + return null; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/NotCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/NotCondition.cs new file mode 100644 index 0000000..f0fd8e8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/NotCondition.cs @@ -0,0 +1,50 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class NotCondition : Condition + { + private Condition _condition; + + public NotCondition(Condition condition) + { + _condition = condition; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + return !_condition.FulfillsCondition(output, port); + } + + public override bool Equals(Condition other) + { + NotCondition ot = other as NotCondition; + if(ot == null) + return false; + return _condition.Equals(ot._condition); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/OrCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/OrCondition.cs new file mode 100644 index 0000000..ef4ca48 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/OrCondition.cs @@ -0,0 +1,76 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class OrCondition : Condition + { + private IEnumerable _conditions; + + public OrCondition(IEnumerable conditions) + { + _conditions = conditions; + } + public OrCondition(params Condition[] conditions) + { + _conditions = conditions; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + foreach(Condition c in _conditions) + if(c.FulfillsCondition(output, port)) + return true; + return false; + } + + public override bool Equals(Condition other) + { + OrCondition ot = other as OrCondition; + if(ot == null) + return false; + return IteratorEquals(_conditions.GetEnumerator(), ot._conditions.GetEnumerator()); + } + + protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List children) + { + foreach(Condition condition in _conditions) + { + CoalescedTreeNode child; + if(!TryGetExistingNode(parent, condition, out child)) + { + child = new CoalescedTreeNode(condition); + parent.ConditionAxis.Add(child); + } + children.Add(child); + } + } + + protected override bool CouldMergeToCoalescedTreeNode(Condition condition) + { + return false; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/OutputSignalsPropertyCondition.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/OutputSignalsPropertyCondition.cs new file mode 100644 index 0000000..5d7d071 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/OutputSignalsPropertyCondition.cs @@ -0,0 +1,85 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class OutputSignalsPropertyCondition : Condition + { + private MathIdentifier _propertyType; + private CombinationMode _mode; + + public OutputSignalsPropertyCondition(MathIdentifier propertyType, CombinationMode mode) + { + _propertyType = propertyType; + _mode = mode; + } + + public override bool FulfillsCondition(Signal output, Port port) + { + if(port == null) + return false; + + int cnt = 0; + switch(_mode) + { + case CombinationMode.All: + foreach(Signal s in port.OutputSignals) + if(!s.HasProperty(_propertyType)) + return false; + return true; + case CombinationMode.None: + foreach(Signal s in port.OutputSignals) + if(s.HasProperty(_propertyType)) + return false; + return true; + case CombinationMode.AtLeastOne: + foreach(Signal s in port.OutputSignals) + if(s.HasProperty(_propertyType)) + return true; + return false; + case CombinationMode.One: + foreach(Signal s in port.OutputSignals) + if(s.HasProperty(_propertyType)) + cnt++; + return cnt == 1; + case CombinationMode.AtMostOne: + foreach(Signal s in port.OutputSignals) + if(s.HasProperty(_propertyType) && cnt++ > 0) + return false; + return true; + default: + throw new NotSupportedException("Pattern Condition doesn't support mode " + _mode.ToString()); + } + } + + public override bool Equals(Condition other) + { + OutputSignalsPropertyCondition ot = other as OutputSignalsPropertyCondition; + if(ot == null) + return false; + return _propertyType.Equals(ot._propertyType) && _mode.Equals(ot._mode); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Pattern.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Pattern.cs new file mode 100644 index 0000000..bfc14c5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/Pattern.cs @@ -0,0 +1,86 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class Pattern + { + private static Pattern _alwaysTrueInstance; + + private Condition _condition; + private string _group; + + public Pattern() + { + _condition = AlwaysTrueCondition.Instance; + } + public Pattern(Condition condition) + { + _condition = condition; + } + + public static Pattern AlwaysTrueInstance + { + get + { + if(_alwaysTrueInstance == null) + _alwaysTrueInstance = new Pattern(); + return _alwaysTrueInstance; + } + } + + public string Group + { + get { return _group; } + set { _group = value; } + } + + public Condition Condition + { + get { return _condition; } + set { _condition = value; } + } + + public virtual bool Match(Signal output, Port port) + { + return _condition.FulfillsCondition(output, port); + } + + protected void MergeGroupToCoalescedTree(MathIdentifier patternId, IList nodes) + { + if(!string.IsNullOrEmpty(_group)) + foreach(CoalescedTreeNode node in nodes) + node.AddGroup(patternId, _group); + } + + public virtual void MergeToCoalescedTree(MathIdentifier patternId, IList parents) + { + IList nodes = _condition.MergeToCoalescedTree(parents); + MergeGroupToCoalescedTree(patternId, nodes); + foreach(CoalescedTreeNode node in nodes) + node.Subscribe(patternId); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/TreePattern.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/TreePattern.cs new file mode 100644 index 0000000..f4488ae --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Patterns/Toolkit/TreePattern.cs @@ -0,0 +1,166 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.Patterns.Toolkit +{ + public class TreePattern : Pattern + { + private List _children = new List(4); + //private Pattern _catchAll = Pattern.AlwaysTrueInstance; + //private bool _exactMatch = true; + //private bool _ordered = true; + + public TreePattern() : base() {} + public TreePattern(Condition condition) : base(condition) {} + + ///// + ///// If true (default), there's a 1:1 relation between child patterns and child signals. + ///// If false, there may be more child signals than child patterns, which are then processed by the CatchAll pattern. + ///// + //public bool ExactMatch + //{ + // get { return _exactMatch; } + // set { _exactMatch = value; } + //} + + ///// + ///// If true (default), the child signals must appear in the right order. + ///// If false, the patterns are permutated until they fit. + ///// + //public bool Ordered + //{ + // get { return _ordered; } + // set { _ordered = value; } + //} + + //public Pattern CatchAllPattern + //{ + // get { return _catchAll; } + // set { _catchAll = value; } + //} + + public void Add(Pattern child) //, bool optional) + { + _children.Add(child); + } + + public override bool Match(Signal output, Port port) + { + if(!base.Match(output, port)) + return false; + + //if(_exactMatch) + //{ + // if(_ordered) + // { + ISignalSet inputs = port.InputSignals; + if(_children.Count != inputs.Count) + return false; + for(int i = 0; i < _children.Count; i++) + { + if(!_children[i].Match(inputs[i], inputs[i].DrivenByPort)) + return false; + } + return true; + // } + // else // permutation + // { + // throw new NotImplementedException("Ineaxct matching is not implemented yet."); + // } + //} + //else // catch all + //{ + // throw new NotImplementedException("Out of order matching is not implemented yet."); + // //if(_ordered) + // //{ + // //} + // //else // permutation + // //{ + // //} + //} + } + + public override void MergeToCoalescedTree(MathIdentifier patternId, IList parents) + { + if(_children.Count == 0) + base.MergeToCoalescedTree(patternId, parents); + else + { + // Merge Conditions & Groups -> "node"-List + IList nodes = Condition.MergeToCoalescedTree(parents); + MergeGroupToCoalescedTree(patternId, nodes); + + // children: find matching pattern or create one + //AlwaysTrueCondition atc = AlwaysTrueCondition.Instance; + foreach(CoalescedTreeNode node in nodes) + { + // check all patterns the current node already has + IList nodePatterns = node.PatternAxis; + bool nodeMatch = false; + foreach(CoalescedChildPattern pattern in nodePatterns) + { + // check all nodes of the current pattern whether they match. + IList patternChildren = pattern.ChildrenAxis; + if(patternChildren.Count != _children.Count) + continue; + bool patternMatch = true; + for(int i = 0; i < _children.Count; i++) + if(!_children[i].Condition.CouldMergeToCoalescedTree(patternChildren[i])) + { + patternMatch = false; + break; + } + if(patternMatch) + { + // we found a matching pattern. merge our tree pattern to this pattern. + nodeMatch = true; + for(int i = 0; i < _children.Count; i++) + { + IList list = new List(); + list.Add(patternChildren[i]); + _children[i].MergeToCoalescedTree(patternId, list); + } + } + } + if(!nodeMatch) + { + // we didn't find a matching pattern. build a new such pattern. + CoalescedChildPattern pattern = new CoalescedChildPattern(); + for(int i = 0; i < _children.Count; i++) + { + CoalescedTreeNode parent = new CoalescedTreeNode(AlwaysTrueCondition.Instance); + pattern.AddChild(parent); + List list = new List(); + list.Add(parent); + _children[i].MergeToCoalescedTree(patternId, list); + } + node.PatternAxis.Add(pattern); + } + } + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b5f7689 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Patterns")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("6f56b92b-243b-461c-bdcc-7f1cae2e84d7")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Yttrium.Patterns.Toolkit.csproj b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Yttrium.Patterns.Toolkit.csproj new file mode 100644 index 0000000..02ce815 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Patterns.Toolkit/Yttrium.Patterns.Toolkit.csproj @@ -0,0 +1,79 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {6AAA89AE-90D5-496B-9EBD-5274C662C147} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Patterns.Toolkit + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6b8ffbc --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Repository Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("57150a84-218c-49c8-aeeb-4e03e301e730")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Repository/ISignalCache.cs b/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Repository/ISignalCache.cs new file mode 100644 index 0000000..d5a91ea --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Repository/ISignalCache.cs @@ -0,0 +1,35 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Repository +{ + public interface ISignalCache //: IDictionary + { + bool TryGetValue(MathIdentifier key, out Signal signal); + void Add(MathIdentifier key, Signal signal); + bool Remove(MathIdentifier key); + bool ContainsKey(MathIdentifier key); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Yttrium.Repository.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Yttrium.Repository.Contracts.csproj new file mode 100644 index 0000000..8c6fcc2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Contracts/Yttrium.Repository.Contracts.csproj @@ -0,0 +1,57 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Repository.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Repository.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4f9726d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Repository")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("ff0f2cca-7946-41ef-9dfe-4ff683c09376")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Service/Repository/SignalCache.cs b/Backup/src/app/MathNet.Yttrium/Repository.Service/Repository/SignalCache.cs new file mode 100644 index 0000000..97d17c2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Service/Repository/SignalCache.cs @@ -0,0 +1,31 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Repository +{ + public class SignalCache : Dictionary, ISignalCache + { + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Service/RepositoryFactory.cs b/Backup/src/app/MathNet.Yttrium/Repository.Service/RepositoryFactory.cs new file mode 100644 index 0000000..b72aa81 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Service/RepositoryFactory.cs @@ -0,0 +1,39 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Repository; + +namespace MathNet.Symbolics +{ + internal class RepositoryFactory : IFactory + { + // SIGNAL CACHE + ISignalCache IFactory.GetInstance() + { + return new SignalCache(); + } + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Repository.Service/Yttrium.Repository.Service.csproj b/Backup/src/app/MathNet.Yttrium/Repository.Service/Yttrium.Repository.Service.csproj new file mode 100644 index 0000000..d637fc2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Repository.Service/Yttrium.Repository.Service.csproj @@ -0,0 +1,66 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Repository.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257} + Yttrium.Repository.Contracts + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9f49670 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Simulation Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("8de0e760-46dd-4032-a799-c2a56c321535")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/ISchedulable.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/ISchedulable.cs new file mode 100644 index 0000000..ca85fe6 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/ISchedulable.cs @@ -0,0 +1,35 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public interface ISchedulable + { + Guid InstanceId { get; } + IValueStructure CurrentValue { get; set; } + bool HasEvent { get; set; } + void NotifyOutputsNewValue(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/IScheduler.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/IScheduler.cs new file mode 100644 index 0000000..d59e083 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/IScheduler.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public interface IScheduler + { + void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value); + void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay); + + TimeSpan SimulationTime { get; } + void ResetSimulationTime(); + /// True if there were any events available. + bool SimulateInstant(); + /// The time (in simulation time space) to simulate. + /// + /// Actually simulated time. + /// If this time is smaller than , there were no more events available. + /// + TimeSpan SimulateFor(TimeSpan timespan); + /// The number of cycles to simulate. + /// Simulated time. + TimeSpan SimulateFor(int cycles); + + event EventHandler SimulationTimeProgress; + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/ISimulationMediator.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/ISimulationMediator.cs new file mode 100644 index 0000000..9d92d48 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/ISimulationMediator.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public interface ISimulationMediator + { + void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value); + void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay); + + bool SimulateInstant(); + TimeSpan SimulateFor(TimeSpan timespan); + TimeSpan SimulateFor(int cycles); + + IScheduler GetCurrentScheduler(); + + /// see http://mathnet.opensourcedotnet.info/doc/YttriumMathContext.ashx for more details. + void CreateSimulationApartement(IScheduler scheduler); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/SimulationTimeEventArgs.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/SimulationTimeEventArgs.cs new file mode 100644 index 0000000..d754442 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Simulation/SimulationTimeEventArgs.cs @@ -0,0 +1,42 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public class SimulationTimeEventArgs : EventArgs + { + private TimeSpan _timeSpan; + + public SimulationTimeEventArgs(TimeSpan timeSpan) + { + _timeSpan = timeSpan; + } + + public TimeSpan TimeSpan + { + get { return _timeSpan; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Yttrium.Simulation.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Yttrium.Simulation.Contracts.csproj new file mode 100644 index 0000000..72ea423 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Contracts/Yttrium.Simulation.Contracts.csproj @@ -0,0 +1,60 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {CFE74A4D-51A2-432C-966A-E29773C55D45} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Simulation.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b9feb84 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Simulation")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("6c410e47-e59d-4cf2-aa32-7cbd388fc820")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/ImmediateScheduler.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/ImmediateScheduler.cs new file mode 100644 index 0000000..0749bd5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/ImmediateScheduler.cs @@ -0,0 +1,188 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public class ImmediateScheduler : IScheduler + { + private List _schedulablesWithEvent; + private Stack _deltaEvents; + private Timeline _timeline; + private ScheduleStore _schedule; + private SchedulerPhase _phase = SchedulerPhase.Idle; + private TimeSpan _simulationTime; + + public event EventHandler SimulationTimeProgress; + + public ImmediateScheduler() + { + _schedulablesWithEvent = new List(128); + _deltaEvents = new Stack(128); + _timeline = new Timeline(); + _schedule = new ScheduleStore(); + _simulationTime = TimeSpan.Zero; + } + + public TimeSpan SimulationTime + { + get { return _simulationTime; } + } + + public void ResetSimulationTime() + { + _simulationTime = TimeSpan.Zero; + } + + public bool SimulateInstant() + { + TimeSpan instant = TimeSpan.FromTicks(1); + return instant <= SimulateFor(instant); + } + + public TimeSpan SimulateFor(TimeSpan timespan) + { + TimeSpan simulatedTimeTotal = TimeSpan.Zero; + TimeSpan simulatedTimePhase = TimeSpan.Zero; + + while(simulatedTimeTotal < timespan) + { + simulatedTimePhase = RunSignalAssignmentPhase(true); + + if(simulatedTimePhase == TimeSpan.MinValue) + return simulatedTimeTotal; + + RunProcessExecutionPhase(); + simulatedTimeTotal += simulatedTimePhase; + } + while(_deltaEvents.Count > 0) + { + RunSignalAssignmentPhase(false); + RunProcessExecutionPhase(); + } + + return simulatedTimeTotal; + } + + public TimeSpan SimulateFor(int cycles) + { + TimeSpan simulatedTimeTotal = TimeSpan.Zero; + TimeSpan simulatedTimePhase = TimeSpan.Zero; + + for(int i = 0; i < cycles; i++) + { + simulatedTimePhase = RunSignalAssignmentPhase(true); + + if(simulatedTimePhase == TimeSpan.MinValue) + return simulatedTimeTotal; + + RunProcessExecutionPhase(); + simulatedTimeTotal += simulatedTimePhase; + } + + return simulatedTimeTotal; + } + + private void RunProcessExecutionPhase() + { + _phase = SchedulerPhase.ProcessExecution; + foreach(ISchedulable item in _schedulablesWithEvent) + item.HasEvent = true; + foreach(ISchedulable item in _schedulablesWithEvent) + item.NotifyOutputsNewValue(); + foreach(ISchedulable item in _schedulablesWithEvent) + item.HasEvent = false; + _schedulablesWithEvent.Clear(); + _phase = SchedulerPhase.Idle; + } + + /// + /// The simulated time. + /// TimeSpan.Zero if no time progress was achieved due to delta events. + /// TimeSpan.MinValue if no events were available. + /// + private TimeSpan RunSignalAssignmentPhase(bool progressTime) + { + _phase = SchedulerPhase.SignalAssignment; + TimeSpan simulatedTime = TimeSpan.Zero; + + while(progressTime && _deltaEvents.Count == 0) + { + TimeSpan timespan; + if(_timeline.TryNextEventTime(out timespan)) + { + _schedule.ProgressTime(timespan, this); + OnSimulationTimeProgress(timespan); + simulatedTime += timespan; + } + else + { + _phase = SchedulerPhase.Idle; + return TimeSpan.MinValue; + // TODO: check, why MinValue? + } + } + + while(_deltaEvents.Count > 0) + { + SchedulerEventItem item = _deltaEvents.Pop(); + ISchedulable subject = item.Subject; + if(subject.CurrentValue == null || !subject.CurrentValue.Equals(item.Value)) + { + item.Subject.CurrentValue = item.Value; + _schedulablesWithEvent.Add(item.Subject); + } + } + + _phase = SchedulerPhase.Idle; + return simulatedTime; + } + + + public void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value) + { + _deltaEvents.Push(new SchedulerEventItem(subject, value, TimeSpan.Zero)); + } + + public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) + { + if(delay < TimeSpan.Zero) + return; + if(delay == TimeSpan.Zero) + ScheduleDeltaEvent(subject, value); + else + { + _schedule.ScheduleDelayedEvent(subject, value, delay); + _timeline.InsertTime(delay); + } + } + + private void OnSimulationTimeProgress(TimeSpan timespan) + { + EventHandler handler = SimulationTimeProgress; + if(handler != null) + handler(this, new SimulationTimeEventArgs(timespan)); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/ScheduleStore.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/ScheduleStore.cs new file mode 100644 index 0000000..61564cd --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/ScheduleStore.cs @@ -0,0 +1,112 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public class ScheduleStore + { + private Dictionary> _delayedEvents; + + public ScheduleStore() + { + _delayedEvents = new Dictionary>(); + } + + private void RemoveAllAfterIncluding(LinkedList timeline, LinkedListNode node) + { + while(node.Next != null) + timeline.Remove(node.Next); + timeline.Remove(node); + } + + public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) + { + LinkedList timeline; + if(!_delayedEvents.TryGetValue(subject.InstanceId, out timeline)) + { + timeline = new LinkedList(); + _delayedEvents.Add(subject.InstanceId, timeline); + } + + if(timeline.Count == 0) + { + timeline.AddFirst(new SchedulerEventItem(subject, value, delay)); + return; + } + + TimeSpan d = TimeSpan.Zero; + LinkedListNode node = timeline.First; + + while(true) + { + if(d + node.Value.TimeSpan == delay) //already there... + { + TimeSpan relativeDelay = node.Value.TimeSpan; + RemoveAllAfterIncluding(timeline, node); + timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); + return; + } + + if(d + node.Value.TimeSpan > delay) //later events available + { + TimeSpan relativeDelay = delay - d; + RemoveAllAfterIncluding(timeline, node); + timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); + return; + } + + if(node.Next == null) //last + { + TimeSpan relativeDelay = delay - d - node.Value.TimeSpan; + timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); + return; + } + + d += node.Value.TimeSpan; + node = node.Next; + } + } + + public void ProgressTime(TimeSpan timespan, IScheduler scheduler) + { + foreach(KeyValuePair> schedulable in _delayedEvents) + { + TimeSpan span = timespan; + LinkedList timeline = schedulable.Value; + while(timeline.First != null && span >= TimeSpan.Zero) + { + SchedulerEventItem item = timeline.First.Value; + item.TimeSpan -= span; + span = -item.TimeSpan; + if(item.TimeSpan <= TimeSpan.Zero) + { + scheduler.ScheduleDeltaEvent(item.Subject, item.Value); + timeline.RemoveFirst(); + } + } + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SchedulerEventItem.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SchedulerEventItem.cs new file mode 100644 index 0000000..68d3515 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SchedulerEventItem.cs @@ -0,0 +1,57 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public struct SchedulerEventItem + { + private readonly ISchedulable _subject; + private readonly IValueStructure _value; + private TimeSpan _timeSpan; + + public SchedulerEventItem(ISchedulable subject, IValueStructure value, TimeSpan timeSpan) + { + _subject = subject; + _value = value; + _timeSpan = timeSpan; + } + + public ISchedulable Subject + { + get { return _subject; } + } + + public IValueStructure Value + { + get { return _value; } + } + + public TimeSpan TimeSpan + { + get { return _timeSpan; } + set { _timeSpan = value; } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SchedulerPhase.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SchedulerPhase.cs new file mode 100644 index 0000000..c1aae89 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SchedulerPhase.cs @@ -0,0 +1,34 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public enum SchedulerPhase + { + Idle, + ProcessExecution, + SignalAssignment + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SimulationMediator.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SimulationMediator.cs new file mode 100644 index 0000000..6808236 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/SimulationMediator.cs @@ -0,0 +1,102 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Events; + +namespace MathNet.Symbolics.Simulation +{ + public class SimulationMediator : ISimulationMediator + { + private Dictionary _schedulerStack; + + public SimulationMediator() + { + _schedulerStack = new Dictionary(); + MathContext.ContextExpired += MathContext_ContextExpired; + } + + public void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value) + { + GetCurrentScheduler().ScheduleDeltaEvent(subject, value); + } + + public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) + { + GetCurrentScheduler().ScheduleDelayedEvent(subject, value, delay); + } + + public bool SimulateInstant() + { + return GetCurrentScheduler().SimulateInstant(); + } + public TimeSpan SimulateFor(TimeSpan timespan) + { + return GetCurrentScheduler().SimulateFor(timespan); + } + public TimeSpan SimulateFor(int cycles) + { + return GetCurrentScheduler().SimulateFor(cycles); + } + + public IScheduler GetCurrentScheduler() + { + MathContext ctx = MathContext.Current; + Guid currentId = ctx.InstanceId; + + lock(_schedulerStack) + { + IScheduler scheduler; + if(_schedulerStack.TryGetValue(ctx.InstanceId, out scheduler)) + return scheduler; + while(ctx.HasParent) + { + ctx = ctx.ParentContext; + if(_schedulerStack.TryGetValue(ctx.InstanceId, out scheduler)) + return scheduler; + } + scheduler = new ImmediateScheduler(); + _schedulerStack.Add(currentId, scheduler); + return scheduler; + } + } + + public void CreateSimulationApartement(IScheduler scheduler) + { + MathContext ctx = MathContext.Current; + lock(_schedulerStack) // don't interfer with GetCurrentScheduler + { + _schedulerStack.Add(ctx.InstanceId, scheduler); + } + } + + void MathContext_ContextExpired(object sender, MathContextEventArgs e) + { + if(_schedulerStack.ContainsKey(e.InstanceId)) + _schedulerStack.Remove(e.InstanceId); + } + + + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/Timeline.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/Timeline.cs new file mode 100644 index 0000000..6173f5d --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Simulation/Timeline.cs @@ -0,0 +1,87 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Simulation +{ + public class Timeline + { + private LinkedList _timeline; + + public Timeline() + { + _timeline = new LinkedList(); + } + + public void InsertTime(TimeSpan delay) + { + if(_timeline.Count == 0) + { + _timeline.AddFirst(delay); + return; + } + + TimeSpan d = TimeSpan.Zero; + LinkedListNode node = _timeline.First; + + while(true) + { + if(d + node.Value == delay) //already there... + return; + + if(d + node.Value > delay) //later events available + { + _timeline.AddAfter(node, d + node.Value - delay); + node.Value = delay - d; + return; + } + + if(node.Next == null) //last + { + _timeline.AddAfter(node, delay - d - node.Value); + return; + } + + d += node.Value; + node = node.Next; + } + } + + /// True if there were future event available and the simulation time progressed. + public bool TryNextEventTime(out TimeSpan timespan) + { + if(_timeline.Count == 0) + { + timespan = TimeSpan.Zero; + return false; + } + else + { + timespan = _timeline.First.Value; + _timeline.RemoveFirst(); + return true; + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/SimulationFactory.cs b/Backup/src/app/MathNet.Yttrium/Simulation.Service/SimulationFactory.cs new file mode 100644 index 0000000..bc2dc51 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/SimulationFactory.cs @@ -0,0 +1,39 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Simulation; + +namespace MathNet.Symbolics +{ + internal class SimulationFactory : IFactory + { + private static ISimulationMediator _mediator = new SimulationMediator(); + + ISimulationMediator IFactory.GetInstance() + { + return _mediator; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Simulation.Service/Yttrium.Simulation.Service.csproj b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Yttrium.Simulation.Service.csproj new file mode 100644 index 0000000..a65b753 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Simulation.Service/Yttrium.Simulation.Service.csproj @@ -0,0 +1,71 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Simulation.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {CFE74A4D-51A2-432C-966A-E29773C55D45} + Yttrium.Simulation.Contracts + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b5f7689 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Patterns")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("6f56b92b-243b-461c-bdcc-7f1cae2e84d7")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/BuilderStateMachine.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/BuilderStateMachine.cs new file mode 100644 index 0000000..62ead49 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/BuilderStateMachine.cs @@ -0,0 +1,96 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + public enum BuilderState : int + { + Idle = 0, + System = 1, + Signals = 2, + Buses = 3, + Ports = 4, + SignalDetails = 5, + InputSignals = 6, + OutputSignals = 7, + NamedSignals = 8, + NamedBuses = 9 + } + + public class BuilderStateMachine + { + private BuilderState _state; + + public BuilderStateMachine() + { + _state = BuilderState.Idle; + } + + public BuilderState CurrentState + { + get { return _state; } + set { _state = value; } + } + + public virtual void Reset() + { + _state = BuilderState.Idle; + } + + public bool IsInsideSystem + { + get { return _state != BuilderState.Idle; } + } + + public bool IsInsideGroup + { + get { return _state != BuilderState.Idle && _state != BuilderState.System; } + } + + public bool CanAdvanceTo(BuilderState next) + { + if(next == BuilderState.Idle) + return true; + + int n = (int)next; + int s = (int)_state; + + return n >= s; + } + + public void AdvanceTo(BuilderState next) + { + if(!CanAdvanceTo(next)) + throw new InvalidOperationException("Can't move from state " + _state.ToString() + " to state " + next.ToString() + "."); + BuilderState before = _state; + _state = next; + OnAfterAdvance(before, next, before != BuilderState.Idle, before != BuilderState.Idle && before != BuilderState.System); + } + + protected virtual void OnAfterAdvance(BuilderState before, BuilderState after, bool wasInsideSystem, bool wasInsideGroup) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/ExpressionWriter.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/ExpressionWriter.cs new file mode 100644 index 0000000..07e07a5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/ExpressionWriter.cs @@ -0,0 +1,157 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + /// + /// Concrete System Builder for constructing an (incomplete) expression + /// strings compatible with the parser infrastructure. + /// + public class ExpressionWriter : ISystemBuilder + { + /* + * Works, but is incomplete (TODO) + */ + + private Queue _writtenExpressions; + private Dictionary _signalMappings; + private Dictionary _busMappings; + private StringBuilder _current; + + public ExpressionWriter() + { + _writtenExpressions = new Queue(); + _signalMappings = new Dictionary(); + _busMappings = new Dictionary(); + } + + public Queue WrittenExpressions + { + get { return _writtenExpressions; } + } + + public void BeginBuildSystem(int inputSignalCount, int outputSignalCount, int busCount) + { + _current = new StringBuilder(); + } + + public Guid BuildSignal(string label, bool hold, bool isSource) + { + Guid guid = Guid.NewGuid(); + if(string.IsNullOrEmpty(label)) + label = "S" + guid.ToString("N"); + _signalMappings.Add(guid, label); + _current.AppendFormat("signal {0};", label); + _current.AppendLine(); + return guid; + } + + public Guid BuildBus(string label) + { + Guid guid = Guid.NewGuid(); + if(string.IsNullOrEmpty(label)) + label = "S" + guid.ToString("N"); + _busMappings.Add(guid, label); + _current.AppendFormat("bus {0};", label); + _current.AppendLine(); + return guid; + } + + public Guid BuildPort(MathIdentifier entityId, InstanceIdSet inputSignals, InstanceIdSet outputSignals, InstanceIdSet buses) + { + Guid guid = Guid.NewGuid(); + _current.AppendFormat("instanciate {0}", entityId.ToString()); + if(inputSignals.Count > 0) + { + _current.Append(" in "); + for(int i = 0; i < inputSignals.Count; i++) + { + if(i > 0) _current.Append(','); + _current.Append(_signalMappings[inputSignals[i]]); + } + } + if(outputSignals.Count > 0) + { + _current.Append(" out "); + for(int i = 0; i < outputSignals.Count; i++) + { + if(i > 0) _current.Append(','); + _current.Append(_signalMappings[outputSignals[i]]); + } + } + if(buses.Count > 0) + { + _current.Append(" bus "); + for(int i = 0; i < buses.Count; i++) + { + if(i > 0) _current.Append(','); + _current.Append(_busMappings[buses[i]]); + } + } + _current.AppendLine(";"); + return guid; + } + + public void AppendSignalValue(Guid iid, ICustomDataPack value) + { + //_current.AppendFormat("{0} <- {1}", _signalMappings[iid], ??); + } + + public void AppendSignalProperty(Guid iid, ICustomDataPack property) + { + //_current.AppendFormat("assume {0} is {1}", _signalMappings[iid], ??); + } + + public void AppendSignalConstraint(Guid iid, ICustomDataPack constraint) + { + //_current.AppendFormat("assume {0} is {1}", _signalMappings[iid], ??); + } + + public void AppendSystemInputSignal(Guid iid) + { + } + + public void AppendSystemOutputSignal(Guid iid) + { + } + + public void AppendSystemNamedSignal(Guid iid, string name) + { + } + + public void AppendSystemNamedBus(Guid iid, string name) + { + } + + public void EndBuildSystem() + { + _writtenExpressions.Enqueue(_current.ToString()); + _current = null; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/Packages.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/Packages.cs new file mode 100644 index 0000000..c14a84f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/Packages.cs @@ -0,0 +1,285 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Xml; +using System.Xml.XPath; +using System.Xml.Serialization; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + /// + /// intermediate custom data description. + /// + [Serializable] + public sealed class CustomDataPack : ICustomDataPack, ISerializable, IXmlSerializable where T : ICustomData + { + private string _serializedXmlFragment; + + private CustomDataPack(string serializedXml) + { + _serializedXmlFragment = serializedXml; + } + + public string SerializedXmlFragment + { + get { return _serializedXmlFragment; } + //set { _serializedXml = value; } + } + + public static CustomDataPack Pack(T property, IDictionary signalMappings, IDictionary busMappings) + { + string xml = Persistence.Serializer.SerializeToString(property, signalMappings, busMappings); + return new CustomDataPack(xml); + } + + public static CustomDataPack Repack(string serializedXml, IDictionary signalMappings, IDictionary busMappings) + { + StringBuilder sb = new StringBuilder(serializedXml); + foreach(KeyValuePair pair in signalMappings) + sb.Replace(pair.Key.ToString(), pair.Value.ToString()); + foreach(KeyValuePair pair in busMappings) + sb.Replace(pair.Key.ToString(), pair.Value.ToString()); + return new CustomDataPack(sb.ToString()); + } + + public T Unpack(IDictionary signals, IDictionary buses) + { + return Persistence.Serializer.DeserializeFromString(_serializedXmlFragment, signals, buses); + } + + #region Serialization + private CustomDataPack() + { + } + private CustomDataPack(SerializationInfo info, StreamingContext context) + { + _serializedXmlFragment = info.GetString("xml"); + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("xml", _serializedXmlFragment); + } + System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema() + { + throw new NotImplementedException(); + } + void IXmlSerializable.ReadXml(XmlReader reader) + { + reader.ReadToFollowing("CustomDataPack", Config.YttriumNamespace); + _serializedXmlFragment = reader.ReadInnerXml(); + reader.ReadEndElement(); + } + void IXmlSerializable.WriteXml(XmlWriter writer) + { + writer.WriteStartElement("CustomDataPack", Config.YttriumNamespace); + writer.WriteRaw(_serializedXmlFragment); + writer.WriteEndElement(); + } + #endregion + } + + ///// + ///// intermediate property description. + ///// + //[Serializable] + //[Obsolete("Use generic CustomDataPack instead")] + //public sealed class PropertyPack : ISerializable, IXmlSerializable + //{ + // private string _serializedXmlFragment; + + // private PropertyPack(string serializedXml) + // { + // _serializedXmlFragment = serializedXml; + // } + + // public string SerializedXmlFragment + // { + // get { return _serializedXmlFragment; } + // //set { _serializedXml = value; } + // } + + // public static PropertyPack Pack(IProperty property, IDictionary signalMappings, IDictionary busMappings) + // { + // string xml = Serializer.SerializeToString(property, signalMappings, busMappings); + // return new PropertyPack(xml); + + // //StringBuilder sb = new StringBuilder(); + // //XmlWriterSettings settings = new XmlWriterSettings(); + // //settings.Encoding = Context.DefaultEncoding; + // //settings.Indent = false; + // //settings.ConformanceLevel = ConformanceLevel.Fragment; + // //settings.NewLineHandling = NewLineHandling.Entitize; + // //settings.OmitXmlDeclaration = true; + // //XmlWriter writer = XmlWriter.Create(sb, settings); + // //Property.Serialize(writer, property); + // //writer.Flush(); + // //writer.Close(); + // //return new PropertyPack(sb.ToString()); + // } + + // public static PropertyPack Repack(string serializedXml, IDictionary signalMappings, IDictionary busMappings) + // { + // StringBuilder sb = new StringBuilder(serializedXml); + // foreach(KeyValuePair pair in signalMappings) + // sb.Replace(pair.Key.ToString(), pair.Value.ToString()); + // foreach(KeyValuePair pair in busMappings) + // sb.Replace(pair.Key.ToString(), pair.Value.ToString()); + // return new PropertyPack(sb.ToString()); + // } + + // public IProperty Unpack(IContext context, IDictionary signals, IDictionary buses) + // { + // return Serializer.DeserializeFromString(_serializedXmlFragment, context, signals, buses); + + // //StringReader sr = new StringReader(_serializedXmlFragment); + // //XmlReader reader = XmlReader.Create(sr); + // //return Property.Deserialize(context, reader); + // } + + // #region Serialization + // private PropertyPack() + // { + // } + // private PropertyPack(SerializationInfo info, StreamingContext context) + // { + // _serializedXmlFragment = info.GetString("xml"); + // } + // [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + // void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + // { + // info.AddValue("xml", _serializedXmlFragment); + // } + // System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema() + // { + // throw new NotImplementedException(); + // } + // void IXmlSerializable.ReadXml(XmlReader reader) + // { + // reader.ReadToFollowing("PropertyPack", Context.YttriumNamespace); + // _serializedXmlFragment = reader.ReadInnerXml(); + // reader.ReadEndElement(); + // } + // void IXmlSerializable.WriteXml(XmlWriter writer) + // { + // writer.WriteStartElement("PropertyPack", Context.YttriumNamespace); + // writer.WriteRaw(_serializedXmlFragment); + // writer.WriteEndElement(); + // } + // #endregion + //} + + ///// + ///// intermediate value structure description. + ///// + //[Serializable] + //[Obsolete("Use generic CustomDataPack instead")] + //public sealed class StructurePack : ISerializable, IXmlSerializable + //{ + // private string _serializedXmlFragment; + + // private StructurePack(string serializedXml) + // { + // _serializedXmlFragment = serializedXml; + // } + + // public string SerializedXmlFragment + // { + // get { return _serializedXmlFragment; } + // //set { _serializedXml = value; } + // } + + // public static StructurePack Pack(IValueStructure structure, IDictionary signalMappings, IDictionary busMappings) + // { + // string xml = Serializer.SerializeToString(structure, signalMappings, busMappings); + // return new StructurePack(xml); + + // //StringBuilder sb = new StringBuilder(); + // //XmlWriterSettings settings = new XmlWriterSettings(); + // //settings.Encoding = Context.DefaultEncoding; + // //settings.Indent = false; + // //settings.ConformanceLevel = ConformanceLevel.Fragment; + // //settings.NewLineHandling = NewLineHandling.Entitize; + // //settings.OmitXmlDeclaration = true; + // //XmlWriter writer = XmlWriter.Create(sb, settings); + // //ValueStructure.Serialize(writer, structure); + // //writer.Flush(); + // //writer.Close(); + // //return new StructurePack(sb.ToString()); + // } + + // public static StructurePack Repack(string serializedXml, IDictionary signalMappings, IDictionary busMappings) + // { + // StringBuilder sb = new StringBuilder(serializedXml); + // foreach(KeyValuePair pair in signalMappings) + // sb.Replace(pair.Key.ToString(), pair.Value.ToString()); + // foreach(KeyValuePair pair in busMappings) + // sb.Replace(pair.Key.ToString(), pair.Value.ToString()); + // return new StructurePack(sb.ToString()); + // } + + // public IValueStructure Unpack(IContext context, IDictionary signals, IDictionary buses) + // { + // return Serializer.DeserializeFromString(_serializedXmlFragment, context, signals, buses); + + // //StringReader sr = new StringReader(_serializedXmlFragment); + // //XmlReader reader = XmlReader.Create(sr); + // //return ValueStructure.Deserialize(context, reader); + // } + + // #region Serialization + // private StructurePack() + // { + // } + // private StructurePack(SerializationInfo info, StreamingContext context) + // { + // _serializedXmlFragment = info.GetString("xml"); + // } + // [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] + // void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + // { + // info.AddValue("xml", _serializedXmlFragment); + // } + // System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema() + // { + // throw new NotImplementedException(); + // } + // void IXmlSerializable.ReadXml(XmlReader reader) + // { + // reader.ReadToFollowing("StructurePack", Context.YttriumNamespace); + // _serializedXmlFragment = reader.ReadInnerXml(); + // reader.ReadEndElement(); + // } + // void IXmlSerializable.WriteXml(XmlWriter writer) + // { + // writer.WriteStartElement("StructurePack", Context.YttriumNamespace); + // writer.WriteRaw(_serializedXmlFragment); + // writer.WriteEndElement(); + // } + // #endregion + //} +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/SystemReader.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/SystemReader.cs new file mode 100644 index 0000000..1768456 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/SystemReader.cs @@ -0,0 +1,48 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + /// + /// System Builder Director for reading a . + /// + public class SystemReader + { + private ISystemBuilder _builder; + + public SystemReader(ISystemBuilder builder) + { + _builder = builder; + } + + public void ReadSystem(IMathSystem system) + { + if(system == null) + throw new ArgumentNullException("system"); + + system.AcceptSystemBuilder(_builder); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/SystemWriter.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/SystemWriter.cs new file mode 100644 index 0000000..f74f291 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/SystemWriter.cs @@ -0,0 +1,140 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; +using MathNet.Symbolics.Library; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + /// + /// Concrete System Builder for constructing a . + /// + public class SystemWriter : ISystemBuilder + { + private Queue _writtenSystems; + private IMathSystem _system; + private Dictionary _signalMappings; + private Dictionary _busMappings; + + public SystemWriter() + { + _writtenSystems = new Queue(); + _signalMappings = new Dictionary(); + _busMappings = new Dictionary(); + } + + public Queue WrittenSystems + { + get { return _writtenSystems; } + } + + private SignalSet MapSignals(InstanceIdSet signals) + { + return SignalSet.ConvertAllFromInstanceIds(signals, delegate(Guid id) { return _signalMappings[id]; }); + } + private BusSet MapBuses(InstanceIdSet buses) + { + return BusSet.ConvertAllFromInstanceIds(buses, delegate(Guid id) { return _busMappings[id]; }); + } + + public void BeginBuildSystem(int inputSignalCount, int outputSignalCount, int busCount) + { + _system = Binder.CreateSystem(); + _signalMappings.Clear(); + _busMappings.Clear(); + } + + public Guid BuildSignal(string label, bool hold, bool isSource) + { + Signal s = Binder.CreateSignal(); + _system.AddSignal(s); + _signalMappings.Add(s.InstanceId, s); + return s.InstanceId; + } + + public Guid BuildBus(string label) + { + Bus b = Binder.CreateBus(); + _system.AddBus(b); + _busMappings.Add(b.InstanceId, b); + return b.InstanceId; + } + + public Guid BuildPort(MathIdentifier entityId, InstanceIdSet inputSignals, InstanceIdSet outputSignals, InstanceIdSet buses) + { + IEntity entity = Service.Instance.LookupEntity(entityId); + Port p = entity.InstantiatePort(MapSignals(inputSignals), MapSignals(outputSignals), MapBuses(buses)); + _system.AddPort(p); + return p.InstanceId; + } + + public void AppendSignalValue(Guid iid, ICustomDataPack value) + { + IValueStructure structure = value.Unpack(_signalMappings, _busMappings); + ((ISignal_BuilderAdapter)_signalMappings[iid]).BuilderSetValue(structure); + } + + public void AppendSignalProperty(Guid iid, ICustomDataPack property) + { + IProperty prop = property.Unpack(_signalMappings, _busMappings); + ((ISignal_BuilderAdapter)_signalMappings[iid]).BuilderAppendProperty(prop); + } + + public void AppendSignalConstraint(Guid iid, ICustomDataPack constraint) + { + IProperty prop = constraint.Unpack(_signalMappings, _busMappings); + ((ISignal_BuilderAdapter)_signalMappings[iid]).BuilderAppendConstraint(prop); + } + + public void AppendSystemInputSignal(Guid iid) + { + _system.PromoteAsInput(_signalMappings[iid]); + } + + public void AppendSystemOutputSignal(Guid iid) + { + _system.PromoteAsOutput(_signalMappings[iid]); + } + + public void AppendSystemNamedSignal(Guid iid, string name) + { + _system.AddNamedSignal(name, _signalMappings[iid]); + } + + public void AppendSystemNamedBus(Guid iid, string name) + { + _system.AddNamedBus(name, _busMappings[iid]); + } + + public void EndBuildSystem() + { + _writtenSystems.Enqueue(_system); + _system = null; + _signalMappings.Clear(); + _busMappings.Clear(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/XmlSystemReader.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/XmlSystemReader.cs new file mode 100644 index 0000000..8d86f6f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/XmlSystemReader.cs @@ -0,0 +1,242 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + /// + /// System Builder Director for reading a complete Xml representation. + /// + public class XmlSystemReader + { + private ISystemBuilder _builder; + private XmlReader _reader; + private StateMachine _fsm; + + private class StateMachine : BuilderStateMachine + { + private XmlReader _reader; + + public StateMachine() + { + } + //public StateMachine(XmlReader reader) + //{ + // _reader = reader; + //} + + public XmlReader Reader + { + //get { return _reader; } + set { _reader = value; } + } + + public BuilderState ReadNextState() + { + while(!_reader.IsStartElement()) + { + if(_reader.NodeType == XmlNodeType.EndElement && _reader.LocalName.Equals("System")) + { + AdvanceTo(BuilderState.Idle); + return CurrentState; + } + else + _reader.Read(); + } + AdvanceTo((BuilderState)Enum.Parse(typeof(BuilderState), _reader.LocalName)); + return CurrentState; + } + } + + public XmlSystemReader(ISystemBuilder builder) + { + _builder = builder; + _fsm = new StateMachine(); + } + + /// true if a start-element was found, false if an end-element was found. + private bool ReadToElement() + { + while(!_reader.IsStartElement()) + { + if(_reader.NodeType == XmlNodeType.EndElement) + return false; + else + _reader.Read(); + } + return true; + } + + public void ReadSystems(XmlReader reader, bool multiple) + { + _reader = reader; + _fsm.Reader = reader; + _fsm.Reset(); + + Dictionary signalMappings = new Dictionary(); + Dictionary busMappings = new Dictionary(); + + bool active = false; + + BuilderState state; + while(BuilderState.Idle != (state = _fsm.ReadNextState()) || active) + { + switch(state) + { + case BuilderState.System: + int inputCnt = int.Parse(_reader.GetAttribute("inputCount"), Config.InternalNumberFormat); + int outputCnt = int.Parse(_reader.GetAttribute("outputCount"), Config.InternalNumberFormat); + int busCnt = int.Parse(_reader.GetAttribute("busCount"), Config.InternalNumberFormat); + _reader.Read(); + _builder.BeginBuildSystem(inputCnt, outputCnt, busCnt); + active = true; + break; + case BuilderState.Signals: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "Signal") + { + Guid myGuid = new Guid(_reader.GetAttribute("iid")); + string label = _reader.GetAttribute("label"); + bool hold = bool.Parse(_reader.GetAttribute("hold")); + bool isSource = bool.Parse(_reader.GetAttribute("isSource")); + _reader.Read(); + Guid tGuid = _builder.BuildSignal(label, hold, isSource); + signalMappings.Add(myGuid, tGuid); + } + break; + case BuilderState.Buses: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "Bus") + { + Guid myGuid = new Guid(_reader.GetAttribute("iid")); + string label = _reader.GetAttribute("label"); + _reader.Read(); + Guid tGuid = _builder.BuildBus(label); + busMappings.Add(myGuid, tGuid); + } + break; + case BuilderState.Ports: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "Port") + { + InstanceIdSet inputSignals = new InstanceIdSet(); + InstanceIdSet outputSignals = new InstanceIdSet(); + InstanceIdSet buses = new InstanceIdSet(); + //Guid myGuid = new Guid(_reader.GetAttribute("iid")); + MathIdentifier entityId = MathIdentifier.Parse(_reader.GetAttribute("entityId")); + _reader.ReadToDescendant("InputSignals"); + _reader.Read(); + while(_reader.IsStartElement("SignalRef")) + inputSignals.Add(signalMappings[new Guid(_reader.ReadElementString())]); + _reader.ReadEndElement(); + _reader.ReadToFollowing("OutputSignals"); + _reader.Read(); + while(_reader.IsStartElement("SignalRef")) + outputSignals.Add(signalMappings[new Guid(_reader.ReadElementString())]); + _reader.ReadEndElement(); + _reader.ReadToFollowing("Buses"); + _reader.Read(); + while(_reader.IsStartElement("BusRef")) + buses.Add(busMappings[new Guid(_reader.ReadElementString())]); + _reader.ReadEndElement(); + _builder.BuildPort(entityId, inputSignals, outputSignals, buses); + } + break; + case BuilderState.SignalDetails: + _reader.Read(); + while(ReadToElement()) + { + Guid tGuid = signalMappings[new Guid(_reader.GetAttribute("iid"))]; + switch(_reader.LocalName) + { + case "SignalValue": + { + CustomDataPack pack = CustomDataPack.Repack(_reader.ReadInnerXml(), signalMappings, busMappings); + _builder.AppendSignalValue(tGuid, pack); + } + break; + case "SignalProperty": + { + CustomDataPack pack = CustomDataPack.Repack(_reader.ReadInnerXml(), signalMappings, busMappings); + _builder.AppendSignalProperty(tGuid, pack); + } + break; + case "SignalConstraint": + { + CustomDataPack pack = CustomDataPack.Repack(_reader.ReadInnerXml(), signalMappings, busMappings); + _builder.AppendSignalConstraint(tGuid, pack); + } + break; + } + } + break; + case BuilderState.InputSignals: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "SignalRef") + { + Guid tGuid = signalMappings[new Guid(_reader.ReadElementString())]; + _builder.AppendSystemInputSignal(tGuid); + } + break; + case BuilderState.OutputSignals: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "SignalRef") + { + Guid tGuid = signalMappings[new Guid(_reader.ReadElementString())]; + _builder.AppendSystemOutputSignal(tGuid); + } + break; + case BuilderState.NamedSignals: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "SignalRef") + { + string name = _reader.GetAttribute("name"); + Guid tGuid = signalMappings[new Guid(_reader.ReadElementString())]; + _builder.AppendSystemNamedSignal(tGuid, name); + } + break; + case BuilderState.NamedBuses: + _reader.Read(); + while(ReadToElement() && _reader.LocalName == "BusRef") + { + string name = _reader.GetAttribute("name"); + Guid tGuid = busMappings[new Guid(_reader.ReadElementString())]; + _builder.AppendSystemNamedBus(tGuid, name); + } + break; + case BuilderState.Idle: + _builder.EndBuildSystem(); + active = false; + if(!multiple) + return; + break; + } + } + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/XmlSystemWriter.cs b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/XmlSystemWriter.cs new file mode 100644 index 0000000..c611c86 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/SystemBuilder/Toolkit/XmlSystemWriter.cs @@ -0,0 +1,222 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Containers; + +namespace MathNet.Symbolics.SystemBuilder.Toolkit +{ + /// + /// Concrete System Builder for constructing a complete Xml representation. + /// + public class XmlSystemWriter : ISystemBuilder + { + private XmlWriter _writer; + private StateMachine _fsm; + + private class StateMachine : BuilderStateMachine + { + private XmlWriter _writer; + + public StateMachine(XmlWriter writer) + { + _writer = writer; + } + + public XmlWriter Writer + { + //get { return _writer; } + set { _writer = value; } + } + + protected override void OnAfterAdvance(BuilderState before, BuilderState after, bool wasInsideSystem, bool wasInsideGroup) + { + if(after != before) + { + if(wasInsideGroup) + _writer.WriteEndElement(); + if(after == BuilderState.Idle) + _writer.WriteEndElement(); + else + _writer.WriteStartElement(after.ToString(), Config.YttriumNamespace); + } + } + } + + public XmlSystemWriter(XmlWriter writer) + { + _writer = writer; + _fsm = new StateMachine(writer); + } + + public XmlWriter Writer + { + get { return _writer; } + set + { + _writer = value; + _fsm.Writer = value; + } + } + + public BuilderState State + { + get { return _fsm.CurrentState; } + } + + public void BeginBuildSystem(int inputSignalCount, int outputSignalCount, int busCount) + { + _fsm.AdvanceTo(BuilderState.System); + _writer.WriteAttributeString("inputCount", inputSignalCount.ToString(Config.InternalNumberFormat)); + _writer.WriteAttributeString("outputCount", outputSignalCount.ToString(Config.InternalNumberFormat)); + _writer.WriteAttributeString("busCount", busCount.ToString(Config.InternalNumberFormat)); + } + + public Guid BuildSignal(string label, bool hold, bool isSource) + { + _fsm.AdvanceTo(BuilderState.Signals); + Guid guid = Guid.NewGuid(); + _writer.WriteStartElement("Signal", Config.YttriumNamespace); + _writer.WriteAttributeString("iid", guid.ToString()); + _writer.WriteAttributeString("label", label); + _writer.WriteAttributeString("hold", hold.ToString()); + _writer.WriteAttributeString("isSource", isSource.ToString()); + _writer.WriteEndElement(); + return guid; + } + + public Guid BuildBus(string label) + { + _fsm.AdvanceTo(BuilderState.Buses); + Guid guid = Guid.NewGuid(); + _writer.WriteStartElement("Bus", Config.YttriumNamespace); + _writer.WriteAttributeString("iid", guid.ToString()); + _writer.WriteAttributeString("label", label); + _writer.WriteEndElement(); + return guid; + } + + public Guid BuildPort(MathIdentifier entityId, InstanceIdSet inputSignals, InstanceIdSet outputSignals, InstanceIdSet buses) + { + _fsm.AdvanceTo(BuilderState.Ports); + Guid guid = Guid.NewGuid(); + _writer.WriteStartElement("Port", Config.YttriumNamespace); + _writer.WriteAttributeString("iid", guid.ToString()); + _writer.WriteAttributeString("entityId", entityId.ToString()); + + _writer.WriteStartElement("InputSignals", Config.YttriumNamespace); + foreach(Guid id in inputSignals) + _writer.WriteElementString("SignalRef", Config.YttriumNamespace, id.ToString()); + _writer.WriteEndElement(); + + _writer.WriteStartElement("OutputSignals", Config.YttriumNamespace); + foreach(Guid id in outputSignals) + _writer.WriteElementString("SignalRef", Config.YttriumNamespace, id.ToString()); + _writer.WriteEndElement(); + + _writer.WriteStartElement("Buses", Config.YttriumNamespace); + foreach(Guid id in buses) + _writer.WriteElementString("BusRef", Config.YttriumNamespace, id.ToString()); + _writer.WriteEndElement(); + + _writer.WriteEndElement(); + return guid; + } + + public void AppendSignalValue(Guid iid, ICustomDataPack value) + { + if(value == null) + throw new ArgumentNullException("value"); + + _fsm.AdvanceTo(BuilderState.SignalDetails); + _writer.WriteStartElement("SignalValue", Config.YttriumNamespace); + _writer.WriteAttributeString("iid", iid.ToString()); + _writer.WriteRaw(value.SerializedXmlFragment); + _writer.WriteEndElement(); + } + + public void AppendSignalProperty(Guid iid, ICustomDataPack property) + { + if(property == null) + throw new ArgumentNullException("property"); + + _fsm.AdvanceTo(BuilderState.SignalDetails); + _writer.WriteStartElement("SignalProperty", Config.YttriumNamespace); + _writer.WriteAttributeString("iid", iid.ToString()); + _writer.WriteRaw(property.SerializedXmlFragment); + _writer.WriteEndElement(); + } + + public void AppendSignalConstraint(Guid iid, ICustomDataPack constraint) + { + if(constraint == null) + throw new ArgumentNullException("constraint"); + + _fsm.AdvanceTo(BuilderState.SignalDetails); + _writer.WriteStartElement("SignalConstraint", Config.YttriumNamespace); + _writer.WriteAttributeString("iid", iid.ToString()); + _writer.WriteRaw(constraint.SerializedXmlFragment); + _writer.WriteEndElement(); + } + + public void AppendSystemInputSignal(Guid iid) + { + _fsm.AdvanceTo(BuilderState.InputSignals); + _writer.WriteElementString("SignalRef", Config.YttriumNamespace, iid.ToString()); + } + + public void AppendSystemOutputSignal(Guid iid) + { + _fsm.AdvanceTo(BuilderState.OutputSignals); + _writer.WriteElementString("SignalRef", Config.YttriumNamespace, iid.ToString()); + + } + + public void AppendSystemNamedSignal(Guid iid, string name) + { + _fsm.AdvanceTo(BuilderState.NamedSignals); + _writer.WriteStartElement("SignalRef", Config.YttriumNamespace); + _writer.WriteAttributeString("name", name); + _writer.WriteString(iid.ToString()); + _writer.WriteEndElement(); + } + + public void AppendSystemNamedBus(Guid iid, string name) + { + _fsm.AdvanceTo(BuilderState.NamedBuses); + _writer.WriteStartElement("BusRef", Config.YttriumNamespace); + _writer.WriteAttributeString("name", name); + _writer.WriteString(iid.ToString()); + _writer.WriteEndElement(); + } + + public void EndBuildSystem() + { + _fsm.AdvanceTo(BuilderState.Idle); + _writer.Flush(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/Yttrium.SystemBuilder.Toolkit.csproj b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/Yttrium.SystemBuilder.Toolkit.csproj new file mode 100644 index 0000000..4fe72e4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/SystemBuilder.Toolkit/Yttrium.SystemBuilder.Toolkit.csproj @@ -0,0 +1,75 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.SystemBuilder.Toolkit + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Exceptions/TraversingException.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Exceptions/TraversingException.cs new file mode 100644 index 0000000..bb345c8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Exceptions/TraversingException.cs @@ -0,0 +1,46 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace MathNet.Symbolics.Exceptions +{ + [Serializable] + public class TraversingException : YttriumException + { + public TraversingException(string message) + : base(message) + { + } + + public TraversingException(string message, Exception innerException) + : base(message, innerException) + { + } + + protected TraversingException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..97676a5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Traversing Contracts")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("23a731d4-c540-414d-9869-0f1311bed5d4")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/AbstractScanVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/AbstractScanVisitor.cs new file mode 100644 index 0000000..8a14243 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/AbstractScanVisitor.cs @@ -0,0 +1,80 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + [System.Diagnostics.DebuggerStepThrough] + public abstract class AbstractScanVisitor : IScanVisitor + { + protected AbstractScanVisitor() + { + } + + public abstract IScanStrategy DefaultStrategy + { + get; + } + + public virtual bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + return !again; + } + + public virtual bool LeaveSignal(Signal signal, Port parent, bool again, bool root) + { + return true; + } + + public virtual bool EnterPort(Port port, Signal parent, bool again, bool root) + { + return !again; + } + + public virtual bool LeavePort(Port port, Signal parent, bool again, bool root) + { + return true; + } + + public virtual bool VisitLeaf(Signal signal, bool again) + { + return true; + } + + public virtual bool VisitLeaf(Port port, bool again) + { + return true; + } + + public virtual bool VisitLeaf(Bus bus, bool again) + { + return true; + } + + public virtual bool VisitCycle(Port port, Signal target, Signal source) + { + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/Delegates.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/Delegates.cs new file mode 100644 index 0000000..67c515c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/Delegates.cs @@ -0,0 +1,30 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + /// true to continue, false if finished. + public delegate bool ActionContinue(T obj); +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ICollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ICollectVisitor.cs new file mode 100644 index 0000000..0beefb7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ICollectVisitor.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface ICollectVisitor : IScanVisitor + { + IList Signals { get;} + IList Ports { get;} + IList Buses { get;} + + void Reset(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IExistsPortVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IExistsPortVisitor.cs new file mode 100644 index 0000000..2b6c9e7 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IExistsPortVisitor.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface IExistsPortVisitor : IScanVisitor + { + bool Exists { get;} + Port FoundPort { get;} + Signal FoundPortTarget { get;} + + void Reset(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IExistsSignalVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IExistsSignalVisitor.cs new file mode 100644 index 0000000..476fce2 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IExistsSignalVisitor.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface IExistsSignalVisitor : IScanVisitor + { + bool Exists { get;} + Signal FoundSignal { get;} + Port FoundSignalTarget { get;} + + void Reset(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IPortPathCollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IPortPathCollectVisitor.cs new file mode 100644 index 0000000..ce7a755 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IPortPathCollectVisitor.cs @@ -0,0 +1,34 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface IPortPathCollectVisitor : IScanVisitor + { + List> Paths { get;} + + void Reset(Port source); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanStrategy.cs new file mode 100644 index 0000000..f4ed5f8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanStrategy.cs @@ -0,0 +1,34 @@ +^#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface IScanStrategy + { + void Traverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold); + void Traverse(Port rootPort, IScanVisitor visitor, bool ignoreHold); + void Traverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanVisitor.cs new file mode 100644 index 0000000..2c28e01 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanVisitor.cs @@ -0,0 +1,70 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public delegate bool ProcessSignal(Signal signal, Port parent, bool again, bool root); + public delegate bool ProcessPort(Port port, Signal parent, bool again, bool root); + public delegate bool ProcessLeafSignal(Signal signal, bool again); + public delegate bool ProcessLeafPort(Port port, bool again); + public delegate bool ProcessLeafBus(Bus bus, bool again); + public delegate bool ProcessCycle(Port port, Signal target, Signal source); + + public interface IScanVisitor + { + IScanStrategy DefaultStrategy { get;} + + /// + /// Visit a signal. The signal is an input signal to the given parent port. + /// + /// false if no childs shall be processed. + bool EnterSignal(Signal signal, Port parent, bool again, bool root); + /// + /// End visiting a signal, after all childs have been processed. + /// + /// false if finished. + bool LeaveSignal(Signal signal, Port parent, bool again, bool root); + + /// + /// Visit a port. The parent signal is an output signal of this port. + /// + /// false if no childs shall be processed. + bool EnterPort(Port port, Signal parent, bool again, bool root); + /// + /// End visiting a port, after all childs have been processed. + /// + /// false if finished. + bool LeavePort(Port port, Signal parent, bool again, bool root); + + /// false if finished. + bool VisitLeaf(Signal signal, bool again); + /// false if finished. + bool VisitLeaf(Port port, bool again); + /// false if finished. + bool VisitLeaf(Bus bus, bool again); + + bool VisitCycle(Port port, Signal target, Signal source); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanner.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanner.cs new file mode 100644 index 0000000..2d83587 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/IScanner.cs @@ -0,0 +1,117 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; + +namespace MathNet.Symbolics.Traversing +{ + public interface IScanner + { + void Traverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold); + void Traverse(Port rootPort, IScanVisitor visitor, bool ignoreHold); + void Traverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold); + void Traverse(Signal rootSignal, IScanStrategy strategy, IScanVisitor visitor, bool ignoreHold); + void Traverse(Port rootPort, IScanStrategy strategy, IScanVisitor visitor, bool ignoreHold); + void Traverse(IEnumerable rootSignals, IScanStrategy strategy, IScanVisitor visitor, bool ignoreHold); + + + bool ExistsSignal(Port rootPort, Predicate match, bool ignoreHold); + bool ExistsSignal(Signal rootSignal, Predicate match, bool ignoreHold, out Signal foundSignal, out Port foundSignalTarget); + bool ExistsSignal(Signal rootSignal, Predicate match, bool ignoreHold); + bool ExistsSignal(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Signal foundSignal, out Port foundSignalTarget); + bool ExistsSignal(IEnumerable rootSignals, Predicate match, bool ignoreHold); + bool ExistsSignal(Port rootPort, Predicate match, bool ignoreHold, out Signal foundSignal, out Port foundSignalTarget); + + bool ExistsPort(Port rootPort, Predicate match, bool ignoreHold, out Port foundPort, out Signal foundPortTarget); + bool ExistsPort(IEnumerable rootSignals, Predicate match, bool ignoreHold); + bool ExistsPort(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Port foundPort, out Signal foundPortTarget); + bool ExistsPort(Signal rootSignal, Predicate match, bool ignoreHold); + bool ExistsPort(Signal rootSignal, Predicate match, bool ignoreHold, out Port foundPort, out Signal foundPortTarget); + bool ExistsPort(Port rootPort, Predicate match, bool ignoreHold); + + + bool TrueForAllSignals(Port rootPort, Predicate match, bool ignoreHold); + bool TrueForAllSignals(Signal rootSignal, Predicate match, bool ignoreHold, out Signal failedSignal, out Port failedSignalTarget); + bool TrueForAllSignals(Signal rootSignal, Predicate match, bool ignoreHold); + bool TrueForAllSignals(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Signal failedSignal, out Port failedSignalTarget); + bool TrueForAllSignals(IEnumerable rootSignals, Predicate match, bool ignoreHold); + bool TrueForAllSignals(Port rootPort, Predicate match, bool ignoreHold, out Signal failedSignal, out Port failedSignalTarget); + + bool TrueForAllPorts(Signal rootSignal, Predicate match, bool ignoreHold); + bool TrueForAllPorts(Signal rootSignal, Predicate match, bool ignoreHold, out Port failedPort, out Signal failedPortTarget); + bool TrueForAllPorts(Port rootPort, Predicate match, bool ignoreHold); + bool TrueForAllPorts(Port rootPort, Predicate match, bool ignoreHold, out Port failedPort, out Signal failedPortTarget); + bool TrueForAllPorts(IEnumerable rootSignals, Predicate match, bool ignoreHold); + bool TrueForAllPorts(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Port failedPort, out Signal failedPortTarget); + + + void ForEachSignal(Signal rootSignal, ActionContinue action, bool ignoreHold); + void ForEachSignal(Port rootPort, ActionContinue action, bool ignoreHold); + void ForEachSignal(IEnumerable rootSignals, ActionContinue action, bool ignoreHold); + void ForEachSignal(IEnumerable rootSignals, Predicate match, ActionContinue action, bool ignoreHold); + void ForEachSignal(Port rootPort, Predicate match, ActionContinue action, bool ignoreHold); + void ForEachSignal(Signal rootSignal, Predicate match, ActionContinue action, bool ignoreHold); + + void ForEachPort(Signal rootSignal, ActionContinue action, bool ignoreHold); + void ForEachPort(Signal rootSignal, Predicate match, ActionContinue action, bool ignoreHold); + void ForEachPort(IEnumerable rootSignals, ActionContinue action, bool ignoreHold); + void ForEachPort(Port rootPort, ActionContinue action, bool ignoreHold); + void ForEachPort(Port rootPort, Predicate match, ActionContinue action, bool ignoreHold); + void ForEachPort(IEnumerable rootSignals, Predicate match, ActionContinue action, bool ignoreHold); + + + IList FindAllSignals(Signal rootSignal, Predicate match, bool ignoreHold); + IList FindAllSignals(Signal rootSignal, bool ignoreHold); + IList FindAllSignals(Port rootPort, bool ignoreHold); + IList FindAllSignals(IEnumerable rootSignals, bool ignoreHold); + IList FindAllSignals(Port rootPort, Predicate match, bool ignoreHold); + IList FindAllSignals(IEnumerable rootSignals, Predicate match, bool ignoreHold); + + IList FindAllPorts(Signal rootSignal, Predicate match, bool ignoreHold); + IList FindAllPorts(Port rootPort, Predicate match, bool ignoreHold); + IList FindAllPorts(IEnumerable rootSignals, Predicate match, bool ignoreHold); + IList FindAllPorts(Signal rootSignal, bool ignoreHold); + IList FindAllPorts(Port rootPort, bool ignoreHold); + IList FindAllPorts(IEnumerable rootSignals, bool ignoreHold); + + void FindAll(IEnumerable rootSignals, bool ignoreHold, out IList signals, out IList ports); + void FindAll(Port rootPort, bool ignoreHold, out IList signals, out IList ports); + void FindAll(Signal rootSignal, bool ignoreHold, out IList signals, out IList ports); + + Signal FindSignal(IEnumerable rootSignals, Predicate match, bool ignoreHold); + Signal FindSignal(Port rootPort, Predicate match, bool ignoreHold); + Signal FindSignal(Signal rootSignal, Predicate match, bool ignoreHold); + + Port FindPort(Signal rootSignal, Predicate match, bool ignoreHold); + Port FindPort(Port rootPort, Predicate match, bool ignoreHold); + Port FindPort(IEnumerable rootSignals, Predicate match, bool ignoreHold); + + + List> FindAllSignalPathsFrom(Port rootPort, Signal from, bool ignoreHold); + List> FindAllSignalPathsFrom(IEnumerable rootSignals, Signal from, bool ignoreHold); + List> FindAllSignalPathsFrom(Signal rootSignal, Signal from, bool ignoreHold); + + List> FindAllPortPathsFrom(IEnumerable rootSignals, Port from, bool ignoreHold); + List> FindAllPortPathsFrom(Port rootPort, Port from, bool ignoreHold); + List> FindAllPortPathsFrom(Signal rootSignal, Port from, bool ignoreHold); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ISignalPathCollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ISignalPathCollectVisitor.cs new file mode 100644 index 0000000..5faee63 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ISignalPathCollectVisitor.cs @@ -0,0 +1,34 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface ISignalPathCollectVisitor : IScanVisitor + { + List> Paths { get;} + + void Reset(Signal source); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ITrueForAllPortsVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ITrueForAllPortsVisitor.cs new file mode 100644 index 0000000..b47ac0e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ITrueForAllPortsVisitor.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface ITrueForAllPortsVisitor : IScanVisitor + { + bool TrueForAll { get;} + Port FailedPort { get;} + Signal FailedPortTarget { get;} + + void Reset(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ITrueForAllSignalsVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ITrueForAllSignalsVisitor.cs new file mode 100644 index 0000000..a1db2cb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Traversing/ITrueForAllSignalsVisitor.cs @@ -0,0 +1,36 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing +{ + public interface ITrueForAllSignalsVisitor : IScanVisitor + { + bool TrueForAll { get;} + Signal FailedSignal { get;} + Port FailedSignalTarget { get;} + + void Reset(); + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Yttrium.Traversing.Contracts.csproj b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Yttrium.Traversing.Contracts.csproj new file mode 100644 index 0000000..1f985a1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Contracts/Yttrium.Traversing.Contracts.csproj @@ -0,0 +1,73 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Traversing.Contracts + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + + + \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Properties/AssemblyInfo.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6f038ec --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +[assembly: AssemblyTitle("Math.NET Yttrium Traversing")] +[assembly: AssemblyDescription("http://mathnet.opensourcedotnet.info")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Math.NET Project")] +[assembly: AssemblyProduct("Math.NET")] +[assembly: AssemblyCopyright("Copyright © 2007, Math.NET Project")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: CLSCompliant(true)] +[assembly: ComVisible(false)] + +[assembly: SecurityPermission(SecurityAction.RequestRefuse)] + +[assembly: Guid("87683e28-9e72-4ac6-a535-a5e77eb21cc9")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/StrategyFactory.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/StrategyFactory.cs new file mode 100644 index 0000000..35c9ae5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/StrategyFactory.cs @@ -0,0 +1,70 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Traversing.Strategies; + +namespace MathNet.Symbolics +{ + internal class AllStrategyFactory : IFactory + { + IScanStrategy IFactory.GetInstance() + { + return AllStrategy.Instance; + } + } + + internal class AllSignalsStrategyFactory : IFactory + { + IScanStrategy IFactory.GetInstance() + { + return AllSignalsStrategy.Instance; + } + } + + internal class AllPortsStrategyFactory : IFactory + { + IScanStrategy IFactory.GetInstance() + { + return AllPortsStrategy.Instance; + } + } + + internal class AllSpanningTreeStrategyFactory : IFactory + { + IScanStrategy IFactory.GetInstance() + { + return AllSpanningTreeStrategy.Instance; + } + } + + internal class AllPathsStrategyFactory : IFactory + { + IScanStrategy IFactory.GetInstance() + { + return AllPathsStrategy.Instance; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/ScanStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/ScanStrategy.cs new file mode 100644 index 0000000..4c7d351 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/ScanStrategy.cs @@ -0,0 +1,130 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Backend; + +namespace MathNet.Symbolics.Traversing +{ + [System.Diagnostics.DebuggerStepThrough] + public abstract class ScanStrategy : IScanStrategy + { + private readonly ConcurrencyMode _concurrency; + private WeakReference _nextInstance; + private int _activeScans; + + public enum ConcurrencyMode + { + /// supports parallel execution with the same shared instance. + ParallelStateless, + /// supports parallel execution with different instances. + ParallelStateful, + /// does not support parallel execution in any way. + MutualExclusive + } + + protected ScanStrategy(ConcurrencyMode concurrency) + { + _concurrency = concurrency; + _nextInstance = new WeakReference(null, false); + } + + public bool IsActive + { + get { return _activeScans != 0; } + } + public ConcurrencyMode Concurrency + { + get { return _concurrency; } + } + + public void Traverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + //lock(??) { + ScanStrategy strat = ProvideExecutableInstance(); + strat._activeScans++; //} + try { strat.DoTraverse(rootSignal, visitor, ignoreHold); } + finally { strat._activeScans--; } + } + public void Traverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + //lock(??) { + ScanStrategy strat = ProvideExecutableInstance(); + strat._activeScans++; //} + try { strat.DoTraverse(rootPort, visitor, ignoreHold); } + finally { strat._activeScans--; } + } + public void Traverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + //lock(??) { + ScanStrategy strat = ProvideExecutableInstance(); + strat._activeScans++; //} + try { strat.DoTraverse(rootSignals, visitor, ignoreHold); } + finally { strat._activeScans--; } + } + + protected abstract void DoTraverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold); + protected abstract void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold); + protected abstract void DoTraverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold); + + private ScanStrategy ProvideExecutableInstance() + { + if(_activeScans == 0 || _concurrency == ConcurrencyMode.ParallelStateless) + { + ReuseStrategy(); + return this; + } + else if(_concurrency == ConcurrencyMode.ParallelStateful) + { + ScanStrategy ss; + if(_nextInstance.IsAlive) + { + ss = _nextInstance.Target as ScanStrategy; + if(ss != null) + return ss.ProvideExecutableInstance(); + } + ss = Clone(); + ss.ReuseStrategy(); + _nextInstance.Target = ss; + return ss; + } + else //Exclusive + throw new MathNet.Symbolics.Exceptions.TraversingException("A mutual exclusive system traversing strategy is already in use and may not be executed again before the other finishes its operation."); + } + + /// Should be overridden in all stateful strategies. + protected virtual void ReuseStrategy() + { + } + + /// + /// Semideep clone, having all shared (reference type) members replaced. + /// + /// Should be overridden in parallel-stateful strategies. + protected virtual ScanStrategy Clone() + { + return (ScanStrategy)this.MemberwiseClone(); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Scanner.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Scanner.cs new file mode 100644 index 0000000..fbbde8c --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Scanner.cs @@ -0,0 +1,629 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Exceptions; + +namespace MathNet.Symbolics.Traversing +{ + public class Scanner : IScanner + { + public void Traverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + if(visitor == null) throw new ArgumentNullException("visitor"); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + } + public void Traverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + if(visitor == null) throw new ArgumentNullException("visitor"); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + } + public void Traverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + if(visitor == null) throw new ArgumentNullException("visitor"); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + } + + public void Traverse(Signal rootSignal, IScanStrategy strategy, IScanVisitor visitor, bool ignoreHold) + { + if(visitor == null) throw new ArgumentNullException("visitor"); + if(strategy == null) throw new ArgumentNullException("strategy"); + strategy.Traverse(rootSignal, visitor, ignoreHold); + } + public void Traverse(Port rootPort, IScanStrategy strategy, IScanVisitor visitor, bool ignoreHold) + { + if(visitor == null) throw new ArgumentNullException("visitor"); + if(strategy == null) throw new ArgumentNullException("strategy"); + strategy.Traverse(rootPort, visitor, ignoreHold); + } + public void Traverse(IEnumerable rootSignals, IScanStrategy strategy, IScanVisitor visitor, bool ignoreHold) + { + if(visitor == null) throw new ArgumentNullException("visitor"); + if(strategy == null) throw new ArgumentNullException("strategy"); + strategy.Traverse(rootSignals, visitor, ignoreHold); + } + + #region Exists Lambdas -> bool + #region Signal + public bool ExistsSignal(Signal rootSignal, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return ExistsSignal(rootSignal, match, ignoreHold, out signal, out port); + } + public bool ExistsSignal(Signal rootSignal, Predicate match, bool ignoreHold, out Signal foundSignal, out Port foundSignalTarget) + { + IExistsSignalVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + if(visitor.Exists) + { + foundSignal = visitor.FoundSignal; + foundSignalTarget = visitor.FoundSignalTarget; + return true; + } + else + { + foundSignal = null; + foundSignalTarget = null; + return false; + } + } + + public bool ExistsSignal(Port rootPort, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return ExistsSignal(rootPort, match, ignoreHold, out signal, out port); + } + public bool ExistsSignal(Port rootPort, Predicate match, bool ignoreHold, out Signal foundSignal, out Port foundSignalTarget) + { + IExistsSignalVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + if(visitor.Exists) + { + foundSignal = visitor.FoundSignal; + foundSignalTarget = visitor.FoundSignalTarget; + return true; + } + else + { + foundSignal = null; + foundSignalTarget = null; + return false; + } + } + + public bool ExistsSignal(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return ExistsSignal(rootSignals, match, ignoreHold, out signal, out port); + } + public bool ExistsSignal(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Signal foundSignal, out Port foundSignalTarget) + { + IExistsSignalVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + if(visitor.Exists) + { + foundSignal = visitor.FoundSignal; + foundSignalTarget = visitor.FoundSignalTarget; + return true; + } + else + { + foundSignal = null; + foundSignalTarget = null; + return false; + } + } + #endregion + #region Port + public bool ExistsPort(Signal rootSignal, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return ExistsPort(rootSignal, match, ignoreHold, out port, out signal); + } + public bool ExistsPort(Signal rootSignal, Predicate match, bool ignoreHold, out Port foundPort, out Signal foundPortTarget) + { + IExistsPortVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + if(visitor.Exists) + { + foundPort = visitor.FoundPort; + foundPortTarget = visitor.FoundPortTarget; + return true; + } + else + { + foundPort = null; + foundPortTarget = null; + return false; + } + } + + public bool ExistsPort(Port rootPort, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return ExistsPort(rootPort, match, ignoreHold, out port, out signal); + } + public bool ExistsPort(Port rootPort, Predicate match, bool ignoreHold, out Port foundPort, out Signal foundPortTarget) + { + IExistsPortVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + if(visitor.Exists) + { + foundPort = visitor.FoundPort; + foundPortTarget = visitor.FoundPortTarget; + return true; + } + else + { + foundPort = null; + foundPortTarget = null; + return false; + } + } + + public bool ExistsPort(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return ExistsPort(rootSignals, match, ignoreHold, out port, out signal); + } + public bool ExistsPort(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Port foundPort, out Signal foundPortTarget) + { + IExistsPortVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + if(visitor.Exists) + { + foundPort = visitor.FoundPort; + foundPortTarget = visitor.FoundPortTarget; + return true; + } + else + { + foundPort = null; + foundPortTarget = null; + return false; + } + } + #endregion + #endregion + + #region True-For-All Lambdas -> bool + #region Signal + public bool TrueForAllSignals(Signal rootSignal, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return TrueForAllSignals(rootSignal, match, ignoreHold, out signal, out port); + } + public bool TrueForAllSignals(Signal rootSignal, Predicate match, bool ignoreHold, out Signal failedSignal, out Port failedSignalTarget) + { + ITrueForAllSignalsVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + if(visitor.TrueForAll) + { + failedSignal = null; + failedSignalTarget = null; + return true; + } + else + { + failedSignal = visitor.FailedSignal; + failedSignalTarget = visitor.FailedSignalTarget; + return false; + } + } + + public bool TrueForAllSignals(Port rootPort, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return TrueForAllSignals(rootPort, match, ignoreHold, out signal, out port); + } + public bool TrueForAllSignals(Port rootPort, Predicate match, bool ignoreHold, out Signal failedSignal, out Port failedSignalTarget) + { + ITrueForAllSignalsVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + if(visitor.TrueForAll) + { + failedSignal = null; + failedSignalTarget = null; + return true; + } + else + { + failedSignal = visitor.FailedSignal; + failedSignalTarget = visitor.FailedSignalTarget; + return false; + } + } + + public bool TrueForAllSignals(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return TrueForAllSignals(rootSignals, match, ignoreHold, out signal, out port); + } + public bool TrueForAllSignals(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Signal failedSignal, out Port failedSignalTarget) + { + ITrueForAllSignalsVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + if(visitor.TrueForAll) + { + failedSignal = null; + failedSignalTarget = null; + return true; + } + else + { + failedSignal = visitor.FailedSignal; + failedSignalTarget = visitor.FailedSignalTarget; + return false; + } + } + #endregion + #region Port + public bool TrueForAllPorts(Signal rootSignal, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return TrueForAllPorts(rootSignal, match, ignoreHold, out port, out signal); + } + public bool TrueForAllPorts(Signal rootSignal, Predicate match, bool ignoreHold, out Port failedPort, out Signal failedPortTarget) + { + ITrueForAllPortsVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + if(visitor.TrueForAll) + { + failedPort = null; + failedPortTarget = null; + return true; + } + else + { + failedPort = visitor.FailedPort; + failedPortTarget = visitor.FailedPortTarget; + return false; + } + } + + public bool TrueForAllPorts(Port rootPort, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return TrueForAllPorts(rootPort, match, ignoreHold, out port, out signal); + } + public bool TrueForAllPorts(Port rootPort, Predicate match, bool ignoreHold, out Port failedPort, out Signal failedPortTarget) + { + ITrueForAllPortsVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + if(visitor.TrueForAll) + { + failedPort = null; + failedPortTarget = null; + return true; + } + else + { + failedPort = visitor.FailedPort; + failedPortTarget = visitor.FailedPortTarget; + return false; + } + } + + public bool TrueForAllPorts(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + return TrueForAllPorts(rootSignals, match, ignoreHold, out port, out signal); + } + public bool TrueForAllPorts(IEnumerable rootSignals, Predicate match, bool ignoreHold, out Port failedPort, out Signal failedPortTarget) + { + ITrueForAllPortsVisitor visitor = Binder.GetInstance>(match); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + if(visitor.TrueForAll) + { + failedPort = null; + failedPortTarget = null; + return true; + } + else + { + failedPort = visitor.FailedPort; + failedPortTarget = visitor.FailedPortTarget; + return false; + } + } + #endregion + #endregion + + #region For-Each Lambdas -> Action + #region Unconditional + public void ForEachSignal(Signal rootSignal, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance>(action); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + } + public void ForEachSignal(Port rootPort, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance>(action); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + } + public void ForEachSignal(IEnumerable rootSignals, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance>(action); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + } + + public void ForEachPort(Signal rootSignal, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance>(action); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + } + public void ForEachPort(Port rootPort, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance>(action); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + } + public void ForEachPort(IEnumerable rootSignals, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance>(action); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + } + #endregion + #region Conditional + public void ForEachSignal(Signal rootSignal, Predicate match, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance, Predicate>(action, match); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + } + public void ForEachSignal(Port rootPort, Predicate match, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance, Predicate>(action, match); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + } + public void ForEachSignal(IEnumerable rootSignals, Predicate match, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance, Predicate>(action, match); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + } + + public void ForEachPort(Signal rootSignal, Predicate match, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance, Predicate>(action, match); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + } + public void ForEachPort(Port rootPort, Predicate match, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance, Predicate>(action, match); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + } + public void ForEachPort(IEnumerable rootSignals, Predicate match, ActionContinue action, bool ignoreHold) + { + IScanVisitor visitor = Binder.GetInstance, Predicate>(action, match); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + } + #endregion + #endregion + + #region Find-All Lambdas -> List + #region Unconditional + public IList FindAllSignals(Signal rootSignal, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance(); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllSignalsStrategy", "Traversing")); + strategy.Traverse(rootSignal, visitor, ignoreHold); + return visitor.Signals; + } + public IList FindAllSignals(Port rootPort, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance(); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllSignalsStrategy", "Traversing")); + strategy.Traverse(rootPort, visitor, ignoreHold); + return visitor.Signals; + } + public IList FindAllSignals(IEnumerable rootSignals, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance(); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllSignalsStrategy", "Traversing")); + strategy.Traverse(rootSignals, visitor, ignoreHold); + return visitor.Signals; + } + + public IList FindAllPorts(Signal rootSignal, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance(); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllPortsStrategy", "Traversing")); + strategy.Traverse(rootSignal, visitor, ignoreHold); + return visitor.Ports; + } + public IList FindAllPorts(Port rootPort, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance(); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllPortsStrategy", "Traversing")); + strategy.Traverse(rootPort, visitor, ignoreHold); + return visitor.Ports; + } + public IList FindAllPorts(IEnumerable rootSignals, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance(); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllPortsStrategy", "Traversing")); + strategy.Traverse(rootSignals, visitor, ignoreHold); + return visitor.Ports; + } + + public void FindAll(Signal rootSignal, bool ignoreHold, out IList signals, out IList ports) + { + ICollectVisitor visitor = Binder.GetInstance(); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + signals = visitor.Signals; + ports = visitor.Ports; + } + public void FindAll(Port rootPort, bool ignoreHold, out IList signals, out IList ports) + { + ICollectVisitor visitor = Binder.GetInstance(); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + signals = visitor.Signals; + ports = visitor.Ports; + } + public void FindAll(IEnumerable rootSignals, bool ignoreHold, out IList signals, out IList ports) + { + ICollectVisitor visitor = Binder.GetInstance(); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + signals = visitor.Signals; + ports = visitor.Ports; + } + #endregion + #region Conditional + public IList FindAllSignals(Signal rootSignal, Predicate match, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance>(match); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllSignalsStrategy", "Traversing")); + strategy.Traverse(rootSignal, visitor, ignoreHold); + return visitor.Signals; + } + public IList FindAllSignals(Port rootPort, Predicate match, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance>(match); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllSignalsStrategy", "Traversing")); + strategy.Traverse(rootPort, visitor, ignoreHold); + return visitor.Signals; + } + public IList FindAllSignals(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance>(match); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllSignalsStrategy", "Traversing")); + strategy.Traverse(rootSignals, visitor, ignoreHold); + return visitor.Signals; + } + + public IList FindAllPorts(Signal rootSignal, Predicate match, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance>(match); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllPortsStrategy", "Traversing")); + strategy.Traverse(rootSignal, visitor, ignoreHold); + return visitor.Ports; + } + public IList FindAllPorts(Port rootPort, Predicate match, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance>(match); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllPortsStrategy", "Traversing")); + strategy.Traverse(rootPort, visitor, ignoreHold); + return visitor.Ports; + } + public IList FindAllPorts(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + ICollectVisitor visitor = Binder.GetInstance>(match); + IScanStrategy strategy = Binder.GetSpecificInstance(new MathIdentifier("AllPortsStrategy", "Traversing")); + strategy.Traverse(rootSignals, visitor, ignoreHold); + return visitor.Ports; + } + #endregion + #endregion + + #region Find Lambdas -> Signal/Port/Bus + public Signal FindSignal(Signal rootSignal, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + if(ExistsSignal(rootSignal, match, ignoreHold, out signal, out port)) + return signal; + else + throw new TraversingException("signal not found"); + } + public Signal FindSignal(Port rootPort, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + if(ExistsSignal(rootPort, match, ignoreHold, out signal, out port)) + return signal; + else + throw new TraversingException("signal not found"); + } + public Signal FindSignal(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + if(ExistsSignal(rootSignals, match, ignoreHold, out signal, out port)) + return signal; + else + throw new TraversingException("signal not found"); + } + + public Port FindPort(Signal rootSignal, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + if(ExistsPort(rootSignal, match, ignoreHold, out port, out signal)) + return port; + else + throw new TraversingException("port not found"); + } + public Port FindPort(Port rootPort, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + if(ExistsPort(rootPort, match, ignoreHold, out port, out signal)) + return port; + else + throw new TraversingException("port not found"); + } + public Port FindPort(IEnumerable rootSignals, Predicate match, bool ignoreHold) + { + Signal signal; Port port; + if(ExistsPort(rootSignals, match, ignoreHold, out port, out signal)) + return port; + else + throw new TraversingException("port not found"); + } + #endregion + + #region Collect Paths -> List of Lists of Signal/Port + public List> FindAllSignalPathsFrom(Signal rootSignal, Signal from, bool ignoreHold) + { + ISignalPathCollectVisitor visitor = Binder.GetInstance(from); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + return visitor.Paths; + } + public List> FindAllSignalPathsFrom(Port rootPort, Signal from, bool ignoreHold) + { + ISignalPathCollectVisitor visitor = Binder.GetInstance(from); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + return visitor.Paths; + } + public List> FindAllSignalPathsFrom(IEnumerable rootSignals, Signal from, bool ignoreHold) + { + ISignalPathCollectVisitor visitor = Binder.GetInstance(from); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + return visitor.Paths; + } + + public List> FindAllPortPathsFrom(Signal rootSignal, Port from, bool ignoreHold) + { + IPortPathCollectVisitor visitor = Binder.GetInstance(from); + visitor.DefaultStrategy.Traverse(rootSignal, visitor, ignoreHold); + return visitor.Paths; + } + public List> FindAllPortPathsFrom(Port rootPort, Port from, bool ignoreHold) + { + IPortPathCollectVisitor visitor = Binder.GetInstance(from); + visitor.DefaultStrategy.Traverse(rootPort, visitor, ignoreHold); + return visitor.Paths; + } + public List> FindAllPortPathsFrom(IEnumerable rootSignals, Port from, bool ignoreHold) + { + IPortPathCollectVisitor visitor = Binder.GetInstance(from); + visitor.DefaultStrategy.Traverse(rootSignals, visitor, ignoreHold); + return visitor.Paths; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllPathsStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllPathsStrategy.cs new file mode 100644 index 0000000..ed6a918 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllPathsStrategy.cs @@ -0,0 +1,131 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Strategies +{ + /// This strategy activates the following visitor features: EnterSignal, LeaveSignal, EnterPort, LeavePort, VisitLeaf(Signal, Port, Bus), VisitCycle. + public class AllPathsStrategy : ScanStrategy + { + protected AllPathsStrategy() : base(ConcurrencyMode.ParallelStateless) { } + + #region Singleton + private static AllPathsStrategy instance; + public static AllPathsStrategy Instance + { + [System.Diagnostics.DebuggerStepThrough] + get + { + if(instance == null) + instance = new AllPathsStrategy(); + return instance; + } + } + #endregion + + protected override void DoTraverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + Stack signals = new Stack(); + TraverseSignal(signals, rootSignal, null, ignoreHold, visitor); + } + protected override void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + Stack signals = new Stack(); + TraverseRootPort(signals, rootPort, ignoreHold, visitor); + } + protected override void DoTraverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + Stack signals = new Stack(); + foreach(Signal rootSignal in rootSignals) + { + signals.Clear(); + if(!TraverseSignal(signals, rootSignal, null, ignoreHold, visitor)) + break; + } + } + + private void TraverseRootPort(Stack signals, Port rootPort, bool ignoreHold, IScanVisitor visitor) + { + if(visitor.EnterPort(rootPort, null, false, true)) + { + foreach(Bus b in rootPort.Buses) + if(!visitor.VisitLeaf(b, false)) + return; // finished + foreach(Signal s in rootPort.InputSignals) + if(!TraverseSignal(signals, s, rootPort, ignoreHold, visitor)) + return; // finished + } + visitor.LeavePort(rootPort, null, false, true); + } + + private bool TraverseSignal(Stack signals, Signal signal, Port target, bool ignoreHold, IScanVisitor visitor) + { + if(signal == null) + return true; + + if(visitor.EnterSignal(signal, target, false, target == null)) + { + signals.Push(signal.InstanceId); + + // HANDLE PORT + if(signal.BehavesAsBeingDriven(ignoreHold)) + { + Port port = signal.DrivenByPort; + + if(visitor.EnterPort(port, signal, false, false)) + { + // LEAF PORT? + if(port.InputSignalCount == 0 && port.BusCount == 0) + if(!visitor.VisitLeaf(port, false)) + return false; // finished + + // HANDLE BUSES + foreach(Bus b in port.Buses) + if(!visitor.VisitLeaf(b, false)) + return false; // finished + + // HANDLE INPUT SIGNALS + foreach(Signal s in port.InputSignals) + { + if(signals.Contains(s.InstanceId)) + { + if(!visitor.VisitCycle(port, signal, s)) + return false; //finished + } + else if(!TraverseSignal(signals, s, port, ignoreHold, visitor)) + return false; // finished + } + } + if(!visitor.LeavePort(port, signal, false, false)) + return false; // finished + } + else if(!visitor.VisitLeaf(signal, false)) + return false; // finished + + signals.Pop(); + } + return visitor.LeaveSignal(signal, target, false, target == null); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllPortsStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllPortsStrategy.cs new file mode 100644 index 0000000..8713881 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllPortsStrategy.cs @@ -0,0 +1,84 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Strategies +{ + /// This strategy activates the following visitor features: EnterPort, LeavePort. + public class AllPortsStrategy : ScanStrategy + { + protected AllPortsStrategy() : base(ConcurrencyMode.ParallelStateless) { } + + #region Singleton + private static AllPortsStrategy instance; + public static AllPortsStrategy Instance + { + [System.Diagnostics.DebuggerStepThrough] + get + { + if(instance == null) + instance = new AllPortsStrategy(); + return instance; + } + } + #endregion + + protected override void DoTraverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + if(rootSignal.BehavesAsBeingDriven(ignoreHold)) + { + List ports = new List(); + TraversePort(ports, rootSignal.DrivenByPort, rootSignal, ignoreHold, visitor); + } + } + protected override void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + List ports = new List(); + TraversePort(ports, rootPort, null, ignoreHold, visitor); + } + protected override void DoTraverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + List ports = new List(); + foreach(Signal rootSignal in rootSignals) + if(rootSignal.BehavesAsBeingDriven(ignoreHold)) + if(!TraversePort(ports, rootSignal.DrivenByPort, rootSignal, ignoreHold, visitor)) + break; // finished + } + + private bool TraversePort(List ports, Port port, Signal target, bool ignoreHold, IScanVisitor visitor) + { + if(ports.Contains(port.InstanceId)) + return true; + ports.Add(port.InstanceId); + if(visitor.EnterPort(port, target, false, target == null)) + { + foreach(Signal input in port.InputSignals) + if(input != null && input.BehavesAsBeingDriven(ignoreHold)) + if(!TraversePort(ports, input.DrivenByPort, input, ignoreHold, visitor)) + return false; // finished + } + return visitor.LeavePort(port, target, false, target == null); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllSignalsStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllSignalsStrategy.cs new file mode 100644 index 0000000..1badeb5 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllSignalsStrategy.cs @@ -0,0 +1,85 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Strategies +{ + /// This strategy activates the following visitor features: EnterSignal, LeaveSignal. + public class AllSignalsStrategy : ScanStrategy + { + protected AllSignalsStrategy() : base(ConcurrencyMode.ParallelStateless) { } + + #region Singleton + private static AllSignalsStrategy instance; + public static AllSignalsStrategy Instance + { + [System.Diagnostics.DebuggerStepThrough] + get + { + if(instance == null) + instance = new AllSignalsStrategy(); + return instance; + } + } + #endregion + + protected override void DoTraverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + TraverseSignal(signals, rootSignal, null, ignoreHold, visitor); + } + protected override void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + foreach(Signal input in rootPort.InputSignals) + if(!TraverseSignal(signals, input, rootPort, ignoreHold, visitor)) + break; // finished + } + protected override void DoTraverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + foreach(Signal rootSignal in rootSignals) + if(!TraverseSignal(signals, rootSignal, null, ignoreHold, visitor)) + break; // finished + } + + private bool TraverseSignal(List signals, Signal signal, Port target, bool ignoreHold, IScanVisitor visitor) + { + if(signal == null || signals.Contains(signal.InstanceId)) + return true; + signals.Add(signal.InstanceId); + if(visitor.EnterSignal(signal, target, false, target == null)) + { + if(signal.BehavesAsBeingDriven(ignoreHold)) + { + Port port = signal.DrivenByPort; + foreach(Signal input in port.InputSignals) + if(!TraverseSignal(signals, input, port, ignoreHold, visitor)) + return false; // finished + } + } + return visitor.LeaveSignal(signal, target, false, target == null); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllSpanningTreeStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllSpanningTreeStrategy.cs new file mode 100644 index 0000000..2369e01 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllSpanningTreeStrategy.cs @@ -0,0 +1,125 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Strategies +{ + /// This strategy activates the following visitor features: EnterSignal, LeaveSignal, EnterPort, LeavePort, VisitLeaf(Signal, Port, Bus). + public class AllSpanningTreeStrategy : ScanStrategy + { + protected AllSpanningTreeStrategy() : base(ConcurrencyMode.ParallelStateless) { } + + #region Singleton + private static AllSpanningTreeStrategy instance; + public static AllSpanningTreeStrategy Instance + { + [System.Diagnostics.DebuggerStepThrough] + get + { + if(instance == null) + instance = new AllSpanningTreeStrategy(); + return instance; + } + } + #endregion + + protected override void DoTraverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + List ports = new List(); + List buses = new List(); + TraverseSignal(signals, ports, buses, rootSignal, null, ignoreHold, visitor); + } + protected override void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + List ports = new List(); + List buses = new List(); + TraversePort(signals, ports, buses, rootPort, null, ignoreHold, visitor); + } + protected override void DoTraverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + List ports = new List(); + List buses = new List(); + foreach(Signal rootSignal in rootSignals) + if(!TraverseSignal(signals, ports, buses, rootSignal, null, ignoreHold, visitor)) + break; // finished + } + + private bool TraverseSignal(List signals, List ports, List buses, Signal signal, Port target, bool ignoreHold, IScanVisitor visitor) + { + if(signal == null || signals.Contains(signal.InstanceId)) + return true; + signals.Add(signal.InstanceId); + + if(visitor.EnterSignal(signal, target, false, target == null)) + { + // LEAF SIGNAL? + if(!signal.BehavesAsBeingDriven(ignoreHold)) + { + if(!visitor.VisitLeaf(signal, false)) + return false; // finished + } + else // HANDLE PORT + { + TraversePort(signals, ports, buses, signal.DrivenByPort, signal, ignoreHold, visitor); + } + } + return visitor.LeaveSignal(signal, target, false, target == null); + } + + private bool TraversePort(List signals, List ports, List buses, Port port, Signal target, bool ignoreHold, IScanVisitor visitor) + { + if(ports.Contains(port.InstanceId)) + return true; + ports.Add(port.InstanceId); + + if(visitor.EnterPort(port, target, false, target == null)) + { + // LEAF PORT? + if(port.InputSignalCount == 0 && port.BusCount == 0) + if(!visitor.VisitLeaf(port, false)) + return false; // finished + + // HANDLE BUSES + foreach(Bus b in port.Buses) + { + if(buses.Contains(b.InstanceId)) + continue; + + buses.Add(b.InstanceId); + if(!visitor.VisitLeaf(b, false)) + return false; // finished + } + + // HANDLE INPUT SIGNALS + foreach(Signal s in port.InputSignals) + if(!TraverseSignal(signals, ports, buses, s, port, ignoreHold, visitor)) + return false; // finished + } + return visitor.LeavePort(port, target, false, target == null); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllStrategy.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllStrategy.cs new file mode 100644 index 0000000..2830159 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Strategies/AllStrategy.cs @@ -0,0 +1,139 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Strategies +{ + /// This strategy activates the following visitor features: EnterSignal, LeaveSignal, EnterPort, LeavePort, VisitLeaf(Signal, Port, Bus). + public class AllStrategy : ScanStrategy + { + protected AllStrategy() : base(ConcurrencyMode.ParallelStateless) { } + + #region Singleton + private static AllStrategy instance; + public static AllStrategy Instance + { + [System.Diagnostics.DebuggerStepThrough] + get + { + if(instance == null) + instance = new AllStrategy(); + return instance; + } + } + #endregion + + protected override void DoTraverse(Signal rootSignal, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + List ports = new List(); + List buses = new List(); + TraverseSignal(signals, ports, buses, rootSignal, null, ignoreHold, visitor); + } + protected override void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + List ports = new List(); + List buses = new List(); + TraversePort(signals, ports, buses, rootPort, null, ignoreHold, visitor); + } + protected override void DoTraverse(IEnumerable rootSignals, IScanVisitor visitor, bool ignoreHold) + { + List signals = new List(); + List ports = new List(); + List buses = new List(); + foreach(Signal rootSignal in rootSignals) + if(!TraverseSignal(signals, ports, buses, rootSignal, null, ignoreHold, visitor)) + break; // finished + } + + private bool TraverseSignal(List signals, List ports, List buses, Signal signal, Port target, bool ignoreHold, IScanVisitor visitor) + { + if(signal == null) + return true; + + bool again = true; + if(!signals.Contains(signal.InstanceId)) + { + again = false; + signals.Add(signal.InstanceId); + } + + if(visitor.EnterSignal(signal, target, again, target == null)) + { + // LEAF SIGNAL? + if(!signal.BehavesAsBeingDriven(ignoreHold)) + { + if(!visitor.VisitLeaf(signal, again)) + return false; // finished + } + else // HANDLE PORT + { + TraversePort(signals, ports, buses, signal.DrivenByPort, signal, ignoreHold, visitor); + } + } + return visitor.LeaveSignal(signal, target, again, target == null); + } + + private bool TraversePort(List signals, List ports, List buses, Port port, Signal target, bool ignoreHold, IScanVisitor visitor) + { + bool again = true; + if(!ports.Contains(port.InstanceId)) + { + again = false; + ports.Add(port.InstanceId); + } + + if(visitor.EnterPort(port, target, again, target == null)) + { + // LEAF PORT? + if(port.InputSignalCount == 0 && port.BusCount == 0) + if(!visitor.VisitLeaf(port, again)) + return false; // finished + + // HANDLE BUSES + foreach(Bus b in port.Buses) + { + if(buses.Contains(b.InstanceId)) + { + if(!visitor.VisitLeaf(b, true)) + return false; // finished + } + else + { + buses.Add(b.InstanceId); + if(!visitor.VisitLeaf(b, false)) + return false; // finished + } + } + + // HANDLE INPUT SIGNALS + foreach(Signal s in port.InputSignals) + if(!TraverseSignal(signals, ports, buses, s, port, ignoreHold, visitor)) + return false; // finished + } + return visitor.LeavePort(port, target, again, target == null); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/BasicScanVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/BasicScanVisitor.cs new file mode 100644 index 0000000..19630cc --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/BasicScanVisitor.cs @@ -0,0 +1,94 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + [System.Diagnostics.DebuggerStepThrough] + public class BasicScanVisitor : IScanVisitor + { + private ProcessSignal _enterSignal, _leaveSignal; + private ProcessPort _enterPort, _leavePort; + private ProcessLeafSignal _leafSignal; + private ProcessLeafPort _leafPort; + private ProcessLeafBus _leafBus; + private ProcessCycle _cycle; + + public BasicScanVisitor(ProcessSignal enterSignal, ProcessSignal leaveSignal, + ProcessPort enterPort, ProcessPort leavePort, + ProcessLeafSignal leafSignal, ProcessLeafPort leafPort, ProcessLeafBus leafBus, + ProcessCycle cycle) + { + _enterSignal = enterSignal; _leaveSignal = leaveSignal; + _enterPort = enterPort; _leavePort = leavePort; + _leafSignal = leafSignal; _leafPort = leafPort; _leafBus = leafBus; + _cycle = cycle; + } + + public IScanStrategy DefaultStrategy + { + get { return Strategies.AllStrategy.Instance; } + } + + public bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + return _enterSignal(signal, parent, again, root); + } + + public bool LeaveSignal(Signal signal, Port parent, bool again, bool root) + { + return _leaveSignal(signal, parent, again, root); + } + + public bool EnterPort(Port port, Signal parent, bool again, bool root) + { + return _enterPort(port, parent, again, root); + } + + public bool LeavePort(Port port, Signal parent, bool again, bool root) + { + return _leavePort(port, parent, again, root); + } + + public bool VisitLeaf(Signal signal, bool again) + { + return _leafSignal(signal, again); + } + + public bool VisitLeaf(Port port, bool again) + { + return _leafPort(port, again); + } + + public bool VisitLeaf(Bus bus, bool again) + { + return _leafBus(bus, again); + } + + public bool VisitCycle(Port port, Signal target, Signal source) + { + return _cycle(port, target, source); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/CollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/CollectVisitor.cs new file mode 100644 index 0000000..581de09 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/CollectVisitor.cs @@ -0,0 +1,91 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class CollectVisitor : AbstractScanVisitor, ICollectVisitor + { + private List _signals; + private List _ports; + private List _buses; + + public CollectVisitor() + { + _signals = new List(); + _ports = new List(); + _buses = new List(); + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllSpanningTreeStrategy.Instance; } + } + + public void Reset() + { + _signals.Clear(); + _ports.Clear(); + _buses.Clear(); + } + + public IList Signals + { + get { return _signals; } + } + + public IList Ports + { + get { return _ports; } + } + + public IList Buses + { + get { return _buses; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + if(again) + return false; + _signals.Add(signal); + return true; + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + if(again) + return false; + _ports.Add(port); + return true; + } + + public override bool VisitLeaf(Bus bus, bool again) + { + if(!again) + _buses.Add(bus); + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ConditionalCollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ConditionalCollectVisitor.cs new file mode 100644 index 0000000..bbd7bde --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ConditionalCollectVisitor.cs @@ -0,0 +1,140 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class ConditionalCollectVisitor : AbstractScanVisitor, ICollectVisitor + { + private List _signals; + private List _ports; + private List _buses; + + private Predicate _signalMatch; + private Predicate _portMatch; + private Predicate _busMatch; + + #region Constructors + public ConditionalCollectVisitor() + { + _signals = new List(); + _ports = new List(); + _buses = new List(); + + _signalMatch = DummySignalPredicate; + _portMatch = DummyPortPredicate; + _busMatch = DummyBusPredicate; + } + public ConditionalCollectVisitor(Predicate signalMatch, Predicate portMatch, Predicate busMatch) + { + _signals = new List(); + _ports = new List(); + _buses = new List(); + + _signalMatch = signalMatch; + _portMatch = portMatch; + _busMatch = busMatch; + } + public ConditionalCollectVisitor(Predicate signalMatch) : this() + { + _signalMatch = signalMatch; + } + public ConditionalCollectVisitor(Predicate portMatch) : this() + { + _portMatch = portMatch; + } + public ConditionalCollectVisitor(Predicate busMatch) : this() + { + _busMatch = busMatch; + } + #endregion + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllSpanningTreeStrategy.Instance; } + } + + public void Reset() + { + _signals.Clear(); + _ports.Clear(); + _buses.Clear(); + } + + public IList Signals + { + get { return _signals; } + } + + public IList Ports + { + get { return _ports; } + } + + public IList Buses + { + get { return _buses; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + if(again) + return false; + if(_signalMatch(signal)) + _signals.Add(signal); + return true; + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + if(again) + return false; + if(_portMatch(port)) + _ports.Add(port); + return true; + } + + public override bool VisitLeaf(Bus bus, bool again) + { + if(!again && _busMatch(bus)) + _buses.Add(bus); + return true; + } + + #region Dummy Predicates + private bool DummySignalPredicate(Signal signal) + { + return true; + } + private bool DummyPortPredicate(Port port) + { + return true; + } + private bool DummyBusPredicate(Bus bus) + { + return true; + } + #endregion + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ExistsPortVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ExistsPortVisitor.cs new file mode 100644 index 0000000..09eec5a --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ExistsPortVisitor.cs @@ -0,0 +1,83 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class ExistsPortVisitor : AbstractScanVisitor, IExistsPortVisitor + { + private Predicate _match; + private Port _foundPort; + private Signal _foundPortTarget; + + public ExistsPortVisitor(Predicate match) + { + _match = match; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllPortsStrategy.Instance; } + } + + public void Reset() + { + _foundPort = null; + _foundPortTarget = null; + } + + public bool Exists + { + get { return _foundPort != null; } + } + + public Port FoundPort + { + get { return _foundPort; } + } + + public Signal FoundPortTarget + { + get { return _foundPortTarget; } + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + if(again) + return false; + if(_match(port)) + { + _foundPort = port; + _foundPortTarget = parent; + return false; + } + return true; + } + + public override bool LeavePort(Port port, Signal parent, bool again, bool root) + { + return _foundPort == null; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ExistsSignalVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ExistsSignalVisitor.cs new file mode 100644 index 0000000..c8aa9c9 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/ExistsSignalVisitor.cs @@ -0,0 +1,83 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class ExistsSignalVisitor : AbstractScanVisitor, IExistsSignalVisitor + { + private Predicate _match; + private Signal _foundSignal; + private Port _foundSignalTarget; + + public ExistsSignalVisitor(Predicate match) + { + _match = match; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllSignalsStrategy.Instance; } + } + + public void Reset() + { + _foundSignal = null; + _foundSignalTarget = null; + } + + public bool Exists + { + get { return _foundSignal != null; } + } + + public Signal FoundSignal + { + get { return _foundSignal; } + } + + public Port FoundSignalTarget + { + get { return _foundSignalTarget; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + if(again) + return false; + if(_match(signal)) + { + _foundSignal = signal; + _foundSignalTarget = parent; + return false; + } + return true; + } + + public override bool LeaveSignal(Signal signal, Port parent, bool again, bool root) + { + return _foundSignal == null; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortActionVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortActionVisitor.cs new file mode 100644 index 0000000..9709c5f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortActionVisitor.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class PortActionVisitor : AbstractScanVisitor + { + private ActionContinue _action; + + public PortActionVisitor(ActionContinue action) + { + _action = action; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllPortsStrategy.Instance; } + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + if(again) + return false; + return _action(port); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortConditionalActionVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortConditionalActionVisitor.cs new file mode 100644 index 0000000..4fb83c1 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortConditionalActionVisitor.cs @@ -0,0 +1,53 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class PortConditionalActionVisitor : AbstractScanVisitor + { + private ActionContinue _action; + private Predicate _match; + + public PortConditionalActionVisitor(ActionContinue action, Predicate match) + { + _action = action; + _match = match; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllPortsStrategy.Instance; } + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + if(again) + return false; + if(_match(port)) + return _action(port); + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortPathCollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortPathCollectVisitor.cs new file mode 100644 index 0000000..e78c3a4 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/PortPathCollectVisitor.cs @@ -0,0 +1,76 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class PortPathCollectVisitor : AbstractScanVisitor, IPortPathCollectVisitor + { + private List> _paths; + private Stack _currentPath; + private Port _source; + + public PortPathCollectVisitor(Port source) + { + _paths = new List>(); + _currentPath = new Stack(); + _source = source; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllPathsStrategy.Instance; } + } + + public void Reset(Port source) + { + _paths.Clear(); + _currentPath.Clear(); + _source = source; + } + + public List> Paths + { + get { return _paths; } + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + _currentPath.Push(port); + if(_source.Equals(port)) + { + List p = new List(_currentPath); + _paths.Add(p); + return false; + } + return base.EnterPort(port, parent, again, root); + } + + public override bool LeavePort(Port port, Signal parent, bool again, bool root) + { + _currentPath.Pop(); + return base.LeavePort(port, parent, again, root); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalActionVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalActionVisitor.cs new file mode 100644 index 0000000..19c3ad3 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalActionVisitor.cs @@ -0,0 +1,49 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class SignalActionVisitor : AbstractScanVisitor + { + private ActionContinue _action; + + public SignalActionVisitor(ActionContinue action) + { + _action = action; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllSignalsStrategy.Instance; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + if(again) + return false; + return _action(signal); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalConditionalActionVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalConditionalActionVisitor.cs new file mode 100644 index 0000000..b01fedb --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalConditionalActionVisitor.cs @@ -0,0 +1,53 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class SignalConditionalActionVisitor : AbstractScanVisitor + { + private ActionContinue _action; + private Predicate _match; + + public SignalConditionalActionVisitor(ActionContinue action, Predicate match) + { + _action = action; + _match = match; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllSignalsStrategy.Instance; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + if(again) + return false; + if(_match(signal)) + return _action(signal); + return true; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalPathCollectVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalPathCollectVisitor.cs new file mode 100644 index 0000000..448955f --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/SignalPathCollectVisitor.cs @@ -0,0 +1,76 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class SignalPathCollectVisitor : AbstractScanVisitor, ISignalPathCollectVisitor + { + private List> _paths; + private Stack _currentPath; + private Signal _source; + + public SignalPathCollectVisitor(Signal source) + { + _paths = new List>(); + _currentPath = new Stack(); + _source = source; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllPathsStrategy.Instance; } + } + + public void Reset(Signal source) + { + _paths.Clear(); + _currentPath.Clear(); + _source = source; + } + + public List> Paths + { + get { return _paths; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + _currentPath.Push(signal); + if(_source.Equals(signal)) + { + List p = new List(_currentPath); + _paths.Add(p); + return false; + } + return base.EnterSignal(signal, parent, again, root); + } + + public override bool LeaveSignal(Signal signal, Port parent, bool again, bool root) + { + _currentPath.Pop(); + return base.LeaveSignal(signal, parent, again, root); + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/TrueForAllPortsVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/TrueForAllPortsVisitor.cs new file mode 100644 index 0000000..e46034e --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/TrueForAllPortsVisitor.cs @@ -0,0 +1,83 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class TrueForAllPortsVisitor : AbstractScanVisitor, ITrueForAllPortsVisitor + { + private Predicate _match; + private Port _failedPort; + private Signal _failedPortTarget; + + public TrueForAllPortsVisitor(Predicate match) + { + _match = match; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllPortsStrategy.Instance; } + } + + public void Reset() + { + _failedPort = null; + _failedPortTarget = null; + } + + public bool TrueForAll + { + get { return _failedPort == null; } + } + + public Port FailedPort + { + get { return _failedPort; } + } + + public Signal FailedPortTarget + { + get { return _failedPortTarget; } + } + + public override bool EnterPort(Port port, Signal parent, bool again, bool root) + { + if(again) + return false; + if(!_match(port)) + { + _failedPort = port; + _failedPortTarget = parent; + return false; + } + return true; + } + + public override bool LeavePort(Port port, Signal parent, bool again, bool root) + { + return _failedPort == null; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/TrueForAllSignalsVisitor.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/TrueForAllSignalsVisitor.cs new file mode 100644 index 0000000..f239a7b --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Traversing/Visitors/TrueForAllSignalsVisitor.cs @@ -0,0 +1,83 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathNet.Symbolics.Traversing.Visitors +{ + public class TrueForAllSignalsVisitor : AbstractScanVisitor, ITrueForAllSignalsVisitor + { + private Predicate _match; + private Signal _failedSignal; + private Port _failedSignalTarget; + + public TrueForAllSignalsVisitor(Predicate match) + { + _match = match; + } + + public override IScanStrategy DefaultStrategy + { + get { return Strategies.AllSignalsStrategy.Instance; } + } + + public void Reset() + { + _failedSignal = null; + _failedSignalTarget = null; + } + + public bool TrueForAll + { + get { return _failedSignal == null; } + } + + public Signal FailedSignal + { + get { return _failedSignal; } + } + + public Port FailedSignalTarget + { + get { return _failedSignalTarget; } + } + + public override bool EnterSignal(Signal signal, Port parent, bool again, bool root) + { + if(again) + return false; + if(!_match(signal)) + { + _failedSignal = signal; + _failedSignalTarget = parent; + return false; + } + return true; + } + + public override bool LeaveSignal(Signal signal, Port parent, bool again, bool root) + { + return _failedSignal == null; + } + } +} diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/VisitorFactory.cs b/Backup/src/app/MathNet.Yttrium/Traversing.Service/VisitorFactory.cs new file mode 100644 index 0000000..070c5f8 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/VisitorFactory.cs @@ -0,0 +1,176 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Traversing.Visitors; + +namespace MathNet.Symbolics +{ + internal class VisitorFactory : + IFactory, + IFactory>, + IFactory>, + IFactory>, + IFactory>, + IFactory, + IFactory, + IFactory, + IFactory>, + IFactory>, + IFactory>, + IFactory, Predicate, Predicate>, + IFactory>, + IFactory>, + IFactory, Predicate>, + IFactory, Predicate>, + IFactory + { + // SCANNER + IScanner IFactory.GetInstance() + { + return new Scanner(); + } + + // ExistsSignalVisitor + IExistsSignalVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: Predicate"); + } + IExistsSignalVisitor IFactory>.GetInstance(Predicate match) + { + return new ExistsSignalVisitor(match); + } + + // ExistsPortVisitor + IExistsPortVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: Predicate"); + } + IExistsPortVisitor IFactory>.GetInstance(Predicate match) + { + return new ExistsPortVisitor(match); + } + + // TrueForAllSignalsVisitor + ITrueForAllSignalsVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: Predicate"); + } + ITrueForAllSignalsVisitor IFactory>.GetInstance(Predicate match) + { + return new TrueForAllSignalsVisitor(match); + } + + // TrueForAllPortsVisitor + ITrueForAllPortsVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: Predicate"); + } + ITrueForAllPortsVisitor IFactory>.GetInstance(Predicate match) + { + return new TrueForAllPortsVisitor(match); + } + + // SignalPathCollectVisitor + ISignalPathCollectVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: ISignal"); + } + ISignalPathCollectVisitor IFactory.GetInstance(Signal source) + { + return new SignalPathCollectVisitor(source); + } + + // SignalPathCollectVisitor + IPortPathCollectVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters: Port"); + } + IPortPathCollectVisitor IFactory.GetInstance(Port source) + { + return new PortPathCollectVisitor(source); + } + + // CollectVisitor + ICollectVisitor IFactory.GetInstance() + { + return new CollectVisitor(); + } + + // ConditionalCollectVisitor + ICollectVisitor IFactory>.GetInstance(Predicate match) + { + return new ConditionalCollectVisitor(match); + } + ICollectVisitor IFactory>.GetInstance(Predicate match) + { + return new ConditionalCollectVisitor(match); + } + ICollectVisitor IFactory>.GetInstance(Predicate match) + { + return new ConditionalCollectVisitor(match); + } + ICollectVisitor IFactory, Predicate, Predicate>.GetInstance(Predicate p1, Predicate p2, Predicate p3) + { + return new ConditionalCollectVisitor(p1, p2, p3); + } + + + IScanVisitor IFactory.GetInstance() + { + throw new NotSupportedException("expected parameters"); + } + + // SignalActionVisitor + IScanVisitor IFactory>.GetInstance(ActionContinue action) + { + return new SignalActionVisitor(action); + } + + // PortActionVisitor + IScanVisitor IFactory>.GetInstance(ActionContinue action) + { + return new PortActionVisitor(action); + } + + // SignalConditionalActionVisitor + IScanVisitor IFactory, Predicate>.GetInstance(ActionContinue action, Predicate match) + { + return new SignalConditionalActionVisitor(action, match); + } + + // PortConditionalActionVisitor + IScanVisitor IFactory, Predicate>.GetInstance(ActionContinue action, Predicate match) + { + return new PortConditionalActionVisitor(action, match); + } + + // BasicVisitor + IScanVisitor IFactory.GetInstance(ProcessSignal enterSignal, ProcessSignal leaveSignal, ProcessPort enterPort, ProcessPort leavePort, ProcessLeafSignal leafSignal, ProcessLeafPort leafPort, ProcessLeafBus leafBus, ProcessCycle cycle) + { + return new BasicScanVisitor(enterSignal,leaveSignal,enterPort,leavePort,leafSignal,leafPort,leafBus,cycle); + } + } +} \ No newline at end of file diff --git a/Backup/src/app/MathNet.Yttrium/Traversing.Service/Yttrium.Traversing.Service.csproj b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Yttrium.Traversing.Service.csproj new file mode 100644 index 0000000..cc0bb38 --- /dev/null +++ b/Backup/src/app/MathNet.Yttrium/Traversing.Service/Yttrium.Traversing.Service.csproj @@ -0,0 +1,91 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {90E6DB8F-7BFD-4DB3-B705-468769B718E8} + Library + Properties + MathNet.Symbolics + MathNet.Yttrium.Traversing.Service + + + true + full + false + ..\..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + ..\..\..\..\build\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\build\Release\MathNet.Iridium.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Yttrium.Traversing.Contracts + + + + + \ No newline at end of file diff --git a/Backup/src/test/MathNet.Yttrium.Test/AutoSimplifyTest.cs b/Backup/src/test/MathNet.Yttrium.Test/AutoSimplifyTest.cs new file mode 100644 index 0000000..6ce0c42 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/AutoSimplifyTest.cs @@ -0,0 +1,162 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +//using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework; +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Numerics; +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Interpreter; +using MathNet.Symbolics.Backend.Channels; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard.Properties; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Formatter; + +namespace Yttrium.UnitTests +{ + //[TestClass] + [TestFixture] + public class AutoSimplifyTest + { + private Project _p; + private IFormatter _f; + + [SetUp] + public void Initialize() + { + _p = new Project(); + _f = Service.Instance; + } + + [TearDown] + public void Cleanup() + { + _p = null; + _f = null; + } + + [Test] + public void AutoSimplify_RationalNumberExpression() + { + // A + Signal a = + StdBuilder.Add( + StdBuilder.Divide(IntegerValue.Constant(2), IntegerValue.Constant(3)), + RationalValue.Constant(3, 4)); + Assert.AreEqual("2/3+3/4", _f.Format(a, FormattingOptions.Compact), "A1"); + + Signal aS = Std.AutoSimplify(a); + Assert.AreEqual("17/12", _f.Format(aS, FormattingOptions.Compact), "A2"); + + // B + Signal b = + StdBuilder.Power( + StdBuilder.Divide(IntegerValue.Constant(4), IntegerValue.Constant(2)), + IntegerValue.Constant(3)); + Assert.AreEqual("(4/2)^3", _f.Format(b, FormattingOptions.Compact), "B1"); + + Signal bS = Std.AutoSimplify(b); + Assert.AreEqual("8", _f.Format(bS, FormattingOptions.Compact), "B2"); + + // C + Signal c = + StdBuilder.Divide( + IntegerValue.ConstantOne, + StdBuilder.Subtract( + RationalValue.Constant(2, 4), + RationalValue.ConstantHalf)); + Assert.AreEqual("1/(1/2-1/2)", _f.Format(c, FormattingOptions.Compact), "C1"); + + Signal cS = Std.AutoSimplify(c); + Assert.AreEqual("Std.Undefined", _f.Format(cS, FormattingOptions.Compact), "C2"); + + // D + Signal d = + StdBuilder.Power( + StdBuilder.Power( + IntegerValue.Constant(5), + IntegerValue.Constant(2)), + StdBuilder.Power( + IntegerValue.Constant(3), + IntegerValue.Constant(1))); + Assert.AreEqual("(5^2)^(3^1)", _f.Format(d, FormattingOptions.Compact), "D1"); + + Signal dS = Std.AutoSimplify(d); + Assert.AreEqual("15625", _f.Format(dS, FormattingOptions.Compact), "D2"); + } + + [Test] + public void AutoSimplify_MathOp_AlgebraDerive() + { + IMathSystem s = _p.CurrentSystem; + + _p.Interpret(@"Signal x;"); + _p.Interpret(@"Signal fn;"); + _p.Interpret(@"Signal fdiv;"); + _p.Interpret(@"Signal fdiff;"); + + _p.Interpret(@"fn <- 3*exp(-3*x)-x;"); + _p.Interpret(@"fdiff <- diff(3*exp(-3*x)-x, x);"); + _p.Interpret(@"fdiv <- fn / fdiff;"); + + Signal x = s.LookupNamedSignal("x"); + Std.ConstrainAlwaysReal(x); + + Signal fdiv = s.LookupNamedSignal("fdiv"); + Assert.AreEqual(new MathIdentifier("Divide", "Std"), fdiv.DrivenByPort.Entity.EntityId, "A"); + + Signal fdiv_n = fdiv.DrivenByPort.InputSignals[0]; + Signal fdiv_d = fdiv.DrivenByPort.InputSignals[1]; + Assert.AreEqual(new MathIdentifier("Subtract", "Std"), fdiv_n.DrivenByPort.Entity.EntityId, "B"); + Assert.AreEqual(new MathIdentifier("Derive", "Std"), fdiv_d.DrivenByPort.Entity.EntityId, "C"); + + // Execute MathOp Std.Derive + Signal simplified = Std.AutoSimplify(fdiv); + Assert.AreEqual("(3*exp(-3*x)+-1*x)*(-1+-9*exp(-3*x))^(-1)", _f.Format(simplified, FormattingOptions.Compact), "D"); + Assert.AreEqual(new MathIdentifier("Multiply", "Std"), simplified.DrivenByPort.Entity.EntityId, "E"); + + Signal simplified_n = simplified.DrivenByPort.InputSignals[0]; + Signal simplified_d = simplified.DrivenByPort.InputSignals[1]; + Assert.AreEqual(new MathIdentifier("Add", "Std"), simplified_n.DrivenByPort.Entity.EntityId, "F"); + Assert.AreEqual(new MathIdentifier("Power", "Std"), simplified_d.DrivenByPort.Entity.EntityId, "G"); + + s.PromoteAsInput(x); + s.AddSignalTree(simplified, true, false); + //s.PromoteAsOutput(simplified); + s.RemoveUnusedObjects(); + + // The Derive Mapping should be removed from the system + Assert.IsFalse(s.GetAllPorts().Exists(delegate(Port port) { return port.Entity.EqualsById(new MathIdentifier("Derive", "Std")); }), "H"); + + Assert.AreEqual(-0.3, s.Evaluate(0.0)[0], 1e-8, "x=0.0"); + Assert.AreEqual(.5874238104, s.Evaluate(1.0)[0], 1e-8, "x=1.0"); + Assert.AreEqual(3.139070661, s.Evaluate(Constants.Pi)[0], 1e-8, "x=Pi"); + Assert.AreEqual(-.3334664750, s.Evaluate(-2.5)[0], 1e-8, "x=-2.5"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/BasicTest.cs b/Backup/src/test/MathNet.Yttrium.Test/BasicTest.cs new file mode 100644 index 0000000..9b9202a --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/BasicTest.cs @@ -0,0 +1,184 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +//using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework; +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Library; +using MathNet.Symbolics.Traversing; +using MathNet.Symbolics.Manipulation; +using MathNet.Symbolics.Packages.Standard; + +namespace Yttrium.UnitTests +{ + //[TestClass] + [TestFixture] + public class BasicTest + { + private Project project; + + //[TestInitialize] + [SetUp] + public void Initialize() + { + this.project = new Project(); + } + + //[TestCleanup] + public void Cleanup() + { + this.project = null; + } + + //[TestMethod] + [Test] + public void Basic_EntityLookupTest() + { + ILibrary library = Service.Instance; + + IEntity addEntity = library.LookupEntity(new MathIdentifier("Add", "Std")); + IEntity subtractEntity = library.LookupEntity("-", 2); + + Assert.AreEqual("+", addEntity.Symbol); + Assert.AreEqual("Std.Subtract", subtractEntity.EntityId.ToString()); + } + + //[TestMethod] + [Test] + public void Basic_SignalTest() + { + Signal a = Binder.CreateSignal(); + Signal b = Binder.CreateSignal(); + + Signal c = a + b; + + Assert.AreEqual("Std.Add", c.DrivenByPort.Entity.EntityId.ToString()); + } + + //[TestMethod] + [Test] + public void Basic_CycleTest() + { + Signal a = Binder.CreateSignal(); a.Label = "A"; + Signal b = Binder.CreateSignal(); b.Label = "B"; + + Signal c = a + b; c.Label = "C"; + Signal d = a * c; d.Label = "D"; + + Assert.AreEqual(0, a.Cycles, "Cycle A0"); + Assert.AreEqual(0, b.Cycles, "Cycle A1"); + Assert.AreEqual(0, c.Cycles, "Cycle A2"); + Assert.AreEqual(0, d.Cycles, "Cycle A3"); + + Service.Instance.MapSignals(c, b); + + Assert.AreEqual(0, a.Cycles, "Cycle B0"); + Assert.AreEqual(1, b.Cycles, "Cycle B1"); + Assert.AreEqual(1, c.Cycles, "Cycle B2"); + Assert.AreEqual(0, d.Cycles, "Cycle B3"); + + Service.Instance.MapSignals(d, a); + + Assert.AreEqual(2, a.Cycles, "Cycle C0"); + Assert.AreEqual(1, b.Cycles, "Cycle C1"); + Assert.AreEqual(2, c.Cycles, "Cycle C2"); + Assert.AreEqual(2, d.Cycles, "Cycle C3"); + + List> paths = Service.Instance.FindAllSignalPathsFrom(d, a, false); + Assert.AreEqual(2, paths.Count,"Paths 0"); + Assert.AreEqual(a, paths[0][0], "Paths 1"); + Assert.AreEqual(d, paths[0][1], "Paths 2"); + Assert.AreEqual(a, paths[1][0], "Paths 3"); + Assert.AreEqual(c, paths[1][1], "Paths 4"); + Assert.AreEqual(d, paths[1][2], "Paths 5"); + + Signal e = Binder.CreateSignal(); e.Label = "E"; + + Signal f = Service.Instance.Substitute(d, c, e); //d.Substitute(c, e); f.Label = "F"; + + Assert.AreEqual(f, f.DrivenByPort.InputSignals[0].DrivenByPort.InputSignals[0], "Paths2 X"); + + List> paths2 = Service.Instance.FindAllSignalPathsFrom(f, e, false); + Assert.AreEqual(1, paths2.Count, "Paths2 0"); + Assert.AreEqual(e, paths2[0][0], "Paths2 1"); + Assert.AreEqual(f, paths2[0][1], "Paths2 2"); + + Assert.AreEqual(0, Service.Instance.FindAllSignalPathsFrom(f, a, false).Count, "Paths3"); + Assert.AreEqual(0, Service.Instance.FindAllSignalPathsFrom(f, d, false).Count, "Paths4"); + + paths = Service.Instance.FindAllSignalPathsFrom(d, a, false); + Assert.AreEqual(2, paths.Count, "Paths5 0"); + Assert.AreEqual(a, paths[0][0], "Paths5 1"); + Assert.AreEqual(d, paths[0][1], "Paths5 2"); + Assert.AreEqual(a, paths[1][0], "Paths5 3"); + Assert.AreEqual(c, paths[1][1], "Paths5 4"); + Assert.AreEqual(d, paths[1][2], "Paths5 5"); + } + + //[TestMethod] + [Test] + public void Basic_Traversing() + { + Signal a = Binder.CreateSignal(); a.Label = "A"; + Signal b = Binder.CreateSignal(); b.Label = "B"; + Signal c = StdBuilder.Add(a, b); c.Label = "C"; //a + b; + Signal d = StdBuilder.Multiply(a, c); d.Label = "D"; //a * c; + + Assert.IsTrue(c.DependsOn(a), "1: a->c"); + Assert.IsTrue(c.DependsOn(b), "1: b->c"); + Assert.IsTrue(d.DependsOn(a), "1: a->d"); + Assert.IsTrue(d.DependsOn(b), "1: b->d"); + Assert.IsTrue(d.DependsOn(c), "1: c->d"); + Assert.IsFalse(a.DependsOn(b), "1: b!->a"); + Assert.IsFalse(b.DependsOn(a), "1: a!->b"); + Assert.IsFalse(a.DependsOn(d), "1: d!->a"); + Assert.IsFalse(b.DependsOn(d), "1: d!->b"); + Assert.IsFalse(c.DependsOn(d), "1: d!->c"); + Assert.IsFalse(a.DependsOn(c), "1: c!->a"); + Assert.IsFalse(b.DependsOn(c), "1: c!->b"); + + Service.Instance.MapSignals(c, b); + + Assert.IsTrue(c.DependsOn(a), "2: a->c"); + Assert.IsTrue(c.DependsOn(b), "2: b->c"); + Assert.IsTrue(d.DependsOn(a), "2: a->d"); + Assert.IsTrue(d.DependsOn(b), "2: b->d"); + Assert.IsTrue(d.DependsOn(c), "2: c->d"); + Assert.IsFalse(a.DependsOn(b), "2: b!->a"); + Assert.IsTrue(b.DependsOn(a), "2: a->b"); // NEW + Assert.IsFalse(a.DependsOn(d), "2: d!->a"); + Assert.IsFalse(b.DependsOn(d), "2: d!->b"); + Assert.IsFalse(c.DependsOn(d), "2: d!->c"); + Assert.IsFalse(a.DependsOn(c), "2: c!->a"); + Assert.IsTrue(b.DependsOn(c), "2: c->b"); // NEW + + Assert.IsTrue(Service.Instance.ExistsSignal(d, delegate(Signal s) { return s.Label == "A"; }, false)); + Assert.IsFalse(Service.Instance.ExistsSignal(d, delegate(Signal s) { return s.Label == "Z"; }, false)); + Assert.AreEqual("B", Service.Instance.FindSignal(d, delegate(Signal s) { return s.Label == "B"; }, false).Label); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/ConversionTest.cs b/Backup/src/test/MathNet.Yttrium.Test/ConversionTest.cs new file mode 100644 index 0000000..55e49d8 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/ConversionTest.cs @@ -0,0 +1,75 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using NUnit.Framework; + +using MathNet.Symbolics; +using MathNet.Symbolics.Conversion; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Library; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class ConversionTest + { + [SetUp] + public void Initialize() + { + Service.Instance.LoadStdPackage(); + } + + [Test] + public void DirectLosslessConversionsTest() + { + IntegerValue int1 = new IntegerValue(35); + + RationalValue rat1 = ValueConverter.ConvertFrom(int1); + Assert.AreEqual(35, rat1.NumeratorValue, "01"); + Assert.AreEqual(1, rat1.DenominatorValue, "02"); + + RealValue real1 = ValueConverter.ConvertFrom(rat1); + Assert.AreEqual(35d, real1.Value, 0.0001d, "03"); + } + + [Test] + public void IndirectLosslessConversionsTest() + { + ToggleValue toggle1 = ToggleValue.InitialToggle; + Assert.AreEqual("Std.Toggle(A)", toggle1.ToString(), "01"); + + RationalValue rat1 = ValueConverter.ConvertFrom(toggle1); + Assert.AreEqual(1, rat1.NumeratorValue, "02"); + Assert.AreEqual(1, rat1.DenominatorValue, "03"); + + RationalValue rat2 = ValueConverter.ConvertFrom(toggle1.Toggle()); + Assert.AreEqual(0, rat2.NumeratorValue, "04"); + Assert.AreEqual(1, rat2.DenominatorValue, "05"); + + RealValue real1 = ValueConverter.ConvertFrom(toggle1); + Assert.AreEqual(1d, real1.Value, 0.0001d, "06"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/FormatterTest.cs b/Backup/src/test/MathNet.Yttrium.Test/FormatterTest.cs new file mode 100644 index 0000000..9be2ded --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/FormatterTest.cs @@ -0,0 +1,148 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Interpreter; +using MathNet.Symbolics.Formatter; +using MathNet.Symbolics.Backend.Channels; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Library; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class FormatterTest + { + private Project project; + + [SetUp] + public void Initialize() + { + this.project = new Project(); + } + + [TearDown] + public void Cleanup() + { + this.project = null; + } + + [Test] + public void FormatPolynomialTest() + { + IFormatter f = Service.Instance; + + Signal x = Binder.CreateSignal(); + x.Label = "x"; + + Signal p = Polynomial.ConstructPolynomial(x, + new RationalValue(1, 3), + new RationalValue(4, 5), + RationalValue.Zero, + new RationalValue(12, 23)); + + Assert.AreEqual("1/3+(4/5)*x+(12/23)*x^3", + f.Format(p, FormattingOptions.Compact), "A01"); + } + + [Test] + public void FormatAssociativeTest() + { + IFormatter f = Service.Instance; + MathSystem s = project.CurrentSystem; + s.RemoveUnusedObjects(); + + project.Interpret("v1 <- (a+b)+(c+d);"); + Signal v1 = s.LookupNamedSignal("v1"); + Assert.AreEqual("(a+b)+(c+d)", f.Format(v1, FormattingOptions.Compact), "V1A"); + Signal v1S = Std.AutoSimplify(v1); + Assert.AreEqual("a+b+c+d", f.Format(v1S, FormattingOptions.Compact), "V1B"); + + project.Interpret("v2 <- (a-b)+(c-d);"); + Signal v2 = s.LookupNamedSignal("v2"); + Assert.AreEqual("(a-b)+(c-d)", f.Format(v2, FormattingOptions.Compact), "V2A"); + Signal v2S = Std.AutoSimplify(v2); + Assert.AreEqual("a+-1*b+c+-1*d", f.Format(v2S, FormattingOptions.Compact), "V2B"); + + project.Interpret("w1 <- (a-b)-(c-d);"); + Signal w1 = s.LookupNamedSignal("w1"); + Assert.AreEqual("(a-b)-(c-d)", f.Format(w1, FormattingOptions.Compact), "W1A"); + Signal w1S = Std.AutoSimplify(w1); + Assert.AreEqual("a+-1*b+-1*c+d", f.Format(w1S, FormattingOptions.Compact), "W1B"); + + project.Interpret("w2 <- (a+b)-(c+d);"); + Signal w2 = s.LookupNamedSignal("w2"); + Assert.AreEqual("(a+b)-(c+d)", f.Format(w2, FormattingOptions.Compact), "W2A"); + Signal w2S = Std.AutoSimplify(w2); + Assert.AreEqual("a+b+-1*c+-1*d", f.Format(w2S, FormattingOptions.Compact), "W2B"); + + project.Interpret("x1 <- (a*b)*(c*d);"); + Signal x1 = s.LookupNamedSignal("x1"); + Assert.AreEqual("(a*b)*(c*d)", f.Format(x1, FormattingOptions.Compact), "X1A"); + Signal x1S = Std.AutoSimplify(x1); + Assert.AreEqual("a*b*c*d", f.Format(x1S, FormattingOptions.Compact), "X1B"); + + project.Interpret("x2 <- (a/b)*(c/d);"); + Signal x2 = s.LookupNamedSignal("x2"); + Assert.AreEqual("(a/b)*(c/d)", f.Format(x2, FormattingOptions.Compact), "X2A"); + Signal x2S = Std.AutoSimplify(x2); + Assert.AreEqual("a*b^(-1)*c*d^(-1)", f.Format(x2S, FormattingOptions.Compact), "X2B"); + + project.Interpret("y1 <- (a/b)/(c/d);"); + Signal y1 = s.LookupNamedSignal("y1"); + Assert.AreEqual("(a/b)/(c/d)", f.Format(y1, FormattingOptions.Compact), "Y1A"); + Signal y1S = Std.AutoSimplify(y1); + Assert.AreEqual("a*b^(-1)*c^(-1)*d", f.Format(y1S, FormattingOptions.Compact), "Y1B"); + + project.Interpret("y2 <- (a*b)/(c*d);"); + Signal y2 = s.LookupNamedSignal("y2"); + Assert.AreEqual("(a*b)/(c*d)", f.Format(y2, FormattingOptions.Compact), "Y2A"); + Signal y2S = Std.AutoSimplify(y2); + Assert.AreEqual("a*b*c^(-1)*d^(-1)", f.Format(y2S, FormattingOptions.Compact), "Y2B"); + } + + [Test] + public void FormatPrecedenceTest() + { + MathSystem s = project.CurrentSystem; + s.RemoveUnusedObjects(); + + project.Interpret("x <- a+3+b*(c+d)/(1/2+3/4)^(5/6);"); + Signal x = s.LookupNamedSignal("x"); + + Assert.AreEqual("(a+3)+(b*(c+d))/(1/2+3/4)^(5/6)", + Service.Instance.Format(x, FormattingOptions.Compact), "A01"); + + Signal x2 = Std.AutoSimplify(x); + + Assert.AreEqual("3+a+b*(c+d)*((5/4)^(5/6))^(-1)", + Service.Instance.Format(x2, FormattingOptions.Compact), "B01"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/FundamentTest.cs b/Backup/src/test/MathNet.Yttrium.Test/FundamentTest.cs new file mode 100644 index 0000000..2592692 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/FundamentTest.cs @@ -0,0 +1,353 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using NUnit.Framework; + +using MathNet.Symbolics; +using MathNet.Symbolics.Events; +using MathNet.Symbolics.AutoEvaluation; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class FundamentTest + { + public class NodeObject + : Node + { + protected override void OnAutoEvaluateFlag(NodeFlag flag) + { + } + + protected override void OnAutoEvaluateProperty(NodeProperty property) + { + } + } + + private int _counter = 0; + private NodePropertyChangedEventArgs _lastPropertyChangedEventArgs; + private NodeFlagChangedEventArgs _lastFlagChangedEventArgs; + private void OnPropertyChanged(object sender, NodePropertyChangedEventArgs e) + { + _lastPropertyChangedEventArgs = e; + _counter++; + } + private void OnFlagChanged(object sender, NodeFlagChangedEventArgs e) + { + _lastFlagChangedEventArgs = e; + _counter--; + } + + [Test] + public void PropertyAspectTest() + { + MathIdentifier propertyId = new MathIdentifier("T0_PA", "FundamentTest"); + NodeProperty property = NodeProperty.Register(propertyId, typeof(string), typeof(FundamentTest)); + + NodeObject n = new NodeObject(); + _counter = 0; + n.AddHandler(property.PropertyChangedEvent, new EventHandler(OnPropertyChanged)); + + Assert.AreEqual(0, _counter, "X1"); + Assert.IsFalse(n.IsPropertySet(property, false), "A01"); + Assert.IsFalse(n.IsPropertySet(property, true), "A02"); + Assert.IsFalse(n.IsPropertyDirty(property), "A03"); + Assert.AreEqual("nothing", n.GetProperty(property, "nothing", false), "A04"); + Assert.AreEqual("nothing", n.GetProperty(property, "nothing", true), "A05"); + + n.SetProperty(property, "myvalue"); + Assert.AreEqual(1, _counter, "X2"); + Assert.AreEqual(null, _lastPropertyChangedEventArgs.OldValue, "X2a"); + Assert.AreEqual("myvalue", _lastPropertyChangedEventArgs.NewValue, "X2b"); + Assert.IsTrue(n.IsPropertySet(property, false), "B01"); + Assert.IsTrue(n.IsPropertySet(property, true), "B02"); + Assert.IsFalse(n.IsPropertyDirty(property), "B03"); + Assert.AreEqual("myvalue", n.GetProperty(property, "nothing", false), "B04"); + Assert.AreEqual("myvalue", n.GetProperty(property, "nothing", true), "B05"); + + n.DirtyPropertyIfSet(property); + Assert.AreEqual(1, _counter, "X3"); + Assert.IsFalse(n.IsPropertySet(property, false), "C01"); + Assert.IsTrue(n.IsPropertySet(property, true), "C02"); + Assert.IsTrue(n.IsPropertyDirty(property), "C03"); + Assert.AreEqual("nothing", n.GetProperty(property, "nothing", false), "C04"); + Assert.AreEqual("myvalue", n.GetProperty(property, "nothing", true), "C05"); + + n.SetProperty(property, "newvalue"); + Assert.AreEqual(2, _counter, "X4"); + Assert.AreEqual("myvalue", _lastPropertyChangedEventArgs.OldValue, "X4a"); + Assert.AreEqual("newvalue", _lastPropertyChangedEventArgs.NewValue, "X4b"); + Assert.IsTrue(n.IsPropertySet(property, false), "D01"); + Assert.IsTrue(n.IsPropertySet(property, true), "D02"); + Assert.IsFalse(n.IsPropertyDirty(property), "D03"); + Assert.AreEqual("newvalue", n.GetProperty(property, "nothing", false), "D04"); + Assert.AreEqual("newvalue", n.GetProperty(property, "nothing", true), "D05"); + + n.ClearProperty(property); + Assert.AreEqual(3, _counter, "X5"); + Assert.AreEqual("newvalue", _lastPropertyChangedEventArgs.OldValue, "X5a"); + Assert.AreEqual(null, _lastPropertyChangedEventArgs.NewValue, "X5b"); + Assert.IsFalse(n.IsPropertySet(property, false), "E01"); + Assert.IsFalse(n.IsPropertySet(property, true), "E02"); + Assert.IsFalse(n.IsPropertyDirty(property), "E03"); + Assert.AreEqual("nothing", n.GetProperty(property, "nothing", false), "E04"); + Assert.AreEqual("nothing", n.GetProperty(property, "nothing", true), "E05"); + } + + [Test] + public void FlagAspectTest() + { + MathIdentifier flagId = new MathIdentifier("T1_FA", "FundamentTest"); + NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest)); + + NodeObject n = new NodeObject(); + _counter = 0; + n.AddHandler(flag.FlagChangedEvent, new EventHandler(OnFlagChanged)); + + Assert.AreEqual(0, _counter, "X1"); + Assert.IsFalse(n.IsFlagSet(flag, false), "A01"); + Assert.IsFalse(n.IsFlagSet(flag, true), "A02"); + Assert.IsFalse(n.IsFlagDirty(flag), "A03"); + Assert.IsFalse(n.IsFlagEnabled(flag, false), "A04"); + Assert.IsFalse(n.IsFlagEnabled(flag, true), "A05"); + Assert.IsFalse(n.IsFlagDisabled(flag, false), "A06"); + Assert.IsFalse(n.IsFlagDisabled(flag, true), "A07"); + Assert.IsTrue(n.IsFlagUnknown(flag), "A08"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A09"); + + n.EnableFlag(flag); + Assert.AreEqual(-1, _counter, "X2"); + Assert.AreEqual(FlagState.Unknown, _lastFlagChangedEventArgs.OldState, "X2a"); + Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.NewState, "X2b"); + Assert.IsTrue(n.IsFlagSet(flag, false), "B01"); + Assert.IsTrue(n.IsFlagSet(flag, true), "B02"); + Assert.IsFalse(n.IsFlagDirty(flag), "B03"); + Assert.IsTrue(n.IsFlagEnabled(flag, false), "B04"); + Assert.IsTrue(n.IsFlagEnabled(flag, true), "B05"); + Assert.IsFalse(n.IsFlagDisabled(flag, false), "B06"); + Assert.IsFalse(n.IsFlagDisabled(flag, true), "B07"); + Assert.IsFalse(n.IsFlagUnknown(flag), "B08"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B09"); + + n.DisableFlag(flag); + Assert.AreEqual(-2, _counter, "X3"); + Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.OldState, "X3a"); + Assert.AreEqual(FlagState.Disabled, _lastFlagChangedEventArgs.NewState, "X3b"); + Assert.IsTrue(n.IsFlagSet(flag, false), "C01"); + Assert.IsTrue(n.IsFlagSet(flag, true), "C02"); + Assert.IsFalse(n.IsFlagDirty(flag), "C03"); + Assert.IsFalse(n.IsFlagEnabled(flag, false), "C04"); + Assert.IsFalse(n.IsFlagEnabled(flag, true), "C05"); + Assert.IsTrue(n.IsFlagDisabled(flag, false), "C06"); + Assert.IsTrue(n.IsFlagDisabled(flag, true), "C07"); + Assert.IsFalse(n.IsFlagUnknown(flag), "C08"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "C09"); + + n.DirtyFlagIfSet(flag); + Assert.AreEqual(-2, _counter, "X4"); + Assert.IsFalse(n.IsFlagSet(flag, false), "D01"); + Assert.IsTrue(n.IsFlagSet(flag, true), "D02"); + Assert.IsTrue(n.IsFlagDirty(flag), "D03"); + Assert.IsFalse(n.IsFlagEnabled(flag, false), "D04"); + Assert.IsFalse(n.IsFlagEnabled(flag, true), "D05"); + Assert.IsFalse(n.IsFlagDisabled(flag, false), "D06"); + Assert.IsTrue(n.IsFlagDisabled(flag, true), "D07"); + Assert.IsFalse(n.IsFlagUnknown(flag), "D08"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "D09"); + + n.EnableFlag(flag); + Assert.AreEqual(-3, _counter, "X5"); + Assert.AreEqual(FlagState.Disabled, _lastFlagChangedEventArgs.OldState, "X5a"); + Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.NewState, "X5b"); + Assert.IsTrue(n.IsFlagSet(flag, false), "E01"); + Assert.IsTrue(n.IsFlagSet(flag, true), "E02"); + Assert.IsFalse(n.IsFlagDirty(flag), "E03"); + Assert.IsTrue(n.IsFlagEnabled(flag, false), "E04"); + Assert.IsTrue(n.IsFlagEnabled(flag, true), "E05"); + Assert.IsFalse(n.IsFlagDisabled(flag, false), "E06"); + Assert.IsFalse(n.IsFlagDisabled(flag, true), "E07"); + Assert.IsFalse(n.IsFlagUnknown(flag), "E08"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "E09"); + + n.ClearFlag(flag); + Assert.AreEqual(-4, _counter, "X6"); + Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.OldState, "X6a"); + Assert.AreEqual(FlagState.Unknown, _lastFlagChangedEventArgs.NewState, "X6b"); + Assert.IsFalse(n.IsFlagSet(flag, false), "F01"); + Assert.IsFalse(n.IsFlagSet(flag, true), "F02"); + Assert.IsFalse(n.IsFlagDirty(flag), "F03"); + Assert.IsFalse(n.IsFlagEnabled(flag, false), "F04"); + Assert.IsFalse(n.IsFlagEnabled(flag, true), "F05"); + Assert.IsFalse(n.IsFlagDisabled(flag, false), "F06"); + Assert.IsFalse(n.IsFlagDisabled(flag, true), "F07"); + Assert.IsTrue(n.IsFlagUnknown(flag), "F08"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "F09"); + } + + [Test] + public void PropertyTriggerTest() + { + MathIdentifier propertyId = new MathIdentifier("T2_PT", "FundamentTest"); + + NodeEvent clearEvent = NodeEvent.Register(propertyId.DerivePostfix("ClearTrigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent clear2Event = NodeEvent.Register(propertyId.DerivePostfix("Clear2Trigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent clear3Event = NodeEvent.Register(propertyId.DerivePostfix("Clear3Trigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent reevaluateEvent = NodeEvent.Register(propertyId.DerivePostfix("ReevaluateTrigger"), typeof(EventHandler), typeof(FundamentTest)); + + NodeProperty property = NodeProperty.Register(propertyId, typeof(string), typeof(FundamentTest), + new NodeEventTrigger(EventTriggerAction.Clear, clearEvent, clear2Event), + new NodeEventTrigger(EventTriggerAction.Clear, clear3Event), + new NodeEventTrigger(EventTriggerAction.Reevaluate, reevaluateEvent)); + + NodeObject n = new NodeObject(); + Assert.IsFalse(n.IsPropertySet(property), "A01"); + + n.SetProperty(property, "test"); + Assert.IsTrue(n.IsPropertySet(property), "B01"); + + n.RaiseEvent(clearEvent, EventArgs.Empty); + Assert.IsFalse(n.IsPropertySet(property), "C01"); + + n.SetProperty(property, "test2"); + Assert.IsTrue(n.IsPropertySet(property), "D01"); + Assert.AreEqual("test2", n.GetProperty(property), "D02"); + + n.RaiseEvent(reevaluateEvent, EventArgs.Empty); + Assert.IsTrue(n.IsPropertySet(property), "E01"); + Assert.AreEqual("test2", n.GetProperty(property), "E02"); + + n.RaiseEvent(clear2Event, EventArgs.Empty); + Assert.IsFalse(n.IsPropertySet(property), "F01"); + + n.SetProperty(property, "test3"); + Assert.IsTrue(n.IsPropertySet(property), "G01"); + + n.RaiseEvent(clear3Event, EventArgs.Empty); + Assert.IsFalse(n.IsPropertySet(property), "H01"); + } + + [Test] + public void FlagTriggerTest() + { + MathIdentifier flagId = new MathIdentifier("T3_FT", "FundamentTest"); + + NodeEvent clearEvent = NodeEvent.Register(flagId.DerivePostfix("ClearTrigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent enableEvent = NodeEvent.Register(flagId.DerivePostfix("EnableTrigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent disableEvent = NodeEvent.Register(flagId.DerivePostfix("DisableTrigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent disable2Event = NodeEvent.Register(flagId.DerivePostfix("Disable2Trigger"), typeof(EventHandler), typeof(FundamentTest)); + NodeEvent reevaluateEvent = NodeEvent.Register(flagId.DerivePostfix("ReevaluateTrigger"), typeof(EventHandler), typeof(FundamentTest)); + + NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest), FlagKind.Default, + new NodeEventTrigger(EventTriggerAction.Clear, clearEvent), + new NodeEventTrigger(EventTriggerAction.Enable, enableEvent), + new NodeEventTrigger(EventTriggerAction.Disable, disableEvent, disable2Event), + new NodeEventTrigger(EventTriggerAction.Reevaluate, reevaluateEvent)); + + NodeObject n = new NodeObject(); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A01"); + + n.EnableFlag(flag); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B01"); + + n.RaiseEvent(disableEvent, EventArgs.Empty); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "C01"); + + n.RaiseEvent(enableEvent, EventArgs.Empty); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "D01"); + + n.RaiseEvent(reevaluateEvent, EventArgs.Empty); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "E01"); + + n.RaiseEvent(disable2Event, EventArgs.Empty); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "F01"); + + n.RaiseEvent(clearEvent, EventArgs.Empty); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "G01"); + } + + [Test] + public void RemoteEventTriggersTest() + { + MathIdentifier flagId = new MathIdentifier("TX_F", "FundamentTest"); + + NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest)); + + NodeFlag flagEnableRemote = NodeFlag.Register(flagId.DerivePostfix("EnableRemote"), typeof(FundamentTest), FlagKind.Default, + new NodeEventTrigger(EventTriggerAction.Enable, flag, flag.FlagEnabledEvent)); + NodeFlag flagEnableLocal = NodeFlag.Register(flagId.DerivePostfix("EnableLocal"), typeof(FundamentTest), FlagKind.Default, + new NodeEventTrigger(EventTriggerAction.Enable, flag.FlagEnabledEvent)); + + NodeFlag flagDisableRemote = NodeFlag.Register(flagId.DerivePostfix("DisableRemote"), typeof(FundamentTest), FlagKind.Default, + new NodeEventTrigger(EventTriggerAction.Disable, flag, flag.FlagChangedEvent)); + NodeFlag flagDisableLocal = NodeFlag.Register(flagId.DerivePostfix("DisableLocal"), typeof(FundamentTest), FlagKind.Default, + new NodeEventTrigger(EventTriggerAction.Disable, flag.FlagChangedEvent)); + + NodeObject n = new NodeObject(); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A01"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableRemote), "A02"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableLocal), "A03"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableRemote), "A04"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableLocal), "A05"); + + n.EnableFlag(flag); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B01"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableRemote), "B02"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableLocal), "B03"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "B04"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableLocal), "B05"); + + n.ClearFlag(flag); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "C01"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableRemote), "C02"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableLocal), "C03"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "C04"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableLocal), "C05"); + + n.EnableFlag(flagDisableLocal); + n.DisableFlag(flagEnableLocal); + n.ClearFlag(flagDisableRemote); + n.ClearFlag(flagEnableRemote); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "D01"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableRemote), "D02"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagEnableLocal), "D03"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableRemote), "D04"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagDisableLocal), "D05"); + + n.DisableFlag(flag); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "E01"); + Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableRemote), "E02"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagEnableLocal), "E03"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "E04"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableLocal), "E05"); + + n.EnableFlag(flag); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "F01"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableRemote), "F02"); + Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableLocal), "F03"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "F04"); + Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableLocal), "F05"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/MicrokernelTest.cs b/Backup/src/test/MathNet.Yttrium.Test/MicrokernelTest.cs new file mode 100644 index 0000000..418ed69 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/MicrokernelTest.cs @@ -0,0 +1,167 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using NUnit.Framework; + +using System; +using System.Xml; +using System.Text; +using System.Collections.Generic; + +using MathNet.Numerics; +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Backend.Properties; + +using MathNet.Symbolics.Persistence; +using MathNet.Symbolics.Packages.Standard.Structures; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class MicrokernelTest + { + [Test] + public void SerializeSingleCustomData() + { + Project p = new Project(); + Dictionary emptyMappings = new Dictionary(); + Dictionary signals = new Dictionary(); + Dictionary buses = new Dictionary(); + + ComplexValue cv = new ComplexValue(Constants.Pi, Constants.E); + + string xml = Serializer.SerializeToString(cv, emptyMappings, emptyMappings); + + ComplexValue ret = Serializer.DeserializeFromString(xml, signals, buses); + + Assert.AreEqual(cv.TypeId, ret.TypeId, "B"); + Assert.AreEqual(cv.ToString(), ret.ToString(), "C"); + } + + [Test] + public void SerializeEmptyCustomDataList() + { + Project p = new Project(); + Dictionary emptyMappings = new Dictionary(); + Dictionary signals = new Dictionary(); + Dictionary buses = new Dictionary(); + + List values = new List(); + + string xml = Serializer.SerializeListToString(values, emptyMappings, emptyMappings, "Structures"); + + List ret = Serializer.DeserializeListFromString(xml, signals, buses, "Structures"); + + Assert.AreEqual(0, ret.Count, "A"); + } + + [Test] + public void SerializeFilledCustomDataList() + { + Project p = new Project(); + Dictionary emptyMappings = new Dictionary(); + Dictionary signals = new Dictionary(); + Dictionary buses = new Dictionary(); + + 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 values = new List(); + values.Add(lv); + values.Add(iv); + values.Add(cv); + values.Add(rv); + + string xml = Serializer.SerializeListToString(values, emptyMappings, emptyMappings, "Structures"); + + List ret = Serializer.DeserializeListFromString(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"); + } + + [Test] + 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(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(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(new MathIdentifier("Port", "Core"), ety); + Assert.IsNotNull(port, "C2"); + Assert.AreEqual("MathNet.Symbolics.Core.Port", port.GetType().FullName, "C3"); + } + + [Test] + public void MathContextStacking() + { + MathContext c1 = MathContext.Current; + Assert.IsNotNull(c1, "01"); + Assert.AreNotEqual(Guid.Empty, c1.InstanceId, "02"); + Guid id1 = c1.InstanceId; + Assert.AreEqual(id1, MathContext.Current.InstanceId, "03"); + Assert.AreEqual(false, c1.HasParent, "04"); + Assert.IsNull(c1.ParentContext, "05"); + + using(MathContext c2 = MathContext.Create()) + { + Assert.IsNotNull(c2, "06"); + Assert.AreNotEqual(Guid.Empty, c2.InstanceId, "07"); + Assert.AreNotEqual(c1.InstanceId, c2.InstanceId, "08"); + Assert.AreEqual(true, c2.HasParent, "09"); + Assert.AreEqual(c1.InstanceId, c2.ParentContext.InstanceId, "10"); + Assert.AreEqual(id1, c1.InstanceId, "11"); + Assert.AreEqual(c2.InstanceId, MathContext.Current.InstanceId, "12"); + } + + Assert.AreEqual(id1, MathContext.Current.InstanceId, "13"); + Assert.AreEqual(id1, c1.InstanceId, "14"); + + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/ParserTest.cs b/Backup/src/test/MathNet.Yttrium.Test/ParserTest.cs new file mode 100644 index 0000000..6bca1d6 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/ParserTest.cs @@ -0,0 +1,111 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Numerics; +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Interpreter; +using MathNet.Symbolics.Backend.Channels; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Library; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class ParserTest + { + [Test] + 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"); + } + + [Test] + public void Parser_StructuralExpressions() + { + Project p = new Project(); + ILibrary l = Service.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)); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/PatternTest.cs b/Backup/src/test/MathNet.Yttrium.Test/PatternTest.cs new file mode 100644 index 0000000..1554ff6 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/PatternTest.cs @@ -0,0 +1,234 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +//using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework; +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Numerics; +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Patterns; +using MathNet.Symbolics.Packages.Standard.Properties; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Patterns.Toolkit; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class PatternTest + { + [Test] + 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"); + } + + [Test] + 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"); + } + + [Test] + 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"); + } + + [Test] + 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 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"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/Properties/AssemblyInfo.cs b/Backup/src/test/MathNet.Yttrium.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7c16a5c --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,54 @@ +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Yttrium.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Luzern")] +[assembly: AssemblyProduct("Yttrium.Test")] +[assembly: AssemblyCopyright("Copyright © Luzern 2006")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3026d7f6-2bb1-4091-8294-f16556166c83")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/src/test/MathNet.Yttrium.Test/SchedulerTest.cs b/Backup/src/test/MathNet.Yttrium.Test/SchedulerTest.cs new file mode 100644 index 0000000..3d5a6f9 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/SchedulerTest.cs @@ -0,0 +1,149 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +//using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework; +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard; + +namespace Yttrium.UnitTests +{ + //[TestClass] + [TestFixture] + public class SchedulerTest + { + private Project project; + + //[TestInitialize] + [SetUp] + public void Initialize() + { + this.project = new Project(); + } + + //[TestCleanup] + public void Cleanup() + { + this.project = null; + } + + //[TestMethod] + [Test] + public void Scheduler_SignalTransportTest() + { + Signal a = Binder.CreateSignal(); + Assert.IsNull(a.Value); + + a.PostNewValue(new IntegerValue(1)); + Assert.IsNull(a.Value); + + Assert.AreEqual(TimeSpan.Zero, project.SimulateFor(100)); + Assert.IsInstanceOfType(typeof(IntegerValue), a.Value); + Assert.AreEqual(1, ((IntegerValue)a.Value).Value); + + a.PostNewValue(new IntegerValue(2),new TimeSpan(0,1,0)); + Assert.AreEqual(1, ((IntegerValue)a.Value).Value); + Assert.AreEqual(new TimeSpan(0, 1, 0), project.SimulateFor(new TimeSpan(0, 0, 30))); + Assert.AreEqual(2, ((IntegerValue)a.Value).Value); + } + + //[TestMethod] + [Test] + public void Scheduler_PortTransportTest() + { + Signal a = Binder.CreateSignal(); + Signal b = Binder.CreateSignal(); + Signal c = StdBuilder.Divide(a, b); + + Signal d = Binder.CreateSignal(); + Signal e = Binder.CreateSignal(); + Signal f = Service.Instance.Function("xor", d, e); + + a.PostNewValue(new RationalValue(1,1)); + b.PostNewValue(new IntegerValue(2)); + d.PostNewValue(LogicValue.True); + e.PostNewValue(LogicValue.False); + + Assert.IsNull(a.Value); + Assert.IsNull(b.Value); + Assert.IsNull(c.Value); + Assert.IsNull(d.Value); + Assert.IsNull(e.Value); + Assert.IsNull(f.Value); + + Assert.AreEqual(TimeSpan.Zero, project.SimulateFor(1)); + Assert.IsNotNull(a.Value); + Assert.IsNotNull(b.Value); + Assert.IsNull(c.Value); + Assert.IsNotNull(d.Value); + Assert.IsNotNull(e.Value); + Assert.IsNull(f.Value); + + Assert.AreEqual(TimeSpan.Zero, project.SimulateFor(1)); + Assert.IsNotNull(c.Value); + Assert.IsInstanceOfType(typeof(RationalValue), c.Value); + Assert.IsNotNull(f.Value); + Assert.IsInstanceOfType(typeof(LogicValue), f.Value); + + Assert.AreEqual(1, ((RationalValue)c.Value).NumeratorValue); + Assert.AreEqual(2, ((RationalValue)c.Value).DenominatorValue); + Assert.AreEqual(ELogicX01.True, ((LogicValue)f.Value).Value); + + a.PostNewValue(new IntegerValue(3), new TimeSpan(0, 1, 0)); + Assert.AreEqual(1, ((RationalValue)c.Value).NumeratorValue); + Assert.AreEqual(2, ((RationalValue)c.Value).DenominatorValue); + Assert.AreEqual(new TimeSpan(0, 1, 0), project.SimulateFor(new TimeSpan(0, 2, 0))); + Assert.IsInstanceOfType(typeof(RationalValue), c.Value); + Assert.AreEqual(3, ((RationalValue)c.Value).NumeratorValue); + Assert.AreEqual(2, ((RationalValue)c.Value).DenominatorValue); + } + + //[TestMethod] + [Test] + public void Scheduler_DelayedSchedulerTest() + { + Signal a = Binder.CreateSignal(); + Signal b = Binder.CreateSignal(); + Signal c = a * b; + + a.PostNewValue(new IntegerValue(5)); + + for(int i=1;i<=1000;i++) + b.PostNewValue(new IntegerValue(i),new TimeSpan(0,0,i)); + + Assert.AreEqual(new TimeSpan(0, 1, 0), project.SimulateFor(new TimeSpan(0, 1, 0))); + Assert.AreEqual(300, ((IntegerValue)c.Value).Value); + + Assert.AreEqual(new TimeSpan(0, 0, 40), project.SimulateFor(new TimeSpan(0, 0, 40))); + Assert.AreEqual(500, ((IntegerValue)c.Value).Value); + + Assert.AreEqual(new TimeSpan(0, 15, 0), project.SimulateFor(new TimeSpan(0, 0, 900))); + Assert.AreEqual(5000, ((IntegerValue)c.Value).Value); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/StdPolynomialTest.cs b/Backup/src/test/MathNet.Yttrium.Test/StdPolynomialTest.cs new file mode 100644 index 0000000..76dd215 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/StdPolynomialTest.cs @@ -0,0 +1,163 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Formatter; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class StdPolynomialTest + { + private Project project; + + [SetUp] + public void Initialize() + { + this.project = new Project(); + } + + [TearDown] + public void Cleanup() + { + this.project = null; + } + + [Test] + public void StdPolynomial_SingleVariable() + { + Signal x = Binder.CreateSignal(); + + Signal a0 = IntegerValue.ConstantZero; + Signal a1 = IntegerValue.ConstantOne; + Signal a2 = RationalValue.ConstantHalf; + Signal a3 = IntegerValue.Constant(2); + Signal a4 = IntegerValue.Constant(3); + + Signal badX = StdBuilder.Sine(x); + Signal badA2 = StdBuilder.Tangent(a2); + Signal badA3 = RealValue.ConstantPI; + + Signal x2 = StdBuilder.Power(x, a3); + Signal x3 = StdBuilder.Power(x, a4); + + Signal a3x3 = a3 * x3; + Signal a2x2 = a2 * x2; + + Assert.IsTrue(Polynomial.IsMonomial(x, x), "x: is SVM(x)"); + Assert.IsTrue(Polynomial.IsMonomial(a0, x), "0: is SVM(x)"); + Assert.IsTrue(Polynomial.IsMonomial(a2, x), "1/2: is SVM(x)"); + Assert.IsFalse(Polynomial.IsMonomial(badX, x), "sin(x): is not SVM(x)"); + Assert.IsFalse(Polynomial.IsMonomial(badA2, x), "tan(1/2): is not SVM(x)"); + Assert.IsFalse(Polynomial.IsMonomial(badA3, x), "pi is not SVM(x)"); + Assert.IsTrue(Polynomial.IsMonomial(x3, x), "x^3: is SVM(x)"); + Assert.IsTrue(Polynomial.IsMonomial(a2x2, x), "1/2*x^2: is SVM(x)"); + + Assert.AreEqual("Std.Integer(1)", Polynomial.MonomialDegree(x, x).ToString(), "x: SVM deg(x)=1"); + Assert.AreEqual("Std.Integer(0)", Polynomial.MonomialDegree(a2, x).ToString(), "1/2: SVM deg(x)=0"); + Assert.AreEqual("Std.NegativeInfinity", Polynomial.MonomialDegree(a0, x).ToString(), "0: SVM deg(x)=-inf"); + Assert.AreEqual("Std.Integer(3)", Polynomial.MonomialDegree(x3, x).ToString(), "x^3: SVM deg(x)=3"); + Assert.AreEqual("Std.Integer(2)", Polynomial.MonomialDegree(a2x2, x).ToString(), "1/2*x^2: SVM deg(x)=2"); + + IValueStructure vs; + Signal test = Polynomial.MonomialCoefficient(x, x, out vs); + Assert.AreEqual("Std.Integer(1)", vs.ToString(), "x: SVM coeff deg=1 "); + Assert.IsTrue(test.Value.Equals(a1.Value), "x: SVM coeff = 1"); + + test = Polynomial.MonomialCoefficient(a2, x, out vs); + Assert.AreEqual("Std.Integer(0)", vs.ToString(), "1/2: SVM coeff deg=0 "); + Assert.IsTrue(test.Value.Equals(a2.Value), "1/2: SVM coeff = 1/2"); + + test = Polynomial.MonomialCoefficient(a3x3, x, out vs); + Assert.AreEqual("Std.Integer(3)", vs.ToString(), "2*x^3: SVM coeff deg=3 "); + Assert.IsTrue(test.Value.Equals(a3.Value), "2*x^3: SVM coeff = 2"); + + Signal a3x3_a2x2_a4 = StdBuilder.Add(a3x3, a2x2, a4); + + Assert.IsFalse(Polynomial.IsMonomial(a3x3_a2x2_a4, x), "2*x^3+1/2*x^2+3: is not SVM(x)"); + Assert.IsTrue(Polynomial.IsPolynomial(a3x3_a2x2_a4, x), "2*x^3+1/2*x^2+3: is SVP(x)"); + Assert.AreEqual("Std.Integer(3)", Polynomial.PolynomialDegree(a3x3_a2x2_a4, x).ToString(), "2*x^3+1/2*x^2+3: SVP deg(x)=3"); + + test = Polynomial.PolynomialCoefficient(a3x3_a2x2_a4, x, 1); + Assert.IsTrue(test.Value.Equals(a0.Value), "2*x^3+1/2*x^2+3: SVP coeff(1) = 0"); + + test = Polynomial.PolynomialCoefficient(a3x3_a2x2_a4, x, 2); + Assert.IsTrue(test.Value.Equals(a2.Value), "2*x^3+1/2*x^2+3: SVP coeff(2) = 1/2"); + + Signal[] coefficients = Polynomial.PolynomialCoefficients(a3x3_a2x2_a4, x); + Assert.AreEqual(4, coefficients.Length, "2*x^3+1/2*x^2+3: SVP coeffs: len(coeffs) = 4 (-> deg=3)"); + Assert.IsTrue(coefficients[0].Value.Equals(a4.Value), "2*x^3+1/2*x^2+3: SVP coeffs: coeffs[0] = 3"); + Assert.IsTrue(coefficients[1].Value.Equals(a0.Value), "2*x^3+1/2*x^2+3: SVP coeffs: coeffs[1] = 0"); + Assert.IsTrue(coefficients[2].Value.Equals(a2.Value), "2*x^3+1/2*x^2+3: SVP coeffs: coeffs[2] = 1/2"); + Assert.IsTrue(coefficients[3].Value.Equals(a3.Value), "2*x^3+1/2*x^2+3: SVP coeffs: coeffs[3] = 2"); + } + + [Test] + public void PolynomialDivisionTest() + { + Signal x = Binder.CreateSignal(); + x.Label = "x"; + + Signal c0 = IntegerValue.ConstantZero; + Signal c1 = IntegerValue.ConstantOne; + Signal c3 = IntegerValue.Constant(3); + Signal c3n = IntegerValue.Constant(-3); + Signal c5 = IntegerValue.Constant(5); + + Signal a = Polynomial.ConstructPolynomial(x, c5, c1, c1, c3); + Signal b = Polynomial.ConstructPolynomial(x, c1, c3n, c5); + Assert.AreEqual("5+x+x^2+3*x^3", Service.Instance.Format(a, FormattingOptions.Compact), "X01"); + Assert.AreEqual("1+-3*x+5*x^2", Service.Instance.Format(b, FormattingOptions.Compact), "X02"); + + Assert.AreEqual(c5.Value, Polynomial.PolynomialCoefficient(a, x, 0).Value, "A01"); + Assert.AreEqual(c1.Value, Polynomial.PolynomialCoefficient(a, x, 1).Value, "A02"); + Assert.AreEqual(c1.Value, Polynomial.PolynomialCoefficient(a, x, 2).Value, "A03"); + Assert.AreEqual(c3.Value, Polynomial.PolynomialCoefficient(a, x, 3).Value, "A04"); + Assert.AreEqual(c1.Value, Polynomial.PolynomialCoefficient(b, x, 0).Value, "A05"); + Assert.AreEqual(c3n.Value, Polynomial.PolynomialCoefficient(b, x, 1).Value, "A06"); + Assert.AreEqual(c5.Value, Polynomial.PolynomialCoefficient(b, x, 2).Value, "A07"); + + Signal remainder; + Signal quotient = Polynomial.PolynomialDivision(a, b, x, out remainder); + + Signal[] quotientCoeff = Polynomial.PolynomialCoefficients(quotient, x); + Assert.AreEqual(2, quotientCoeff.Length, "B01"); + Assert.AreEqual(new RationalValue(14, 25), quotientCoeff[0].Value, "B02"); + Assert.AreEqual(new RationalValue(3, 5), quotientCoeff[1].Value, "B03"); + Assert.AreEqual("14/25+(3/5)*x", Service.Instance.Format(quotient, FormattingOptions.Compact), "B04"); + + Signal[] remainderCoeff = Polynomial.PolynomialCoefficients(remainder, x); + Assert.AreEqual(2, remainderCoeff.Length, "C01"); + Assert.AreEqual(new RationalValue(111, 25), remainderCoeff[0].Value, "C02"); + Assert.AreEqual(new RationalValue(52, 25), remainderCoeff[1].Value, "C03"); + Assert.AreEqual("111/25+(52/25)*x", Service.Instance.Format(remainder, FormattingOptions.Compact), "C04"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/StdVariousTest.cs b/Backup/src/test/MathNet.Yttrium.Test/StdVariousTest.cs new file mode 100644 index 0000000..eff63e1 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/StdVariousTest.cs @@ -0,0 +1,86 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using NUnit.Framework; + +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Packages.Standard.Structures; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class StdVariousTest + { + private Project _project; + + [SetUp] + public void Initialize() + { + _project = new Project(); + } + + [TearDown] + public void Cleanup() + { + _project = null; + } + + [Test] + public void ConstraintsTest() + { + Signal signal = IntegerValue.ConstantOne; + Assert.IsTrue(Std.IsConstant(signal), "A01"); + Assert.IsTrue(Std.IsAlwaysInteger(signal), "A02"); + Assert.IsTrue(Std.IsAlwaysRational(signal), "A03"); + Assert.IsTrue(Std.IsAlwaysReal(signal), "A04"); + Assert.IsTrue(Std.IsAlwaysPositive(signal), "A05"); + Assert.IsTrue(Std.IsAlwaysNonnegative(signal), "A06"); + Assert.IsTrue(Std.IsAlwaysPositiveInteger(signal), "A07"); + Assert.IsTrue(Std.IsAlwaysNonnegativeInteger(signal), "A08"); + + signal = IntegerValue.ConstantZero; + Assert.IsTrue(Std.IsConstant(signal), "B01"); + Assert.IsTrue(Std.IsAlwaysInteger(signal), "B02"); + Assert.IsTrue(Std.IsAlwaysRational(signal), "B03"); + Assert.IsTrue(Std.IsAlwaysReal(signal), "B04"); + Assert.IsFalse(Std.IsAlwaysPositive(signal), "B05"); + Assert.IsTrue(Std.IsAlwaysNonnegative(signal), "B06"); + Assert.IsFalse(Std.IsAlwaysPositiveInteger(signal), "B07"); + Assert.IsTrue(Std.IsAlwaysNonnegativeInteger(signal), "B08"); + + signal = IntegerValue.ConstantMinusOne; + Assert.IsTrue(Std.IsConstant(signal), "C01"); + Assert.IsTrue(Std.IsAlwaysInteger(signal), "C02"); + Assert.IsTrue(Std.IsAlwaysRational(signal), "C03"); + Assert.IsTrue(Std.IsAlwaysReal(signal), "C04"); + Assert.IsFalse(Std.IsAlwaysPositive(signal), "C05"); + Assert.IsFalse(Std.IsAlwaysNonnegative(signal), "C06"); + Assert.IsFalse(Std.IsAlwaysPositiveInteger(signal), "C07"); + Assert.IsFalse(Std.IsAlwaysNonnegativeInteger(signal), "C08"); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/SystemBuilderTest.cs b/Backup/src/test/MathNet.Yttrium.Test/SystemBuilderTest.cs new file mode 100644 index 0000000..fab4f26 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/SystemBuilderTest.cs @@ -0,0 +1,199 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +using NUnit.Framework; + +using System; +using System.Text; +using System.Xml; +using System.IO; +using System.Collections.Generic; + +using MathNet.Numerics; +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Packages.Standard.Properties; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.SystemBuilder.Toolkit; + +namespace Yttrium.UnitTests +{ + [TestFixture] + public class SystemBuilderTest + { + [Test] + 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"); + } + + [Test] + 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 + } + + [Test] + 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); + + // .... + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/UseCasesBasicTest.cs b/Backup/src/test/MathNet.Yttrium.Test/UseCasesBasicTest.cs new file mode 100644 index 0000000..14409bc --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/UseCasesBasicTest.cs @@ -0,0 +1,166 @@ +#region Math.NET Yttrium (GPL) by Christoph Ruegg +// Math.NET Yttrium, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2001-2007, Christoph Rüegg, http://christoph.ruegg.name +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#endregion + +//using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework; +using NUnit.Framework; + +using System; +using System.Collections.Generic; + +using MathNet.Numerics; +using MathNet.Symbolics; +using MathNet.Symbolics.Workplace; +using MathNet.Symbolics.Backend; +using MathNet.Symbolics.Packages.Standard; +using MathNet.Symbolics.Packages.Standard.Properties; +using MathNet.Symbolics.Packages.Standard.Structures; +using MathNet.Symbolics.Formatter; + +namespace Yttrium.UnitTests +{ + //[TestClass] + [TestFixture] + public class UseCasesBasicTest + { + private Project _p; + private IFormatter _f; + + [SetUp] + public void Initialize() + { + _p = new Project(); + _f = Service.Instance; + } + + [TearDown] + public void Cleanup() + { + _p = null; + _f = null; + } + + //[TestMethod] + [Test] + public void UseCase_SimpleSystemAsFunction() + { + // TODO: Replace with new (easier to use) MathFunction class instead of MathSystem + + _p.KeepTrack = true; + MathSystem s = _p.CurrentSystem; + s.RemoveUnusedObjects(); + + Signal x = Binder.CreateSignal(); + Std.ConstrainAlwaysReal(x); + Signal x2 = StdBuilder.Square(x); + Signal sinx2 = StdBuilder.Sine(x2); + + Assert.AreEqual(0, s.InputCount, "Input Signal Count A"); + Assert.AreEqual(0, s.OutputCount, "Output Signal Count A"); + Assert.AreEqual(0, s.BusCount, "Bus Count A"); + Assert.AreEqual(3, s.SignalCount, "Signal Count A"); + Assert.AreEqual(2, s.PortCount, "Port Count A"); + + s.PromoteAsInput(x); + s.PromoteAsOutput(sinx2); + s.RemoveUnusedObjects(); + + Assert.AreEqual(1, s.InputCount, "Input Signal Count B"); + Assert.AreEqual(1, s.OutputCount, "Output Signal Count B"); + Assert.AreEqual(0, s.BusCount, "Bus Count B"); + Assert.AreEqual(3, s.SignalCount, "Signal Count B"); + Assert.AreEqual(2, s.PortCount, "Port Count B"); + + double ret = Math.Round(s.Evaluate(Math.PI)[0],4); + + Assert.AreEqual(-0.4303, ret, "Result"); + } + + //[TestMethod] + [Test] + public void UseCase_ComplexDerivedSystemAsFunction() + { + // TODO: Replace with new (easier to use) MathFunction class instead of MathSystem + + _p.KeepTrack = false; + MathSystem s = _p.CurrentSystem; + + Signal x = Binder.CreateSignal(); x.Label = "x"; + Signal x2 = StdBuilder.Square(x); x2.Label = "x2"; + Signal secx2 = StdBuilder.Secant(x2); secx2.Label = "secx2"; + Signal diff = Std.Derive(secx2, x); diff.Label = "diff1"; + s.AddSignalTree(diff, true, true); + s.RemoveUnusedObjects(); + + Assert.AreEqual("2*sec(sqr(x))*tan(sqr(x))*x", _f.Format(diff, FormattingOptions.Compact), "Formatted Diff A"); + Assert.AreEqual(1, s.InputCount, "Input Signal Count A"); + Assert.AreEqual(1, s.OutputCount, "Output Signal Count A"); + Assert.AreEqual(0, s.BusCount, "Bus Count A"); + Assert.AreEqual(6, s.SignalCount, "Signal Count A"); + Assert.AreEqual(4, s.PortCount, "Port Count A"); + + Signal diff2 = Std.AutoSimplify(diff); + s.UnpromoteAsOutput(diff); + s.AddSignalTree(diff2, true, true); + s.RemoveUnusedObjects(); + + Assert.AreEqual("2*sec(sqr(x))*tan(sqr(x))*x", _f.Format(diff2, FormattingOptions.Compact), "Formatted Diff B"); + Assert.AreEqual(1, s.InputCount, "Input Signal Count B"); + Assert.AreEqual(1, s.OutputCount, "Output Signal Count B"); + Assert.AreEqual(0, s.BusCount, "Bus Count B"); + Assert.AreEqual(6, s.SignalCount, "Signal Count B"); + Assert.AreEqual(4, s.PortCount, "Port Count B"); + + IValueStructure vs = s.Evaluate(ComplexValue.I)[0]; + Assert.IsInstanceOfType(typeof(ComplexValue), vs, "Result is complex."); + ComplexValue cv = (ComplexValue)vs; + + Assert.AreEqual(0, Math.Round(cv.RealValue, 4), "Real Result"); + Assert.AreEqual(-5.7649, Math.Round(cv.ImaginaryValue, 4), "Imag Result"); + } + + //[TestMethod] + [Test] + public void UseCase_SystemAsCompoundArchitecture() + { + _p.KeepTrack = false; + MathSystem s = _p.CurrentSystem; + s.RemoveUnusedObjects(); + + Signal x = Binder.CreateSignal(); + Std.ConstrainAlwaysReal(x); + Signal x2 = StdBuilder.Square(x); + Signal sinx2 = StdBuilder.Sine(x2); + + s.AddSignalTree(sinx2, true, true); + s.RemoveUnusedObjects(); + + s.PublishToLibrary("SineOfSquaredX", "sinx2"); + + Signal y = Binder.CreateSignal(); + y.PostNewValue(RealValue.E); + Signal z = Service.Instance.Function("sinx2", y); + _p.SimulateInstant(); //.SimulateFor(new TimeSpan(1)); + IValueStructure res = z.Value; + RealValue resReal = RealValue.ConvertFrom(res); + Assert.AreEqual(0.8939, Math.Round(resReal.Value, 4)); + } + } +} diff --git a/Backup/src/test/MathNet.Yttrium.Test/Yttrium.Test.csproj b/Backup/src/test/MathNet.Yttrium.Test/Yttrium.Test.csproj new file mode 100644 index 0000000..f474842 --- /dev/null +++ b/Backup/src/test/MathNet.Yttrium.Test/Yttrium.Test.csproj @@ -0,0 +1,143 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB} + Library + Properties + Yttrium.UnitTests + Yttrium.Test + + + true + full + false + ..\..\..\build\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + ..\..\..\build\Release\ + TRACE + prompt + 4 + true + + + + False + ..\..\..\build\Release\MathNet.Iridium.dll + + + False + ..\..\..\lib\nunit\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + + + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F} + Yttrium.Contracts + + + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9} + Yttrium.Conversion.Contracts + + + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351} + Yttrium.Conversion.Toolkit + + + {92C1E300-20D2-4195-AB4C-1402A9152E25} + Yttrium.Formatter.Contracts + + + {FDD51A32-1C78-4135-A6E8-222B022A01C6} + Yttrium.Fundament + + + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6} + Yttrium.Interpreter.Contracts + + + {70E79678-387A-4AF6-8F64-4271CFE914BE} + Yttrium.Library.Contracts + + + {CAB86B17-68FA-4081-B687-DB71B74BAF79} + Yttrium + + + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C} + Yttrium.Manipulation.Contracts + + + {E623ED40-9B92-40CA-9080-0FC78F668FFE} + Yttrium.Mediator.Contracts + + + {D03B156A-D6F3-4F46-AC59-7156681F69B7} + Yttrium.Microkernel + + + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} + Yttrium.Packages.Helper + + + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} + Yttrium.Packages.Standard + + + {6AAA89AE-90D5-496B-9EBD-5274C662C147} + Yttrium.Patterns.Toolkit + + + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257} + Yttrium.Repository.Contracts + + + {CFE74A4D-51A2-432C-966A-E29773C55D45} + Yttrium.Simulation.Contracts + + + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3} + Yttrium.SystemBuilder.Toolkit + + + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8} + Yttrium.Traversing.Contracts + + + + + \ No newline at end of file diff --git a/UpgradeLog.XML b/UpgradeLog.XML new file mode 100644 index 0000000..33123be --- /dev/null +++ b/UpgradeLog.XML @@ -0,0 +1,587 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Yttrium.sln b/Yttrium.sln index 2e0b591..cdcf6cc 100644 --- a/Yttrium.sln +++ b/Yttrium.sln @@ -1,335 +1,330 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium", "src\app\MathNet.Yttrium\Library\Yttrium.csproj", "{CAB86B17-68FA-4081-B687-DB71B74BAF79}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Test", "src\test\MathNet.Yttrium.Test\Yttrium.Test.csproj", "{C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Contracts", "src\app\MathNet.Yttrium\Contracts\Yttrium.Contracts.csproj", "{8966E2C5-B1C9-44BE-8751-45DCCA3D268F}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Microkernel", "src\app\MathNet.Yttrium\Microkernel\Yttrium.Microkernel.csproj", "{D03B156A-D6F3-4F46-AC59-7156681F69B7}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Interpreter.Contracts", "src\app\MathNet.Yttrium\Interpreter.Contracts\Yttrium.Interpreter.Contracts.csproj", "{3A0BF5B0-653C-40BD-8046-ED614D95D3D6}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.Standard", "src\app\MathNet.Yttrium\Packages.Standard\Yttrium.Packages.Standard.csproj", "{7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Contracts", "src\app\MathNet.Yttrium\Conversion.Contracts\Yttrium.Conversion.Contracts.csproj", "{FACEF94F-CB8B-45FA-8664-3B9F043C27E9}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.Helper", "src\app\MathNet.Yttrium\Packages.Helper\Yttrium.Packages.Helper.csproj", "{F1B95DE1-5170-4C65-92A4-CFE69256D6E1}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Library.Contracts", "src\app\MathNet.Yttrium\Library.Contracts\Yttrium.Library.Contracts.csproj", "{70E79678-387A-4AF6-8F64-4271CFE914BE}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Traversing.Contracts", "src\app\MathNet.Yttrium\Traversing.Contracts\Yttrium.Traversing.Contracts.csproj", "{191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Manipulation.Contracts", "src\app\MathNet.Yttrium\Manipulation.Contracts\Yttrium.Manipulation.Contracts.csproj", "{B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Patterns.Toolkit", "src\app\MathNet.Yttrium\Patterns.Toolkit\Yttrium.Patterns.Toolkit.csproj", "{6AAA89AE-90D5-496B-9EBD-5274C662C147}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.SystemBuilder.Toolkit", "src\app\MathNet.Yttrium\SystemBuilder.Toolkit\Yttrium.SystemBuilder.Toolkit.csproj", "{8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Manipulation.Service", "src\app\MathNet.Yttrium\Manipulation.Service\Yttrium.Manipulation.Service.csproj", "{4927027C-5A8B-41ED-B680-84C656A98031}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Traversing.Service", "src\app\MathNet.Yttrium\Traversing.Service\Yttrium.Traversing.Service.csproj", "{90E6DB8F-7BFD-4DB3-B705-468769B718E8}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Library.Service", "src\app\MathNet.Yttrium\Library.Service\Yttrium.Library.Service.csproj", "{C1280263-2D0B-4D42-909D-B750FB52D873}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Builder.Service", "src\app\MathNet.Yttrium\Builder.Service\Yttrium.Builder.Service.csproj", "{55E44945-2BB3-4BDB-8E2D-934C334D73ED}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Service", "src\app\MathNet.Yttrium\Conversion.Service\Yttrium.Conversion.Service.csproj", "{3B927CA1-FD05-4DC0-A065-A45B2B2730EC}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Interpreter.Service", "src\app\MathNet.Yttrium\Interpreter.Service\Yttrium.Interpreter.Service.csproj", "{66210C43-A4BD-4B01-A862-BC5EE789CC6E}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Repository.Contracts", "src\app\MathNet.Yttrium\Repository.Contracts\Yttrium.Repository.Contracts.csproj", "{FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Repository.Service", "src\app\MathNet.Yttrium\Repository.Service\Yttrium.Repository.Service.csproj", "{36E41B54-4992-40AF-ABF9-5F0EE34B8B32}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Toolkit", "src\app\MathNet.Yttrium\Conversion.Toolkit\Yttrium.Conversion.Toolkit.csproj", "{8CD3403D-22BF-4BBD-9F8E-36F0F0201351}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Simulation.Contracts", "src\app\MathNet.Yttrium\Simulation.Contracts\Yttrium.Simulation.Contracts.csproj", "{CFE74A4D-51A2-432C-966A-E29773C55D45}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Simulation.Service", "src\app\MathNet.Yttrium\Simulation.Service\Yttrium.Simulation.Service.csproj", "{A214B5AE-5823-4E97-9809-39CB5FC1C1F2}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Contracts", "src\app\MathNet.Yttrium\Mediator.Contracts\Yttrium.Mediator.Contracts.csproj", "{E623ED40-9B92-40CA-9080-0FC78F668FFE}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Service", "src\app\MathNet.Yttrium\Mediator.Service\Yttrium.Mediator.Service.csproj", "{5ADA1A0C-25A8-4B09-8956-AF0C94575D22}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.PetriNet", "src\app\MathNet.Yttrium\Packages\Yttrium.Packages.PetriNet\Yttrium.Packages.PetriNet.csproj", "{5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Toolkit", "src\app\MathNet.Yttrium\Mediator.Toolkit\Yttrium.Mediator.Toolkit.csproj", "{334D8A1D-1004-4097-ACEE-8B954F911EB2}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Fundament", "src\app\MathNet.Yttrium\Fundament\Yttrium.Fundament.csproj", "{FDD51A32-1C78-4135-A6E8-222B022A01C6}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Formatter.Contracts", "src\app\MathNet.Yttrium\Formatter.Contracts\Yttrium.Formatter.Contracts.csproj", "{92C1E300-20D2-4195-AB4C-1402A9152E25}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Formatter.Service", "src\app\MathNet.Yttrium\Formatter.Service\Yttrium.Formatter.Service.csproj", "{36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}" - ProjectSection(WebsiteProperties) = preProject - Debug.AspNetCompiler.Debug = "True" - Release.AspNetCompiler.Debug = "False" - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Release|Any CPU.Build.0 = Release|Any CPU - {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Release|Any CPU.Build.0 = Release|Any CPU - {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Release|Any CPU.Build.0 = Release|Any CPU - {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Release|Any CPU.Build.0 = Release|Any CPU - {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Release|Any CPU.Build.0 = Release|Any CPU - {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Release|Any CPU.Build.0 = Release|Any CPU - {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Release|Any CPU.Build.0 = Release|Any CPU - {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Release|Any CPU.Build.0 = Release|Any CPU - {70E79678-387A-4AF6-8F64-4271CFE914BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {70E79678-387A-4AF6-8F64-4271CFE914BE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {70E79678-387A-4AF6-8F64-4271CFE914BE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {70E79678-387A-4AF6-8F64-4271CFE914BE}.Release|Any CPU.Build.0 = Release|Any CPU - {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Release|Any CPU.Build.0 = Release|Any CPU - {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Release|Any CPU.Build.0 = Release|Any CPU - {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Release|Any CPU.Build.0 = Release|Any CPU - {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Release|Any CPU.Build.0 = Release|Any CPU - {4927027C-5A8B-41ED-B680-84C656A98031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4927027C-5A8B-41ED-B680-84C656A98031}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4927027C-5A8B-41ED-B680-84C656A98031}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4927027C-5A8B-41ED-B680-84C656A98031}.Release|Any CPU.Build.0 = Release|Any CPU - {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Release|Any CPU.Build.0 = Release|Any CPU - {C1280263-2D0B-4D42-909D-B750FB52D873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C1280263-2D0B-4D42-909D-B750FB52D873}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C1280263-2D0B-4D42-909D-B750FB52D873}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C1280263-2D0B-4D42-909D-B750FB52D873}.Release|Any CPU.Build.0 = Release|Any CPU - {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Debug|Any CPU.Build.0 = Debug|Any CPU - {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Release|Any CPU.ActiveCfg = Release|Any CPU - {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Release|Any CPU.Build.0 = Release|Any CPU - {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Release|Any CPU.Build.0 = Release|Any CPU - {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Release|Any CPU.Build.0 = Release|Any CPU - {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Release|Any CPU.Build.0 = Release|Any CPU - {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Debug|Any CPU.Build.0 = Debug|Any CPU - {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Release|Any CPU.ActiveCfg = Release|Any CPU - {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Release|Any CPU.Build.0 = Release|Any CPU - {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Release|Any CPU.Build.0 = Release|Any CPU - {CFE74A4D-51A2-432C-966A-E29773C55D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CFE74A4D-51A2-432C-966A-E29773C55D45}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CFE74A4D-51A2-432C-966A-E29773C55D45}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CFE74A4D-51A2-432C-966A-E29773C55D45}.Release|Any CPU.Build.0 = Release|Any CPU - {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Release|Any CPU.Build.0 = Release|Any CPU - {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Release|Any CPU.Build.0 = Release|Any CPU - {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Release|Any CPU.Build.0 = Release|Any CPU - {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Release|Any CPU.Build.0 = Release|Any CPU - {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Release|Any CPU.Build.0 = Release|Any CPU - {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Release|Any CPU.Build.0 = Release|Any CPU - {92C1E300-20D2-4195-AB4C-1402A9152E25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {92C1E300-20D2-4195-AB4C-1402A9152E25}.Debug|Any CPU.Build.0 = Debug|Any CPU - {92C1E300-20D2-4195-AB4C-1402A9152E25}.Release|Any CPU.ActiveCfg = Release|Any CPU - {92C1E300-20D2-4195-AB4C-1402A9152E25}.Release|Any CPU.Build.0 = Release|Any CPU - {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {F1B95DE1-5170-4C65-92A4-CFE69256D6E1} = {F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D} - {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A} = {F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D} - {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD} = {F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{F75A5EAF-5C00-4F8C-AA9D-0745AA7E210D}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium", "src\app\MathNet.Yttrium\Library\Yttrium.csproj", "{CAB86B17-68FA-4081-B687-DB71B74BAF79}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Test", "src\test\MathNet.Yttrium.Test\Yttrium.Test.csproj", "{C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Contracts", "src\app\MathNet.Yttrium\Contracts\Yttrium.Contracts.csproj", "{8966E2C5-B1C9-44BE-8751-45DCCA3D268F}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Microkernel", "src\app\MathNet.Yttrium\Microkernel\Yttrium.Microkernel.csproj", "{D03B156A-D6F3-4F46-AC59-7156681F69B7}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Interpreter.Contracts", "src\app\MathNet.Yttrium\Interpreter.Contracts\Yttrium.Interpreter.Contracts.csproj", "{3A0BF5B0-653C-40BD-8046-ED614D95D3D6}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.Standard", "src\app\MathNet.Yttrium\Packages.Standard\Yttrium.Packages.Standard.csproj", "{7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Contracts", "src\app\MathNet.Yttrium\Conversion.Contracts\Yttrium.Conversion.Contracts.csproj", "{FACEF94F-CB8B-45FA-8664-3B9F043C27E9}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.Helper", "src\app\MathNet.Yttrium\Packages.Helper\Yttrium.Packages.Helper.csproj", "{F1B95DE1-5170-4C65-92A4-CFE69256D6E1}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Library.Contracts", "src\app\MathNet.Yttrium\Library.Contracts\Yttrium.Library.Contracts.csproj", "{70E79678-387A-4AF6-8F64-4271CFE914BE}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Traversing.Contracts", "src\app\MathNet.Yttrium\Traversing.Contracts\Yttrium.Traversing.Contracts.csproj", "{191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Manipulation.Contracts", "src\app\MathNet.Yttrium\Manipulation.Contracts\Yttrium.Manipulation.Contracts.csproj", "{B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Patterns.Toolkit", "src\app\MathNet.Yttrium\Patterns.Toolkit\Yttrium.Patterns.Toolkit.csproj", "{6AAA89AE-90D5-496B-9EBD-5274C662C147}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.SystemBuilder.Toolkit", "src\app\MathNet.Yttrium\SystemBuilder.Toolkit\Yttrium.SystemBuilder.Toolkit.csproj", "{8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Manipulation.Service", "src\app\MathNet.Yttrium\Manipulation.Service\Yttrium.Manipulation.Service.csproj", "{4927027C-5A8B-41ED-B680-84C656A98031}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Traversing.Service", "src\app\MathNet.Yttrium\Traversing.Service\Yttrium.Traversing.Service.csproj", "{90E6DB8F-7BFD-4DB3-B705-468769B718E8}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Library.Service", "src\app\MathNet.Yttrium\Library.Service\Yttrium.Library.Service.csproj", "{C1280263-2D0B-4D42-909D-B750FB52D873}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Builder.Service", "src\app\MathNet.Yttrium\Builder.Service\Yttrium.Builder.Service.csproj", "{55E44945-2BB3-4BDB-8E2D-934C334D73ED}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Service", "src\app\MathNet.Yttrium\Conversion.Service\Yttrium.Conversion.Service.csproj", "{3B927CA1-FD05-4DC0-A065-A45B2B2730EC}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Interpreter.Service", "src\app\MathNet.Yttrium\Interpreter.Service\Yttrium.Interpreter.Service.csproj", "{66210C43-A4BD-4B01-A862-BC5EE789CC6E}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Repository.Contracts", "src\app\MathNet.Yttrium\Repository.Contracts\Yttrium.Repository.Contracts.csproj", "{FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Repository.Service", "src\app\MathNet.Yttrium\Repository.Service\Yttrium.Repository.Service.csproj", "{36E41B54-4992-40AF-ABF9-5F0EE34B8B32}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Conversion.Toolkit", "src\app\MathNet.Yttrium\Conversion.Toolkit\Yttrium.Conversion.Toolkit.csproj", "{8CD3403D-22BF-4BBD-9F8E-36F0F0201351}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Simulation.Contracts", "src\app\MathNet.Yttrium\Simulation.Contracts\Yttrium.Simulation.Contracts.csproj", "{CFE74A4D-51A2-432C-966A-E29773C55D45}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Simulation.Service", "src\app\MathNet.Yttrium\Simulation.Service\Yttrium.Simulation.Service.csproj", "{A214B5AE-5823-4E97-9809-39CB5FC1C1F2}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Contracts", "src\app\MathNet.Yttrium\Mediator.Contracts\Yttrium.Mediator.Contracts.csproj", "{E623ED40-9B92-40CA-9080-0FC78F668FFE}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Service", "src\app\MathNet.Yttrium\Mediator.Service\Yttrium.Mediator.Service.csproj", "{5ADA1A0C-25A8-4B09-8956-AF0C94575D22}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Packages.PetriNet", "src\app\MathNet.Yttrium\Packages\Yttrium.Packages.PetriNet\Yttrium.Packages.PetriNet.csproj", "{5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Mediator.Toolkit", "src\app\MathNet.Yttrium\Mediator.Toolkit\Yttrium.Mediator.Toolkit.csproj", "{334D8A1D-1004-4097-ACEE-8B954F911EB2}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Fundament", "src\app\MathNet.Yttrium\Fundament\Yttrium.Fundament.csproj", "{FDD51A32-1C78-4135-A6E8-222B022A01C6}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Formatter.Contracts", "src\app\MathNet.Yttrium\Formatter.Contracts\Yttrium.Formatter.Contracts.csproj", "{92C1E300-20D2-4195-AB4C-1402A9152E25}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yttrium.Formatter.Service", "src\app\MathNet.Yttrium\Formatter.Service\Yttrium.Formatter.Service.csproj", "{36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}" + ProjectSection(WebsiteProperties) = preProject + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.Debug = "False" + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAB86B17-68FA-4081-B687-DB71B74BAF79}.Release|Any CPU.Build.0 = Release|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5F4F488-5A7A-47BB-936C-19E30AFB4FEB}.Release|Any CPU.Build.0 = Release|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8966E2C5-B1C9-44BE-8751-45DCCA3D268F}.Release|Any CPU.Build.0 = Release|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D03B156A-D6F3-4F46-AC59-7156681F69B7}.Release|Any CPU.Build.0 = Release|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A0BF5B0-653C-40BD-8046-ED614D95D3D6}.Release|Any CPU.Build.0 = Release|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D33EAA2-C873-4BC0-88C5-FA350CB4B67A}.Release|Any CPU.Build.0 = Release|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FACEF94F-CB8B-45FA-8664-3B9F043C27E9}.Release|Any CPU.Build.0 = Release|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1B95DE1-5170-4C65-92A4-CFE69256D6E1}.Release|Any CPU.Build.0 = Release|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70E79678-387A-4AF6-8F64-4271CFE914BE}.Release|Any CPU.Build.0 = Release|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {191C1DF6-DDD9-4CFB-B459-3FA3FC421AC8}.Release|Any CPU.Build.0 = Release|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B273E022-E5DC-4FEE-8B70-FD9AF6A9BF6C}.Release|Any CPU.Build.0 = Release|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6AAA89AE-90D5-496B-9EBD-5274C662C147}.Release|Any CPU.Build.0 = Release|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8005E26B-E82F-4AF4-92E5-EDFA6FABCAA3}.Release|Any CPU.Build.0 = Release|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4927027C-5A8B-41ED-B680-84C656A98031}.Release|Any CPU.Build.0 = Release|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90E6DB8F-7BFD-4DB3-B705-468769B718E8}.Release|Any CPU.Build.0 = Release|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1280263-2D0B-4D42-909D-B750FB52D873}.Release|Any CPU.Build.0 = Release|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55E44945-2BB3-4BDB-8E2D-934C334D73ED}.Release|Any CPU.Build.0 = Release|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B927CA1-FD05-4DC0-A065-A45B2B2730EC}.Release|Any CPU.Build.0 = Release|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66210C43-A4BD-4B01-A862-BC5EE789CC6E}.Release|Any CPU.Build.0 = Release|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF88EDDE-73BB-4BE1-B0FB-33278F3FD257}.Release|Any CPU.Build.0 = Release|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36E41B54-4992-40AF-ABF9-5F0EE34B8B32}.Release|Any CPU.Build.0 = Release|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CD3403D-22BF-4BBD-9F8E-36F0F0201351}.Release|Any CPU.Build.0 = Release|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFE74A4D-51A2-432C-966A-E29773C55D45}.Release|Any CPU.Build.0 = Release|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A214B5AE-5823-4E97-9809-39CB5FC1C1F2}.Release|Any CPU.Build.0 = Release|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E623ED40-9B92-40CA-9080-0FC78F668FFE}.Release|Any CPU.Build.0 = Release|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5ADA1A0C-25A8-4B09-8956-AF0C94575D22}.Release|Any CPU.Build.0 = Release|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D5C5661-1B83-4C25-AC7A-C7AED7FFC9DD}.Release|Any CPU.Build.0 = Release|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {334D8A1D-1004-4097-ACEE-8B954F911EB2}.Release|Any CPU.Build.0 = Release|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDD51A32-1C78-4135-A6E8-222B022A01C6}.Release|Any CPU.Build.0 = Release|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92C1E300-20D2-4195-AB4C-1402A9152E25}.Release|Any CPU.Build.0 = Release|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36BE1C95-3E2A-4110-9FE1-E46EC3A3D5C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/_UpgradeReport_Files/UpgradeReport.css b/_UpgradeReport_Files/UpgradeReport.css new file mode 100644 index 0000000..fae98af --- /dev/null +++ b/_UpgradeReport_Files/UpgradeReport.css @@ -0,0 +1,207 @@ +BODY +{ + BACKGROUND-COLOR: white; + FONT-FAMILY: "Verdana", sans-serif; + FONT-SIZE: 100%; + MARGIN-LEFT: 0px; + MARGIN-TOP: 0px +} +P +{ + FONT-FAMILY: "Verdana", sans-serif; + FONT-SIZE: 70%; + LINE-HEIGHT: 12pt; + MARGIN-BOTTOM: 0px; + MARGIN-LEFT: 10px; + MARGIN-TOP: 10px +} +.note +{ + BACKGROUND-COLOR: #ffffff; + COLOR: #336699; + FONT-FAMILY: "Verdana", sans-serif; + FONT-SIZE: 100%; + MARGIN-BOTTOM: 0px; + MARGIN-LEFT: 0px; + MARGIN-TOP: 0px; + PADDING-RIGHT: 10px +} +.infotable +{ + BACKGROUND-COLOR: #f0f0e0; + BORDER-BOTTOM: #ffffff 0px solid; + BORDER-COLLAPSE: collapse; + BORDER-LEFT: #ffffff 0px solid; + BORDER-RIGHT: #ffffff 0px solid; + BORDER-TOP: #ffffff 0px solid; + FONT-SIZE: 70%; + MARGIN-LEFT: 10px +} +.issuetable +{ + BACKGROUND-COLOR: #ffffe8; + BORDER-COLLAPSE: collapse; + COLOR: #000000; + FONT-SIZE: 100%; + MARGIN-BOTTOM: 10px; + MARGIN-LEFT: 13px; + MARGIN-TOP: 0px +} +.issuetitle +{ + BACKGROUND-COLOR: #ffffff; + BORDER-BOTTOM: #dcdcdc 1px solid; + BORDER-TOP: #dcdcdc 1px; + COLOR: #003366; + FONT-WEIGHT: normal +} +.header +{ + BACKGROUND-COLOR: #cecf9c; + BORDER-BOTTOM: #ffffff 1px solid; + BORDER-LEFT: #ffffff 1px solid; + BORDER-RIGHT: #ffffff 1px solid; + BORDER-TOP: #ffffff 1px solid; + COLOR: #000000; + FONT-WEIGHT: bold +} +.issuehdr +{ + BACKGROUND-COLOR: #E0EBF5; + BORDER-BOTTOM: #dcdcdc 1px solid; + BORDER-TOP: #dcdcdc 1px solid; + COLOR: #000000; + FONT-WEIGHT: normal +} +.issuenone +{ + BACKGROUND-COLOR: #ffffff; + BORDER-BOTTOM: 0px; + BORDER-LEFT: 0px; + BORDER-RIGHT: 0px; + BORDER-TOP: 0px; + COLOR: #000000; + FONT-WEIGHT: normal +} +.content +{ + BACKGROUND-COLOR: #e7e7ce; + BORDER-BOTTOM: #ffffff 1px solid; + BORDER-LEFT: #ffffff 1px solid; + BORDER-RIGHT: #ffffff 1px solid; + BORDER-TOP: #ffffff 1px solid; + PADDING-LEFT: 3px +} +.issuecontent +{ + BACKGROUND-COLOR: #ffffff; + BORDER-BOTTOM: #dcdcdc 1px solid; + BORDER-TOP: #dcdcdc 1px solid; + PADDING-LEFT: 3px +} +A:link +{ + COLOR: #cc6633; + TEXT-DECORATION: underline +} +A:visited +{ + COLOR: #cc6633; +} +A:active +{ + COLOR: #cc6633; +} +A:hover +{ + COLOR: #cc3300; + TEXT-DECORATION: underline +} +H1 +{ + BACKGROUND-COLOR: #003366; + BORDER-BOTTOM: #336699 6px solid; + COLOR: #ffffff; + FONT-SIZE: 130%; + FONT-WEIGHT: normal; + MARGIN: 0em 0em 0em -20px; + PADDING-BOTTOM: 8px; + PADDING-LEFT: 30px; + PADDING-TOP: 16px +} +H2 +{ + COLOR: #000000; + FONT-SIZE: 80%; + FONT-WEIGHT: bold; + MARGIN-BOTTOM: 3px; + MARGIN-LEFT: 10px; + MARGIN-TOP: 20px; + PADDING-LEFT: 0px +} +H3 +{ + COLOR: #000000; + FONT-SIZE: 80%; + FONT-WEIGHT: bold; + MARGIN-BOTTOM: -5px; + MARGIN-LEFT: 10px; + MARGIN-TOP: 20px +} +H4 +{ + COLOR: #000000; + FONT-SIZE: 70%; + FONT-WEIGHT: bold; + MARGIN-BOTTOM: 0px; + MARGIN-TOP: 15px; + PADDING-BOTTOM: 0px +} +UL +{ + COLOR: #000000; + FONT-SIZE: 70%; + LIST-STYLE: square; + MARGIN-BOTTOM: 0pt; + MARGIN-TOP: 0pt +} +OL +{ + COLOR: #000000; + FONT-SIZE: 70%; + LIST-STYLE: square; + MARGIN-BOTTOM: 0pt; + MARGIN-TOP: 0pt +} +LI +{ + LIST-STYLE: square; + MARGIN-LEFT: 0px +} +.expandable +{ + CURSOR: hand +} +.expanded +{ + color: black +} +.collapsed +{ + DISPLAY: none +} +.foot +{ +BACKGROUND-COLOR: #ffffff; +BORDER-BOTTOM: #cecf9c 1px solid; +BORDER-TOP: #cecf9c 2px solid +} +.settings +{ +MARGIN-LEFT: 25PX; +} +.help +{ +TEXT-ALIGN: right; +margin-right: 10px; +} diff --git a/_UpgradeReport_Files/UpgradeReport.xslt b/_UpgradeReport_Files/UpgradeReport.xslt new file mode 100644 index 0000000..73c4e7a --- /dev/null +++ b/_UpgradeReport_Files/UpgradeReport.xslt @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ Solution: + Project: + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + src + + + + + + + + + + + + +
FilenameStatusErrorsWarnings
+ javascript:document.images[''].click()src + + + + Converted + + + + Converted + +
+ + files + + + 1 file + + + Converted:
+ Not converted: +
+
+
+ + + + : + + + + + + + + + Conversion Report + <xsl:if test="Properties/Property[@Name='LogNumber']"> + <xsl:value-of select="Properties/Property[@Name='LogNumber']/@Value"/> + </xsl:if> + + + + +

Conversion Report -

+ +

+ Time of Conversion:
+

+ + + + + + + + + + + + + + + + + + + + + + + + +

+ + + + + +
+ Conversion Settings +

+ + +
+
diff --git a/_UpgradeReport_Files/UpgradeReport_Minus.gif b/_UpgradeReport_Files/UpgradeReport_Minus.gif new file mode 100644 index 0000000..17751cb Binary files /dev/null and b/_UpgradeReport_Files/UpgradeReport_Minus.gif differ diff --git a/_UpgradeReport_Files/UpgradeReport_Plus.gif b/_UpgradeReport_Files/UpgradeReport_Plus.gif new file mode 100644 index 0000000..f6009ca Binary files /dev/null and b/_UpgradeReport_Files/UpgradeReport_Plus.gif differ diff --git a/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs b/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs index 0a75b04..ce216bc 100644 --- a/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs +++ b/src/app/MathNet.Yttrium/Builder.Service/Properties/Resources.Designer.cs @@ -1,72 +1,72 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.42 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace MathNet.Symbolics.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to A requested feature is not yet implemented.. - /// - internal static string ex_NotImplementedYet { - get { - return ResourceManager.GetString("ex_NotImplementedYet", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.269 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to A requested feature is not yet implemented.. + /// + internal static string ex_NotImplementedYet { + get { + return ResourceManager.GetString("ex_NotImplementedYet", resourceCulture); + } + } + } +} diff --git a/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj b/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj index c1adbbf..06f3dcd 100644 --- a/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj +++ b/src/app/MathNet.Yttrium/Builder.Service/Yttrium.Builder.Service.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -9,6 +10,12 @@ Properties MathNet.Symbolics MathNet.Yttrium.Builder.Service + v4.0 + + + + + 2.0 true diff --git a/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs b/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs index 436bf36..0caf774 100644 --- a/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs +++ b/src/app/MathNet.Yttrium/Contracts/Containers/ISignalSet.cs @@ -26,7 +26,7 @@ namespace MathNet.Symbolics.Backend.Containers { - public interface ISignalSet : ISet + public interface ISignalSet : MathNet.Numerics.ISet { InstanceIdSet ConvertAllToInstanceIds(Converter convert); InstanceIdSet ConvertAllToInstanceIds(); diff --git a/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs b/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs index dcbe817..2667462 100644 --- a/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs +++ b/src/app/MathNet.Yttrium/Contracts/Properties/Resources.Designer.cs @@ -1,198 +1,198 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.832 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace MathNet.Symbolics.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to The operation '{0}' does not support circular systems, that is systems with signals depending upon themselves.. - /// - internal static string ex_CyclicSignalsNotSupportes { - get { - return ResourceManager.GetString("ex_CyclicSignalsNotSupportes", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Failed to deserialize the entity {0}.{1}: entity is generic but no extension is attached.. - /// - internal static string ex_Deserialize_Failed_GenericEntity { - get { - return ResourceManager.GetString("ex_Deserialize_Failed_GenericEntity", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Failed to deserialize an item, due to an invalid data file or a usage error. Expected '{0}' but got '{1}' instead. Check the data file for errors and report to the developer.. - /// - internal static string ex_Deserialize_Failed_UnexpectedPosition { - get { - return ResourceManager.GetString("ex_Deserialize_Failed_UnexpectedPosition", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No proper category deserialization method found.. - /// - internal static string ex_Deserialize_Failed_UnsupportedCategory { - get { - return ResourceManager.GetString("ex_Deserialize_Failed_UnsupportedCategory", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No proper structure deserialization method found.. - /// - internal static string ex_Deserialize_Failed_UnsupportedStructure { - get { - return ResourceManager.GetString("ex_Deserialize_Failed_UnsupportedStructure", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The operation expected {0} but got {1} instead. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. - /// - internal static string ex_Entity_Unexpected_SignalCount { - get { - return ResourceManager.GetString("ex_Entity_Unexpected_SignalCount", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No Math.NET Architecture matching the requirements (including supporting the entity '{0}') was found. Maybe an extension module is not loaded yet, or the input signals are not qualified enough.. - /// - internal static string ex_NotAvailable_Architecture { - get { - return ResourceManager.GetString("ex_NotAvailable_Architecture", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The currently loaded context library does not list the demanded domain '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. - /// - internal static string ex_NotAvailable_Domain { - get { - return ResourceManager.GetString("ex_NotAvailable_Domain", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The currently loaded context library does not list the demanded entity '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. - /// - internal static string ex_NotAvailable_Entity { - get { - return ResourceManager.GetString("ex_NotAvailable_Entity", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The search for a specific item has returned no result.. - /// - internal static string ex_NotFound { - get { - return ResourceManager.GetString("ex_NotFound", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A requested feature is not yet implemented.. - /// - internal static string ex_NotImplementedYet { - get { - return ResourceManager.GetString("ex_NotImplementedYet", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0}' but got '{1}' around '{2}'.. - /// - internal static string ex_Parsing_Failed_TokenMismatch { - get { - return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatch", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0} [{3}]' but got '{1}' around '{2}'.. - /// - internal static string ex_Parsing_Failed_TokenMismatchEx { - get { - return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatchEx", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A theorem was used on a wrong item or a matching theorem was not found. This probably is a programming error, please report to the manufacturer.. - /// - internal static string ex_Theorem_Mismatch { - get { - return ResourceManager.GetString("ex_Theorem_Mismatch", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A mutual exclusive system traversing strategy is already in use and may not be executed again before the other finishes its operation.. - /// - internal static string ex_Traversing_Failed_ReserveMutex { - get { - return ResourceManager.GetString("ex_Traversing_Failed_ReserveMutex", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.269 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MathNet.Symbolics.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Symbolics.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to The operation '{0}' does not support circular systems, that is systems with signals depending upon themselves.. + /// + internal static string ex_CyclicSignalsNotSupportes { + get { + return ResourceManager.GetString("ex_CyclicSignalsNotSupportes", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to deserialize the entity {0}.{1}: entity is generic but no extension is attached.. + /// + internal static string ex_Deserialize_Failed_GenericEntity { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_GenericEntity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to deserialize an item, due to an invalid data file or a usage error. Expected '{0}' but got '{1}' instead. Check the data file for errors and report to the developer.. + /// + internal static string ex_Deserialize_Failed_UnexpectedPosition { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_UnexpectedPosition", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No proper category deserialization method found.. + /// + internal static string ex_Deserialize_Failed_UnsupportedCategory { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_UnsupportedCategory", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No proper structure deserialization method found.. + /// + internal static string ex_Deserialize_Failed_UnsupportedStructure { + get { + return ResourceManager.GetString("ex_Deserialize_Failed_UnsupportedStructure", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The operation expected {0} but got {1} instead. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. + /// + internal static string ex_Entity_Unexpected_SignalCount { + get { + return ResourceManager.GetString("ex_Entity_Unexpected_SignalCount", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No Math.NET Architecture matching the requirements (including supporting the entity '{0}') was found. Maybe an extension module is not loaded yet, or the input signals are not qualified enough.. + /// + internal static string ex_NotAvailable_Architecture { + get { + return ResourceManager.GetString("ex_NotAvailable_Architecture", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The currently loaded context library does not list the demanded domain '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. + /// + internal static string ex_NotAvailable_Domain { + get { + return ResourceManager.GetString("ex_NotAvailable_Domain", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The currently loaded context library does not list the demanded entity '{0}'. Maybe an extension module is not loaded yet, there is a typo, or the module is faulty.. + /// + internal static string ex_NotAvailable_Entity { + get { + return ResourceManager.GetString("ex_NotAvailable_Entity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The search for a specific item has returned no result.. + /// + internal static string ex_NotFound { + get { + return ResourceManager.GetString("ex_NotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A requested feature is not yet implemented.. + /// + internal static string ex_NotImplementedYet { + get { + return ResourceManager.GetString("ex_NotImplementedYet", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0}' but got '{1}' around '{2}'.. + /// + internal static string ex_Parsing_Failed_TokenMismatch { + get { + return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parsing failed. Token Mismatch. Expected '{0} [{3}]' but got '{1}' around '{2}'.. + /// + internal static string ex_Parsing_Failed_TokenMismatchEx { + get { + return ResourceManager.GetString("ex_Parsing_Failed_TokenMismatchEx", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A theorem was used on a wrong item or a matching theorem was not found. This probably is a programming error, please report to the manufacturer.. + /// + internal static string ex_Theorem_Mismatch { + get { + return ResourceManager.GetString("ex_Theorem_Mismatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A mutual exclusive system traversing strategy is already in use and may not be executed again before the other finishes its operation.. + /// + internal static string ex_Traversing_Failed_ReserveMutex { + get { + return ResourceManager.GetString("ex_Traversing_Failed_ReserveMutex", resourceCulture); + } + } + } +} diff --git a/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj b/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj index c639aeb..a5f1f0e 100644 --- a/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj +++ b/src/app/MathNet.Yttrium/Contracts/Yttrium.Contracts.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -9,6 +10,27 @@ Properties MathNet.Symbolics MathNet.Yttrium.Contracts + v4.0 + + + + + 2.0 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -28,9 +50,8 @@ 4 - - False - ..\..\..\..\build\Release\MathNet.Iridium.dll + + ..\..\..\..\lib\Math.NET-Iridium\MathNet.Iridium.dll @@ -133,6 +154,28 @@ Yttrium.Fundament + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + +