Ejemplo n.º 1
0
 private static bool VectorBalance(float[] destinations, float[] destinationStar, float[] columnTotals, float epsilon)
 {
     VectorHelper.Divide(columnTotals, 0, destinations, 0, columnTotals, 0, columnTotals.Length);
     VectorHelper.Multiply(destinationStar, 0, destinationStar, 0, columnTotals, 0, destinationStar.Length);
     VectorHelper.ReplaceIfNotFinite(destinationStar, 0, 1.0f, destinationStar.Length);
     return(VectorHelper.AreBoundedBy(columnTotals, 0, 1.0f, epsilon, columnTotals.Length));
 }
Ejemplo n.º 2
0
        private static bool VectorBalance(float[] ret, float[] destinations, float[] destinationStar, float[] columnTotals, float epsilon, int categories)
        {
            bool balanced = true;

            VectorHelper.Divide(columnTotals, 0, destinations, 0, columnTotals, 0, columnTotals.Length);
            VectorHelper.Multiply(destinationStar, 0, destinationStar, 0, columnTotals, 0, destinationStar.Length);
            VectorHelper.ReplaceIfNotFinite(destinationStar, 0, 1.0f, destinationStar.Length);
            balanced = VectorHelper.AreBoundedBy(columnTotals, 0, 1.0f, epsilon, columnTotals.Length);
            return(balanced);
        }
Ejemplo n.º 3
0
        private bool Balance(float[] columnTotals)
        {
            var   flatAttractions    = Attractions.GetFlatData();
            var   flatAttractionStar = AttractionsStar.GetFlatData();
            float ep = Epsilon;

            VectorHelper.Divide(columnTotals, 0, flatAttractions, 0, columnTotals, 0, columnTotals.Length);
            VectorHelper.Multiply(flatAttractionStar, 0, flatAttractionStar, 0, columnTotals, 0, flatAttractionStar.Length);
            VectorHelper.ReplaceIfNotFinite(flatAttractionStar, 0, 1.0f, flatAttractionStar.Length);
            return(VectorHelper.AreBoundedBy(columnTotals, 0, 1.0f, ep, columnTotals.Length));
        }
Ejemplo n.º 4
0
        private bool Balance(float[] columnTotals, float[] oldTotal)
        {
            bool  balanced           = true;
            var   flatAttractions    = Attractions.GetFlatData();
            var   flatFlows          = FlowMatrix.GetFlatData();
            var   flatAttractionStar = AttractionsStar.GetFlatData();
            int   length             = flatAttractions.Length;
            float ep = (float)Epsilon;

            VectorHelper.Divide(columnTotals, 0, flatAttractions, 0, columnTotals, 0, columnTotals.Length);
            VectorHelper.Multiply(flatAttractionStar, 0, flatAttractionStar, 0, columnTotals, 0, flatAttractionStar.Length);
            VectorHelper.ReplaceIfNotFinite(flatAttractionStar, 0, 1.0f, flatAttractionStar.Length);
            return(balanced = VectorHelper.AreBoundedBy(columnTotals, 0, 1.0f, ep, columnTotals.Length));
        }
Ejemplo n.º 5
0
        private bool Balance(float[] columnTotals, float[] oldTotal)
        {
            bool  balanced           = true;
            var   flatAttractions    = Attractions.GetFlatData();
            var   flatFlows          = FlowMatrix.GetFlatData();
            var   flatAttractionStar = AttractionsStar.GetFlatData();
            int   length             = flatAttractions.Length;
            float ep = (float)Epsilon;

            if (VectorHelper.IsHardwareAccelerated)
            {
                VectorHelper.Divide(columnTotals, 0, flatAttractions, 0, columnTotals, 0, columnTotals.Length);
                VectorHelper.Multiply(flatAttractionStar, 0, flatAttractionStar, 0, columnTotals, 0, flatAttractionStar.Length);
                VectorHelper.ReplaceIfNotFinite(flatAttractionStar, 0, 1.0f, flatAttractionStar.Length);
                balanced = VectorHelper.AreBoundedBy(columnTotals, 0, 1.0f, ep, columnTotals.Length);
            }
            else
            {
                // profiling showed that this is actually faster without running in parallel
                for (int i = 0; i < flatAttractions.Length; i++)
                {
                    if (flatAttractions[i] > 0)
                    {
                        var total = 1.0f / columnTotals[i];
                        if (!float.IsInfinity(total) & !float.IsNaN(total))
                        {
                            var residual = (float)(flatAttractions[i] * total);
                            if (Math.Abs(1 - residual) > ep)
                            {
                                balanced = false;
                            }
                            flatAttractionStar[i] *= residual;
                        }
                        else
                        {
                            flatAttractionStar[i] = 1.0f;
                        }
                    }
                }
            }
            return(balanced);
        }