private void PackingAssert(CorrectnessTestCase testCase)
        {
            var greatestCost =
                PackingAlgorithm.GetMaxPossibleCost(testCase.AllItems, testCase.Knapsack);

            Assert.AreEqual(testCase.ExpectedGreatestCost, greatestCost);
        }
        //Perform a packing iteration
        public bool Pack(PackingAlgorithm algorithm, double damping, double tolerance)
        {
            foreach (var c in m_circles)
            c.InMotion = false;

              if (algorithm == PackingAlgorithm.Random)
            Jiggle();
              else
            Sort(); //Simple, Fast, Double

              bool rc = false;

              for (int i = 0; i <= m_circles.Length - 2; i++)
              {
            for (int j = i + 1; j < m_circles.Length; j++)
            {
              if( algorithm == PackingAlgorithm.Double )
            rc = rc | m_circles[i].DoublePack(m_circles[j], tolerance);
              else // Fast, Random, Simple
            rc = rc | m_circles[i].FastPack(m_circles[j], tolerance);
            }
              }

              if( algorithm== PackingAlgorithm.Double || algorithm == PackingAlgorithm.Fast || algorithm == PackingAlgorithm.Random)
              Contract(damping);

              DestroyBoundingBoxCache();
              return rc;
        }
 /// <summary>
 /// Constructs a new instance of <see cref="RectanglePacker{T}"/>.
 /// </summary>
 /// <param name="width">The width of the container rectangle.</param>
 /// <param name="height">The height of the container rectangle.</param>
 /// <param name="quality">The packing algorithm to use.</param>
 public RectanglePacker(int width, int height, PackingAlgorithm quality = PackingAlgorithm.Maxrects)
 {
     _impl = quality switch
     {
         PackingAlgorithm.Maxrects => new SkylinePacker <T>(width, height),
         PackingAlgorithm.Skyline => new SkylinePacker <T>(width, height),
         PackingAlgorithm.Shelf => new ShelfPacker <T>(width, height),
         _ => throw new ArgumentException("Incorrect packing algorithm specified.", nameof(quality)),
     };
 }
Exemple #4
0
        public static List <Container> TestPackingAlgorithm(PackingAlgorithm algorithm, List <Item> items, uint V, out double Time)
        {
            List <Container> res;
            var stopwatch = new Stopwatch(); //секундомер

            GC.Collect();                    //принудительно запускаем сборщик мусора, чтоб он не выехал во время теста

            stopwatch.Start();
            res = algorithm(items, V);
            stopwatch.Stop();
            Time = stopwatch.Elapsed.TotalMilliseconds;
            return(res);
        }
Exemple #5
0
        //Perform a packing iteration
        public bool Pack(PackingAlgorithm algorithm, double damping, double tolerance)
        {
            foreach (var c in m_circles)
            {
                c.InMotion = false;
            }

            if (algorithm == PackingAlgorithm.Random)
            {
                Jiggle();
            }
            else
            {
                Sort(); //Simple, Fast, Double
            }
            bool rc = false;

            for (int i = 0; i <= m_circles.Length - 2; i++)
            {
                for (int j = i + 1; j < m_circles.Length; j++)
                {
                    if (algorithm == PackingAlgorithm.Double)
                    {
                        rc = rc | m_circles[i].DoublePack(m_circles[j], tolerance);
                    }
                    else // Fast, Random, Simple
                    {
                        rc = rc | m_circles[i].FastPack(m_circles[j], tolerance);
                    }
                }
            }

            if (algorithm == PackingAlgorithm.Double || algorithm == PackingAlgorithm.Fast || algorithm == PackingAlgorithm.Random)
            {
                Contract(damping);
            }

            DestroyBoundingBoxCache();
            return(rc);
        }
 private void RunTestCase(PerformanceTestCase testCase)
 {
     PackingAlgorithm.GetMaxPossibleCost(testCase.AllItems, testCase.Knapsack);
 }
 public void TranslateMethodToMachineCode()
 {
     PackingAlgorithm.GetMaxPossibleCost(new List <Item>(), new Knapsack(0));
 }
        /// <summary>
        /// Fails if any two different items in the specified solution overlap,
        /// or if any item in the specified solution exceeds the strip width,
        /// and writes the solution to the debug console.
        /// </summary>
        /// <param name="stripWidth">
        /// Strip width to check.
        /// </param>
        /// <param name="result">
        /// Packing algorithm solution to check.
        /// </param>
        private static void CheckSolution(float stripWidth, PackingAlgorithm result)
        {
            PrintSolution(result);

            CheckStripWidthExceeded(stripWidth, result);
            CheckItemsOverlap(result);
        }
 /// <summary>
 /// Fails if any two different items in the specified solution overlap.
 /// </summary>
 /// <param name="result">
 /// Packing algorithm solution to check.
 /// </param>
 private static void CheckItemsOverlap(PackingAlgorithm result)
 {
     foreach (var first in result)
     {
         foreach (var second in result)
         {
             if (first != second && first.Rectangle.Intersects(second.Rectangle))
             {
                 Assert.Fail("Items {0} and {1} overlap.", first, second);
             }
         }
     }
 }
 /// <summary>
 /// Constructs a new instance of <see cref="RectanglePacker{T}"/>.
 /// </summary>
 /// <param name="size">The size of the container rectangle.</param>
 /// <param name="quality">The packing algorithm to use.</param>
 public RectanglePacker(IntSize size, PackingAlgorithm quality = PackingAlgorithm.Maxrects)
     : this(size.Width, size.Height, quality)
 {
 }