Skip to content

Commit 100ba51

Browse files
Fix issues to make the project build successfully and rename files
1 parent 4c53d06 commit 100ba51

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/main/java/com/thealgorithms/graph/ConstraintShortestPath.java renamed to src/main/java/com/thealgorithms/graph/ConstrainedShortestPath.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @author <a href="https://github.com/DenizAltunkapan">Deniz Altunkapan</a>
1414
*/
15-
public class ConstraintShortestPath {
15+
public class ConstrainedShortestPath {
1616

1717
/**
1818
* Represents a graph using an adjacency list.
@@ -57,7 +57,7 @@ public int getNumNodes() {
5757
return adjacencyList.size();
5858
}
5959

60-
public static record Edge(int from, int to, int cost, int resource) {
60+
public record Edge(int from, int to, int cost, int resource) {
6161
}
6262
}
6363

@@ -70,7 +70,7 @@ public static record Edge(int from, int to, int cost, int resource) {
7070
* @param graph the graph representing the problem
7171
* @param maxResource the maximum allowable resource
7272
*/
73-
public ConstraintShortestPath(Graph graph, int maxResource) {
73+
public ConstrainedShortestPath(Graph graph, int maxResource) {
7474
this.graph = graph;
7575
this.maxResource = maxResource;
7676
}
@@ -97,7 +97,9 @@ public int solve(int start, int target) {
9797
// Dynamic Programming: Iterate over resources and nodes
9898
for (int r = 0; r <= maxResource; r++) {
9999
for (int u = 0; u < numNodes; u++) {
100-
if (dp[r][u] == Integer.MAX_VALUE) continue;
100+
if (dp[r][u] == Integer.MAX_VALUE) {
101+
continue;
102+
}
101103
for (Graph.Edge edge : graph.getEdges(u)) {
102104
int v = edge.to();
103105
int cost = edge.cost();

src/test/java/com/thealgorithms/graph/ConstraintShortestPathTest.java renamed to src/test/java/com/thealgorithms/graph/ConstrainedShortestPathTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.thealgorithms.graph;
22

3-
import static org.junit.jupiter.api.Assertions.*;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import com.thealgorithms.graph.ConstraintShortestPath.*;
5+
import com.thealgorithms.graph.ConstrainedShortestPath.Graph;
66
import org.junit.jupiter.api.Test;
77

8-
public class ConstraintShortestPathTest {
8+
public class ConstrainedShortestPathTest {
99

1010
/**
1111
* Tests a simple linear graph to verify if the solver calculates the shortest path correctly.
@@ -18,7 +18,7 @@ public void testSimpleGraph() {
1818
graph.addEdge(1, 2, 3, 2);
1919

2020
int maxResource = 5;
21-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
21+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
2222

2323
assertEquals(5, solver.solve(0, 2));
2424
}
@@ -34,7 +34,7 @@ public void testNoPath() {
3434
graph.addEdge(1, 2, 3, 6);
3535

3636
int maxResource = 5;
37-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
37+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
3838

3939
assertEquals(-1, solver.solve(0, 2));
4040
}
@@ -52,7 +52,7 @@ public void testMultiplePaths() {
5252
graph.addEdge(2, 3, 3, 2);
5353

5454
int maxResource = 3;
55-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
55+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
5656

5757
assertEquals(5, solver.solve(0, 3));
5858
}
@@ -68,7 +68,7 @@ public void testExactResourceLimit() {
6868
graph.addEdge(1, 2, 3, 2);
6969

7070
int maxResource = 5;
71-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
71+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
7272

7373
assertEquals(5, solver.solve(0, 2));
7474
}
@@ -84,7 +84,7 @@ public void testDisconnectedGraph() {
8484
graph.addEdge(2, 3, 3, 2);
8585

8686
int maxResource = 5;
87-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
87+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
8888

8989
assertEquals(-1, solver.solve(0, 3));
9090
}
@@ -102,7 +102,7 @@ public void testGraphWithCycles() {
102102
graph.addEdge(1, 3, 4, 2);
103103

104104
int maxResource = 3;
105-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
105+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
106106

107107
assertEquals(6, solver.solve(0, 3));
108108
}
@@ -120,7 +120,7 @@ public void testLargeGraphPerformance() {
120120
}
121121

122122
int maxResource = 1000;
123-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
123+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
124124

125125
assertEquals(999, solver.solve(0, nodeCount - 1));
126126
}
@@ -136,7 +136,7 @@ public void testIsolatedNodes() {
136136
graph.addEdge(1, 2, 3, 1);
137137

138138
int maxResource = 5;
139-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
139+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
140140

141141
assertEquals(-1, solver.solve(0, 3));
142142
}
@@ -154,7 +154,7 @@ public void testCyclicLargeGraph() {
154154
graph.addEdge(0, 5, 5, 3);
155155

156156
int maxResource = 10;
157-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
157+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
158158

159159
assertEquals(5, solver.solve(0, 5));
160160
}
@@ -180,7 +180,7 @@ public void testLargeComplexGraph() {
180180
graph.addEdge(8, 9, 2, 1);
181181

182182
int maxResource = 10;
183-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
183+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
184184

185185
assertEquals(19, solver.solve(0, 9));
186186
}
@@ -194,7 +194,7 @@ public void testSingleNodeGraph() {
194194
Graph graph = new Graph(1);
195195

196196
int maxResource = 0;
197-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
197+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
198198

199199
assertEquals(0, solver.solve(0, 0));
200200
}
@@ -211,7 +211,7 @@ public void testTightResourceConstraint() {
211211
graph.addEdge(0, 2, 2, 2);
212212

213213
int maxResource = 3;
214-
ConstraintShortestPath solver = new ConstraintShortestPath(graph, maxResource);
214+
ConstrainedShortestPath solver = new ConstrainedShortestPath(graph, maxResource);
215215

216216
assertEquals(2, solver.solve(0, 2));
217217
}

0 commit comments

Comments
 (0)