public void Best(int count_row, int g_size, Piping_System piping) //Selection of the best individuals from the population { double F = 100000; //Evaluation Value double F2 = 100000; int A = 0; int B = 0; for (int i = 0; i < size; i++) { double fit = designplans[i].Fittness(count_row, g_size, piping); if (fit < F) { F = fit; B = A; A = i; } else if (fit < F2) { F2 = fit; B = i; } } best = designplans[A]; second = designplans[B]; }
private void button3_Click_1(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox4.Text = openFileDialog1.FileName; string ExcelBookFileName = textBox4.Text; Excel.Application ExcelApp = new Excel.Application(); ExcelApp.Visible = false; Excel.Workbook wb = ExcelApp.Workbooks.Open(ExcelBookFileName); Excel.Worksheet ws1 = wb.Sheets[1]; ws1.Select(Type.Missing); count_row = ws1.get_Range("A2").End[Excel.XlDirection.xlDown].Row - 1;//A1から数えているので"-1"している count_row = cluster数 //count_column = ws1.get_Range("A2").End[Excel.XlDirection.xlToRight].Column;//A1から数えている Excel.Range range = ExcelApp.get_Range("A1", "K150");//K150までの情報は読み取り可能→一応クラスタは150個まで if (range != null) { for (int i = 0; i < count_row; i++) { string cluster_name = Convert.ToString(range.Value2[i + 2, 1]); //ID int size_x = Convert.ToInt32(range.Value2[i + 2, 2]); //width int size_y = Convert.ToInt32(range.Value2[i + 2, 3]); //height int const_f = Convert.ToInt32(range.Value2[i + 2, 4]); //floor int const_p = Convert.ToInt32(range.Value2[i + 2, 5]); //partial int const_3rd = Convert.ToInt32(range.Value2[i + 2, 6]); //3rd dk int const_2nd = Convert.ToInt32(range.Value2[i + 2, 7]); //2nd dk string side = Convert.ToString(range.Value2[i + 2, 8]); //(S)or(P) string pos_deck = Convert.ToString(range.Value2[i + 2, 9]); //deck int pos_row = Convert.ToInt32(range.Value2[i + 2, 10]); //row int pos_col = Convert.ToInt32(range.Value2[i + 2, 11]); //column form_cluster_Inf.Add(new Cluster_Inf(cluster_name, size_x, size_y, const_f, const_p, const_2nd, const_3rd, pos_deck, pos_row, pos_col, side)); listBox1.Items.Add(form_cluster_Inf[i].c_data); } } form_cluster = new Cluster(form_cluster_Inf); //----------接続関係の読み取り---------------------------- Excel.Worksheet ws2 = wb.Sheets[2]; ws2.Select(Type.Missing); piping = new Piping_System(); piping.Interaction(count_row, ws2); //-------------------------------------------------------- wb.Close(false, Type.Missing, Type.Missing); ExcelApp.Quit(); } }
public double Fittness(int count_row, int g_size, Piping_System piping) //Calculation of fitness { if (penalty.Count != 0) //Give the greater the number of overlapping penalty { PipeLength = piping.Calc_Length(count_row, C_List, g_size); fittness = PipeLength + (100 * penalty.Count);//Number only 100 lattice amount of penalty of overlap return(fittness); } { PipeLength = piping.Calc_Length(count_row, C_List, g_size); fittness = PipeLength; return(fittness); } }
public void makeGeneration2(Random r1, Generation GB, int popu_size, int n, Deck[] form_decks, int count_row, Cluster cluster_orig, int g_size, Piping_System piping_orig)//1-point crossover { Population P1 = new Population(popu_size, n); Population P2 = P1.Tournament(r1, GB.populations, count_row, form_decks, cluster_orig); Population P3 = P2.Crossover(r1, P2, count_row); Population P4 = P3.Mutation(r1, P3, count_row); Population P5 = P4.DesignPlan(P4, form_decks, count_row, cluster_orig, g_size, piping_orig, r1); populations = P5; }
public void makeGeneration1(int popu_size, int n, Deck[] deck_GA, int count_row, Cluster cluster_GA, int g_size, Piping_System piping_GA, Random r1) { Population P = new Population(popu_size, n); P.makePopulaiton1(deck_GA, count_row, cluster_GA, r1, piping_GA); P.Best(count_row, g_size, piping_GA); populations = P; }
public Population DesignPlan(Population P, Deck[] deck_GA, int count_row, Cluster cluster_GA, int g_size, Piping_System piping, Random r1) { for (int i = 0; i < size; i++) { designplans[i].makeDesignplan2(count_row, deck_GA, cluster_GA); //-----------designplans[i]Initialize after Generation, The deck Information--------------- Deck deck = new Deck(); deck.Initialize(deck_GA); //------------------------------------------------------------------------ } P.Best(count_row, g_size, piping); return(P); }
public void makePopulaiton1(Deck[] deck_GA, int count_row, Cluster cluster_GA, Random r1, Piping_System piping_GA) //First Generation { designplans = new DesignPlan[size]; for (int i = 0; i < size; i++) //size: generation size { DesignPlan C1 = new DesignPlan(count_row); C1.makeDesignplan1(count_row, r1, cluster_GA, deck_GA); designplans[i] = C1; //-----------designplans[i] Initialize after Generation, The deck Information--------------- Deck deck = new Deck(); deck.Initialize(deck_GA); //------------------------------------------------------------------------ } }
public GA(Cluster form_cluster, Deck[] form_decks, Piping_System piping) { cluster_GA = form_cluster; deck_GA = form_decks; piping_GA = piping; }