Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.graphhopper:jsprit:1.9.0-beta.32'
}
dependencies {
implementation("com.github.graphhopper:jsprit:1.9.0-beta.32")
}
<dependency>
<groupId>com.github.graphhopper</groupId>
<artifactId>jsprit</artifactId>
<version>1.9.0-beta.32</version>
</dependency>
libraryDependencies += "com.github.graphhopper" % "jsprit" % "1.9.0-beta.32"
:dependencies [[com.github.graphhopper/jsprit "1.9.0-beta.32"]]
jsprit is a java based, open source toolkit for solving rich Traveling Salesman Problems (TSP) and Vehicle Routing Problems (VRP).
It is lightweight, flexible and easy-to-use, and based on a single all-purpose meta-heuristic currently solving:
Setting up the problem, defining additional constraints, modifying the algorithms and visualising the discovered solutions is straightforward. It is designed for change and extension with a modular architecture and comprehensive test coverage. More features...
The jsprit-project is maintained by GraphHopper.
Maven:
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>jsprit-core</artifactId>
<version>2.0.0</version>
</dependency>
Gradle:
implementation 'com.graphhopper:jsprit-core:2.0.0'
// Define vehicles
VehicleType vehicleType = VehicleTypeImpl.Builder.newInstance("type")
.addCapacityDimension(0, 10)
.build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle")
.setStartLocation(Location.newInstance(0, 0))
.setType(vehicleType)
.build();
// Define jobs
Service job1 = Service.Builder.newInstance("job1")
.addSizeDimension(0, 1)
.setLocation(Location.newInstance(5, 7))
.build();
Service job2 = Service.Builder.newInstance("job2")
.addSizeDimension(0, 2)
.setLocation(Location.newInstance(3, 4))
.build();
// Build the problem
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
.addVehicle(vehicle)
.addJob(job1)
.addJob(job2)
.build();
// Solve
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution best = Solutions.bestOf(solutions);
Independent Operator Selection - Configure ruin and insertion strategies separately:
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp)
.addRuinOperator(0.4, Ruin.radial())
.addRuinOperator(0.4, Ruin.random())
.addRuinOperator(0.2, Ruin.worst())
.addInsertionOperator(0.7, Insertion.regretFast())
.addInsertionOperator(0.3, Insertion.best())
.buildAlgorithm();
Algorithm Event System - Monitor algorithm execution:
AlgorithmEventAdapter adapter = new AlgorithmEventAdapter(algorithm);
algorithm.addListener(adapter);
algorithm.addEventListener(event -> {
if (event instanceof StrategyExecuted e) {
System.out.println("Strategy: " + e.strategyId());
}
});
Other improvements:
See CHANGELOG.md for full details.
Upgrading from 1.x? See MIGRATION.md.
Please visit docs to learn more.
Please read NOTICE.md to get to know the direct dependencies of each module.
This software is released under Apache License v2.
Any contribution is welcome. Feel free to improve jsprit and make pull requests. If you want to contribute to jsprit, fork the project and build your fork, make changes, run tests and make a pull request (see GitHub help for details).
See who has contributed here.
Forum: In the GraphHopper Forum you can discuss jsprit related issues and get answers to your questions.
Issue Tracker: For bugs and feature requests, use the issue tracker.
Email: If you prefer private communication, contact us via mail.