示例#1
0
        static void addBarriers(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);

            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                BarriersDB db = new BarriersDB(connection);
                Barrier    b1 = new Barrier(Util.CreateGuid(), 34.8514759540558, 32.0996901152282, 0);
                Barrier    b2 = new Barrier(Util.CreateGuid(), 34.8514759540558, 32.1002763321138, 0);
                Barrier    b3 = new Barrier(Util.CreateGuid(), 34.8511058092117, 32.0973406656135, 0);
                Barrier    b4 = new Barrier(Util.CreateGuid(), 34.8504620790482, 32.0961000227717, 0);
                db.addBarriers(new Barrier[] { b1, b2, b3, b4 });
                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }
示例#2
0
        static async Task addWaypointRoutes(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);

            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                // travel waypoints
                //DPoint[] travelCoordinates = new DPoint[] { new DPoint(34.8496, 32.0996), new DPoint(34.8506, 32.099), new DPoint(34.8486, 32.099),
                //                                        new DPoint(34.8503, 32.0981), new DPoint(34.8487, 32.0983),
                //                                        new DPoint(34.8486, 32.099), new DPoint(34.851, 32.0997),
                //                                        new DPoint(34.8515, 32.0992), new DPoint(34.8514, 32.0983),
                //                                        new DPoint(34.8511, 32.0973), new DPoint(34.8501, 32.0977),
                //                                        new DPoint(34.8487, 32.0982), new DPoint(34.8478, 32.0986)};

                DPoint[] travelCoordinates = new DPoint[] { new DPoint(34.848627448082, 32.0995901398799), new DPoint(34.8495876789093, 32.0996264945646),
                                                            new DPoint(34.8505747318268, 32.0996492162353),
                                                            new DPoint(34.850612282753, 32.0982768171897), new DPoint(34.8492550849915, 32.0980950409352),
                                                            new DPoint(34.8486435413361, 32.098308627997), new DPoint(34.8514652252197, 32.0996855708965),
                                                            new DPoint(34.851508140564, 32.0986403686134), new DPoint(34.8511004447937, 32.0973452100618),
                                                            new DPoint(34.8498612642288, 32.0977905648985), new DPoint(34.8485255241394, 32.0982631839831),
                                                            new DPoint(34.8479408025742, 32.0971543430385), new DPoint(34.8504567146301, 32.096090933751) };

                // read all barrier coordinates
                BarriersDB     barriersDB = new BarriersDB(connection);
                List <Barrier> barriers   = barriersDB.readAllBarriers();

                RouteGenerator generator = new RouteGenerator(connection);

                // generate routes from waypoint to other waypoints
                for (int i = 0; i < travelCoordinates.Count(); i++)
                {
                    for (int j = 0; j < travelCoordinates.Count(); j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        Route waypointRoute = await generator.generateRouteByShortestPath("WaypointToWaypoint_" + i + "," + j, travelCoordinates[i], travelCoordinates[j]);

                        generator.saveRouteToDB(waypointRoute);
                    }
                }

                // generate routes from waypoint to barriers
                for (int i = 0; i < travelCoordinates.Count(); i++)
                {
                    for (int j = 0; j < barriers.Count(); j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }

                        DPoint barrierCoordinates = new DPoint(barriers[j].x, barriers[j].y);
                        Route  waypointRoute      = await generator.generateRouteByShortestPath("WaypointToBarrier_" + i + "," + j, travelCoordinates[i], barrierCoordinates);

                        generator.saveRouteToDB(waypointRoute);
                    }
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }
示例#3
0
文件: Program.cs 项目: ohadmanor/TDS
        static async Task addWaypointRoutes(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);
            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                // travel waypoints
                //DPoint[] travelCoordinates = new DPoint[] { new DPoint(34.8496, 32.0996), new DPoint(34.8506, 32.099), new DPoint(34.8486, 32.099),
                //                                        new DPoint(34.8503, 32.0981), new DPoint(34.8487, 32.0983),
                //                                        new DPoint(34.8486, 32.099), new DPoint(34.851, 32.0997),
                //                                        new DPoint(34.8515, 32.0992), new DPoint(34.8514, 32.0983),
                //                                        new DPoint(34.8511, 32.0973), new DPoint(34.8501, 32.0977),
                //                                        new DPoint(34.8487, 32.0982), new DPoint(34.8478, 32.0986)};

                DPoint[] travelCoordinates = new DPoint[] { new DPoint(34.848627448082, 32.0995901398799), new DPoint(34.8495876789093, 32.0996264945646),
                                                        new DPoint(34.8505747318268, 32.0996492162353),
                                                        new DPoint(34.850612282753, 32.0982768171897), new DPoint(34.8492550849915, 32.0980950409352),
                                                        new DPoint(34.8486435413361, 32.098308627997), new DPoint(34.8514652252197, 32.0996855708965),
                                                        new DPoint(34.851508140564, 32.0986403686134), new DPoint(34.8511004447937, 32.0973452100618),
                                                        new DPoint(34.8498612642288, 32.0977905648985), new DPoint(34.8485255241394, 32.0982631839831),
                                                        new DPoint(34.8479408025742, 32.0971543430385), new DPoint(34.8504567146301, 32.096090933751)};

                // read all barrier coordinates
                BarriersDB barriersDB = new BarriersDB(connection);
                List<Barrier> barriers = barriersDB.readAllBarriers();

                RouteGenerator generator = new RouteGenerator(connection);

                // generate routes from waypoint to other waypoints
                for (int i = 0; i < travelCoordinates.Count(); i++)
                {
                    for (int j = 0; j < travelCoordinates.Count(); j++)
                    {
                        if (i == j) continue;
                        Route waypointRoute = await generator.generateRouteByShortestPath("WaypointToWaypoint_" + i + "," + j, travelCoordinates[i], travelCoordinates[j]);
                        generator.saveRouteToDB(waypointRoute);
                    }
                }

                // generate routes from waypoint to barriers
                for (int i = 0; i < travelCoordinates.Count(); i++)
                {
                    for (int j = 0; j < barriers.Count(); j++)
                    {
                        if (i == j) continue;

                        DPoint barrierCoordinates = new DPoint(barriers[j].x, barriers[j].y);
                        Route waypointRoute = await generator.generateRouteByShortestPath("WaypointToBarrier_" + i + "," + j, travelCoordinates[i], barrierCoordinates);
                        generator.saveRouteToDB(waypointRoute);
                    }
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();

        }
示例#4
0
文件: Program.cs 项目: ohadmanor/TDS
        static void addBarriers(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);
            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                BarriersDB db = new BarriersDB(connection);
                Barrier b1 = new Barrier(Util.CreateGuid(), 34.8514759540558, 32.0996901152282, 0);
                Barrier b2 = new Barrier(Util.CreateGuid(), 34.8514759540558, 32.1002763321138, 0);
                Barrier b3 = new Barrier(Util.CreateGuid(), 34.8511058092117, 32.0973406656135, 0);
                Barrier b4 = new Barrier(Util.CreateGuid(), 34.8504620790482, 32.0961000227717, 0);
                db.addBarriers(new Barrier[] { b1, b2, b3, b4 });
                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }