public void ProcessRequest() { List <ViaLocation> address = WPF.RandomLocationsFromOrigin(currentLocation, WPF.Rng.Next(5, 200)); destination = XML.ParseXMLToRoad(Http.Request(address)); Console.WriteLine(destination.StringTravelTime); bool drive = CalculateEarnings(); //MessageBox.Show("Driver " + id + " earned " + earning, drive.ToString(), MessageBoxButton.OK, MessageBoxImage.Information); }
public static List <ViaLocation> RandomLocationsFromOrigin(Location origin, double radius) { List <ViaLocation> viaLocations = new List <ViaLocation>(); for (int i = 0; i < 2; i++) { double lat = WPF.RandomDouble(origin.Latitude - (radius / 110.567), origin.Latitude + (radius / 110.567)); double lon = WPF.RandomDouble(origin.Longitude - (radius / 111.321), origin.Longitude + (radius / 111.321)); viaLocations.Add(new ViaLocation(lat.ToString(CultureInfo.InvariantCulture) + "," + lon.ToString(CultureInfo.InvariantCulture), i)); } return(viaLocations); }
public TaxiDriver(double currentl, double currentlo) { currentLocation = new Location(currentl, currentlo); id = globalid++; faulCost = WPF.RandomDouble(1.0, 100); startCost = WPF.RandomDouble(0.0, faulCost * 2); workSpan = WPF.RandomDouble(1.0, 10.0); workLeft = workSpan; costPerKm = WPF.RandomDouble(faulCost, faulCost * 10.0); minEarning = WPF.RandomDouble(faulCost, faulCost * 5.0); }
public MainWindow() { InitializeComponent(); Location origin = new Location(52.228683, 20.881577); List <TaxiDriver> drivers = new List <TaxiDriver>(); drivers.Add(new TaxiDriver(52.228683, 20.181577)); drivers.Add(new TaxiDriver(53.228683, 20.781577)); drivers.Add(new TaxiDriver(52.258683, 20.881577)); drivers.Add(new TaxiDriver(52.218683, 20.821577)); drivers.Add(new TaxiDriver(54.228683, 21.181577)); drivers.Add(new TaxiDriver(53.228683, 21.981577)); drivers.Add(new TaxiDriver(52.258683, 21.881577)); drivers.Add(new TaxiDriver(51.218683, 20.121577)); List <Thread> threads = new List <Thread>(); foreach (TaxiDriver driver in drivers) { Thread t = new Thread(driver.ProcessRequest); t.IsBackground = true; t.Start(); threads.Add(t); } foreach (Thread t in threads) { t.Join(); } foreach (TaxiDriver driver in drivers) { worldMap.Children.Add(WPF.DrawRoad(driver.Destination)); } }