  Motivated by the problem of market power in electricity markets, we
introduced in previous works a mechanism for simplified markets of two agents
with linear cost. In standard procurement auctions, the market power resulting
from the quadratic transmission losses allows the producers to bid above their
true values, which are their production cost. The mechanism proposed in the
previous paper optimally reduces the producers' margin to the society's
benefit. In this paper, we extend those results to a more general market made
of a finite number of agents with piecewise linear cost functions, which makes
the problem more difficult, but simultaneously more realistic. We show that the
methodology works for a large class of externalities. We also provide an
algorithm to solve the principal allocation problem. Our contribution provides
a benchmark to assess the sub-optimality of the mechanisms used in practice.
