UDST / choicemodels

Python library for discrete choice modeling
https://udst.github.io/choicemodels
BSD 3-Clause "New" or "Revised" License
74 stars 33 forks source link

[0.2.dev8] added if statement to iterative_lottery and added test #56

Closed cvanoli closed 5 years ago

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.001%) to 75.188% when pulling d9e389c8d11ea942cf51ce1ad23634c2fc8e67a9 on iterative_lottery_add into 769800de1aa50abead0ec42e7e3e31dbe247974d on master.

cvanoli commented 5 years ago

This PR adds a breakpoint in the iterative_lottery_choice function when the maximum capacity of alternatives is less than the minimum size of choosers.

Discussion

The function iterative_lottery_choices in choicemodels/tools/simulation.py allows the choices to be constrained by capacity of alternatives and size of choosers. The while loop works the choices' simulations sequentially, each time reducing the alternatives' available capacity. This loop ends when all choosers are accomodated into the alternatives or when the number of iterations reach the maximum specified (if specified). There is one case that can make this loop infinite. When not all choosers are accomodated and their sizes do not fit into any of the remaining alternative capacities.

Solution

To solve this, I added an if statement with a break that works when the maximum capacity of the remaining alternatives in that iteration is less than the minimum size of the still-to-allocate choosers. This statements is placed after the maximum-iteration piece of code.

Versioning

This PR is 0.2.dev8