public void afisTrace(String s) { Console.WriteLine(s+"\n"); state temp = new state(start); for (int i = 0; i < s.Length; i++) { if (s[i] == 'u') { temp.mutasus(); temp.afis(); Console.WriteLine("------------"); } if (s[i] == 'j') { temp.mutajos(); temp.afis(); Console.WriteLine("------------"); } if (s[i] == 's') { temp.mutast(); temp.afis(); Console.WriteLine("------------"); } if (s[i] == 'd') { temp.mutadr(); temp.afis(); Console.WriteLine("------------"); } } }
public void afisTrace(String s) { Console.WriteLine(s + "\n"); state temp = new state(start); for (int i = 0; i < s.Length; i++) { if (s[i] == 'u') { temp.mutasus(); temp.afis(); Console.WriteLine("------------"); } if (s[i] == 'j') { temp.mutajos(); temp.afis(); Console.WriteLine("------------"); } if (s[i] == 's') { temp.mutast(); temp.afis(); Console.WriteLine("------------"); } if (s[i] == 'd') { temp.mutadr(); temp.afis(); Console.WriteLine("------------"); } } }
public bool executeHC() { DateTime dt = DateTime.Now; state temp; var distCalc = new Dictionary<state, int>(); val = start; while ((distCalc.Count != 0 ||cnt==0) && (cnt < 3000)) { distCalc = new Dictionary<state, int>(); Console.WriteLine("PAS:"******"OMG SUCCESS!!!"); trace = val.rettr(); Console.WriteLine(trace); afisTrace(trace); // Thread.Sleep(5000); return true; } vis.Add(val); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) if (isVisited(temp) == false) distCalc.Add(temp, calcDist(temp)); else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) if (isVisited(temp) == false) distCalc.Add(temp, calcDist(temp)); else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) if (isVisited(temp) == false) distCalc.Add(temp, calcDist(temp)); else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) if (isVisited(temp) == false) distCalc.Add(temp, calcDist(temp)); else Console.WriteLine("Stare deja vizitata!"); var q = distCalc.OrderBy(k => k.Value); foreach (var item in q) { val = item.Key; break; } } ts = DateTime.Now - dt; Console.WriteLine("NU S-A GASIT SOLUTIE!!!"); return false; }
public void executeBKT() { cnt++; Console.WriteLine("APELARI:"+cnt); if(cnt>4600) { Console.WriteLine("NU EXISTA SOLUTIE!"); Thread.Sleep(20000); Environment.Exit(0); } if (val == fin) { Console.WriteLine("OMG SUCCESS!:"); Thread.Sleep(2000); Console.Clear(); afisTrace(trace); Thread.Sleep(20000); Environment.Exit(1); } state temp = new state(val); // Thread.Sleep(500); if (temp.mutasus()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); msus = new node(temp); msus.setTrace(trace + 'u'); } else Console.WriteLine("Stare deja vizitata!"); } // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); mjos = new node(temp); mjos.setTrace(trace + 'j'); } else Console.WriteLine("Stare deja vizitata!"); } // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); mst = new node(temp); mst.setTrace(trace + 's'); } else Console.WriteLine("Stare deja vizitata!"); } // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); mdr = new node(temp); mdr.setTrace(trace + 'd'); } else Console.WriteLine("Stare deja vizitata!"); } // Thread.Sleep(500); /* state[] xtest = (state [])vis.ToArray(typeof(state)); Console.WriteLine("---------------------------"); for (int c = 0; c < xtest.Length; c++) xtest[c].afis(); Console.WriteLine("---------------------------"); */ if (msus != null) msus.executeBKT(); if (mjos != null) mjos.executeBKT(); if(mst!=null) mst.executeBKT(); if(mdr!=null) mdr.executeBKT(); }
public bool executeBF4() { DateTime dt = DateTime.Now; state temp; devisC.Enqueue(start); var distCalc = new Dictionary<state, int>(); while (devisC.Count != 0 && cnt < 3000) { val = devisC.Dequeue(); distCalc = new Dictionary<state, int>(); Console.WriteLine("PAS:"******"OMG SUCCESS!!!"); trace = val.rettr(); Console.WriteLine(trace); // afisTrace(trace); // Thread.Sleep(5000); return true; } vis.Add(val); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) if (isVisited(temp) == false) distCalc.Add(temp, calcDiff(temp)); else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) if (isVisited(temp) == false) distCalc.Add(temp, calcDiff(temp)); else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) if (isVisited(temp) == false) distCalc.Add(temp, calcDiff(temp)); else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) if (isVisited(temp) == false) distCalc.Add(temp, calcDiff(temp)); else Console.WriteLine("Stare deja vizitata!"); var q = distCalc.OrderBy(k => k.Value); foreach (var item in q) devisC.Enqueue(item.Key); } ts = DateTime.Now - dt; Console.WriteLine("NU S-A GASIT SOLUTIE!!!"); return false; }
public bool executeA() { DateTime dt = DateTime.Now; state temp; devisA.Add(start,calcDist(start)); while (devisA.Count != 0 && cnt < 3000) { val = devisA.First().Key; devisA.Remove(val); Console.WriteLine("PAS:"******"OMG SUCCESS!!!"); trace = val.rettr(); //Console.WriteLine(trace); afisTrace(trace); // Thread.Sleep(5000); return true; } vis.Add(val); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) if (isVisited(temp) == false) if (!devisA.ContainsKey(temp)) devisA.Add(temp, calcA(temp)); else if(calcA(temp)<devisA[temp]) { devisA.Remove(temp); devisA.Add(temp, calcA(temp)); } else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) if (isVisited(temp) == false) if (!devisA.ContainsKey(temp)) devisA.Add(temp, calcA(temp)); else if(calcA(temp)<devisA[temp]) { devisA.Remove(temp); devisA.Add(temp,calcA(temp)); } else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) if (isVisited(temp) == false) if (!devisA.ContainsKey(temp)) devisA.Add(temp, calcA(temp)); else if(calcA(temp)<devisA[temp]) { devisA.Remove(temp); devisA.Add(temp,calcA(temp)); } else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) if (isVisited(temp) == false) if (!devisA.ContainsKey(temp)) devisA.Add(temp, calcA(temp)); else if(calcA(temp)<devisA[temp]) { devisA.Remove(temp); devisA.Add(temp,calcA(temp)); } else Console.WriteLine("Stare deja vizitata!"); var v = devisA.OrderBy(k => k.Value); devisA = new Dictionary<state, int>(); foreach (var item in v) devisA.Add(item.Key, item.Value); } ts = DateTime.Now - dt; Console.WriteLine("NU S-A GASIT SOLUTIE!!!"); return false; }
public bool executeBF2() { DateTime dt = DateTime.Now; state temp; while (true) { cnt++; Console.WriteLine("APELARI:" + cnt); if (val == fin) { ts = DateTime.Now - dt; Console.WriteLine("OMG SUCCESS!:"); // Thread.Sleep(2000); Console.Clear(); afisTrace(trace); // Thread.Sleep(20000); return(true); } state min = new state(); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); min = new state(temp); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); if (calcDiff(temp) < calcDiff(min)) { min = new state(temp); } } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); if (calcDiff(temp) < calcDiff(min)) { min = new state(temp); } } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); if (calcDiff(temp) < calcDiff(min)) { min = new state(temp); } } else { Console.WriteLine("Stare deja vizitata!"); } } val = new state(min); setTrace(trace + val.rettr()); if (val == new state()) { ts = DateTime.Now - dt; Console.WriteLine("NU EXISTA SOLUTIE!"); // Thread.Sleep(20000); return(false); } } }
/* public state bestFind(state[] x) * { * state min = x[0]; * for (int i = 1; i < x.Length; i++) * if (calcDist(x[i]) < calcDist(min)) * min = new state(x[i]); * return min; * }*/ #endregion public void executeBKT() //DFS ? { cnt++; Console.WriteLine("APELARI:" + cnt); if (cnt > 4600) { Console.WriteLine("NU EXISTA SOLUTIE!"); Thread.Sleep(20000); Environment.Exit(0); } if (val == fin) { Console.WriteLine("OMG SUCCESS!:"); Thread.Sleep(2000); Console.Clear(); afisTrace(trace); Thread.Sleep(20000); Environment.Exit(1); } state temp = new state(val); // Thread.Sleep(500); if (temp.mutasus()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); msus = new node(temp); msus.setTrace(trace + 'u'); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); mjos = new node(temp); mjos.setTrace(trace + 'j'); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); mst = new node(temp); mst.setTrace(trace + 's'); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) { if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); mdr = new node(temp); mdr.setTrace(trace + 'd'); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); /* state[] xtest = (state [])vis.ToArray(typeof(state)); * Console.WriteLine("---------------------------"); * for (int c = 0; c < xtest.Length; c++) * xtest[c].afis(); * Console.WriteLine("---------------------------"); */ if (msus != null) { msus.executeBKT(); } if (mjos != null) { mjos.executeBKT(); } if (mst != null) { mst.executeBKT(); } if (mdr != null) { mdr.executeBKT(); } }
} //A*(dist) public bool executeHC() { DateTime dt = DateTime.Now; state temp; var distCalc = new Dictionary <state, int>(); val = start; while ((distCalc.Count != 0 || cnt == 0) && (cnt < 3000)) { distCalc = new Dictionary <state, int>(); Console.WriteLine("PAS:"******"OMG SUCCESS!!!"); trace = val.rettr(); Console.WriteLine(trace); afisTrace(trace); // Thread.Sleep(5000); return(true); } vis.Add(val); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDist(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDist(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDist(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDist(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } var q = distCalc.OrderBy(k => k.Value); foreach (var item in q) { val = item.Key; break; } } ts = DateTime.Now - dt; Console.WriteLine("NU S-A GASIT SOLUTIE!!!"); return(false); } //hill climbing
} //bfs diff public bool executeA() { DateTime dt = DateTime.Now; state temp; devisA.Add(start, calcDist(start)); while (devisA.Count != 0 && cnt < 3000) { val = devisA.First().Key; devisA.Remove(val); Console.WriteLine("PAS:"******"OMG SUCCESS!!!"); trace = val.rettr(); //Console.WriteLine(trace); afisTrace(trace); // Thread.Sleep(5000); return(true); } vis.Add(val); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) { if (isVisited(temp) == false) { if (!devisA.ContainsKey(temp)) { devisA.Add(temp, calcA(temp)); } else if (calcA(temp) < devisA[temp]) { devisA.Remove(temp); devisA.Add(temp, calcA(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } } // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) { if (isVisited(temp) == false) { if (!devisA.ContainsKey(temp)) { devisA.Add(temp, calcA(temp)); } else if (calcA(temp) < devisA[temp]) { devisA.Remove(temp); devisA.Add(temp, calcA(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } } // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) { if (isVisited(temp) == false) { if (!devisA.ContainsKey(temp)) { devisA.Add(temp, calcA(temp)); } else if (calcA(temp) < devisA[temp]) { devisA.Remove(temp); devisA.Add(temp, calcA(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } } // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) { if (isVisited(temp) == false) { if (!devisA.ContainsKey(temp)) { devisA.Add(temp, calcA(temp)); } else if (calcA(temp) < devisA[temp]) { devisA.Remove(temp); devisA.Add(temp, calcA(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } } var v = devisA.OrderBy(k => k.Value); devisA = new Dictionary <state, int>(); foreach (var item in v) { devisA.Add(item.Key, item.Value); } } ts = DateTime.Now - dt; Console.WriteLine("NU S-A GASIT SOLUTIE!!!"); return(false); } //A*(dist)
} //bfs dist public bool executeBF4() { DateTime dt = DateTime.Now; state temp; devisC.Enqueue(start); var distCalc = new Dictionary <state, int>(); while (devisC.Count != 0 && cnt < 3000) { val = devisC.Dequeue(); distCalc = new Dictionary <state, int>(); Console.WriteLine("PAS:"******"OMG SUCCESS!!!"); trace = val.rettr(); Console.WriteLine(trace); // afisTrace(trace); // Thread.Sleep(5000); return(true); } vis.Add(val); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDiff(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDiff(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDiff(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) { if (isVisited(temp) == false) { distCalc.Add(temp, calcDiff(temp)); } else { Console.WriteLine("Stare deja vizitata!"); } } var q = distCalc.OrderBy(k => k.Value); foreach (var item in q) { devisC.Enqueue(item.Key); } } ts = DateTime.Now - dt; Console.WriteLine("NU S-A GASIT SOLUTIE!!!"); return(false); } //bfs diff
public bool executeBF2() { DateTime dt=DateTime.Now; state temp; while (true) { cnt++; Console.WriteLine("APELARI:" + cnt); if (val == fin) { ts=DateTime.Now-dt; Console.WriteLine("OMG SUCCESS!:"); // Thread.Sleep(2000); Console.Clear(); afisTrace(trace); // Thread.Sleep(20000); return true; } state min = new state(); // Thread.Sleep(500); temp = new state(val); if (temp.mutasus()) if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); min = new state(temp); } else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutajos()) if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); if (calcDiff(temp) < calcDiff(min)) min = new state(temp); } else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutast()) if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); if (calcDiff(temp) < calcDiff(min)) min = new state(temp); } else Console.WriteLine("Stare deja vizitata!"); // Thread.Sleep(500); temp = new state(val); if (temp.mutadr()) if (isVisited(temp) == false) { temp.afis(); vis.Add(temp); if (calcDiff(temp) < calcDiff(min)) min = new state(temp); } else Console.WriteLine("Stare deja vizitata!"); val = new state(min); setTrace(trace + val.rettr()); if (val == new state()) { ts = DateTime.Now - dt; Console.WriteLine("NU EXISTA SOLUTIE!"); // Thread.Sleep(20000); return false; } } }