Ejemplo n.º 1
0
 public AggregatedFittingResult(FitStrategy FitStrategy, double NumberOfBinsUsed, double NumberOfItemsNotFitted, double TotalWastedLength, double TotalRemainingLength, double TimeElapsedInTicks)
 {
     this.FitStrategy            = FitStrategy;
     this.NumberOfBinsUsed       = NumberOfBinsUsed;
     this.NumberOfItemsNotFitted = NumberOfItemsNotFitted;
     this.TotalWastedLength      = TotalWastedLength;
     this.TotalRemainingLength   = TotalRemainingLength;
     this.TimeElapsedInTicks     = TimeElapsedInTicks;
 }
Ejemplo n.º 2
0
 public FittingResult(List <Bin> Bins, List <Item> Items, FitStrategy FitStrategy, TimeSpan TimeElapsed)
 {
     this.FitStrategy        = FitStrategy;
     this.Bins               = Bins;
     this.Items              = Items;
     this.TimeElapsedInTicks = TimeElapsed.Ticks;
     NumberOfBinsUsed        = FittingResultComputer.ComputeNumberOfBinsUsed(Bins);
     NumberOfItemsNotFitted  = FittingResultComputer.ComputeNumberOfItemsNotFitted(Items);
     TotalWastedLength       = FittingResultComputer.ComputeTotalWastedLength(Bins);
     TotalRemainingLength    = FittingResultComputer.ComputeTotalRemainingLength(Bins);
 }
Ejemplo n.º 3
0
        public static void ComputeBestFitOBB(Vector3[] points, out float[] sides, out Matrix4 matrix, FitStrategy strategy)
        {
            matrix = Matrix4.Identity;
            AABBf aabb = new AABBf();

            for (int i = 0; i < points.Length; i++)
            {
                aabb.Add(points[i]);
            }

            float avolume = (aabb.MaxX - aabb.MinX) * (aabb.MaxY - aabb.MinY) * (aabb.MaxZ - aabb.MinZ);

            Plane plane;

            ComputeBestFitPlane(points, out plane);

            plane.ToMatrix(ref matrix);
            ComputeOBB(points, ref matrix, out sides);

            Matrix4 refmatrix = new Matrix4();

            refmatrix = matrix;

            float volume = sides[0] * sides[1] * sides[2];

            float stepSize = 5;

            switch (strategy)
            {
            case BestFit.FitStrategy.FS_FAST_FIT:
                stepSize = 13;     // 15 degree increments
                break;

            case BestFit.FitStrategy.FS_MEDIUM_FIT:
                stepSize = 7;     // 10 degree increments
                break;

            case BestFit.FitStrategy.FS_SLOW_FIT:
                stepSize = 3;     // 5 degree increments
                break;

            case BestFit.FitStrategy.FS_SLOWEST_FIT:
                stepSize = 1;     // 1 degree increments
                break;
            }

            Quaternion quat = new Quaternion();

            for (float a = 0; a < 180; a += stepSize)
            {
                Matrix4 temp;
                Matrix4.CreateRotationY(MathHelper.DegreesToRadians(a), out temp);
                QuaternionEx.CreateFromMatrix(ref temp, ref quat);

                Matrix4 pmatrix;
                Matrix4.Mult(ref temp, ref refmatrix, out pmatrix);

                float[] psides;
                ComputeOBB(points, ref pmatrix, out psides);
                float v = psides[0] * psides[1] * psides[2];
                if (v < volume)
                {
                    volume   = v;
                    matrix   = pmatrix;
                    sides[0] = psides[0];
                    sides[1] = psides[1];
                    sides[2] = psides[2];
                }
            }

            if (avolume < volume)
            {
                matrix = Matrix4.CreateTranslation(
                    (aabb.MinX + aabb.MaxX) * 0.5f,
                    (aabb.MinY + aabb.MaxY) * 0.5f,
                    (aabb.MinZ + aabb.MaxZ) * 0.5f);
                sides[0] = aabb.MaxX - aabb.MinX;
                sides[1] = aabb.MaxY - aabb.MinY;
                sides[2] = aabb.MaxZ - aabb.MinZ;
            }
        }
