/// <summary> /// Read and Parse Input File /// </summary> public override void ReadInputFile() { using (FileHandler inputFile = new FileHandler(Global.IOMode.Input, true)) { try { lengthOfCut = int.Parse(inputFile.FetchLine(1)); } catch { throw new DynamicProgrammingException("In Rod-Cutting problem first line of the input text should always be a valid number which represent number of cuts to make."); } try { costs = inputFile.FetchLine(2).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray(); } catch { throw new DynamicProgrammingException("In Rod-Cutting problem second line of the input text should always be the array of cost (number) seperated by blankspace"); } } }
public override void ReadInputFile() { using (FileHandler inputFile = new FileHandler(Global.IOMode.Input, true)) { try { firstSequence = inputFile.FetchLine(1).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray(); } catch { throw new DynamicProgrammingException("In Longest Common Subsequence problem first line of the input text should always be a valid sequence seperated by blank space."); } try { secondSequence = inputFile.FetchLine(2).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray(); } catch { throw new DynamicProgrammingException("In Longest Common Subsequence problem second line of the input text should always be a valid sequence seperated by blank space."); } } }
public override void StoreResult(params object[] obj) { Tuple<double[], int[]> solutions; try { solutions = (Tuple<double[], int[]>)obj[0]; } catch { throw new DynamicProgrammingException("\n\nLogical Error at Rod Cutting Default Problem. The Optimal Solution Table is not in a correct format."); } using (FileHandler outputFile = new FileHandler(Global.IOMode.Output)) { outputFile.WriteContent("If you cut a " + lengthOfCut + " length rod you can generate a maximum revenue : " + solutions.Item1[lengthOfCut - 1] + ". And you will get this result if you cut the rod at these pieces -"); while (lengthOfCut > 0) { outputFile.WriteContent(solutions.Item2[lengthOfCut - 1]); lengthOfCut -= solutions.Item2[lengthOfCut - 1]; } } }
/// <summary> /// Store the result of the execution /// </summary> /// <param name="output">Result to be stored</param> public virtual void StoreResult(params object[] 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."); }