• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 18685379784

21 Oct 2025 01:25PM UTC coverage: 72.522% (+0.1%) from 72.391%
18685379784

push

github

paulmthompson
fix failing tests

18 of 40 new or added lines in 1 file covered. (45.0%)

1765 existing lines in 32 files now uncovered.

53998 of 74457 relevant lines covered (72.52%)

46177.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.14
/src/StateEstimation/MinCostFlowSolver.cpp
1
#include "MinCostFlowSolver.hpp"
2

3
#include "ortools/graph/min_cost_flow.h"
4

5
#include <unordered_map>
6

7
namespace StateEstimation {
8

9
std::optional<std::vector<int>>
10
solveMinCostSingleUnitPath(int num_nodes,
1✔
11
                           int source_node,
12
                           int sink_node,
13
                           std::vector<ArcSpec> const & arcs) {
14
    operations_research::SimpleMinCostFlow min_cost_flow;
1✔
15

16
    for (ArcSpec const & a : arcs) {
4✔
17
        min_cost_flow.AddArcWithCapacityAndUnitCost(a.tail, a.head, a.capacity, a.unit_cost);
3✔
18
    }
19

20
    min_cost_flow.SetNodeSupply(source_node, 1);
1✔
21
    min_cost_flow.SetNodeSupply(sink_node, -1);
1✔
22

23
    auto status = min_cost_flow.Solve();
1✔
24
    if (status != operations_research::SimpleMinCostFlow::OPTIMAL) {
1✔
UNCOV
25
        std::cerr << "Min-cost flow solver failed with status: " << status << std::endl;
×
26

27
        //Try again with solvemaxflowwithmincost
UNCOV
28
        status = min_cost_flow.SolveMaxFlowWithMinCost();
×
29

UNCOV
30
        if (status != operations_research::SimpleMinCostFlow::OPTIMAL) {
×
UNCOV
31
            std::cerr << "Min-cost with max flow failed with status: " << status << std::endl;
×
32
        }
33
        else {
UNCOV
34
            std::cout << "Min-cost flow solver succeeded when switched to max flow with status: " << status << std::endl;
×
35
        }
36

UNCOV
37
        return std::nullopt;
×
38
    }
39

40
    // Build successor map from positive-flow arcs
41
    std::unordered_map<int, int> successor;
1✔
42
    successor.reserve(static_cast<size_t>(min_cost_flow.NumNodes()));
1✔
43
    for (int a = 0; a < min_cost_flow.NumArcs(); ++a) {
4✔
44
        if (min_cost_flow.Flow(a) > 0) {
3✔
45
            successor[min_cost_flow.Tail(a)] = min_cost_flow.Head(a);
3✔
46
        }
47
    }
48

49
    // Follow from source to sink to produce a node sequence
50
    std::vector<int> sequence;
1✔
51
    sequence.reserve(static_cast<size_t>(num_nodes));
1✔
52
    int current = source_node;
1✔
53
    sequence.push_back(current);
1✔
54

55
    const int flow_limit = 10;
1✔
56

57
    for (int steps = 0; steps < (num_nodes + 2)*flow_limit; ++steps) {
3✔
58
        auto it = successor.find(current);
3✔
59
        if (it == successor.end()) break;
3✔
60
        current = it->second;
3✔
61
        sequence.push_back(current);
3✔
62
        if (current == sink_node) break;
3✔
63
    }
64

65
    if (sequence.empty() || sequence.front() != source_node) {
1✔
UNCOV
66
        std::cerr << "Min-cost flow solver failed to find a path from source to sink" << std::endl;
×
UNCOV
67
        return std::nullopt;
×
68
    }
69
    return sequence;
1✔
70
}
1✔
71

72
} // namespace StateEstimation
73

74

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc