bernardoct / WaterPaths

WaterPaths - A utility planning and management tool based off the NC Triangle model.
Apache License 2.0
18 stars 8 forks source link

InfrastructureManager::infrastructureConstructionHandler does not remove demand-triggered infrastructure #36

Open degorelick opened 4 years ago

degorelick commented 4 years ago

Lines 388-401 of InfrastructureManager.cpp on master branch will not properly remove a built project from the demand_infra_construction_order vector if any ROF-triggered projects exist (i.e. if rof_infra_construction_order is not empty) because of the if-elseif structure. Given increasing demand, this can result in repeated implementation of the same demand-triggered project. A solution would be replacing these lines with the following:

                bool rof_check = false; bool demand_check = false;
                if (!rof_infra_construction_order.empty()) {
                    Utils::removeIntFromVector(rof_infra_construction_order, wss);
                    rof_check = true;
                }
                if (!demand_infra_construction_order.empty()) {
                    Utils::removeIntFromVector(demand_infra_construction_order, wss);
                    demand_check = true;
                }
                // if a project was triggered, but removed from neither list, throw error
                if (!rof_check && !demand_check)
                    throw logic_error("Infrastructure option whose construction was"
                                        " complete is not in the demand or "
                                        "rof triggered construction lists.");
bernardoct commented 4 years ago

Hi Dave, thanks for submitting the issue and sorry about the awfully delayed reply. I've been busy for a while helping a Brazilian MS student using WaterPaths and her schedule is quite tight, which is why I haven't gotten into this yet.

If you have the time and the disposition, would you mind creating a unit test for this and submitting a pull request with your bug fix?