Ejemplo n.º 4
0
        static FittingResult FitSingleStrategy(ref List <Bin> Bins, ref List <Item> Items, FitStrategy FitStrategy)
        {
            Stopwatch StopWatch = new Stopwatch();

            StopWatch.Start();
            switch (FitStrategy)
            {
            case FitStrategy.FirstFit:
                FirstFit(ref Bins, ref Items);
                break;

            case FitStrategy.FirstFitSortItemsDecreasingLength:
                FirstFitDecreasingLength(ref Bins, ref Items);
                break;

            case FitStrategy.FirstFitSortItemsDecreasingEffect:
                FirstFitDecreasingEffect(ref Bins, ref Items);
                break;

            case FitStrategy.FirstFitSortItemsDecreasingLengthSortBinsIncreasingLength:
                FirstFitDecreasingLengthSortBinsIncreasingLength(ref Bins, ref Items);
                break;

            case FitStrategy.FirstFitSortItemsDecreasingLengthSortBinsIncreasingResistance:
                FirstFitDecreasingLengthSortBinsIncreasingResistance(ref Bins, ref Items);
                break;

            case FitStrategy.FirstFitSortItemsDecreasingEffectSortBinsIncreasingLength:
                FirstFitDecreasingEffectSortBinsIncreasingLength(ref Bins, ref Items);
                break;

            case FitStrategy.FirstFitSortItemsDecreasingEffectSortBinsIncreasingResistance:
                FirstFitDecreasingEffectSortBinsIncreasingResistance(ref Bins, ref Items);
                break;


            case FitStrategy.BestFitNoSortMinRemainingLength:
                BestFitMinRemainingLength(ref Bins, ref Items);
                break;

            case FitStrategy.BestFitNoSortMaxEffectOverResistance:
                BestFitMaxEffectOverResistance(ref Bins, ref Items);
                break;

            case FitStrategy.BestFitSortItemsDecreasingLengthMinRemainingLength:
                BestFitDecreasingLengthMinRemainingLength(ref Bins, ref Items);
                break;

            case FitStrategy.BestFitSortItemsDecreasingLengthMaxEffectOverResistance:
                BestFitDecreasingLengthMaxEffectOverResistance(ref Bins, ref Items);
                break;

            case FitStrategy.BestFitSortItemsDecreasingEffectMinRemainingLength:
                BestFitDecreasingEffectMinRemainingLength(ref Bins, ref Items);
                break;

            case FitStrategy.BestFitSortItemsDecreasingEffectMaxEffectOverResistance:
                BestFitDecreasingEffectMaxEffectOverResistance(ref Bins, ref Items);
                break;
            }
            StopWatch.Stop();
            return(new FittingResult(Bins, Items, FitStrategy, StopWatch.Elapsed)); //figureo out how to pass the timeelapsed thingy...
        }
Ejemplo n.º 5
0
        public static void ComputeBestFitOBB(Vector3[] points, out float[] sides, out Matrix4 matrix, FitStrategy strategy)
        {
            matrix = Matrix4.Identity;
            AABBf aabb = new AABBf();
            for (int i = 0; i < points.Length; i++)
                aabb.Add(points[i]);

            float avolume = (aabb.MaxX - aabb.MinX) * (aabb.MaxY - aabb.MinY) * (aabb.MaxZ - aabb.MinZ);

            Plane plane;
            ComputeBestFitPlane(points, out plane);

            plane.ToMatrix(ref matrix);
            ComputeOBB(points, ref matrix, out sides);

            Matrix4 refmatrix = new Matrix4();
            refmatrix = matrix;

            float volume = sides[0] * sides[1] * sides[2];

            float stepSize = 5;
            switch (strategy)
            {
                case BestFit.FitStrategy.FS_FAST_FIT:
                    stepSize = 13; // 15 degree increments
                    break;
                case BestFit.FitStrategy.FS_MEDIUM_FIT:
                    stepSize = 7; // 10 degree increments
                    break;
                case BestFit.FitStrategy.FS_SLOW_FIT:
                    stepSize = 3; // 5 degree increments
                    break;
                case BestFit.FitStrategy.FS_SLOWEST_FIT:
                    stepSize = 1; // 1 degree increments
                    break;
            }

            Quaternion quat = new Quaternion();
            for (float a = 0; a < 180; a += stepSize)
            {
                Matrix4 temp;
                Matrix4.CreateRotationY(MathHelper.DegreesToRadians(a), out temp);
                QuaternionEx.CreateFromMatrix(ref temp, ref quat);

                Matrix4 pmatrix;
                Matrix4.Mult(ref temp, ref refmatrix, out pmatrix);

                float[] psides;
                ComputeOBB(points, ref pmatrix, out psides);
                float v = psides[0] * psides[1] * psides[2];
                if (v < volume)
                {
                    volume = v;
                    matrix = pmatrix;
                    sides[0] = psides[0];
                    sides[1] = psides[1];
                    sides[2] = psides[2];
                }
            }

            if (avolume < volume)
            {
                matrix = Matrix4.CreateTranslation(
                    (aabb.MinX + aabb.MaxX) * 0.5f,
                    (aabb.MinY + aabb.MaxY) * 0.5f,
                    (aabb.MinZ + aabb.MaxZ) * 0.5f);
                sides[0] = aabb.MaxX - aabb.MinX;
                sides[1] = aabb.MaxY - aabb.MinY;
                sides[2] = aabb.MaxZ - aabb.MinZ;
            }
        }