Пример #1
0
        //--------------------------------------------------------------------------------
        //This functions only works in a feasible path. It takes one random node and checks if
        //its neighboors can have a better cost with other conexion of the commons neighboors
        public void Improve(ref MeshEnvironment env)
        {
            if (is_feasible)
            {
                int random_idx = random.Next(1, path.Count - 1);

                //Get the previous and next node of that obstacle in the path
                int previous_node = path[random_idx - 1];
                int next_node     = path[random_idx + 1];

                List <int> neigh_previous = env.world[previous_node].neighboors;
                List <int> neigh_next     = env.world[next_node].neighboors;
                List <int> intersection   = neigh_previous.Intersect(neigh_next).ToList();
                intersection.Remove(path[random_idx]);

                if (intersection.Count != 0 && !env.obstacles.Contains(intersection[0]))
                {
                    List <int> tmp_path = new List <int>(path);
                    tmp_path[random_idx] = intersection[0];
                    Double tmp_cost = ExtraTools.GetCost(ref tmp_path, ref env);

                    if (tmp_cost < best_cost)
                    {
                        best_cost = tmp_cost;
                        path      = new List <int>(tmp_path);
                        SetExtraParameters(ref env);
                        SetFitness(ref env);
                    }
                }
            }
        }
Пример #2
0
 //
 //	copied the source file by https://github.com/stackprobe/Factory/blob/master/SubTools/CopyLib.c
 //
 public static void GameEnd2(ExceptionDam eDam)
 {
     while (1 <= Finalizers.Count)
     {
         eDam.Invoke(ExtraTools.UnaddElement(Finalizers));
     }
 }
Пример #3
0
 public static void UnloadAllDer(List <int> derHandleList)
 {
     while (1 <= derHandleList.Count)
     {
         UnloadDer(ExtraTools.UnaddElement(derHandleList));
     }
 }
Пример #4
0
        //-------------------------------------------------------------------
        public void SetProximities()
        {
            Double max_proximity = Double.MinValue;
            Double min_proximity = Double.MaxValue;

            GetMaxMinProximities(ref max_proximity, ref min_proximity);

            foreach (var node in world)
            {
                List <Double> proximities = new List <Double>();

                if (node.id != final_node)
                {
                    List <int> neighboors = node.neighboors;

                    foreach (var next_node in neighboors)
                    {
                        Double proximity = CalculateProximity(node.id, next_node);
                        proximity = ExtraTools.NormalizeWithInterval(proximity, min_proximity, max_proximity);

                        proximities.Add(proximity);
                    }
                }

                node.proximities = proximities;
            }
        }
Пример #5
0
        //-------------------------------------------------------------------
        //Proximity value setting the target node of the environment
        public Double CalculateProximity(int current_node, int next_node)
        {
            Double di_t = ExtraTools.EucDistance(world[current_node], world[final_node]);
            Double dj_t = ExtraTools.EucDistance(world[next_node], world[final_node]);

            return(di_t / dj_t);
        }
 //-------------------------------------------------------------------
 public void DeltaTau(ref MeshEnvironment env, ref List <int> route)
 {
     if (best_cost != Double.MaxValue)
     {
         Double current_cost = ExtraTools.GetCost(ref route, ref env);
         delta_tau = best_cost / current_cost;
     }
 }
Пример #7
0
        //-------------------------------------------------------------------
        public void CheckAndSetBestCost(ref MeshEnvironment env, ref List <int> route)
        {
            Double current_cost = ExtraTools.GetCost(ref route, ref env);

            if (current_cost < best_cost)
            {
                best_cost = current_cost;
            }
        }
Пример #8
0
        /// <summary>
        /// <para>surface を削除する。</para>
        /// <para>this.Surfaces にある surface を削除する処理は全てここに到達する。</para>
        /// </summary>
        /// <param name="index">削除する surface のインデックス</param>
        private void RemoveSurface(int index)
        {
            Surface surface = this.Surfaces[index];

            // surface 削除時にすること
            {
                Game.I.SurfaceEL.Add(surface.Act.Draw);
            }

            ExtraTools.FastDesertElement(this.Surfaces, index);
        }
Пример #9
0
        //
        //	copied the source file by https://github.com/stackprobe/Factory/blob/master/SubTools/CopyLib.c
        //
        public static T FastDesertElement <T>(List <T> list, Predicate <T> match, T defval = default(T))
        {
            for (int index = 0; index < list.Count; index++)
            {
                if (match(list[index]))
                {
                    return(ExtraTools.FastDesertElement(list, index));
                }
            }

            return(defval);
        }
Пример #10
0
        public void Clear()
        {
            while (1 <= this.Infos.Count)
            {
                TaskInfo ti = ExtraTools.UnaddElement(this.Infos);

                if (ti.ReleaseParam != null)
                {
                    ti.ReleaseParam(ti.Param);
                }
            }
        }
Пример #11
0
        private void MainWin_Load(object sender, EventArgs e)
        {
            {
                string logFile  = Path.Combine(ProcMain.SelfDir, Path.GetFileNameWithoutExtension(ProcMain.SelfFile)) + ".log";
                string logFile0 = logFile + "0";

                File.Delete(logFile);
                File.Delete(logFile0);

                ProcMain.WriteLog = message =>
                {
                    try
                    {
                        using (new MSection("{67bbcf7a-ebe2-42a9-aeb2-54ee4bb40c67}"))                         // 念の為ロック
                        {
                            if (File.Exists(logFile) && Consts.LOG_FILE_SIZE_MAX < new FileInfo(logFile).Length)
                            {
                                File.Delete(logFile0);
                                File.Move(logFile, logFile0);
                            }
                            using (StreamWriter writer = new StreamWriter(logFile, true, Encoding.UTF8))
                            {
                                writer.WriteLine("[" + DateTime.Now + "] " + message);
                            }
                        }
                    }
                    catch
                    { }
                };
            }

            ExtraTools.AntiWindowsDefenderSmartScreen();

            Ground.I.LoadFromFile();

            if (Ground.I.Config.SettingToLog)
            {
                ProcMain.WriteLog("Setting: " + JsonTools.Encode(DebugTools.ToListOrMap(Ground.I)));                 // デバッグ用
            }
            if (Ground.I.MainWin_Maximized)
            {
                this.WindowState = FormWindowState.Maximized;
            }
            else if (Ground.I.MainWin_W != -1)
            {
                this.Left   = Ground.I.MainWin_L;
                this.Top    = Ground.I.MainWin_T;
                this.Width  = Ground.I.MainWin_W;
                this.Height = Ground.I.MainWin_H;
            }
        }
Пример #12
0
        //-------------------------------------------------------------------

        public override string ToString()
        {
            if (mode == 'N')
            {
                string str_neigh = ExtraTools.PrintList(ref neighboors);
                string str_edges = ExtraTools.PrintList(ref edges);

                return("id: " + id + " neighboors: " + str_neigh + " edges: " + str_edges + " mode: " + mode);
            }
            else
            {
                return("obstacle");
            }
        }
Пример #13
0
        public static string ToCreatableFairFullPath(string path)
        {
            path = FileTools.MakeFullPath(path);

            string dir       = Path.GetDirectoryName(path);
            string localPath = Path.GetFileName(path);

            localPath = DenebolaToolkit.GetFairLocalPath(localPath, dir + "0123456789");             // 重複回避のため追加される文字列のためにマージンを取る。

            path = Path.Combine(dir, localPath);
            path = ExtraTools.ToCreatablePath(path);

            return(path);
        }
Пример #14
0
        //-------------------------------------------------------------------
        public List <int> FindRoute(ref MeshEnvironment env)
        {
            //List to store the new route
            List <int> route = new List <int>();

            route.Add(env.start_node); //Include the initial node

            //Variable to detect if the ant finds a route
            bool found_route = false;

            //Init the loop from the initial node
            int current_node = env.start_node;

            while (!found_route)
            {
                int next_node = SelectNextNode(ref env, current_node);
                if (next_node != -1)
                {
                    //Add the new node and change the current node
                    route.Add(next_node);
                    current_node = next_node;
                }
                else
                {
                    //If there is a stuck condition break the loop
                    break;
                }

                //Configuro mi variable si he encontrado el objetivo
                found_route = current_node == env.final_node;
            }

            //If the ant found a route
            if (found_route)
            {
                //Set the current route, the current cost and the current counter
                current_route = route;
                current_cost  = ExtraTools.GetCost(ref current_route, ref env);
                counter_route++;
            }
            else
            {
                route = new List <int>();
            }


            return(route);
        }
Пример #15
0
        private void MS_Init()
        {
            this.MainSheet.RowCount    = 0;
            this.MainSheet.ColumnCount = 0;

            ExtraTools.SetEnabledDoubleBuffer(this.MainSheet);

            this.MS_AddColumn("ステータス", 100);             // 0
            this.MS_AddColumn("エラー情報", 100);             // 1
            this.MS_AddColumn("音楽ファイル (入力)", 600);       // 2 絶対パス
            this.MS_AddColumn("音楽ファイル (入力)", 300);       // 3 ローカルパス
            this.MS_AddColumn("映像用の画像 (入力)", 600);       // 4 絶対パス
            this.MS_AddColumn("映像用の画像 (入力)", 300);       // 5 ローカルパス
            this.MS_AddColumn("動画ファイル (出力)", 600);       // 6 絶対パス
            this.MS_AddColumn("動画ファイル (出力)", 300);       // 7 ローカルパス
            this.MS_AddColumn("FPS", 100, true);         // 8

            this.MS_Refresh();
        }
Пример #16
0
        private void Main2(ArgsReader ar)
        {
            Directory.SetCurrentDirectory(ExtraTools.GetHomeDir());

            using (CsvFileReader reader = new CsvFileReader(@"src\syukujitsu.csv"))
                using (StreamWriter writer = new StreamWriter(@"dest\祝日.js.txt", false, StringTools.ENCODING_SJIS))
                {
                    if (reader.ReadRow() == null)   // ヘッダ
                    {
                        throw null;                 // 想定外!
                    }
                    for (; ;)
                    {
                        string[] row = reader.ReadRow();

                        if (row == null)
                        {
                            break;
                        }

                        if (row.Length != 2)
                        {
                            throw null;                     // 想定外!
                        }
                        string date = row[0];
                        string name = row[1];

                        string[] dateTokens = StringTools.Tokenize(date, "/");

                        if (dateTokens.Length != 3)
                        {
                            throw null;                     // 想定外!
                        }
                        int y = int.Parse(dateTokens[0]);
                        int m = int.Parse(dateTokens[1]);
                        int d = int.Parse(dateTokens[2]);

                        int iDate = y * 10000 + m * 100 + d;

                        writer.WriteLine("\t[ " + iDate + ", \"" + name.Replace("\"", "\\\"") + "\" ],");
                    }
                }
        }
Пример #17
0
        //-------------------------------------------------------------------------
        //Funcion fitness puede variar de acuerdo al requerimiento del algoritmo
        public void SetFitness(ref MeshEnvironment env)
        {
            //Costo general por la distancia del camino
            Double cost = ExtraTools.GetCost(ref path, ref env);

            //Costo extra por aristas obstaculos
            if (edges_obstacles.Count != 0)
            {
                foreach (var idx_edge in edges_obstacles)
                {
                    cost += env.edges[idx_edge].distance * coef_edge_obs;
                }
            }

            //Costo extra por nodos obstaculos
            cost += num_infeasible_nodes * coef_node_obs;

            fitness   = 1 / cost;
            best_cost = cost;
        }
Пример #18
0
        private void ReportLogViewer_Shown(object sender, EventArgs e)
        {
            try
            {
                this.MS_Init();
                this.MS_AutoResize();
                this.LoadReport();
                this.MS_AutoResize();

                ExtraTools.SetEnabledDoubleBuffer(this.MainSheet);

                this.MS_Refresh();
                this.MainSheet.ClearSelection();
            }
            catch (Exception ex)
            {
                MessageDlgTools.Error("レポート_初期化エラー", ex);

                // clear
                this.MainSheet.RowCount    = 0;
                this.MainSheet.ColumnCount = 0;
            }
        }
Пример #19
0
        private void Main2(ArgsReader ar)
        {
            Directory.SetCurrentDirectory(ExtraTools.GetHomeDir());

            {
                HtmlConverter hc = new HtmlConverter()
                {
                    InputHtmlFile  = @"src\index.html",
                    OutputHtmlFile = @"out\index.html",
                };

                hc.Perform();
            }

            {
                HtmlConverter hc = new HtmlConverter()
                {
                    InputHtmlFile  = @"src\Hatena.html",
                    OutputHtmlFile = @"out\Hatena.html",
                };

                hc.Perform();
            }

            HtmlToDataUrl(@"out\Hatena.html", @"out\Hatena.html.data-url.txt");

            {
                HtmlConverter hc = new HtmlConverter()
                {
                    InputHtmlFile  = @"src2\GeTunnel.html",
                    OutputHtmlFile = @"out\GeTunnel.html",
                };

                hc.Perform();
            }
        }
Пример #20
0
        //--------------------------------------------------------------
        public bool CheckPopulation(ref MeshEnvironment env)
        {
            int num_convergence = (int)Math.Round(num_individuals * percentage_convergence);

            Double best_cost_individual = Double.MaxValue;
            int    best_individual      = -1;

            for (int k = 0; k < population.Count; k++)
            {
                Double current_cost = population[k].best_cost;
                if (current_cost < best_cost_individual)
                {
                    best_cost_individual = current_cost;
                    best_individual      = k;
                }
            }


            List <int> best_route_individual = population[best_individual].path;

            int i = 0, j = 0;

            while (i < num_convergence && j < num_individuals)
            {
                //if (population[j].path.SequenceEqual(best_route_individual))
                if (Math.Round(population[j].best_cost, 4) == Math.Round(best_cost_individual, 4))
                {
                    i++;
                }
                j++;
            }


            bool converge = false;

            if (best_route_individual.Count != 0)
            {
                if (i == num_convergence)
                {
                    final_best_path = population[0].path;
                    final_best_cost = ExtraTools.GetCost(ref final_best_path, ref env);
                    converge        = true;
                }
            }

            //Probemos con el segundo mejor
            if (converge == false)
            {
                best_cost_individual = Double.MaxValue;
                best_individual      = -1;
                for (int k = 1; k < population.Count; k++)
                {
                    Double current_cost = population[k].best_cost;
                    if (current_cost < best_cost_individual)
                    {
                        best_cost_individual = current_cost;
                        best_individual      = k;
                    }
                }


                best_route_individual = population[best_individual].path;

                i = 0;
                j = 0;
                while (i < (num_convergence - 1) && j < num_individuals)
                {
                    if (Math.Round(population[j].best_cost, 4) == Math.Round(best_cost_individual, 4))
                    {
                        i++;
                    }
                    j++;
                }

                if (best_route_individual.Count != 0)
                {
                    if (i == num_convergence - 1)
                    {
                        final_best_path = population[0].path;
                        final_best_cost = ExtraTools.GetCost(ref final_best_path, ref env);
                        converge        = true;
                    }
                }
            }

            return(converge);
        }
Пример #21
0
 public static string GetRiotDir()
 {
     return(ExtraTools.GetHomeDir("_riot"));
 }
Пример #22
0
        //-------------------------------------------------------------------

        //Init all the other attributes of the Enviroment
        public void InitEnviroment(string type_mesh)
        {
            world = new List <Node>(); //Store all the nodes
            edges = new List <Edge>(); //Sore all the edges

            string path = @"data_sets/" + type_mesh + "/";

            //Load data
            var file = File.ReadAllLines(path + file_name);


            //Init nodes, conections, and obstacles
            int count      = 0;
            int count_edge = 0;

            for (int i = 2; i < file.Length; i++)
            {
                var    fields     = file[i].Split(' ');
                string identifier = fields[0];

                switch (identifier)
                {
                //Init nodes
                case "v":
                    Double x_coord = Convert.ToDouble(fields[1]);
                    Double y_coord = Convert.ToDouble(fields[2]);
                    Double z_coord = Convert.ToDouble(fields[3]);
                    world.Add(new Node(count, x_coord, y_coord, z_coord, 'N'));
                    count++;
                    break;

                //Init connections in the heuristic_criteria matrix
                case "f":

                    int    node1, node2;
                    Edge   new_edge;
                    Double distance;
                    for (int j = 1; j < fields.Length; j++)
                    {
                        node1    = Int32.Parse(fields[j]) - 1;
                        node2    = ((j == fields.Length - 1) ? Int32.Parse(fields[1]) : Int32.Parse(fields[j + 1])) - 1;
                        distance = ExtraTools.EucDistance(world[node1], world[node2]);

                        new_edge = new Edge(count_edge, world[node1], world[node2], distance);

                        if (!edges.Contains(new_edge))
                        {
                            edges.Add(new_edge);
                            world[node1].neighboors.Add(node2);
                            world[node1].edges.Add(edges.Count - 1);

                            world[node2].neighboors.Add(node1);
                            world[node2].edges.Add(edges.Count - 1);

                            count_edge++;
                        }
                    }

                    break;
                }
            }


            SetProximities();
        }
Пример #23
0
        private void MainWin_Shown(object sender, EventArgs e)
        {
            // -- 0001

            // TODO WriteLog = write to .log file

            ExtraTools.AntiWindowsDefenderSmartScreen();

            Prime4096.INIT();
            Prime53Lite.INIT();

            Prime53Lite.GeneratePrimeDat();

            this.Base_MainWin_H = this.Height;
            this.Base_T1_H      = this.T出力_最小値.Height;
            this.Base_L2_T      = this.L出力_最大値.Top;
            this.Base_T2_T      = this.T出力_最大値.Top;
            this.Base_T2_H      = this.T出力_最大値.Height;

            this.Base2_T1_H = this.T判定_入力.Height;
            this.Base2_B1_T = this.Btn判定.Top;
            this.Base2_T2_T = this.T判定_結果.Top;
            this.Base2_T2_H = this.T判定_結果.Height;

            // --

            this.T出力_最小値.Text = "" + 2;
            this.T出力_最大値.Text = "" + 10000000000;

            this.T判定_入力.Text = Consts.S2P1279_1;
            this.T判定_結果.Text = "";

            this.T探索_入力.Text = ("" + 1) + StringTools.Repeat("0", 400);
            this.T探索_結果.Text = "";

            this.T素因数分解_入力.Text = Consts.SMP1000;
            this.T素因数分解_結果.Text = "";

            this.T個数_最小値.Text = "" + 2;
            this.T個数_最大値.Text = "" + 10000000000;

            // --

            this.T出力_最小値.SelectAll();
            this.T出力_最大値.SelectAll();

            this.T判定_入力.SelectAll();

            this.T探索_入力.SelectAll();

            this.T素因数分解_入力.SelectAll();

            this.T個数_最小値.SelectAll();
            this.T個数_最大値.SelectAll();

            // --

            this.MainToolTip.SetToolTip(this.T出力_最小値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));
            this.MainToolTip.SetToolTip(this.T出力_最大値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T判定_入力, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T探索_入力, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T素因数分解_入力, Utils.AutoInsertNewLine("1 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            this.MainToolTip.SetToolTip(this.T個数_最小値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));
            this.MainToolTip.SetToolTip(this.T個数_最大値, Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_ToolTip));

            // ----

            this.RefreshUI();

            ChocomintDialogsCommon.PostShown(this);

            // ----

            this.MTBusy.Leave();
        }
Пример #24
0
        //-------------------------------------------------------------------------------

        public void Execute(ref MeshEnvironment env)
        {
            //Fill distances to objective
            env.FillDistancesToFinal();

            //Init the node tags list;
            int size = env.size * env.size;

            InitNodeTags(size);

            //Get the distance between node. Adjacency Matrix
            env.FillDistanceMatrix();
            Double[,] distances_matrix = env.distances;


            //Get initial and final nodes
            int initial_position = env.start_node;
            int final_position   = env.final_node;

            //Get world of the env
            List <Node> world = env.world;

            //Init the values of the initial node and its tag
            node_tags[initial_position].local_goal  = 0.0;
            node_tags[initial_position].global_goal = MeasureHeuristic(initial_position, ref env);

            //Fijar la posicion actual
            Tag current_position = node_tags[initial_position];

            //Nodos que seran testeados
            List <Tag> tested_nodes_list = new List <Tag>();


            tested_nodes_list.Add(node_tags[initial_position]);

            //Time variable
            var watch = System.Diagnostics.Stopwatch.StartNew();


            while (tested_nodes_list.Count != 0) // && current_position.node_id != env.final_node)
            {
                //Ordenar la lista de acuerdo al objetivo global en orden ascendente
                tested_nodes_list = tested_nodes_list.OrderBy(tag => tag.global_goal).ToList();

                //Remover de la lista si el nodo analizado ya ha sido visitado
                while (tested_nodes_list.Count != 0 && tested_nodes_list[0].visited)
                {
                    tested_nodes_list.RemoveAt(0);
                }

                //Si la lista es vacia salimos del bucle
                if (tested_nodes_list.Count == 0)
                {
                    break;
                }

                //Inicializamos nuestra posicion actual
                current_position                    = tested_nodes_list[0];
                current_position.visited            = true;
                tested_nodes_list[0]                = current_position;
                node_tags[current_position.node_id] = current_position;


                //Obtengo los posibles nodos a los cuales me puedo mover
                List <int> list_posible_nodes = GetPosibleNodes(current_position.node_id, ref env);

                //Itero por los posibles nodos
                foreach (var neighbour_id in list_posible_nodes)
                {
                    int current_id = current_position.node_id;

                    Double possible_lower_goal = current_position.local_goal + distances_matrix[current_id, neighbour_id];

                    if (possible_lower_goal < node_tags[neighbour_id].local_goal && !node_tags[neighbour_id].visited)
                    {
                        Tag new_tag = node_tags[neighbour_id];
                        new_tag.parent          = current_id;
                        new_tag.local_goal      = possible_lower_goal;
                        new_tag.global_goal     = new_tag.local_goal + MeasureHeuristic(neighbour_id, ref env);
                        node_tags[neighbour_id] = new_tag;

                        if (tested_nodes_list.Contains(new_tag))
                        {
                            int idx = tested_nodes_list.IndexOf(new_tag);
                            tested_nodes_list[idx] = new_tag;
                        }
                    }

                    //Si los nodos analizados aun no han sido marcados como visitados
                    //Los añadimos a lista de testeo
                    if (!node_tags[neighbour_id].visited && !tested_nodes_list.Contains(node_tags[neighbour_id]))
                    {
                        tested_nodes_list.Add(node_tags[neighbour_id]);
                    }
                }
            }


            List <int> optimal_path = GetPath(final_position, initial_position);
            Double     optimal_cost = ExtraTools.GetCost(ref optimal_path, ref env);

            final_best_path = optimal_path;
            final_best_path.Reverse();
            final_best_cost = optimal_cost;

            //Execution Time
            watch.Stop();
            execution_time = watch.ElapsedMilliseconds;
        }