Exemplo n.º 1
0
        double DeltaWithChangedAngles(int rotationOfSourceRigthPoint, int rotationOfSourceLeftPoint, int rotationOfTargetRigthPoint, int rotationOfTargetLeftPoint,
                                      BundleInfo bundleInfo, double bundleCost, double parameterChange)
        {
            if (!bundleInfo.RotationIsLegal(rotationOfSourceRigthPoint, rotationOfSourceLeftPoint, rotationOfTargetRigthPoint, rotationOfTargetLeftPoint, parameterChange))
            {
                return(0);
            }

            bundleInfo.RotateBy(rotationOfSourceRigthPoint, rotationOfSourceLeftPoint, rotationOfTargetRigthPoint, rotationOfTargetLeftPoint, parameterChange);
            var newCost = Cost(bundleInfo, bundleCost);

            //restoring
            bundleInfo.RotateBy(-rotationOfSourceRigthPoint, -rotationOfSourceLeftPoint, -rotationOfTargetRigthPoint, -rotationOfTargetLeftPoint, parameterChange);

            return(bundleCost - newCost);
        }
Exemplo n.º 2
0
        bool OptimizeBundle(BundleInfo bundleInfo, double parameterChange, ref double cost)
        {
            double bundleCost = Cost(bundleInfo);

            if (bundleCost < CostThreshold)
            {
                return(false);
            }

            //choose the best step
            double bestDelta = 0;
            int    bestI = -1, bestJ = -1;

            for (int i = 0; i < Deltas.Length - 1; i++)
            {
                double delta = DeltaWithChangedAngles(Deltas[i][0], Deltas[i][1], 0, 0, bundleInfo, bundleCost, parameterChange);
                if (delta > CostDeltaThreshold && delta > bestDelta)
                {
                    bestI     = i;
                    bestJ     = Deltas.Length - 1;
                    bestDelta = delta;
                }

                delta = DeltaWithChangedAngles(0, 0, Deltas[i][0], Deltas[i][1], bundleInfo, bundleCost, parameterChange);
                if (delta > CostDeltaThreshold && delta > bestDelta)
                {
                    bestI     = Deltas.Length - 1;
                    bestJ     = i;
                    bestDelta = delta;
                }
            }

            if (bestDelta < CostDeltaThreshold)
            {
                return(false);
            }
            //do the change
            cost -= bestDelta;

            bundleInfo.RotateBy(Deltas[bestI][0], Deltas[bestI][1], Deltas[bestJ][0], Deltas[bestJ][1], parameterChange);

            return(true);
        }
        double DeltaWithChangedAngles(int rotationOfSourceRigthPoint, int rotationOfSourceLeftPoint, int rotationOfTargetRigthPoint, int rotationOfTargetLeftPoint,
            BundleInfo bundleInfo, double bundleCost, double parameterChange) {
            if (!bundleInfo.RotationIsLegal(rotationOfSourceRigthPoint, rotationOfSourceLeftPoint, rotationOfTargetRigthPoint, rotationOfTargetLeftPoint, parameterChange))
                return 0;

            bundleInfo.RotateBy(rotationOfSourceRigthPoint, rotationOfSourceLeftPoint, rotationOfTargetRigthPoint, rotationOfTargetLeftPoint, parameterChange);
            var newCost = Cost(bundleInfo, bundleCost);

            //restoring
            bundleInfo.RotateBy(-rotationOfSourceRigthPoint, -rotationOfSourceLeftPoint, -rotationOfTargetRigthPoint, -rotationOfTargetLeftPoint, parameterChange);

            return bundleCost - newCost;
        }
        bool OptimizeBundle(BundleInfo bundleInfo, double parameterChange, ref double cost) {
            double bundleCost = Cost(bundleInfo);
            if (bundleCost < CostThreshold)
                return false;

            //choose the best step
            double bestDelta = 0;
            int bestI = -1, bestJ = -1;

            for (int i = 0; i < Deltas.Length - 1; i++) {
                double delta = DeltaWithChangedAngles(Deltas[i][0], Deltas[i][1], 0, 0, bundleInfo, bundleCost, parameterChange);
                if (delta > CostDeltaThreshold && delta > bestDelta) {
                    bestI = i;
                    bestJ = Deltas.Length - 1;
                    bestDelta = delta;
                }

                delta = DeltaWithChangedAngles(0, 0, Deltas[i][0], Deltas[i][1], bundleInfo, bundleCost, parameterChange);
                if (delta > CostDeltaThreshold && delta > bestDelta) {
                    bestI = Deltas.Length - 1;
                    bestJ = i;
                    bestDelta = delta;
                }
            }

            if (bestDelta < CostDeltaThreshold)
                return false;
            //do the change
            cost -= bestDelta;

            bundleInfo.RotateBy(Deltas[bestI][0], Deltas[bestI][1], Deltas[bestJ][0], Deltas[bestJ][1], parameterChange);

            return true;
        }