Re: [問題] 最佳化問題 (方程式數目比未知數多)已回收
※ 引述《josh0114 (small)》之銘言:
: 各位高手大家好:
: 金額 數量 總金額
: 2292
: 1526
: 甲: 258 * 7 = 1806
: 乙: 187 * 8 = 1496
: 丙: 178 * 5 = 890
: 丁: 197 * 4 = 788
: -------
: 8805
: 現今欲利用甲、乙、丙、丁之金額以及數量的關係
: 拼湊出一組總金額4946或3861(數量可自行搭配 且搭配後之總金額可容許(-2)之誤差)
: 請問各位高手
: 是否有如此關係之答案 謝謝
我是比較建議使用LP法來解
這是非常標準LP法在處理的問題
不過要怎樣限定LP法一定要用整數的處理我實在想不起來了
Matlab的最佳化Toolbox都不適用整數在解的
剛好這題的case只有2160種而已,所以可以使用暴力法來解
但能用最佳化解當然是更好啦,誰知道下個問題用暴力法會不會跑出out of memory
[ A1 A2 A3 A4 ] = ndgrid( [ 0 : 7 ] , [ 0 : 8 ] , [ 0 : 5 ] , [ 0 : 4 ] ) ;
B = A1( : ) * 258 + A2( : ) * 187 + A3( : ) * 178 + A4( : ) * 197 ;
index1 = find( ( B >= ( 3861 - 2 ) ) & ( B <= ( 3861 + 2 ) ) )
index1 =
Empty matrix: 0-by-1
所以3861±2的組合找不到
index2 = find( ( B >= ( 4946 - 2 ) ) & ( B <= ( 4946 + 2 ) ) )
index2 =
Empty matrix: 0-by-1
而4946±2的組合一樣是沒有辦法找到
--
Deserves death! I daresay he does. Many that live deserve death. And some die
that deserve life. Can you give that to them? Then be not too eager to deal out
death in the name of justice, fearing for your own safty. Even the wise cannot
see all ends.
Gandalf to Frodo
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.131.229.150
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章