예제 #1
0
        async private void buttonGenerateGraph_Click(object sender, EventArgs e)
        {
            this.MyMF.PlayStop();
            I_NetworkGenerator network_generator = null;

            this.MyOSM.MyNetwork  = null;
            this.MyOSM.MyAgentSet = null;
            this.MyOSM.MyAlgo     = null;

            bool   seed_enable     = true;
            int    node_num        = (int)this.numericUpDownNodeNum.Value;
            int    network_seed    = (int)this.numericUpDownGraphSeed.Value;
            double rewire_p        = (double)this.numericUpDownWSrewirep.Value;
            int    degree          = (int)this.numericUpDownWSdegree.Value;
            int    attach_edge_num = (int)this.numericUpDownBAattachEdge.Value;
            int    rnd_edge_num    = (int)this.numericUpDownPCrndEdge.Value;
            double triangle_p      = (double)this.numericUpDownPCaddTriP.Value;
            double edge_creation_p = (double)this.numericUpDownEdgeCreationP.Value;
            int    grid_m          = (int)this.numericUpDownGridM.Value;
            int    grid_n          = (int)this.numericUpDownGridN.Value;

            if (this.radioButtonSmallWorld.Checked)
            {
                seed_enable = true;
                switch ((NetworkEnum)Enum.Parse(typeof(NetworkEnum), this.comboBoxSmallWorld.Text, true))
                {
                case NetworkEnum.WS:
                    network_generator = new WS_NetworkGenerator(node_num, degree, rewire_p);
                    break;

                case NetworkEnum.NewmanWS:
                    network_generator = new NewmanWS_NetworkGenerator(node_num, degree, rewire_p);
                    break;

                case NetworkEnum.ConnectedWS:
                    network_generator = new ConnectedWS_NetworkGenerator(node_num, degree, rewire_p);
                    break;
                }
            }
            else if (this.radioButtonScaleFree.Checked)
            {
                seed_enable = true;
                switch ((NetworkEnum)Enum.Parse(typeof(NetworkEnum), this.comboBoxScaleFree.Text, true))
                {
                case NetworkEnum.BA:
                    network_generator = new BA_NetworkGenerator(node_num, attach_edge_num);
                    break;

                case NetworkEnum.PowerLawCluster:
                    network_generator = new PC_NetworkGenerator(node_num, rnd_edge_num, triangle_p);
                    break;
                }
            }
            else if (this.radioButtonRandom.Checked)
            {
                seed_enable = true;
                switch ((NetworkEnum)Enum.Parse(typeof(NetworkEnum), this.comboBoxRandom.Text, true))
                {
                case NetworkEnum.ER:
                    network_generator = new ER_NetworkGenerator(node_num, edge_creation_p);
                    break;
                }
            }
            else if (this.radioButtonOther.Checked)
            {
                switch ((NetworkEnum)Enum.Parse(typeof(NetworkEnum), this.comboBoxOther.Text, true))
                {
                case NetworkEnum.Grid2D:
                    seed_enable       = false;
                    network_generator = new Grid2D_NetworkGenerator(grid_m, grid_n);
                    break;

                case NetworkEnum.Hexagonal:
                    seed_enable       = false;
                    network_generator = new Hexagonal_NetworkGenerator(grid_m, grid_n);
                    break;

                case NetworkEnum.Triangular:
                    seed_enable       = false;
                    network_generator = new Triangular_NetworkGenerator(grid_m, grid_n);
                    break;
                }
            }

            this.IsGeneratingNetwork = true;
            await Task.Run(() =>
            {
                this.MyOSM.MyNetwork = network_generator.Generate(network_seed, seed_enable);
                this.MyAF.UpdatePictureBox();
            });

            this.IsGeneratingNetwork = false;


            /*
             * I_Network network = new WS_NetworkGenerator(100, 6, 0.01).Generate(1);
             * I_Layout layout = new Circular_LayoutGenerator(network).Generate();
             * network.SetLayout(layout);
             *
             * I_AgentSet agent_set = new BasicAgentSetFactory(network, InfoEnum.Undeter, 0.9, 0.1).Generate(1, AgentInitMode.Random);
             * agent_set.SetSensors(SetSensorMode.Number, 20, 0.55);
             *
             * this.MyAnimationForm.MyNetwork = network;
             * this.MyAnimationForm.MyAgentSet = agent_set;
             * var pos = new PlayOneStep(new SendOpinion(0.1), new ReceiveOpinion());
             * I_Algo algo = new AAT_Algo(new GeneratingCanWeights(), new EstimatingAwaRates(), new SelectingWeiStrategies(), pos);
             * this.MyAnimationForm.MyAlgo = algo;
             *
             * I_OSM osm = new BaseOSM(network, agent_set, algo);
             * osm.Initialize();
             * osm.PlaySteps(1000, 1);
             * this.MyAnimationForm.UpdatePictureBox();
             *
             * return;
             * osm.RunRounds(100, 1000, 1);
             * osm.PlaySteps(1000, 1);
             */
        }
        public void Run()
        {
            //network
            int        network_start_seed  = 14;
            int        network_finish_seed = 19;
            int        total_rounds        = 300;
            int        round_steps         = 1500;
            int        round_seed          = 0;
            List <int> node_num_list       = new List <int> {
                600, 700, 800, 900, 1000
            };
            bool   fix_sensor_num  = false;
            double sensor_rate     = 0.1;
            int    sensor_num      = 10;
            double rewire_p        = 0.01;
            int    degree          = 6;
            int    attach_edge_num = 2;
            int    rnd_edge_num    = 1;
            double triangle_p      = 0.01;
            double edge_creation_p = 0.01;
            //int grid_m = 20;
            //int grid_n = 20;
            bool seed_enable = true;
            //List<NetworkEnum> network_enum_list = new List<NetworkEnum> { NetworkEnum.WS, NetworkEnum.BA, NetworkEnum.ER, NetworkEnum.Grid2D, NetworkEnum.Hexagonal, NetworkEnum.Triangular };
            List <NetworkEnum> network_enum_list = new List <NetworkEnum> {
                NetworkEnum.Grid2D, NetworkEnum.Hexagonal, NetworkEnum.Triangular
            };
            I_NetworkGenerator network_generator = null;

            //agent
            InfoEnum init_op = InfoEnum.Undeter;
            //int agent_seed = ;
            double g_sigma           = 0.9;
            double r_sigma           = 0.1;
            double sensor_acc        = 0.55;
            double op_intro_rate     = 0.1;
            int    op_intro_duration = 1;
            var    t_awa_rate        = 0.9;

            //algo
            List <AlgoEnum> algo_enum_list = new List <AlgoEnum> {
                AlgoEnum.OriginalAAT, AlgoEnum.AATD_NoTargetH
            };

            //List<AlgoEnum> algo_enum_list = new List<AlgoEnum> { AlgoEnum.AATD_NoTargetH, AlgoEnum.AATD };

            for (int network_seed = network_start_seed; network_seed <= network_finish_seed; network_seed++)
            {
                foreach (var node_num in node_num_list)
                {
                    foreach (var network_enum in network_enum_list)
                    {
                        int grid_m, grid_n;
                        grid_m = grid_n = 0;
                        //grid_m = grid_n = (int)Math.Floor(Math.Sqrt(Convert.ToDouble(node_num)));


                        switch (network_enum)
                        {
                        case NetworkEnum.WS:
                            seed_enable       = true;
                            network_generator = new WS_NetworkGenerator(node_num, degree, rewire_p);
                            break;

                        case NetworkEnum.BA:
                            seed_enable       = true;
                            network_generator = new BA_NetworkGenerator(node_num, attach_edge_num);
                            break;

                        case NetworkEnum.ER:
                            seed_enable       = true;
                            network_generator = new ER_NetworkGenerator(node_num, edge_creation_p);
                            break;

                        case NetworkEnum.Grid2D:
                            grid_m            = grid_n = (int)Math.Floor(Math.Sqrt(Convert.ToDouble(node_num)));
                            seed_enable       = false;
                            network_generator = new Grid2D_NetworkGenerator(grid_m, grid_n);
                            break;

                        case NetworkEnum.Hexagonal:
                            if (node_num == 100)
                            {
                                grid_m = grid_n = 6;
                            }
                            else if (node_num == 200)
                            {
                                grid_m = grid_n = 9;
                            }
                            else if (node_num == 300)
                            {
                                grid_m = 12;
                                grid_n = 11;
                            }
                            else if (node_num == 400)
                            {
                                grid_m = 13;
                                grid_n = 13;
                            }
                            else if (node_num == 500)
                            {
                                grid_m = grid_n = 15;
                            }
                            else if (node_num == 600)
                            {
                                grid_m = 18;
                                grid_n = 15;
                            }
                            else if (node_num == 700)
                            {
                                grid_m = 19;
                                grid_n = 17;
                            }
                            else if (node_num == 800)
                            {
                                grid_m = 20;
                                grid_n = 18;
                            }
                            else if (node_num == 900)
                            {
                                grid_m = 21;
                                grid_n = 20;
                            }
                            else if (node_num == 1000)
                            {
                                grid_m = 22;
                                grid_n = 21;
                            }
                            seed_enable       = false;
                            network_generator = new Hexagonal_NetworkGenerator(grid_m, grid_n);
                            break;

                        case NetworkEnum.Triangular:
                            if (node_num == 100)
                            {
                                grid_m = 12;
                                grid_n = 13;
                            }
                            else if (node_num == 200)
                            {
                                grid_m = 18;
                                grid_n = 19;
                            }
                            else if (node_num == 300)
                            {
                                grid_m = 24;
                                grid_n = 22;
                            }
                            else if (node_num == 400)
                            {
                                grid_m = 27;
                                grid_n = 27;
                            }
                            else if (node_num == 500)
                            {
                                grid_m = grid_n = 30;
                            }
                            else if (node_num == 600)
                            {
                                grid_m = 32;
                                grid_n = 34;
                            }
                            else if (node_num == 700)
                            {
                                grid_m = 36;
                                grid_n = 36;
                            }
                            else if (node_num == 800)
                            {
                                grid_m = 39;
                                grid_n = 38;
                            }
                            else if (node_num == 900)
                            {
                                grid_m = 42;
                                grid_n = 40;
                            }
                            else if (node_num == 1000)
                            {
                                grid_m = 42;
                                grid_n = 45;
                            }
                            seed_enable       = false;
                            network_generator = new Triangular_NetworkGenerator(grid_m, grid_n);
                            break;

                        default:
                            break;
                        }
                        var      network = network_generator.Generate(network_seed, seed_enable);
                        I_Layout layout  = new Square_LayoutGenerator(network).Generate();

                        int        agent_seed = network_seed;
                        I_AgentSet agent_set  = new BasicAgentSetFactory(network, init_op, g_sigma, r_sigma).Generate(agent_seed, AgentInitMode.Normal);
                        if (!fix_sensor_num)
                        {
                            agent_set.SetSensors((int)(node_num * sensor_rate), sensor_acc);
                        }
                        else
                        {
                            agent_set.SetSensors(sensor_num, sensor_acc);
                        }

                        I_Algo algo = null;

                        foreach (var algo_enum in algo_enum_list)
                        {
                            switch (algo_enum)
                            {
                            case AlgoEnum.OriginalAAT:
                                var gcw = new GeneratingCanWeights();
                                var ear = new EstimatingAwaRates();
                                var sws = new SelectingWeiStrategies(t_awa_rate);
                                var pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion());
                                algo = new AAT_Algo(AlgoEnum.OriginalAAT, gcw, ear, sws, pos);
                                break;

                            case AlgoEnum.HCII_AATD:
                                var hcii_aatd_gcw = new GeneratingCanWeights();
                                var hcii_aatd_ear = new HCII_AATD_EstimatingAwaRates();
                                var hcii_sws      = new SelectingWeiStrategies(t_awa_rate);
                                var hcii_aatd_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion());
                                algo = new AAT_Algo(AlgoEnum.HCII_AATD, hcii_aatd_gcw, hcii_aatd_ear, hcii_sws, hcii_aatd_pos);
                                break;

                            case AlgoEnum.AATD:
                                var aatd_gcw = new GeneratingCanWeights();
                                var aatd_ear = new AATD_EstimatingAwaRates();
                                var aatd_sws = new AATD_SelectingWeiStrategies(t_awa_rate, 2, agent_set.AgentList.Count);
                                var aatd_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion());
                                algo = new AAT_Algo(AlgoEnum.AATD, aatd_gcw, aatd_ear, aatd_sws, aatd_pos);
                                break;

                            case AlgoEnum.AATD_NoTargetH:
                                var aatd_noth_gcw = new GeneratingCanWeights();
                                var aatd_noth_ear = new AATD_EstimatingAwaRates();
                                var aatd_noth_sws = new AATD_SelectingWeiStrategies(1.0, 2, agent_set.AgentList.Count);
                                var aatd_noth_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion());
                                algo = new AAT_Algo(AlgoEnum.AATD, aatd_noth_gcw, aatd_noth_ear, aatd_noth_sws, aatd_noth_pos);
                                break;
                            }

                            I_OSM osm = new BaseOSM();
                            osm.MyNetwork  = network;
                            osm.MyAgentSet = agent_set;
                            osm.MyAlgo     = algo;
                            osm.Initialize();

                            this.MakeFile(network_enum, node_num, network_seed, algo_enum);

                            RandomPool.Declare(SeedEnum.RoundSeed, round_seed);
                            RandomPool.Declare(SeedEnum.PlayStepSeed, round_seed);

                            //Console.WriteLine(this.PrintObject());
                            osm.MyAlgo.MyOSMLog.StartRecordRounds(this.OutputRoundFilePath);
                            for (int current_round = 1; current_round <= total_rounds; current_round++)
                            {
                                osm.MyAlgo.RunOneRound(osm.MyNetwork, osm.MyAgentSet, current_round, round_steps);
                            }
                            osm.MyAlgo.MyOSMLog.StopRecordRounds();
                        }
                    }
                }
            }
        }