public IGraphColoringSolution Optimize() { GraphColoringSolution bestSolution = null; var solutionInfeasible = false; var maxColorsAllowed = _nodeAndArcRepository.GetAllNodes().Count(); while (!solutionInfeasible) { var domainStore = new DomainStore(_nodeAndArcRepository.GetAllNodes(), maxColorsAllowed); var scoringFunction = new LexicographicScoringFunction(_nodeAndArcRepository.GetAllNodes(), maxColorsAllowed); var solution = new GraphColoringSolution(); var firstNode = scoringFunction.GetNewNode(); solutionInfeasible = _searchAlgorithm.SearchFurther(firstNode, 0, domainStore, scoringFunction, solution); if (!solutionInfeasible) { bestSolution = solution; maxColorsAllowed = solution.GetColorsUsed(); } //solutionInfeasible = true; } return(bestSolution); }
private void CreateArcs() { foreach (var node1 in _nodeAndArcRepository.GetAllNodes()) { foreach (var node2 in _nodeAndArcRepository.GetAllNodes()) { if (node1.Equals(node2)) { continue; } _nodeAndArcRepository.AddArc(node1.Id, node2.Id); } } }
public async Task WriteSolution(IGraphColoringSolution solution) { var sb = new StringBuilder(); sb.AppendLine($"{solution.GetColorsUsed()} 0"); foreach (var node in _nodeAndArcRepository.GetAllNodes()) { sb.Append($"{solution.GetSolution(node)} "); } await _dtoStore.WriteSolution(sb.ToString()); }
public void CreateRoute() { Route route = null; foreach (var node in _nodeAndArcRepository.GetAllNodes()) { if (route == null) { route = new Route(new List <Node> { node }); _routeRepository.AddRoute(route); } else { var stops = _bestInsertion.AddNodeToRoute(node, route.Nodes, out double changeInCost); route.UpdateRoute(stops, route.Cost + changeInCost); } } }