예제 #1
0
        //Properties

        public InputData(string filePath)
        {
            //int linesRead = 0;
            int tempCount = 0;
            int rideId    = 0;

            using (StreamReader str = new StreamReader(filePath))
            {
                while (!str.EndOfStream)
                {
                    if (tempCount == 0)
                    {
                        string nextLine = str.ReadLine();

                        string[] lineData = nextLine.Split(' ');
                        City               = new CityGrid();
                        City.Rows          = Convert.ToInt32(lineData[0]);
                        City.Columns       = Convert.ToInt32(lineData[1]);
                        City.VehiclesCount = Convert.ToInt32(lineData[2]);
                        City.RidesCount    = Convert.ToInt32(lineData[3]);
                        tempCount          = City.RidesCount;
                        City.Bonus         = Convert.ToInt32(lineData[4]);
                        City.Steps         = Convert.ToInt32(lineData[5]);
                        City.Rides         = new List <Ride>();//will be added in following rows
                    }

                    else
                    {
                        string nextLine = str.ReadLine();

                        string[] lineData = nextLine.Split(' ');
                        int      rid      = rideId;
                        rideId++;
                        int  a    = Convert.ToInt32(lineData[0]);
                        int  b    = Convert.ToInt32(lineData[1]);
                        int  x    = Convert.ToInt32(lineData[2]);
                        int  y    = Convert.ToInt32(lineData[3]);
                        int  eS   = Convert.ToInt32(lineData[4]);
                        int  lF   = Convert.ToInt32(lineData[5]);
                        Ride ride = new Ride(rid, a, b, x, y, eS, lF);
                        City.Rides.Add(ride);
                        tempCount--;
                    }
                }
            }
        }
예제 #2
0
        // find vehicle without ride, find "best" ride for this vehicle
        // Go through rides
        // find ride that we can reach early enough
        // calculate event times
        private void FindRides()
        {
            foreach (var v in Vehicles)
            {
                if (v.WithoutRide)
                {
                    Ride r = FindRide(v);
                    if (r != null)
                    {
                        // The vehicle is going to do this ride.
                        v.ActiveRide = r;
                        Rides.Remove(r); // Remove from list of all.
                        v.Rides.Add(r);  // Add to vehicle list.
                        v.EmptyRideToRow        = r.StartRow;
                        v.EmptyRideToColumn     = r.StartColumn;
                        v.PassengerRideToRow    = r.FinishRow;
                        v.PassengerRideToColumn = r.FinishColumn;

                        // NextEvent is the step, in which we delivered the passenger.
                        int emptyRide     = Distance(v.ActualPosRow, v.ActualPosColumn, r.StartRow, r.StartColumn);
                        int passengerRide = Distance(r.StartRow, r.StartColumn, r.FinishRow, r.FinishColumn);

                        if (StepNo + emptyRide < r.EarliestStart)
                        {
                            v.NextEvent = r.EarliestStart + passengerRide;
                        }
                        else
                        {
                            v.NextEvent = StepNo + emptyRide + passengerRide;
                        }

                        HashSet <Vehicle> value;
                        if (VehicleEvents.TryGetValue(v.NextEvent, out value))
                        {
                            value.Add(v);
                        }
                        else
                        {
                            HashSet <Vehicle> hsv = new HashSet <Vehicle>();
                            hsv.Add(v);
                            VehicleEvents.Add(v.NextEvent, hsv);
                        }
                    }
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            var lines = File.ReadAllLines(args[0]);

            ParseFirst(lines[0], out var rows, out var cols, out var vehicles, out var rideCount, out var bonus, out var steps);

            var rides = lines
                        .Skip(1)
                        .Select((line, i) => Ride.Parse(line, i))
                        .ToList();

            var cars = Enumerable
                       .Range(0, vehicles)
                       .Select(i => new Car {
                index = i
            })
                       .ToList();

            RunSimulation(ClosestStrategy, rides, cars, bonus, steps);
        }
예제 #4
0
 public int DistanceTo(Ride ride)
 {
     return(Math.Abs(ride.a - x0) + Math.Abs(ride.b - y0));
 }
예제 #5
0
 public void DriveToFinishIntersaction(Ride ride)
 {
     stepsOfVehicle += ride.Distance;
     x0              = ride.x;
     y0              = ride.y;
 }
예제 #6
0
 public void DriveToStartIntersaction(Ride ride)
 {
     stepsOfVehicle = stepsOfVehicle + Math.Abs(ride.a - x0) + Math.Abs(ride.b - y0);
     x0             = ride.a;
     y0             = ride.b;
 }
예제 #7
0
 public bool IsCurrentStepEarlier(Ride ride)
 {
     return(stepsOfVehicle < ride.EarliestStart);
 }
예제 #8
0
 public RideScore(Ride ride, double score)
 {
     Ride  = ride;
     Score = score;
 }
예제 #9
0
 public static int WhichIsCloser(List <Vehicle> vehicles, Ride ride)
 {
     return(vehicles.OrderBy(v => v.DistanceTo(ride)).First().Id);
 }