title: Optimisation (linear programming) in Python
body: <p>I am new to optimisation and was trying out an example I made up in Python. My objective is to figure out how much of each component I need to add to mimic the product as closely as possible.</p>
  <p>The example that I made goes something like: I get given a product that contains 3 components (x, y, z), these components have values associated with them, but I don't know how much of each component is used to make the final product. One extra condition is that total of the 3 component's values might not match up with final product's values. One constraint I have given myself is that I know how much the product weighs, in this case I made the example 10.</p>
  <p>Since the values for the components and the product might not match up, I thought it might be a good idea to use the difference between each value of the total values of the components and the product and then minimise that wrt the original 3 components.</p>
  <p>I tired using PuLP to solve this, but I'm unsure how to go about writing a good objective function or even if my idea for the objective function will work.</p>
  <p>Some example python code:</p>
  <pre><code>components = pd.DataFrame({
          &quot;x&quot;: [3, 4, 1, 4],
          &quot;y&quot;: [0, 2, 1, 4],
          &quot;z&quot;: [0, 0, 1, 4],
          &quot;total&quot;: [4, 6, 3, 12]
          })
  
  product = pd.DataFrame({
          &quot;product&quot;: [4, 2, 6, 12]
          })
  
  difference = product[&quot;product&quot;] - components[&quot;total&quot;]
  
  # define model
  model = LpProblem(&quot;test&quot;, sense = LpMinimize)
  
  # variables to add to the model to add to the model
  component1 = LpVariable(&quot;component1&quot;, lowBound = 0, upBound = None, cat = &quot;Integer&quot;)
  component2 = LpVariable(&quot;component2&quot;, lowBound = 0, upBound = None, cat = &quot;Integer&quot;)
  component3 = LpVariable(&quot;component3&quot;, lowBound = 0, upBound = None, cat = &quot;Integer&quot;)
  
  # constraints
  
  model += component1 + component2 + component3 == 10
  
  # objective function
  # minimise the difference wrt to the 3 components
  
  model.solve()
  </code></pre>
  <p>Example output (if this is optimal):</p>
  <pre><code>component1 = 3
  component2 = 6
  component3 = 1
  </code></pre>
  <p>Thank you in advance</p>