public async Task <int> ExecuteAsync()
        {
            var edges = await getEdges.ExecuteAsync();

            var nodes = await _getNodes.ExecuteAsync();

            var adjMatrix = new AdjacencyMatrix(nodes.Select(s => s.Id).ToArray(), edges.ToArray());

            var identity        = adjMatrix.Identity();
            var identitiesEqual = await IsEqualToLastIdentityAsync(identity);

            if (identitiesEqual)
            {
                return(await GetCenterIdAsync());
            }

            var service = new LogisticCenterService(adjMatrix);
            var nodeId  = service.CalculateLogisticCenter();

            await this.UpsertIdAsync(nodeId);

            await this.UpsertIdentityAsync(identity);

            return(nodeId);
        }
Example #2
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var data = await getNodes.ExecuteAsync();

                return(new JsonResult(data));
            }
            catch (Exception e)
            {
                return(BadRequest("Could not fetch settlements"));
            }
        }