Beispiel #1
0
        public void Test1()
        {
            var cityRegion = new CityRegion(0, 2.0, 0, 1.0);

            Assert.AreEqual(0, cityRegion.Get(3, 0, 0.2));
            Assert.AreEqual(1, cityRegion.Get(3, 1.0, 0.3));
            Assert.AreEqual(2, cityRegion.Get(3, 1.5, 0.1));
            Assert.AreEqual(4, cityRegion.Get(3, 1.0, 0.5));
            Assert.AreEqual(7, cityRegion.Get(3, 1.22, 0.8673));
        }
Beispiel #2
0
        private static void RunTaxiTripsInnerProduct(Random random)
        {
            // NYC Coords
            // Big Square
            const double minLat  = 40.49;
            const double maxLat  = 40.91;
            const double minLong = -74.26;
            const double maxLong = -73.66;
            // Small Square

            /*const double minLat = 40.623;
             * const double maxLat = 40.846;
             * const double minLong = -74.04;
             * const double maxLong = -73.74;*/

            var nycCityRegion = new CityRegion(minLat, maxLat, minLong, maxLong);
            //var          sqrtNumOfNodes   = 5;
            //var          sqrtVectorLength = 10;
            var hoursInWindow      = 24;
            var iterations         = 750;
            var tipSplitter        = new DataSplitter <TaxiTripEntry>(entry => entry.Tip > 0, "Tip");
            var vendorSplitter     = new DataSplitter <TaxiTripEntry>(entry => entry.TaxiVendor == TaxiVendor.CMT, "Vendor");
            var paymentSplitter    = new DataSplitter <TaxiTripEntry>(entry => entry.PaymentType == PaymentType.Cash, "PaymentType");
            var passengersSplitter = new DataSplitter <TaxiTripEntry>(entry => entry.NumOfPassangers > 1, "Passengers");
            var splitters          = ArrayUtils.Init(tipSplitter, vendorSplitter, paymentSplitter, passengersSplitter);
            var approximation      = new MultiplicativeUpperLowerApproximation(0.7, 1.3);
            var chosenSplitter     = vendorSplitter;


            foreach (var sqrtVectorLength in ArrayUtils.Init(101))
            {
                // foreach (var sqrtVectorLength in ArrayUtils.Init(35, 61, 86, 100, 111, 122, 132, 141, 158, 173, 187, 200, 212, 223))
                //foreach (var sqrtNumOfNodes in ArrayUtils.Init(6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))
                foreach (var sqrtNumOfNodes in ArrayUtils.Init(8))
                {
                    InnerProductRunner.RunTaxiTrips(random, iterations, sqrtNumOfNodes, hoursInWindow, approximation,
                                                    sqrtVectorLength, chosenSplitter, nycCityRegion, taxiBinDataPath, resultDir);
                }
            }
        }
Beispiel #3
0
    public bool TryGenerateRecursive(int pass)
    {
        if (pass >= GetGenerationPass())
        {
            //subdivide protects against multiple subdivisions
            if (!meshGenerated)
            {
                GenerateMeshes();
            }
            if (IsSubdividable())
            {
                if (!IsSubdivided())
                {
                    Subdivide();
                }

                //SubdividableEdgeLoop<CityEdge>[] children = GetChildren();
                bool allChildrenGenerated = true;
                //if there are no children, this returns true
                foreach (SubdividableEdgeLoop <CityEdge> child in children)
                {
                    if (child is CityRegion)
                    {
                        CityRegion cityChild      = (CityRegion)child;
                        bool       childGenerated = cityChild.TryGenerateRecursive(pass);
                        allChildrenGenerated = allChildrenGenerated & childGenerated;
                    }
                }

                return(allChildrenGenerated);
            }
            else
            {
                return(true);
            }
        }
        return(false);
    }
Beispiel #4
0
 public CityRegionDataWithInstanceValues(CityRegionData cityRegionData, CityRegion cityRegionInstance)
 {
     this.cityRegionData     = cityRegionData;
     this.cityRegionInstance = cityRegionInstance;
 }
        public static void RunTaxiTrips(Random random, int iterations, int sqrtNumOfNodes, int hoursInWindow, ApproximationType approximation, int sqrtVectorLength, DataSplitter <TaxiTripEntry> splitter, CityRegion cityRegion, string taxiBinDataPath, string resultDir)
        {
            var vectorLength = 2 * sqrtVectorLength * sqrtVectorLength;
            var numOfNodes   = sqrtNumOfNodes * sqrtNumOfNodes;
            var resultPath   =
                PathBuilder.Create(resultDir, "InnerProduct")
                .AddProperty("Dataset", "TaxiTrips")
                .AddProperty("Nodes", numOfNodes.ToString())
                .AddProperty("VectorLength", vectorLength.ToString())
                .AddProperty("Window", hoursInWindow.ToString())
                .AddProperty("Iterations", iterations.ToString())
                .AddProperty("Approximation", approximation.AsString())
                .AddProperty("DataSplit", splitter.Name)
                .ToPath("csv");

            using (var resultCsvFile = AutoFlushedTextFile.Create(resultPath, AccumaltedResult.Header(numOfNodes)))
                using (var binaryReader = new BinaryReader(File.OpenRead(taxiBinDataPath)))
                {
                    var innerProductFunction = new InnerProductFunction(vectorLength);
                    var taxiTrips            = TaxiTripEntry.FromBinary(binaryReader);
                    var windowManager        = TaxiTripsWindowManger.Init(hoursInWindow, sqrtNumOfNodes, sqrtVectorLength, splitter, cityRegion, taxiTrips);
                    var initVectors          = windowManager.GetCurrentVectors();
                    var multiRunner          = MultiRunner.InitAll(initVectors, numOfNodes, vectorLength, approximation, innerProductFunction.MonitoredFunction);
                    for (int i = 0; i < iterations; i++)
                    {
                        if (!windowManager.TakeStep())
                        {
                            break;
                        }
                        var changeVectors = windowManager.GetChangeVector();
                        multiRunner.Run(changeVectors, random, false)
                        .Select(r => r.AsCsvString())
                        .ForEach(resultCsvFile.WriteLine);
                    }
                }
        }
Beispiel #6
0
 public BoundaryBuilder(CityRegion region, City city, BoundaryContourPoint[] contour)
 {
     this.region  = region;
     this.city    = city;
     this.contour = contour;
 }