private void Init() { generator = new ObjectGenerator(); containerFactory = new ContainerFactory(); factory = new AlgorithmFactory(); algorithmProperties = new AlgorithmProperties(); results = new AlgorithmExecutionResults(); stopwatch = new Stopwatch(); HandleDimensionalityChange(); }
public AlgorithmExecutionResults CreateResults() { double averageFulfilment = 0.0; double standardDeviation = 0.0; var containerVolume = containers.Sum(x => x.Height * x.Width * x.Depth); var objectsTotalVolume = containers.Sum(container => container.PlacedObjects.Sum(o => (o as Object3D).Width * (o as Object3D).Height * (o as Object3D).Depth)); double worstFulfillment; PlacedObjects placedObjectsTotal = new PlacedObjects(); foreach (var container in containers) { placedObjectsTotal.AddRange(container.PlacedObjects); averageFulfilment += container.GetFulfilment(); } averageFulfilment /= containers.Count(); foreach (var container in containers) { standardDeviation += Math.Pow((double)(averageFulfilment - container.GetFulfilment()), 2.0); } standardDeviation = Math.Sqrt(standardDeviation / containers.Count); // If more than 1 container was used, do not take last created into account if (containers.Count > 1) { worstFulfillment = containers.OrderBy(x => x.GetFulfilment()).Skip(1).FirstOrDefault().GetFulfilment(); } else { worstFulfillment = containers.OrderBy(x => x.GetFulfilment()).FirstOrDefault().GetFulfilment(); } var results = new AlgorithmExecutionResults { PlacedObjects = placedObjectsTotal, ContainerSize = containers.First(), ContainerFulfillment = containerVolume, ObjectsTotalFulfillment = objectsTotalVolume, AverageFulfillmentRatio = averageFulfilment, FulfillmentRatioStandardDeviation = standardDeviation, Quality = (double)containerVolume / objectsTotalVolume, ContainersUsed = containers.Count, ObjectCount = placedObjectsTotal.Count, WorstFulfillment = worstFulfillment }; return(results); }
public static void Write(AlgorithmExecutionResults endResults, AlgorithmProperties properties, ObjectOrdering ordering, IFigure initialContainer, string filePath, string inputSetName) { if (!CheckDestinationCSV(filePath)) { FileHelper.CreateNewFile(filePath); } //throw new InvalidArgumentException($"Cannot access target file at given path {filePath}"); WriteHeaders(filePath); string containerSize = properties.Dimensionality.Equals(AlgorithmDimensionality.TwoDimensional) ? $"{(initialContainer as Container2D).Width}x{(initialContainer as Container2D).Height}" : $"{(initialContainer as Container3D).Width}x{(initialContainer as Container3D).Height}x{(initialContainer as Container3D).Depth}"; File.AppendAllText(filePath, $"{inputSetName};{properties.Dimensionality};{properties.Family};{properties.AlgorithmType};{properties.SplittingStrategy};{ordering};{containerSize};{endResults.AverageFulfillmentRatio};{endResults.Quality};{endResults.ExecutionTime};{endResults.ContainersUsed};{endResults.ObjectCount}" + Environment.NewLine); }
private static void WriteResiltsToCsv(AlgorithmExecutionResults endResults, IFigure initialContainer) { CSVWriter.Write(endResults, Properties, Ordering, initialContainer, OutputFilePath, Path.GetFileName(InputFilePath)); }