static public void orchestrator_of_service(TF_Demand outbound_demand, Train_obj train, List <Service> services)
 {
     for (int i = 0; i < outbound_demand.demand.Count; i++)
     {
         outbound_demand.get_demand(i);
         while (!isDemandEmpty(outbound_demand.demand[i]))
         {
             float p;
             int   s = 0;
             (s, p) = index_of_most_utilize_service(outbound_demand.cal_demand, train, services);
             Console.WriteLine("\n\nthis is CARRY_matrix \n\n\n");
             showarray(outbound_demand.carry_matrix);
             Console.WriteLine("this is PERCENT " + p);
             if (p <= 60)
             {
                 for (int out_loop = 0; out_loop < outbound_demand.dimension; out_loop++)
                 {
                     for (int in_loop = out_loop + 1; in_loop < outbound_demand.dimension; in_loop++)
                     {
                         if (outbound_demand.demand[i][out_loop, in_loop] > 0)
                         {
                             outbound_demand.carry_matrix[out_loop, in_loop] = i;
                         }
                     }
                 }
                 break;
             }
             Console.WriteLine("----IN ACTUAL ---- " + "\n\n");
             actual_run(outbound_demand, train, services[s], i);
             Console.WriteLine("----OUT ACTUAL ---- " + "\n\n");
         }
         Console.WriteLine("----END--OF--orchestrate----LOOP--- " + i + "\n\n\n\n\n");
     }
     Console.WriteLine("----END--OF--orchestrate-------- ");
 }
Пример #2
0
        public TF_Demand Gen_Inbound_demand()
        {
            TF_Demand inbound = new TF_Demand(this.interval, this.dimension, "I", "B");

            for (int k = 0; k < this.demand.Count; k++)
            {
                for (int i = 0; i < this.dimension; i++)
                {
                    for (int j = 0; j < this.dimension; j++)
                    {
                        if (i > j)
                        {
                            int m = this.dimension - 1 - i;
                            int l = dimension - 1 - j;
                            inbound.demand[k][m, l] = this.demand[k][i, j];
                        }
                        else
                        {
                            inbound.demand[k][j, i] = 0;
                        }
                    }
                }
            }
            return(inbound);
        }
Пример #3
0
 public Station(TF_Demand tf_demand)
 {
     for (int i = 0; i < tf_demand.dimension; i++)
     {
         demand_station.Add(tf_demand.To_station_class(i));
     }
 }
 static public void actual_run(TF_Demand demands, Train_obj train, Service service, int timeframe)
 {
     Console.WriteLine("ACTUAL_RUN . ");
     Console.WriteLine(service.service_id);
     Train_a_b_c_d_e(demands, train, service, timeframe);
     Console.WriteLine("This is remainning demand . ");
     showarray(demands.cal_demand);
     Console.WriteLine("This is CURRENT demand . ");
     showarray(demands.demand[timeframe]);
     Console.WriteLine("------------------ ");
 }
 public static void clear_remain_demand(TF_Demand demands, int timeframe, int i, int j)
 {
     if (demands.carry_matrix[i, j] == -1)
     {
         demands.demand[timeframe][i, j] = 0;
     }
     else
     {
         for (int k = demands.carry_matrix[i, j]; k <= timeframe; k++)
         {
             demands.demand[k][i, j] = 0;
         }
     }
 }
 public static void update_remain_demand(TF_Demand demands, int timeframe, int fill_demand, int i, int j)
 {
     if (demands.carry_matrix[i, j] == -1)
     {
         demands.demand[timeframe][i, j] -= fill_demand;
     }
     else
     {
         for (int k = demands.carry_matrix[i, j]; k <= timeframe; k++)
         {
             if (demands.demand[k][i, j] < fill_demand)
             {
                 fill_demand            -= demands.demand[k][i, j];
                 demands.demand[k][i, j] = 0;
             }
             else
             {
                 demands.demand[k][i, j] -= fill_demand;
                 return;
             }
         }
     }
 }
Пример #7
0
        public TF_Demand Gen_Outbound_demand()
        {
            TF_Demand outbound = new TF_Demand(this.interval, this.dimension, "O", "B");

            int[,] halfmatrix = new int[this.dimension, this.dimension];
            for (int k = 0; k < this.demand.Count; k++)
            {
                for (int i = 0; i < this.dimension; i++)
                {
                    for (int j = 0; j < this.dimension; j++)
                    {
                        if (i < j)
                        {
                            outbound.demand[k][i, j] = this.demand[k][i, j];
                        }
                        else
                        {
                            outbound.demand[k][i, j] = 0;
                        }
                    }
                }
            }
            return(outbound);
        }
