// Update selected stops status // StopDto - nested class - properties set up @ ajax // REST API - AJAX // ~/Scripts/Apps/HomeIndex.js - updateStop() public async Task Put([FromBody] StopDto oStopDto) { var oStop = new Stop() { Key = oStopDto.Key, Customer = new Customer() { ID = oStopDto.CustomerID }, CurrentStatus = await StopStatus.Instance(oStopDto.Status) }; var oStopFactory = new StopFactory(); try { await oStopFactory.Update(oStop); } catch (Exception oException) { oException.Log("Update Stop"); this.InternalServerError(); } this.Ok(); }
private UserStoppedModel getUserStoppedModel() { UserStoppedModel modelGroupStopped = null; List <StopDto> unresolvedGroups = this.stopService.GetUnresolved(); StopDto currentUserStoppedGroup = null; foreach (StopDto unresolvedGroup in unresolvedGroups) { if (unresolvedGroup.ById == ((ClaimsPrincipal)this.User).AppUserId()) { currentUserStoppedGroup = unresolvedGroup; break; } } if (currentUserStoppedGroup != null) { List <GroupUserDto> users = this.groupService.GetUsers(currentUserStoppedGroup.GroupId); modelGroupStopped = new UserStoppedModel(this.tenantContext.FriendlyName); modelGroupStopped.Group = Mapper.Map <StopDto, GroupModel>(currentUserStoppedGroup); modelGroupStopped.Users = Mapper.Map <List <GroupUserDto>, List <Web.Models.Group.UserModel> >(users); } return(modelGroupStopped); }
public Task Stop(string packageFullName, CancellationToken cancellationToken = default) { var proxyObject = new StopDto { PackageFullName = packageFullName }; return(this.client.Invoke(proxyObject, cancellationToken)); }
protected BaseStopTimeHarmonyGenerator(IObjectiveFunction <StopTimeInfo> function, Graph <int, StopTimeInfo> graph, Location source, Location destination) : base(function) { Graph = graph ?? throw new ArgumentNullException(nameof(graph)); Destination = destination ?? throw new ArgumentNullException(nameof(destination)); Source = source ?? throw new ArgumentNullException(nameof(source)); // Set up source and destination nodes ReferentialDestinationStop = graph.GetReferenceDestinationStop(Destination.Name); SourceNodes = graph.GetSourceNodes(Source.Name, ReferentialDestinationStop); }
public StopTimePathSearcher(IStopTimePathFinder pathFinder, Graph <int, StopTimeInfo> graph, Location source, Location destination) { _pathFinder = pathFinder ?? throw new ArgumentNullException(nameof(pathFinder)); _graph = graph ?? throw new ArgumentNullException(nameof(graph)); Destination = destination ?? throw new ArgumentNullException(nameof(destination)); Source = source ?? throw new ArgumentNullException(nameof(source)); // Set up source and destination nodes _referentialDestinationStop = graph.GetReferenceDestinationStop(Destination.Name); _sourceNodes = graph.GetSourceNodes(Source.Name, _referentialDestinationStop); }
public ActionResult Stop(StopModel model) { if (ModelState.IsValid) { StopDto stop = this.stopService.Create(((ClaimsPrincipal)this.User).AppUserId(), model.GroupId, model.Reason); Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <GroupHub>() .Clients.All.groupLifeCycleStateChange(this.tenantContext.FriendlyName, Web.Models.Group.LifeCycleState.Stopped.ToString()); return(RedirectToAction("Index", "Dashboard")); } return(PartialView(model)); }
private GroupsStateModel getGroupsStateModel() { List <GroupDto> groups = this.groupService.GetGroups(); List <StopDto> stops = this.stopService.GetUnresolved(); Dictionary <Guid, StopDto> stopHash = new Dictionary <Guid, StopDto>(); if (stops != null) { stopHash = stops.ToDictionary(x => x.GroupId); } List <GroupModel> groupsState = new List <GroupModel>(); foreach (GroupDto group in groups) { GroupModel groupState = new GroupModel(); groupState.Name = group.Name; groupState.GroupId = group.Id; groupState.State = Web.Models.Group.State.Working; groupState.CanStop = group.Users.Exists(user => user.Id == ((ClaimsPrincipal)this.User).AppUserId()); if (stopHash.ContainsKey(group.Id)) { StopDto stop = stopHash[group.Id]; groupState.State = Web.Models.Group.State.Stopped; groupState.StoppedBy = stop.By; groupState.DownTime = TimeProvider.Current.UtcNow - stop.Date; groupState.StoppedDateTime = stop.Date; } groupsState.Add(groupState); } GroupsStateModel modelGroups = new GroupsStateModel(this.tenantContext.FriendlyName); modelGroups.Groups = groupsState; return(modelGroups); }
/// <summary> /// Initializes a new instance of the <see cref="StopTimeAntColonyOptimizer"/> class. /// </summary> /// <param name="function">The function.</param> /// <param name="graph">The graph.</param> /// <param name="source">The source.</param> /// <param name="destination">The destination.</param> public StopTimeAntColonyOptimizer(IObjectiveFunction <StopTimeInfo> function, Graph <int, StopTimeInfo> graph, Location source, Location destination) { _objectiveFunction = function ?? throw new ArgumentNullException(nameof(function)); _graph = graph ?? throw new ArgumentNullException(nameof(graph)); Destination = destination ?? throw new ArgumentNullException(nameof(destination)); Source = source ?? throw new ArgumentNullException(nameof(source)); // Set up source and destination nodes _referentialDestinationStop = graph.GetReferenceDestinationStop(Destination.Name); _sourceNodes = graph.GetSourceNodes(Source.Name, _referentialDestinationStop); // Set up ant colony specifics PheromoneInfluence = 0.2; EdgeCostInfluence = 1 - PheromoneInfluence; InitialPheromoneAmount = 1; PheromoneEvaporationSpeed = 0.05; // Initialize pheromone tables _pheromoneIndexes = _graph.Nodes.Values .ToDictionary(k => k.Id, k => k.Neighbors.ToDictionary(n => n.DestinationId, v => 0)); _pheromoneArray = new double[_pheromoneIndexes.Sum(n => n.Value.Count)]; var index = 0; foreach (var nodeId in _pheromoneIndexes.Keys.ToList()) { var neighborNodesPheromone = _pheromoneIndexes[nodeId]; foreach (var neighborId in neighborNodesPheromone.Keys.ToList()) { neighborNodesPheromone[neighborId] = index; _pheromoneArray[index] = InitialPheromoneAmount; index++; } } }
public async Task <StopDto> GetById(int id) { var x = await _context.Stops.Where(x => x.IsDeleted == false).FirstOrDefaultAsync(x => x.Id == id); if (x == null) { return(null); } var stop = new StopDto() { Id = x.Id, Name = x.Name, Address = x.Address, Longitude = x.Longitude, Latitude = x.Latitude, TimePickUp = x.TimePickUp, TimeDropOff = x.TimeDropOff, NumberOfStudents = x.NumberOfStudents, Status = (int)x.Status }; return(stop); }
public async Task <IActionResult> Post(string tripName, [FromBody] StopDto dto) { try { if (ModelState.IsValid) { var newStop = Mapper.Map <Stop>(dto); // Lookup the Geocodes var result = await _coordsService.GetCoordsAsync(newStop.Name); if (!result.Success) { _logger.LogError(result.Message); } else { newStop.Latitude = result.Latitude; newStop.Longitude = result.Longitude; _unitOfWork.Stops.AddStop(tripName, newStop, User.Identity.Name); if (await _unitOfWork.CompleteAsync()) { return(Created($"api/trips/{tripName}/stops/{newStop.Name}", Mapper.Map <StopDto>(newStop))); } } } } catch (Exception ex) { _logger.LogError($"Failed to save new Stop: {ex}"); } return(BadRequest("Failed to save the stop")); }
/// <summary> /// Finds the shortest path using A* algorithm /// </summary> /// <param name="graph">The graph.</param> /// <param name="source">The source.</param> /// <param name="destinationStop">Name of the destination.</param> /// <returns>Shortest path between source and destination</returns> public Path <StopTimeInfo> FindShortestPath(Graph <int, StopTimeInfo> graph, StopTimeInfo source, StopDto destinationStop) { // Initialize extended list var nodesAlreadyExtended = new List <GraphNode <int, StopTimeInfo> >(); var nodesToExtend = new Dictionary <int, GraphNode <int, StopTimeInfo> > { { source.Id, graph.Nodes[source.Id] } }; // Initialize distance lookups var cameFrom = new Dictionary <int, GraphNode <int, StopTimeInfo> >(); var nodeDistances = graph.Nodes.ToDictionary(k => k.Key, v => double.MaxValue); var distanceFromSource = new Dictionary <int, double>(nodeDistances) { [source.Id] = 0 }; var totalDistanceToDestination = new Dictionary <int, double>(nodeDistances) { [source.Id] = source.StopDto.GetDistanceTo(destinationStop) * DistanceEnhancementFactor }; // Look for paths while (nodesToExtend.Any()) { // Get node with minimum distance var currentNodeWithMinimumDistance = nodesToExtend.Aggregate((l, r) => totalDistanceToDestination[l.Key] < totalDistanceToDestination[r.Key] ? l : r).Value; // If destination is reached if (currentNodeWithMinimumDistance.Data.StopDto.Name.TrimToLower() == destinationStop.Name.TrimToLower() || currentNodeWithMinimumDistance.Id.Equals(destinationStop?.Id)) { // Reconstruct path return(ReconstructPath(currentNodeWithMinimumDistance, graph, cameFrom, source.StopDto.Name)); } nodesToExtend.Remove(currentNodeWithMinimumDistance.Id); nodesAlreadyExtended.Add(currentNodeWithMinimumDistance); foreach (var neighborEdge in currentNodeWithMinimumDistance.Neighbors) { var neighbor = graph.Nodes[neighborEdge.DestinationId]; // Ignore the neighbor which is already extended if (nodesAlreadyExtended.Contains(neighbor)) { continue; } // Calculate the distance from start to a neighbor var distanceToNeighbor = distanceFromSource[currentNodeWithMinimumDistance.Id] + neighborEdge.Cost; if (!nodesToExtend.ContainsKey(neighbor.Id)) { nodesToExtend.Add(neighbor.Id, neighbor); } // Skip neighbor if it is not better than the best minimum distance so far else if (distanceToNeighbor >= distanceFromSource[neighbor.Id]) { continue; } // This path is the best until now. Record it! cameFrom[neighbor.Id] = currentNodeWithMinimumDistance; distanceFromSource[neighbor.Id] = distanceToNeighbor; var distanceFromNeighborToDestination = neighbor.Data.StopDto.GetDistanceTo(destinationStop) * DistanceEnhancementFactor; totalDistanceToDestination[neighbor.Id] = distanceFromSource[neighbor.Id] + distanceFromNeighborToDestination; } } return(new Path <StopTimeInfo>()); }
public static List <GraphNode <int, StopTimeInfo> > GetSourceNodes(this Graph <int, StopTimeInfo> graph, string sourceName, StopDto referentialDestinationStop) { // Get source stops that have the same name var sourceStopTimesGroupedByStop = graph.Nodes.Values .Where(s => s.Data.StopDto.Name.TrimToLower() == sourceName.TrimToLower()) .GroupBy(s => s.Data.StopDto) .ToDictionary(k => k.Key, v => v.GroupBy(st => st.Data.Route) .SelectMany(gr => gr.GroupBy(st => st.Data.DirectionId) .Select(g => g.OrderBy(st => st.Data.DepartureTime) .First().Id)) .ToList()); // Calculate straight-line distance to destination var distanceToDestination = sourceStopTimesGroupedByStop.Keys .Select(s => s.GetDistanceTo(referentialDestinationStop)).Max(); var stopsWithRightDirectionIds = new List <int>(); foreach (var stopWithTimes in sourceStopTimesGroupedByStop) { // Get neighbor stops var neighborStops = stopWithTimes.Value .SelectMany(stopTimeInfoId => graph.GetNeighborsQueryable(stopTimeInfoId) .Select(n => n.Data.StopDto) .Where(s => s.Name.TrimToLower() != sourceName.TrimToLower())) .Distinct() .ToList(); if (neighborStops.Any()) { var minimumDistanceToNeighbor = neighborStops .Select(s => s.GetDistanceTo(referentialDestinationStop)) .Min(); // Take only those stops which have neighbors closer to the destination if (minimumDistanceToNeighbor < distanceToDestination) { stopsWithRightDirectionIds.Add(stopWithTimes.Key.Id); } } } // Get matching graph nodes (get only one node per route id and stop id) var filteredSourceNodes = graph.Nodes.Values .Where(s => stopsWithRightDirectionIds.Contains(s.Data.StopId)) .GroupBy(s => s.Data.StopId) .SelectMany(g => g.GroupBy(st => st.Data.Route) .SelectMany(gr => gr.GroupBy(st => st.Data.DirectionId) .Select(dg => dg.OrderBy(st => st.Data.DepartureTime).First()))) .ToList(); return(filteredSourceNodes); }