2012年5月13日 星期日

組合最佳化的真諦

今天母親節,炎熱的下午

睡了一覺起來之後

突然發現了,組合最佳化的真諦

就是在真實解空間裡面,尋找合理解空間

在從合理解空間當中找到最佳解空間裡面去收斂

所以可以透過,已知的可能最佳解空間當中去收斂

用各種方式收斂,或是探試可能的最佳解

假若 今天我解的題目,是48個tour

那我可以從已知的題目最佳解當中

可以推理出,在最佳解空間裡

各點的tour 對 下一點的tour 最佳路徑可能是 1-2 ,1-3

有 三組路徑解是可以被採用且有可能的最佳路徑

而1-4,1-5,1-6  ~  1-48 都是不可行且是浪費試探的路徑

同時也根本不用當作是可能解當中的路徑,所以是完全不當作解空間當中的路徑

例如 3^48 是 例子 tour 48當中被我定義的合理解且可能是最佳解的空間

而不是48 !

所以我要解決的問題可以簡化成在 3^48 條路徑中找出最佳解

而不是 48!中找最佳解

剩下的問題是如何在3^48組解當中,找出一個有效率的組合演算公式

是一個 線性的數學解問題

最笨的方式就是 用類神經架構慢慢去Try

或是 有其他 有創意的方式去找解空間當中的組合解

需要一些機率的問題,跟如何有效率去搜尋解空間


排列組合問題在MATLAB中的實現方法大全


http://top99.blog.hexun.com.tw/59689479_d.html



matlab做排列組合:比如要ABCD的全排列,可以用perms函數
perms(['ABCD'])運行結果
DCBA
DCAB
DBCA
DBAC
DABC
DACB
CDBA
CDAB
CBDA
CBAD
CABD
CADB
BCDA
BCAD
BDCA
BDAC
BADC
BACD
ACBD
ACDB
ABCD
ABDC
ADBC
ADCB

以下是幾個常用的排列、組合與階乘等函數。
1、combntns(x,m)
列舉出從n個元素中取出m個元素的組合。其中,x是含有n個元素的向量。
2、perms(x) 
給出向量x的所有排列。
3、nchoosek(n,m)
從n各元素中取m個元素的所有組合數。   nchoosek(x,m)從向量x中取m個元素的組合
4、factorial(n)
求n的階乘。
5、prod(n:m)      %求排列數:m*(m-1)*(m-2)*…*(n+1)*n    prod(1:2:2n-1)或prod(2:2:2n)      %求(2n-1)!!或(2n)!!
6、cumprod(n:m)
輸出一個向量[n n*(n+1) n(n+1)(n+2) … n(n+1)(n+2)…(m-1)m]
7、gamma(n)
求n!
8、v='n!';
   vpa(v) 
更詳細資料如下:
nchoosek
Binomial coefficient or all combinations
Syntax:
        nchoosek(n,k)
        函數描述:      從 個元素中 一次選 個元素的所有組合數 C(註意,C是一個數值)。
                          n!/((n–k)! k!);
         nchoosek(v,k)
       函數描述: 從 向量 中 一次選其中 個元素 的所有組合 (註意:C是一個矩陣,列數 為 )
Description
nchoosek(n,k)
where and are nonnegative integers,
returns n!/((n–k)! k!).
This is the number of combinations of things taken at time.
nchoosek(v,k),
where is row vector of length n,creates matrix whose rows consist of all possible combinations of the elements of taken at time.
Matrix contains n!/((n–k)! k!) rows and columns.
Inputs n, k, and support classes of float double and float single.
Examples:
The command nchoosek(2:2:10,4)
returns the even numbers from two to ten, taken four at time:     
                                     8
                                    10
                                    10
                                    10
                                    10
combntns
All possible combinations of set of values 從給定集合set中列出所有可能的subset個元素的組合
Syntax
     combos combntns(set,subset)
     combos combntns(set,subset)       returns matrix whose rows are the various combinations that can be taken of the elements of the vector set of length subset.
Many combinatorial applications can make use of vector 1:n for the input set to return generalized, indexed combination subsets.
Description
The combntns function provides the combinatorial subsets of set of numbers.
It is similar to the mathematical expression choose b, except that instead of the number of such combinations,the actual combinations are returned.
In combinatorial counting, the ordering of the values is not significant.The numerical value of the mathematical statement choose is size(combos,1).
Examples
How can the numbers to be taken in sets of three (that is, whatis choose 3)?
combos combntns(1:5,3)
combos =
                      3
                      4
                      5
                      4
                      5
                      5
                      4
                      5
                      5
                      5
size(combos,1)     "5 choose 3"
ans =
       10
(註意事項):Note that if value is repeated in the input vector, each occurrence is treated as independent:
combos combntns([2 5],2)
combos =
               2
               5
               


沒有留言:

張貼留言