title: How to set up linear programming optimization in R using LpSolve?
body: <p>For example, I have this sample data:</p>
  
  <pre><code>d=data.frame(x=c(1,1,1,2,2,3,4,4),y=c(5,6,7,8,7,5,6,5),w=c(1,2,3,4,5,6,7,8))
  </code></pre>
  
  <p>Which looks like this:</p>
  
  <pre><code>  x y w
  1 1 5 1
  2 1 6 2
  3 1 7 3
  4 2 8 4
  5 2 7 5
  6 3 5 6
  7 4 6 7
  8 4 5 8
  </code></pre>
  
  <p><code>x</code> and <code>y</code> represent indices from <code>datax</code> and <code>datay</code>. <code>w</code> represents a score from comparing <code>datax[x]</code> with <code>datay[y]</code>. I want to maximize the total score (or <code>w</code>) from <code>d</code>, where each value of <code>x</code> is matched to at most one value of <code>y</code>, and vice versa.</p>
  
  <p>The result should look like this:</p>
  
  <pre><code>  x y w
  1 2 7 5
  2 3 5 6
  3 4 6 7
  </code></pre>
  
  <p>Where the sum of all <code>w</code> values is maximized, and each <code>x</code> and each <code>y</code> show up only once in the result.</p>
  
  <p>How do I set this problem up in the <code>lpSolve::lp</code> function?</p>