public Route SolveRecurent(DvrpProblemData problem) { Solution = new Route(); bestFound = Double.MaxValue; ///problem variables: capacity = problem.Fleet.capacity; speed = problem.Fleet.speed; clients = problem.Clients; visitedClients = new bool[clients.Length]; depot = problem.Depots[0]; for (int i = 0; i < clients.Length; ++i) { visitedClients[i] = true; var nextPath = NextNode(visitedClients, clients[i], depot.location, 0, 0, capacity, 1); if (nextPath != null) { Solution = nextPath; } visitedClients[i] = false; } Solution.Distance = bestFound; Solution.Insert(0, depot.location); Solution.Tag = problem.Tag; return(Solution); }
public override byte[] Solve(byte[] partialData, TimeSpan timeout) { State = TaskSolverState.Solving; var tspSolver = new RecurentTspSolver(); var partialProblem = DvrpProblemData.Deserialize(partialData); Route route = tspSolver.SolveRecurent(partialProblem); State = TaskSolverState.Idle; OnProblemSolvingFinished(this); return((new DvrpSolutionData() { Routes = new List <Route>() { route }, Distance = route.Distance }).Serialize()); }
public override byte[][] DivideProblem(int threadCount) { State = TaskSolverState.Dividing; solution = new DvrpSolutionData(); solution.StartTime = DateTime.Now; List <DvrpProblemData> dvrpPartialProblems = new List <DvrpProblemData>(); partialDictionary = new Dictionary <List <int>, int>(new ListComparer <int>()); var subsets = Set.GenerateAllSubsets(problem.Clients.Length); int tag = 0; foreach (var subset in subsets) { List <Client> clients = new List <Client>(); foreach (int index in subset.Elements) { clients.Add(problem.Clients[index]); } var partialProblem = new DvrpProblemData(clients.ToArray(), problem.Depots, problem.Fleet, tag); partialDictionary.Add(subset.Elements, tag); ++tag; dvrpPartialProblems.Add(partialProblem); } byte[][] dividedData = new byte[dvrpPartialProblems.Count][]; for (int i = 0; i < dvrpPartialProblems.Count; i++) { dividedData[i] = dvrpPartialProblems[i].Serialize(); } PartialProblems = dividedData; OnProblemDividingFinished(this); State = TaskSolverState.Idle; return(dividedData); }
DvrpSolutionData solution;//to be removed public DvrpTaskSolver(byte[] problemData) : base(problemData) { this.problem = DvrpProblemData.Deserialize(problemData); }