<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Puzzler: optimize this</title>
	<atom:link href="http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:31:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Yi Cao</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1357</link>
		<dc:creator>Yi Cao</dc:creator>
		<pubDate>Wed, 11 Mar 2009 11:22:16 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1357</guid>
		<description>Doug,

Just read this blog to know such a puzzler has been going on and to understand why John came to me to ask for the use of the munkres code a few weeks ago. Thanks to Darren who pointed out my code as a solution to the puzzler. Thank you and John to post this puzzler, which shows how useful of the Hungarian method is.

Regards,
Yi</description>
		<content:encoded><![CDATA[<p>Doug,</p>
<p>Just read this blog to know such a puzzler has been going on and to understand why John came to me to ask for the use of the munkres code a few weeks ago. Thanks to Darren who pointed out my code as a solution to the puzzler. Thank you and John to post this puzzler, which shows how useful of the Hungarian method is.</p>
<p>Regards,<br />
Yi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1342</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Tue, 17 Feb 2009 18:14:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1342</guid>
		<description>Doug: I thought that might&#039;ve been the issue. I guess external links are to be avoided if one wants to post quickly.</description>
		<content:encoded><![CDATA[<p>Doug: I thought that might&#8217;ve been the issue. I guess external links are to be avoided if one wants to post quickly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhull</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1341</link>
		<dc:creator>dhull</dc:creator>
		<pubDate>Tue, 17 Feb 2009 18:06:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1341</guid>
		<description>Oliver,

For some reason, Francois&#039; comment needed to be &quot;moderated&quot; because the automatic spam filter thought it might be spammy.  Usually things are posted immediately, but sometimes things get stuck, like his post.

Doug</description>
		<content:encoded><![CDATA[<p>Oliver,</p>
<p>For some reason, Francois&#8217; comment needed to be &#8220;moderated&#8221; because the automatic spam filter thought it might be spammy.  Usually things are posted immediately, but sometimes things get stuck, like his post.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1340</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Tue, 17 Feb 2009 17:16:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1340</guid>
		<description>Credit to Francois. None of us saw his post because it only appeared today, despite being posted 3 days earlier.</description>
		<content:encoded><![CDATA[<p>Credit to Francois. None of us saw his post because it only appeared today, despite being posted 3 days earlier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhull</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1339</link>
		<dc:creator>dhull</dc:creator>
		<pubDate>Tue, 17 Feb 2009 16:32:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1339</guid>
		<description>Wow,  I set you all loose on this problem right before I went home for the long weekend and come back to find it well taken care of.

I like how the community of readers are able to quickly write, optimize and re-optimize a problem.  Petter makes a solid greedy algorithm, then Danilo is able to optimize the bottleneck in it.

Francois is able to make an algorithmic advance by recognizing the problem as one with an existing solution and then Darren points out a file exchange submission that does this already.

This is what I love about the social computing aspect of this site. 

Thanks for all the effort!
-Doug</description>
		<content:encoded><![CDATA[<p>Wow,  I set you all loose on this problem right before I went home for the long weekend and come back to find it well taken care of.</p>
<p>I like how the community of readers are able to quickly write, optimize and re-optimize a problem.  Petter makes a solid greedy algorithm, then Danilo is able to optimize the bottleneck in it.</p>
<p>Francois is able to make an algorithmic advance by recognizing the problem as one with an existing solution and then Darren points out a file exchange submission that does this already.</p>
<p>This is what I love about the social computing aspect of this site. </p>
<p>Thanks for all the effort!<br />
-Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John DErrico</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1338</link>
		<dc:creator>John DErrico</dc:creator>
		<pubDate>Tue, 17 Feb 2009 12:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1338</guid>
		<description>Interesting. (I&#039;ve just had a chance to read through what has happened over the last couple of days.) My own solution seemed reasonably good, using a greedy algorithm to get a starting point, not too unlike Jensen. Then my code used a swapping scheme to search the space, not too inefficiently.

The greedy algorithm trick is to use sort. If we have

[junk,tags] = sort(A,2);

then if the first column of tags contains all of the numbers from 1:n, then the solution is given by that column. This is extremely fast to compute, and so is well worth checking. Even if not, the sort does much of the work that jensen was doing. You only need to look for the columns that were not assigned positions uniquely by the sort.

Regardless, munkres by Yi Cao is an order of magnitude better than my own search scheme. My thanks to those who pointed it out.</description>
		<content:encoded><![CDATA[<p>Interesting. (I&#8217;ve just had a chance to read through what has happened over the last couple of days.) My own solution seemed reasonably good, using a greedy algorithm to get a starting point, not too unlike Jensen. Then my code used a swapping scheme to search the space, not too inefficiently.</p>
<p>The greedy algorithm trick is to use sort. If we have</p>
<p>[junk,tags] = sort(A,2);</p>
<p>then if the first column of tags contains all of the numbers from 1:n, then the solution is given by that column. This is extremely fast to compute, and so is well worth checking. Even if not, the sort does much of the work that jensen was doing. You only need to look for the columns that were not assigned positions uniquely by the sort.</p>
<p>Regardless, munkres by Yi Cao is an order of magnitude better than my own search scheme. My thanks to those who pointed it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1337</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Tue, 17 Feb 2009 11:54:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1337</guid>
		<description>By &quot;is possible&quot;, I meant tractable, i.e. solvable in polynomial time, rather than the factorial (which is greater than exponential!) time of an exhaustive search. I&#039;m sure there are several methods that can be used to solve it - I use the Linear Interior Point Solver in linprog, but the Simplex method would work just as well (though I found it to be slower). Darren has suggested the Hungarian method, which (using the implementation suggested) is much faster, as it is tailored to this particular type of problem. Good work, Darren!</description>
		<content:encoded><![CDATA[<p>By &#8220;is possible&#8221;, I meant tractable, i.e. solvable in polynomial time, rather than the factorial (which is greater than exponential!) time of an exhaustive search. I&#8217;m sure there are several methods that can be used to solve it &#8211; I use the Linear Interior Point Solver in linprog, but the Simplex method would work just as well (though I found it to be slower). Darren has suggested the Hungarian method, which (using the implementation suggested) is much faster, as it is tailored to this particular type of problem. Good work, Darren!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren R</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1336</link>
		<dc:creator>Darren R</dc:creator>
		<pubDate>Tue, 17 Feb 2009 06:24:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1336</guid>
		<description>This problem is analogous to the &quot;job assignment&quot; problem, for which a polynomial-time algorithm exists (Hungarian method). A number of implementations are on the file exchange, see for example
http://www.mathworks.com/matlabcentral/fileexchange/20652</description>
		<content:encoded><![CDATA[<p>This problem is analogous to the &#8220;job assignment&#8221; problem, for which a polynomial-time algorithm exists (Hungarian method). A number of implementations are on the file exchange, see for example<br />
<a href="http://www.mathworks.com/matlabcentral/fileexchange/20652" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/20652</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1334</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Mon, 16 Feb 2009 11:10:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1334</guid>
		<description>In fact, finding the optimal solution IS possible using linear programming:
&lt;pre&gt; &lt;code&gt;function [matOut, trace] = findTrace(matIn)
% Specify the problem as a linear program
N = size(matIn,1);
% Create the equality matrix
i = reshape(repmat(1:2*N, [N 1]), [], 1);
j = bsxfun(@plus, (1:N)&#039;, 0:N:N*N-1);
j = [reshape(j, [], 1); reshape(j&#039;, [], 1)];
Aeq = sparse(i, j, ones(size(i)), 2*N, N*N);
% Optimize
options = optimset(&#039;LargeScale&#039;, &#039;on&#039;, &#039;Display&#039;, &#039;off&#039;);
x = linprog(matIn(:), [], [], Aeq, ones(1, 2*N), zeros(N*N, 1), ones(N*N, 1), [], options);
x = reshape(x, N, N);
% Extract the permutation
[perm dummy] = find(x&#039; &gt; 0.5);
matOut = matIn(:,perm);
trace = diag(matOut);
% Check the solution is valid
assert(numel(perm)==N &amp;&amp; numel(unique(perm(:)))==N);&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>In fact, finding the optimal solution IS possible using linear programming:</p>
<pre> <code>function [matOut, trace] = findTrace(matIn)
% Specify the problem as a linear program
N = size(matIn,1);
% Create the equality matrix
i = reshape(repmat(1:2*N, [N 1]), [], 1);
j = bsxfun(@plus, (1:N)', 0:N:N*N-1);
j = [reshape(j, [], 1); reshape(j', [], 1)];
Aeq = sparse(i, j, ones(size(i)), 2*N, N*N);
% Optimize
options = optimset('LargeScale', 'on', 'Display', 'off');
x = linprog(matIn(:), [], [], Aeq, ones(1, 2*N), zeros(N*N, 1), ones(N*N, 1), [], options);
x = reshape(x, N, N);
% Extract the permutation
[perm dummy] = find(x' &gt; 0.5);
matOut = matIn(:,perm);
trace = diag(matOut);
% Check the solution is valid
assert(numel(perm)==N &amp;&amp; numel(unique(perm(:)))==N);</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1333</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Mon, 16 Feb 2009 11:04:09 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2009/02/13/puzzler-optimize-this/#comment-1333</guid>
		<description>A problem with the test script is that it doesn&#039;t verify the validity of solutions. To do this one must check that the permutation of columns contains unique indices. Rewriting Jensen&#039;s solution to explicitly generate the permutation, we see that it uses some columns multiple times:
&lt;pre&gt; &lt;code&gt;
function [matOut tr] = findTrace3(matIn)
[nr nc]    = size(matIn);
matOut     = matIn;
perm = zeros(nc, 1);
for n = 1 : nc
    [value cIndex]    	= min(min(matIn));
    rowNr            	= find(matIn(:,cIndex) == value, 1);
    perm(rowNr)	        = cIndex;
    matIn(rowNr,:)     = NaN;
end
matOut = matOut(:,perm);
tr = diag(matOut);
% Check the solution is valid
assert(numel(perm)==nc &amp;&amp; numel(unique(perm(:)))==nc);
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>A problem with the test script is that it doesn&#8217;t verify the validity of solutions. To do this one must check that the permutation of columns contains unique indices. Rewriting Jensen&#8217;s solution to explicitly generate the permutation, we see that it uses some columns multiple times:</p>
<pre> <code>
function [matOut tr] = findTrace3(matIn)
[nr nc]    = size(matIn);
matOut     = matIn;
perm = zeros(nc, 1);
for n = 1 : nc
    [value cIndex]    	= min(min(matIn));
    rowNr            	= find(matIn(:,cIndex) == value, 1);
    perm(rowNr)	        = cIndex;
    matIn(rowNr,:)     = NaN;
end
matOut = matOut(:,perm);
tr = diag(matOut);
% Check the solution is valid
assert(numel(perm)==nc &amp;&amp; numel(unique(perm(:)))==nc);
</code></pre>
]]></content:encoded>
	</item>
</channel>
</rss>

