Advanced Examples (JOpt.TourOptimizer)
This package contains advanced, feature-focused examples for JOpt.TourOptimizer. The intent is to help you identify which of your real-world business use cases can be covered by the product features and how to model them cleanly.
There is no required order. You can start with the feature that matches your current problem class and then branch out into adjacent topics (skills, territories, relations, PND, etc.).
Before you start
- If you are new to JOpt.TourOptimizer, begin with the basic examples first:
- Official documentation home:
How to run an example
All examples are plain Java classes with a main(...) method (or an equivalent entrypoint). Typical ways to run:
- Open the repository in your IDE (e.g., IntelliJ, Eclipse etc.).
- Navigate to an example package under
.../examples/advanced/.... - Run the example class (Run ▶).
Many examples subscribe to optimization event streams (progress, status, warnings, errors). If you are integrating into services or UIs, these subscriptions are the recommended entry points for telemetry and control flows.
Advanced feature index
Advanced package root: https://github.com/DNA-Evolutions/Java-TourOptimizer-Examples/tree/master/src/main/java/com/dna/jopt/touroptimizer/java/examples/advanced
| Package | What it demonstrates | Examples and deep dives |
|---|---|---|
alternatedestination | Alternate start/end locations for routes (alternate destination). | AlternateDestinationExample.java · AlternateDestinationExample.md |
autofilter | Automatic pre-filtering of nodes that are very likely infeasible (time windows, skills, etc.) to speed up optimization. | AutoFilterLateExample.java · AutoFilterParticularNodeExample.java · AutoFilter.md · ref · ref |
clustering | Clustering-based construction of an initial solution (city-to-city, inner-city, keeping clusters during optimization). | ClusteringCityToCityExample.java · ClusteringCityToCityKeepClustersForOptimizationExample.java · +1 more · Clustering.md · ref |
co2emission | Minimize CO₂ emissions by defining resource emission factors and optimizing accordingly. | CO2EmissionOptimizationExample.java · CO2EmissionOptimization.md · ref |
condition | Binding and excluding resources for nodes; skills/type constraints including expertise levels and cost models. | MandatoryResourceConditionExample.java · PreferredResourceConditionExample.java · +5 more · BindingExcludingResourceCondition.md · ResourceType.md · ref |
constraintaliasid | Constraint Alias IDs to model teams and group-based mandatory assignment rules. | ResourceConstraintAliasIdExample.java · ResourceConstraintAliasId.md |
extrainfo | Attach structured extra information to nodes/resources (e.g., store JSON-encoded POJOs). | ExtraInfoExample.java · NodeExtraInfo.java · +1 more · ExtraInfo.md |
firstlastnode | Influence first/last placement using importance values (soft steering, not hard fixing). | FirstLastNodeExample.java · FirstLastNode.md |
includevisitduration | Arrival windows vs finish-within windows: include visit duration into time windows. | IncludeVisitDurationExample.java · IncludeVisitDuration.md |
jointvisitduration | Reduce total service time for colocated nodes via joint visit duration. | JointVisitDurationExample.java · JointVisitDuration.md |
looprun | Run optimization stages in loops to implement external convergers or stop criteria. | RunOptimizationInLoopExample.java · RunOptimizationInLoop.md |
openclosedroute | Open vs closed routes: end at last node vs return to home. | OpenClosedRouteExample.java · OpenClosedRoute.md |
openlocation | Use Open Location Codes (Plus Codes) instead of latitude/longitude. | OptimizationWithOpenLocationCodesExample.java · LatLon2PlusCodeBackAndForthExample.java · OpenLocationCode.md · ref |
overnightstay | Multi-day routing with overnight stays (“stay out”) and stay policies. | OvernightStayExample.java · OvernightStay.md |
performancemode | Performance mode for faster optimization on easy/low-restriction instances. | PerformanceModeExample.java · PerformanceModeBigOptiExample.java · PerformanceMode.md · ref |
pickupanddelivery | Pickup & Delivery (PND): classic PND, fuzzy fulfillment, timed loads, flex loads, manufacturing planning, report extraction. | PNDSimpleExample.java · PNDSimpleFuzzyExample.java · +8 more · PND.md · ref |
progressfrequency | Progress reporting frequency and requesting progress snapshots at arbitrary times. | ChangeOnProgressDefaultFrequencyExample.java · RequestOnProgressViaExternalTimeExample.java · OptimizationProgress.md |
readoutfullprogress | Extract full progress KPIs from the progress object (manual vs ParsedProgress util). | ReadOutFullProgressExample.java · ReadOutFullProgressWithUtilExample.java · ReadOutFullProgress.md |
relationship | Node relations: same route/visitor, different route/visitor, and relative time window relations; can be combined. | SameRouteRelationExample.java · SameVisitorRelationExample.java · +5 more · Relations.md |
requestresult | Request an intermediate best-so-far result while the optimization is still running. | RequestResultExample.java · RequestResult.md |
return2start | Return2Start: force intermediate returns to the resource home between visits (with dwell time). | ReturnStartExample.java · ReturnStart.md · ref |
visitdurationefficiency | Resource visit duration efficiency: faster/slower resources, minimum visit duration caps, fixed-duration nodes. | ResourceVisitDurationEfficiencyExample.java · ResourceVisitDurationEfficiency.md |
waitonearlyarrival | Allow working immediately on early arrival, but enforce waiting for the first node of a route. | WaitOnEarlyArrivalFirstNodeExample.java · WaitOnEarlyArrivalFirstNode.md |
zonecode | Define territories via ZoneCodes / ZoneNumbers; territories can vary per WorkingHours; border nodes can have multiple codes. | UKPostCodeExample.java · ZoneNumberConstraintExample.java · ZoneConde.md · ref |
zonecrossing | Penalize crossings between zones (bridges/tunnels) to prevent zig-zag routes across costly borders. | BridgeTunnelCrossingZoneNumberConstraintExample.java · BridgeTunnelCrossingZoneNumberConstraint.md · ref |
Guidance on selecting the right feature
If your main pain is runtime
- Start with AutoFilter (remove infeasible nodes early) and Performance Mode (reduced genetic operator set).
- If your instance grows large, evaluate Clustering construction for better initial solutions and faster convergence.
If you need strong business rules (structural feasibility)
- Use Relations for coupling nodes across route/resource/time.
- Use ZoneCodes for territories (hard or soft) and ZoneCrossing to discourage expensive boundary crossings.
- Use Return2Start or OvernightStay to model operationally mandatory depot returns or multi-day tours.
If you optimize logistics flows, not just routes
- Use Pickup & Delivery (PND) when feasibility depends on load state (underload/overload), timed transport, or production planning.
Notes on documentation files
For many packages, this repository includes a dedicated Markdown document placed alongside the example sources. These documents are intended to be copied into other environments and provide:
- conceptual explanation of the feature,
- implementation guidance and modeling patterns,
- links back to the corresponding Java example(s) and official documentation.
If you are maintaining an internal knowledge base, these Markdown files can be used directly as reference pages.
Authors
A product by DNA Evolutions
https://www.dna-evolutions.com
Setting the JOpt License — setLicenseJSON(...) in Java
This document explains how to configure the optimization license for JOpt TourOptimizer (Java) and how the repository example SetLicenseExample applies it.
Alternate Destination — AlternateDestinationExample
This advanced example shows how to terminate a resource route at an alternate destination instead of the resource’s home/start location.