Commit b41e52e8 authored by Unknown's avatar Unknown

Сделал реализацию SQRT декомпозиции и базовый вывод массива

parent 73de435b
......@@ -28,13 +28,102 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.debug_log = new System.Windows.Forms.TextBox();
this.source_array_panel = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.support_array_panel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// debug_log
//
this.debug_log.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.debug_log.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.debug_log.Location = new System.Drawing.Point(12, 448);
this.debug_log.Multiline = true;
this.debug_log.Name = "debug_log";
this.debug_log.ReadOnly = true;
this.debug_log.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.debug_log.Size = new System.Drawing.Size(1240, 76);
this.debug_log.TabIndex = 0;
//
// source_array_panel
//
this.source_array_panel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.source_array_panel.AutoScroll = true;
this.source_array_panel.Location = new System.Drawing.Point(16, 41);
this.source_array_panel.Name = "source_array_panel";
this.source_array_panel.Size = new System.Drawing.Size(1236, 104);
this.source_array_panel.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(192, 24);
this.label1.TabIndex = 2;
this.label1.Text = "Исходный массив:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 432);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(63, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Debug Log:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.label3.Location = new System.Drawing.Point(12, 148);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(272, 24);
this.label3.TabIndex = 5;
this.label3.Text = "Вспомогательный массив:";
//
// support_array_panel
//
this.support_array_panel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.support_array_panel.AutoScroll = true;
this.support_array_panel.Location = new System.Drawing.Point(16, 180);
this.support_array_panel.Name = "support_array_panel";
this.support_array_panel.Size = new System.Drawing.Size(1236, 98);
this.support_array_panel.TabIndex = 4;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
this.ClientSize = new System.Drawing.Size(1264, 536);
this.Controls.Add(this.label3);
this.Controls.Add(this.support_array_panel);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.source_array_panel);
this.Controls.Add(this.debug_log);
this.Name = "Form1";
this.Text = "Визуализатор SQRT-декомпозиции";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox debug_log;
private System.Windows.Forms.Panel source_array_panel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel support_array_panel;
}
}
......@@ -12,9 +12,128 @@ namespace SQRT_Decomposition_Visualizer
{
public partial class Form1 : Form
{
class View
{
Panel panel;
string tag;
public View(Panel panel, string tag)
{
this.panel = panel;
this.tag = tag;
}
public void DisplayArray(List<int> a)
{
int x = 0;
for (int i = 0; i < a.Count; i++)
{
Label tmp = new Label();
tmp.Text = a[i].ToString();
tmp.Font = new Font(tmp.Font.FontFamily, 14);
tmp.BorderStyle = BorderStyle.FixedSingle;
tmp.BackColor = Color.White;
tmp.AutoSize = true;
tmp.Padding = new Padding(10, 10, 10, 10);
tmp.Name = "array_" + tag + a[i];
tmp.Location = new Point(x, 20);
panel.Controls.Add(tmp);
Label tmp1 = new Label();
tmp1.Text = i.ToString();
tmp1.Font = new Font(tmp.Font.FontFamily, 10);
tmp1.ForeColor = Color.Gray;
tmp1.AutoSize = true;
tmp1.Name = "array_" + tag + a[i];
tmp1.Location = new Point(x, 0);
panel.Controls.Add(tmp1);
x += (int)tmp.CreateGraphics().MeasureString(tmp.Text, tmp.Font).Width + 22;
}
}
}
List<int> GenerateArray(int lenght, int min=0, int max = 100)
{
List<int> gen = new List<int>();
Random r = new Random();
for (int i = 0; i < lenght; i++)
{
gen.Add(r.Next(min,max));
}
return gen;
}
public Form1()
{
InitializeComponent();
//CHECK SQRT
List<int> source_array = GenerateArray(25, 1, 50);
debug_log.AppendText("START ARRAY:\r\n");
foreach (int e in source_array)
{
debug_log.AppendText(e + " ");
}
SQRTDecompositionSum sqrtd = new SQRTDecompositionSum(source_array);
debug_log.AppendText("\r\nSegment length: " + sqrtd.GetSegmentLength());
debug_log.AppendText("\r\nSUPPORT ARRAY:\r\n");
foreach (int e in sqrtd.GetSupportArray())
{
debug_log.AppendText(e + " ");
}
debug_log.AppendText("\r\nSum from range (2, 8): " + sqrtd.GetRangeSum(2,8));
//VISUALIZER
View source_array_view = new View(source_array_panel, "source");
source_array_view.DisplayArray(source_array);
View support_array_view = new View(support_array_panel, "support");
support_array_view.DisplayArray(sqrtd.GetSupportArray());
}
}
class SQRTDecompositionSum
{
List<int> source, support;
int segment_length;
public SQRTDecompositionSum(List<int> src)
{
source = src;
CalculateSupportArray();
}
public int GetSegmentLength()
{
return segment_length;
}
public List<int> GetSupportArray()
{
return support;
}
void CalculateSupportArray()
{
segment_length = (int)Math.Sqrt(source.Count + .0) + 1;
support = new List<int>(new int[segment_length]);
for (int i = 0; i < source.Count; ++i)
support[i / segment_length] += source[i];
}
public int GetRangeSum(int l, int r)
{
int sum = 0;
int c_l = l / segment_length, c_r = r / segment_length;
if (c_l == c_r)
{
for (int i = l; i <= r; ++i)
sum += source[i];
} else
{
for (int i = l, end = (c_l + 1) * segment_length - 1; i <= end; ++i)
sum += source[i];
for (int i = c_l + 1; i <= c_r - 1; ++i)
sum += support[i];
for (int i = c_r * segment_length; i <= r; ++i)
sum += source[i];
}
return sum;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
......@@ -53,6 +53,9 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment