//метод поиска ближайшего к въезду в парковку парковочного места private ParkingPlace FindParkingPlace(TypeOfCar type) { ParkingPlace res = map.ParkingPlaces.OrderBy(pp => Vector2.Distance(map.EntranceVertex.Position, pp.VertexOnGraph.Position)).FirstOrDefault(pp => pp.Type == type && pp.IsEmpty); return(res); }
public ParkingManager(ParkingPlace parking) { _parking = parking; }
//метод таймера добавления машин на сцену private void AddCarsOnScene(Object myObject, EventArgs myEventArgs) { addCarTimer.Stop(); addCarTimer.Interval = GetInterval(); TryFunc <Vertex, IEnumerable <Edge <Vertex> > > tryGetPath; Random rnd = new Random(); int needParking = rnd.Next(3); int type = rnd.Next(4); int parkingPeriod = rnd.Next(5, 20) * 4; float tarif; TypeOfCar typeOfCar; if (type != 1) { typeOfCar = TypeOfCar.Automobile; tarif = settings.TarifAuto; } else { typeOfCar = TypeOfCar.Lorry; tarif = settings.TarifLorry; } Car car = new Car(typeOfCar, 1.0f); Vertex finishVertex; IEnumerable <Edge <Vertex> > path; if (needParking == 1) { tryGetPath = map.Graph.ShortestPathsDijkstra(e => { if (e.Target == map.EntranceVertex) { return(999); } else { return(1); } }, map.StartVertex); // метод поиска кратчайшего пути от начальной вершины графа к парковочному месту (Алгоритм Дейкстры) ParkingPlace place = FindParkingPlace(typeOfCar); if (place == null) { finishVertex = map.EndVertex; } else { finishVertex = place.VertexOnGraph; place.Take(car, new TimeSpan(0, 0, parkingPeriod)); MoneyInCash += tarif * parkingPeriod; } } else { tryGetPath = map.Graph.ShortestPathsDijkstra(e => 1, map.StartVertex); // метод поиска кратчайшего пути от начальной вершины графа к конечной вершине (Алгоритм Дейкстры) finishVertex = map.EndVertex; } if (tryGetPath(finishVertex, out path)) { car.Path = path; } cars.Add(car); addCarTimer.Start(); }
public static ParkingMap CreateLittleMap() { ParkingMap result = new ParkingMap("Малая карта", 800, 600); //создаём вершины графа Vertex v1 = new Vertex(1, new Vector2(850, 525)); Vertex v2 = new Vertex(2, new Vector2(600, 525)); Vertex v3 = new Vertex(3, new Vector2(580, 400)); Vertex v4 = new Vertex(4, new Vector2(450, 400)); Vertex v5 = new Vertex(5, new Vector2(700, 400)); Vertex v6 = new Vertex(6, new Vector2(580, 300)); Vertex v7 = new Vertex(7, new Vector2(450, 300)); Vertex v8 = new Vertex(8, new Vector2(700, 300)); Vertex v9 = new Vertex(9, new Vector2(580, 200)); Vertex v10 = new Vertex(10, new Vector2(450, 200)); Vertex v11 = new Vertex(11, new Vector2(700, 200)); Vertex v12 = new Vertex(12, new Vector2(580, 100)); Vertex v13 = new Vertex(13, new Vector2(450, 100)); Vertex v14 = new Vertex(14, new Vector2(700, 100)); Vertex v15 = new Vertex(15, new Vector2(540, 30)); Vertex v16 = new Vertex(16, new Vector2(450, 30)); Vertex v17 = new Vertex(17, new Vector2(300, 30)); Vertex v18 = new Vertex(18, new Vector2(300, 100)); Vertex v19 = new Vertex(19, new Vector2(125, 100)); Vertex v20 = new Vertex(20, new Vector2(300, 200)); Vertex v21 = new Vertex(21, new Vector2(125, 200)); Vertex v22 = new Vertex(22, new Vector2(300, 300)); Vertex v23 = new Vertex(23, new Vector2(125, 300)); Vertex v24 = new Vertex(24, new Vector2(300, 400)); Vertex v25 = new Vertex(25, new Vector2(125, 400)); Vertex v26 = new Vertex(26, new Vector2(300, 525)); Vertex v27 = new Vertex(27, new Vector2(125, 525)); Vertex v28 = new Vertex(28, new Vector2(-50, 525)); Vertex v29 = new Vertex(29, new Vector2(450, 525)); //добавляем рёбра графа result.AddEdge(v1, v2); result.AddEdge(v2, v3); result.AddEdge(v3, v4); result.AddEdge(v3, v5); result.AddEdge(v3, v6); result.AddEdge(v6, v7); result.AddEdge(v6, v8); result.AddEdge(v6, v9); result.AddEdge(v9, v10); result.AddEdge(v9, v11); result.AddEdge(v9, v12); result.AddEdge(v12, v13); result.AddEdge(v12, v14); result.AddEdge(v12, v15); result.AddEdge(v15, v16); result.AddEdge(v16, v17); result.AddEdge(v17, v18); result.AddEdge(v18, v19); result.AddEdge(v18, v20); result.AddEdge(v20, v21); result.AddEdge(v20, v22); result.AddEdge(v22, v23); result.AddEdge(v22, v24); result.AddEdge(v24, v25); result.AddEdge(v24, v26); result.AddEdge(v26, v27); result.AddEdge(v27, v28); result.AddEdge(v2, v29); result.AddEdge(v29, v26); result.AddEdge(v4, v3); result.AddEdge(v5, v3); result.AddEdge(v7, v6); result.AddEdge(v8, v6); result.AddEdge(v10, v9); result.AddEdge(v11, v9); result.AddEdge(v13, v12); result.AddEdge(v14, v12); result.AddEdge(v19, v18); result.AddEdge(v21, v20); result.AddEdge(v23, v22); result.AddEdge(v25, v24); //создаём парковочные места ParkingPlace p1 = new ParkingPlace(1, v4, TypeOfCar.Automobile); ParkingPlace p2 = new ParkingPlace(2, v7, TypeOfCar.Automobile); ParkingPlace p3 = new ParkingPlace(3, v10, TypeOfCar.Automobile); ParkingPlace p4 = new ParkingPlace(4, v13, TypeOfCar.Automobile); ParkingPlace p5 = new ParkingPlace(5, v5, TypeOfCar.Automobile); ParkingPlace p6 = new ParkingPlace(6, v8, TypeOfCar.Automobile); ParkingPlace p7 = new ParkingPlace(7, v11, TypeOfCar.Automobile); ParkingPlace p8 = new ParkingPlace(8, v14, TypeOfCar.Automobile); ParkingPlace p1L = new ParkingPlace(1, v25, TypeOfCar.Lorry); ParkingPlace p2L = new ParkingPlace(2, v23, TypeOfCar.Lorry); ParkingPlace p3L = new ParkingPlace(3, v21, TypeOfCar.Lorry); ParkingPlace p4L = new ParkingPlace(4, v19, TypeOfCar.Lorry); result.ParkingPlaces = new[] { p1, p2, p3, p4, p5, p6, p7, p8, p1L, p2L, p3L, p4L }; result.StartVertex = v1; result.EndVertex = v28; result.EntranceVertex = v29; result.MoveBorderY = 450; return(result); }
public static ParkingMap CreateBigMap() { ParkingMap result = new ParkingMap("Большая карта", 800, 700); //создаём вершины графа Vertex v1 = new Vertex(1, new Vector2(850, 625)); Vertex v2 = new Vertex(2, new Vector2(590, 625)); Vertex v3 = new Vertex(3, new Vector2(425, 625)); Vertex v4 = new Vertex(4, new Vector2(275, 625)); Vertex v5 = new Vertex(5, new Vector2(125, 625)); Vertex v6 = new Vertex(6, new Vector2(-50, 625)); Vertex v9 = new Vertex(9, new Vector2(700, 475)); Vertex v7 = new Vertex(7, new Vector2(575, 475)); Vertex v8 = new Vertex(8, new Vector2(425, 475)); Vertex v33 = new Vertex(33, new Vector2(275, 475)); Vertex v34 = new Vertex(34, new Vector2(125, 475)); Vertex v11 = new Vertex(11, new Vector2(700, 375)); Vertex v10 = new Vertex(10, new Vector2(575, 375)); Vertex v12 = new Vertex(12, new Vector2(425, 375)); Vertex v31 = new Vertex(31, new Vector2(275, 375)); Vertex v32 = new Vertex(32, new Vector2(125, 375)); Vertex v15 = new Vertex(15, new Vector2(700, 275)); Vertex v13 = new Vertex(13, new Vector2(575, 275)); Vertex v14 = new Vertex(14, new Vector2(425, 275)); Vertex v29 = new Vertex(29, new Vector2(275, 275)); Vertex v30 = new Vertex(30, new Vector2(125, 275)); Vertex v18 = new Vertex(18, new Vector2(700, 175)); Vertex v16 = new Vertex(16, new Vector2(575, 175)); Vertex v17 = new Vertex(17, new Vector2(425, 175)); Vertex v27 = new Vertex(27, new Vector2(275, 175)); Vertex v28 = new Vertex(28, new Vector2(125, 175)); Vertex v21 = new Vertex(21, new Vector2(700, 75)); Vertex v19 = new Vertex(19, new Vector2(575, 75)); Vertex v20 = new Vertex(20, new Vector2(425, 75)); Vertex v25 = new Vertex(25, new Vector2(275, 75)); Vertex v26 = new Vertex(26, new Vector2(125, 75)); Vertex v23 = new Vertex(23, new Vector2(425, 15)); result.AddEdge(v1, v2); result.AddEdge(v2, v3); result.AddEdge(v3, v4); result.AddEdge(v4, v5); result.AddEdge(v5, v6); result.AddEdge(v2, v7); result.AddEdge(v7, v8); result.AddEdge(v7, v9); result.AddEdge(v7, v10); result.AddEdge(v10, v12); result.AddEdge(v10, v11); result.AddEdge(v10, v13); result.AddEdge(v13, v14); result.AddEdge(v13, v15); result.AddEdge(v13, v16); result.AddEdge(v16, v17); result.AddEdge(v16, v18); result.AddEdge(v16, v19); result.AddEdge(v19, v20); result.AddEdge(v19, v21); result.AddEdge(v19, v23); result.AddEdge(v23, v25); result.AddEdge(v25, v26); result.AddEdge(v25, v27); result.AddEdge(v27, v28); result.AddEdge(v27, v29); result.AddEdge(v29, v30); result.AddEdge(v29, v31); result.AddEdge(v31, v32); result.AddEdge(v31, v33); result.AddEdge(v33, v34); result.AddEdge(v33, v4); result.AddEdge(v8, v7); result.AddEdge(v9, v7); result.AddEdge(v12, v10); result.AddEdge(v11, v10); result.AddEdge(v14, v13); result.AddEdge(v15, v13); result.AddEdge(v17, v16); result.AddEdge(v18, v16); result.AddEdge(v20, v19); result.AddEdge(v21, v19); result.AddEdge(v26, v25); result.AddEdge(v28, v27); result.AddEdge(v30, v29); result.AddEdge(v32, v31); result.AddEdge(v34, v33); //создаём парковочные места ParkingPlace p1 = new ParkingPlace(1, v8, TypeOfCar.Automobile); ParkingPlace p2 = new ParkingPlace(2, v12, TypeOfCar.Automobile); ParkingPlace p3 = new ParkingPlace(3, v14, TypeOfCar.Automobile); ParkingPlace p4 = new ParkingPlace(4, v17, TypeOfCar.Automobile); ParkingPlace p5 = new ParkingPlace(5, v20, TypeOfCar.Automobile); ParkingPlace p6 = new ParkingPlace(6, v9, TypeOfCar.Automobile); ParkingPlace p7 = new ParkingPlace(7, v11, TypeOfCar.Automobile); ParkingPlace p8 = new ParkingPlace(8, v15, TypeOfCar.Automobile); ParkingPlace p9 = new ParkingPlace(9, v18, TypeOfCar.Automobile); ParkingPlace p10 = new ParkingPlace(20, v21, TypeOfCar.Automobile); ParkingPlace p1L = new ParkingPlace(1, v34, TypeOfCar.Lorry); ParkingPlace p2L = new ParkingPlace(2, v32, TypeOfCar.Lorry); ParkingPlace p3L = new ParkingPlace(3, v30, TypeOfCar.Lorry); ParkingPlace p4L = new ParkingPlace(4, v28, TypeOfCar.Lorry); ParkingPlace p5L = new ParkingPlace(4, v26, TypeOfCar.Lorry); result.ParkingPlaces = new[] { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p1L, p2L, p3L, p4L, p5L }; result.StartVertex = v1; result.EndVertex = v6; result.EntranceVertex = v2; result.MoveBorderY = 600; return(result); }
public static ParkingMap CreateBigMap() { ParkingMap result = new ParkingMap("Большая карта", 800, 700); //создаём вершины графа Vertex v1 = new Vertex(1, new Vector2(850, 625)); Vertex v2 = new Vertex(2, new Vector2(590, 625)); Vertex v3 = new Vertex(3, new Vector2(425, 625)); Vertex v4 = new Vertex(4, new Vector2(275, 625)); Vertex v5 = new Vertex(5, new Vector2(125, 625)); Vertex v6 = new Vertex(6, new Vector2(-50, 625)); Vertex v9 = new Vertex(9, new Vector2(700, 475)); Vertex v7 = new Vertex(7, new Vector2(575, 475)); Vertex v8 = new Vertex(8, new Vector2(425, 475)); Vertex v33 = new Vertex(33, new Vector2(275, 475)); Vertex v34 = new Vertex(34, new Vector2(125, 475)); Vertex v11 = new Vertex(11, new Vector2(700, 375)); Vertex v10 = new Vertex(10, new Vector2(575, 375)); Vertex v12 = new Vertex(12, new Vector2(425, 375)); Vertex v31 = new Vertex(31, new Vector2(275, 375)); Vertex v32 = new Vertex(32, new Vector2(125, 375)); Vertex v15 = new Vertex(15, new Vector2(700, 275)); Vertex v13 = new Vertex(13, new Vector2(575, 275)); Vertex v14 = new Vertex(14, new Vector2(425, 275)); Vertex v29 = new Vertex(29, new Vector2(275, 275)); Vertex v30 = new Vertex(30, new Vector2(125, 275)); Vertex v18 = new Vertex(18, new Vector2(700, 175)); Vertex v16 = new Vertex(16, new Vector2(575, 175)); Vertex v17 = new Vertex(17, new Vector2(425, 175)); Vertex v27 = new Vertex(27, new Vector2(275, 175)); Vertex v28 = new Vertex(28, new Vector2(125, 175)); Vertex v21 = new Vertex(21, new Vector2(700, 75)); Vertex v19 = new Vertex(19, new Vector2(575, 75)); Vertex v20 = new Vertex(20, new Vector2(425, 75)); Vertex v25 = new Vertex(25, new Vector2(275, 75)); Vertex v26 = new Vertex(26, new Vector2(125, 75)); Vertex v23 = new Vertex(23, new Vector2(425, 15)); result.AddEdge(v1, v2); result.AddEdge(v2, v3); result.AddEdge(v3, v4); result.AddEdge(v4, v5); result.AddEdge(v5, v6); result.AddEdge(v2, v7); result.AddEdge(v7, v8); result.AddEdge(v7, v9); result.AddEdge(v7, v10); result.AddEdge(v10, v12); result.AddEdge(v10, v11); result.AddEdge(v10, v13); result.AddEdge(v13, v14); result.AddEdge(v13, v15); result.AddEdge(v13, v16); result.AddEdge(v16, v17); result.AddEdge(v16, v18); result.AddEdge(v16, v19); result.AddEdge(v19, v20); result.AddEdge(v19, v21); result.AddEdge(v19, v23); result.AddEdge(v23, v25); result.AddEdge(v25, v26); result.AddEdge(v25, v27); result.AddEdge(v27, v28); result.AddEdge(v27, v29); result.AddEdge(v29, v30); result.AddEdge(v29, v31); result.AddEdge(v31, v32); result.AddEdge(v31, v33); result.AddEdge(v33, v34); result.AddEdge(v33, v4); result.AddEdge(v8, v7); result.AddEdge(v9, v7); result.AddEdge(v12, v10); result.AddEdge(v11, v10); result.AddEdge(v14, v13); result.AddEdge(v15, v13); result.AddEdge(v17, v16); result.AddEdge(v18, v16); result.AddEdge(v20, v19); result.AddEdge(v21, v19); result.AddEdge(v26, v25); result.AddEdge(v28, v27); result.AddEdge(v30, v29); result.AddEdge(v32, v31); result.AddEdge(v34, v33); //создаём парковочные места ParkingPlace p1 = new ParkingPlace(1, v8, TypeOfCar.Automobile); ParkingPlace p2 = new ParkingPlace(2, v12, TypeOfCar.Automobile); ParkingPlace p3 = new ParkingPlace(3, v14, TypeOfCar.Automobile); ParkingPlace p4 = new ParkingPlace(4, v17, TypeOfCar.Automobile); ParkingPlace p5 = new ParkingPlace(5, v20, TypeOfCar.Automobile); ParkingPlace p6 = new ParkingPlace(6, v9, TypeOfCar.Automobile); ParkingPlace p7 = new ParkingPlace(7, v11, TypeOfCar.Automobile); ParkingPlace p8 = new ParkingPlace(8, v15, TypeOfCar.Automobile); ParkingPlace p9 = new ParkingPlace(9, v18, TypeOfCar.Automobile); ParkingPlace p10 = new ParkingPlace(20, v21, TypeOfCar.Automobile); ParkingPlace p1L = new ParkingPlace(1, v34, TypeOfCar.Lorry); ParkingPlace p2L = new ParkingPlace(2, v32, TypeOfCar.Lorry); ParkingPlace p3L = new ParkingPlace(3, v30, TypeOfCar.Lorry); ParkingPlace p4L = new ParkingPlace(4, v28, TypeOfCar.Lorry); ParkingPlace p5L = new ParkingPlace(4, v26, TypeOfCar.Lorry); result.ParkingPlaces = new[] { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p1L, p2L, p3L, p4L, p5L }; result.StartVertex = v1; result.EndVertex = v6; result.EntranceVertex = v2; result.MoveBorderY = 600; return result; }
public static ParkingMap CreateLittleMap() { ParkingMap result = new ParkingMap("Малая карта", 800, 600); //создаём вершины графа Vertex v1 = new Vertex(1, new Vector2(850, 525)); Vertex v2 = new Vertex(2, new Vector2(600, 525)); Vertex v3 = new Vertex(3, new Vector2(580, 400)); Vertex v4 = new Vertex(4, new Vector2(450, 400)); Vertex v5 = new Vertex(5, new Vector2(700, 400)); Vertex v6 = new Vertex(6, new Vector2(580, 300)); Vertex v7 = new Vertex(7, new Vector2(450, 300)); Vertex v8 = new Vertex(8, new Vector2(700, 300)); Vertex v9 = new Vertex(9, new Vector2(580, 200)); Vertex v10 = new Vertex(10, new Vector2(450, 200)); Vertex v11 = new Vertex(11, new Vector2(700, 200)); Vertex v12 = new Vertex(12, new Vector2(580, 100)); Vertex v13 = new Vertex(13, new Vector2(450, 100)); Vertex v14 = new Vertex(14, new Vector2(700, 100)); Vertex v15 = new Vertex(15, new Vector2(540, 30)); Vertex v16 = new Vertex(16, new Vector2(450, 30)); Vertex v17 = new Vertex(17, new Vector2(300, 30)); Vertex v18 = new Vertex(18, new Vector2(300, 100)); Vertex v19 = new Vertex(19, new Vector2(125, 100)); Vertex v20 = new Vertex(20, new Vector2(300, 200)); Vertex v21 = new Vertex(21, new Vector2(125, 200)); Vertex v22 = new Vertex(22, new Vector2(300, 300)); Vertex v23 = new Vertex(23, new Vector2(125, 300)); Vertex v24 = new Vertex(24, new Vector2(300, 400)); Vertex v25 = new Vertex(25, new Vector2(125, 400)); Vertex v26 = new Vertex(26, new Vector2(300, 525)); Vertex v27 = new Vertex(27, new Vector2(125, 525)); Vertex v28 = new Vertex(28, new Vector2(-50, 525)); Vertex v29 = new Vertex(29, new Vector2(450, 525)); //добавляем рёбра графа result.AddEdge(v1, v2); result.AddEdge(v2, v3); result.AddEdge(v3, v4); result.AddEdge(v3, v5); result.AddEdge(v3, v6); result.AddEdge(v6, v7); result.AddEdge(v6, v8); result.AddEdge(v6, v9); result.AddEdge(v9, v10); result.AddEdge(v9, v11); result.AddEdge(v9, v12); result.AddEdge(v12, v13); result.AddEdge(v12, v14); result.AddEdge(v12, v15); result.AddEdge(v15, v16); result.AddEdge(v16, v17); result.AddEdge(v17, v18); result.AddEdge(v18, v19); result.AddEdge(v18, v20); result.AddEdge(v20, v21); result.AddEdge(v20, v22); result.AddEdge(v22, v23); result.AddEdge(v22, v24); result.AddEdge(v24, v25); result.AddEdge(v24, v26); result.AddEdge(v26, v27); result.AddEdge(v27, v28); result.AddEdge(v2, v29); result.AddEdge(v29, v26); result.AddEdge(v4, v3); result.AddEdge(v5, v3); result.AddEdge(v7, v6); result.AddEdge(v8, v6); result.AddEdge(v10, v9); result.AddEdge(v11, v9); result.AddEdge(v13, v12); result.AddEdge(v14, v12); result.AddEdge(v19, v18); result.AddEdge(v21, v20); result.AddEdge(v23, v22); result.AddEdge(v25, v24); //создаём парковочные места ParkingPlace p1 = new ParkingPlace(1, v4, TypeOfCar.Automobile); ParkingPlace p2 = new ParkingPlace(2, v7, TypeOfCar.Automobile); ParkingPlace p3 = new ParkingPlace(3, v10, TypeOfCar.Automobile); ParkingPlace p4 = new ParkingPlace(4, v13, TypeOfCar.Automobile); ParkingPlace p5 = new ParkingPlace(5, v5, TypeOfCar.Automobile); ParkingPlace p6 = new ParkingPlace(6, v8, TypeOfCar.Automobile); ParkingPlace p7 = new ParkingPlace(7, v11, TypeOfCar.Automobile); ParkingPlace p8 = new ParkingPlace(8, v14, TypeOfCar.Automobile); ParkingPlace p1L = new ParkingPlace(1, v25, TypeOfCar.Lorry); ParkingPlace p2L = new ParkingPlace(2, v23, TypeOfCar.Lorry); ParkingPlace p3L = new ParkingPlace(3, v21, TypeOfCar.Lorry); ParkingPlace p4L = new ParkingPlace(4, v19, TypeOfCar.Lorry); result.ParkingPlaces = new[] { p1, p2, p3, p4, p5, p6, p7, p8, p1L, p2L, p3L, p4L }; result.StartVertex = v1; result.EndVertex = v28; result.EntranceVertex = v29; result.MoveBorderY = 450; return result; }
} //парковочное место, соответствующее этой вершине графа, возможно null //конструктор вершины public Vertex(int num, Vector2 pos) { Number = num; Position = pos; Place = null; }