title: How can I implement an all different constraint in LPSolve?
body: <p>I have a problem whose solution must contain a unique value in each variable.  E.g., 24 fighter pilots must depart in different hours of one day.  So the solution must contain the integerse 1:24, in some order, according to a few constraints on the order.</p>
  
  <p>I've tried using a Special Ordered Set to do that in LPSolve, but I can't understand how to use it.  In any case, my trials have all been taking so long to execute, I cannot believe I am setting this up correctly.  I could use brute force to solve it in 1/1000th of the time.</p>
  
  <p>Is it feasible to use LPSolve/integer programming to optimize an set of unique adjacent integers?  If so, what is the best way to add a constraint to express x1 != x2 != x3 != xN  in R (or Python)?  If not, which algorithm(s) should I be looking into for this kind of optimization?</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>library('lpSolveAPI')
  
  people &lt;- c('Joe', 'Bob', 'Dave', 'Mike')
  number_of_people = length(people)
  
  model &lt;- make.lp(0, number_of_people)
  set.type(model, 1:number_of_people, 'integer')
  set.bounds(model, lower=rep(1, number_of_people), 
        upper=rep(number_of_people, number_of_people))
  
  constraint_names &lt;- c('Bob &lt; Mike')
  add.constraint(model, c(0, 1, 0, -1), '&lt;=', -0.1)
  constraint_names &lt;- append(constraint_names, 'Mike &gt; Joe')
  add.constraint(model, c(-1, 0, 0, 1), '&gt;=', 0.1)
  dimnames(model) &lt;- list(constraint_names, people)
  
  #not sure about this
  #add.SOS(model, 'different positions', type=2, 
  #priority=1,columns=1:number_of_people, weights=rep(1, number_of_people))
  
  set.objfn(model, rep(1, length(people)))
  lp.control(model, sense='min')
  write.lp(model,'model.lp',type='lp')
  
  solve(model)
  get.variables(model)
  </code></pre>