dancealgorithm 0.1.1__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 +3 -3
- dancealgorithm/assignments/GC - Classroom/Solution.java +119 -0
- dancealgorithm/assignments/GC - Classroom/__init__.py +38 -0
- dancealgorithm/assignments/GC - Interference/Solution.java +120 -0
- dancealgorithm/assignments/GC - Interference/__init__.py +38 -0
- dancealgorithm/assignments/GC - University/Solution.java +119 -0
- dancealgorithm/assignments/GC - University/__init__.py +38 -0
- dancealgorithm/assignments/GC.txt +25 -0
- dancealgorithm/assignments/LC - Delivery/Solution.java +261 -0
- dancealgorithm/assignments/LC - Delivery/__init__.py +38 -0
- dancealgorithm/assignments/LC - Drilling/Solution.java +275 -0
- dancealgorithm/assignments/LC - Drilling/__init__.py +38 -0
- dancealgorithm/assignments/LC - Flight/Solution.java +261 -0
- dancealgorithm/assignments/LC - Flight/__init__.py +38 -0
- dancealgorithm/assignments/LC.txt +31 -0
- dancealgorithm/assignments/__init__.py +7 -1
- dancealgorithm/downloader.py +8 -1
- {dancealgorithm-0.1.1.dist-info → dancealgorithm-0.1.2.dist-info}/METADATA +26 -11
- {dancealgorithm-0.1.1.dist-info → dancealgorithm-0.1.2.dist-info}/RECORD +23 -9
- {dancealgorithm-0.1.1.dist-info → dancealgorithm-0.1.2.dist-info}/WHEEL +0 -0
- {dancealgorithm-0.1.1.dist-info → dancealgorithm-0.1.2.dist-info}/entry_points.txt +0 -0
- {dancealgorithm-0.1.1.dist-info → dancealgorithm-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {dancealgorithm-0.1.1.dist-info → dancealgorithm-0.1.2.dist-info}/top_level.txt +0 -0
dancealgorithm/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""
|
|
2
2
|
DanceAlgorithm - Instant DAA Algorithms, Lab Problem Sheets, Datasets & Code Vault.
|
|
3
|
-
All
|
|
3
|
+
All 24 Practical Exam Problem Sheets & Algorithm Notes Bundled & Instantly Importable.
|
|
4
4
|
"""
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
@@ -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
|
|
@@ -128,4 +128,4 @@ __all__ = [
|
|
|
128
128
|
"extract",
|
|
129
129
|
"open_folder",
|
|
130
130
|
]
|
|
131
|
-
|
|
131
|
+
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
PATH = Path(__file__).resolve().parent
|
|
7
|
+
DIR = PATH
|
|
8
|
+
JAVA_SOLUTION = PATH / "Solution.java"
|
|
9
|
+
DATASET_PATH = PATH / "dataset.csv"
|
|
10
|
+
TITLE = "GC - Classroom"
|
|
11
|
+
|
|
12
|
+
def get_code() -> str:
|
|
13
|
+
if JAVA_SOLUTION.exists():
|
|
14
|
+
return JAVA_SOLUTION.read_text(encoding="utf-8")
|
|
15
|
+
return ""
|
|
16
|
+
|
|
17
|
+
def extract(destination: Optional[str | Path] = None, overwrite: bool = True) -> Path:
|
|
18
|
+
from dancealgorithm.downloader import extract_bundled
|
|
19
|
+
from dancealgorithm.config import get_destination
|
|
20
|
+
target = Path(destination) if destination else get_destination()
|
|
21
|
+
extract_bundled(target, subject_filter=TITLE, overwrite=overwrite)
|
|
22
|
+
return target / PATH.name
|
|
23
|
+
|
|
24
|
+
def open_folder() -> None:
|
|
25
|
+
import os
|
|
26
|
+
if sys.platform == "win32":
|
|
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 &')
|
|
32
|
+
|
|
33
|
+
def __getattr__(name: str):
|
|
34
|
+
if name in ("code", "java_code", "solution_code"):
|
|
35
|
+
return get_code()
|
|
36
|
+
if name in ("path", "folder", "dir"):
|
|
37
|
+
return PATH
|
|
38
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
PATH = Path(__file__).resolve().parent
|
|
7
|
+
DIR = PATH
|
|
8
|
+
JAVA_SOLUTION = PATH / "Solution.java"
|
|
9
|
+
DATASET_PATH = PATH / "dataset.csv"
|
|
10
|
+
TITLE = "GC - Interference"
|
|
11
|
+
|
|
12
|
+
def get_code() -> str:
|
|
13
|
+
if JAVA_SOLUTION.exists():
|
|
14
|
+
return JAVA_SOLUTION.read_text(encoding="utf-8")
|
|
15
|
+
return ""
|
|
16
|
+
|
|
17
|
+
def extract(destination: Optional[str | Path] = None, overwrite: bool = True) -> Path:
|
|
18
|
+
from dancealgorithm.downloader import extract_bundled
|
|
19
|
+
from dancealgorithm.config import get_destination
|
|
20
|
+
target = Path(destination) if destination else get_destination()
|
|
21
|
+
extract_bundled(target, subject_filter=TITLE, overwrite=overwrite)
|
|
22
|
+
return target / PATH.name
|
|
23
|
+
|
|
24
|
+
def open_folder() -> None:
|
|
25
|
+
import os
|
|
26
|
+
if sys.platform == "win32":
|
|
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 &')
|
|
32
|
+
|
|
33
|
+
def __getattr__(name: str):
|
|
34
|
+
if name in ("code", "java_code", "solution_code"):
|
|
35
|
+
return get_code()
|
|
36
|
+
if name in ("path", "folder", "dir"):
|
|
37
|
+
return PATH
|
|
38
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,119 @@
|
|
|
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 courses: ");
|
|
10
|
+
int iSize = sc.nextInt();
|
|
11
|
+
|
|
12
|
+
String sCourses[] = new String[iSize];
|
|
13
|
+
|
|
14
|
+
// 2. Get Course Names
|
|
15
|
+
sc.nextLine();
|
|
16
|
+
|
|
17
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
18
|
+
System.out.print("Enter course " + (iCnt + 1) + ": ");
|
|
19
|
+
sCourses[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 course numbers for conflict pair " + (iCnt + 1));
|
|
30
|
+
|
|
31
|
+
System.out.print("First course: ");
|
|
32
|
+
int iU = sc.nextInt() - 1;
|
|
33
|
+
|
|
34
|
+
System.out.print("Second course: ");
|
|
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 course numbers!");
|
|
43
|
+
iCnt--;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 4. Get Available Exam Slots
|
|
48
|
+
System.out.print("\nEnter available exam slots: ");
|
|
49
|
+
int iSlots = sc.nextInt();
|
|
50
|
+
|
|
51
|
+
// 5. Apply Graph Coloring
|
|
52
|
+
TimetableScheduler(iGraph, iSlots, sCourses);
|
|
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 iSlots,
|
|
71
|
+
int iColor[], int iV, int iSize) {
|
|
72
|
+
if (iV == iSize) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (int iC = 1; iC <= iSlots; iC++) {
|
|
77
|
+
if (IsSafe(iV, iGraph, iColor, iC, iSize)) {
|
|
78
|
+
iColor[iV] = iC;
|
|
79
|
+
|
|
80
|
+
if (GraphColoring(iGraph, iSlots, 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. Timetable Scheduler
|
|
94
|
+
static void TimetableScheduler(int iGraph[][],
|
|
95
|
+
int iSlots, String sCourses[]) {
|
|
96
|
+
int iSize = sCourses.length;
|
|
97
|
+
int iColor[] = new int[iSize];
|
|
98
|
+
|
|
99
|
+
System.out.println("\nUniversity Exam Timetable:");
|
|
100
|
+
System.out.println("------------------------------------------------");
|
|
101
|
+
|
|
102
|
+
if (!GraphColoring(iGraph, iSlots, iColor, 0, iSize)) {
|
|
103
|
+
System.out.println("No conflict-free schedule possible!");
|
|
104
|
+
} else {
|
|
105
|
+
System.out.printf("%-30s %-15s%n",
|
|
106
|
+
"Course Name", "Exam Slot");
|
|
107
|
+
|
|
108
|
+
System.out.println("------------------------------------------------");
|
|
109
|
+
|
|
110
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
111
|
+
System.out.printf("%-30s Slot %d%n",
|
|
112
|
+
sCourses[iCnt], iColor[iCnt]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
System.out.println("------------------------------------------------");
|
|
116
|
+
System.out.println("Status: All courses scheduled without clashes.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
PATH = Path(__file__).resolve().parent
|
|
7
|
+
DIR = PATH
|
|
8
|
+
JAVA_SOLUTION = PATH / "Solution.java"
|
|
9
|
+
DATASET_PATH = PATH / "dataset.csv"
|
|
10
|
+
TITLE = "GC - University"
|
|
11
|
+
|
|
12
|
+
def get_code() -> str:
|
|
13
|
+
if JAVA_SOLUTION.exists():
|
|
14
|
+
return JAVA_SOLUTION.read_text(encoding="utf-8")
|
|
15
|
+
return ""
|
|
16
|
+
|
|
17
|
+
def extract(destination: Optional[str | Path] = None, overwrite: bool = True) -> Path:
|
|
18
|
+
from dancealgorithm.downloader import extract_bundled
|
|
19
|
+
from dancealgorithm.config import get_destination
|
|
20
|
+
target = Path(destination) if destination else get_destination()
|
|
21
|
+
extract_bundled(target, subject_filter=TITLE, overwrite=overwrite)
|
|
22
|
+
return target / PATH.name
|
|
23
|
+
|
|
24
|
+
def open_folder() -> None:
|
|
25
|
+
import os
|
|
26
|
+
if sys.platform == "win32":
|
|
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 &')
|
|
32
|
+
|
|
33
|
+
def __getattr__(name: str):
|
|
34
|
+
if name in ("code", "java_code", "solution_code"):
|
|
35
|
+
return get_code()
|
|
36
|
+
if name in ("path", "folder", "dir"):
|
|
37
|
+
return PATH
|
|
38
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
==================================================
|
|
2
|
+
7. GRAPH COLORING (BACKTRACKING)
|
|
3
|
+
==================================================
|
|
4
|
+
|
|
5
|
+
ALGORITHM:
|
|
6
|
+
1. Represent the graph using an adjacency matrix.
|
|
7
|
+
2. Initialize all vertex colors to zero.
|
|
8
|
+
3. Start coloring from vertex 0.
|
|
9
|
+
4. Try every available color from 1 to m.
|
|
10
|
+
5. Check whether the color is safe.
|
|
11
|
+
6. If safe, assign the color and recursively color the next vertex.
|
|
12
|
+
7. If unsuccessful, reset color to zero (backtracking).
|
|
13
|
+
8. Continue until all vertices are colored or no solution exists.
|
|
14
|
+
|
|
15
|
+
RECURRENCE RELATION:
|
|
16
|
+
T(V) = mT(V-1) + O(V)
|
|
17
|
+
|
|
18
|
+
TIME COMPLEXITY:
|
|
19
|
+
Best Case : Depends on early solution.
|
|
20
|
+
Average Case : Input-dependent.
|
|
21
|
+
Worst Case : O(V * m^V)
|
|
22
|
+
Space : O(V) auxiliary space
|
|
23
|
+
|
|
24
|
+
IMPORTANT:
|
|
25
|
+
1. Graph Coloring uses Backtracking.
|