# STV with Constraints

The single transferable vote (STV) is an amazing voting system because it naturally provides proportional representation. This means that the demographics or interests of the elected candidates will tend to match the demographics or interests of the voters.

Some organizations want to use STV for their online elections, but also want to require that the elected candidates meet a specified requirement. For example, an organization might want to require that half the elected candidates are women and half are men.

It is fairly straightforward to impose constraints like this in an STV election with OpaVote, and in this post, we provide instructions for how to do this. As an example, we'll consider an organization with 10 candidates (denote them as W1, ..., W5 and M1, ..., M5) running for 6 positions, and the organization requires that the 6 positions are filled by 3 women and 3 men.

The first step is to simply run an STV election. If the outcome of the election meets the constraints, then you are done! If not, then we take action to make sure the constraint is met. In particular, we remove candidates from the election to make sure the constraint is met.

An STV count proceeds in rounds (here are example STV results). At one round in the results, a constraint will be violated. For example, at round 6, we may have 3 men elected (M1, M2, and M3) and 1 woman elected (W1), and at round 7, a fourth man (M4) may be elected. We now have a constraint violation at round 7!

The solution is to eliminate M4 and M5 from the election and recount the votes. You can do this by creating a "Count" at OpaVote using the ballots from the election. Before counting the ballots in an OpaVote Count, you have the option to remove one or more candidates from the ballot. For this second count of the votes, we now elect 3 women and 3 men and we are done.

While this is straightforward, there is one quirk that I want to warn you about. It is possible (although very unlikely) that W1 is not a winner of the second election even though she was a winner of the first election. In other words, it is possible that the three women elected in the second election are W2, W3, and W4. This may seem surprising at first, but it actually makes sense. Under the imposed constraints (equal men and women), the voters believe that W2, W3, and W4, are the best women candidates to represent them.

You can also impose more complicated constraints. For example, a sports club may want to elect 2 tennis players, 2 swimmers, and 2 golfers. After a first count, tennis player may violate a constraint and extra tennis players are eliminated. After a second count, an extra swimmer may be elected and extra swimmers are eliminated.  A third count may then produce results that meet the constraints.