Exemplo n.º 1
0
        /// <summary>
        /// Runs the process
        /// </summary>
        /// <param name="context">Dummy / not in use</param>
        public void Run(object context)
        {
            // Prepare statistics file
            using (StreamWriter statisticsWriter = new StreamWriter(File.Open(Path.Combine(_exportDir, _statisticsFile), FileMode.Create)))
            {
                // Start statistics file
                statisticsWriter.WriteLine(
                    "Instance" + ExportationConstants.CSV_DELIMITER +
                    "Runtime" + ExportationConstants.CSV_DELIMITER +
                    "Solution" + ExportationConstants.CSV_DELIMITER +
                    "BestBound" + ExportationConstants.CSV_DELIMITER +
                    "Gap");
            }

            // Init default config
            switch (_methodToUse)
            {
            case MethodType.ExtremePointInsertion:
            case MethodType.SpaceDefragmentation:
            case MethodType.PushInsertion:
            {
                if (Config == null)
                {
                    Config = new Configuration(_methodToUse, true)
                    {
                        Log = _logAction
                    };
                }
            }
            break;

            case MethodType.FrontLeftBottomStyle:
            case MethodType.TetrisStyle:
            {
                if (Config == null)
                {
                    Config = new Configuration(_methodToUse, true)
                    {
                        Log = _logAction
                    };
                }
            }
            break;

            case MethodType.SpaceIndexed:
                throw new NotImplementedException("Space indexed model not working for now.");

            default:
                throw new ArgumentException("Unknown method: " + _methodToUse.ToString());
            }


            _timeConsumed     = _timeConsumed ?? new List <TimeSpan>();
            _evaluationValues = _evaluationValues ?? new List <double>();
            _bestBounds       = _bestBounds ?? new List <double>();
            _gaps             = _gaps ?? new List <double>();

            // Solve incrementally for each seed
            for (int k = 0; k < SeedPasses; k++)
            {
                // Solve incrementally for given container count
                for (int j = GeneratorConfig.ContainerMin; j <= GeneratorConfig.ContainerMax; j++)
                {
                    // Solve incrementally for given piece count
                    for (int i = 1; i <= GeneratorConfig.MaxBoxCount && !_cancel; i++)
                    {
                        // Prepare
                        switch (_methodToUse)
                        {
                        case MethodType.ExtremePointInsertion:
                        case MethodType.TetrisStyle:
                        {
                            _instance            = new Instance();
                            _instance.Containers = InstanceGenerator.GenerateContainer(
                                j,
                                GeneratorConfig.ContainerSideLengthMin,
                                GeneratorConfig.ContainerSideLengthMax,
                                GeneratorConfig.Rounding,
                                k);
                            _instance.Pieces = InstanceGenerator.GeneratePerformanceTestTetrisPieces(
                                i,
                                GeneratorConfig.PieceMaxSize,
                                GeneratorConfig.PieceMinSize,
                                GeneratorConfig.PieceMinEquals,
                                GeneratorConfig.PieceMaxEquals,
                                roundedDecimals: GeneratorConfig.Rounding,
                                seed: k);
                        }
                        break;

                        case MethodType.FrontLeftBottomStyle:
                        case MethodType.SpaceDefragmentation:
                        case MethodType.PushInsertion:
                        {
                            _instance            = new Instance();
                            _instance.Containers = InstanceGenerator.GenerateContainer(
                                j,
                                GeneratorConfig.ContainerSideLengthMin,
                                GeneratorConfig.ContainerSideLengthMax,
                                GeneratorConfig.Rounding,
                                k);
                            _instance.Pieces = InstanceGenerator.GeneratePieces(
                                i,
                                GeneratorConfig.PieceMaxSize,
                                GeneratorConfig.PieceMinSize,
                                GeneratorConfig.PieceMinEquals,
                                GeneratorConfig.PieceMaxEquals,
                                roundedDecimals: GeneratorConfig.Rounding,
                                seed: k);
                        }
                        break;

                        case MethodType.SpaceIndexed:
                            throw new NotImplementedException("Space indexed model not working for now.");

                        default:
                            throw new ArgumentException("Unknown method: " + _methodToUse.ToString());
                        }

                        // Execute
                        Execute(ExportationConstants.ExportDir, _instance.GetIdent(), int.MaxValue);
                    }
                }
            }
            _finishAction();
        }