/// <summary> /// Get The Implementation ID of the available implementations from user /// </summary> /// <returns>Index of the Implementations chosen by user</returns> public virtual int GetImplementationID() { string returnVal; int retVal; while (true) { returnVal = CUI.ShowImplementations(Name, Implementations); if (string.IsNullOrEmpty(returnVal)) { return(DefaultSubMethod); } else { if (int.TryParse(returnVal, out retVal)) { if (retVal <= Implementations.Count) { return(retVal); } } else { CUI.ErrorMessage(); } } } }
public override void Compute() { switch (base.GetImplementationID()) { case 1: base.StoreResult(LCSGeneral()); break; } CUI.ShowTimeElapsed(stopWatch.Elapsed); }
public virtual void StoreResult <T>(List <T> output) { using (FileHandler outputFile = new FileHandler(Global.IOMode.Output)) { foreach (object obj in output) { outputFile.WriteContent(obj); } } CUI.ShowGeneralInformation("\n\nPlease open output.txt to view the result."); }
/// <summary> /// Check the error type, handles the error if error type is fatal /// </summary> /// <param name="exception">Exception that needs to be determined for fatality</param> /// <returns>true if the exception is fatal, false otherwise</returns> public static bool HandleFatalError(this Exception exception) { if (exception.IsFatal()) { CUI.ShowGeneralInformation("\n\nA fata error occurred. Please find below the error : \n" + exception.ToString() + "\n\nPlease notify Diptarag regarding this error. \n\nSystem will exit now. Press any key to exit."); Console.ReadKey(); return(true); } else { return(false); } }
/// <summary> /// Solve the problem and store the result using the implementations chosen by user /// </summary> public override void Compute() { if (lengthOfCut > costs.Length) { throw new DynamicProgrammingException("\nLength of Cut can not be more than the cost array provided, if you want to cut the rod into a length x then u must provide separate cost of each length cut i.e. cost array must be greater than x."); } switch (methodNumber) { case 1: base.StoreResult(SimpleRecursive()); break; case 2: base.StoreResult(TopDownMemoization()); break; case 3: base.StoreResult(BottomUpMemoization()); break; case 4: StoreResult(BottomUpSolution()); break; } CUI.ShowTimeElapsed(stopWatch.Elapsed); }
static void Main(string[] args) { int choice; Dictionary <Global.Problems, string> problems = new Dictionary <Global.Problems, string>(); try { problems = ProblemMetaData.GetProblems(); } catch (DynamicProgrammingException ex) { CUI.ShowGeneralInformation(ex.Message + "\nPlease revert any changes you have made to the xml file and try again.\n\nSystem will now exit. Press any key to exit..."); Console.ReadKey(); System.Environment.Exit(0); } while (true) { try { switch (CUI.StartScreen()) { case "1": while (true) { if (problems.Count >= 0 && int.TryParse(CUI.ShowProblemListings(problems), out choice) && problems.Keys.Any(e => (int)e == choice)) { Problem problem = ProblemFactory((Global.Problems)choice); if (problem != null) { problem.Compute(); //problem.StoreResult(); break; } throw new DynamicProgrammingException("A logical exception occurred."); } CUI.ErrorMessage(); } break; case "2": CUI.About(); break; case "3": System.Environment.Exit(0); break; default: CUI.ErrorMessage(); break; } } catch (Exception ex) { if (ex.HandleFatalError()) { System.Environment.Exit(1); } else { ex.Handle(); } } } }