title: Value of objective and constraint are endogenous in lpSolveAPI
body: <p>Hello I'm running a linear programming in R with lpSolveAPI and it's almost my first try to do it. I made a simple version of model about maximizing consumer surplus and variables are set of 9 prices. However, I really don't know how to solve endogenity problem between price and demand.</p>
  
  <p>To do this, I supposed simple demand function <code>q_(h,i)=A_(h,i)*P_h^e, price P_h of each hour is different</code>. Following this demand function, consumer's surplus change would be <code>∆CS_(h,i)=A_(h,i)/(e+1)(P^(e+1)-P'^(e+1))</code> and objective fc is <code>max ∆CS_(h,i)</code></p>
  
  <p>Then I add constraints. A company impose 9 prices set to consumer, but their margin rate are controlled as constraints. <code>marginrate=(sum(demand)*price-totalcost)/totalcost</code>. And this margin rate is endogenously affected by consumers' demand.</p>
  
  <p>Demand data of each time period are listed in AA~II data.frame</p>
  
  <pre><code>lprec&lt;-make.lp(0,9)
  set.objfn(lprec,
        obj=1300-c(sum(AA$demand),sum(BB$demand),...sum(II$demand)),
        indices=c(1,2,3,4,5,6,7,8,9))
  add.constraint(lprec,xt=c(sum(AA$demand),...,sum(II$demand)),"=", marginrate*totalcost+totalcost,indices=c(1,2,3,4,5,6,7,8,9))
  </code></pre>
  
  <p>And plus other constraints. Here, at first, I'd want to add constraint that this model can reflect demand change by price change. But I cannot imagine how to put AA~II$demand is determined by prices which are chosen variables <code>q_(h,i)=A_(h,i)*P_h^e</code>.</p>
  
  <p>Next another problem is total cost. Total cost is not only affected by endogenous value of demand, but by cost function which depends on total demand of consumer.</p>
  
  <p>I'm not sure my question can be delivered to you. 
  My key question is how to solve endogeneity problem in lp model. I'm first in lp model and it is easy to understand lp model constituted with scholar value (e.g. profit maximization with constant cost), but it's not easy to handle vector form of data into lp model.</p>
  
  <p>Thank you for your help !</p>