WIP Adding Reservations

This commit is contained in:
Dawid Pietrykowski 2022-09-04 00:35:45 +02:00
parent ca0eaa9568
commit f26a570c93
6 changed files with 317 additions and 108 deletions

141
Assets/Data/Tablica1.csv Normal file
View File

@ -0,0 +1,141 @@
Ranga stanowiska ,wybrany sposób parkowania,Klasyfikacja gabarytu ,od planwane,do planowane,od rzeczywiste,do rzeczywiste,czas miedzy sprawdzaniem miejsca
1,P,Duży,9,15,8:45,13:20,60
1,T,Duży,8,10,7:53,10:01,60
1,,Duży,9,13,8:53,14:02,60
1,P,Duży,8,16,7:45,16:10,60
1,,Duży,9,16,9:30,14,60
1,P,Duży,11,14,12,14:10,60
1,P,Duży,10,15,9:50,13:10,60
1,P,Duży,9,15,9:20,14:50,60
1,,Duży,9,17,9,17:04,60
1,,Duży,12,17,12:50,17:02,60
1,,Duży,9,17,9,16:58,60
1,P,Duży,10,15,9:50,13:30,60
1,,Duży,9,14,9:30,14:10,60
1,,Duży,8,16,7:56,17:12,60
1,,Duży,9,15,10,12:30,60
2,,Duży,8,16,7:50,17:05,15
2,P,Mały,7,15,6:40,14:50,15
2,,Średni,7,15,7:05,15:14,15
2,,Duży,10,16,10:49,15:58,15
2,P,Średni,8,16,8:49,15:04,15
2,,Średni,9,17,9:23,16:59,15
2,P,Duży,8,16,7:49,16:05,15
2,T,Średni,7:30,15:30,7:27,15:36,15
2,T,Duży,8,16,8:10,15:50,15
2,P,Duży,7:30,15:30,7:53,15:37,15
2,,Duży,8,16,7:53,16:01,15
2,T,Średni,7:30,15:30,7:35,15:30,15
2,,Duży,8,16,7:53,16:40,15
2,P,Średni,8,16,7:57,16:01,15
2,,Średni,8,16,7:45,16:10,15
2,T,Duży,11,16,11:18,16:13,15
2,,Duży,10,16,10:05,16:08,15
2,,Duży,7,15,7,15:10,15
3,P,Mały,6,14,6:05,13:55,15
3,,Mały,8,16,7:45,16:10,15
3,P,Średni,8,16,7:50,16:15,15
3,,Duży,8,16,8:03,16:10,15
3,,Średni,8,10,8,9:58,15
3,,Średni,7:30,12:30,7:25,12:32,15
3,T,Duży,8,12,8:02,12:05,15
3,,Średni,7:30,13:30,7:28,13:40,15
3,T,Średni,7:30,15:30,7:15,15:17,15
3,,Mały,8,16,7:45,16:10,15
3,P,Średni,7,7,6:58,7:10,15
3,P,Duży,8,16,7:57,15:58,15
3,,Średni,6,14,6:05,14:10,15
3,,Średni,6,14,6:01,14:03,15
3,,Mały,6:30,14:30,6:32,14:34,15
3,P,Średni,7,15,6:57,15,15
3,P,Duży,8,16,7:45,16:10,15
3,,Średni,8,16,8:02,15:59,15
3,,Średni,8:30,16:30,8:21,16:27,15
3,P,Mały,9,17,9:02,17:10,15
3,,Średni,9,17,8:57,16:58,15
3,,Średni,8,16,8:04,16:12,15
3,,Mały,8,16,7:52,15:57,15
3,T,Średni,7,15,7:08,15:14,15
3,,Średni,7:30,15:30,7:31,15:39,15
3,,Duży,8,16,7:56,15:57,15
3,,Mały,8,16,7:50,15:59,15
3,P,Średni,8:30,16:30,8:27,16:34,15
3,,Mały,7,15,6:57,15:05,15
3,,Średni,8,16,8:02,15:59,15
3,T,Średni,7,15,6:54,15:01,15
3,,Mały,8,16,7:49,15:58,15
3,,Średni,8,16,8,15:58,15
3,,Duży,8:30,16:30,8:25,16:32,15
3,T,Średni,8,16,8:04,16:10,15
3,,Średni,7,15,6:58,15:03,15
3,,Średni,7:30,15:30,7:29,15:40,15
3,,Mały,7:30,3:30,7:28,12:33,15
3,P,Średni,7,15,7:57,14:59,15
3,P,Mały,7,13,0:00,0:00,15
3,,Duży,8,16,8:04,15:59,15
3,,Średni,7:30,15:30,7:25,15:35,15
3,P,Mały,8,16,8:02,15:58,15
3,,Duży,7:30,15:30,7:28,15:34,15
3,,Średni,8,16,7:53,16:01,15
3,,Średni,7,12,6:58,12:05,15
3,,Mały,8,13,7:56,13:59,15
3,,Mały,7:30,12,7:24,12:28,15
3,,Średni,8,14,8:01,14:07,15
3,T,Duży,8,13,8:10,13:12,15
3,,Średni,7:30,15:30,7:22,15:20,15
3,P,Średni,8,16,7:49,15:58,15
3,,Mały,8,16,7:45,16:10,15
3,,Średni,7:30,15:30,7:31,15:35,15
3,,Duży,7,15,6:57,15:01,15
3,T,Średni,7,15,7:08,1:15,15
3,,Mały,7:30,15:30,7:25,15:28,15
3,,Duży,8,16,7:53,16:01,15
3,P,Średni,8,16,7:56,15:58,15
3,,Średni,7,15,6:56,15:03,15
3,T,Mały,7,15,7,15:05,15
3,,Średni,8,16,7:56,16:58,15
3,P,Średni,7,15,6:57,14:59,15
3,,Średni,7,15,6:55,14:58,15
3,,Duży,8,16,8:02,16:07,15
3,T,Średni,8,16,7:56,16:05,15
3,,Średni,7,15,6:58,15:03,15
3,,Duży,8,16,8,16:05,15
3,,Mały,8,16,8:04,15:58,15
3,,Średni,7:30,15:30,7:34,15:40,15
3,P,Średni,8,16,7:53,16:01,15
3,,Średni,8,13,7:49,13:02,15
3,,Średni,7,15,6:58,15:04,15
3,,Średni,7,15,7:08,15:05,15
3,P,Średni,8,16,7:58,16:05,15
3,,Średni,7,15,7:04,15:11,15
3,P,Średni,6:30,14:30,6:25,14:29,15
3,P,Średni,9,17,8:49,17:05,15
3,,Średni,9,17,8:55,17:01,15
3,P,Duży,7,15,6:58,15:10,15
3,,Duży,7:30,15:30,7:25,15:31,15
3,,Średni,7:30,11:30,7:27,11:32,15
3,T,Średni,8,16,7:56,16,15
3,,Średni,8,16,8:02,16:05,15
3,,Średni,7:30,15:30,7:36,15:40,15
3,,Średni,8,16,8:04,16:07,15
3,P,Średni,8,9,7:59,9:09,15
3,,Średni,7:15,15:15,7:10,15:18,15
3,T,Duży,8,16,7:49,15:51,15
3,,Średni,8,16,8:04,16:11,15
3,P,Średni,8,16,8:02,16:03,15
3,,Średni,7,15,7:01,15:07,15
3,,Duży,7:30,15:30,7:25,15:25,15
3,P,Średni,7,15,7:08,15:15,15
3,,Średni,8,16,7:45,16:10,15
3,,Średni,8,16,7:49,15:59,15
3,,Średni,8,16,7:45,16:10,15
3,T,Duży,7,15,7:07,15:20,15
3,,Średni,7,15,7:02,15:11,15
3,,Średni,8,16,8:06,15:49,15
3,P,Średni,7,15,7:24,16:40,15
3,,Średni,8,16,8:02,16:05,15
3,,Duży,8,16,8:05,16:01,15
3,T,Średni,7,15,7:13,15:13,15
3,,Średni,8,16,7:36,16:00,15
3,T,Średni,7,15,6:55,15:11,15
3,,Średni,9,17,9:09,17:14,15
1 Ranga stanowiska wybrany sposób parkowania Klasyfikacja gabarytu od planwane do planowane od rzeczywiste do rzeczywiste czas miedzy sprawdzaniem miejsca
2 1 P Duży 9 15 8:45 13:20 60
3 1 T Duży 8 10 7:53 10:01 60
4 1 Duży 9 13 8:53 14:02 60
5 1 P Duży 8 16 7:45 16:10 60
6 1 Duży 9 16 9:30 14 60
7 1 P Duży 11 14 12 14:10 60
8 1 P Duży 10 15 9:50 13:10 60
9 1 P Duży 9 15 9:20 14:50 60
10 1 Duży 9 17 9 17:04 60
11 1 Duży 12 17 12:50 17:02 60
12 1 Duży 9 17 9 16:58 60
13 1 P Duży 10 15 9:50 13:30 60
14 1 Duży 9 14 9:30 14:10 60
15 1 Duży 8 16 7:56 17:12 60
16 1 Duży 9 15 10 12:30 60
17 2 Duży 8 16 7:50 17:05 15
18 2 P Mały 7 15 6:40 14:50 15
19 2 Średni 7 15 7:05 15:14 15
20 2 Duży 10 16 10:49 15:58 15
21 2 P Średni 8 16 8:49 15:04 15
22 2 Średni 9 17 9:23 16:59 15
23 2 P Duży 8 16 7:49 16:05 15
24 2 T Średni 7:30 15:30 7:27 15:36 15
25 2 T Duży 8 16 8:10 15:50 15
26 2 P Duży 7:30 15:30 7:53 15:37 15
27 2 Duży 8 16 7:53 16:01 15
28 2 T Średni 7:30 15:30 7:35 15:30 15
29 2 Duży 8 16 7:53 16:40 15
30 2 P Średni 8 16 7:57 16:01 15
31 2 Średni 8 16 7:45 16:10 15
32 2 T Duży 11 16 11:18 16:13 15
33 2 Duży 10 16 10:05 16:08 15
34 2 Duży 7 15 7 15:10 15
35 3 P Mały 6 14 6:05 13:55 15
36 3 Mały 8 16 7:45 16:10 15
37 3 P Średni 8 16 7:50 16:15 15
38 3 Duży 8 16 8:03 16:10 15
39 3 Średni 8 10 8 9:58 15
40 3 Średni 7:30 12:30 7:25 12:32 15
41 3 T Duży 8 12 8:02 12:05 15
42 3 Średni 7:30 13:30 7:28 13:40 15
43 3 T Średni 7:30 15:30 7:15 15:17 15
44 3 Mały 8 16 7:45 16:10 15
45 3 P Średni 7 7 6:58 7:10 15
46 3 P Duży 8 16 7:57 15:58 15
47 3 Średni 6 14 6:05 14:10 15
48 3 Średni 6 14 6:01 14:03 15
49 3 Mały 6:30 14:30 6:32 14:34 15
50 3 P Średni 7 15 6:57 15 15
51 3 P Duży 8 16 7:45 16:10 15
52 3 Średni 8 16 8:02 15:59 15
53 3 Średni 8:30 16:30 8:21 16:27 15
54 3 P Mały 9 17 9:02 17:10 15
55 3 Średni 9 17 8:57 16:58 15
56 3 Średni 8 16 8:04 16:12 15
57 3 Mały 8 16 7:52 15:57 15
58 3 T Średni 7 15 7:08 15:14 15
59 3 Średni 7:30 15:30 7:31 15:39 15
60 3 Duży 8 16 7:56 15:57 15
61 3 Mały 8 16 7:50 15:59 15
62 3 P Średni 8:30 16:30 8:27 16:34 15
63 3 Mały 7 15 6:57 15:05 15
64 3 Średni 8 16 8:02 15:59 15
65 3 T Średni 7 15 6:54 15:01 15
66 3 Mały 8 16 7:49 15:58 15
67 3 Średni 8 16 8 15:58 15
68 3 Duży 8:30 16:30 8:25 16:32 15
69 3 T Średni 8 16 8:04 16:10 15
70 3 Średni 7 15 6:58 15:03 15
71 3 Średni 7:30 15:30 7:29 15:40 15
72 3 Mały 7:30 3:30 7:28 12:33 15
73 3 P Średni 7 15 7:57 14:59 15
74 3 P Mały 7 13 0:00 0:00 15
75 3 Duży 8 16 8:04 15:59 15
76 3 Średni 7:30 15:30 7:25 15:35 15
77 3 P Mały 8 16 8:02 15:58 15
78 3 Duży 7:30 15:30 7:28 15:34 15
79 3 Średni 8 16 7:53 16:01 15
80 3 Średni 7 12 6:58 12:05 15
81 3 Mały 8 13 7:56 13:59 15
82 3 Mały 7:30 12 7:24 12:28 15
83 3 Średni 8 14 8:01 14:07 15
84 3 T Duży 8 13 8:10 13:12 15
85 3 Średni 7:30 15:30 7:22 15:20 15
86 3 P Średni 8 16 7:49 15:58 15
87 3 Mały 8 16 7:45 16:10 15
88 3 Średni 7:30 15:30 7:31 15:35 15
89 3 Duży 7 15 6:57 15:01 15
90 3 T Średni 7 15 7:08 1:15 15
91 3 Mały 7:30 15:30 7:25 15:28 15
92 3 Duży 8 16 7:53 16:01 15
93 3 P Średni 8 16 7:56 15:58 15
94 3 Średni 7 15 6:56 15:03 15
95 3 T Mały 7 15 7 15:05 15
96 3 Średni 8 16 7:56 16:58 15
97 3 P Średni 7 15 6:57 14:59 15
98 3 Średni 7 15 6:55 14:58 15
99 3 Duży 8 16 8:02 16:07 15
100 3 T Średni 8 16 7:56 16:05 15
101 3 Średni 7 15 6:58 15:03 15
102 3 Duży 8 16 8 16:05 15
103 3 Mały 8 16 8:04 15:58 15
104 3 Średni 7:30 15:30 7:34 15:40 15
105 3 P Średni 8 16 7:53 16:01 15
106 3 Średni 8 13 7:49 13:02 15
107 3 Średni 7 15 6:58 15:04 15
108 3 Średni 7 15 7:08 15:05 15
109 3 P Średni 8 16 7:58 16:05 15
110 3 Średni 7 15 7:04 15:11 15
111 3 P Średni 6:30 14:30 6:25 14:29 15
112 3 P Średni 9 17 8:49 17:05 15
113 3 Średni 9 17 8:55 17:01 15
114 3 P Duży 7 15 6:58 15:10 15
115 3 Duży 7:30 15:30 7:25 15:31 15
116 3 Średni 7:30 11:30 7:27 11:32 15
117 3 T Średni 8 16 7:56 16 15
118 3 Średni 8 16 8:02 16:05 15
119 3 Średni 7:30 15:30 7:36 15:40 15
120 3 Średni 8 16 8:04 16:07 15
121 3 P Średni 8 9 7:59 9:09 15
122 3 Średni 7:15 15:15 7:10 15:18 15
123 3 T Duży 8 16 7:49 15:51 15
124 3 Średni 8 16 8:04 16:11 15
125 3 P Średni 8 16 8:02 16:03 15
126 3 Średni 7 15 7:01 15:07 15
127 3 Duży 7:30 15:30 7:25 15:25 15
128 3 P Średni 7 15 7:08 15:15 15
129 3 Średni 8 16 7:45 16:10 15
130 3 Średni 8 16 7:49 15:59 15
131 3 Średni 8 16 7:45 16:10 15
132 3 T Duży 7 15 7:07 15:20 15
133 3 Średni 7 15 7:02 15:11 15
134 3 Średni 8 16 8:06 15:49 15
135 3 P Średni 7 15 7:24 16:40 15
136 3 Średni 8 16 8:02 16:05 15
137 3 Duży 8 16 8:05 16:01 15
138 3 T Średni 7 15 7:13 15:13 15
139 3 Średni 8 16 7:36 16:00 15
140 3 T Średni 7 15 6:55 15:11 15
141 3 Średni 9 17 9:09 17:14 15

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a0c5faf62b0aec144841274fbf661fa5
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
namespace Parking namespace Parking
@ -18,6 +19,9 @@ namespace Parking
var counter = 0; var counter = 0;
foreach (var line in lines) foreach (var line in lines)
{ {
if(line == "")
continue;
if (counter == 0) if (counter == 0)
{ {
counter++; counter++;
@ -27,11 +31,11 @@ namespace Parking
var lineData = line.Trim().Split(','); var lineData = line.Trim().Split(',');
var preference = lineData[0] == "" var preference = lineData[0] == ""
? ParkingPreference.Any ? ParkingPreference.Any
: lineData[0] == "P" : lineData[1] == "P"
? ParkingPreference.Front ? ParkingPreference.Front
: ParkingPreference.Back; : ParkingPreference.Back;
Size size; Size size;
switch (lineData[1]) switch (lineData[2])
{ {
case "Mały": case "Mały":
size = Size.A; size = Size.A;
@ -50,11 +54,19 @@ namespace Parking
break; break;
} }
DateTime realArrival = DateTime.Parse(lineData[4].Contains(':') ? lineData[4] : lineData[4] + ":00", CultureInfo.InvariantCulture); DateTime realArrival = DateTime.Parse(lineData[5].Contains(':') ? lineData[5] : lineData[5] + ":00", CultureInfo.InvariantCulture);
DateTime realDeparture = DateTime.Parse(lineData[5].Contains(':') ? lineData[5] : lineData[5] + ":00", CultureInfo.InvariantCulture); DateTime realDeparture = DateTime.Parse(lineData[6].Contains(':') ? lineData[6] : lineData[6] + ":00", CultureInfo.InvariantCulture);
DateTime plannedArrival = DateTime.Parse(lineData[3].Contains(':') ? lineData[3] : lineData[3] + ":00", CultureInfo.InvariantCulture);
DateTime plannedDeparture = DateTime.Parse(lineData[4].Contains(':') ? lineData[4] : lineData[4] + ":00", CultureInfo.InvariantCulture);
Driver driver = new Driver(size, counter, preference); if (!Int32.TryParse(lineData[0], out var priority))
driver.Times = new[] {realArrival, realDeparture}; priority = 3;
if (!Int32.TryParse(lineData[7], out var updateInterval))
updateInterval = 3;
Driver driver = new Driver(size, counter, preference, priority, updateInterval);
driver.Times = new[] {plannedArrival, plannedDeparture, realArrival, realDeparture};
Drivers.Add(driver); Drivers.Add(driver);
counter++; counter++;

View File

@ -14,12 +14,16 @@ namespace Parking
public bool Parked = false; public bool Parked = false;
public GameObject GameObject; public GameObject GameObject;
public bool Rejected = false; public bool Rejected = false;
public int Priority;
public int UpdateInterval;
public Driver(Size size, int number, ParkingPreference parkingPreference) public Driver(Size size, int number, ParkingPreference parkingPreference, int priority, int updateInterval)
{ {
Size = size; Size = size;
Number = number; Number = number;
ParkingPreference = parkingPreference; ParkingPreference = parkingPreference;
Priority = priority;
UpdateInterval = updateInterval;
} }
public void Reset() public void Reset()
@ -41,7 +45,7 @@ namespace Parking
public GameObject GameObject; public GameObject GameObject;
public bool Free = true; public bool Free = true;
public bool Reserved = false; public bool Reserved = false;
public Driver ReservedDriver = null; public int ReservedPriority = 0;
public ParkingPreference ParkingDirection = ParkingPreference.Any; public ParkingPreference ParkingDirection = ParkingPreference.Any;
public Spot(Size size, bool flipped) public Spot(Size size, bool flipped)
@ -50,6 +54,10 @@ namespace Parking
Flipped = flipped; Flipped = flipped;
} }
public Spot()
{
}
public int CompareTo(Spot obj) public int CompareTo(Spot obj)
{ {
return Size.CompareTo(obj.Size); return Size.CompareTo(obj.Size);

View File

@ -51,9 +51,9 @@ namespace Parking
// counts[(int) Size.D] += 1; // counts[(int) Size.D] += 1;
var fixedCarSpots = 0; var fixedCarSpots = 0;
foreach (var c in counts) fixedCarSpots += c; foreach (var c in counts) fixedCarSpots += c;
Debug.Log($"Fixed car spots: {fixedCarSpots}"); // Debug.Log($"Fixed car spots: {fixedCarSpots}");
Debug.Log("Calculating required spot counts..."); // Debug.Log("Calculating required spot counts...");
for (var i = 0; i < DataImporter.Drivers.Count && i + fixedCarSpots < carsToPlace; i++) for (var i = 0; i < DataImporter.Drivers.Count && i + fixedCarSpots < carsToPlace; i++)
counts[(int) DataImporter.Drivers[i].Size]++; counts[(int) DataImporter.Drivers[i].Size]++;
@ -63,7 +63,7 @@ namespace Parking
Debug.Log(countsString); Debug.Log(countsString);
Debug.Log("Printing top 5 combinations..."); // Debug.Log("Printing top 5 combinations...");
foreach (var comb in Combinations) foreach (var comb in Combinations)
{ {
var res = TestCombination(comb.ToArray(), spotCountsPerpendicular, spotCountsParallel, counts, var res = TestCombination(comb.ToArray(), spotCountsPerpendicular, spotCountsParallel, counts,
@ -77,7 +77,7 @@ namespace Parking
private void PreProcessCombinations(out int[] spotCountsPerpendicular, out int[,] spotCountsParallel) private void PreProcessCombinations(out int[] spotCountsPerpendicular, out int[,] spotCountsParallel)
{ {
Debug.Log("Calculating spot counts..."); // Debug.Log("Calculating spot counts...");
float[] spotLengthsParallel = {4f, 4.5f, 5f}; //, 7.5f}; float[] spotLengthsParallel = {4f, 4.5f, 5f}; //, 7.5f};
spotCountsPerpendicular = new[] {0, 0, 0, 0}; spotCountsPerpendicular = new[] {0, 0, 0, 0};
spotCountsPerpendicular[0] = Mathf.FloorToInt((ParkingManager.Width - 5.5f) / _spotWidth); spotCountsPerpendicular[0] = Mathf.FloorToInt((ParkingManager.Width - 5.5f) / _spotWidth);
@ -92,10 +92,10 @@ namespace Parking
for (var j = 0; j < spotLengthsParallel.Length; j++) for (var j = 0; j < spotLengthsParallel.Length; j++)
spotCountsParallel[3, j] = spotCountsParallel[3, j] =
Mathf.FloorToInt((ParkingManager.Width - 5.5f - 3.6f * 2 - 2.5f * 4) / spotLengthsParallel[j]); Mathf.FloorToInt((ParkingManager.Width - 5.5f - 3.6f * 2 - 2.5f * 4) / spotLengthsParallel[j]);
Debug.Log("" + // Debug.Log("" +
$"P1: {spotCountsPerpendicular[0]}/ P2: {spotCountsPerpendicular[1]} " + // $"P1: {spotCountsPerpendicular[0]}/ P2: {spotCountsPerpendicular[1]} " +
$"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " + // $"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " +
$"Sum: {spotCountsPerpendicular.Sum()}"); // $"Sum: {spotCountsPerpendicular.Sum()}");
Debug.Log("Generating combinations..."); Debug.Log("Generating combinations...");
int[] arr = {0, 1, 2, 3, 4}; int[] arr = {0, 1, 2, 3, 4};

View File

@ -13,6 +13,10 @@ namespace Parking
public static ParkingManager Instance; public static ParkingManager Instance;
private static readonly TimeSpan StartTime = TimeSpan.FromHours(5) + TimeSpan.FromMinutes(45);
private static readonly TimeSpan EndTime = TimeSpan.FromHours(17) + TimeSpan.FromMinutes(15);
private static TimeSpan _currentTime = StartTime;
[SerializeField] private int stepTime = 15; [SerializeField] private int stepTime = 15;
[SerializeField] private TextMeshProUGUI timeText; [SerializeField] private TextMeshProUGUI timeText;
[SerializeField] public TextMeshProUGUI countsText; [SerializeField] public TextMeshProUGUI countsText;
@ -25,14 +29,13 @@ namespace Parking
private readonly float[] _spotHeights = {3.5f, 4f, 5f, 7.5f}; private readonly float[] _spotHeights = {3.5f, 4f, 5f, 7.5f};
public readonly List<List<Spot>> SpotMap = new() private readonly List<List<Spot>> _spotMap = new()
{new List<Spot>(), new List<Spot>(), new List<Spot>(), new List<Spot>()}; {new List<Spot>(), new List<Spot>(), new List<Spot>(), new List<Spot>()};
private static readonly TimeSpan StartTime = TimeSpan.FromHours(5) + TimeSpan.FromMinutes(45); private int _initialConfigurationSpotCount;
private static readonly TimeSpan EndTime = TimeSpan.FromHours(17) + TimeSpan.FromMinutes(15);
private static TimeSpan _currentTime = StartTime;
private int[] _rejectedDrivers = {0, 0, 0, 0}; private int[] _rejectedDrivers = {0, 0, 0, 0};
private void Awake() private void Awake()
{ {
Instance = this; Instance = this;
@ -43,32 +46,58 @@ namespace Parking
timeText.text = _currentTime.ToString(); timeText.text = _currentTime.ToString();
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " + rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
$"Duże: {_rejectedDrivers[2]}"; $"Duże: {_rejectedDrivers[2]}";
DataImporter.ReadFile("Assets/Data/v1.csv"); DataImporter.ReadFile("Assets/Data/Tablica1.csv");
Debug.Log(DataImporter.Drivers);
InitialConfigurationGenerator generator = new(); InitialConfigurationGenerator generator = new();
ArrangeSpots(generator.FindSolution()); ArrangeSpots(generator.FindSolution());
ReserveInitialSpots();
}
private void ReserveInitialSpots()
{
for (var i = 0; i < Math.Min(DataImporter.Drivers.Count, _initialConfigurationSpotCount); i++) {
bool found = false;
// Find spot
for (var j = 3; j >= 0 && !found; j--)
foreach (Spot spot in _spotMap[j])
if (spot.Size == DataImporter.Drivers[i].Size && !spot.Reserved) {
spot.Reserved = true;
spot.ReservedPriority = DataImporter.Drivers[i].Priority;
found = true;
break;
}
}
// Find spot
for (var j = 3; j >= 0; j--)
foreach (Spot spot in _spotMap[j])
if (!spot.Reserved && spot.Size != Size.D)
Debug.Log("Spot not reserved");
} }
public void AdvanceTime() public void AdvanceTime()
{ {
// Update time
_currentTime += TimeSpan.FromMinutes(stepTime); _currentTime += TimeSpan.FromMinutes(stepTime);
if (_currentTime > EndTime) if (_currentTime > EndTime) {
{
_currentTime = StartTime; _currentTime = StartTime;
// TODO: Reset spot reservations
ResetDrivers(); ResetDrivers();
_rejectedDrivers = new int[]{0, 0,0 ,0}; _rejectedDrivers = new[] {0, 0, 0, 0};
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " + rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
$"Duże: {_rejectedDrivers[2]}"; $"Duże: {_rejectedDrivers[2]}";
timeText.text = _currentTime.ToString(); timeText.text = _currentTime.ToString();
return; return;
} }
timeText.text = _currentTime.ToString(); timeText.text = _currentTime.ToString();
foreach (Driver driver in DataImporter.Drivers)
if (_currentTime <= driver.Times[1].TimeOfDay && _currentTime > driver.Times[0].TimeOfDay &&
!driver.Parked && !driver.Rejected) foreach (Driver driver in DataImporter.Drivers) {
{ // TODO: Check if car can stay before other reservation
if (!PlaceCarOnParking(driver)) var triesToPark = _currentTime <= driver.Times[3].TimeOfDay && _currentTime > driver.Times[2].TimeOfDay;
{ var leftTheParking = _currentTime > driver.Times[3].TimeOfDay && driver.Parked;
if (triesToPark && !driver.Parked && !driver.Rejected) {
if (!PlaceCarOnParking(driver)) {
Debug.Log($"Placing failed for car {driver.Number}"); Debug.Log($"Placing failed for car {driver.Number}");
driver.Rejected = true; driver.Rejected = true;
_rejectedDrivers[(int) driver.Size]++; _rejectedDrivers[(int) driver.Size]++;
@ -76,64 +105,82 @@ namespace Parking
$"Duże: {_rejectedDrivers[2]}"; $"Duże: {_rejectedDrivers[2]}";
} }
} }
else if (_currentTime > driver.Times[1].TimeOfDay && else if (leftTheParking) {
driver.Parked) driver.Spot.Reserved = false;
{
driver.Reset(); driver.Reset();
} }
} }
}
private void ResetDrivers() private void ResetDrivers()
{ {
foreach (Driver driver in DataImporter.Drivers) foreach (Driver driver in DataImporter.Drivers)
{
driver.Reset(); driver.Reset();
} }
private bool FindReservedSpot(Driver driver, out Spot spot)
{
foreach (var list in _spotMap)
foreach (Spot spot1 in list)
if (spot1.Reserved && spot1.ReservedPriority == driver.Priority) {
spot = spot1;
return true;
}
spot = new Spot();
return false;
} }
private bool PlaceCarOnParking(Driver driver) private bool PlaceCarOnParking(Driver driver)
{ {
for (var i = 0; i < SpotMap.Count; i++) if (FindReservedSpot(driver, out Spot reservedSpot)) {
foreach (Spot spot in SpotMap[i]) if (reservedSpot.Free) {
if (spot.Size == driver.Size && spot.Free && PlaceDriverOnSpot(driver, reservedSpot);
(spot.ParkingDirection == driver.ParkingPreference ||
spot.ParkingDirection == ParkingPreference.Any))
{
spot.Free = false;
driver.Spot = spot;
driver.Parked = true;
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
driver.GameObject.transform.position = spot.GameObject.transform.position;
driver.GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
return true; return true;
} }
else
Debug.Log("Spot should be reserved but is taken");
}
for (var i = 0; i < SpotMap.Count; i++)
foreach (Spot spot in SpotMap[i])
if (spot.Size == driver.Size && spot.Free)
{
spot.Free = false;
driver.Spot = spot;
driver.Parked = true;
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
driver.GameObject.transform.position = spot.GameObject.transform.position;
driver.GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
foreach (var t in _spotMap)
foreach (Spot spot in t) {
var spotAvailable = spot.Size == driver.Size && spot.Free &&
(spot.ParkingDirection == driver.ParkingPreference ||
spot.ParkingDirection == ParkingPreference.Any)
&& !spot.Reserved;
if (spotAvailable) {
PlaceDriverOnSpot(driver, spot);
return true;
}
}
foreach (var t in _spotMap)
foreach (Spot spot in t)
if (spot.Size == driver.Size && spot.Free && !spot.Reserved) {
PlaceDriverOnSpot(driver, spot);
return true; return true;
} }
return false; return false;
} }
private void PlaceDriverOnSpot(Driver driver, Spot spot)
{
spot.Free = false;
spot.Reserved = false;
driver.Spot = spot;
driver.Parked = true;
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
driver.GameObject.transform.position = spot.GameObject.transform.position;
driver.GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
}
public void UpdateText(string text) public void UpdateText(string text)
{ {
countsText.text = text; countsText.text = text;
@ -141,28 +188,27 @@ namespace Parking
private void ReconfigureSpots() private void ReconfigureSpots()
{ {
int[] freeSpots = GetFreeSpotCount(); var freeSpots = GetFreeSpotCount();
List<Driver> nextCars = GetNextCars(10); var nextCars = GetNextCars(10);
int[] plannedSpots = new[] {0, 0, 0, 0}; int[] plannedSpots = {0, 0, 0, 0};
foreach (Driver driver in nextCars) foreach (Driver driver in nextCars)
plannedSpots[(int) driver.Size]++; plannedSpots[(int) driver.Size]++;
int[] neededSpots = new[] {0, 0, 0, 0}; int[] neededSpots = {0, 0, 0, 0};
for (int i = 0; i < neededSpots.Length; i++) for (var i = 0; i < neededSpots.Length; i++)
neededSpots[i] = Math.Max(freeSpots[i] - plannedSpots[i], 0); neededSpots[i] = Math.Max(freeSpots[i] - plannedSpots[i], 0);
if (neededSpots.Max() > 0) if (neededSpots.Max() > 0) {
{
Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}"); Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}");
Debug.Log($"Attempting reconfiguration..."); Debug.Log("Attempting reconfiguration...");
} }
} }
private int[] GetFreeSpotCount() private int[] GetFreeSpotCount()
{ {
int[] freeSpots = new[] {0, 0, 0, 0}; int[] freeSpots = {0, 0, 0, 0};
foreach (var t in SpotMap) foreach (var t in _spotMap)
foreach (Spot spot in t) foreach (Spot spot in t)
if (spot.Free) if (spot.Free)
freeSpots[(int) spot.Size]++; freeSpots[(int) spot.Size]++;
@ -171,17 +217,14 @@ namespace Parking
private List<Driver> GetNextCars(int n) private List<Driver> GetNextCars(int n)
{ {
List<Driver> nextCars = new List<Driver>(); var nextCars = new List<Driver>();
TimeSpan updatedTime = _currentTime + TimeSpan.FromMinutes(stepTime); TimeSpan updatedTime = _currentTime + TimeSpan.FromMinutes(stepTime);
while (nextCars.Count < n && updatedTime < EndTime) while (nextCars.Count < n && updatedTime < EndTime) {
{
foreach (Driver driver in DataImporter.Drivers) foreach (Driver driver in DataImporter.Drivers)
if (_currentTime + updatedTime <= driver.Times[1].TimeOfDay && if (_currentTime + updatedTime <= driver.Times[3].TimeOfDay &&
_currentTime > driver.Times[0].TimeOfDay && _currentTime > driver.Times[2].TimeOfDay &&
!driver.Parked && !driver.Rejected && !nextCars.Contains(driver)) !driver.Parked && !driver.Rejected && !nextCars.Contains(driver))
{
nextCars.Add(driver); nextCars.Add(driver);
}
updatedTime += TimeSpan.FromMinutes(stepTime); updatedTime += TimeSpan.FromMinutes(stepTime);
} }
@ -195,11 +238,9 @@ namespace Parking
var maxP3 = _spotHeights[(int) spotMap[2].Max().Size]; var maxP3 = _spotHeights[(int) spotMap[2].Max().Size];
var maxP2 = _spotHeights[(int) spotMap[1].Max().Size]; var maxP2 = _spotHeights[(int) spotMap[1].Max().Size];
for (var i = 0; i < 4; i++) for (var i = 0; i < 4; i++) {
{
float currentY; float currentY;
switch (i) switch (i) {
{
case 0: case 0:
currentY = -Height / 2.0f + 2f; currentY = -Height / 2.0f + 2f;
break; break;
@ -224,12 +265,10 @@ namespace Parking
var flipped = false; var flipped = false;
var parkingFromTop = i % 2 != 0; var parkingFromTop = i % 2 != 0;
for (var j = 0; j < spotMap[i].Count; j++) for (var j = 0; j < spotMap[i].Count; j++) {
{
spotMap[i][j].Flipped = flipped; spotMap[i][j].Flipped = flipped;
var alignTop = i % 2 != 0; var alignTop = i % 2 != 0;
switch (spotMap[i][j].Size) switch (spotMap[i][j].Size) {
{
case Size.A: case Size.A:
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA); spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA);
spotMap[i][j].GameObject.transform.position = new Vector3(currentX, currentY, 0); spotMap[i][j].GameObject.transform.position = new Vector3(currentX, currentY, 0);
@ -268,15 +307,17 @@ namespace Parking
{ {
for (var i = 0; i < 4; i++) for (var i = 0; i < 4; i++)
for (var j = 0; j < spotsCreated.GetLength(1); j++) for (var j = 0; j < spotsCreated.GetLength(1); j++)
for (var k = 0; k < spotsCreated[i, j]; k++) for (var k = 0; k < spotsCreated[i, j]; k++) {
SpotMap[i].Add(new Spot((Size) j, false)); _spotMap[i].Add(new Spot((Size) j, false));
_initialConfigurationSpotCount++;
}
SpotMap[0].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort _spotMap[0].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
SpotMap[1].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort _spotMap[1].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
SpotMap[2].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort _spotMap[2].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
SpotMap[3].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort _spotMap[3].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
SpotMap[2].Add(new Spot(Size.D, false)); _spotMap[2].Add(new Spot(Size.D, false));
return SpotMap; return _spotMap;
} }
} }
} }