コード例 #1
0
 public emu_utilization_ans(emu_utilization_ans _ans)
 {
     if (_ans.emu != null)
     {
         emu = new emu_calculate_data(_ans.emu);
     }
     else
     {
         emu = null;
     }
     if (_ans.trip != null)
     {
         trip = new trip_calculate_data(_ans.trip);
     }
     else
     {
         trip = null;
     }
     maintain = _ans.maintain;
 }
コード例 #2
0
            public emu_utilization_ans(emu_calculate_data _emu, trip_calculate_data _trip, maintenance_routine _maintain)
            {
                if (_emu != null)
                {
                    emu = new emu_calculate_data(_emu);
                }
                else
                {
                    emu = null;
                }

                if (_trip != null)
                {
                    trip = new trip_calculate_data(_trip);
                }
                else
                {
                    trip = null;
                }

                maintain = _maintain;
            }
コード例 #3
0
        public void search_utilize(int _n, List <List <emu_calculate_data> > train_in_station, List <queuing_train> in_depot, List <queuing_train> transfering)
        {
            if (utilize_complete == true)
            {
                return;
            }
            if (_n < trip_data.Count)
            {
                // deep copy
                Queue <List <emu_calculate_data> > _trains = new Queue <List <emu_calculate_data> >(train_in_station);
                for (int k = 0; k < _trains.Count; k++)
                {
                    _trains = new Queue <emu_calculate_data>(train_in_station[k]);
                    for (int l = 0; l < _trains[k].Count; l++)
                    {
                        _trains[k][l] = new emu_calculate_data(train_in_station[k][l]);
                    }
                }

                Queue <queuing_train> _transfering = new Queue <queuing_train>();
                for (int k = 0; k < transfering.Count; k++)
                {
                    _transfering.Add(new queuing_train(transfering[k].emu, transfering[k].queue_time));
                }

                Queue <queuing_train> _in_depot = new Queue <queuing_train>();
                for (int k = 0; k < in_depot.Count; k++)
                {
                    _in_depot.Enqueue(new queuing_train(in_depot[k].emu, in_depot[k].queue_time));
                }

                trip_calculate_data _trip = trip_data[_n];
                int current_time          = _trip.depart_time;
                int arrival_cnt           = 0;

                // check if train arrived and depot necessary
                for (int j = 0; j < _transfering.Count; j++)
                {
                    // train arrived
                    if (_transfering[j].queue_time < current_time)
                    {
                        arrival_cnt++;
                        emu_calculate_data _arrived_train = _transfering[j].emu;
                        utilization_ans.Add(new emu_utilization_ans(_transfering[j].emu, _trip, null));
                        utilization_ans.Last().trip.used_distance = 0;
                        utilization_ans.Last().trip.arrival_time = _transfering[j].queue_time;

                        //Console.WriteLine(transfering[j].emu.name + " arrived at " + planning_sch[transfering[j].emu.location].station_name);

                        // go to depot
                        if (_arrived_train.next_maintain < main_tain_threshold)
                        {
                            _arrived_train.last_maintain += _arrived_train.maintenamce_plan.level[0].used_distance;
                            _arrived_train.next_maintain  = _arrived_train.maintenamce_plan.level[0].used_distance;
                            int maintain_index = 0;
                            for (int k = 0; k < _arrived_train.maintenamce_plan.level.Count; k++)
                            {
                                maintenance_routine _routine = _arrived_train.maintenamce_plan.level[k];
                                if (_arrived_train.last_maintain % _routine.used_distance == 0)
                                {
                                    maintain_index = k;
                                }
                            }

                            //Console.WriteLine(transfering[j].emu.name + " go to depot for " + _arrived_train.maintenamce_plan.level[maintain_index].name);
                            arrival_cnt++;
                            utilization_ans.Add(new emu_utilization_ans(_arrived_train, _trip, _arrived_train.maintenamce_plan.level[maintain_index]));
                            utilization_ans.Last().trip.depart_time = _transfering[j].queue_time;
                            _in_depot.Add(new queuing_train(_transfering[j].emu, _transfering[j].queue_time + ((_arrived_train.maintenamce_plan.level[maintain_index].maintain_time + 1) * 24 * 60 * 60)));
                        }
                        // go to station
                        else
                        {
                            _trains[_transfering[j].emu.location].Add(_transfering[j].emu);
                        }

                        _transfering.RemoveAt(j);
                        j = -1;
                    }
                }

                // check if train arrival from depot
                for (int j = 0; j < _in_depot.Count; j++)
                {
                    if (_in_depot[j].queue_time < current_time)
                    {
                        arrival_cnt++;
                        emu_calculate_data _arrived_train = _in_depot[j].emu;
                        utilization_ans.Add(new emu_utilization_ans(_in_depot[j].emu, _trip, _in_depot[j].emu.maintenamce_plan.level[0]));
                        utilization_ans.Last().trip.used_distance = 0;
                        utilization_ans.Last().trip.arrival_time = _in_depot[j].queue_time;

                        //Console.WriteLine("hi");

                        _trains[_in_depot[j].emu.location].Add(_in_depot[j].emu);
                        _in_depot.RemoveAt(j);
                        j = -1;
                    }
                }

                // select the lowest distance train to use

                if (_trains[_trip.origin_station].Count > 0)
                {
                    _trains[_trip.origin_station].Sort((x, y) => (y.used_distance.CompareTo(x.used_distance)));

                    for (int j = 0; j < _trains[_trip.origin_station].Count; j++)
                    {
                        int last_location = _trains[_trip.origin_station][j].location;
                        utilization_ans.Add(new emu_utilization_ans(_trains[_trip.origin_station][0], _trip, null));

                        //select emu
                        _trains[_trip.origin_station][j].location       = _trip.destination_station;
                        _trains[_trip.origin_station][j].used_distance += _trip.used_distance / 1000;
                        _trains[_trip.origin_station][j].used_time     += _trip.used_time / 1000;
                        _trains[_trip.origin_station][j].next_maintain -= _trip.used_distance / 1000;
                        _trains[_trip.origin_station][j].in_use         = true;

                        ///Console.WriteLine("use " + _trains[_trip.origin_station][j].name + " as " + _trip.name + " from " + planning_sch[_trip.origin_station].station_name + " to " + planning_sch[_trip.destination_station].station_name);

                        _transfering.Add(new queuing_train(_trains[_trip.origin_station][j], _trip.arrival_time));
                        _trains[_trip.origin_station].RemoveAt(j);

                        //Console.WriteLine(_n.ToString() + ":" + j.ToString());

                        search_utilize(_n + 1, _trains, _in_depot, _transfering);

                        _trains[_trip.origin_station].Insert(j, new emu_calculate_data(_transfering.Last().emu));
                        _trains[_trip.origin_station][j].used_distance -= _trip.used_distance / 1000;
                        _trains[_trip.origin_station][j].used_time     -= _trip.used_time / 1000;
                        _trains[_trip.origin_station][j].next_maintain += _trip.used_distance / 1000;
                        _trains[_trip.origin_station][j].location       = last_location;
                        _transfering.RemoveAt(_transfering.Count - 1);


                        utilization_ans.RemoveAt(utilization_ans.Count - 1);
                    }
                    //Console.WriteLine("use " + train_in_station[_trip.origin_station].First().name + " as " + _trip.name + " from " + planning_sch[_trip.origin_station].station_name + " to " + planning_sch[_trip.destination_station].station_name);
                }
                else
                {
                    //Console.WriteLine("no train in station wtf can i do???");
                    //return;
                }

                // remove arrival report
                for (int i = 0; i < arrival_cnt; i++)
                {
                    utilization_ans.RemoveAt(utilization_ans.Count - 1);
                }
            }
            else
            {
                // found solution f*****g deep copy!!!

                utilization_output.Clear();
                foreach (emu_utilization_ans _ans in utilization_ans)
                {
                    utilization_output.Add(new emu_utilization_ans(_ans));
                }
                foreach (queuing_train _ans in transfering)
                {
                    utilization_output.Add(new emu_utilization_ans(_ans.emu, trip_data.Last(), null));
                    utilization_output.Last().trip.used_distance = 0;
                    utilization_output.Last().trip.arrival_time = _ans.queue_time;
                }
                utilize_complete = true;
            }
        }