dancealgorithm 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dancealgorithm/__init__.py +12 -9
- dancealgorithm/__main__.py +1 -0
- dancealgorithm/assignments/DA - Campus/__init__.py +4 -0
- dancealgorithm/assignments/DA - Flight/__init__.py +4 -0
- dancealgorithm/assignments/DA - Smart/__init__.py +4 -0
- dancealgorithm/assignments/FK - Advertisement/__init__.py +4 -0
- dancealgorithm/assignments/FK - Electric/__init__.py +4 -0
- dancealgorithm/assignments/FK - Emergency/__init__.py +4 -0
- dancealgorithm/assignments/GC - Classroom/Solution.java +119 -87
- dancealgorithm/assignments/GC - Classroom/__init__.py +4 -0
- dancealgorithm/assignments/GC - Interference/Solution.java +120 -88
- dancealgorithm/assignments/GC - Interference/__init__.py +4 -0
- dancealgorithm/assignments/GC - University/Solution.java +119 -88
- dancealgorithm/assignments/GC - University/__init__.py +4 -0
- dancealgorithm/assignments/K - Cloud/__init__.py +4 -0
- dancealgorithm/assignments/K - Disaster/__init__.py +4 -0
- dancealgorithm/assignments/K - Hospital/__init__.py +4 -0
- dancealgorithm/assignments/LC - Delivery/Solution.java +261 -180
- dancealgorithm/assignments/LC - Delivery/__init__.py +4 -0
- dancealgorithm/assignments/LC - Drilling/Solution.java +275 -197
- dancealgorithm/assignments/LC - Drilling/__init__.py +4 -0
- dancealgorithm/assignments/LC - Flight/Solution.java +261 -180
- dancealgorithm/assignments/LC - Flight/__init__.py +4 -0
- dancealgorithm/assignments/MS - Commerce/__init__.py +4 -0
- dancealgorithm/assignments/MS - Customer/__init__.py +4 -0
- dancealgorithm/assignments/MS - Library/__init__.py +4 -0
- dancealgorithm/assignments/MSG - Emergency/__init__.py +4 -0
- dancealgorithm/assignments/MSG - Logistics/__init__.py +4 -0
- dancealgorithm/assignments/MSG - Skyconnect/__init__.py +4 -0
- dancealgorithm/assignments/QS - Commerce/__init__.py +4 -0
- dancealgorithm/assignments/QS - Movie/__init__.py +4 -0
- dancealgorithm/assignments/QS - Online/__init__.py +4 -0
- dancealgorithm/assignments/__init__.py +25 -25
- dancealgorithm/downloader.py +7 -6
- {dancealgorithm-0.1.0.dist-info → dancealgorithm-0.1.2.dist-info}/METADATA +22 -19
- {dancealgorithm-0.1.0.dist-info → dancealgorithm-0.1.2.dist-info}/RECORD +40 -40
- {dancealgorithm-0.1.0.dist-info → dancealgorithm-0.1.2.dist-info}/WHEEL +0 -0
- {dancealgorithm-0.1.0.dist-info → dancealgorithm-0.1.2.dist-info}/entry_points.txt +0 -0
- {dancealgorithm-0.1.0.dist-info → dancealgorithm-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {dancealgorithm-0.1.0.dist-info → dancealgorithm-0.1.2.dist-info}/top_level.txt +0 -0
dancealgorithm/__init__.py
CHANGED
|
@@ -9,7 +9,7 @@ import sys
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from typing import Any, Dict, List, Optional, Union
|
|
11
11
|
|
|
12
|
-
__version__ = "0.1.
|
|
12
|
+
__version__ = "0.1.2"
|
|
13
13
|
|
|
14
14
|
# Import bundled assignments registry and sheets
|
|
15
15
|
from dancealgorithm.assignments import ASSIGNMENTS_DIR, REGISTRY, SHEETS
|
|
@@ -34,8 +34,8 @@ for sheet in SHEETS:
|
|
|
34
34
|
|
|
35
35
|
def get(identifier: Union[int, str]) -> Any:
|
|
36
36
|
"""
|
|
37
|
-
Get a specific problem sheet module by number (1..
|
|
38
|
-
or keyword/name (e.g. 'Customer', 'MS - Customer', '
|
|
37
|
+
Get a specific problem sheet module by number (1..18), ID (e.g. 'ps1', 'PS01'),
|
|
38
|
+
or keyword/name (e.g. 'Customer', 'MS - Customer', 'MSG - Logistics').
|
|
39
39
|
"""
|
|
40
40
|
if identifier in REGISTRY:
|
|
41
41
|
return REGISTRY[identifier]
|
|
@@ -57,7 +57,7 @@ def get(identifier: Union[int, str]) -> Any:
|
|
|
57
57
|
if norm in clean_title or clean_title in norm:
|
|
58
58
|
return sheet
|
|
59
59
|
|
|
60
|
-
raise KeyError(f"Problem sheet not found for '{identifier}'. Available: 1..
|
|
60
|
+
raise KeyError(f"Problem sheet not found for '{identifier}'. Available: 1..18.")
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
# Convenience alias: dancealgorithm.ps(1)
|
|
@@ -86,7 +86,7 @@ def extract(
|
|
|
86
86
|
) -> List[Path]:
|
|
87
87
|
"""
|
|
88
88
|
Extract all problem sheets or a specific one to the destination directory.
|
|
89
|
-
Default destination is C:\\DAA_Assignments (or ~/DAA_Assignments).
|
|
89
|
+
Default destination is C:\\DAA_Assignments on Windows (or ~/DAA_Assignments on Linux).
|
|
90
90
|
"""
|
|
91
91
|
from dancealgorithm.config import get_destination
|
|
92
92
|
from dancealgorithm.downloader import extract_bundled
|
|
@@ -98,13 +98,18 @@ def extract(
|
|
|
98
98
|
|
|
99
99
|
def open_folder(destination: Optional[Union[str, Path]] = None) -> None:
|
|
100
100
|
"""
|
|
101
|
-
Open the assignments destination folder in
|
|
101
|
+
Open the assignments destination folder in the default system file manager.
|
|
102
|
+
Works seamlessly on Windows (explorer), macOS (open), and Linux (xdg-open).
|
|
102
103
|
"""
|
|
103
104
|
from dancealgorithm.config import get_destination
|
|
104
105
|
target = Path(destination) if destination else get_destination()
|
|
105
106
|
target.mkdir(parents=True, exist_ok=True)
|
|
106
107
|
if sys.platform == "win32":
|
|
107
108
|
os.system(f'explorer "{target}"')
|
|
109
|
+
elif sys.platform == "darwin":
|
|
110
|
+
os.system(f'open "{target}"')
|
|
111
|
+
else:
|
|
112
|
+
os.system(f'xdg-open "{target}" 2>/dev/null &')
|
|
108
113
|
|
|
109
114
|
|
|
110
115
|
def __getattr__(name: str) -> Any:
|
|
@@ -123,6 +128,4 @@ __all__ = [
|
|
|
123
128
|
"extract",
|
|
124
129
|
"open_folder",
|
|
125
130
|
]
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
|
dancealgorithm/__main__.py
CHANGED
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -1,87 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
public class Solution {
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
public class Solution {
|
|
5
|
+
// 1. Main Function
|
|
6
|
+
public static void main(String args[]) {
|
|
7
|
+
Scanner sc = new Scanner(System.in);
|
|
8
|
+
|
|
9
|
+
System.out.print("Enter number of lectures: ");
|
|
10
|
+
int iSize = sc.nextInt();
|
|
11
|
+
|
|
12
|
+
String sLectures[] = new String[iSize];
|
|
13
|
+
|
|
14
|
+
// 2. Get Lecture Details
|
|
15
|
+
sc.nextLine();
|
|
16
|
+
|
|
17
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
18
|
+
System.out.print("Enter lecture " + (iCnt + 1) + ": ");
|
|
19
|
+
sLectures[iCnt] = sc.nextLine();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 3. Create Conflict Graph
|
|
23
|
+
int iGraph[][] = new int[iSize][iSize];
|
|
24
|
+
|
|
25
|
+
System.out.print("Enter number of conflict pairs: ");
|
|
26
|
+
int iPairs = sc.nextInt();
|
|
27
|
+
|
|
28
|
+
for (int iCnt = 0; iCnt < iPairs; iCnt++) {
|
|
29
|
+
System.out.println("\nEnter lecture numbers for conflict pair " + (iCnt + 1));
|
|
30
|
+
|
|
31
|
+
System.out.print("First lecture: ");
|
|
32
|
+
int iU = sc.nextInt() - 1;
|
|
33
|
+
|
|
34
|
+
System.out.print("Second lecture: ");
|
|
35
|
+
int iV = sc.nextInt() - 1;
|
|
36
|
+
|
|
37
|
+
if (iU >= 0 && iU < iSize && iV >= 0 &&
|
|
38
|
+
iV < iSize && iU != iV) {
|
|
39
|
+
iGraph[iU][iV] = 1;
|
|
40
|
+
iGraph[iV][iU] = 1;
|
|
41
|
+
} else {
|
|
42
|
+
System.out.println("Invalid lecture numbers!");
|
|
43
|
+
iCnt--;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 4. Get Available Classrooms
|
|
48
|
+
System.out.print("\nEnter available classrooms: ");
|
|
49
|
+
int iRooms = sc.nextInt();
|
|
50
|
+
|
|
51
|
+
// 5. Apply Graph Coloring
|
|
52
|
+
ClassroomScheduler(iGraph, iRooms, sLectures);
|
|
53
|
+
|
|
54
|
+
sc.close();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 6. Check Whether Color Is Safe
|
|
58
|
+
static boolean IsSafe(int iV, int iGraph[][],
|
|
59
|
+
int iColor[], int iC, int iSize) {
|
|
60
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
61
|
+
if (iGraph[iV][iCnt] == 1 && iColor[iCnt] == iC) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 7. Graph Coloring Using Backtracking
|
|
70
|
+
static boolean GraphColoring(int iGraph[][], int iRooms,
|
|
71
|
+
int iColor[], int iV, int iSize) {
|
|
72
|
+
if (iV == iSize) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (int iC = 1; iC <= iRooms; iC++) {
|
|
77
|
+
if (IsSafe(iV, iGraph, iColor, iC, iSize)) {
|
|
78
|
+
iColor[iV] = iC;
|
|
79
|
+
|
|
80
|
+
if (GraphColoring(iGraph, iRooms, iColor,
|
|
81
|
+
iV + 1, iSize)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Backtrack
|
|
86
|
+
iColor[iV] = 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 8. Classroom Scheduler
|
|
94
|
+
static void ClassroomScheduler(int iGraph[][],
|
|
95
|
+
int iRooms, String sLectures[]) {
|
|
96
|
+
int iSize = sLectures.length;
|
|
97
|
+
int iColor[] = new int[iSize];
|
|
98
|
+
|
|
99
|
+
System.out.println("\nClassroom Allocation:");
|
|
100
|
+
System.out.println("------------------------------------------------");
|
|
101
|
+
|
|
102
|
+
if (!GraphColoring(iGraph, iRooms, iColor, 0, iSize)) {
|
|
103
|
+
System.out.println("Cannot schedule all lectures without conflicts!");
|
|
104
|
+
} else {
|
|
105
|
+
System.out.printf("%-35s %-20s%n",
|
|
106
|
+
"Lecture Session", "Allocated Classroom");
|
|
107
|
+
|
|
108
|
+
System.out.println("------------------------------------------------");
|
|
109
|
+
|
|
110
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
111
|
+
System.out.printf("%-35s Room Hall %d%n",
|
|
112
|
+
sLectures[iCnt], iColor[iCnt]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
System.out.println("------------------------------------------------");
|
|
116
|
+
System.out.println("Status: All lectures scheduled without conflicts.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|
|
@@ -1,88 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
public class Solution {
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
int
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
public class Solution {
|
|
5
|
+
// 1. Main Function
|
|
6
|
+
public static void main(String args[]) {
|
|
7
|
+
Scanner sc = new Scanner(System.in);
|
|
8
|
+
|
|
9
|
+
System.out.print("Enter number of towers: ");
|
|
10
|
+
int iSize = sc.nextInt();
|
|
11
|
+
|
|
12
|
+
String sTowers[] = new String[iSize];
|
|
13
|
+
|
|
14
|
+
// 2. Get Tower Names
|
|
15
|
+
sc.nextLine();
|
|
16
|
+
|
|
17
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
18
|
+
System.out.print("Enter tower " + (iCnt + 1) + ": ");
|
|
19
|
+
sTowers[iCnt] = sc.nextLine();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 3. Create Interference Graph
|
|
23
|
+
int iGraph[][] = new int[iSize][iSize];
|
|
24
|
+
|
|
25
|
+
System.out.print("Enter number of interference pairs: ");
|
|
26
|
+
int iPairs = sc.nextInt();
|
|
27
|
+
|
|
28
|
+
for (int iCnt = 0; iCnt < iPairs; iCnt++) {
|
|
29
|
+
System.out.println("\nEnter tower numbers for interference pair " + (iCnt + 1));
|
|
30
|
+
|
|
31
|
+
System.out.print("First tower: ");
|
|
32
|
+
int iU = sc.nextInt() - 1;
|
|
33
|
+
|
|
34
|
+
System.out.print("Second tower: ");
|
|
35
|
+
int iV = sc.nextInt() - 1;
|
|
36
|
+
|
|
37
|
+
if (iU >= 0 && iU < iSize && iV >= 0 &&
|
|
38
|
+
iV < iSize && iU != iV) {
|
|
39
|
+
iGraph[iU][iV] = 1;
|
|
40
|
+
iGraph[iV][iU] = 1;
|
|
41
|
+
} else {
|
|
42
|
+
System.out.println("Invalid tower numbers!");
|
|
43
|
+
iCnt--;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 4. Get Available Frequency Channels
|
|
48
|
+
System.out.print("\nEnter available frequency channels: ");
|
|
49
|
+
int iChannels = sc.nextInt();
|
|
50
|
+
|
|
51
|
+
// 5. Apply Graph Coloring
|
|
52
|
+
FrequencyAllocator(iGraph, iChannels, sTowers);
|
|
53
|
+
|
|
54
|
+
sc.close();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 6. Check Whether Color Is Safe
|
|
58
|
+
static boolean IsSafe(int iV, int iGraph[][],
|
|
59
|
+
int iColor[], int iC, int iSize) {
|
|
60
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
61
|
+
if (iGraph[iV][iCnt] == 1 && iColor[iCnt] == iC) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 7. Graph Coloring Using Backtracking
|
|
70
|
+
static boolean GraphColoring(int iGraph[][], int iChannels,
|
|
71
|
+
int iColor[], int iV, int iSize) {
|
|
72
|
+
if (iV == iSize) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (int iC = 1; iC <= iChannels; iC++) {
|
|
77
|
+
if (IsSafe(iV, iGraph, iColor, iC, iSize)) {
|
|
78
|
+
iColor[iV] = iC;
|
|
79
|
+
|
|
80
|
+
if (GraphColoring(iGraph, iChannels, iColor,
|
|
81
|
+
iV + 1, iSize)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Backtrack
|
|
86
|
+
iColor[iV] = 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 8. Frequency Allocator
|
|
94
|
+
static void FrequencyAllocator(int iGraph[][],
|
|
95
|
+
int iChannels, String sTowers[]) {
|
|
96
|
+
int iSize = sTowers.length;
|
|
97
|
+
int iColor[] = new int[iSize];
|
|
98
|
+
|
|
99
|
+
System.out.println("\nCellular Network Frequency Allocation:");
|
|
100
|
+
System.out.println("---------------------------------------------------------------");
|
|
101
|
+
|
|
102
|
+
if (!GraphColoring(iGraph, iChannels, iColor, 0, iSize)) {
|
|
103
|
+
System.out.println("Cannot allocate frequencies without interference!");
|
|
104
|
+
} else {
|
|
105
|
+
System.out.printf("%-28s %-20s%n",
|
|
106
|
+
"Cellular Tower", "Frequency Channel");
|
|
107
|
+
|
|
108
|
+
System.out.println("---------------------------------------------------------------");
|
|
109
|
+
|
|
110
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
111
|
+
System.out.printf("%-28s Channel %d (Band %d MHz)%n",
|
|
112
|
+
sTowers[iCnt], iColor[iCnt],
|
|
113
|
+
800 + iColor[iCnt] * 50);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
System.out.println("---------------------------------------------------------------");
|
|
117
|
+
System.out.println("Status: All towers allocated without interference.");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -25,6 +25,10 @@ def open_folder() -> None:
|
|
|
25
25
|
import os
|
|
26
26
|
if sys.platform == "win32":
|
|
27
27
|
os.system(f'explorer "{PATH}"')
|
|
28
|
+
elif sys.platform == "darwin":
|
|
29
|
+
os.system(f'open "{PATH}"')
|
|
30
|
+
else:
|
|
31
|
+
os.system(f'xdg-open "{PATH}" 2>/dev/null &')
|
|
28
32
|
|
|
29
33
|
def __getattr__(name: str):
|
|
30
34
|
if name in ("code", "java_code", "solution_code"):
|