private ObjMochila mochilaFilha(ObjMochila mochila1, ObjMochila mochila2) { ObjMochila nova = new ObjMochila(); nova.Nome = "Mochila-" + (objParameters.Index + 1); for (int a = 0; a < mochila1.ListItens.Count; a++) { if (mochila1.ListItens[a] % 2 == 0) { nova.addItens(a, Mutacao(mochila1.ListItens[a])); } else { nova.addItens(a, Mutacao(mochila2.ListItens[a])); } } return(nova); }
private void listBox_Mochilas_SelectedIndexChanged(object sender, EventArgs e) { int indexMochila = listBox_Mochilas.SelectedIndex; ObjParameters parameters = new ObjParameters(); ObjMochila objMochila = parameters.GetMochilas()[indexMochila]; listBox_Itens_Mochila.Items.Clear(); for (int i = 0; i < objMochila.ListItens.Count; i++) { if (objMochila.ListItens[i] == 1) { ObjItem item = parameters.GetItens()[i]; listBox_Itens_Mochila.Items.Add(item.Nome + " = " + item.Peso + "Kg - R$ " + item.Valor); } } }
private List <ObjMochila> Cruzamento() { int total = objParameters.MelhoresPais; List <ObjMochila> novasMochilas = new List <ObjMochila>(); for (int i = 0; i < total; i++) { int index1 = i; int index2 = i + 1; ObjMochila mochila1 = mochilas[index1]; ObjMochila mochila2 = mochilas[index2]; novasMochilas.Add(mochilaFilha(mochila1, mochila2)); objParameters.Index += 1; novasMochilas.Add(mochilaFilha(mochila2, mochila1)); objParameters.Index += 1; } return(novasMochilas); }
private void listBox_Mochilas_best_SelectedIndexChanged(object sender, EventArgs e) { ObjParameters parameters = new ObjParameters(); string conteudo = listBox_Mochilas_best.SelectedItem.ToString(); int ini = conteudo.IndexOf(" ="); int fin = conteudo.Length - ini; string aux = conteudo.Substring(ini, fin); conteudo = conteudo.Replace(aux, ""); ObjMochila objMochila = parameters.GetMochilas().Single(s => s.Nome == conteudo); listBox_bestItens.Items.Clear(); for (int i = 0; i < objMochila.ListItens.Count; i++) { if (objMochila.ListItens[i] == 1) { ObjItem item = parameters.GetItens()[i]; listBox_bestItens.Items.Add(item.Nome + " = " + item.Peso + "Kg - R$ " + item.Valor); } } }