Load a Snapshot and Add a Pillar: LoadOptimizationFromJsonAndReassignPillar
This example loads a saved optimization state from myopti.json.bz2 and adds one pillar node (a fixed appointment) to it before the next run. It shows how a planned state can take a new appointment with a strict time window without rebuilding the model.
Links
- Example source (GitHub):
LoadOptimizationFromJsonAndReassignPillar.java - Overview of all load and save examples in this package:
LoadAndSaveOptimization.md - Pillar nodes in general:
Pillar.md
Before you run it
The example reads myopti.json.bz2 from the working directory. Run SaveOptimizationToJsonExample first, in the same working directory; it writes that file at the end of its run.
If the file is missing, the example prints:
JsonFile not existing. Run example 'SaveOptimizationToJsonExample.java' first.
followed by the stack trace of the FileNotFoundException, and does not start a run.
Execution flow
example() does the following:
- Sets the license via
ExampleLicenseHelper.setLicense(this); - Loads the snapshot into this optimization:
IOptimizationImporter importer = new OptimizationJSONImporter();importer.update(jsonFile, opti);
- Adds the pillar through reassignment:
this.addReassignNodes(getAdditionalNodes());
- Sets the properties for the new run via
setProperties(). - Starts the run with
startRunAsync().get()and prints the result inonAsynchronousOptimizationResult(...).
The added pillar
getAdditionalNodes() creates one PillarTimeWindowGeoNode:
- id:
Koeln-Pillar - position: 50.9333, 6.95 (the coordinates the other examples use for Koeln)
- opening hours: March 7, 2020, 08:00 to 17:00 (Europe/Berlin)
- visit duration: 20 minutes
IPillarNode koeln =
new PillarTimeWindowGeoNode("Koeln-Pillar", 50.9333, 6.95, weeklyOpeningHours.get(0), visitDuration);
The code does not attach the pillar to a resource (there is no attachResource(...) call, unlike in PillarExample).
A pillar is a fixed appointment: its time window must be met. addReassignNodes(...) hands the pillar to the loaded optimization, so the next run plans it together with the elements from the snapshot.
Solver properties
setProperties() registers:
JOptExitCondition.JOptGenerationCount = 2000JOpt.Algorithm.PreOptimization.SA.NumIterations = 100000JOpt.Algorithm.PreOptimization.SA.NumRepetitions = 1JOpt.NumCPUCores = 4
Related examples
LoadOptimizationFromJsonAndReassignNodes: the same pattern with three ordinary time-window nodes instead of a pillar.LoadOptimizationToFreshRunExample: loads the snapshot but ignores its solution.PillarExample: pillars attached to resources, built from scratch.
How to run
- Run the
main(String[] args)method ofSaveOptimizationToJsonExample. - Run the
main(String[] args)method ofLoadOptimizationFromJsonAndReassignPillarin the same working directory.
Load and Save Optimization Snapshots (JSON / JSON.BZ2) — JOpt TourOptimizer (Java)
This document consolidates and explains the load/save patterns demonstrated by the io_03 examples. It is written as a practical reference for building restartable, recoverable, and portable optimization runs.
Pillar Nodes (Captured Nodes) — Hard Constraints Fulfilled by Architecture
A CapturedNode (also called a Pillar / PillarNode) models an absolute, non-negotiable constraint: its SLA (OpeningHours / time window) must be met.