フィルターのクリア

Is there a one line code solution to generate a matrix of permutations

2 ビュー (過去 30 日間)
Amit
Amit 2012 年 11 月 4 日
I am looking for a single-line matlab code to solve the following problem:
There are five consultants, and five projects to be done. Any consultants can carry out any the project, but at a different cost to the company. The cost matrix is as follows:
The business manager is trying to allocate one project each to the five sonsultants such that the overall cost to the company is the minimum.
Obviously, there are 5! (=120) possibilities, and total costs can be calculated, and combination with minimum cost can be selected.
The challenge is to do it in single line of matlab code, however complex.
For your ease: costs=[24 10 21 11 16; 14 22 10 15 15; 15 17 12 20 14; 11 19 14 13 13; 23 13 13 18 12]; Thank you.

採用された回答

Amit
Amit 2012 年 11 月 6 日
I got a notification that José-Luis posted an answer. I read it first but strangely I can't see it here. This is what José-Luis posted, and it works like a charm:
costs=[24 10 21 11 16; 14 22 10 15 15; 15 17 12 20 14; 11 19 14 13 13; 23 13 13 18 12];
min(sum(costs(bsxfun(@plus,perms(1:5),0:5:20)),2))
Thanks José-Luis.

その他の回答 (2 件)

Matt J
Matt J 2012 年 11 月 4 日
編集済み: Matt J 2012 年 11 月 4 日
The PERMS command.
  2 件のコメント
Amit
Amit 2012 年 11 月 5 日
編集済み: Amit 2012 年 11 月 5 日
Matt J, thanks. Of course 'perms' command is good, but doesn't allow usage in the way I have data. The way the data is, I need to shuffle the matrix either along rows or along columns, and sum the diagonal. And I am allowed a single line code. So 'perms' is not all that we require. Cheers.
Matt J
Matt J 2012 年 11 月 5 日
No, it's not all that you require, but it's the main thing that you require. I don't see why you think you need to shuffle the matrix and sum the diagonal.
As a hint, here are a few other commands that might be useful: SUB2IND, REPMAT

サインインしてコメントする。


Matt Fig
Matt Fig 2012 年 11 月 4 日
The cheapest rate I find is 59 units. I can find the minimum cost in one line. But I cannot find this and also return the job assignments in one line. Fun little project!
  5 件のコメント
Matt J
Matt J 2012 年 11 月 5 日
If the goal is just the minimum cost, you probably don't need SUBSREF.
Walter Roberson
Walter Roberson 2012 年 11 月 5 日
Remember, one line, not one expression.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by