diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..984791f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +!*.dll diff --git a/Codes.C#/P10/P10.sln b/Codes.C#/P10/P10.sln new file mode 100644 index 0000000..b3bbd26 --- /dev/null +++ b/Codes.C#/P10/P10.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P10", "P10\P10.csproj", "{E9C02F89-4E17-4DBE-B064-D4C358C984F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E9C02F89-4E17-4DBE-B064-D4C358C984F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9C02F89-4E17-4DBE-B064-D4C358C984F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9C02F89-4E17-4DBE-B064-D4C358C984F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9C02F89-4E17-4DBE-B064-D4C358C984F8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P10/P10/App.config b/Codes.C#/P10/P10/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P10/P10/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P10/P10/Form1.Designer.cs b/Codes.C#/P10/P10/Form1.Designer.cs new file mode 100644 index 0000000..e31d4e3 --- /dev/null +++ b/Codes.C#/P10/P10/Form1.Designer.cs @@ -0,0 +1,138 @@ +namespace P10 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.tBq = new System.Windows.Forms.TextBox(); + this.tBPrior = new System.Windows.Forms.TextBox(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label4 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 205); + this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(185, 12); + this.label3.TabIndex = 9; + this.label3.Text = "The probability after sensing:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 61); + this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 12); + this.label2.TabIndex = 8; + this.label2.Text = "The Prior:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(40, 376); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 7; + this.label1.Text = "label1"; + // + // tBq + // + this.tBq.Location = new System.Drawing.Point(11, 219); + this.tBq.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tBq.Multiline = true; + this.tBq.Name = "tBq"; + this.tBq.Size = new System.Drawing.Size(366, 122); + this.tBq.TabIndex = 6; + // + // tBPrior + // + this.tBPrior.Location = new System.Drawing.Point(11, 75); + this.tBPrior.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tBPrior.Multiline = true; + this.tBPrior.Name = "tBPrior"; + this.tBPrior.Size = new System.Drawing.Size(366, 122); + this.tBPrior.TabIndex = 5; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(11, 29); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(83, 20); + this.comboBox1.TabIndex = 10; + this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(11, 14); + this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(53, 12); + this.label4.TabIndex = 11; + this.label4.Text = "观测值:"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(388, 401); + this.Controls.Add(this.label4); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.tBq); + this.Controls.Add(this.tBPrior); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox tBq; + private System.Windows.Forms.TextBox tBPrior; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label4; + } +} + diff --git a/Codes.C#/P10/P10/Form1.cs b/Codes.C#/P10/P10/Form1.cs new file mode 100644 index 0000000..502d7ff --- /dev/null +++ b/Codes.C#/P10/P10/Form1.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace P10 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + comboBox1.Items.Add("green"); + comboBox1.Items.Add("red"); + comboBox1.Text = "green"; + print(); + } + void print() + { + tBPrior.Text = ""; + tBq.Text = ""; + string[,] world = {{"red", "green", "green", "red" , "red"}, + {"red", "red", "green", "red", "red"}, + {"red", "red", "green", "green", "red"}, + {"red", "red", "red", "red", "red"}}; // Map + double[,] ones = { { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 } }; + int nRow = world.GetLength(0); + int nCol = world.GetLength(1); + double[,] prior = new double[nRow, nCol]; + List> q = new List>(nRow); + + double pSenseCorrect = 0.7; + double pStart = 0.7; + + for (int i = 0; i < nRow; i++) + { + for (int j = 0; j < nCol; j++) + { + prior[i, j] = (1 - pStart) / (nRow * nCol - 1) * ones[i, j];// Prior + } + } + prior[2, 1] = pStart; + string measurements = comboBox1.Text; + // Measurment update + q = sense(prior, measurements, world, nRow, nCol, pSenseCorrect); + + for (int i = 0; i < nRow; i++) + { + for (int j = 0; j < nCol; j++) + { + tBPrior.Text += string.Format("{0:F4}\t", prior[i, j]); + } + tBPrior.Text += Environment.NewLine; + } + + // disp('The probability after moving:'); + for (int i = 0; i < nRow; i++) + { + for (int j = 0; j < nCol; j++) + { + tBq.Text += string.Format("{0:F4}\t", q[i][j]); + } + tBq.Text += Environment.NewLine; + } + int[] maxindex = new int[2]; + maxindex = FindMax(q); + label1.Text = string.Format("The largest probability {0:F4} occurs at cell({1},{2})", q[maxindex[0]][maxindex[1]], maxindex[0], maxindex[1]); + } + + List> sense(double[,] p, string z, string[,] world, int nRow,int nCol,double pSenseCorrect) + { + nRow = p.GetLength(0); + nCol = p.GetLength(1); + List tList = new List(nCol); + List> tposterior = new List>(); + List> posterior = new List>(); + for(int r = 0;r < nRow;r++) + { + tList = new List(nCol); + for(int c = 0;c < nCol;c++) + { + int hit = z.CompareTo(world[r,c]); // 相同为0,否则为1或-1 + tList.Add((pSenseCorrect * (1 - hit * hit) + (1 - pSenseCorrect) * hit * hit) * p[r, c]); + } + tposterior.Add(tList); + //tList.Clear(); // List是引用类型,所以清空后,tposterior也清空了!!!!!!!!!!!! + } + + double sum = tposterior[0].Sum() + tposterior[1].Sum() + tposterior[2].Sum() + tposterior[3].Sum(); + for (int i = 0; i < nRow; i++) + { + tList = new List(nCol); + for (int j = 0; j < nCol;j++) + { + tList.Add(tposterior[i][j] / sum); + } + posterior.Add(tList); + } + return posterior; + } + + int[] FindMax(List> array) + { + int[] index = new int[2]; + double max = array[0][0]; + if (array == null || array.Count == 0) + { + index = new int[] { -1, -1 }; + return index; + } + index = new int[] { 0, 0 }; + for (int i = 0; i < array.Count; i++) + { + for (int j = 0; j < array[i].Count; j++) + { + if (array[i][j] > max) + { + index[0] = i; + index[1] = j; + max = array[i][j]; + } + } + } + return index; + } + + private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) + { + print(); + } + } +} diff --git a/Codes.C#/P10/P10/Form1.resx b/Codes.C#/P10/P10/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P10/P10/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P10/P10/P10.csproj b/Codes.C#/P10/P10/P10.csproj new file mode 100644 index 0000000..d8c8275 --- /dev/null +++ b/Codes.C#/P10/P10/P10.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {E9C02F89-4E17-4DBE-B064-D4C358C984F8} + WinExe + Properties + P10 + P10 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P10/P10/Program.cs b/Codes.C#/P10/P10/Program.cs new file mode 100644 index 0000000..bbdbbb0 --- /dev/null +++ b/Codes.C#/P10/P10/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P10 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P10/P10/Properties/AssemblyInfo.cs b/Codes.C#/P10/P10/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7751000 --- /dev/null +++ b/Codes.C#/P10/P10/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P10")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P10")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("e2bad832-e51f-4f44-b7f6-a740714e4dab")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P10/P10/Properties/Resources.Designer.cs b/Codes.C#/P10/P10/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f2014c3 --- /dev/null +++ b/Codes.C#/P10/P10/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P10.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P10.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P10/P10/Properties/Resources.resx b/Codes.C#/P10/P10/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P10/P10/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P10/P10/Properties/Settings.Designer.cs b/Codes.C#/P10/P10/Properties/Settings.Designer.cs new file mode 100644 index 0000000..952bbef --- /dev/null +++ b/Codes.C#/P10/P10/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P10.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P10/P10/Properties/Settings.settings b/Codes.C#/P10/P10/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P10/P10/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P11/P11.sln b/Codes.C#/P11/P11.sln new file mode 100644 index 0000000..3de387d --- /dev/null +++ b/Codes.C#/P11/P11.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P11", "P11\P11.csproj", "{A4B03255-1A0C-4EE9-8E59-88D2BD93593A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A4B03255-1A0C-4EE9-8E59-88D2BD93593A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4B03255-1A0C-4EE9-8E59-88D2BD93593A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4B03255-1A0C-4EE9-8E59-88D2BD93593A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4B03255-1A0C-4EE9-8E59-88D2BD93593A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P11/P11/App.config b/Codes.C#/P11/P11/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P11/P11/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P11/P11/MainForm.Designer.cs b/Codes.C#/P11/P11/MainForm.Designer.cs new file mode 100644 index 0000000..a986060 --- /dev/null +++ b/Codes.C#/P11/P11/MainForm.Designer.cs @@ -0,0 +1,176 @@ +namespace P11 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.tBq = new System.Windows.Forms.TextBox(); + this.tBPrior = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.tBMotions = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.tBMeasurements = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 259); + this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(185, 12); + this.label3.TabIndex = 14; + this.label3.Text = "The probability after sensing:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 0); + this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 12); + this.label2.TabIndex = 13; + this.label2.Text = "The Prior:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 416); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 12; + this.label1.Text = "label1"; + // + // tBq + // + this.tBq.Location = new System.Drawing.Point(8, 274); + this.tBq.Margin = new System.Windows.Forms.Padding(2); + this.tBq.Multiline = true; + this.tBq.Name = "tBq"; + this.tBq.ReadOnly = true; + this.tBq.Size = new System.Drawing.Size(366, 122); + this.tBq.TabIndex = 11; + // + // tBPrior + // + this.tBPrior.Location = new System.Drawing.Point(8, 14); + this.tBPrior.Margin = new System.Windows.Forms.Padding(2); + this.tBPrior.Multiline = true; + this.tBPrior.Name = "tBPrior"; + this.tBPrior.ReadOnly = true; + this.tBPrior.Size = new System.Drawing.Size(366, 122); + this.tBPrior.TabIndex = 10; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(6, 148); + this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(53, 12); + this.label4.TabIndex = 15; + this.label4.Text = "Motions:"; + // + // tBMotions + // + this.tBMotions.Location = new System.Drawing.Point(70, 148); + this.tBMotions.Multiline = true; + this.tBMotions.Name = "tBMotions"; + this.tBMotions.Size = new System.Drawing.Size(184, 59); + this.tBMotions.TabIndex = 17; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(279, 148); + this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(83, 12); + this.label5.TabIndex = 15; + this.label5.Text = "measurements:"; + // + // tBMeasurements + // + this.tBMeasurements.Location = new System.Drawing.Point(368, 145); + this.tBMeasurements.Multiline = true; + this.tBMeasurements.Name = "tBMeasurements"; + this.tBMeasurements.Size = new System.Drawing.Size(189, 59); + this.tBMeasurements.TabIndex = 17; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(271, 223); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 18; + this.button1.Text = "计算"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 446); + this.Controls.Add(this.button1); + this.Controls.Add(this.tBMeasurements); + this.Controls.Add(this.tBMotions); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.tBq); + this.Controls.Add(this.tBPrior); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "MainForm"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox tBq; + private System.Windows.Forms.TextBox tBPrior; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox tBMotions; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox tBMeasurements; + private System.Windows.Forms.Button button1; + } +} + diff --git a/Codes.C#/P11/P11/MainForm.cs b/Codes.C#/P11/P11/MainForm.cs new file mode 100644 index 0000000..3bb8bd8 --- /dev/null +++ b/Codes.C#/P11/P11/MainForm.cs @@ -0,0 +1,244 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace P11 +{ + public partial class MainForm : Form + { + List tList; + public MainForm() + { + InitializeComponent(); + print(); + } + void print() + { + tBPrior.Text = ""; + tBq.Text = ""; + label1.Text = ""; + string[,] world = {{"red", "green", "green", "red" , "red"}, + {"red", "red", "green", "red", "red"}, + {"red", "red", "green", "green", "red"}, + {"red", "red", "red", "red", "red"}}; // Map + double[,] ones = { { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 } }; + int nRow = world.GetLength(0); + int nCol = world.GetLength(1); + List stop = new List{0, 0}; + List right = new List{0, 1}; + List left = new List{0,-1}; + List down = new List{1, 0}; + List up = new List{-1,0}; + List> directions = new List> { stop, right, left, down, up }; + double pMoveCorrect = 0.8; + double pSenseCorrect = 0.7; + + List> prior = new List>(); + + for (int i = 0; i < nRow; i++) + { + tList = new List(); + for (int j = 0; j < nCol; j++) + { + tList.Add(1.0 / (nRow * nCol) * ones[i, j]); + } + prior.Add(tList); + } + + List> motions = new List>(); + List measurements = new List(); + string[] strMotionEnum = {"stop","right","left","down","up"}; + string[] strMeasurementEnum = { "green", "red" }; + + // First configuration + if(string.IsNullOrEmpty(tBMotions.Text) && string.IsNullOrEmpty(tBMeasurements.Text)) + { + motions = new List> { stop, right, down, down, right }; + measurements = new List{ "green", "green", "green", "green", "green" }; + tBMotions.Text = "stop " + "right " + "down " + "down " + "right "; + tBMeasurements.Text = "green " + "green " + "green " + "green " + "green "; + } + else + { + string[] strMotions = tBMotions.Text.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries); + int count = 0; + for (int i = 0; i < strMotions.Length; i++) + { + foreach (var k in strMotionEnum) + { + if (k == strMotions[i]) + { + motions.Add(directions[count]); + } + count++; + } + count = 0; + } + + string[] strMeasurements = tBMeasurements.Text.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries); + for (int i = 0; i < strMeasurements.Length; i++) + { + foreach (var k in strMeasurementEnum) + { + if (k == strMeasurements[i]) + { + measurements.Add(strMeasurements[i]); + } + } + } + } + // Check the size + if(motions.Count != 0 && measurements.Count != 0) + { + if (motions.Count != measurements.Count) + { + MessageBox.Show("The variable \"motions\" should be of the same size as \"measurements\"!"); + return; + } + else + { + double[,] entropy = new double[2, motions.Count]; + List> p0; + + // The main loop + for (int i = 0; i < motions.Count; i++) + { + prior = Move(prior, motions[i], pMoveCorrect); + p0 = prior; + prior = Sense(prior, measurements[i], world, nRow, nCol, pSenseCorrect); + // Compute entropy + entropy[0, i] = ComputeEntropy(p0); + entropy[1, i] = ComputeEntropy(prior); + } + + for (int i = 0; i < nRow; i++) + { + for (int j = 0; j < nCol; j++) + { + tBPrior.Text += string.Format("{0:F4}\t", prior[i][j]); + } + tBPrior.Text += Environment.NewLine; + } + + // disp('The probability after sensing:'); + for (int i = 0; i < nRow; i++) + { + for (int j = 0; j < nCol; j++) + { + tBq.Text += string.Format("{0:F4}\t", prior[i][j]); + } + tBq.Text += Environment.NewLine; + } + + int[] maxindex = new int[2]; + maxindex = FindMax(prior); + label1.Text = string.Format("The largest probability {0:F4} occurs at cell({1},{2})", prior[maxindex[0]][maxindex[1]], maxindex[0], maxindex[1]); + } + } + else + { + MessageBox.Show("请输入有效数据"); + } + } + + public List> Move(List> prior, List u, double pMoveCorrect) + { + int nRow = prior.Count(); + int nCol = prior[0].Count(); + List> q = new List>(); + + for (int r = 0; r < nRow; r++) + { + tList = new List(); + for (int c = 0; c < nCol; c++) + { + tList.Add(pMoveCorrect * prior[mod((r - u[0]), nRow)][mod(c - u[1], nCol)] + + (1 - pMoveCorrect) * prior[r][c]); + } + q.Add(tList); + } + return q; + } + + List> Sense(List> p, string z, string[,] world, int nRow, int nCol, double pSenseCorrect) + { + nRow = p.Count(); + nCol = p[0].Count(); + List> tposterior = new List>(); + List> posterior = new List>(); + + for (int r = 0; r < nRow; r++) + { + tList = new List(nCol); + for (int c = 0; c < nCol; c++) + { + int hit = z.CompareTo(world[r, c]); // 相同为0,否则为1或-1 + tList.Add((pSenseCorrect * (1 - hit * hit) + (1 - pSenseCorrect) * hit * hit) * p[r][c]); + } + tposterior.Add(tList); + //tList.Clear(); // List是引用类型,所以清空后,tposterior也清空了!!!!!!!!!!!! + } + + double sum = tposterior[0].Sum() + tposterior[1].Sum() + tposterior[2].Sum() + tposterior[3].Sum(); + for (int i = 0; i < nRow; i++) + { + tList = new List(nCol); + for (int j = 0; j < nCol; j++) + { + tList.Add(tposterior[i][j] / sum); + } + posterior.Add(tList); + } + return posterior; + } + + int[] FindMax(List> array) + { + int[] index = new int[2]; + double max = array[0][0]; + if (array == null || array.Count == 0) + { + index = new int[] { -1, -1 }; + return index; + } + index = new int[] { 0, 0 }; + for (int i = 0; i < array.Count; i++) + { + for (int j = 0; j < array[i].Count; j++) + { + if (array[i][j] > max) + { + index[0] = i; + index[1] = j; + max = array[i][j]; + } + } + } + return index; + } + + double ComputeEntropy(List> p) + { + double entropy = new double { }; + for (int i = 0; i < p.Count(); i++) + { + for (int j = 0; j < p[0].Count(); j++) + { + entropy += -p[i][j] * Math.Log(p[i][j], 2); + } + } + return entropy; + } + + int mod(int a, int b) + { + return ((a % b + b) % b); + } + + private void button1_Click(object sender, EventArgs e) + { + print(); + } + } +} diff --git a/Codes.C#/P11/P11/MainForm.resx b/Codes.C#/P11/P11/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P11/P11/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P11/P11/P11.csproj b/Codes.C#/P11/P11/P11.csproj new file mode 100644 index 0000000..5003de6 --- /dev/null +++ b/Codes.C#/P11/P11/P11.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {A4B03255-1A0C-4EE9-8E59-88D2BD93593A} + WinExe + Properties + P11 + P11 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P11/P11/Program.cs b/Codes.C#/P11/P11/Program.cs new file mode 100644 index 0000000..d53056b --- /dev/null +++ b/Codes.C#/P11/P11/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P11 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P11/P11/Properties/AssemblyInfo.cs b/Codes.C#/P11/P11/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..80c68ea --- /dev/null +++ b/Codes.C#/P11/P11/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P11")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P11")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("413a1420-f908-4360-8fb6-c386c9dc0fde")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P11/P11/Properties/Resources.Designer.cs b/Codes.C#/P11/P11/Properties/Resources.Designer.cs new file mode 100644 index 0000000..a68b615 --- /dev/null +++ b/Codes.C#/P11/P11/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P11.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P11.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P11/P11/Properties/Resources.resx b/Codes.C#/P11/P11/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P11/P11/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P11/P11/Properties/Settings.Designer.cs b/Codes.C#/P11/P11/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3ec0b5d --- /dev/null +++ b/Codes.C#/P11/P11/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P11.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P11/P11/Properties/Settings.settings b/Codes.C#/P11/P11/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P11/P11/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P12/P12.sln b/Codes.C#/P12/P12.sln new file mode 100644 index 0000000..2c0b2e5 --- /dev/null +++ b/Codes.C#/P12/P12.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P12", "WindowsFormsApplication1\P12.csproj", "{D534C60C-4E04-421E-A41B-8B7F1B0AFB40}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D534C60C-4E04-421E-A41B-8B7F1B0AFB40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D534C60C-4E04-421E-A41B-8B7F1B0AFB40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D534C60C-4E04-421E-A41B-8B7F1B0AFB40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D534C60C-4E04-421E-A41B-8B7F1B0AFB40}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P12/WindowsFormsApplication1/App.config b/Codes.C#/P12/WindowsFormsApplication1/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P12/WindowsFormsApplication1/MainForm.Designer.cs b/Codes.C#/P12/WindowsFormsApplication1/MainForm.Designer.cs new file mode 100644 index 0000000..ef7d9f8 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/MainForm.Designer.cs @@ -0,0 +1,96 @@ +namespace WindowsFormsApplication1 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(94, 59); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(121, 20); + this.comboBox1.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(5, 62); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(83, 12); + this.label1.TabIndex = 1; + this.label1.Text = "Cancer Test:"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(7, 135); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(384, 60); + this.textBox1.TabIndex = 2; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(316, 62); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 3; + this.button1.Text = "计算"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(402, 262); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBox1); + this.Name = "MainForm"; + this.Text = "MainForm"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; + } +} + diff --git a/Codes.C#/P12/WindowsFormsApplication1/MainForm.cs b/Codes.C#/P12/WindowsFormsApplication1/MainForm.cs new file mode 100644 index 0000000..48baf59 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/MainForm.cs @@ -0,0 +1,45 @@ +using System; +using System.Windows.Forms; + +namespace WindowsFormsApplication1 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + comboBox1.Items.Add("positive"); + comboBox1.Items.Add("negative"); + comboBox1.Text = "positive"; + } + + private void button1_Click(object sender, EventArgs e) + { + double pCan = 0.001; + double pNon = 0.999; + string z = comboBox1.Text; + double pPosCan = 0.8; + double pPosNon = 0.1; + double[] p; + textBox1.Text = ""; + + if (z == "positive") + { + p = new[] { pPosCan * pCan, pPosNon * pNon }; + } + else if(z == "negative") + { + p = new[] { (1 - pPosCan) * pCan, (1 - pPosNon) * pNon }; + } + else + { + textBox1.Text = "\"Cancer Test\"的值不正确"; + return; + } + + p = new[] { p[0] / (p[0] + p[1]), p[1] / (p[0] + p[1]) }; + textBox1.Text = string.Format("The probability of having cancer given the {0} test:{1}\r\n", z, p[0]); + textBox1.Text += string.Format("The probability of cancer free given the {0} test:{1}\r\n", z, p[1]); + } + } +} diff --git a/Codes.C#/P12/WindowsFormsApplication1/MainForm.resx b/Codes.C#/P12/WindowsFormsApplication1/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P12/WindowsFormsApplication1/P12.csproj b/Codes.C#/P12/WindowsFormsApplication1/P12.csproj new file mode 100644 index 0000000..9caba82 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/P12.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {D534C60C-4E04-421E-A41B-8B7F1B0AFB40} + WinExe + Properties + P12 + P12 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P12/WindowsFormsApplication1/Program.cs b/Codes.C#/P12/WindowsFormsApplication1/Program.cs new file mode 100644 index 0000000..980be59 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace WindowsFormsApplication1 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P12/WindowsFormsApplication1/Properties/AssemblyInfo.cs b/Codes.C#/P12/WindowsFormsApplication1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..92403e4 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("WindowsFormsApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsApplication1")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("18b697e2-46c5-4b02-b337-a0c3bfe46b6d")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P12/WindowsFormsApplication1/Properties/Resources.Designer.cs b/Codes.C#/P12/WindowsFormsApplication1/Properties/Resources.Designer.cs new file mode 100644 index 0000000..bc25254 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace P12.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [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("P12.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [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/Codes.C#/P12/WindowsFormsApplication1/Properties/Resources.resx b/Codes.C#/P12/WindowsFormsApplication1/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P12/WindowsFormsApplication1/Properties/Settings.Designer.cs b/Codes.C#/P12/WindowsFormsApplication1/Properties/Settings.Designer.cs new file mode 100644 index 0000000..e7f9acc --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace P12.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P12/WindowsFormsApplication1/Properties/Settings.settings b/Codes.C#/P12/WindowsFormsApplication1/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P12/WindowsFormsApplication1/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P13/P13.sln b/Codes.C#/P13/P13.sln new file mode 100644 index 0000000..8762d6f --- /dev/null +++ b/Codes.C#/P13/P13.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P13", "P13\P13.csproj", "{FC7D9704-5A80-4DA7-9187-1078C4808304}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FC7D9704-5A80-4DA7-9187-1078C4808304}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC7D9704-5A80-4DA7-9187-1078C4808304}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC7D9704-5A80-4DA7-9187-1078C4808304}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC7D9704-5A80-4DA7-9187-1078C4808304}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P13/P13/App.config b/Codes.C#/P13/P13/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P13/P13/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P13/P13/Form1.Designer.cs b/Codes.C#/P13/P13/Form1.Designer.cs new file mode 100644 index 0000000..227cc54 --- /dev/null +++ b/Codes.C#/P13/P13/Form1.Designer.cs @@ -0,0 +1,163 @@ +namespace P13 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.tBData = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.tBMean = new System.Windows.Forms.TextBox(); + this.tBVarience = new System.Windows.Forms.TextBox(); + this.tBStd = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // tBData + // + this.tBData.Location = new System.Drawing.Point(92, 40); + this.tBData.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tBData.Name = "tBData"; + this.tBData.Size = new System.Drawing.Size(269, 25); + this.tBData.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(16, 44); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(52, 15); + this.label1.TabIndex = 1; + this.label1.Text = "数据:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(16, 100); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(52, 15); + this.label2.TabIndex = 2; + this.label2.Text = "均值:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(16, 158); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(52, 15); + this.label3.TabIndex = 3; + this.label3.Text = "方差:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(16, 216); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(67, 15); + this.label4.TabIndex = 4; + this.label4.Text = "标准差:"; + // + // tBMean + // + this.tBMean.Location = new System.Drawing.Point(92, 96); + this.tBMean.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tBMean.Name = "tBMean"; + this.tBMean.ReadOnly = true; + this.tBMean.Size = new System.Drawing.Size(132, 25); + this.tBMean.TabIndex = 0; + // + // tBVarience + // + this.tBVarience.Location = new System.Drawing.Point(92, 154); + this.tBVarience.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tBVarience.Name = "tBVarience"; + this.tBVarience.ReadOnly = true; + this.tBVarience.Size = new System.Drawing.Size(132, 25); + this.tBVarience.TabIndex = 0; + // + // tBStd + // + this.tBStd.Location = new System.Drawing.Point(95, 212); + this.tBStd.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tBStd.Name = "tBStd"; + this.tBStd.ReadOnly = true; + this.tBStd.Size = new System.Drawing.Size(132, 25); + this.tBStd.TabIndex = 0; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(121, 275); + this.button1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(79, 28); + this.button1.TabIndex = 5; + this.button1.Text = "计算"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(379, 328); + this.Controls.Add(this.button1); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.tBStd); + this.Controls.Add(this.tBVarience); + this.Controls.Add(this.tBMean); + this.Controls.Add(this.tBData); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox tBData; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox tBMean; + private System.Windows.Forms.TextBox tBVarience; + private System.Windows.Forms.TextBox tBStd; + private System.Windows.Forms.Button button1; + } +} + diff --git a/Codes.C#/P13/P13/Form1.cs b/Codes.C#/P13/P13/Form1.cs new file mode 100644 index 0000000..e4b2994 --- /dev/null +++ b/Codes.C#/P13/P13/Form1.cs @@ -0,0 +1,74 @@ +using System; +using System.Linq; +using System.Windows.Forms; + +namespace P13 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + this.StartPosition = FormStartPosition.CenterScreen; + } + + private void button1_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrEmpty(tBData.Text)) + { + throw new Exception("输入为空!"); + } + string[] strData = new string[] { }; + strData = tBData.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + if (strData.Contains(",")) + { + strData = tBData.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + } + if (strData.Length == 0) + { + throw new Exception("输入为空!"); + } + + double[] dData = new double[strData.Length]; + for (int i = 0; i < strData.Length; i++) + { + if (!double.TryParse(strData[i], out dData[i])) + { + throw new Exception("请输入有效数据!"); + } + } + double mean = 0.0; + double varience = 0.0; + varience = Varience(dData, out mean); + tBMean.Text = mean.ToString("F4"); + tBVarience.Text = varience.ToString("F4"); + tBStd.Text = Math.Sqrt(varience).ToString("F4"); + } + + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private double Varience(double[] dData,out double mean) + { + double sum = 0; + double varience = 0.0; + int l = dData.Length; + for(int i = 0;i < l;i++) + { + sum += dData[i]; + } + mean = sum / l; + for(int i = 0;i < l;i++) + { + varience += (dData[i] - mean) * (dData[i] - mean); + } + varience = varience / l; + return varience; + } + } +} diff --git a/Codes.C#/P13/P13/Form1.resx b/Codes.C#/P13/P13/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P13/P13/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P13/P13/P13.csproj b/Codes.C#/P13/P13/P13.csproj new file mode 100644 index 0000000..cc1279b --- /dev/null +++ b/Codes.C#/P13/P13/P13.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {FC7D9704-5A80-4DA7-9187-1078C4808304} + WinExe + Properties + P13 + P13 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P13/P13/Program.cs b/Codes.C#/P13/P13/Program.cs new file mode 100644 index 0000000..48aced2 --- /dev/null +++ b/Codes.C#/P13/P13/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P13 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P13/P13/Properties/AssemblyInfo.cs b/Codes.C#/P13/P13/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9da32e2 --- /dev/null +++ b/Codes.C#/P13/P13/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P13")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P13")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("c13ca56e-8c46-463b-954e-f4f92024da1e")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P13/P13/Properties/Resources.Designer.cs b/Codes.C#/P13/P13/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0f83480 --- /dev/null +++ b/Codes.C#/P13/P13/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P13.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P13.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P13/P13/Properties/Resources.resx b/Codes.C#/P13/P13/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P13/P13/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P13/P13/Properties/Settings.Designer.cs b/Codes.C#/P13/P13/Properties/Settings.Designer.cs new file mode 100644 index 0000000..6ce0926 --- /dev/null +++ b/Codes.C#/P13/P13/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P13.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P13/P13/Properties/Settings.settings b/Codes.C#/P13/P13/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P13/P13/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P17/P17.sln b/Codes.C#/P17/P17.sln new file mode 100644 index 0000000..e363dd3 --- /dev/null +++ b/Codes.C#/P17/P17.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P17", "P17\P17.csproj", "{F7E30224-4D22-4048-8EB1-21B1BD8ACB8A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F7E30224-4D22-4048-8EB1-21B1BD8ACB8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7E30224-4D22-4048-8EB1-21B1BD8ACB8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7E30224-4D22-4048-8EB1-21B1BD8ACB8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7E30224-4D22-4048-8EB1-21B1BD8ACB8A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P17/P17/App.config b/Codes.C#/P17/P17/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P17/P17/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P17/P17/Form1.Designer.cs b/Codes.C#/P17/P17/Form1.Designer.cs new file mode 100644 index 0000000..89c511a --- /dev/null +++ b/Codes.C#/P17/P17/Form1.Designer.cs @@ -0,0 +1,112 @@ +namespace P17 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisX.Title = "x"; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.Title = "P(x)"; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(0, 25); + this.chart1.Margin = new System.Windows.Forms.Padding(4); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series1.Legend = "Legend1"; + series1.LegendText = "高斯分布"; + series1.Name = "Series1"; + series2.ChartArea = "ChartArea1"; + series2.Legend = "Legend1"; + series2.LegendText = "均值"; + series2.Name = "Series2"; + this.chart1.Series.Add(series1); + this.chart1.Series.Add(series2); + this.chart1.Size = new System.Drawing.Size(608, 375); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(171, 6); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(159, 15); + this.label1.TabIndex = 1; + this.label1.Text = "均值:5,标准差:0.5"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(125, 409); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(55, 15); + this.label2.TabIndex = 2; + this.label2.Text = "label2"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(609, 433); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.chart1); + this.Margin = new System.Windows.Forms.Padding(4); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + } +} + diff --git a/Codes.C#/P17/P17/Form1.cs b/Codes.C#/P17/P17/Form1.cs new file mode 100644 index 0000000..745fbb8 --- /dev/null +++ b/Codes.C#/P17/P17/Form1.cs @@ -0,0 +1,50 @@ +using System; +using System.Windows.Forms; + +namespace P17 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + print(); + } + void print() + { + double x = -1.99; + int mu = 5; + double sigma = 0.5; + double[] xx = new double[1400]; + double[] res = new double[1400]; + double max = 0.0; + double integration = 0.0; + for(int i = 0;i < 1400;i++) + { + //xx[i-1] = -2 + i / 100.0; + xx[i] = x; + res[i] = gaussian1d(mu, sigma, x); + integration += 0.01 * res[i]; + x += 0.01; + + if(max < res[i]) + { + max = res[i]; + } + } + label2.Text = "The integration of p with respect to x is " + integration.ToString("F4"); + //chart1.ChartAreas[0].AxisY.Minimum = -2; + chart1.Series[0].Points.DataBindXY(xx,res); + chart1.Series[1]["PointWidth"] = "0.1"; //柱子宽度 + chart1.Series[1].Points.AddXY(5, max); + } + + double gaussian1d(int mu, double sigma, double x) + { + double p; + + p = 1 / (sigma * Math.Sqrt(2 * Math.PI)) * Math.Exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)); + return p; + } + } +} diff --git a/Codes.C#/P17/P17/Form1.resx b/Codes.C#/P17/P17/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P17/P17/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P17/P17/P17.csproj b/Codes.C#/P17/P17/P17.csproj new file mode 100644 index 0000000..eb4d80e --- /dev/null +++ b/Codes.C#/P17/P17/P17.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {F7E30224-4D22-4048-8EB1-21B1BD8ACB8A} + WinExe + Properties + P17 + P17 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P17/P17/Program.cs b/Codes.C#/P17/P17/Program.cs new file mode 100644 index 0000000..c321fda --- /dev/null +++ b/Codes.C#/P17/P17/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P17 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P17/P17/Properties/AssemblyInfo.cs b/Codes.C#/P17/P17/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f92a515 --- /dev/null +++ b/Codes.C#/P17/P17/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P17")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P17")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("8aeccd2f-a23d-4de9-bdbe-1273165d75d5")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P17/P17/Properties/Resources.Designer.cs b/Codes.C#/P17/P17/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f65c31b --- /dev/null +++ b/Codes.C#/P17/P17/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P17.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P17.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P17/P17/Properties/Resources.resx b/Codes.C#/P17/P17/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P17/P17/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P17/P17/Properties/Settings.Designer.cs b/Codes.C#/P17/P17/Properties/Settings.Designer.cs new file mode 100644 index 0000000..7cd4cd3 --- /dev/null +++ b/Codes.C#/P17/P17/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P17.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P17/P17/Properties/Settings.settings b/Codes.C#/P17/P17/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P17/P17/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P19/P19.sln b/Codes.C#/P19/P19.sln new file mode 100644 index 0000000..8cbc61f --- /dev/null +++ b/Codes.C#/P19/P19.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P19", "P19\P19.csproj", "{23064594-BBD7-4C83-B57E-24037A97D8A5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {23064594-BBD7-4C83-B57E-24037A97D8A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23064594-BBD7-4C83-B57E-24037A97D8A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23064594-BBD7-4C83-B57E-24037A97D8A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23064594-BBD7-4C83-B57E-24037A97D8A5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P19/P19/App.config b/Codes.C#/P19/P19/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P19/P19/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P19/P19/Form1.Designer.cs b/Codes.C#/P19/P19/Form1.Designer.cs new file mode 100644 index 0000000..757d305 --- /dev/null +++ b/Codes.C#/P19/P19/Form1.Designer.cs @@ -0,0 +1,166 @@ +namespace P19 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + this.chart1.Anchor = System.Windows.Forms.AnchorStyles.Top; + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.MinorGrid.Enabled = true; + chartArea1.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; + chartArea1.AxisY.Title = "Probability"; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(23, 3); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series1.Legend = "Legend1"; + series1.LegendText = "Prior"; + series1.Name = "Series1"; + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series2.Legend = "Legend1"; + series2.LegendText = "Motion model"; + series2.Name = "Series2"; + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series3.Legend = "Legend1"; + series3.LegendText = "Predicted prob"; + series3.Name = "Series3"; + this.chart1.Series.Add(series1); + this.chart1.Series.Add(series2); + this.chart1.Series.Add(series3); + this.chart1.Size = new System.Drawing.Size(1741, 320); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + this.chart2.Anchor = System.Windows.Forms.AnchorStyles.Top; + chartArea2.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisY.MinorGrid.Enabled = true; + chartArea2.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; + chartArea2.AxisY.Title = "Probability"; + chartArea2.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.chart2.Legends.Add(legend2); + this.chart2.Location = new System.Drawing.Point(23, 320); + this.chart2.Name = "chart2"; + series4.ChartArea = "ChartArea1"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series4.Legend = "Legend1"; + series4.LegendText = "Predicted prob"; + series4.Name = "Series1"; + series5.ChartArea = "ChartArea1"; + series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series5.Legend = "Legend1"; + series5.LegendText = "Sensor model"; + series5.Name = "Series2"; + series6.ChartArea = "ChartArea1"; + series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series6.Legend = "Legend1"; + series6.LegendText = "Posterior"; + series6.Name = "Series3"; + this.chart2.Series.Add(series4); + this.chart2.Series.Add(series5); + this.chart2.Series.Add(series6); + this.chart2.Size = new System.Drawing.Size(1741, 318); + this.chart2.TabIndex = 1; + this.chart2.Text = "chart2"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(623, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(223, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Bayes Filtering(Prediction)"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(706, 308); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(55, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Update"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1841, 638); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "Form1"; + this.Text = "Form1"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + } +} + diff --git a/Codes.C#/P19/P19/Form1.cs b/Codes.C#/P19/P19/Form1.cs new file mode 100644 index 0000000..7e88efd --- /dev/null +++ b/Codes.C#/P19/P19/Form1.cs @@ -0,0 +1,120 @@ +using System; +using System.Windows.Forms; + +namespace P19 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + print(); + } + double[] prior = new double[2000]; + double[] motionModel = new double[2000]; + double[] sensorModel = new double[2000]; + double[] probAfterMove = new double[2000]; + double[] probAfterSense = new double[2000]; + double x = -9.99; + double[] xx = new double[2000]; + + void print() + { + try + { + //x = -10:0.01:10; + for (int i = 0; i < 2000; i++) + { + prior[i] = gaussian1d(2, 1, x); // a Gaussian Prior of mean 2 and SD 1 + motionModel[i] = gaussian1d(1, 2, x); // a Gaussian motion model of mean 1 and SD 2 + sensorModel[i] = gaussian1d(5, 1, x); // a Gaussian observation model of mean 5 and SD 1 + + chart1.Series[0].Points.AddXY(x, prior[i]); + chart1.Series[1].Points.AddXY(x, motionModel[i]); + + chart2.Series[1].Points.AddXY(x, sensorModel[i]); + + xx[i] = x; + x += 0.01; + } + probAfterMove = Convoltion(motionModel, prior,2000); // prediction is convolution + probAfterSense = product1d(sensorModel, probAfterMove); // update is multiplication + + chart1.Series[2].Points.DataBindXY(xx, probAfterMove); + //chart1.Series[2].Points.DataBindY(probAfterMove); + chart2.Series[0].Points.DataBindXY(xx, probAfterMove); + chart2.Series[2].Points.DataBindXY(xx, probAfterSense); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + + } + + private double[] product1d(double[] X, double[] Y) + { + int Xl = X.Length; + int Yl = Y.Length; + double[] result = new double[Xl]; + double integration = 0.0; + + if (Xl != Yl) + { + throw new Exception("概率数组必须有相同长度!"); + } + for(int i = 0;i < Xl;i++) + { + result[i] = X[i] * Y[i]; + integration += result[i] * 0.01; + } + + for (int i = 0; i < Xl;i++ ) + { + result[i] = result[i] / integration; // normalization + } + return result; + } + + double[] Convoltion(double[] X,double[] Y,int N) // matlab:conv(X,Y,'same'); + { + int L = X.Length + Y.Length - 1; + int halfL = L / 2; + int halfN = N / 2; + double[] result = new double[L]; + double[] sameresult = new double[N]; + double P = new double(); + double integration = 0.0; // 积分 + int k = 0; + for (int i = halfL - halfN + 1; i <= halfL + halfN; i++) + { + for (int j = 0; j < X.Length; j++) + { + if ((j <= i) & (i - j) < Y.Length) + { + P = X[j] * Y[i - j]; + result[i] += P; + } + } + sameresult[k] = result[i]; + integration += sameresult[k] * 0.01; // 积分 + k++; + } + + for (int i = 0; i < N; i++) + { + sameresult[i] = sameresult[i] / integration; // normalization + } + + return sameresult; + } + + double gaussian1d(int mu, double sigma, double x) + { + double p; + + p = 1 / (sigma * Math.Sqrt(2 * Math.PI)) * Math.Exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)); + return p; + } + } +} diff --git a/Codes.C#/P19/P19/Form1.resx b/Codes.C#/P19/P19/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P19/P19/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P19/P19/P19.csproj b/Codes.C#/P19/P19/P19.csproj new file mode 100644 index 0000000..b232854 --- /dev/null +++ b/Codes.C#/P19/P19/P19.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {23064594-BBD7-4C83-B57E-24037A97D8A5} + WinExe + Properties + P19 + P19 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P19/P19/Program.cs b/Codes.C#/P19/P19/Program.cs new file mode 100644 index 0000000..6644963 --- /dev/null +++ b/Codes.C#/P19/P19/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P19 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P19/P19/Properties/AssemblyInfo.cs b/Codes.C#/P19/P19/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..840ce42 --- /dev/null +++ b/Codes.C#/P19/P19/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P19")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P19")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("de2e3484-79d5-4e24-8883-e8309d01ddfe")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P19/P19/Properties/Resources.Designer.cs b/Codes.C#/P19/P19/Properties/Resources.Designer.cs new file mode 100644 index 0000000..cb5e3b6 --- /dev/null +++ b/Codes.C#/P19/P19/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P19.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P19.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P19/P19/Properties/Resources.resx b/Codes.C#/P19/P19/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P19/P19/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P19/P19/Properties/Settings.Designer.cs b/Codes.C#/P19/P19/Properties/Settings.Designer.cs new file mode 100644 index 0000000..5a474fa --- /dev/null +++ b/Codes.C#/P19/P19/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P19.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P19/P19/Properties/Settings.settings b/Codes.C#/P19/P19/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P19/P19/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P2/P2.sln b/Codes.C#/P2/P2.sln new file mode 100644 index 0000000..768e661 --- /dev/null +++ b/Codes.C#/P2/P2.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P2", "P2\P2.csproj", "{7209537D-BDE6-491E-A876-0E34ADD6FC8E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7209537D-BDE6-491E-A876-0E34ADD6FC8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7209537D-BDE6-491E-A876-0E34ADD6FC8E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7209537D-BDE6-491E-A876-0E34ADD6FC8E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7209537D-BDE6-491E-A876-0E34ADD6FC8E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P2/P2/App.config b/Codes.C#/P2/P2/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P2/P2/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P2/P2/MainForm.Designer.cs b/Codes.C#/P2/P2/MainForm.Designer.cs new file mode 100644 index 0000000..2b9d66a --- /dev/null +++ b/Codes.C#/P2/P2/MainForm.Designer.cs @@ -0,0 +1,165 @@ +namespace P2 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend6 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart3 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); + this.cBObservation = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart3)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea4.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.AxisX.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.AxisX.Title = "Position"; + chartArea4.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.AxisY.Title = "Probability of being at the position"; + chartArea4.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea4); + legend4.Name = "Legend1"; + this.chart1.Legends.Add(legend4); + this.chart1.Location = new System.Drawing.Point(27, 104); + this.chart1.Name = "chart1"; + series4.ChartArea = "ChartArea1"; + series4.IsXValueIndexed = true; + series4.Legend = "Legend1"; + series4.LegendText = "Prior"; + series4.Name = "Series1"; + this.chart1.Series.Add(series4); + this.chart1.Size = new System.Drawing.Size(300, 300); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + chartArea5.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea5.AxisX.Title = "Position"; + chartArea5.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea5.AxisY.Title = "Likelihood"; + chartArea5.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea5); + legend5.Name = "Legend1"; + this.chart2.Legends.Add(legend5); + this.chart2.Location = new System.Drawing.Point(349, 104); + this.chart2.Name = "chart2"; + series5.ChartArea = "ChartArea1"; + series5.IsXValueIndexed = true; + series5.Legend = "Legend1"; + series5.LegendText = "Observation"; + series5.Name = "Series1"; + this.chart2.Series.Add(series5); + this.chart2.Size = new System.Drawing.Size(300, 300); + this.chart2.TabIndex = 1; + this.chart2.Text = "chart2"; + // + // chart3 + // + chartArea6.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea6.AxisX.Title = "Position"; + chartArea6.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea6.AxisY.Title = "Probability of being at the position"; + chartArea6.Name = "ChartArea1"; + this.chart3.ChartAreas.Add(chartArea6); + legend6.Name = "Legend1"; + this.chart3.Legends.Add(legend6); + this.chart3.Location = new System.Drawing.Point(674, 104); + this.chart3.Name = "chart3"; + series6.ChartArea = "ChartArea1"; + series6.IsXValueIndexed = true; + series6.Legend = "Legend1"; + series6.LegendText = "Posterior"; + series6.Name = "Series1"; + this.chart3.Series.Add(series6); + this.chart3.Size = new System.Drawing.Size(300, 300); + this.chart3.TabIndex = 2; + this.chart3.Text = "chart3"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 4; + this.label1.Text = "观测值"; + // + // cBObservation + // + this.cBObservation.FormattingEnabled = true; + this.cBObservation.Location = new System.Drawing.Point(53, 26); + this.cBObservation.Name = "cBObservation"; + this.cBObservation.Size = new System.Drawing.Size(90, 20); + this.cBObservation.TabIndex = 5; + this.cBObservation.SelectedIndexChanged += new System.EventHandler(this.cBObservation_SelectedIndexChanged); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1004, 429); + this.Controls.Add(this.cBObservation); + this.Controls.Add(this.label1); + this.Controls.Add(this.chart3); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.MainForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart3)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + private System.Windows.Forms.DataVisualization.Charting.Chart chart3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cBObservation; + } +} + diff --git a/Codes.C#/P2/P2/MainForm.cs b/Codes.C#/P2/P2/MainForm.cs new file mode 100644 index 0000000..6ea65dc --- /dev/null +++ b/Codes.C#/P2/P2/MainForm.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace P2 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + private void MainForm_Load(object sender, EventArgs e) + { + cBObservation.Items.Add("red"); + cBObservation.Items.Add("green"); + cBObservation.Text = "red"; + PaintHist(); + } + + private void cBObservation_SelectedIndexChanged(object sender, EventArgs e) + { + PaintHist(); + } + + private void PaintHist() + { + string[] world = { "green", "red", "red", "green", "green" }; // Map + List prior = new List{ 0.2, 0.2, 0.2, 0.2, 0.2 }; // Prior + string observation = cBObservation.Text; // Observation + double pHit = 0.6; // Observation model + double pMiss = 0.2; + List likelihood; + List posterior; + posterior = Robot.ClassRobot.Sense(prior, observation, world, pHit, pMiss, out likelihood); // Update + //绘图 + chart1.Series[0].Points.DataBindY(prior); + chart2.Series[0].Points.DataBindY(likelihood); + chart3.Series[0].Points.DataBindY(posterior); + } + } +} diff --git a/Codes.C#/P2/P2/MainForm.resx b/Codes.C#/P2/P2/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P2/P2/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P2/P2/P2.csproj b/Codes.C#/P2/P2/P2.csproj new file mode 100644 index 0000000..35588df --- /dev/null +++ b/Codes.C#/P2/P2/P2.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {7209537D-BDE6-491E-A876-0E34ADD6FC8E} + WinExe + Properties + P2 + P2 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + .\Robot.dll + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P2/P2/Program.cs b/Codes.C#/P2/P2/Program.cs new file mode 100644 index 0000000..7ec5628 --- /dev/null +++ b/Codes.C#/P2/P2/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P2 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P2/P2/Properties/AssemblyInfo.cs b/Codes.C#/P2/P2/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..008c50b --- /dev/null +++ b/Codes.C#/P2/P2/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P2")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("74090b68-a58e-4903-a2d6-55cccc6fd4e5")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P2/P2/Properties/Resources.Designer.cs b/Codes.C#/P2/P2/Properties/Resources.Designer.cs new file mode 100644 index 0000000..4aa30f7 --- /dev/null +++ b/Codes.C#/P2/P2/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P2.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P2.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P2/P2/Properties/Resources.resx b/Codes.C#/P2/P2/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P2/P2/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P2/P2/Properties/Settings.Designer.cs b/Codes.C#/P2/P2/Properties/Settings.Designer.cs new file mode 100644 index 0000000..19d9025 --- /dev/null +++ b/Codes.C#/P2/P2/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P2.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P2/P2/Properties/Settings.settings b/Codes.C#/P2/P2/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P2/P2/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P2/P2/Robot.dll b/Codes.C#/P2/P2/Robot.dll new file mode 100644 index 0000000..be7bc22 Binary files /dev/null and b/Codes.C#/P2/P2/Robot.dll differ diff --git a/Codes.C#/P20/P20.sln b/Codes.C#/P20/P20.sln new file mode 100644 index 0000000..353be9f --- /dev/null +++ b/Codes.C#/P20/P20.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P20", "P20\P20.csproj", "{17359A9F-8ABC-47E5-BEC0-D258EDCE4757}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {17359A9F-8ABC-47E5-BEC0-D258EDCE4757}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17359A9F-8ABC-47E5-BEC0-D258EDCE4757}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17359A9F-8ABC-47E5-BEC0-D258EDCE4757}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17359A9F-8ABC-47E5-BEC0-D258EDCE4757}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P20/P20/App.config b/Codes.C#/P20/P20/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P20/P20/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P20/P20/Form1.Designer.cs b/Codes.C#/P20/P20/Form1.Designer.cs new file mode 100644 index 0000000..363abba --- /dev/null +++ b/Codes.C#/P20/P20/Form1.Designer.cs @@ -0,0 +1,187 @@ +namespace P20 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series9 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series10 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea3.AxisX.Interval = 5D; + chartArea3.AxisX.MajorGrid.Interval = 5D; + chartArea3.AxisX.MajorTickMark.Interval = 5D; + chartArea3.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea3.AxisX.MinorGrid.Enabled = true; + chartArea3.AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; + chartArea3.AxisX.MinorTickMark.Enabled = true; + chartArea3.AxisX.MinorTickMark.Interval = 1D; + chartArea3.AxisX.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea3.AxisX.ScaleBreakStyle.Spacing = 5D; + chartArea3.AxisX2.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.False; + chartArea3.AxisX2.IsLabelAutoFit = false; + chartArea3.AxisX2.LabelStyle.Enabled = false; + chartArea3.AxisX2.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea3.AxisY.MajorTickMark.Interval = 0D; + chartArea3.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea3.AxisY.MinorGrid.Enabled = true; + chartArea3.AxisY.MinorGrid.Interval = 0.01D; + chartArea3.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; + chartArea3.AxisY.MinorTickMark.Enabled = true; + chartArea3.AxisY.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea3.AxisY.Title = "Probability"; + chartArea3.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea3); + legend3.Name = "Legend1"; + this.chart1.Legends.Add(legend3); + this.chart1.Location = new System.Drawing.Point(28, 28); + this.chart1.Name = "chart1"; + series6.ChartArea = "ChartArea1"; + series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series6.Legend = "Legend1"; + series6.LegendText = "Predicted prob"; + series6.Name = "Series1"; + series7.ChartArea = "ChartArea1"; + series7.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series7.Legend = "Legend1"; + series7.LegendText = "Predicted prob with params"; + series7.Name = "Series2"; + this.chart1.Series.Add(series6); + this.chart1.Series.Add(series7); + this.chart1.Size = new System.Drawing.Size(1514, 303); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + chartArea4.AxisX.Interval = 5D; + chartArea4.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea4.AxisX.MinorGrid.Enabled = true; + chartArea4.AxisX.MinorGrid.Interval = 1D; + chartArea4.AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; + chartArea4.AxisX.MinorTickMark.Enabled = true; + chartArea4.AxisX.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea4.AxisX2.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.False; + chartArea4.AxisX2.IsLabelAutoFit = false; + chartArea4.AxisX2.LabelStyle.Enabled = false; + chartArea4.AxisX2.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea4.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea4.AxisY.MinorGrid.Enabled = true; + chartArea4.AxisY.MinorGrid.Interval = 0.02D; + chartArea4.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; + chartArea4.AxisY.MinorTickMark.Enabled = true; + chartArea4.AxisY.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.InsideArea; + chartArea4.AxisY.Title = "Probability"; + chartArea4.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea4); + legend4.Name = "Legend1"; + this.chart2.Legends.Add(legend4); + this.chart2.Location = new System.Drawing.Point(28, 337); + this.chart2.Name = "chart2"; + series8.ChartArea = "ChartArea1"; + series8.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series8.Legend = "Legend1"; + series8.LegendText = "Posterior"; + series8.Name = "Series1"; + series9.ChartArea = "ChartArea1"; + series9.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series9.Legend = "Legend1"; + series9.LegendText = "Posterior with params as input and output"; + series9.Name = "Series2"; + series10.ChartArea = "ChartArea1"; + series10.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series10.Legend = "Legend1"; + series10.LegendText = "Posterior with params as input"; + series10.Name = "Series3"; + this.chart2.Series.Add(series8); + this.chart2.Series.Add(series9); + this.chart2.Series.Add(series10); + this.chart2.Size = new System.Drawing.Size(1514, 303); + this.chart2.TabIndex = 0; + this.chart2.Text = "chart1"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(612, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(223, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Bayes filtering(Pridiction)"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(696, 334); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(55, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Update"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1559, 620); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "Form1"; + this.Text = "Form1"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + } +} + diff --git a/Codes.C#/P20/P20/Form1.cs b/Codes.C#/P20/P20/Form1.cs new file mode 100644 index 0000000..b662336 --- /dev/null +++ b/Codes.C#/P20/P20/Form1.cs @@ -0,0 +1,152 @@ +using System; +using System.Windows.Forms; + +namespace P20 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + print(); + } + static int arrayL = 2000; + double[] prior = new double[arrayL]; + double[] motionModel = new double[arrayL]; + double[] sensorModel = new double[arrayL]; + double[] probAfterMove = new double[arrayL]; + double[] probAfterSense = new double[arrayL]; + double[] probAfterMoveParam = new double[arrayL]; + double[] probAfterSenseParam = new double[arrayL]; + double[] probAfterSenseParamSeq = new double[arrayL]; + + double[] paraAfterMove = new double[2]; + double[] paraAfterSense = new double[2]; + + double x = -9.9; + double[] xx = new double[arrayL]; + + void print() + { + //x = -10:0.01:10; + + paraAfterMove = convolute1dParam(2, 1, 1, 2); + paraAfterSense = product1dParam(paraAfterMove[0], paraAfterMove[1], 5, 1); + + for (int i = 0; i < arrayL; i++) + { + prior[i] = gaussian1d(2, 1, x); // a Gaussian Prior of mean 2 and SD 1 + motionModel[i] = gaussian1d(1, 2, x); // a Gaussian motion model of mean 1 and SD 2 + sensorModel[i] = gaussian1d(5, 1, x); // a Gaussian observation model of mean 5 and SD 1 + + probAfterMoveParam[i] = gaussian1d(paraAfterMove[0], paraAfterMove[1], x); + probAfterSenseParam[i] = gaussian1d(paraAfterSense[0], paraAfterSense[1], x); + + + xx[i] = x; + x += 0.01; + } + + probAfterMove = Convoltion1d(motionModel, prior, arrayL); // prediction is convolution + probAfterSense = product1d(sensorModel, probAfterMove); // update is multiplication + + probAfterSenseParamSeq = product1d(sensorModel, probAfterMoveParam); + + chart1.ChartAreas[0].AxisX.Minimum = -5; + chart2.ChartAreas[0].AxisX.Minimum = -5; + chart1.ChartAreas[0].AxisX.Maximum = 10; + chart2.ChartAreas[0].AxisX.Maximum = 10; + + //chart1.Series[0]["PointWidth"] = "20"; + chart1.Series[0].BorderWidth = 5; + chart1.Series[0].Points.DataBindXY(xx, probAfterMove); + chart1.Series[1].Points.DataBindXY(xx, probAfterMoveParam); + + chart2.Series[0].BorderWidth = 5; + chart2.Series[0].Points.DataBindXY(xx, probAfterSense); + chart2.Series[1].Points.DataBindXY(xx, probAfterSenseParam); + chart2.Series[2].Points.DataBindXY(xx, probAfterSenseParamSeq); + } + + private double[] product1dParam(double muAfterMove, double sdAfterMove, double muSensor, double sdSensor) + { + double[] para = new double[2]; + para[0] = (muAfterMove * Math.Pow(sdSensor, 2) + muSensor * Math.Pow(sdAfterMove, 2)) / (Math.Pow(sdAfterMove, 2) + Math.Pow(sdSensor, 2)); + para[1] = (Math.Pow(sdSensor, 2) * Math.Pow(sdAfterMove, 2)) / (Math.Pow(sdAfterMove, 2) + Math.Pow(sdSensor, 2)); + return para; + } + + private double[] convolute1dParam(int muPrior, int sdPrior, int muMotion, int sdMotion) + { + double[] para = new double[2]; + para[0] = muPrior + muMotion; + para[1] = Math.Sqrt(Math.Pow(sdPrior,2) + Math.Pow(sdMotion, 2)); + return para; + } + + private double[] product1d(double[] X, double[] Y) + { + int Xl = X.Length; + int Yl = Y.Length; + double[] result = new double[Xl]; + double integration = 0.0; + + if (Xl != Yl) + { + MessageBox.Show("概率数组必须有相同长度!"); + } + for (int i = 0; i < Xl; i++) + { + result[i] = X[i] * Y[i]; + integration += result[i] * 0.01; + } + + for (int i = 0; i < Xl; i++) + { + result[i] = result[i] / integration; // normalization + } + return result; + } + + double[] Convoltion1d(double[] X, double[] Y, int N) // matlab:conv(X,Y,'same'); + { + int L = X.Length + Y.Length - 1; + int halfL = L / 2; + int halfN = N / 2; + double[] result = new double[L]; + double[] sameresult = new double[N]; + double P = new double(); + double integration = 0.0; // 积分 + int k = 0; + for (int i = halfL - halfN + 1; i <= halfL + halfN; i++) + { + for (int j = 0; j < X.Length; j++) + { + if ((j <= i) & (i - j) < Y.Length) + { + P = X[j] * Y[i - j]; + result[i] += P; + } + } + sameresult[k] = result[i]; + integration += sameresult[k] * 0.01; // 积分 + k++; + } + + for (int i = 0; i < N; i++) + { + sameresult[i] = sameresult[i] / integration; // normalization + } + + return sameresult; + } + + double gaussian1d(double mu, double sigma, double x) + { + double p; + + p = 1 / (sigma * Math.Sqrt(2 * Math.PI)) * Math.Exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)); + return p; + } + } +} diff --git a/Codes.C#/P20/P20/Form1.resx b/Codes.C#/P20/P20/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P20/P20/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P20/P20/P20.csproj b/Codes.C#/P20/P20/P20.csproj new file mode 100644 index 0000000..77e3119 --- /dev/null +++ b/Codes.C#/P20/P20/P20.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {17359A9F-8ABC-47E5-BEC0-D258EDCE4757} + WinExe + Properties + P20 + P20 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P20/P20/Program.cs b/Codes.C#/P20/P20/Program.cs new file mode 100644 index 0000000..c31e375 --- /dev/null +++ b/Codes.C#/P20/P20/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P20 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P20/P20/Properties/AssemblyInfo.cs b/Codes.C#/P20/P20/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a03243c --- /dev/null +++ b/Codes.C#/P20/P20/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P20")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P20")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("18e45d4c-cddb-4527-8198-2b8b5b5be537")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P20/P20/Properties/Resources.Designer.cs b/Codes.C#/P20/P20/Properties/Resources.Designer.cs new file mode 100644 index 0000000..66a83bf --- /dev/null +++ b/Codes.C#/P20/P20/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P20.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P20.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P20/P20/Properties/Resources.resx b/Codes.C#/P20/P20/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P20/P20/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P20/P20/Properties/Settings.Designer.cs b/Codes.C#/P20/P20/Properties/Settings.Designer.cs new file mode 100644 index 0000000..03a1249 --- /dev/null +++ b/Codes.C#/P20/P20/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P20.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P20/P20/Properties/Settings.settings b/Codes.C#/P20/P20/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P20/P20/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P22/P22.sln b/Codes.C#/P22/P22.sln new file mode 100644 index 0000000..8e61b20 --- /dev/null +++ b/Codes.C#/P22/P22.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P22", "P22\P22.csproj", "{2953ADCA-7B83-43B4-A35F-A0450CA01F0B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2953ADCA-7B83-43B4-A35F-A0450CA01F0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2953ADCA-7B83-43B4-A35F-A0450CA01F0B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2953ADCA-7B83-43B4-A35F-A0450CA01F0B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2953ADCA-7B83-43B4-A35F-A0450CA01F0B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P22/P22/App.config b/Codes.C#/P22/P22/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P22/P22/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P22/P22/Form1.Designer.cs b/Codes.C#/P22/P22/Form1.Designer.cs new file mode 100644 index 0000000..1c2a74a --- /dev/null +++ b/Codes.C#/P22/P22/Form1.Designer.cs @@ -0,0 +1,133 @@ +namespace P22 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.tBXwb = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.tBXwa = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.tBXab = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 159); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(39, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Xwb:"; + // + // tBXwb + // + this.tBXwb.Location = new System.Drawing.Point(97, 159); + this.tBXwb.Multiline = true; + this.tBXwb.Name = "tBXwb"; + this.tBXwb.Size = new System.Drawing.Size(100, 51); + this.tBXwb.TabIndex = 1; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(26, 17); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(39, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Xwa:"; + // + // tBXwa + // + this.tBXwa.Location = new System.Drawing.Point(97, 17); + this.tBXwa.Multiline = true; + this.tBXwa.Name = "tBXwa"; + this.tBXwa.Size = new System.Drawing.Size(100, 51); + this.tBXwa.TabIndex = 1; + this.tBXwa.TextChanged += new System.EventHandler(this.tBXwa_TextChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(26, 89); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(39, 15); + this.label3.TabIndex = 2; + this.label3.Text = "Xab:"; + // + // tBXab + // + this.tBXab.Location = new System.Drawing.Point(97, 89); + this.tBXab.Multiline = true; + this.tBXab.Name = "tBXab"; + this.tBXab.Size = new System.Drawing.Size(100, 51); + this.tBXab.TabIndex = 1; + this.tBXab.TextChanged += new System.EventHandler(this.tBXab_TextChanged); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(107, 223); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 33); + this.button1.TabIndex = 3; + this.button1.Text = "计算"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(237, 268); + this.Controls.Add(this.button1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.tBXab); + this.Controls.Add(this.tBXwa); + this.Controls.Add(this.tBXwb); + this.Controls.Add(this.label1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox tBXwb; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox tBXwa; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox tBXab; + private System.Windows.Forms.Button button1; + } +} + diff --git a/Codes.C#/P22/P22/Form1.cs b/Codes.C#/P22/P22/Form1.cs new file mode 100644 index 0000000..b850545 --- /dev/null +++ b/Codes.C#/P22/P22/Form1.cs @@ -0,0 +1,162 @@ +using System; +using System.Windows.Forms; + +namespace P22 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + this.StartPosition = FormStartPosition.CenterScreen; + Detect(); + Compute(); + } + string[] strXwa; + string[] strXab; + double[] Xwa = new double[3]; + double[] Xab = new double[3]; + double[] Xwb = new double[3]; + + private void button1_Click(object sender, EventArgs e) + { + try + { + Detect(); + Compute(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + } + void Detect() + { + if (!string.IsNullOrEmpty(tBXwa.Text)) + { + try + { + if(strXwa.Length != 3) + { + throw new Exception("请在“Xwa”文本框中完整输入3个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 3; i++) + { + if (!double.TryParse(strXwa[i], out Xwa[i])) + { + throw new Exception(("“Xwa”文本框中的输入格式不正确,请重新输入!")); + } + } + Xwa[2] = degtorad(Xwa[2]); + } + catch (Exception ex) + { + throw (ex); + } + } + else + { + Xwa = new[] { 5, 3, degtorad(50) }; + tBXwa.Text = "5" + Environment.NewLine + "3" + Environment.NewLine + "50"; + } + + if (!string.IsNullOrEmpty(tBXab.Text)) + { + try + { + if(strXab.Length != 3) + { + throw new Exception("请在“Xab”文本框中完整输入3个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 3; i++) + { + if (!double.TryParse(strXab[i], out Xab[i])) + { + throw new Exception(("“Xab”文本框中的输入格式不正确,请重新输入!")); + } + } + Xab[2] = degtorad(Xab[2]); + } + catch(Exception ex) + { + throw ex; + } + } + else + { + Xab = new[] { 4, 2, degtorad(20) }; + tBXab.Text = "4" + Environment.NewLine + "2" + Environment.NewLine + "20"; + } + } + + void Compute() + { + Xwb = compound(Xwa, Xab); + tBXwb.Text = ""; + for (int i = 0; i < 3;i++ ) + { + tBXwb.Text += Xwb[i].ToString("F2") + Environment.NewLine; + } + } + + + double[] compound(double[] Xwa, double[] Xab) + { + double[] Xwb = new double[3]; + + double[] rot = {Math.Cos(Xwa[2]),-Math.Sin(Xwa[2]),Math.Sin(Xwa[2]),Math.Cos(Xwa[2])}; + Xwb[0] = rot[0] * Xab[0] + rot[1] * Xab[1] + Xwa[0]; + Xwb[1] = rot[2] * Xab[0] + rot[3] * Xab[1] + Xwa[1]; + Xwb[2] = Xab[2] + Xwa[2]; + + Xwb[2] = piTopi(Xwb[2]); + Xwb[2] = radtodeg(Xwb[2]); + + return Xwb; + } + + private double radtodeg(double rad) + { + return (180 * rad / Math.PI); + } + private double degtorad(double degree) + { + return (degree * Math.PI / 180); + } + + double piTopi(double angle) + { + double twopi = 2 * Math.PI; + angle = angle - twopi * (int)(angle/twopi); // this is a stripped-down version of rem(angle, 2*pi) + + while(angle >= Math.PI) + { + angle -= twopi; + } + while(angle <= -Math.PI) + { + angle += twopi; + } + + return angle; + } + + private void tBXwa_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBXwa.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strXwa = temp.Split(new char[] { ',' }, 3, StringSplitOptions.RemoveEmptyEntries); + } + + private void tBXab_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBXab.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strXab = temp.Split(new char[] { ',' }, 3, StringSplitOptions.RemoveEmptyEntries); + } + } +} diff --git a/Codes.C#/P22/P22/Form1.resx b/Codes.C#/P22/P22/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P22/P22/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P22/P22/P22.csproj b/Codes.C#/P22/P22/P22.csproj new file mode 100644 index 0000000..635a105 --- /dev/null +++ b/Codes.C#/P22/P22/P22.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {2953ADCA-7B83-43B4-A35F-A0450CA01F0B} + WinExe + Properties + P22 + P22 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P22/P22/Program.cs b/Codes.C#/P22/P22/Program.cs new file mode 100644 index 0000000..754ffe0 --- /dev/null +++ b/Codes.C#/P22/P22/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P22 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P22/P22/Properties/AssemblyInfo.cs b/Codes.C#/P22/P22/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7d8b94e --- /dev/null +++ b/Codes.C#/P22/P22/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P22")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P22")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("9db3f4f4-f296-4285-b7d1-294a9b1254d7")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P22/P22/Properties/Resources.Designer.cs b/Codes.C#/P22/P22/Properties/Resources.Designer.cs new file mode 100644 index 0000000..8599b17 --- /dev/null +++ b/Codes.C#/P22/P22/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P22.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P22.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P22/P22/Properties/Resources.resx b/Codes.C#/P22/P22/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P22/P22/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P22/P22/Properties/Settings.Designer.cs b/Codes.C#/P22/P22/Properties/Settings.Designer.cs new file mode 100644 index 0000000..5353caf --- /dev/null +++ b/Codes.C#/P22/P22/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P22.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P22/P22/Properties/Settings.settings b/Codes.C#/P22/P22/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P22/P22/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P23/P23.sln b/Codes.C#/P23/P23.sln new file mode 100644 index 0000000..9ac7570 --- /dev/null +++ b/Codes.C#/P23/P23.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P23", "P23\P23.csproj", "{BA26F46A-5745-4F4A-8EF4-9CFAC93E82F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BA26F46A-5745-4F4A-8EF4-9CFAC93E82F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA26F46A-5745-4F4A-8EF4-9CFAC93E82F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA26F46A-5745-4F4A-8EF4-9CFAC93E82F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA26F46A-5745-4F4A-8EF4-9CFAC93E82F8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P23/P23/App.config b/Codes.C#/P23/P23/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P23/P23/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P23/P23/Form1.Designer.cs b/Codes.C#/P23/P23/Form1.Designer.cs new file mode 100644 index 0000000..5c6cd27 --- /dev/null +++ b/Codes.C#/P23/P23/Form1.Designer.cs @@ -0,0 +1,177 @@ +namespace P23 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.tBXwa = new System.Windows.Forms.TextBox(); + this.tBXad = new System.Windows.Forms.TextBox(); + this.tBXaf = new System.Windows.Forms.TextBox(); + this.tBXwd = new System.Windows.Forms.TextBox(); + this.tBXwf = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(32, 42); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(39, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Xwa:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(32, 96); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(39, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Xad:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(32, 150); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(39, 15); + this.label4.TabIndex = 2; + this.label4.Text = "Xaf:"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(32, 204); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(39, 15); + this.label5.TabIndex = 1; + this.label5.Text = "Xwd:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(32, 258); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(39, 15); + this.label6.TabIndex = 2; + this.label6.Text = "Xwf:"; + // + // tBXwa + // + this.tBXwa.Location = new System.Drawing.Point(97, 39); + this.tBXwa.Name = "tBXwa"; + this.tBXwa.Size = new System.Drawing.Size(173, 25); + this.tBXwa.TabIndex = 3; + this.tBXwa.TextChanged += new System.EventHandler(this.tBXwa_TextChanged); + // + // tBXad + // + this.tBXad.Location = new System.Drawing.Point(97, 93); + this.tBXad.Name = "tBXad"; + this.tBXad.Size = new System.Drawing.Size(173, 25); + this.tBXad.TabIndex = 3; + this.tBXad.TextChanged += new System.EventHandler(this.tBXad_TextChanged); + // + // tBXaf + // + this.tBXaf.Location = new System.Drawing.Point(97, 147); + this.tBXaf.Name = "tBXaf"; + this.tBXaf.Size = new System.Drawing.Size(173, 25); + this.tBXaf.TabIndex = 3; + this.tBXaf.TextChanged += new System.EventHandler(this.tBXaf_TextChanged); + // + // tBXwd + // + this.tBXwd.Location = new System.Drawing.Point(97, 201); + this.tBXwd.Name = "tBXwd"; + this.tBXwd.ReadOnly = true; + this.tBXwd.Size = new System.Drawing.Size(173, 25); + this.tBXwd.TabIndex = 3; + // + // tBXwf + // + this.tBXwf.Location = new System.Drawing.Point(97, 255); + this.tBXwf.Name = "tBXwf"; + this.tBXwf.ReadOnly = true; + this.tBXwf.Size = new System.Drawing.Size(173, 25); + this.tBXwf.TabIndex = 3; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(137, 303); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 27); + this.button1.TabIndex = 4; + this.button1.Text = "计算"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(282, 340); + this.Controls.Add(this.button1); + this.Controls.Add(this.tBXwf); + this.Controls.Add(this.tBXwd); + this.Controls.Add(this.tBXaf); + this.Controls.Add(this.tBXad); + this.Controls.Add(this.tBXwa); + this.Controls.Add(this.label6); + this.Controls.Add(this.label4); + this.Controls.Add(this.label5); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox tBXwa; + private System.Windows.Forms.TextBox tBXad; + private System.Windows.Forms.TextBox tBXaf; + private System.Windows.Forms.TextBox tBXwd; + private System.Windows.Forms.TextBox tBXwf; + private System.Windows.Forms.Button button1; + } +} + diff --git a/Codes.C#/P23/P23/Form1.cs b/Codes.C#/P23/P23/Form1.cs new file mode 100644 index 0000000..8522aa1 --- /dev/null +++ b/Codes.C#/P23/P23/Form1.cs @@ -0,0 +1,205 @@ +using System; +using System.Windows.Forms; + +namespace P23 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + Detect(); + Compute(); + } + double[] Xwa; + double[] Xad; + double[] Xaf; + double[] Xwd; + double[] Xwf; + string[] strXwa; + string[] strXad; + string[] strXaf; + + private void button1_Click(object sender, EventArgs e) + { + try + { + Detect(); + Compute(); + } + + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + } + void Detect() + { + // Xwa + if (!string.IsNullOrEmpty(tBXwa.Text)) + { + try + { + if (strXwa.Length != 3) + { + throw new Exception("请在“Xwa”文本框中完整输入3个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 3; i++) + { + if (!double.TryParse(strXwa[i], out Xwa[i])) + { + throw new Exception(("“Xwa”文本框的输入格式不正确,请重新输入!")); + } + } + Xwa[2] = degtorad(Xwa[2]); + } + catch (Exception ex) + { + throw (ex); + } + } + else + { + Xwa = new[] { 5, 3, degtorad(50) }; + tBXwa.Text = "5.00" + " " + "3.00" + " " + "50.00"; + } + // Xad + if (!string.IsNullOrEmpty(tBXad.Text)) + { + try + { + if (strXad.Length != 2) + { + throw new Exception("请在“Xad”文本框中完整输入2个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 2; i++) + { + if (!double.TryParse(strXad[i], out Xad[i])) + { + throw new Exception(("“Xad”文本框中的输入格式不正确,请重新输入!")); + } + } + } + catch (Exception ex) + { + throw (ex); + } + } + else + { + Xad = new[] { 5.0, 2.0 }; + tBXad.Text = "5.00" + " " + "2.00" ; + } + + // Xaf + if (!string.IsNullOrEmpty(tBXaf.Text)) + { + try + { + if (strXaf.Length != 2) + { + throw new Exception("请在“Xaf”文本框中完整输入2个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 2; i++) + { + if (!double.TryParse(strXwa[i], out Xwa[i])) + { + throw new Exception(("“Xaf”文本框中的输入格式不正确,请重新输入!")); + } + } + } + catch (Exception ex) + { + throw (ex); + } + } + else + { + Xaf = new[] { 3.0, 2.5 }; + tBXaf.Text = "3.00" + " " + "2.50" ; + } + } + void Compute() + { + Xwd = compound(Xwa, Xad); + Xwf = compound(Xwa, Xaf); + // 显示 + tBXwd.Text = ""; + for (int i = 0; i < 2; i++) + { + tBXwd.Text += Xwd[i].ToString("F4") + " "; + } + tBXwd.Text = tBXwd.Text.TrimEnd(' '); + + tBXwf.Text = ""; + for (int i = 0; i < 2; i++) + { + tBXwf.Text += Xwf[i].ToString("F4") + " "; + } + tBXwf.Text = tBXwf.Text.TrimEnd(' '); + } + private double degtorad(double degree) + { + return (degree * Math.PI / 180); + } + double[] compound(double[] Xwa, double[] Xab) + { + double[] Xwb = new double[2]; + + double[] rot = { Math.Cos(Xwa[2]), -Math.Sin(Xwa[2]), Math.Sin(Xwa[2]), Math.Cos(Xwa[2]) }; + Xwb[0] = rot[0] * Xab[0] + rot[1] * Xab[1] + Xwa[0]; + Xwb[1] = rot[2] * Xab[0] + rot[3] * Xab[1] + Xwa[1]; + + return Xwb; + } + private double radtodeg(double rad) + { + return (180 * rad / Math.PI); + } + + double piTopi(double angle) + { + double twopi = 2 * Math.PI; + angle = angle - twopi * (int)(angle / twopi); // this is a stripped-down version of rem(angle, 2*pi) + + while (angle >= Math.PI) + { + angle -= twopi; + } + while (angle <= -Math.PI) + { + angle += twopi; + } + + return angle; + } + + private void tBXwa_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBXwa.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strXwa = temp.Split(new char[] { ',' }, 3, StringSplitOptions.RemoveEmptyEntries); + } + + private void tBXad_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBXad.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strXad = temp.Split(new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries); + } + + private void tBXaf_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBXwa.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strXaf = temp.Split(new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries); + } + + } +} diff --git a/Codes.C#/P23/P23/Form1.resx b/Codes.C#/P23/P23/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P23/P23/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P23/P23/P23.csproj b/Codes.C#/P23/P23/P23.csproj new file mode 100644 index 0000000..1bcba99 --- /dev/null +++ b/Codes.C#/P23/P23/P23.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {BA26F46A-5745-4F4A-8EF4-9CFAC93E82F8} + WinExe + Properties + P23 + P23 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P23/P23/Program.cs b/Codes.C#/P23/P23/Program.cs new file mode 100644 index 0000000..fc26604 --- /dev/null +++ b/Codes.C#/P23/P23/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P23 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P23/P23/Properties/AssemblyInfo.cs b/Codes.C#/P23/P23/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8edb579 --- /dev/null +++ b/Codes.C#/P23/P23/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P23")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P23")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("9fda6c10-6852-400d-b465-2e04c5c31834")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P23/P23/Properties/Resources.Designer.cs b/Codes.C#/P23/P23/Properties/Resources.Designer.cs new file mode 100644 index 0000000..82a0e28 --- /dev/null +++ b/Codes.C#/P23/P23/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P23.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P23.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P23/P23/Properties/Resources.resx b/Codes.C#/P23/P23/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P23/P23/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P23/P23/Properties/Settings.Designer.cs b/Codes.C#/P23/P23/Properties/Settings.Designer.cs new file mode 100644 index 0000000..23ebb7a --- /dev/null +++ b/Codes.C#/P23/P23/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P23.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P23/P23/Properties/Settings.settings b/Codes.C#/P23/P23/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P23/P23/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P27/P27.sln b/Codes.C#/P27/P27.sln new file mode 100644 index 0000000..d1f1ccd --- /dev/null +++ b/Codes.C#/P27/P27.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P27", "P27\P27.csproj", "{EBF784BB-8C2D-46BA-8197-FFD4F755A6D7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EBF784BB-8C2D-46BA-8197-FFD4F755A6D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBF784BB-8C2D-46BA-8197-FFD4F755A6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBF784BB-8C2D-46BA-8197-FFD4F755A6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBF784BB-8C2D-46BA-8197-FFD4F755A6D7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P27/P27/App.config b/Codes.C#/P27/P27/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P27/P27/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P27/P27/Form1.Designer.cs b/Codes.C#/P27/P27/Form1.Designer.cs new file mode 100644 index 0000000..bb682a0 --- /dev/null +++ b/Codes.C#/P27/P27/Form1.Designer.cs @@ -0,0 +1,131 @@ +namespace P27 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.tBXwa = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.tBPab = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.tBXwb = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(39, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Xwa:"; + // + // tBXwa + // + this.tBXwa.Location = new System.Drawing.Point(87, 26); + this.tBXwa.Name = "tBXwa"; + this.tBXwa.Size = new System.Drawing.Size(100, 25); + this.tBXwa.TabIndex = 1; + this.tBXwa.TextChanged += new System.EventHandler(this.tBXwa_TextChanged); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(26, 75); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(39, 15); + this.label2.TabIndex = 0; + this.label2.Text = "Pab:"; + // + // tBPab + // + this.tBPab.Location = new System.Drawing.Point(87, 72); + this.tBPab.Name = "tBPab"; + this.tBPab.Size = new System.Drawing.Size(100, 25); + this.tBPab.TabIndex = 1; + this.tBPab.TextChanged += new System.EventHandler(this.tBPab_TextChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(26, 123); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(39, 15); + this.label3.TabIndex = 0; + this.label3.Text = "Xwb:"; + // + // tBXwb + // + this.tBXwb.Location = new System.Drawing.Point(87, 120); + this.tBXwb.Name = "tBXwb"; + this.tBXwb.ReadOnly = true; + this.tBXwb.Size = new System.Drawing.Size(145, 25); + this.tBXwb.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(96, 192); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 26); + this.button1.TabIndex = 2; + this.button1.Text = "计算"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(282, 253); + this.Controls.Add(this.button1); + this.Controls.Add(this.tBXwb); + this.Controls.Add(this.tBPab); + this.Controls.Add(this.tBXwa); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox tBXwa; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox tBPab; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox tBXwb; + private System.Windows.Forms.Button button1; + } +} + diff --git a/Codes.C#/P27/P27/Form1.cs b/Codes.C#/P27/P27/Form1.cs new file mode 100644 index 0000000..e9d9e25 --- /dev/null +++ b/Codes.C#/P27/P27/Form1.cs @@ -0,0 +1,175 @@ +using System; +using System.Windows.Forms; + +namespace P27 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + this.StartPosition = FormStartPosition.CenterScreen; + Detect(); + Compute(); + } + double[] Xwa; + double[] Pab; + double[] Xab; + double[] Xwb; + + string[] strXwa; + string[] strPab; + + private void button1_Click(object sender, EventArgs e) + { + try + { + Detect(); + Compute(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + void Detect() + { + if (!string.IsNullOrEmpty(tBXwa.Text)) + { + try + { + if (strXwa.Length != 3) + { + throw new Exception("请在“Xwa”文本框中完整输入3个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 3; i++) + { + if (!double.TryParse(strXwa[i], out Xwa[i])) + { + throw new Exception(("“Xwa”文本框中的输入格式不正确,请重新输入!")); + } + } + Xwa[2] = degtorad(Xwa[2]); + } + catch (Exception ex) + { + throw (ex); + } + } + else + { + Xwa = new[] { 5, 3, degtorad(50) }; + tBXwa.Text = "5" + " " + "3" + " " + "50"; + } + + if (!string.IsNullOrEmpty(tBPab.Text)) + { + try + { + if (strPab.Length != 2) + { + throw new Exception("请在“Pab”文本框中完整输入2个参数,以“,”或“ ”为分割。"); + } + for (int i = 0; i < 2; i++) + { + if (!double.TryParse(strPab[i], out Pab[i])) + { + throw new Exception(("“Pab”文本框中的输入格式不正确,请重新输入!")); + } + } + } + catch (Exception ex) + { + throw (ex); + } + } + else + { + Pab = new[] { 7.0, 40.0 }; + tBPab.Text = "7" + " " + "40" ; + } + + Pab[1] = degtorad(Pab[1]); + Xab = pol2cart(Pab); + } + void Compute() + { + Xwb = compound(Xwa, Xab); + tBXwb.Text = ""; + for (int i = 0; i < 3; i++) + { + tBXwb.Text += Xwb[i].ToString("F2") + " "; + } + tBXwb.Text = tBXwb.Text.TrimEnd(' '); + } + + private double[] pol2cart(double[] pol) + { + double[] cart = new double[3]; + cart[0] = pol[0] * Math.Cos(pol[1]); + cart[1] = pol[0] * Math.Sin(pol[1]); + cart[2] = pol[1]; + return cart; + } + double[] compound(double[] Xwa, double[] Xab) + { + double[] Xwb = new double[3]; + + double[] rot = { Math.Cos(Xwa[2]), -Math.Sin(Xwa[2]), Math.Sin(Xwa[2]), Math.Cos(Xwa[2]) }; + Xwb[0] = rot[0] * Xab[0] + rot[1] * Xab[1] + Xwa[0]; + Xwb[1] = rot[2] * Xab[0] + rot[3] * Xab[1] + Xwa[1]; + Xwb[2] = Xab[2] + Xwa[2]; + + Xwb[2] = piTopi(Xwb[2]); + Xwb[2] = radtodeg(Xwb[2]); + + return Xwb; + } + + double piTopi(double angle) + { + double twopi = 2 * Math.PI; + angle = angle - twopi * (int)(angle / twopi); // this is a stripped-down version of rem(angle, 2*pi) + + while (angle >= Math.PI) + { + angle -= twopi; + } + while (angle <= -Math.PI) + { + angle += twopi; + } + + return angle; + } + + private double radtodeg(double rad) + { + return (180 * rad / Math.PI); + } + + private double degtorad(double degree) + { + return (degree * Math.PI / 180); + } + + private void tBXwa_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBXwa.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strXwa = temp.Split(new char[] { ',' }, 3, StringSplitOptions.RemoveEmptyEntries); + } + + private void tBPab_TextChanged(object sender, EventArgs e) + { + string temp = string.Empty; + temp = tBPab.Text.Replace(Environment.NewLine, " "); + temp = temp.Replace(' ', ','); + + strPab = temp.Split(new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries); + } + } +} diff --git a/Codes.C#/P27/P27/Form1.resx b/Codes.C#/P27/P27/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P27/P27/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P27/P27/P27.csproj b/Codes.C#/P27/P27/P27.csproj new file mode 100644 index 0000000..dfe0c9a --- /dev/null +++ b/Codes.C#/P27/P27/P27.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {EBF784BB-8C2D-46BA-8197-FFD4F755A6D7} + WinExe + Properties + P27 + P27 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P27/P27/Program.cs b/Codes.C#/P27/P27/Program.cs new file mode 100644 index 0000000..40d9219 --- /dev/null +++ b/Codes.C#/P27/P27/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P27 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Codes.C#/P27/P27/Properties/AssemblyInfo.cs b/Codes.C#/P27/P27/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aa04c7f --- /dev/null +++ b/Codes.C#/P27/P27/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P27")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P27")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("4a826b85-6dfa-4e16-8073-547665300510")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P27/P27/Properties/Resources.Designer.cs b/Codes.C#/P27/P27/Properties/Resources.Designer.cs new file mode 100644 index 0000000..fae0a6a --- /dev/null +++ b/Codes.C#/P27/P27/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P27.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P27.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P27/P27/Properties/Resources.resx b/Codes.C#/P27/P27/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P27/P27/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P27/P27/Properties/Settings.Designer.cs b/Codes.C#/P27/P27/Properties/Settings.Designer.cs new file mode 100644 index 0000000..32d2b79 --- /dev/null +++ b/Codes.C#/P27/P27/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P27.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P27/P27/Properties/Settings.settings b/Codes.C#/P27/P27/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P27/P27/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P3/P3.sln b/Codes.C#/P3/P3.sln new file mode 100644 index 0000000..1f13ede --- /dev/null +++ b/Codes.C#/P3/P3.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P3", "P3\P3.csproj", "{1D2D6727-C333-4996-8F9E-9FD670C54257}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1D2D6727-C333-4996-8F9E-9FD670C54257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D2D6727-C333-4996-8F9E-9FD670C54257}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D2D6727-C333-4996-8F9E-9FD670C54257}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D2D6727-C333-4996-8F9E-9FD670C54257}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P3/P3/App.config b/Codes.C#/P3/P3/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P3/P3/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P3/P3/MainForm.Designer.cs b/Codes.C#/P3/P3/MainForm.Designer.cs new file mode 100644 index 0000000..ab5c833 --- /dev/null +++ b/Codes.C#/P3/P3/MainForm.Designer.cs @@ -0,0 +1,257 @@ +namespace P3 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend6 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart3 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.chart6 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart5 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart4 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart6)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart5)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart4)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisX.Title = "Position"; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.Title = "Prior"; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Enabled = false; + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(38, 36); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.IsXValueIndexed = true; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(387, 198); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + chartArea2.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisX.Title = "Position"; + chartArea2.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisY.Title = "Observation"; + chartArea2.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea2); + legend2.Enabled = false; + legend2.Name = "Legend1"; + this.chart2.Legends.Add(legend2); + this.chart2.Location = new System.Drawing.Point(38, 240); + this.chart2.Name = "chart2"; + series2.ChartArea = "ChartArea1"; + series2.IsXValueIndexed = true; + series2.Legend = "Legend1"; + series2.Name = "Series1"; + this.chart2.Series.Add(series2); + this.chart2.Size = new System.Drawing.Size(387, 198); + this.chart2.TabIndex = 1; + this.chart2.Text = "chart2"; + // + // chart3 + // + chartArea3.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea3.AxisX.Title = "Position"; + chartArea3.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea3.AxisY.Title = "Posterior"; + chartArea3.Name = "ChartArea1"; + this.chart3.ChartAreas.Add(chartArea3); + legend3.Enabled = false; + legend3.Name = "Legend1"; + this.chart3.Legends.Add(legend3); + this.chart3.Location = new System.Drawing.Point(38, 444); + this.chart3.Name = "chart3"; + series3.ChartArea = "ChartArea1"; + series3.IsXValueIndexed = true; + series3.Legend = "Legend1"; + series3.Name = "Series1"; + this.chart3.Series.Add(series3); + this.chart3.Size = new System.Drawing.Size(387, 198); + this.chart3.TabIndex = 2; + this.chart3.Text = "chart3"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label1.ForeColor = System.Drawing.Color.Blue; + this.label1.Location = new System.Drawing.Point(147, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(110, 12); + this.label1.TabIndex = 3; + this.label1.Text = "Measurement=red"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.ForeColor = System.Drawing.Color.Blue; + this.label2.Location = new System.Drawing.Point(677, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(124, 12); + this.label2.TabIndex = 7; + this.label2.Text = "Measurement=green"; + // + // chart6 + // + chartArea4.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.AxisX.Title = "Position"; + chartArea4.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.AxisY.Title = "Posterior"; + chartArea4.Name = "ChartArea1"; + this.chart6.ChartAreas.Add(chartArea4); + legend4.Enabled = false; + legend4.Name = "Legend1"; + this.chart6.Legends.Add(legend4); + this.chart6.Location = new System.Drawing.Point(547, 444); + this.chart6.Name = "chart6"; + series4.ChartArea = "ChartArea1"; + series4.IsXValueIndexed = true; + series4.Legend = "Legend1"; + series4.Name = "Series1"; + this.chart6.Series.Add(series4); + this.chart6.Size = new System.Drawing.Size(376, 198); + this.chart6.TabIndex = 6; + this.chart6.Text = "chart6"; + // + // chart5 + // + chartArea5.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea5.AxisX.Title = "Position"; + chartArea5.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea5.AxisY.Title = "Observation"; + chartArea5.Name = "ChartArea1"; + this.chart5.ChartAreas.Add(chartArea5); + legend5.Enabled = false; + legend5.Name = "Legend1"; + this.chart5.Legends.Add(legend5); + this.chart5.Location = new System.Drawing.Point(547, 240); + this.chart5.Name = "chart5"; + series5.ChartArea = "ChartArea1"; + series5.IsXValueIndexed = true; + series5.Legend = "Legend1"; + series5.Name = "Series1"; + this.chart5.Series.Add(series5); + this.chart5.Size = new System.Drawing.Size(376, 198); + this.chart5.TabIndex = 5; + this.chart5.Text = "chart5"; + // + // chart4 + // + chartArea6.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea6.AxisX.Title = "Position"; + chartArea6.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea6.AxisY.Title = "Prior"; + chartArea6.Name = "ChartArea1"; + this.chart4.ChartAreas.Add(chartArea6); + legend6.Enabled = false; + legend6.Name = "Legend1"; + this.chart4.Legends.Add(legend6); + this.chart4.Location = new System.Drawing.Point(547, 34); + this.chart4.Name = "chart4"; + series6.ChartArea = "ChartArea1"; + series6.IsXValueIndexed = true; + series6.Legend = "Legend1"; + series6.Name = "Series1"; + this.chart4.Series.Add(series6); + this.chart4.Size = new System.Drawing.Size(374, 198); + this.chart4.TabIndex = 4; + this.chart4.Text = "chart4"; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(958, 688); + this.Controls.Add(this.label2); + this.Controls.Add(this.chart6); + this.Controls.Add(this.chart5); + this.Controls.Add(this.chart4); + this.Controls.Add(this.label1); + this.Controls.Add(this.chart3); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "MainForm"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart6)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart5)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart4)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + private System.Windows.Forms.DataVisualization.Charting.Chart chart3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.DataVisualization.Charting.Chart chart6; + private System.Windows.Forms.DataVisualization.Charting.Chart chart5; + private System.Windows.Forms.DataVisualization.Charting.Chart chart4; + } +} + diff --git a/Codes.C#/P3/P3/MainForm.cs b/Codes.C#/P3/P3/MainForm.cs new file mode 100644 index 0000000..0c6f708 --- /dev/null +++ b/Codes.C#/P3/P3/MainForm.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Windows.Forms; + +namespace P3 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + PaintHist(); + } + + private void PaintHist() + { + string[] world = { "green", "red", "red", "green", "green" }; // Map + List prior = new List{ 0.2, 0.2, 0.2, 0.2, 0.2 }; // Prior + string[] observation = {"red","green"}; // Observation + double pHit = 0.6; // Observation model + double pMiss = 0.2; + List likelihood; + List posterior; + for (int i = 0; i < observation.Length; i++) + { + //绘图 + if (i == 0) + { + posterior = Robot.ClassRobot.Sense(prior, observation[i], world, pHit, pMiss, out likelihood); // Update + chart1.Series[0].Points.DataBindY(prior); + chart2.Series[0].Points.DataBindY(likelihood); + chart3.Series[0].Points.DataBindY(posterior); + prior = posterior; + } + else + { + posterior = Robot.ClassRobot.Sense(prior, observation[i], world, pHit, pMiss, out likelihood); // Update + chart4.Series[0].Points.DataBindY(prior); + chart5.Series[0].Points.DataBindY(likelihood); + chart6.Series[0].Points.DataBindY(posterior); + } + } + } + } +} diff --git a/Codes.C#/P3/P3/MainForm.resx b/Codes.C#/P3/P3/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P3/P3/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P3/P3/P3.csproj b/Codes.C#/P3/P3/P3.csproj new file mode 100644 index 0000000..b133a6f --- /dev/null +++ b/Codes.C#/P3/P3/P3.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {1D2D6727-C333-4996-8F9E-9FD670C54257} + WinExe + Properties + P3 + P3 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + .\Robot.dll + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P3/P3/Program.cs b/Codes.C#/P3/P3/Program.cs new file mode 100644 index 0000000..653bb5a --- /dev/null +++ b/Codes.C#/P3/P3/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P3 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P3/P3/Properties/AssemblyInfo.cs b/Codes.C#/P3/P3/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5a0cc7a --- /dev/null +++ b/Codes.C#/P3/P3/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P3")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P3")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("fcb7dee0-b198-495c-975b-6cafc61b2dcf")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P3/P3/Properties/Resources.Designer.cs b/Codes.C#/P3/P3/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d0b88dd --- /dev/null +++ b/Codes.C#/P3/P3/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P3.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P3.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P3/P3/Properties/Resources.resx b/Codes.C#/P3/P3/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P3/P3/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P3/P3/Properties/Settings.Designer.cs b/Codes.C#/P3/P3/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3157362 --- /dev/null +++ b/Codes.C#/P3/P3/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P3.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P3/P3/Properties/Settings.settings b/Codes.C#/P3/P3/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P3/P3/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P3/P3/Robot.dll b/Codes.C#/P3/P3/Robot.dll new file mode 100644 index 0000000..be7bc22 Binary files /dev/null and b/Codes.C#/P3/P3/Robot.dll differ diff --git a/Codes.C#/P31/P31.sln b/Codes.C#/P31/P31.sln new file mode 100644 index 0000000..8837a23 --- /dev/null +++ b/Codes.C#/P31/P31.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P31", "P31\P31.csproj", "{F093BE1D-9923-4A5E-9EE2-F4C23F133448}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F093BE1D-9923-4A5E-9EE2-F4C23F133448}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F093BE1D-9923-4A5E-9EE2-F4C23F133448}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F093BE1D-9923-4A5E-9EE2-F4C23F133448}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F093BE1D-9923-4A5E-9EE2-F4C23F133448}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P31/P31/App.config b/Codes.C#/P31/P31/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P31/P31/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P31/P31/P31.csproj b/Codes.C#/P31/P31/P31.csproj new file mode 100644 index 0000000..143b111 --- /dev/null +++ b/Codes.C#/P31/P31/P31.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {F093BE1D-9923-4A5E-9EE2-F4C23F133448} + Exe + Properties + P31 + P31 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P31/P31/Program.cs b/Codes.C#/P31/P31/Program.cs new file mode 100644 index 0000000..177d8d1 --- /dev/null +++ b/Codes.C#/P31/P31/Program.cs @@ -0,0 +1,76 @@ +using System; + +namespace P31 +{ + class Program + { + static void Main(string[] args) + { + double[] Xab = {96, 35, degtorad(62)}; + + double[] Xba = Inverse(Xab); + double[] Xab_ = Inverse(Xba); + + Xab_[2] = radtodeg(Xab_[2]); + + //disp(Xab); + Console.WriteLine("Xab:"); + for(int i = 0;i < 2;i++) + { + Console.WriteLine(Xab[i].ToString("F4")); + } + Console.WriteLine(radtodeg(Xab[2]).ToString("F4")); + Console.WriteLine(); + + //disp(Xab_); + Console.WriteLine("Inverse(Inverse(Xab)):"); + for (int i = 0; i < 3; i++) + { + Console.WriteLine(Xab_[i].ToString("F4")); + } + Console.ReadKey(); + } + private static double[] Inverse(double[] Xab) + { + if (Xab.Length != 3) + { + Console.WriteLine("Xab should be of the size 3*1!"); + } + double[] Xba = new double[3]; + + Xba[0] = -Xab[0] * Math.Cos(Xab[2]) - Xab[1] * Math.Sin(Xab[2]); + Xba[1] = Xab[0] * Math.Sin(Xab[2]) - Xab[1] * Math.Cos(Xab[2]); + Xba[2] = -Xab[2]; + Xba[2] = piTopi(Xba[2]); + + return Xba; + } + + static private double piTopi(double angle) + { + double twopi = 2 * Math.PI; + angle = angle - twopi * (int)(angle / twopi); // this is a stripped-down version of rem(angle, 2*pi) + + while (angle >= Math.PI) + { + angle -= twopi; + } + while (angle <= -Math.PI) + { + angle += twopi; + } + + return angle; + } + + static private double degtorad(double degree) + { + return (degree * Math.PI / 180); + } + + static private double radtodeg(double rad) + { + return (180 * rad / Math.PI); + } + } +} diff --git a/Codes.C#/P31/P31/Properties/AssemblyInfo.cs b/Codes.C#/P31/P31/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8a2d39f --- /dev/null +++ b/Codes.C#/P31/P31/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P31")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P31")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("16b17f99-7ab0-4194-b891-873a8a47ea94")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P33/P33.sln b/Codes.C#/P33/P33.sln new file mode 100644 index 0000000..a7575e7 --- /dev/null +++ b/Codes.C#/P33/P33.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P33", "P33\P33.csproj", "{750B16C1-08F2-4790-BC13-944E24D8F2C7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {750B16C1-08F2-4790-BC13-944E24D8F2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {750B16C1-08F2-4790-BC13-944E24D8F2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {750B16C1-08F2-4790-BC13-944E24D8F2C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {750B16C1-08F2-4790-BC13-944E24D8F2C7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P33/P33/App.config b/Codes.C#/P33/P33/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P33/P33/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P33/P33/P33.csproj b/Codes.C#/P33/P33/P33.csproj new file mode 100644 index 0000000..66e1809 --- /dev/null +++ b/Codes.C#/P33/P33/P33.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {750B16C1-08F2-4790-BC13-944E24D8F2C7} + Exe + Properties + P33 + P33 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P33/P33/Program.cs b/Codes.C#/P33/P33/Program.cs new file mode 100644 index 0000000..a13c2ac --- /dev/null +++ b/Codes.C#/P33/P33/Program.cs @@ -0,0 +1,91 @@ +using System; + +namespace P33 +{ + class Program + { + static void Main(string[] args) + { + double[] Xab = {5.0,3.0,degtorad(50)}; + + double[] Xwb = {9.0,6.0,degtorad(70)}; + + // First solution + double[] Xba = Inverse(Xab); + double[] Xwa = compound(Xwb, Xba); + + Console.WriteLine("Fisrt solution:"); + for (int i = 0; i < 3;i++ ) + { + Console.WriteLine(Xwa[i].ToString("F4")); + } + Console.WriteLine(); + + // Second solution + double[] Xwa2 = Inverse(compound(Xab, Inverse(Xwb))); + + Console.WriteLine("Second solution:"); + for (int i = 0; i < 3; i++) + { + Console.WriteLine(Xwa2[i].ToString("F4")); + } + Console.ReadLine(); + + } + + private static double[] Inverse(double[] Xab) + { + if(Xab.Length != 3) + { + Console.WriteLine("Xab should be of the size 3*1!"); + } + double[] Xba = new double[3]; + Xba[0] = -Xab[0] * Math.Cos(Xab[2]) - Xab[1] * Math.Sin(Xab[2]); + Xba[1] = Xab[0] * Math.Sin(Xab[2]) - Xab[1] * Math.Cos(Xab[2]); + Xba[2] = -Xab[2]; + Xba[2] = piTopi(Xba[2]); + + return Xba; + } + + private static double[] compound(double[] Xwa, double[] Xab) + { + double[] Xwb = new double[3]; + + double[] rot = {Math.Cos(Xwa[2]),-Math.Sin(Xwa[2]),Math.Sin(Xwa[2]),Math.Cos(Xwa[2])}; + Xwb[0] = rot[0] * Xab[0] + rot[1] * Xab[1] + Xwa[0]; + Xwb[1] = rot[2] * Xab[0] + rot[3] * Xab[1] + Xwa[1]; + Xwb[2] = Xab[2] + Xwa[2]; + + Xwb[2] = piTopi(Xwb[2]); + //Xwb[2] = radtodeg(Xwb[2]); + + return Xwb; + } + static private double piTopi(double angle) + { + double twopi = 2 * Math.PI; + angle = angle - twopi * (int)(angle/twopi); // this is a stripped-down version of rem(angle, 2*pi) + + while(angle >= Math.PI) + { + angle -= twopi; + } + while(angle <= -Math.PI) + { + angle += twopi; + } + + return angle; + } + static private double degtorad(double degree) + { + return (degree * Math.PI / 180); + } + + static private double radtodeg(double rad) + { + return (180 * rad / Math.PI); + } + } +} diff --git a/Codes.C#/P33/P33/Properties/AssemblyInfo.cs b/Codes.C#/P33/P33/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e10d086 --- /dev/null +++ b/Codes.C#/P33/P33/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P33")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P33")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ca107321-0559-43b1-8780-44ef7c60fe3a")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P5/P5.sln b/Codes.C#/P5/P5.sln new file mode 100644 index 0000000..295f415 --- /dev/null +++ b/Codes.C#/P5/P5.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P5", "P5\P5.csproj", "{C552CEB7-D10A-4D65-B9D9-E64033DAF335}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C552CEB7-D10A-4D65-B9D9-E64033DAF335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C552CEB7-D10A-4D65-B9D9-E64033DAF335}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C552CEB7-D10A-4D65-B9D9-E64033DAF335}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C552CEB7-D10A-4D65-B9D9-E64033DAF335}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P5/P5/App.config b/Codes.C#/P5/P5/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P5/P5/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P5/P5/P5.csproj b/Codes.C#/P5/P5/P5.csproj new file mode 100644 index 0000000..005c1d5 --- /dev/null +++ b/Codes.C#/P5/P5/P5.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {C552CEB7-D10A-4D65-B9D9-E64033DAF335} + Exe + Properties + P5 + P5 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + .\Robot.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P5/P5/Program.cs b/Codes.C#/P5/P5/Program.cs new file mode 100644 index 0000000..3551204 --- /dev/null +++ b/Codes.C#/P5/P5/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; + +namespace P5 +{ + class Program + { + static void Main(string[] args) + { + List p = new List{0, 0.5, 0, 0.5, 0}; + int u = 2; + double pExact = 0.8; + double pOvershoot = 0.1; + double pUndershoot = 0.1; + List q = new List(); + q = Robot.ClassRobot.Move(p, u, pExact, pOvershoot, pUndershoot); + Console.Write("U=2:\t"); + for(int i = 0;i < p.Count;i++) + { + Console.Write(string.Format("{0}\t",q[i])); + } + Console.WriteLine(); + Console.ReadLine(); + } + } +} diff --git a/Codes.C#/P5/P5/Properties/AssemblyInfo.cs b/Codes.C#/P5/P5/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a766a3c --- /dev/null +++ b/Codes.C#/P5/P5/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P5")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P5")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("85e74183-9244-4231-97e3-253b651d63f1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P5/P5/Robot.dll b/Codes.C#/P5/P5/Robot.dll new file mode 100644 index 0000000..be7bc22 Binary files /dev/null and b/Codes.C#/P5/P5/Robot.dll differ diff --git a/Codes.C#/P6/P6.sln b/Codes.C#/P6/P6.sln new file mode 100644 index 0000000..7bb3ce8 --- /dev/null +++ b/Codes.C#/P6/P6.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P6", "P6\P6.csproj", "{BC694BD9-B9C4-4770-9F1F-14E4074631C2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BC694BD9-B9C4-4770-9F1F-14E4074631C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC694BD9-B9C4-4770-9F1F-14E4074631C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC694BD9-B9C4-4770-9F1F-14E4074631C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC694BD9-B9C4-4770-9F1F-14E4074631C2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P6/P6/App.config b/Codes.C#/P6/P6/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P6/P6/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P6/P6/MainForm.Designer.cs b/Codes.C#/P6/P6/MainForm.Designer.cs new file mode 100644 index 0000000..7c81f34 --- /dev/null +++ b/Codes.C#/P6/P6/MainForm.Designer.cs @@ -0,0 +1,296 @@ +namespace P6 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend4 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend6 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart3 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart4 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart5 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart6 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart4)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart5)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart6)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + this.chart1.BackColor = System.Drawing.SystemColors.Control; + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Enabled = false; + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(2, 27); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.IsXValueIndexed = true; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(300, 300); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + this.chart2.BackColor = System.Drawing.SystemColors.Control; + chartArea2.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea2); + legend2.Enabled = false; + legend2.Name = "Legend1"; + this.chart2.Legends.Add(legend2); + this.chart2.Location = new System.Drawing.Point(308, 27); + this.chart2.Name = "chart2"; + series2.ChartArea = "ChartArea1"; + series2.IsXValueIndexed = true; + series2.Legend = "Legend1"; + series2.Name = "Series1"; + this.chart2.Series.Add(series2); + this.chart2.Size = new System.Drawing.Size(300, 300); + this.chart2.TabIndex = 1; + this.chart2.Text = "chart2"; + // + // chart3 + // + this.chart3.BackColor = System.Drawing.SystemColors.Control; + chartArea3.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea3.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea3.Name = "ChartArea1"; + this.chart3.ChartAreas.Add(chartArea3); + legend3.Enabled = false; + legend3.Name = "Legend1"; + this.chart3.Legends.Add(legend3); + this.chart3.Location = new System.Drawing.Point(614, 27); + this.chart3.Name = "chart3"; + series3.ChartArea = "ChartArea1"; + series3.IsXValueIndexed = true; + series3.Legend = "Legend1"; + series3.Name = "Series1"; + this.chart3.Series.Add(series3); + this.chart3.Size = new System.Drawing.Size(300, 300); + this.chart3.TabIndex = 2; + this.chart3.Text = "chart3"; + // + // chart4 + // + this.chart4.BackColor = System.Drawing.SystemColors.Control; + chartArea4.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea4.Name = "ChartArea1"; + this.chart4.ChartAreas.Add(chartArea4); + legend4.Enabled = false; + legend4.Name = "Legend1"; + this.chart4.Legends.Add(legend4); + this.chart4.Location = new System.Drawing.Point(2, 364); + this.chart4.Name = "chart4"; + series4.ChartArea = "ChartArea1"; + series4.IsXValueIndexed = true; + series4.Legend = "Legend1"; + series4.Name = "Series1"; + this.chart4.Series.Add(series4); + this.chart4.Size = new System.Drawing.Size(300, 300); + this.chart4.TabIndex = 5; + this.chart4.Text = "chart4"; + // + // chart5 + // + this.chart5.BackColor = System.Drawing.SystemColors.Control; + chartArea5.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea5.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea5.Name = "ChartArea1"; + this.chart5.ChartAreas.Add(chartArea5); + legend5.Enabled = false; + legend5.Name = "Legend1"; + this.chart5.Legends.Add(legend5); + this.chart5.Location = new System.Drawing.Point(308, 364); + this.chart5.Name = "chart5"; + series5.ChartArea = "ChartArea1"; + series5.IsXValueIndexed = true; + series5.Legend = "Legend1"; + series5.Name = "Series1"; + this.chart5.Series.Add(series5); + this.chart5.Size = new System.Drawing.Size(300, 300); + this.chart5.TabIndex = 4; + this.chart5.Text = "chart5"; + // + // chart6 + // + chartArea6.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea6.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea6.Name = "ChartArea1"; + this.chart6.ChartAreas.Add(chartArea6); + legend6.Enabled = false; + legend6.Name = "Legend1"; + this.chart6.Legends.Add(legend6); + this.chart6.Location = new System.Drawing.Point(614, 364); + this.chart6.Name = "chart6"; + series6.ChartArea = "ChartArea1"; + series6.IsXValueIndexed = true; + series6.Legend = "Legend1"; + series6.Name = "Series1"; + this.chart6.Series.Add(series6); + this.chart6.Size = new System.Drawing.Size(300, 300); + this.chart6.TabIndex = 3; + this.chart6.Text = "chart6"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(139, 27); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 6; + this.label1.Text = "step=1"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(442, 27); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(0, 12); + this.label2.TabIndex = 7; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(756, 27); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(0, 12); + this.label3.TabIndex = 8; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(756, 349); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(0, 12); + this.label4.TabIndex = 11; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(442, 349); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(0, 12); + this.label5.TabIndex = 10; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(139, 349); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(0, 12); + this.label6.TabIndex = 9; + // + // timer1 + // + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(995, 666); + this.Controls.Add(this.label4); + this.Controls.Add(this.label5); + this.Controls.Add(this.label6); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.chart4); + this.Controls.Add(this.chart5); + this.Controls.Add(this.chart6); + this.Controls.Add(this.chart3); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "MainForm"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart4)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart5)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart6)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + private System.Windows.Forms.DataVisualization.Charting.Chart chart3; + private System.Windows.Forms.DataVisualization.Charting.Chart chart4; + private System.Windows.Forms.DataVisualization.Charting.Chart chart5; + private System.Windows.Forms.DataVisualization.Charting.Chart chart6; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Timer timer1; + } +} + diff --git a/Codes.C#/P6/P6/MainForm.cs b/Codes.C#/P6/P6/MainForm.cs new file mode 100644 index 0000000..6bd182d --- /dev/null +++ b/Codes.C#/P6/P6/MainForm.cs @@ -0,0 +1,94 @@ +using System; +using System.Windows.Forms; + +namespace P6 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + timer1.Interval = 200; + timer1.Start(); + } + + private static int n = 5; + private static int u = 1; + private static double pExact = 0.8; + private static double pOvershoot = 0.1; + private static double pUndershoot = 0.1; + + private static int step = 1; + private static double[] p = { 1, 0, 0, 0, 0 }; + + + public void paint() + { + chart1.Series[0].Points.DataBindY(p); + label1.Text = "step=" + step.ToString(); + + p = move(); + + switch (step) + { + case 9: + { + label2.Text = "step=" + step.ToString(); + chart2.Series[0].Points.DataBindY(p); + break; + } + case 11: + { + label3.Text = "step=" + step.ToString(); + chart3.Series[0].Points.DataBindY(p); + break; + } + case 14: + { + label6.Text = "step=" + step.ToString(); + chart4.Series[0].Points.DataBindY(p); + break; + } + case 23: + { + label5.Text = "step=" + step.ToString(); + chart5.Series[0].Points.DataBindY(p); + break; + } + case 50: + { + label4.Text = "step=" + step.ToString(); + chart6.Series[0].Points.DataBindY(p); + break; + } + default: + break; + } + } + double[] move() + { + double[] q = new double[5]; + for (int i = 0; i < n; i++) + { + //a mod b = (a % b + b) % b + q[i] = pExact * p[((i - u) % n + n) % n]; + q[i] = q[i] + pOvershoot * p[((i - 1 - u) % n + n) % n]; + q[i] = q[i] + pUndershoot * p[((i + 1 - u) % n + n) % n]; + } + return q; + } + + private void timer1_Tick(object sender, EventArgs e) + { + if(step <= 100) + { + paint(); + step++; + } + else + { + timer1.Stop(); + } + } + } +} diff --git a/Codes.C#/P6/P6/MainForm.resx b/Codes.C#/P6/P6/MainForm.resx new file mode 100644 index 0000000..1f666f2 --- /dev/null +++ b/Codes.C#/P6/P6/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Codes.C#/P6/P6/P6.csproj b/Codes.C#/P6/P6/P6.csproj new file mode 100644 index 0000000..586ff3c --- /dev/null +++ b/Codes.C#/P6/P6/P6.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {BC694BD9-B9C4-4770-9F1F-14E4074631C2} + WinExe + Properties + P6 + P6 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P6/P6/Program.cs b/Codes.C#/P6/P6/Program.cs new file mode 100644 index 0000000..09a217f --- /dev/null +++ b/Codes.C#/P6/P6/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace P6 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P6/P6/Properties/AssemblyInfo.cs b/Codes.C#/P6/P6/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8db6340 --- /dev/null +++ b/Codes.C#/P6/P6/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P6")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P6")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("6a2daa82-73fd-462a-8f27-4d73bdb0e1e9")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P6/P6/Properties/Resources.Designer.cs b/Codes.C#/P6/P6/Properties/Resources.Designer.cs new file mode 100644 index 0000000..3d01829 --- /dev/null +++ b/Codes.C#/P6/P6/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P6.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P6.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P6/P6/Properties/Resources.resx b/Codes.C#/P6/P6/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P6/P6/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P6/P6/Properties/Settings.Designer.cs b/Codes.C#/P6/P6/Properties/Settings.Designer.cs new file mode 100644 index 0000000..8f312ac --- /dev/null +++ b/Codes.C#/P6/P6/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P6.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P6/P6/Properties/Settings.settings b/Codes.C#/P6/P6/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P6/P6/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P65/P65.sln b/Codes.C#/P65/P65.sln new file mode 100644 index 0000000..c777297 --- /dev/null +++ b/Codes.C#/P65/P65.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P65", "P65\P65.csproj", "{DD15D9D0-E338-40D9-962B-6952C5888E7C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DD15D9D0-E338-40D9-962B-6952C5888E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD15D9D0-E338-40D9-962B-6952C5888E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD15D9D0-E338-40D9-962B-6952C5888E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD15D9D0-E338-40D9-962B-6952C5888E7C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P65/P65/App.config b/Codes.C#/P65/P65/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P65/P65/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P65/P65/MainForm.Designer.cs b/Codes.C#/P65/P65/MainForm.Designer.cs new file mode 100644 index 0000000..1e3332c --- /dev/null +++ b/Codes.C#/P65/P65/MainForm.Designer.cs @@ -0,0 +1,116 @@ +namespace P65 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.Title = "Probability"; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Enabled = false; + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(12, 46); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(300, 300); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + chartArea2.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisX.Title = "The Probability of being head"; + chartArea2.AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount; + chartArea2.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisY.Title = "Entropy"; + chartArea2.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea2); + legend2.Enabled = false; + legend2.Name = "Legend1"; + this.chart2.Legends.Add(legend2); + this.chart2.Location = new System.Drawing.Point(367, 46); + this.chart2.Name = "chart2"; + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; + series2.CustomProperties = "LineTension=0"; + series2.IsXValueIndexed = true; + series2.Legend = "Legend1"; + series2.Name = "Series1"; + this.chart2.Series.Add(series2); + this.chart2.Size = new System.Drawing.Size(300, 300); + this.chart2.TabIndex = 1; + this.chart2.Text = "chart2"; + // + // timer1 + // + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(680, 402); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "MainForm"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + private System.Windows.Forms.Timer timer1; + } +} + diff --git a/Codes.C#/P65/P65/MainForm.cs b/Codes.C#/P65/P65/MainForm.cs new file mode 100644 index 0000000..9b24d1a --- /dev/null +++ b/Codes.C#/P65/P65/MainForm.cs @@ -0,0 +1,68 @@ +using System; +using System.Windows.Forms; + +namespace P65 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + timer1.Interval = 30; + timer1.Start(); + chart1.ChartAreas[0].AxisY.Maximum = 1.0; + chart1.ChartAreas[0].AxisY.Minimum = 0.0; + } + double pHead = 0.0; + int n = 100; + int i = 0; + + string[] xValues = { "pHead", "pTail" }; + double[] yValues = new double[2]; + double[] H = new double[101];//y2Values + + + void print() + { + if(i == 0 || i == 100) + { + H[i] = 0; + } + else + { + H[i] = -((pHead * Math.Log((pHead), 2)) + (1 - pHead) * Math.Log((1 - pHead), 2)); + } + + if (i == 0 || i % 10 == 0) + { + yValues = new double[] { pHead, 1 - pHead }; + chart1.Series[0].Points.DataBindXY(xValues, yValues); + } + pHead += 0.01; + + } + + private void timer1_Tick(object sender, EventArgs e) + { + if (i <= 100) + { + print(); + i++; + } + else + { + timer1.Stop(); + + double[] x2Value = new double[n + 1]; + double[] y2Value = new double[n + 1]; + for (int j = 0; j <= n; j++) + { + x2Value[j] = j / 100.0; + } + y2Value = H; + chart2.ChartAreas[0].AxisY.Minimum = 0.0; + chart2.Series[0].Points.DataBindXY(x2Value, y2Value); + } + } + } +} \ No newline at end of file diff --git a/Codes.C#/P65/P65/MainForm.resx b/Codes.C#/P65/P65/MainForm.resx new file mode 100644 index 0000000..1f666f2 --- /dev/null +++ b/Codes.C#/P65/P65/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Codes.C#/P65/P65/P65.csproj b/Codes.C#/P65/P65/P65.csproj new file mode 100644 index 0000000..52622db --- /dev/null +++ b/Codes.C#/P65/P65/P65.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {DD15D9D0-E338-40D9-962B-6952C5888E7C} + WinExe + Properties + P65 + P65 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P65/P65/Program.cs b/Codes.C#/P65/P65/Program.cs new file mode 100644 index 0000000..5cce11a --- /dev/null +++ b/Codes.C#/P65/P65/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P65 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P65/P65/Properties/AssemblyInfo.cs b/Codes.C#/P65/P65/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4f36ed5 --- /dev/null +++ b/Codes.C#/P65/P65/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P65")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P65")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("eb65ba3c-9704-4b18-a3b3-d9df30f4a16b")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P65/P65/Properties/Resources.Designer.cs b/Codes.C#/P65/P65/Properties/Resources.Designer.cs new file mode 100644 index 0000000..10ce7fa --- /dev/null +++ b/Codes.C#/P65/P65/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P65.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P65.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P65/P65/Properties/Resources.resx b/Codes.C#/P65/P65/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P65/P65/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P65/P65/Properties/Settings.Designer.cs b/Codes.C#/P65/P65/Properties/Settings.Designer.cs new file mode 100644 index 0000000..14254b4 --- /dev/null +++ b/Codes.C#/P65/P65/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P65.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P65/P65/Properties/Settings.settings b/Codes.C#/P65/P65/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P65/P65/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P7/P7.sln b/Codes.C#/P7/P7.sln new file mode 100644 index 0000000..dbbd2e9 --- /dev/null +++ b/Codes.C#/P7/P7.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P7", "P7\P7.csproj", "{72528191-0703-4618-880A-4F2EDBB50B86}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {72528191-0703-4618-880A-4F2EDBB50B86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72528191-0703-4618-880A-4F2EDBB50B86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72528191-0703-4618-880A-4F2EDBB50B86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72528191-0703-4618-880A-4F2EDBB50B86}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P7/P7/App.config b/Codes.C#/P7/P7/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P7/P7/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P7/P7/MainForm.Designer.cs b/Codes.C#/P7/P7/MainForm.Designer.cs new file mode 100644 index 0000000..62e5118 --- /dev/null +++ b/Codes.C#/P7/P7/MainForm.Designer.cs @@ -0,0 +1,79 @@ +namespace P7 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea1.AxisX.Interval = 10D; + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisX.Title = "Step"; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.Title = "Entropy"; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Enabled = false; + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(0, 0); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(579, 465); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(588, 489); + this.Controls.Add(this.chart1); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + } +} + diff --git a/Codes.C#/P7/P7/MainForm.cs b/Codes.C#/P7/P7/MainForm.cs new file mode 100644 index 0000000..93e3f84 --- /dev/null +++ b/Codes.C#/P7/P7/MainForm.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace P7 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + print(); + } + public void print() + { + List p = new List{1, 0, 0, 0, 0}; + double[] q = new double[p.Count]; + int u = 1; + int step = 100; + double pExact = 0.8; + double pOvershoot = 0.1; + double pUndershoot = 0.1; + double[] entropy = new double[step]; + double tLog = 0.0; + for (int i = 0; i < step; i++) + { + p = Robot.ClassRobot.Move(p, u, pExact, pOvershoot, pUndershoot); + for(int j = 0;j < 5;j++) + { + if(IsEqual(p[j],0.0)) + { + tLog = 0.0; + } + else + { + tLog = Math.Log(p[j], 2); + } + entropy[i] += -(p[j] * tLog); + } + } + chart1.Series[0].Points.DataBindY(entropy); + } + bool IsEqual(double n1, double n2) + { + if (Math.Abs(n1 - n2) <= Math.Pow(10, -2)) + return true; + else + return false; + } + } +} diff --git a/Codes.C#/P7/P7/MainForm.resx b/Codes.C#/P7/P7/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P7/P7/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P7/P7/P7.csproj b/Codes.C#/P7/P7/P7.csproj new file mode 100644 index 0000000..03b4563 --- /dev/null +++ b/Codes.C#/P7/P7/P7.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {72528191-0703-4618-880A-4F2EDBB50B86} + WinExe + Properties + P7 + P7 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + .\Robot.dll + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P7/P7/Program.cs b/Codes.C#/P7/P7/Program.cs new file mode 100644 index 0000000..207276c --- /dev/null +++ b/Codes.C#/P7/P7/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P7 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P7/P7/Properties/AssemblyInfo.cs b/Codes.C#/P7/P7/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cc40334 --- /dev/null +++ b/Codes.C#/P7/P7/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P7")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P7")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("876eb668-a23b-440d-9a97-28f9e3e3ccaa")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P7/P7/Properties/Resources.Designer.cs b/Codes.C#/P7/P7/Properties/Resources.Designer.cs new file mode 100644 index 0000000..de34e44 --- /dev/null +++ b/Codes.C#/P7/P7/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P7.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P7.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P7/P7/Properties/Resources.resx b/Codes.C#/P7/P7/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P7/P7/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P7/P7/Properties/Settings.Designer.cs b/Codes.C#/P7/P7/Properties/Settings.Designer.cs new file mode 100644 index 0000000..f481748 --- /dev/null +++ b/Codes.C#/P7/P7/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P7.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P7/P7/Properties/Settings.settings b/Codes.C#/P7/P7/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P7/P7/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P7/P7/Robot.dll b/Codes.C#/P7/P7/Robot.dll new file mode 100644 index 0000000..be7bc22 Binary files /dev/null and b/Codes.C#/P7/P7/Robot.dll differ diff --git a/Codes.C#/P8/P8.sln b/Codes.C#/P8/P8.sln new file mode 100644 index 0000000..5610e51 --- /dev/null +++ b/Codes.C#/P8/P8.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P8", "P8\P8.csproj", "{0BFA906D-3700-406E-9049-91DA9B3D251F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0BFA906D-3700-406E-9049-91DA9B3D251F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0BFA906D-3700-406E-9049-91DA9B3D251F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0BFA906D-3700-406E-9049-91DA9B3D251F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0BFA906D-3700-406E-9049-91DA9B3D251F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P8/P8/App.config b/Codes.C#/P8/P8/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P8/P8/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P8/P8/MainForm.Designer.cs b/Codes.C#/P8/P8/MainForm.Designer.cs new file mode 100644 index 0000000..c8aed41 --- /dev/null +++ b/Codes.C#/P8/P8/MainForm.Designer.cs @@ -0,0 +1,124 @@ +namespace P8 +{ + partial class MainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.LegendCellColumn legendCellColumn1 = new System.Windows.Forms.DataVisualization.Charting.LegendCellColumn(); + System.Windows.Forms.DataVisualization.Charting.LegendItem legendItem1 = new System.Windows.Forms.DataVisualization.Charting.LegendItem(); + System.Windows.Forms.DataVisualization.Charting.LegendItem legendItem2 = new System.Windows.Forms.DataVisualization.Charting.LegendItem(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit(); + this.SuspendLayout(); + // + // chart1 + // + chartArea1.AxisX.MajorGrid.Enabled = false; + chartArea1.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisX.Minimum = 0.5D; + chartArea1.AxisX.Title = "Index of cell"; + chartArea1.AxisY.MajorGrid.Enabled = false; + chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea1.AxisY.Title = "Posterior"; + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Enabled = false; + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(0, 0); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(431, 401); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // chart2 + // + chartArea2.AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisX.Title = "Step"; + chartArea2.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None; + chartArea2.AxisY.Title = "Entropy"; + chartArea2.Name = "ChartArea1"; + this.chart2.ChartAreas.Add(chartArea2); + legendCellColumn1.Name = "Column1"; + legend2.CellColumns.Add(legendCellColumn1); + legendItem1.ImageStyle = System.Windows.Forms.DataVisualization.Charting.LegendImageStyle.Marker; + legendItem1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle; + legendItem1.Name = "Before sensing"; + legendItem2.ImageStyle = System.Windows.Forms.DataVisualization.Charting.LegendImageStyle.Line; + legendItem2.Name = "After sensing"; + legend2.CustomItems.Add(legendItem1); + legend2.CustomItems.Add(legendItem2); + legend2.Enabled = false; + legend2.Name = "Legend1"; + this.chart2.Legends.Add(legend2); + this.chart2.Location = new System.Drawing.Point(485, 0); + this.chart2.Name = "chart2"; + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point; + series2.IsVisibleInLegend = false; + series2.Legend = "Legend1"; + series2.Name = "Series1"; + series2.YValuesPerPoint = 6; + this.chart2.Series.Add(series2); + this.chart2.Size = new System.Drawing.Size(431, 401); + this.chart2.TabIndex = 1; + this.chart2.Text = "chart2"; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1072, 538); + this.Controls.Add(this.chart2); + this.Controls.Add(this.chart1); + this.Name = "MainForm"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart2; + } +} + diff --git a/Codes.C#/P8/P8/MainForm.cs b/Codes.C#/P8/P8/MainForm.cs new file mode 100644 index 0000000..78ad0ae --- /dev/null +++ b/Codes.C#/P8/P8/MainForm.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Robot; + +namespace P8 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + print(); + } + void print() + { + List p = new List{0.2, 0.2, 0.2, 0.2, 0.2}; // Prior + string[] world = {"green", "red", "red", "green", "green"}; // Map + // First configuration of meas. & motion + string[] measurements = {"red", "green"}; // Observation + int[] motions = {1, 1}; // Motions + // Observation model + double pHit = 0.6; + double pMiss = 0.2; + // Motion model / Process model + double pExact = 0.8; + double pOvershoot = 0.1; + double pUndershoot = 0.1; + // The recursive sensing and moving + double[,] entropy = new double[2,motions.Length];// zeros(2, length(motions)); + + List likehood; + + for(int i = 0;i < measurements.Length;i++) + { + // Update by sensing + p = Robot.ClassRobot.Sense(p, measurements[i], world, pHit, pMiss,out likehood); + for(int j = 0;j < 5;j++) + { + entropy[0,i] += -p[i] * Math.Log(p[i],2); + } + // Predict by moving + p = Robot.ClassRobot.Move(p, motions[i], pExact, pOvershoot, pUndershoot); + for(int j = 0;j < 5;j++) + { + entropy[1,i] += -p[i] * Math.Log(p[i],2); + } + } + chart1.Series[0]["PointWidth"] = "0.975"; + chart1.Series[0].Points.DataBindY(p); + + + chart2.Series[0].Points.AddXY(1.0,entropy[0,0]); + chart2.Series[0].Points[0].Color = Color.Blue; + + chart2.Series[0].Points.AddXY(1.0, entropy[0, 1]); + chart2.Series[0].Points[1].Color = Color.Red; + + chart2.Series[0].Points.AddXY(2.0, entropy[1, 0]); + chart2.Series[0].Points[2].Color = Color.Blue; + + chart2.Series[0].Points.AddXY(2.0, entropy[1, 1]); + chart2.Series[0].Points[3].Color = Color.Red; + + } + + bool IsEqual(double n1, double n2) + { + if (Math.Abs(n1 - n2) <= Math.Pow(10, -2)) + return true; + else + return false; + } + } +} diff --git a/Codes.C#/P8/P8/MainForm.resx b/Codes.C#/P8/P8/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P8/P8/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/P8/P8/P8.csproj b/Codes.C#/P8/P8/P8.csproj new file mode 100644 index 0000000..219cca1 --- /dev/null +++ b/Codes.C#/P8/P8/P8.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {0BFA906D-3700-406E-9049-91DA9B3D251F} + WinExe + Properties + P8 + P8 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + .\Robot.dll + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P8/P8/Program.cs b/Codes.C#/P8/P8/Program.cs new file mode 100644 index 0000000..a34bb18 --- /dev/null +++ b/Codes.C#/P8/P8/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace P8 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Codes.C#/P8/P8/Properties/AssemblyInfo.cs b/Codes.C#/P8/P8/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f284b54 --- /dev/null +++ b/Codes.C#/P8/P8/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P8")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P8")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("bc623264-3046-4f40-bb10-53367e66784d")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P8/P8/Properties/Resources.Designer.cs b/Codes.C#/P8/P8/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d29ae16 --- /dev/null +++ b/Codes.C#/P8/P8/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P8.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P8.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P8/P8/Properties/Resources.resx b/Codes.C#/P8/P8/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P8/P8/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P8/P8/Properties/Settings.Designer.cs b/Codes.C#/P8/P8/Properties/Settings.Designer.cs new file mode 100644 index 0000000..5ab17e1 --- /dev/null +++ b/Codes.C#/P8/P8/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P8.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P8/P8/Properties/Settings.settings b/Codes.C#/P8/P8/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P8/P8/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P8/P8/Robot.dll b/Codes.C#/P8/P8/Robot.dll new file mode 100644 index 0000000..be7bc22 Binary files /dev/null and b/Codes.C#/P8/P8/Robot.dll differ diff --git a/Codes.C#/P9/P9.sln b/Codes.C#/P9/P9.sln new file mode 100644 index 0000000..2b3298c --- /dev/null +++ b/Codes.C#/P9/P9.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P9", "P9\P9.csproj", "{FF67DE87-C372-4448-BB4D-982716935DC5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FF67DE87-C372-4448-BB4D-982716935DC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF67DE87-C372-4448-BB4D-982716935DC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF67DE87-C372-4448-BB4D-982716935DC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF67DE87-C372-4448-BB4D-982716935DC5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/P9/P9/App.config b/Codes.C#/P9/P9/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Codes.C#/P9/P9/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codes.C#/P9/P9/P9.csproj b/Codes.C#/P9/P9/P9.csproj new file mode 100644 index 0000000..6a9e461 --- /dev/null +++ b/Codes.C#/P9/P9/P9.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {FF67DE87-C372-4448-BB4D-982716935DC5} + WinExe + Properties + P9 + P9 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + mainForm.cs + + + + + mainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/P9/P9/Program.cs b/Codes.C#/P9/P9/Program.cs new file mode 100644 index 0000000..46566cf --- /dev/null +++ b/Codes.C#/P9/P9/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace P9 +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new mainForm()); + } + } +} diff --git a/Codes.C#/P9/P9/Properties/AssemblyInfo.cs b/Codes.C#/P9/P9/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bd9e22a --- /dev/null +++ b/Codes.C#/P9/P9/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("P9")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("P9")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("20908b0f-18e7-4201-91d8-5d66d80f10cc")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/P9/P9/Properties/Resources.Designer.cs b/Codes.C#/P9/P9/Properties/Resources.Designer.cs new file mode 100644 index 0000000..2aaf0d3 --- /dev/null +++ b/Codes.C#/P9/P9/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace P9.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [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() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("P9.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [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/Codes.C#/P9/P9/Properties/Resources.resx b/Codes.C#/P9/P9/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Codes.C#/P9/P9/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Codes.C#/P9/P9/Properties/Settings.Designer.cs b/Codes.C#/P9/P9/Properties/Settings.Designer.cs new file mode 100644 index 0000000..aa6b8ee --- /dev/null +++ b/Codes.C#/P9/P9/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace P9.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Codes.C#/P9/P9/Properties/Settings.settings b/Codes.C#/P9/P9/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Codes.C#/P9/P9/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Codes.C#/P9/P9/mainForm.Designer.cs b/Codes.C#/P9/P9/mainForm.Designer.cs new file mode 100644 index 0000000..53e80d3 --- /dev/null +++ b/Codes.C#/P9/P9/mainForm.Designer.cs @@ -0,0 +1,138 @@ +namespace P9 +{ + partial class mainForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.textBoxPrior = new System.Windows.Forms.TextBox(); + this.textBoxq = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // textBoxPrior + // + this.textBoxPrior.Location = new System.Drawing.Point(9, 92); + this.textBoxPrior.Margin = new System.Windows.Forms.Padding(2); + this.textBoxPrior.Multiline = true; + this.textBoxPrior.Name = "textBoxPrior"; + this.textBoxPrior.Size = new System.Drawing.Size(366, 122); + this.textBoxPrior.TabIndex = 0; + // + // textBoxq + // + this.textBoxq.Location = new System.Drawing.Point(9, 236); + this.textBoxq.Margin = new System.Windows.Forms.Padding(2); + this.textBoxq.Multiline = true; + this.textBoxq.Name = "textBoxq"; + this.textBoxq.Size = new System.Drawing.Size(366, 122); + this.textBoxq.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(38, 393); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 2; + this.label1.Text = "label1"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(7, 78); + this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 12); + this.label2.TabIndex = 3; + this.label2.Text = "The Prior:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(7, 222); + this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(179, 12); + this.label3.TabIndex = 4; + this.label3.Text = "The probability after moving:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(7, 9); + this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(47, 12); + this.label4.TabIndex = 3; + this.label4.Text = "Motion:"; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(9, 24); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(121, 20); + this.comboBox1.TabIndex = 5; + this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted); + // + // mainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(388, 430); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label4); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxq); + this.Controls.Add(this.textBoxPrior); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "mainForm"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBoxPrior; + private System.Windows.Forms.TextBox textBoxq; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ComboBox comboBox1; + } +} + diff --git a/Codes.C#/P9/P9/mainForm.cs b/Codes.C#/P9/P9/mainForm.cs new file mode 100644 index 0000000..ac6cefe --- /dev/null +++ b/Codes.C#/P9/P9/mainForm.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace P9 +{ + public partial class mainForm : Form + { + List tList; + + public mainForm() + { + InitializeComponent(); + comboBox1.Items.Add("stop"); + comboBox1.Items.Add("right"); + comboBox1.Items.Add("left"); + comboBox1.Items.Add("down"); + comboBox1.Items.Add("up"); + + comboBox1.Text = "right"; + + print(); + } + public void print() + { + textBoxPrior.Text = ""; + textBoxq.Text = ""; + string[,] world = {{"red", "green", "green", "red" , "red"}, + {"red", "red", "green", "red", "red"}, + {"red", "red", "green", "green", "red"}, + {"red", "red", "red", "red", "red"}}; // Map + double[,] ones = {{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}}; + List> prior = new List>(); + List> q; + int nRow = world.GetLength(0); + int nCol = world.GetLength(1); + int[] stop = {0, 0}; + int[] right = {0, 1}; + int[] left = {0,-1}; + int[] down = {1, 0}; + int[] up = {-1,0}; + int[][] directions = { stop, right, left, down, up }; + string[] strDirections = { "stop", "right", "left", "down", "up" }; + + double pMoveCorrect = 0.8; + double pStart = 0.7; + for(int i = 0;i < nRow;i++) + { + tList = new List(); + for(int j = 0;j < nCol;j++) + { + tList.Add((1 - pStart) / (nRow * nCol - 1) * ones[i, j]);// Prior + } + prior.Add(tList); + } + + // Fisrt configuration + prior[2][1] = pStart; + int[] motions = new int[]{}; + + for(int i = 0;i < strDirections.Length;i++) + { + if(comboBox1.SelectedItem == strDirections[i]) + { + motions = directions[i]; + break; + } + } + + q = move(prior, motions, pMoveCorrect,nRow,nCol); + + for(int i = 0;i < nRow;i++) + { + for(int j = 0;j < nCol;j++) + { + textBoxPrior.Text += string.Format("{0:F4}\t",prior[i][j]); + } + textBoxPrior.Text += Environment.NewLine; + } + + // disp('The probability after moving:'); + for(int i = 0;i < nRow;i++) + { + for(int j = 0;j < nCol;j++) + { + textBoxq.Text += string.Format("{0:F4}\t",q[i][j]); + } + textBoxq.Text += Environment.NewLine; + } + int[] maxindex = new int[2]; + maxindex = FindMax(q); + label1.Text = string.Format("The largest probability {0:F4} occurs at cell({1},{2})",q[maxindex[0]][maxindex[1]],maxindex[0],maxindex[1]); + } + + List> move(List> prior, int[] u, double pMoveCorrect, int nRow, int nCol) + { + nRow = prior.Count(); + nCol = prior[0].Count(); + List> q = new List>(); + + for (int r = 0; r < nRow; r++) + { + tList = new List(); + + for (int c = 0; c < nCol; c++) + { + tList.Add(pMoveCorrect * prior[mod(r - u[0], nRow)][mod(c - u[1], nCol)] + (1 - pMoveCorrect) * prior[r][c]); + } + q.Add(tList); + } + + return q; + } + + int[] FindMax(List> array) + { + int[] index = new int[2]; + double max = array[0][0]; + if (array == null || array.Count == 0) + { + index = new int[] { -1, -1 }; + return index; + } + index = new int[] { 0, 0 }; + for (int i = 0; i < array.Count; i++) + { + for (int j = 0; j < array[i].Count; j++) + { + if (array[i][j] > max) + { + index[0] = i; + index[1] = j; + max = array[i][j]; + } + } + } + return index; + } + + int mod(int a,int b) + { + return ((a % b + b) % b); + } + + private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) + { + print(); + } + } +} diff --git a/Codes.C#/P9/P9/mainForm.resx b/Codes.C#/P9/P9/mainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Codes.C#/P9/P9/mainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Codes.C#/Robot/Robot.sln b/Codes.C#/Robot/Robot.sln new file mode 100644 index 0000000..89f7075 --- /dev/null +++ b/Codes.C#/Robot/Robot.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robot", "Robot\Robot.csproj", "{068E95F5-FC34-4D4F-914B-C3C63338BEF2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {068E95F5-FC34-4D4F-914B-C3C63338BEF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {068E95F5-FC34-4D4F-914B-C3C63338BEF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {068E95F5-FC34-4D4F-914B-C3C63338BEF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {068E95F5-FC34-4D4F-914B-C3C63338BEF2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Codes.C#/Robot/Robot/Class1.cs b/Codes.C#/Robot/Robot/Class1.cs new file mode 100644 index 0000000..a39f068 --- /dev/null +++ b/Codes.C#/Robot/Robot/Class1.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Robot +{ + static public class ClassRobot + { + static public List Move(List prior, int u, double pExact, double pOvershoot, double pUndershoot) + { + int n = prior.Count; + List q = new List(); + for (int i = 0; i < n; i++) + { + //a mod b = (a % b + b) % b + q.Add(pExact * prior[((i - u) % n + n) % n]); + q[i] = q[i] + pOvershoot * prior[((i - 1 - u) % n + n) % n]; + q[i] = q[i] + pUndershoot * prior[((i + 1 - u) % n + n) % n]; + } + return q; + } + + static public List Sense(List prior, string observation, string[] world, double pHit, double pMiss, out List likelihood) + { + List tPosterior = new List(); + List q = new List(); + List posterior = new List(); + + for (int i = 0; i < prior.Count; i++) + { + int hit = observation.CompareTo(world[i]); // 相同为0,否则为1或-1 + q.Add(pHit * (1 - hit * hit) + pMiss * hit * hit); + tPosterior.Add(prior[i] * q[i]); + } + for (int i = 0; i < prior.Count; i++) + { + posterior.Add(tPosterior[i] / tPosterior.Sum()); + } + likelihood = q; + return posterior; + } + } +} diff --git a/Codes.C#/Robot/Robot/Properties/AssemblyInfo.cs b/Codes.C#/Robot/Robot/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c24d574 --- /dev/null +++ b/Codes.C#/Robot/Robot/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Robot")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Robot")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("05d36238-2192-47ad-8233-6907728abae4")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Codes.C#/Robot/Robot/Robot.csproj b/Codes.C#/Robot/Robot/Robot.csproj new file mode 100644 index 0000000..43312aa --- /dev/null +++ b/Codes.C#/Robot/Robot/Robot.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {068E95F5-FC34-4D4F-914B-C3C63338BEF2} + Library + Properties + Robot + Robot + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Codes.C#/readme.md b/Codes.C#/readme.md new file mode 100644 index 0000000..dccdc58 --- /dev/null +++ b/Codes.C#/readme.md @@ -0,0 +1,3 @@ +Operating environment: VS2013 or higher version. +Note: The Robot Folder is used to generate a dll which contains Move method and Sense method for robot + with the purpose of being used by other instances. \ No newline at end of file