public void run() { CSVFile csvFile = new CSVFile(); var evo = getNewIntace(); csvFile.Write(0, 0, evo.descricao()); csvFile.addCabecalhoE(data); Hipotese best = null; for (int i = 0; i < tests; i++) { evo = getNewIntace(); evo.run(); Hipotese hip = evo.getBest(); if (best == null || best.eval > hip.eval) // guardar a melhor { best = new Hipotese(hip, "Melhor", hip.interacao); best.evaluate(); } csvFile.addBestEvolutivo(evo); } best.evaluate(); csvFile.addHipoteseE(best); csvFile.toFile(outputfile); }
public void run() { CSVFile csvFile = new CSVFile(); var evo = getNewIntace(); csvFile.Write(0, 0, evo.descricao()); csvFile.addCabecalhoH(data); Hipotese bestE = null; Hipotese bestT = null; for (int i = 0; i < tests; i++) { evo = getNewIntace(); evo.run(); Hipotese hip = evo.getBest(); if (bestT == null || bestT.eval > hip.eval) // guardar a melhor { bestT = new Hipotese(evo.solTrepaColinas, "Melhor", i); bestE = new Hipotese(evo.solEHibrido, "Melhor", i); bestT.evaluate(); bestE.evaluate(); } csvFile.addBestHibrido(evo); } bestE.evaluate(); bestT.evaluate(); csvFile.addHipoteseH(bestE, bestT); csvFile.toFile(outputfile); }
protected virtual Hipotese gera_vizinho(Hipotese old) { var newHip = new Hipotese(old, getName(), iteracao); var rand = this.rand.Next(newHip.NCMoedas.Count); var rand2 = this.rand.NextDouble(); if (rand2 < 0.5) { --newHip.NCMoedas[rand]; } else { ++newHip.NCMoedas[rand]; } for (int i = 0; i < newHip.NCMoedas.Count; i++) { if (newHip.NCMoedas[i] < 0) { newHip.NCMoedas[i] = 0; } } return(newHip); }
public virtual Hipotese init() { var hip = new Hipotese(data, getName(), iteracao); for (var i = 0; i < hip.NCMoedas.Count; ++i) { hip.NCMoedas[i] = 0; } return(hip); }
public override Hipotese init() { var max = (int)(data.objetivo / data.moedas[0] / 10); var hip = new Hipotese(data, getName(), iteracao); for (var i = 0; i < hip.NCMoedas.Count; ++i) { hip.NCMoedas[i] = rand.Next(0, max); } return(hip); }
protected void init_pop() { var max = (int)(data.objetivo / data.moedas[0] / 50); pop = new List <Hipotese>(); for (var i = 0; i < popSize; i++) { var hip = new Hipotese(data, getName(), iteracao); for (var j = 0; j < data.moedas.Count; j++) { hip.NCMoedas[j] = getRandN(max); } pop.Add(hip); } }
public int addHipoteseTC(Hipotese hip, int x = 0) { if (x == 0) { ++lastLine; } Write(x++, lastLine, hip.getSource()); Write(x++, lastLine, hip.interacao.ToString()); for (var i = 0; i < hip.NCMoedas.Count; ++i, ++x) { Write(x, lastLine, $"{hip.NCMoedas[i]}"); } Write(x++, lastLine, hip.sum.ToString()); Write(x++, lastLine, hip.eval.ToString()); return(x); }
public override void run() { if (log) { Console.WriteLine("Hibrido:"); Console.Out.WriteLine($"{id} -> Inicio Evolutivo"); } _evolutivo.run(); solEHibrido = _evolutivo.getBest(); _trepaColinas.setSolInit(solEHibrido); if (log) { Console.Out.WriteLine($"{id} -> Inicio Trepa-Colinas"); } _trepaColinas.run(); solTrepaColinas = _trepaColinas.getBest(); bestSol = solTrepaColinas; if (log) { Console.Out.WriteLine($"{id} -> Terminou"); } }
public override void run() { if (log) { Console.WriteLine("TrepaColinas:"); } Hipotese hip = bestSol; hip.evaluate(); if (Program.debug) { imprimeHipotese(hip); } for (iteracao = 0; iteracao < data.MaxIteracoes; ++iteracao) { hip = gera_vizinho(hip); hip.evaluate(); if (Program.debug) { imprimeHipotese(hip); } if (bestSol.compareTo(hip) < 0) { bestSol = hip; } if (hip.valido == 0) { if (log) { Console.Out.WriteLine("Solução encontrada, Iteração: " + iteracao); } break; } } }
public void run() { CSVFile csvFile = new CSVFile(); TrepaColinas tr = getNewIntace(); csvFile.Write(0, 0, tr.descricao()); csvFile.addCabecalhoTC(data); Hipotese best = null; for (int i = 0; i < tests; i++) { tr = getNewIntace(); tr.run(); Hipotese hip = tr.getBest(); if ((best == null || best.eval > hip.eval) && hip.valido == 0) // guardar a melhor { best = new Hipotese(hip, "Melhor", hip.interacao); best.evaluate(); } //Console.Out.WriteLine(hip.ToString2() + " : " + hip.ToString()); //System.Threading.Thread.Sleep(100); csvFile.addBestTrepaColinas(tr); } if (best != null) { best.evaluate(); csvFile.addHipoteseTC(best); } else { csvFile.Write(0, -1, "Nao foi encontrada nenhuma solucao"); } csvFile.toFile(outputfile); }
protected override Hipotese gera_vizinho(Hipotese old) { var newHip = new Hipotese(old, getName(), iteracao); var rand = this.rand.Next(newHip.NCMoedas.Count); if (old.valido < 0) { --newHip.NCMoedas[rand]; } if (old.valido > 0) { ++newHip.NCMoedas[rand]; } for (int i = 0; i < newHip.NCMoedas.Count; i++) { if (newHip.NCMoedas[i] < 0) { newHip.NCMoedas[i] = 0; } } return(newHip); }
public TrepaColinasV3(Data data, Hipotese init) : base(data, init) { }
public TrepaColinas(Data data, Hipotese init) : base(data) { bestSol = init; }
public virtual void setSolInit(Hipotese initSol) { bestSol = initSol; }
public void addHipoteseH(Hipotese bestE, Hipotese bestT) { addHipoteseTC(bestT, addHipoteseE(bestE) + 1); }