/// <summary> /// Constructor for the Problem class, initializes all data regarding one Particular problem /// </summary> /// <param name="problemID">ID of the Problem</param> protected Problem(Global.Problems problemID) { ProblemID = problemID; metaData = new ProblemMetaData(problemID); Name = metaData.GetName(); Description = metaData.GetDescription(); Implementations = metaData.GetImplementations(); Instruction = metaData.GetInstruction(); DefaultSubMethod = metaData.GetDefaultSubMethod(); }
/// <summary> /// Get the particular Problem object based on the option chosen by user /// </summary> /// <param name="problem">Problem ID</param> /// <returns>Respective problem object</returns> static Problem ProblemFactory(Global.Problems problem) { switch (problem) { case Global.Problems.RodCutting: return(new RodCutting()); case Global.Problems.LongestCommonSubSequence: return(new LongestCommonSubsequence()); default: return(null); } }
/// <summary> /// Constructor to initialize properties /// </summary> /// <param name="problemID">ID of the particular problem, must be of type Problems enum</param> public ProblemMetaData(Global.Problems problemID) { doc = XDocument.Load(xmlFilePath); ProblemID = problemID; /*It is proved that .Where(predicate).First() is faster than .First(predicate), though it may sound very much counter-intuitive but it is true, * If any one can prove me otherwise or explain this weird behaviour, I am all ears * My guess is .First uses simple foreach loop whereas .Where uses many different iterators for different purposes, it may give some edge (by optimizing) to .Where * - Diptarag */ try { problemElement = doc.Descendants("Problem").Where(node => Convert.ToInt32(node.Attribute("Id").Value) == (int)ProblemID).First(); } catch { throw new DynamicProgrammingException("It seems Id attribute of Problem element has been changed in ProblemDescription.xml or some element is deleted. Please do not change the content of the xml"); } }