Пример #8
0
        static void Main(string[] args)
        {
            String[] str1 = { "xxxx", "YYY" };

            List <Service> outbound_services = new List <Service>();
            List <int[]>   backward          = new List <int[]>();
            Train_obj      train             = new Train_obj(10);

            int[] service  = { 1, 0, 1, 0, 1 };
            int[] service2 = { 1, 0, 1, 0, 1 };
            //int[] service3 = { 1, 0, 0, 0, 1 };
            int[] service4 = { 1, 0, 1, 0, 1 };



            Service aService;

            aService = new Service("All_station", service);
            //add service to list
            outbound_services.Add(aService);
            outbound_services[0].show();
            aService = new Service("3_station_outbound", service2);
            outbound_services.Add(aService);
            outbound_services[1].show();
            aService = new Service("4_station_outbound_start_at_1", service4);
            outbound_services.Add(aService);
            outbound_services[2].show();



            //add demand to be time frame demand

            TF_Demand passeng_demand = new TF_Demand(720, 5);
            Station   station        = new Station(passeng_demand);

            for (int i = 0; i < passeng_demand.dimension; i++)
            {
                Service_algo.showarray(station.demand_station[i]);
            }
            TF_Demand outbound_demand = passeng_demand.Gen_Outbound_demand();
            TF_Demand inbound_demand  = passeng_demand.Gen_Inbound_demand();

            for (int i = 0; i < passeng_demand.getTF_amount(); i++)
            {
                Console.WriteLine("This is all station demand . at : " + i);
                Service_algo.showarray(passeng_demand.demand[i]);
            }

            Service_algo.orchestrator_of_service(outbound_demand, train, outbound_services);
            Console.WriteLine("This is OUTBOUND demand . ");
            Service_algo.showarray(outbound_demand.demand[0]);
            Console.WriteLine("This is INBOUND demand . ");
            Service_algo.showarray(inbound_demand.demand[0]);



            Console.WriteLine("This is unserved demand in TF demand. ");
            Service_algo.showarray(outbound_demand.unserve_demand[0]);
            Console.WriteLine("This is LAST demand . ");
            Service_algo.showarray(passeng_demand.getDemand(0));
            Console.WriteLine("This is carry matrix . ");
            Service_algo.showarray(outbound_demand.carry_matrix);
            Console.WriteLine("Sum");


            LogWriter log = new LogWriter(str1[0] + str1[1]);
        }
        public static void Train_a_b_c_d_e(TF_Demand demands, Train_obj train, Service aService, int timeframe)
        {
            int[,] actual_getoff = new int[5, 5];
            int get_off_next_station = 0;
            int i, j, k, next_station_index = -1;

            for (i = 0; i < 5; i++)
            {
                if (aService.stop_station[i] == 0)
                {
                    continue;
                }
                for (int a = 4; a > i; a--)
                {
                    if (aService.stop_station[a] == 1)
                    {
                        next_station_index = a;
                    }
                }

                int demand_at_station = 0;
                Console.WriteLine("Remainning Seat : " + train.remain_cap);
                get_off_next_station = train.passenger[i];
                Console.WriteLine("Number of getting off passenger at station " + i + " = " + get_off_next_station);
                train.getOff(i);
                Console.WriteLine("Remainning Seat after get off : " + train.remain_cap);
                for (k = i + 1; k < 5; k++) // sum of demand at station i
                {
                    if (aService.stop_station[k] == 0)
                    {
                        continue;
                    }
                    demand_at_station += demands.cal_demand[i, k];
                    Console.WriteLine("Demand at station " + i + " to station " + k + " is " + demands.cal_demand[i, k]);
                }
                Console.WriteLine("All of Demand at station " + i + " is " + demand_at_station);
                if (demand_at_station < train.remain_cap)
                {
                    for (j = i + 1; j < 5; j++)
                    {
                        if (aService.stop_station[j] == 0)
                        {
                            continue;
                        }
                        train.getOn(demands.cal_demand[i, j], j);

                        demands.cal_demand[i, j] = 0;
                        clear_remain_demand(demands, timeframe, i, j);
                    }
                }
                else
                {
                    double ratio = 1.0 * train.remain_cap / demand_at_station;
                    demand_at_station = 0;
                    int fill_demand;
                    for (j = i + 1; j < 5; j++)
                    {
                        if (aService.stop_station[j] == 0)
                        {
                            continue;
                        }

                        fill_demand = (int)(demands.cal_demand[i, j] * ratio);


                        demand_at_station += fill_demand;
                    }
                    int remain_cap = train.remain_cap;
                    remain_cap -= demand_at_station;
                    for (j = i + 1; j < 5; j++)
                    {
                        if (aService.stop_station[j] == 0)
                        {
                            continue;
                        }
                        Console.WriteLine("..............Debug train remainning seat  " + train.remain_cap);
                        Console.WriteLine("..............Debug Demand at station      " + demands.cal_demand[i, j]);
                        Console.WriteLine("..............Debug ratio      " + ratio);
                        fill_demand = (int)(demands.cal_demand[i, j] * ratio);

                        Console.WriteLine("..............Debug fill_demand  " + fill_demand);
                        actual_getoff[i, j] = fill_demand;
                        if (remain_cap > 0 && demands.cal_demand[i, j] > fill_demand)
                        {
                            demands.cal_demand[i, j] -= (fill_demand + 1);
                            train.getOn(fill_demand + 1, j);
                            update_remain_demand(demands, timeframe, fill_demand + 1, i, j);
                            remain_cap -= 1;
                        }
                        else
                        {
                            demands.cal_demand[i, j] -= fill_demand;
                            train.getOn(fill_demand, j);
                            update_remain_demand(demands, timeframe, fill_demand, i, j);
                        }
                        demand_at_station += fill_demand;
                    }
                    Console.WriteLine("..............train remainning seat AFTER  " + train.remain_cap);
                }
            }
        }