📄 frm_af_xl.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace bs
{
public partial class frm_af_xl : Form
{
public ArrayList arrXlq = null;//训练前随机生成的边的权值
public LineArray arrXlh = null;//训练后相应的权值
public ArrayList arrYb = null;//生成训练样本的权值
public Image image = null;//画图的图片
public Graphics g1 = null;
public Graphics g2 = null;
public int NumB=0;//边的条数,省去访问了
public frm_af_xl()
{
InitializeComponent();
}
private void frm_af_xl_Load(object sender, EventArgs e)
{
#region 窗体Load事件
if (this.arrXlh.Count == 0 || this.arrXlq.Count == 0 || this.arrYb.Count == 0)
{
MessageBox.Show("边的权值不完全!");
return;
}
else
{
for (int i = 0; i < this.arrXlh.Count; i++)
{
ListViewItem li = new ListViewItem((i + 1).ToString());
li.SubItems.Add((string)this.arrYb[i]);
li.SubItems.Add((string)this.arrXlq[i]);
li.SubItems.Add(this.arrXlh[i].wij);
this.listView1.Items.Add(li);
this.NumB++;
}
//MessageBox.Show(listView1.Items.Count.ToString());
}
g1 = this.pictureBox1.CreateGraphics();
this.image = new Bitmap(this.pictureBox1.Width,this.pictureBox1.Height,g1);
g2 = Graphics.FromImage(this.image);
this.pictureBox1.Image = this.image;
Pen pxy = new Pen(Color.Red, 5);
g2.DrawLine(pxy, 20, 20, 20, 650);//y轴
g2.DrawLine(pxy, 20, 650, this.pictureBox1.Width-20, 650);//x轴
Pen pYb = new Pen(Color.Yellow, 5);//样本权值曲线的画笔
Point ps=new Point();
Point pd=new Point();
for (int i = 0; i < this.NumB-1; i++)//样本权值曲线
{
double d1 = Convert.ToDouble((string)this.arrYb[i]);
d1 *= 100d;
int t1 = (int)d1;
ps.X=i*(600/(this.NumB-1))+20;
ps.Y=500-t1;
double d2 = Convert.ToDouble((string)this.arrYb[i+1]);
d2 *= 100d;
int t2 = (int)d2;
pd.X=(i+1)*(600/(this.NumB-1))+20;
pd.Y =500-t2;
g2.DrawLine(pYb, ps, pd);
SolidBrush sr = new SolidBrush(Color.LightSkyBlue);
g2.FillEllipse(sr, ps.X-5,ps.Y-5,10,10);
g2.FillEllipse(sr, pd.X - 5, pd.Y - 5, 10, 10);
}
g2.DrawLine(pYb, this.pictureBox1.Width - 100, 25, this.pictureBox1.Width - 60,25);
Font font=new Font(FontFamily.GenericSerif,10);
SolidBrush br=new SolidBrush(Color.Red);
Point pf=new Point();
pf.X=this.pictureBox1.Width-60;
pf.Y=20;
g2.DrawString("样本权值", font, br, pf);
Pen pSj = new Pen(Color.Blue,5);//随机生成的权值
for (int i = 0; i < this.NumB - 1; i++)//随机生成权值曲线
{
double d1 = Convert.ToDouble((string)this.arrXlq[i]);
d1 *= 100d;
int t1 = (int)d1;
ps.X = i * (600 / (this.NumB - 1)) + 20;
ps.Y = 500 - t1;
double d2 = Convert.ToDouble((string)this.arrXlq[i + 1]);
d2 *= 100d;
int t2 = (int)d2;
pd.X = (i + 1) * (600 / (this.NumB - 1)) + 20;
pd.Y = 500 - t2;
g2.DrawLine(pSj, ps, pd);
SolidBrush sr = new SolidBrush(Color.LightSkyBlue);
g2.FillEllipse(sr, ps.X - 5, ps.Y - 5, 10, 10);
g2.FillEllipse(sr, pd.X - 5, pd.Y - 5, 10, 10);
}
g2.DrawLine(pSj, this.pictureBox1.Width - 100, 45, this.pictureBox1.Width - 60, 45);
Point pf1 = new Point();
pf1.X = this.pictureBox1.Width - 60;
pf1.Y = 40;
g2.DrawString("随机权值", font, br, pf1);
g2.DrawString("权值", font, br, 20,20);
g2.DrawString("边的个数", font, br, this.pictureBox1.Width - 100, 630);
Pen pxlh = new Pen(Color.Orange, 5);
for (int i = 0; i < this.NumB - 1; i++)//训练后权值曲线
{
double d1 = Convert.ToDouble(this.arrXlh[i].wij);
d1 *= 100d;
int t1 = (int)d1;
ps.X = i * (600 / (this.NumB - 1)) + 20;
ps.Y = 500 - t1;
double d2 = Convert.ToDouble(this.arrXlh[i+1].wij);
d2 *= 100d;
int t2 = (int)d2;
pd.X = (i + 1) * (600 / (this.NumB - 1)) + 20;
pd.Y = 500 - t2;
g2.DrawLine(pxlh, ps, pd);
SolidBrush sr = new SolidBrush(Color.LightSkyBlue);
g2.FillEllipse(sr, ps.X - 5, ps.Y - 5, 10, 10);
g2.FillEllipse(sr, pd.X - 5, pd.Y - 5, 10, 10);
}
g2.DrawLine(pxlh, this.pictureBox1.Width - 100, 65, this.pictureBox1.Width - 60, 65);
Point pf2 = new Point();
pf2.X = this.pictureBox1.Width - 60;
pf2.Y = 60;
g2.DrawString("训练权值", font, br, pf2);
#endregion
}
private void button2_Click(object sender, EventArgs e)
{
#region 保存图片代码
if (this.image == null)
{
MessageBox.Show("您还没有画图");
return;
}
else
{
SaveFileDialog sf = new SaveFileDialog();
sf.DefaultExt = ".bmp";
sf.Filter = "bmp文件|*.bmp";
if (sf.ShowDialog() == DialogResult.OK)
{
try
{
this.image.Save(sf.FileName);
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
}
}
#endregion
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -