Tree Search(樹狀搜尋)

一、什麼是 Tree Search(樹狀搜尋)? 在人工智慧(AI)與演算法中,許多問題都可以表示成一棵樹(圖一): 起點(A) / | \ B C D /|\ | / \ E F G H I J 每個節點(Node)代表一種狀態(State)。 例如: 迷宮中的位置 棋局的盤面 路徑規劃中的城市 遊戲中的決策 搜尋演算法的目的: 從起點找到目標節點(Goal Node) 二、Breadth First Search (BFS) 核心思想 先搜尋離起點最近的節點。 一層一層往外擴展。 Level 0: A Level 1: B C D Level 2: E F G H I J 搜尋順序: A B C D E F G H I J 圖一結果: A → B → C → D → E → F → G → H → I → J 使用資料結構 Queue(佇列) FIFO: First In First Out 先進先出 例如: Queue: A 取出A 加入B,C,D Queue: B,C,D BFS特性 優點 如果邊權重相同: BFS一定找到最短路徑。 缺點 需要大量記憶體。 假設每個節點有10個子節點: 深度5: 10^5 = 100000 需要保存很多節點。 時間複雜度 O(V + E) V = Vertex(節點數) E = Edge(邊數) 三、Depth First Search (DFS) 核心思想 一路往下走到底。 不能走才回頭。 A | B | E 然後: A | B | F 搜尋順序 圖一結果: A B E F G C H D I J 使用資料結構 Stack(堆疊) LIFO Last In First Out 後進先出 例如: push(B) push(C) push(D) pop() => D DFS特性 優點 記憶體需求小。 只需保存: 目前路徑 即可。 缺點 可能找到很差的解。 例如: A ├── Goal └── 巨大子樹 DFS可能先跑完整個巨大子樹。 時間複雜度 O(V+E)...

Ubuntu 18.04 LEMP(Linux+Nginx+Mysql+PHP)環境建立

底下紀錄如何在 Ubuntu 18.04 上建立 LEMP 的環境。
This note demonstrates how to create a LEMP environment on an Ubuntu 18.04 server.

步驟一:安裝 Nginx Web Server (Step One: Installing nginx web server)
Open a console and input the following commands to install nginx.
  1. sudo apt-get update
  2. sudo apt-get install nginx

接著查詢主機IP
You can find your server's public IP address by the following command:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'


在瀏覽器鍵入 local host ip。
Type the address in your web browser(Google chrome or firefox .etc).
http://server_domain_name_or_IP

若在瀏覽器上看到下圖,表示 nginx 已安裝成功。If you see the below message, your nginx installation is completed.
可看到上圖時,nginx便已經可跑靜態網頁了,預設的html檔案存放位置為 /var/www/html


步驟二:安裝MySql(Step Two: Installing mysql
Open a console and input the following commands to install mysql.
sudo apt-get install mysql-server
安裝完後輸入以下指令進行安全性設定
Type the following command to secure the MySQL installation:
sudo mysql_secure_installation











步驟三:安裝php與設定 php.ini(Step Three: Installing php and configuring the php.ini)
Installing php:
sudo apt-get install php-fpm php-mysql
Modifying php.ini file:
sudo nano /etc/php/7.2/fpm/php.ini
Replace this line:
;cgi.fix_pathinfo=1
with
cgi.fix_pathinfo=0

Save and restart php service:
sudo service php7.2-fpm restart


步驟四:設定Nginx的php模組功能(The PHP Processor configuration for nginx)
建立一個nginx設定
Create the configuration file for nginx:
sudo nano /etc/nginx/sites-available/test.com
Input the below text to the configuration file:
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm;
        server_name test.com;
 
        location / {
                try_files $uri $uri/ =404;
        }
 
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
 
        location ~ /\.ht {
                deny all;
        }
}
# Creating a symbolic link to enable the new server block.
sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/
 
# Unlink the default configuration
sudo unlink /etc/nginx/sites-enabled/default
 
# Checking the new configuration file
sudo nginx -t
 
# Reload Nginx
sudo service nginx reload
步驟五:建立php測試檔案(Step Five: Create a php file to test)
# Creating the test php file
sudo nano /var/www/html/info.php
Input the following php code into the new file(info.php).
<?php
phpinfo();

Open your browser to visit this page:
http://your_server_domain_or_IP/info.php

You should see some information about your server:


參考資料:

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

If you like this post, please click the ads on the blog or buy me a coffee. Thank you very much.

留言

這個網誌中的熱門文章