mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add javadoc and tests
This commit is contained in:
parent
5842bd73a4
commit
b6d97d6688
4 changed files with 73 additions and 7 deletions
|
|
@ -18,10 +18,20 @@ package jsprit.core.problem.solution;
|
||||||
|
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for all factories that create initial solutions for the specified {@link VehicleRoutingProblem}.
|
||||||
|
*
|
||||||
|
* @author schroeder
|
||||||
|
*
|
||||||
|
*/
|
||||||
public interface InitialSolutionFactory {
|
public interface InitialSolutionFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an initial solution for the specified {@link VehicleRoutingProblem}.
|
||||||
|
*
|
||||||
|
* @param vrp
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public VehicleRoutingProblemSolution createSolution(VehicleRoutingProblem vrp);
|
public VehicleRoutingProblemSolution createSolution(VehicleRoutingProblem vrp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,21 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem.solution;
|
package jsprit.core.problem.solution;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for all solutionCostCalculators which should be the objective-functions of the problem.
|
||||||
|
*
|
||||||
|
* <p>It evaluates VehicleRoutingProblemSolution and returns its costs.
|
||||||
|
*
|
||||||
|
* @author schroeder
|
||||||
|
*
|
||||||
|
*/
|
||||||
public interface SolutionCostCalculator {
|
public interface SolutionCostCalculator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns costs of solution.
|
* Returns costs of solution.
|
||||||
*
|
*
|
||||||
* @param solution
|
* @param solution
|
||||||
* @return TODO
|
* @return costs
|
||||||
*/
|
*/
|
||||||
public double getCosts(VehicleRoutingProblemSolution solution);
|
public double getCosts(VehicleRoutingProblemSolution solution);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
/**
|
/**
|
||||||
* Contains the solution of a vehicle routing problem and its corresponding costs.
|
* Contains the solution of a vehicle routing problem and its corresponding costs.
|
||||||
*
|
*
|
||||||
* @author stefan schröder
|
* @author stefan schroeder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class VehicleRoutingProblemSolution {
|
public class VehicleRoutingProblemSolution {
|
||||||
|
|
@ -67,16 +67,29 @@ public class VehicleRoutingProblemSolution {
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of vehicle-routes.
|
||||||
|
*
|
||||||
|
* @return collection of vehicle-routes
|
||||||
|
*/
|
||||||
public Collection<VehicleRoute> getRoutes() {
|
public Collection<VehicleRoute> getRoutes() {
|
||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns cost of this solution.
|
||||||
|
*
|
||||||
|
* @return costs
|
||||||
|
*/
|
||||||
public double getCost() {
|
public double getCost() {
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the costs of this solution.
|
||||||
|
*
|
||||||
|
* @param cost
|
||||||
|
*/
|
||||||
public void setCost(double cost){
|
public void setCost(double cost){
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package jsprit.core.problem.solution;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class VehicleRoutingProblemSolutionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingSolutionWithTwoRoutes_solutionShouldContainTheseRoutes(){
|
||||||
|
VehicleRoute r1 = mock(VehicleRoute.class);
|
||||||
|
VehicleRoute r2 = mock(VehicleRoute.class);
|
||||||
|
|
||||||
|
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Arrays.asList(r1,r2), 0.0);
|
||||||
|
assertEquals(2,sol.getRoutes().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingSolutionCostsTo10_solutionCostsShouldBe10(){
|
||||||
|
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.<VehicleRoute>emptyList(), 10.0);
|
||||||
|
assertEquals(10.0,sol.getCost(),0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingSolWithCostsOf10AndSettingCostsAfterwardsTo20_solutionCostsShouldBe20(){
|
||||||
|
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.<VehicleRoute>emptyList(), 10.0);
|
||||||
|
sol.setCost(20.0);
|
||||||
|
assertEquals(20.0,sol.getCost(),0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue