Examples : LoadSolutionExample.cs
using System;
using VRSolver;
namespace Examples
{
/// <summary>
/// An example showing how to load an existing Solution and pass an
/// initial Solution to the Solver to start solving from.
/// </summary>
internal class LoadSolutionExample
{
internal void Start()
{
string problemFile = "ExampleData\\Demo-A.json";
//
// Load the Problem from a JSON data file
//
Problem problem = Problem.Load(problemFile);
//
// Create the Solver and solve the Problem
//
Solver solver = new Solver
{
// Set the maximum time to give the solver
MaximumSolveTime = new TimeSpan(0, 0, 5)
};
//
// The Solve method returns a Solution object which lists the Job
// assignments and schedules for each Resource
//
Console.WriteLine("Solver started...");
Solution solution = solver.Solve(problem);
Console.WriteLine("Solver finished. Solution = " + solution.ObjectiveFunctionValue);
//
// Save the solution to a text file
//
solution.Save("solution_out.txt");
//
// Load a new solution from the text file just written
//
Solution solutionCopy = Solution.Load(problemFile, "solution_out.txt");
Console.WriteLine("New solution loaded. New Solution = " + solution.ObjectiveFunctionValue);
//
// Call the solver again but this time giving it an initial
// solution to start from.
//
Solution newSolution = solver.Solve(solutionCopy);
Console.WriteLine("Solver finished. Solution = " + newSolution.ObjectiveFunctionValue);
//
// Write the solution to text file
//
WriteSolutionExample.WriteSolution(newSolution, "NewSolution.txt");
}
}
}