using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ZedGraph; namespace GeneticAlgorithm { public partial class Form1 : Form { GA spinsGA; int nsteps; double beta; double[] results; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { nsteps = 500; beta = 1; spinsGA = new GA(nsteps, 100, 0.1); } private void but_run_Click(object sender, EventArgs e) { results = spinsGA.Run(); CreateGraph(ObjectiveGraph); } private void CreateGraph(ZedGraphControl zgc) { // get a reference to the GraphPane GraphPane myPane = zgc.GraphPane; // Set the Titles myPane.Title.Text = "Minimum Energy in Population (Beta = "+ beta.ToString() +")"; myPane.XAxis.Title.Text = "Evolutionary Progress"; myPane.YAxis.Title.Text = "Energy"; // Make up some data arrays based on the Sine function double x, y; PointPairList list1 = new PointPairList(); for (int i = 0; i < nsteps; i++) { x = i; y = results[i]; list1.Add(x, y); } LineItem myCurve = myPane.AddCurve("Energy", list1, Color.Black, SymbolType.None); PointPairList list2 = new PointPairList(); list2.Add(0, spinsGA.LB); list2.Add(nsteps, spinsGA.LB); LineItem LB = myPane.AddCurve("LB", list2, Color.Red, SymbolType.None); // Tell ZedGraph to refigure the axes since the data have changed zgc.AxisChange(); } } }