2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 03:32:57 +00:00
This commit is contained in:
Ahmed Zamil 2023-03-28 03:16:29 +03:00
parent 1c440adf43
commit 1d48d97dbe
2 changed files with 81 additions and 22 deletions

View File

@ -35,9 +35,10 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(468, 409);
this.button1.Location = new System.Drawing.Point(535, 545);
this.button1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.Size = new System.Drawing.Size(86, 31);
this.button1.TabIndex = 0;
this.button1.Text = "Step";
this.button1.UseVisualStyleBackColor = true;
@ -46,21 +47,21 @@
// pbDraw
//
this.pbDraw.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pbDraw.Location = new System.Drawing.Point(36, 40);
this.pbDraw.Location = new System.Drawing.Point(12, 13);
this.pbDraw.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pbDraw.Name = "pbDraw";
this.pbDraw.Size = new System.Drawing.Size(639, 345);
this.pbDraw.Size = new System.Drawing.Size(1194, 499);
this.pbDraw.TabIndex = 1;
this.pbDraw.TabStop = false;
this.pbDraw.Paint += new System.Windows.Forms.PaintEventHandler(this.pbDraw_Paint);
//
// FGraph
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(729, 459);
this.ClientSize = new System.Drawing.Size(1218, 612);
this.Controls.Add(this.pbDraw);
this.Controls.Add(this.button1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FGraph";
this.Text = "FGraph";
((System.ComponentModel.ISupportInitialize)(this.pbDraw)).EndInit();

View File

@ -20,17 +20,69 @@ namespace Esiur.Analysis.Test
{
graph = new DirectedGraph<decimal>();
var n1 = graph.AddNode(1, "1", 80, 120);
var n2 = graph.AddNode(2, "2", 300, 120);
//var n1 = graph.AddNode(1, "1", 100, 300);
//var n2 = graph.AddNode(2, "2", 500, 300);
//graph.Link(n1, n2, (decimal)0.5, "1->2");
//graph.Link(n1, n1, (decimal)0.5, "1->1");
graph.Link(n1, n2, (decimal)0.5, "1->2");
graph.Link(n1, n1, (decimal)0.5, "1->1");
//graph.Link(n2, n1, (decimal)0.2, "2->1");
//graph.Link(n2, n2, (decimal)0.8, "2->2");
var n0 = graph.AddNode(1, "0", 100, 300);
var n1 = graph.AddNode(1, "1", 300, 300);
var n2 = graph.AddNode(2, "2", 500, 300);
var n3 = graph.AddNode(3, "3", 700, 300);
var n4 = graph.AddNode(4, "4", 900, 300);
var n5 = graph.AddNode(0, "5", 1100, 300);
graph.Link(n0, n0, (decimal)0.2, "00");
graph.Link(n0, n2, (decimal)0.2, "02");
graph.Link(n0, n3, (decimal)0.2, "03");
graph.Link(n0, n4, (decimal)0.2, "04");
graph.Link(n0, n5, (decimal)0.2, "05");
graph.Link(n1, n0, (decimal)0.1, "10");
graph.Link(n1, n1, (decimal)0.1, "11");
graph.Link(n1, n2, (decimal)0.2, "12");
graph.Link(n1, n3, (decimal)0.2, "13");
graph.Link(n1, n4, (decimal)0.2, "14");
graph.Link(n1, n5, (decimal)0.2, "15");
graph.Link(n2, n1, (decimal)0.2, "21");
graph.Link(n2, n2, (decimal)0.2, "22");
graph.Link(n2, n3, (decimal)0.2, "23");
graph.Link(n2, n4, (decimal)0.2, "24");
graph.Link(n2, n5, (decimal)0.2, "25");
graph.Link(n3, n2, (decimal)0.2, "32");
graph.Link(n3, n3, (decimal)0.2, "33");
graph.Link(n3, n4, (decimal)0.3, "34");
graph.Link(n3, n5, (decimal)0.3, "35");
graph.Link(n4, n3, (decimal)0.4, "43");
graph.Link(n4, n4, (decimal)0.3, "44");
graph.Link(n4, n5, (decimal)0.3, "45");
graph.Link(n5, n4, (decimal)0.5, "54");
graph.Link(n5, n5, (decimal)0.5, "55");
graph.Link(n2, n1, (decimal)0.2, "2->1");
graph.Link(n2, n2, (decimal)0.8, "2->2");
graph.Build();
for(var i = 0; i < graph.Nodes.Count; i++)
{
decimal sum = 0;
for(var j = 0; j < graph.Nodes.Count; j++)
{
sum += graph.TransitionMatrix[i, j];
}
if (sum != 1)
throw new Exception("Sum must be 1");
}
InitializeComponent();
}
@ -60,7 +112,7 @@ namespace Esiur.Analysis.Test
foreach (var node in graph.Nodes)
{
g.FillEllipse(Brushes.LightGreen, node.X - 30, node.Y - 30, 60, 60);
g.DrawString(node.Label, new Font("Arial", 26), Brushes.Blue, node.X - 15, node.Y - 20);
g.DrawString(node.Label, new Font("Arial", 26), Brushes.Blue, node.X - 20, node.Y - 20);
}
@ -72,33 +124,39 @@ namespace Esiur.Analysis.Test
public void DrawArcBetweenTwoPoints(Graphics g, Pen pen, PointF a, PointF b, string label)
{
if (a.X == b.X && a.Y == b.Y)
{
var c = new PointF(a.X, a.Y - 60);
// draw
g.DrawString(label, new Font("Arial", 14), Brushes.Black, new PointF(c.X, c.Y - 25));
g.DrawString(label, new Font("Arial", 12), Brushes.Black, new PointF(c.X, c.Y - 25));
g.DrawCurve(pen, new PointF[] { a, new PointF(a.X - 30, a.Y - 30), c, new PointF(a.X + 30, a.Y - 30), a });
}
else
{
float dis = (float)Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
if (b.X > a.X)
{
var c = new PointF(a.X + ((b.X - a.X) / 2), a.Y - 20);
var c = new PointF(a.X + ((b.X - a.X) / 2), a.Y - 0.25f * dis);
g.DrawCurve(pen, new PointF[] { a, c, b });
g.DrawString(label, new Font("Arial", 14), Brushes.Black, new PointF( c.X - 30, c.Y - 25));
g.DrawString(label, new Font("Arial", 12), Brushes.Black, new PointF( c.X - 30, c.Y - 25));
g.DrawLines(pen, new PointF[] { new PointF(c.X - 6, c.Y - 6), c, new PointF(c.X - 6, c.Y + 6) });
}
else
{
var c = new PointF(b.X + ((a.X - b.X) / 2), b.Y + 20);
var c = new PointF(b.X + ((a.X - b.X) / 2), b.Y + 0.25f * dis);
g.DrawCurve(pen, new PointF[] { b, c, a });
g.DrawString(label, new Font("Arial", 14), Brushes.Black, new PointF(c.X - 30, c.Y + 5));
g.DrawString(label, new Font("Arial", 12), Brushes.Black, new PointF(c.X - 30, c.Y + 5));
g.DrawLines(pen, new PointF[] { new PointF(c.X + 6, c.Y + 6), c, new PointF(c.X + 6, c.Y - 6) });
}
}
}