Skip to content

Commit

Permalink
Solve for given number of trucks
Browse files Browse the repository at this point in the history
  • Loading branch information
gocklkatz committed Jul 19, 2024
1 parent 34be335 commit 0e007b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public VehicleRoutingProblem(List<List<Integer>> distanceMatrix) {
checkMatrix();
}

public Solution solveCompleteEnumerationNoCapacityConstraintOptimalTruckNumber(){
public Solution solveCompleteEnumerationNoCapacityConstraintGivenTruckNumber(int givenTruckNumber){

Solution bestSolution = new Solution(new ArrayList<>());

Expand All @@ -37,7 +37,8 @@ public Solution solveCompleteEnumerationNoCapacityConstraintOptimalTruckNumber()
Solution solution = new Solution(tspRoutes);
solution.setObjectiveFunctionValue(calcZf(tspRoutes));

if (solution.getObjectiveFunctionValue() < bestSolution.getObjectiveFunctionValue()) {
if (solution.getObjectiveFunctionValue() < bestSolution.getObjectiveFunctionValue() &&
solution.getRoutes().size() >= givenTruckNumber) {
bestSolution = solution;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ void givenCertainMatrix_whenCallingSolveCompleteEnumeration_NoCapacityConstraint
}

@Test
void solveCompleteEnumerationNoCapacityConstraintOptimalTruckNumberTest() {
void solveCompleteEnumerationNoCapacityConstraintGivenTruckNumberTest() {
VehicleRoutingProblem vrp = new VehicleRoutingProblem(matrix);
Solution solution = vrp.solveCompleteEnumerationNoCapacityConstraintOptimalTruckNumber();
Solution solution = vrp.solveCompleteEnumerationNoCapacityConstraintGivenTruckNumber(4);

assertEquals(List.of(4, 6, 3, 1, 2, 5), solution.getRoutes().getFirst().stops());
assertEquals(133, solution.getObjectiveFunctionValue());
assertEquals(List.of(2 ,1 ,3), solution.getRoutes().getFirst().stops());
assertEquals(List.of(4), solution.getRoutes().get(1).stops());
assertEquals(List.of(5), solution.getRoutes().get(2).stops());
assertEquals(List.of(6), solution.getRoutes().get(3).stops());
assertEquals(166, solution.getObjectiveFunctionValue());
}

}

0 comments on commit 0e007b2

Please sign in to comment.