diff --git a/Assets/Data/.~lock.Tablica1.csv# b/Assets/Data/.~lock.Tablica1.csv# new file mode 100644 index 0000000..e5d1df5 --- /dev/null +++ b/Assets/Data/.~lock.Tablica1.csv# @@ -0,0 +1 @@ +,davp,arch-desktop,04.09.2022 23:00,file:///home/davp/.config/libreoffice/4; \ No newline at end of file diff --git a/Assets/Scripts/InitialConfigurationGenerator.cs b/Assets/Scripts/InitialConfigurationGenerator.cs index 803748c..cdbb4e8 100644 --- a/Assets/Scripts/InitialConfigurationGenerator.cs +++ b/Assets/Scripts/InitialConfigurationGenerator.cs @@ -17,16 +17,16 @@ namespace Parking var spotsCreated = new int[4, 4]; - var count = 100; + var count = 77; - var maxCount = 0; + var maxCount = count; if (PlaceNCars(count, spotCountsPerpendicular, spotCountsParallel, spotsCreated)) { count++; while (PlaceNCars(count, spotCountsPerpendicular, spotCountsParallel, spotsCreated)) count++; - maxCount = count--; + maxCount = count - 1; } else { @@ -38,6 +38,19 @@ namespace Parking Debug.Log($"Best solution count {maxCount}"); + int[] counts = new int[] {0, 0, 0, 0}; + for (int i = 0; i < spotsCreated.GetLength(0); i++) { + for (int j = 0; j < spotsCreated.GetLength(1); j++) { + counts[j] += spotsCreated[i, j]; + } + } + + var countsString = $"Małe: {counts[0]} Średnie: {counts[1]} Duże: {counts[2]} " + + $"Suma: {counts.Sum()}"; + ParkingManager.Instance.UpdateText(countsString); + Debug.Log(countsString); + + return spotsCreated; } @@ -54,11 +67,34 @@ namespace Parking // Debug.Log($"Fixed car spots: {fixedCarSpots}"); // Debug.Log("Calculating required spot counts..."); + int maxI = 0; + List driversLowerPrioritySorted = new List(DataImporter.Drivers.Count); for (var i = 0; i < DataImporter.Drivers.Count && i + fixedCarSpots < carsToPlace; i++) - counts[(int) DataImporter.Drivers[i].Size]++; + if (DataImporter.Drivers[i].Priority == 1) { + counts[(int) DataImporter.Drivers[i].Size]++; + maxI = i; + } + + foreach (Driver driver in DataImporter.Drivers) + if(driver.Priority != 1) + driversLowerPrioritySorted.Add(driver); + + for(int i = maxI + 1; counts[(int) Size.C] < 20 && i < DataImporter.Drivers.Count; i++) + if (DataImporter.Drivers[i].Size == Size.C) { + counts[(int) DataImporter.Drivers[i].Size]++; + driversLowerPrioritySorted.Remove(DataImporter.Drivers[i]); + } + + driversLowerPrioritySorted.Sort(BiggerSizeComparator); + + int singlePriorityCars = counts.Sum(); + for (var i = 0; i < driversLowerPrioritySorted.Count && i + fixedCarSpots + singlePriorityCars < carsToPlace; i++) + counts[(int) driversLowerPrioritySorted[i].Size]++; + + var countsString = $"Małe: {counts[0]} Średnie: {counts[1]} Duże: {counts[2]} " + - $"Suma: {counts.Sum()}"; + $"Suma: {counts.Sum() + 1}"; ParkingManager.Instance.UpdateText(countsString); Debug.Log(countsString); @@ -114,9 +150,11 @@ namespace Parking var sizes = sizeIds.Select(x => AvailableSizesCombinations[x]).ToArray(); // Debug.Log($"Testing: {sizes[0]} {sizes[1]} {sizes[2]} {sizes[3]} sum: {sizes.Sum()}"); - for (var i = 0; i < spotsCreated.GetLength(0); i++) - for (var j = 0; j < spotsCreated.GetLength(1); j++) - spotsCreated[i, j] = 0; + var spotsCreatedTemp = new int[4, 4]; + + for (var i = 0; i < spotsCreatedTemp.GetLength(0); i++) + for (var j = 0; j < spotsCreatedTemp.GetLength(1); j++) + spotsCreatedTemp[i, j] = 0; var requiredCounts = new int[requiredCountsRef.Length]; requiredCountsRef.CopyTo((Span) requiredCounts); @@ -143,7 +181,7 @@ namespace Parking spotCountsPerpendicular[laneId] -= spotsTaken; requiredCounts[spotSize] -= spotsTaken; - spotsCreated[laneId, spotSize] += spotsTaken; + spotsCreatedTemp[laneId, spotSize] += spotsTaken; // TODO: Allow mixed configuration for (var x = 0; x < 3; x++) @@ -155,7 +193,7 @@ namespace Parking // spotCountsParallel[laneId, spotSize] -= spotsTaken; // requiredCounts[spotSize] -= spotsTaken; // - // spotsCreated[laneId, spotSize] += spotsTaken; + // spotsCreatedTemp[laneId, spotSize] += spotsTaken; // // // TODO: Allow mixed configuration // spotCountsPerpendicular[laneId] = 0; @@ -170,6 +208,26 @@ namespace Parking var sum = requiredCounts.Sum(); if (sum > 0) return false; + + + for (var laneId = 3; laneId >= 0; laneId--) { + if (spotCountsPerpendicular[laneId] != 0) { + if (sizeIds[laneId] == 0) { + // empty + } + else if (sizeIds[laneId] == 1) { + // parallel only + } + else { + spotsCreatedTemp[laneId, 0] += spotCountsPerpendicular[laneId]; + spotCountsPerpendicular[laneId] = 0; + } + } + } + + for (var i = 0; i < spotsCreatedTemp.GetLength(0); i++) + for (var j = 0; j < spotsCreatedTemp.GetLength(1); j++) + spotsCreated[i, j] = spotsCreatedTemp[i, j]; return true; } @@ -183,6 +241,14 @@ namespace Parking return -1 * sum1.CompareTo(sum2); } + + private int BiggerSizeComparator(Driver d1, Driver d2) + { + int sizeComp = d1.Size.CompareTo(d2.Size); + if (sizeComp == 0) + return d1.Priority.CompareTo(d2.Priority); + return sizeComp; + } private void CombinationRepetitionUtil(int[] chosen, int[] arr, int index, int r, int start, int end) @@ -192,7 +258,7 @@ namespace Parking // combinations.Add(new[] {arr[chosen[0]]}); var tempArr = new List(r); for (var i = 0; i < r; i++) tempArr.Add(arr[chosen[i]]); - var hasEnoughSpace = tempArr.Select(x => AvailableSizesCombinations[x]).Sum() < + var hasEnoughSpace = tempArr.Select(x => AvailableSizesCombinations[x]).Sum() <= ParkingManager.Height - 11; var contains5 = tempArr.Contains(4); tempArr.Sort(); diff --git a/Assets/Scripts/ParkingManager.cs b/Assets/Scripts/ParkingManager.cs index a4a23e2..1d13306 100644 --- a/Assets/Scripts/ParkingManager.cs +++ b/Assets/Scripts/ParkingManager.cs @@ -269,8 +269,8 @@ namespace Parking { var spotMap = GenerateSpotMap(spotsCreated); - var maxP3 = _spotHeights[(int) spotMap[2].Max().Size]; - var maxP2 = _spotHeights[(int) spotMap[1].Max().Size]; + var maxP3 = spotMap[2].Count == 0 ? 0 : _spotHeights[(int) spotMap[2].Max().Size]; + var maxP2 = spotMap[1].Count == 0 ? 0 : _spotHeights[(int) spotMap[1].Max().Size]; for (var i = 0; i < 4; i++) { float currentY;