internal void ApplyVariableHeuristic(VariableHeuristicType variableHeuristicType) { switch (variableHeuristicType) { case VariableHeuristicType.Random: { var r = new Random(); variables = variables.OrderBy(x => r.Next()).ToList(); break; } case VariableHeuristicType.SmallestDomain: { variables = variables.OrderBy(v => v.domain.values.Count).ToList(); break; } case VariableHeuristicType.ShortestWord: { if (typeof(T) == typeof(String)) { variables = variables.OrderBy(v => - ((string)(object)v.domain.values[0]).Length).ToList(); } else { Console.WriteLine("Variable type is not a string, cannot perform ShortestWord variable heuristic"); } break; } case VariableHeuristicType.SpecificOrder: { if (specificOrder != null) { variables = variables.OrderBy(v => specificOrder.IndexOf(v.id)).ToList(); } else { Console.WriteLine("Specific order not provided"); } break; } } }
public List <Solution <T> > Solve(VariableHeuristicType variableHeuristicType, ValueHeuristicType valueHeuristicType) { ResetValues(); stopwatch.Start(); Stopwatch stopwatchAll = new Stopwatch(); stopwatchAll.Start(); ApplyValueHeuristic(valueHeuristicType); ApplyVariableHeuristic(variableHeuristicType); switch (searchType) { case SearchType.ForwardChecking: { CloneDomains(); Solution <T> solution = new Solution <T>(invariables, variables); //Wykorzystując ograniczenia odfiltruj dziedziny zmiennych bez wartości solution.FilterOutDomains(); ForwardChecking(solution, 0); break; } case SearchType.Backtracking: { Solution <T> solution = new Solution <T>(invariables, variables); Backtracking(solution, 0); break; } } stopwatchAll.Stop(); Console.WriteLine("Total time: " + stopwatchAll.ElapsedMilliseconds); Console.WriteLine("Nodes visited till first solution: " + nodesFirst); Console.WriteLine("Nodes visited total: " + nodes); Console.WriteLine("Turn backs count till first solution: " + turnBacksFirst); Console.WriteLine("Turn backs count total: " + turnBacks); Console.WriteLine("Number of solutions: " + solutions.Count); return(solutions); }
public List <Solution <string> > Solve(VariableHeuristicType variableHeuristicType, ValueHeuristicType valueHeuristicType) { return(problem.Solve(variableHeuristicType, valueHeuristicType)); }