dancealgorithm 0.1.0__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 +128 -0
- dancealgorithm/__main__.py +8 -0
- dancealgorithm/assignments/DA - Campus/Solution.java +198 -0
- dancealgorithm/assignments/DA - Campus/__init__.py +34 -0
- dancealgorithm/assignments/DA - Flight/Solution.java +204 -0
- dancealgorithm/assignments/DA - Flight/__init__.py +34 -0
- dancealgorithm/assignments/DA - Smart/Solution.java +220 -0
- dancealgorithm/assignments/DA - Smart/__init__.py +34 -0
- dancealgorithm/assignments/DA.txt +29 -0
- dancealgorithm/assignments/FK - Advertisement/Solution.java +141 -0
- dancealgorithm/assignments/FK - Advertisement/__init__.py +34 -0
- dancealgorithm/assignments/FK - Electric/Solution.java +168 -0
- dancealgorithm/assignments/FK - Electric/__init__.py +34 -0
- dancealgorithm/assignments/FK - Emergency/Solution.java +159 -0
- dancealgorithm/assignments/FK - Emergency/__init__.py +34 -0
- dancealgorithm/assignments/FK.txt +26 -0
- dancealgorithm/assignments/GC - Classroom/Solution.java +87 -0
- dancealgorithm/assignments/GC - Classroom/__init__.py +34 -0
- dancealgorithm/assignments/GC - Interference/Solution.java +88 -0
- dancealgorithm/assignments/GC - Interference/__init__.py +34 -0
- dancealgorithm/assignments/GC - University/Solution.java +88 -0
- dancealgorithm/assignments/GC - University/__init__.py +34 -0
- dancealgorithm/assignments/GC.txt +25 -0
- dancealgorithm/assignments/K - Cloud/Solution.java +115 -0
- dancealgorithm/assignments/K - Cloud/__init__.py +34 -0
- dancealgorithm/assignments/K - Disaster/Solution.java +116 -0
- dancealgorithm/assignments/K - Disaster/__init__.py +34 -0
- dancealgorithm/assignments/K - Hospital/Solution.java +115 -0
- dancealgorithm/assignments/K - Hospital/__init__.py +34 -0
- dancealgorithm/assignments/K.txt +38 -0
- dancealgorithm/assignments/LC - Delivery/Solution.java +180 -0
- dancealgorithm/assignments/LC - Delivery/__init__.py +34 -0
- dancealgorithm/assignments/LC - Drilling/Solution.java +197 -0
- dancealgorithm/assignments/LC - Drilling/__init__.py +34 -0
- dancealgorithm/assignments/LC - Flight/Solution.java +180 -0
- dancealgorithm/assignments/LC - Flight/__init__.py +34 -0
- dancealgorithm/assignments/LC.txt +31 -0
- dancealgorithm/assignments/MS - Commerce/Solution.java +162 -0
- dancealgorithm/assignments/MS - Commerce/__init__.py +34 -0
- dancealgorithm/assignments/MS - Commerce/dataset.csv +16 -0
- dancealgorithm/assignments/MS - Customer/Solution.java +144 -0
- dancealgorithm/assignments/MS - Customer/__init__.py +34 -0
- dancealgorithm/assignments/MS - Customer/dataset.csv +16 -0
- dancealgorithm/assignments/MS - Library/Solution.java +162 -0
- dancealgorithm/assignments/MS - Library/__init__.py +34 -0
- dancealgorithm/assignments/MS - Library/dataset.csv +16 -0
- dancealgorithm/assignments/MS.txt +32 -0
- dancealgorithm/assignments/MSG - Emergency/Solution.java +211 -0
- dancealgorithm/assignments/MSG - Emergency/__init__.py +34 -0
- dancealgorithm/assignments/MSG - Logistics/Solution.java +189 -0
- dancealgorithm/assignments/MSG - Logistics/__init__.py +34 -0
- dancealgorithm/assignments/MSG - Skyconnect/Solution.java +204 -0
- dancealgorithm/assignments/MSG - Skyconnect/__init__.py +34 -0
- dancealgorithm/assignments/MSG.txt +28 -0
- dancealgorithm/assignments/QS - Commerce/Solution.java +147 -0
- dancealgorithm/assignments/QS - Commerce/__init__.py +34 -0
- dancealgorithm/assignments/QS - Commerce/dataset.csv +16 -0
- dancealgorithm/assignments/QS - Movie/Solution.java +148 -0
- dancealgorithm/assignments/QS - Movie/__init__.py +34 -0
- dancealgorithm/assignments/QS - Movie/dataset.csv +16 -0
- dancealgorithm/assignments/QS - Online/Solution.java +147 -0
- dancealgorithm/assignments/QS - Online/__init__.py +34 -0
- dancealgorithm/assignments/QS - Online/dataset.csv +16 -0
- dancealgorithm/assignments/QS.txt +33 -0
- dancealgorithm/assignments/__init__.py +65 -0
- dancealgorithm/cli.py +349 -0
- dancealgorithm/config.py +125 -0
- dancealgorithm/downloader.py +330 -0
- dancealgorithm-0.1.0.dist-info/METADATA +199 -0
- dancealgorithm-0.1.0.dist-info/RECORD +74 -0
- dancealgorithm-0.1.0.dist-info/WHEEL +5 -0
- dancealgorithm-0.1.0.dist-info/entry_points.txt +3 -0
- dancealgorithm-0.1.0.dist-info/licenses/LICENSE +22 -0
- dancealgorithm-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
// 1. Main Function
|
|
5
|
+
public class Solution {
|
|
6
|
+
static final int INF = 999999;
|
|
7
|
+
|
|
8
|
+
public static void main(String args[]) {
|
|
9
|
+
Scanner sc = new Scanner(System.in);
|
|
10
|
+
|
|
11
|
+
int iSize = 8;
|
|
12
|
+
int iStages = 4;
|
|
13
|
+
|
|
14
|
+
String sNames[] = {
|
|
15
|
+
"NH-44 Crash Site",
|
|
16
|
+
"Primary Health Post PHC-1",
|
|
17
|
+
"Primary Health Post PHC-2",
|
|
18
|
+
"Community Health Post CHC-3",
|
|
19
|
+
"District Civil Hospital Alpha",
|
|
20
|
+
"District Civil Hospital Beta",
|
|
21
|
+
"Regional Medical Center",
|
|
22
|
+
"AIIMS Apex Trauma Care"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
int iStage[] = { 0, 1, 1, 1, 2, 2, 2, 3 };
|
|
26
|
+
|
|
27
|
+
// 2. Create Multistage Graph
|
|
28
|
+
int iGraph[][] = new int[iSize][iSize];
|
|
29
|
+
|
|
30
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
31
|
+
Arrays.fill(iGraph[iCnt], INF);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 3. Add Directed Roads and Travel Times
|
|
35
|
+
|
|
36
|
+
// Stage 1 to Stage 2
|
|
37
|
+
iGraph[0][1] = 15;
|
|
38
|
+
iGraph[0][2] = 12;
|
|
39
|
+
iGraph[0][3] = 18;
|
|
40
|
+
|
|
41
|
+
// Stage 2 to Stage 3
|
|
42
|
+
iGraph[1][4] = 25;
|
|
43
|
+
iGraph[1][5] = 30;
|
|
44
|
+
|
|
45
|
+
iGraph[2][4] = 20;
|
|
46
|
+
iGraph[2][5] = 22;
|
|
47
|
+
iGraph[2][6] = 28;
|
|
48
|
+
|
|
49
|
+
iGraph[3][5] = 24;
|
|
50
|
+
iGraph[3][6] = 26;
|
|
51
|
+
|
|
52
|
+
// Stage 3 to Stage 4
|
|
53
|
+
iGraph[4][7] = 35;
|
|
54
|
+
iGraph[5][7] = 28;
|
|
55
|
+
iGraph[6][7] = 32;
|
|
56
|
+
|
|
57
|
+
// 4. Display Available Locations
|
|
58
|
+
System.out.println("\nAvailable Medical Locations:");
|
|
59
|
+
|
|
60
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
61
|
+
System.out.println(iCnt + " : " + sNames[iCnt]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 5. Get Source and Destination
|
|
65
|
+
System.out.print("\nEnter Source Location: ");
|
|
66
|
+
String sSource = sc.nextLine();
|
|
67
|
+
|
|
68
|
+
System.out.print("Enter Destination Hospital: ");
|
|
69
|
+
String sDestination = sc.nextLine();
|
|
70
|
+
|
|
71
|
+
int iSource = findLocationIndex(sSource, sNames, iSize);
|
|
72
|
+
int iDestination = findLocationIndex(sDestination, sNames, iSize);
|
|
73
|
+
|
|
74
|
+
if (iSource == -1 || iDestination == -1) {
|
|
75
|
+
System.out.println("Invalid Location Name!");
|
|
76
|
+
sc.close();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (iStage[iSource] > iStage[iDestination]) {
|
|
81
|
+
System.out.println("No valid forward route available.");
|
|
82
|
+
sc.close();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 6. Apply Multistage Algorithm
|
|
87
|
+
Multistage(iGraph, iStage, iSize, iStages,
|
|
88
|
+
iSource, iDestination, sNames);
|
|
89
|
+
|
|
90
|
+
sc.close();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 7. Multistage Dynamic Programming
|
|
94
|
+
static void Multistage(int iGraph[][], int iStage[],
|
|
95
|
+
int iSize, int iStages,
|
|
96
|
+
int iSource, int iDestination,
|
|
97
|
+
String sNames[]) {
|
|
98
|
+
int iTime[] = new int[iSize];
|
|
99
|
+
int iNext[] = new int[iSize];
|
|
100
|
+
|
|
101
|
+
Arrays.fill(iTime, INF);
|
|
102
|
+
Arrays.fill(iNext, -1);
|
|
103
|
+
|
|
104
|
+
iTime[iDestination] = 0;
|
|
105
|
+
|
|
106
|
+
// 8. Calculate Minimum Travel Time Backwards
|
|
107
|
+
for (int iCnt = iStage[iDestination] - 1; iCnt >= 0; iCnt--) {
|
|
108
|
+
for (int i = 0; i < iSize; i++) {
|
|
109
|
+
if (iStage[i] == iCnt) {
|
|
110
|
+
for (int j = 0; j < iSize; j++) {
|
|
111
|
+
if (iStage[j] > iStage[i] &&
|
|
112
|
+
iStage[j] <= iStage[iDestination] &&
|
|
113
|
+
iGraph[i][j] != INF &&
|
|
114
|
+
iTime[j] != INF) {
|
|
115
|
+
int iTotal = iGraph[i][j] + iTime[j];
|
|
116
|
+
|
|
117
|
+
if (iTotal < iTime[i]) {
|
|
118
|
+
iTime[i] = iTotal;
|
|
119
|
+
iNext[i] = j;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 9. Display Optimal Evacuation Route
|
|
128
|
+
System.out.println("\nEmergency Patient Medical Evacuation:");
|
|
129
|
+
System.out.println("---------------------------------------------");
|
|
130
|
+
|
|
131
|
+
System.out.println("Source Location: " + sNames[iSource]);
|
|
132
|
+
System.out.println("Destination Hospital: " + sNames[iDestination]);
|
|
133
|
+
|
|
134
|
+
if (iTime[iSource] == INF) {
|
|
135
|
+
System.out.println("No valid evacuation route available.");
|
|
136
|
+
} else {
|
|
137
|
+
System.out.println("Minimum Travel Time: " +
|
|
138
|
+
iTime[iSource] + " minutes");
|
|
139
|
+
|
|
140
|
+
System.out.print("Optimal Evacuation Route: ");
|
|
141
|
+
|
|
142
|
+
int iCurr = iSource;
|
|
143
|
+
|
|
144
|
+
while (iCurr != -1) {
|
|
145
|
+
System.out.print(sNames[iCurr]);
|
|
146
|
+
|
|
147
|
+
if (iCurr == iDestination) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
iCurr = iNext[iCurr];
|
|
152
|
+
|
|
153
|
+
if (iCurr != -1) {
|
|
154
|
+
System.out.print(" -> ");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
System.out.println("\n---------------------------------------------");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Helper to resolve location by name, index, or "index : name"
|
|
163
|
+
static int findLocationIndex(String sInput, String sNames[], int iSize) {
|
|
164
|
+
if (sInput == null) {
|
|
165
|
+
return -1;
|
|
166
|
+
}
|
|
167
|
+
sInput = sInput.trim();
|
|
168
|
+
if (sInput.isEmpty()) {
|
|
169
|
+
return -1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (sInput.contains(":")) {
|
|
173
|
+
String parts[] = sInput.split(":", 2);
|
|
174
|
+
int idx = findLocationIndex(parts[0], sNames, iSize);
|
|
175
|
+
if (idx != -1) return idx;
|
|
176
|
+
idx = findLocationIndex(parts[1], sNames, iSize);
|
|
177
|
+
if (idx != -1) return idx;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (sInput.contains("-")) {
|
|
181
|
+
String parts[] = sInput.split("-", 2);
|
|
182
|
+
int idx = findLocationIndex(parts[0], sNames, iSize);
|
|
183
|
+
if (idx != -1) return idx;
|
|
184
|
+
idx = findLocationIndex(parts[1], sNames, iSize);
|
|
185
|
+
if (idx != -1) return idx;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
int idx = Integer.parseInt(sInput);
|
|
190
|
+
if (idx >= 0 && idx < iSize) {
|
|
191
|
+
return idx;
|
|
192
|
+
}
|
|
193
|
+
} catch (NumberFormatException ignored) {
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
for (int i = 0; i < iSize; i++) {
|
|
197
|
+
if (sNames[i].equalsIgnoreCase(sInput)) {
|
|
198
|
+
return i;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (int i = 0; i < iSize; i++) {
|
|
203
|
+
if (sInput.toLowerCase().contains(sNames[i].toLowerCase()) ||
|
|
204
|
+
sNames[i].toLowerCase().contains(sInput.toLowerCase())) {
|
|
205
|
+
return i;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return -1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 = "MSG - Emergency"
|
|
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
|
+
|
|
29
|
+
def __getattr__(name: str):
|
|
30
|
+
if name in ("code", "java_code", "solution_code"):
|
|
31
|
+
return get_code()
|
|
32
|
+
if name in ("path", "folder", "dir"):
|
|
33
|
+
return PATH
|
|
34
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
// 1. Main Function
|
|
5
|
+
public class Solution {
|
|
6
|
+
static final int INF = 999999;
|
|
7
|
+
|
|
8
|
+
public static void main(String args[]) {
|
|
9
|
+
Scanner sc = new Scanner(System.in);
|
|
10
|
+
|
|
11
|
+
int iSize = 8;
|
|
12
|
+
int iStages = 4;
|
|
13
|
+
|
|
14
|
+
String sNames[] = {
|
|
15
|
+
"Surat",
|
|
16
|
+
"Mumbai",
|
|
17
|
+
"Pune",
|
|
18
|
+
"Nashik",
|
|
19
|
+
"Indore",
|
|
20
|
+
"Nagpur",
|
|
21
|
+
"Jaipur",
|
|
22
|
+
"Delhi"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// 2. Create Multistage Graph
|
|
26
|
+
int iGraph[][] = new int[iSize][iSize];
|
|
27
|
+
|
|
28
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
29
|
+
Arrays.fill(iGraph[iCnt], INF);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 3. Add Directed Routes and Costs
|
|
33
|
+
|
|
34
|
+
// Stage 1 to Stage 2
|
|
35
|
+
iGraph[0][1] = 1;
|
|
36
|
+
iGraph[0][2] = 2;
|
|
37
|
+
iGraph[0][3] = 5;
|
|
38
|
+
|
|
39
|
+
// Stage 2 to Stage 3
|
|
40
|
+
iGraph[1][4] = 4;
|
|
41
|
+
iGraph[1][5] = 11;
|
|
42
|
+
|
|
43
|
+
iGraph[2][4] = 9;
|
|
44
|
+
iGraph[2][5] = 5;
|
|
45
|
+
iGraph[2][6] = 16;
|
|
46
|
+
|
|
47
|
+
iGraph[3][6] = 2;
|
|
48
|
+
|
|
49
|
+
// Stage 3 to Stage 4
|
|
50
|
+
iGraph[4][7] = 18;
|
|
51
|
+
iGraph[5][7] = 13;
|
|
52
|
+
iGraph[6][7] = 2;
|
|
53
|
+
|
|
54
|
+
// 4. Display Destination Cities
|
|
55
|
+
System.out.println("\nSwiftCargo Destination Cities:");
|
|
56
|
+
|
|
57
|
+
for (int iCnt = 1; iCnt < iSize; iCnt++) {
|
|
58
|
+
System.out.println(iCnt + " : " + sNames[iCnt]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 5. Get Destination City
|
|
62
|
+
System.out.print("\nEnter Destination City: ");
|
|
63
|
+
String sDestination = sc.nextLine();
|
|
64
|
+
|
|
65
|
+
int iDestination = findCityIndex(sDestination, sNames, iSize);
|
|
66
|
+
|
|
67
|
+
if (iDestination == -1) {
|
|
68
|
+
System.out.println("Invalid Destination City!");
|
|
69
|
+
sc.close();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 6. Apply Multistage Algorithm
|
|
74
|
+
Multistage(iGraph, iSize, iStages, iDestination, sNames);
|
|
75
|
+
|
|
76
|
+
sc.close();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 7. Multistage Dynamic Programming
|
|
80
|
+
static void Multistage(int iGraph[][], int iSize,
|
|
81
|
+
int iStages, int iDestination,
|
|
82
|
+
String sNames[]) {
|
|
83
|
+
int iCost[] = new int[iSize];
|
|
84
|
+
int iNext[] = new int[iSize];
|
|
85
|
+
|
|
86
|
+
Arrays.fill(iCost, INF);
|
|
87
|
+
Arrays.fill(iNext, -1);
|
|
88
|
+
|
|
89
|
+
iCost[iDestination] = 0;
|
|
90
|
+
|
|
91
|
+
// 8. Calculate Minimum Cost Backwards
|
|
92
|
+
for (int iCnt = iStages - 1; iCnt >= 0; iCnt--) {
|
|
93
|
+
for (int i = 0; i < iSize; i++) {
|
|
94
|
+
for (int j = i + 1; j < iSize; j++) {
|
|
95
|
+
if (iGraph[i][j] != INF && iCost[j] != INF) {
|
|
96
|
+
int iTotal = iGraph[i][j] + iCost[j];
|
|
97
|
+
|
|
98
|
+
if (iTotal < iCost[i]) {
|
|
99
|
+
iCost[i] = iTotal;
|
|
100
|
+
iNext[i] = j;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 9. Display Optimal Delivery Route
|
|
108
|
+
System.out.println("\nSwiftCargo Logistics Route Optimization:");
|
|
109
|
+
|
|
110
|
+
System.out.println("Source City: Surat");
|
|
111
|
+
System.out.println("Destination City: " + sNames[iDestination]);
|
|
112
|
+
|
|
113
|
+
if (iCost[0] == INF) {
|
|
114
|
+
System.out.println("No valid route available.");
|
|
115
|
+
} else {
|
|
116
|
+
System.out.println("Minimum Total Cost: Rs. " + iCost[0]);
|
|
117
|
+
|
|
118
|
+
System.out.print("Optimal Delivery Route: ");
|
|
119
|
+
|
|
120
|
+
int iCurr = 0;
|
|
121
|
+
|
|
122
|
+
while (iCurr != -1) {
|
|
123
|
+
System.out.print(sNames[iCurr]);
|
|
124
|
+
|
|
125
|
+
if (iCurr == iDestination) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
iCurr = iNext[iCurr];
|
|
130
|
+
|
|
131
|
+
if (iCurr != -1) {
|
|
132
|
+
System.out.print(" -> ");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
System.out.println();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Helper to resolve city by name, index, or "index : name"
|
|
141
|
+
static int findCityIndex(String sInput, String sNames[], int iSize) {
|
|
142
|
+
if (sInput == null) {
|
|
143
|
+
return -1;
|
|
144
|
+
}
|
|
145
|
+
sInput = sInput.trim();
|
|
146
|
+
if (sInput.isEmpty()) {
|
|
147
|
+
return -1;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (sInput.contains(":")) {
|
|
151
|
+
String parts[] = sInput.split(":", 2);
|
|
152
|
+
int idx = findCityIndex(parts[0], sNames, iSize);
|
|
153
|
+
if (idx != -1) return idx;
|
|
154
|
+
idx = findCityIndex(parts[1], sNames, iSize);
|
|
155
|
+
if (idx != -1) return idx;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (sInput.contains("-")) {
|
|
159
|
+
String parts[] = sInput.split("-", 2);
|
|
160
|
+
int idx = findCityIndex(parts[0], sNames, iSize);
|
|
161
|
+
if (idx != -1) return idx;
|
|
162
|
+
idx = findCityIndex(parts[1], sNames, iSize);
|
|
163
|
+
if (idx != -1) return idx;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
int idx = Integer.parseInt(sInput);
|
|
168
|
+
if (idx >= 1 && idx < iSize) {
|
|
169
|
+
return idx;
|
|
170
|
+
}
|
|
171
|
+
} catch (NumberFormatException ignored) {
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (int i = 1; i < iSize; i++) {
|
|
175
|
+
if (sNames[i].equalsIgnoreCase(sInput)) {
|
|
176
|
+
return i;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for (int i = 1; i < iSize; i++) {
|
|
181
|
+
if (sInput.toLowerCase().contains(sNames[i].toLowerCase()) ||
|
|
182
|
+
sNames[i].toLowerCase().contains(sInput.toLowerCase())) {
|
|
183
|
+
return i;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return -1;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 = "MSG - Logistics"
|
|
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
|
+
|
|
29
|
+
def __getattr__(name: str):
|
|
30
|
+
if name in ("code", "java_code", "solution_code"):
|
|
31
|
+
return get_code()
|
|
32
|
+
if name in ("path", "folder", "dir"):
|
|
33
|
+
return PATH
|
|
34
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
// 1. Main Function
|
|
5
|
+
public class Solution {
|
|
6
|
+
static final int INF = 999999;
|
|
7
|
+
|
|
8
|
+
public static void main(String args[]) {
|
|
9
|
+
Scanner sc = new Scanner(System.in);
|
|
10
|
+
|
|
11
|
+
int iSize = 8;
|
|
12
|
+
int iStages = 4;
|
|
13
|
+
|
|
14
|
+
String sNames[] = {
|
|
15
|
+
"Chandigarh",
|
|
16
|
+
"Delhi",
|
|
17
|
+
"Lucknow",
|
|
18
|
+
"Ahmedabad",
|
|
19
|
+
"Mumbai",
|
|
20
|
+
"Pune",
|
|
21
|
+
"Hyderabad",
|
|
22
|
+
"Bengaluru"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
int iStage[] = { 0, 1, 1, 1, 2, 2, 2, 3 };
|
|
26
|
+
|
|
27
|
+
// 2. Create Multistage Graph
|
|
28
|
+
int iGraph[][] = new int[iSize][iSize];
|
|
29
|
+
|
|
30
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
31
|
+
Arrays.fill(iGraph[iCnt], INF);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 3. Add Directed Flights and Costs
|
|
35
|
+
|
|
36
|
+
// Stage 1 to Stage 2
|
|
37
|
+
iGraph[0][1] = 2200;
|
|
38
|
+
iGraph[0][2] = 2500;
|
|
39
|
+
iGraph[0][3] = 2800;
|
|
40
|
+
|
|
41
|
+
// Stage 2 to Stage 3
|
|
42
|
+
iGraph[1][4] = 4200;
|
|
43
|
+
iGraph[1][5] = 4500;
|
|
44
|
+
|
|
45
|
+
iGraph[2][4] = 3400;
|
|
46
|
+
iGraph[2][5] = 3600;
|
|
47
|
+
iGraph[2][6] = 3900;
|
|
48
|
+
|
|
49
|
+
iGraph[3][5] = 3200;
|
|
50
|
+
iGraph[3][6] = 3500;
|
|
51
|
+
|
|
52
|
+
// Stage 3 to Stage 4
|
|
53
|
+
iGraph[4][7] = 3100;
|
|
54
|
+
iGraph[5][7] = 2400;
|
|
55
|
+
iGraph[6][7] = 1900;
|
|
56
|
+
|
|
57
|
+
// 4. Display Available Airports
|
|
58
|
+
System.out.println("\nAvailable Airports:");
|
|
59
|
+
|
|
60
|
+
for (int iCnt = 0; iCnt < iSize; iCnt++) {
|
|
61
|
+
System.out.println(iCnt + " : " + sNames[iCnt]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 5. Get Source and Destination
|
|
65
|
+
System.out.print("\nEnter Source Airport: ");
|
|
66
|
+
String sSource = sc.nextLine();
|
|
67
|
+
|
|
68
|
+
System.out.print("Enter Destination Airport: ");
|
|
69
|
+
String sDestination = sc.nextLine();
|
|
70
|
+
|
|
71
|
+
int iSource = findAirportIndex(sSource, sNames, iSize);
|
|
72
|
+
int iDestination = findAirportIndex(sDestination, sNames, iSize);
|
|
73
|
+
|
|
74
|
+
if (iSource == -1 || iDestination == -1) {
|
|
75
|
+
System.out.println("Invalid Airport Name!");
|
|
76
|
+
sc.close();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 6. Apply Multistage Algorithm
|
|
81
|
+
Multistage(iGraph, iStage, iSize, iStages,
|
|
82
|
+
iSource, iDestination, sNames);
|
|
83
|
+
|
|
84
|
+
sc.close();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 7. Multistage Dynamic Programming
|
|
88
|
+
static void Multistage(int iGraph[][], int iStage[],
|
|
89
|
+
int iSize, int iStages,
|
|
90
|
+
int iSource, int iDestination,
|
|
91
|
+
String sNames[]) {
|
|
92
|
+
int iCost[] = new int[iSize];
|
|
93
|
+
int iNext[] = new int[iSize];
|
|
94
|
+
|
|
95
|
+
Arrays.fill(iCost, INF);
|
|
96
|
+
Arrays.fill(iNext, -1);
|
|
97
|
+
|
|
98
|
+
iCost[iDestination] = 0;
|
|
99
|
+
|
|
100
|
+
// 8. Calculate Minimum Cost Backwards
|
|
101
|
+
for (int iCnt = iStage[iDestination] - 1; iCnt >= 0; iCnt--) {
|
|
102
|
+
for (int i = 0; i < iSize; i++) {
|
|
103
|
+
if (iStage[i] == iCnt) {
|
|
104
|
+
for (int j = 0; j < iSize; j++) {
|
|
105
|
+
if (iStage[j] > iStage[i] &&
|
|
106
|
+
iStage[j] <= iStage[iDestination] &&
|
|
107
|
+
iGraph[i][j] != INF &&
|
|
108
|
+
iCost[j] != INF) {
|
|
109
|
+
int iTotal = iGraph[i][j] + iCost[j];
|
|
110
|
+
|
|
111
|
+
if (iTotal < iCost[i]) {
|
|
112
|
+
iCost[i] = iTotal;
|
|
113
|
+
iNext[i] = j;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 9. Display Optimal Flight Route
|
|
122
|
+
System.out.println("\nSkyConnect Flight Route Optimization:");
|
|
123
|
+
System.out.println("---------------------------------------------");
|
|
124
|
+
|
|
125
|
+
System.out.println("Source Airport: " + sNames[iSource]);
|
|
126
|
+
System.out.println("Destination Airport: " + sNames[iDestination]);
|
|
127
|
+
|
|
128
|
+
if (iCost[iSource] == INF) {
|
|
129
|
+
System.out.println("No valid flight route available.");
|
|
130
|
+
} else {
|
|
131
|
+
System.out.println("Minimum Ticket Cost: Rs. " + iCost[iSource]);
|
|
132
|
+
|
|
133
|
+
System.out.print("Optimal Flight Route: ");
|
|
134
|
+
|
|
135
|
+
int iCurr = iSource;
|
|
136
|
+
|
|
137
|
+
while (iCurr != -1) {
|
|
138
|
+
System.out.print(sNames[iCurr]);
|
|
139
|
+
|
|
140
|
+
if (iCurr == iDestination) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
iCurr = iNext[iCurr];
|
|
145
|
+
|
|
146
|
+
if (iCurr != -1) {
|
|
147
|
+
System.out.print(" -> ");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
System.out.println("\n---------------------------------------------");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Helper to resolve airport by name, index, or "index : name"
|
|
156
|
+
static int findAirportIndex(String sInput, String sNames[], int iSize) {
|
|
157
|
+
if (sInput == null) {
|
|
158
|
+
return -1;
|
|
159
|
+
}
|
|
160
|
+
sInput = sInput.trim();
|
|
161
|
+
if (sInput.isEmpty()) {
|
|
162
|
+
return -1;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (sInput.contains(":")) {
|
|
166
|
+
String parts[] = sInput.split(":", 2);
|
|
167
|
+
int idx = findAirportIndex(parts[0], sNames, iSize);
|
|
168
|
+
if (idx != -1) return idx;
|
|
169
|
+
idx = findAirportIndex(parts[1], sNames, iSize);
|
|
170
|
+
if (idx != -1) return idx;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (sInput.contains("-")) {
|
|
174
|
+
String parts[] = sInput.split("-", 2);
|
|
175
|
+
int idx = findAirportIndex(parts[0], sNames, iSize);
|
|
176
|
+
if (idx != -1) return idx;
|
|
177
|
+
idx = findAirportIndex(parts[1], sNames, iSize);
|
|
178
|
+
if (idx != -1) return idx;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
int idx = Integer.parseInt(sInput);
|
|
183
|
+
if (idx >= 0 && idx < iSize) {
|
|
184
|
+
return idx;
|
|
185
|
+
}
|
|
186
|
+
} catch (NumberFormatException ignored) {
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (int i = 0; i < iSize; i++) {
|
|
190
|
+
if (sNames[i].equalsIgnoreCase(sInput)) {
|
|
191
|
+
return i;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (int i = 0; i < iSize; i++) {
|
|
196
|
+
if (sInput.toLowerCase().contains(sNames[i].toLowerCase()) ||
|
|
197
|
+
sNames[i].toLowerCase().contains(sInput.toLowerCase())) {
|
|
198
|
+
return i;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return -1;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 = "MSG - Skyconnect"
|
|
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
|
+
|
|
29
|
+
def __getattr__(name: str):
|
|
30
|
+
if name in ("code", "java_code", "solution_code"):
|
|
31
|
+
return get_code()
|
|
32
|
+
if name in ("path", "folder", "dir"):
|
|
33
|
+
return PATH
|
|
34
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|