static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Path points = PathStorage.LoadPath("..\\..\\TestFiles\\Input.txt"); foreach (Point3D point in points) { Console.WriteLine(point); } Console.WriteLine(Point3D.Origin); double shortestDistance = Double.MaxValue; for (int i = 0; i < points.Count - 1; i++) { for (int j = i + 1; j < points.Count; j++) { double distance = DistanceFinder.CalcDistance(points[i], points[j]); if (shortestDistance > distance) { shortestDistance = distance; } } } Console.WriteLine("The distance between the closest points is {0:F2}.", shortestDistance); }
static void Main(string[] args) { int verticesCount = Convert.ToInt32(Console.ReadLine()); int pairsToFindCount = Convert.ToInt32(Console.ReadLine()); List <int[]> pairsToFind = new List <int[]>(); Dictionary <int, List <int> > graph = new Dictionary <int, List <int> >(); for (int i = 0; i < verticesCount; i++) { string input = Console.ReadLine(); int key = Convert.ToInt32(input.Split(':')[0]); List <int> children = new List <int>(); try { children = input.Split(':')[1].Split(' ').Select(x => Convert.ToInt32(x)).ToList(); } catch (Exception) { }//Preventing throwing exception graph.Add(key, children); } for (int y = 0; y < pairsToFindCount; y++) { pairsToFind.Add(Console.ReadLine().Split('-').Select(x => Convert.ToInt32(x)).ToArray()); } List <int> result = new List <int>(); var distanceFinder = new DistanceFinder(graph); for (int i = 0; i < pairsToFindCount; i++) { var solution = distanceFinder.FindShortestPath(pairsToFind[i][0], pairsToFind[i][1]); Console.WriteLine("Distance: " + solution.Keys.ElementAt(0)); Console.WriteLine(string.Join(",", solution.Values.ElementAt(0))); } }
public float GetDistanceFromCity(Address destinationAddress) { var distanceFromCity = 0.0f; var distanceFinder = new DistanceFinder(); var url = string.Empty; try { url = distanceFinder.GetUrl(startingAddress, destinationAddress); } catch (ArgumentNullException) { // part of the address was not supplied distanceFromCity = 0.0f; } catch (Exception) { throw; } if (!string.IsNullOrEmpty(url)) { var response = distanceFinder.GetWebResponse(url); distanceFromCity = distanceFinder.GetDistance(response); } return(distanceFromCity); }
public void Part1_Example() { var firstWirePath = "R8,U5,L5,D3".ToPath(); var secondWirePath = "U7,R6,D4,L4".ToPath(); var distance = DistanceFinder.FindMinManhattanDistance(firstWirePath, secondWirePath); Assert.Equal(6, distance); }
public void Part2_Example() { var firstWirePath = "R8,U5,L5,D3".ToPath(); var secondWirePath = "U7,R6,D4,L4".ToPath(); var distance = DistanceFinder.FindFewestSteps(firstWirePath, secondWirePath); Assert.Equal(30, distance); }
public DistanceFinder GET(string id) { DistanceFinder distance = _distance.Find_Value(id); if (distance == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(distance); }
public ActionResult EditActivity(ActivityModel model) { ActivityModel activity = db.Activity.Find(model.Id); activity.Name = model.Name; activity.Invitees = model.Invitees; activity.TimeStart = DateTime.Now; activity.TimeEnd = DateTime.Now.AddMinutes(model.ActivityLength); activity.CostPerUser = model.CostPerUser; activity.Area = DistanceFinder.ConvertInviteeArea(model.Area); db.SaveChanges(); return(RedirectToAction("ViewActivities")); }
public ActionResult DisplayUsers() { DisplayUsersViewModel main = new DisplayUsersViewModel(); try { var UserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); double userLatitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Latitude).First(); double userLongitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Longitude).First(); int users100ft = 0; int users300ft = 0; int users1000ft = 0; int usersHalf = 0; int usersMile = 0; int users5Mile = 0; foreach (var activeUser in db.Checkin.Where(n => n.Active == true).Where(n => n.UserId != UserId)) { double userDistance = DistanceFinder.FindActivitiesDistance(userLatitude, userLongitude, activeUser.Latitude, activeUser.Longitude); if (userDistance < .00036) { users100ft += 1; } if (userDistance < .00109) { users300ft += 1; } if (userDistance < .00363) { users1000ft += 1; } if (userDistance < .00958) { usersHalf += 1; } if (userDistance < .01916) { usersMile += 1; } if (userDistance < .09581) { users5Mile += 1; } } string usersDistance = DistanceFinder.ConstructUsersDistance(users100ft, users300ft, users1000ft, usersHalf, usersMile, users5Mile); main.Users_Distance = usersDistance; } catch { main.Users_Distance = null; } return(PartialView(main)); }
public void TestCalcDistance() { Path points = new Path(); Point3D point1 = new Point3D(0, 0, 0); points.Add(point1); Point3D point2 = new Point3D(1, 1, 0); points.Add(point2); double distance = DistanceFinder.CalcDistance(points[1], points[0]); Assert.AreEqual(1.41, Math.Round(distance, 2)); }
public ActionResult CreateActivity(ActivityModel model) { var UserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); ActivityModel newActivity = new ActivityModel(); newActivity.Name = model.Name; newActivity.CostPerUser = model.CostPerUser; if (model.CostPerUser == 0) { newActivity.CostPerUser = 0; } newActivity.Invitees = model.Invitees; newActivity.CreatorId = UserId; newActivity.Description = model.Description; newActivity.TimeStart = DateTime.Now; newActivity.TimeEnd = DateTime.Now.AddMinutes(model.ActivityLength); newActivity.Area = DistanceFinder.ConvertInviteeArea(model.Area); newActivity.Active = true; newActivity.Latitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Latitude).First(); newActivity.Longitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Longitude).First(); //User can only have one created activity at a time try { foreach (var row in db.Activity) { if (row.CreatorId == UserId && row.Active == true) { row.Active = false; } } } catch { } //create null entries in db.UserToActivity for each invitee for (int i = 0; i < model.Invitees; i++) { UserToActivityModel userToActivity = new UserToActivityModel(); userToActivity.ActivityId = model.Id; userToActivity.UserId = null; db.UserToActivity.Add(userToActivity); } db.Activity.Add(newActivity); db.SaveChanges(); return(RedirectToAction("ViewActivities")); }
public ActionResult ViewActivities(UserToActivityModel model) { //inactivate checkins over an hour old foreach (var row in db.Checkin.Where(n => n.Active == true)) { if (DateTime.Now >= row.CheckinTime.AddHours(1)) { row.Active = false; } } //inactivate activities past their expiration times foreach (var row in db.Activity.Where(n => n.Active == true)) { if (DateTime.Now >= row.TimeEnd) { row.Active = false; } } db.SaveChanges(); var UserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); MainPageViewModel main = new MainPageViewModel(); main.Messages = new List <string>(); main.ActivityJoined = model.Id; main.UserId = UserId; // find out if user is checked in foreach (var checkin in db.Checkin.Where(n => n.Active)) { if (checkin.UserId == UserId) { main.CheckedIn = true; break; } else { main.CheckedIn = false; } } // create available activities main.Activities_Invitees = new List <Activity_InviteesViewModel>(); main.UserToActivity = new List <UserToActivityModel>(); foreach (var row in db.UserToActivity.Where(n => n.UserId == UserId)) { main.UserToActivity.Add(row); } ActivitiesViewModel activities = new ActivitiesViewModel(); activities.Activities = new List <ActivityModel>(); foreach (var activity in db.Activity.Where(n => n.Active == true)) { activities.Activities.Add(activity); } try { double userLatitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Latitude).First(); double userLongitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Longitude).First(); foreach (var activity in activities.Activities) { //find activites within creator's specified area double activityDistance = DistanceFinder.FindActivitiesDistance(userLatitude, userLongitude, activity.Latitude, activity.Longitude); if (activityDistance <= activity.Area) { Activity_InviteesViewModel activity_Invitees = new Activity_InviteesViewModel(); activity_Invitees.Activity = activity; activity_Invitees.Distance = DistanceFinder.ConvertActivityDistance(activityDistance); activity_Invitees.timeStart = activity_Invitees.Activity.TimeStart.ToShortTimeString(); activity_Invitees.timeEnd = activity_Invitees.Activity.TimeEnd.ToShortTimeString(); //find users that joined that same activity. List <string> invitees = new List <string>(); foreach (var invitee in db.UserToActivity.Include(n => n.User)) { if (invitee.ActivityId == activity.Id && invitee.UserId != null) { //Ratings Joiner joiner = new Joiner(invitee.User.FirstName, invitee.User.Rating, invitee.User.RatingCount, invitee.Message); string listInvitee = joiner.CreateRatingString(); invitees.Add(listInvitee); //Messages if (invitee.Message != null) { string message = joiner.CreateMessageString(); main.Messages.Add(message); } } } activity_Invitees.Invitees = new SelectList(invitees); main.Activities_Invitees.Add(activity_Invitees); ViewData["Joined"] = new SelectList(invitees); foreach (var row in main.UserToActivity) { if (row.ActivityId == activity.Id) { main.ActivityJoined = row.ActivityId; } } } } } catch { } return(View(main)); }
public void Initialize() { testDistanceFinder = new DistanceFinder(); testDistanceResponse = File.ReadAllText(@"C:\Users\Dj Music\Documents\Visual Studio 2015\Projects\Property Finder App\Supplied files\TestDistanceResponse.html"); }
public DistanceFinder Post(DistanceFinder value) { DistanceFinder distance = _distance.Insert_Values(value); return(distance); }