Line data Source code
1 : #include <catch2/catch_test_macros.hpp>
2 : #include <catch2/matchers/catch_matchers_floating_point.hpp>
3 :
4 : #include "Static/Solution.hpp"
5 :
6 : using Catch::Matchers::WithinAbs;
7 : using namespace std;
8 :
9 1 : TEST_CASE("Static solution", "[static-solution]") {
10 1 : Static::SolutionBase x;
11 2 : SECTION("Add path") {
12 1 : x.addPath(Static::Network::Path{1l, 3l}, 1.0);
13 2 : REQUIRE_THAT(x.getFlowInEdge(1), WithinAbs(1.0, 1e-10));
14 2 : REQUIRE_THAT(x.getFlowInEdge(2), WithinAbs(0.0, 1e-10));
15 3 : REQUIRE_THAT(x.getFlowInEdge(3), WithinAbs(1.0, 1e-10));
16 : }
17 1 : }
18 :
19 4 : TEST_CASE("Static solution interpolation", "[static-solution][interpolation]") {
20 4 : Static::SolutionBase x1;
21 4 : x1.addPath(Static::Network::Path{1, 4, 3, 7}, 2.0);
22 :
23 8 : Static::SolutionBase x2;
24 4 : x2.addPath(Static::Network::Path{4, 2, 6, 5}, 3.0);
25 :
26 4 : double e = 1e-10;
27 :
28 5 : SECTION("alpha=0.0") {
29 2 : Static::Solution x = Static::Solution::interpolate(x1, x2, 0.0);
30 2 : REQUIRE_THAT(x.getFlowInEdge(0), WithinAbs(0.0, e));
31 2 : REQUIRE_THAT(x.getFlowInEdge(1), WithinAbs(2.0, e));
32 2 : REQUIRE_THAT(x.getFlowInEdge(2), WithinAbs(0.0, e));
33 2 : REQUIRE_THAT(x.getFlowInEdge(3), WithinAbs(2.0, e));
34 2 : REQUIRE_THAT(x.getFlowInEdge(4), WithinAbs(2.0, e));
35 2 : REQUIRE_THAT(x.getFlowInEdge(5), WithinAbs(0.0, e));
36 2 : REQUIRE_THAT(x.getFlowInEdge(6), WithinAbs(0.0, e));
37 2 : REQUIRE_THAT(x.getFlowInEdge(7), WithinAbs(2.0, e));
38 3 : REQUIRE_THAT(x.getFlowInEdge(8), WithinAbs(0.0, e));
39 : }
40 :
41 5 : SECTION("alpha=1.0") {
42 2 : Static::Solution x = Static::Solution::interpolate(x1, x2, 1.0);
43 2 : REQUIRE_THAT(x.getFlowInEdge(0), WithinAbs(0.0, e));
44 2 : REQUIRE_THAT(x.getFlowInEdge(1), WithinAbs(0.0, e));
45 2 : REQUIRE_THAT(x.getFlowInEdge(2), WithinAbs(3.0, e));
46 2 : REQUIRE_THAT(x.getFlowInEdge(3), WithinAbs(0.0, e));
47 2 : REQUIRE_THAT(x.getFlowInEdge(4), WithinAbs(3.0, e));
48 2 : REQUIRE_THAT(x.getFlowInEdge(5), WithinAbs(3.0, e));
49 2 : REQUIRE_THAT(x.getFlowInEdge(6), WithinAbs(3.0, e));
50 2 : REQUIRE_THAT(x.getFlowInEdge(7), WithinAbs(0.0, e));
51 3 : REQUIRE_THAT(x.getFlowInEdge(8), WithinAbs(0.0, e));
52 : }
53 :
54 5 : SECTION("alpha=0.5") {
55 2 : Static::Solution x = Static::Solution::interpolate(x1, x2, 0.5);
56 2 : REQUIRE_THAT(x.getFlowInEdge(0), WithinAbs(0.0, e));
57 2 : REQUIRE_THAT(x.getFlowInEdge(1), WithinAbs(1.0, e));
58 2 : REQUIRE_THAT(x.getFlowInEdge(2), WithinAbs(1.5, e));
59 2 : REQUIRE_THAT(x.getFlowInEdge(3), WithinAbs(1.0, e));
60 2 : REQUIRE_THAT(x.getFlowInEdge(4), WithinAbs(2.5, e));
61 2 : REQUIRE_THAT(x.getFlowInEdge(5), WithinAbs(1.5, e));
62 2 : REQUIRE_THAT(x.getFlowInEdge(6), WithinAbs(1.5, e));
63 2 : REQUIRE_THAT(x.getFlowInEdge(7), WithinAbs(1.0, e));
64 3 : REQUIRE_THAT(x.getFlowInEdge(8), WithinAbs(0.0, e));
65 : }
66 :
67 5 : SECTION("alpha=0.3") {
68 2 : Static::Solution x = Static::Solution::interpolate(x1, x2, 0.3);
69 2 : REQUIRE_THAT(x.getFlowInEdge(0), WithinAbs(0.0 * (1.0 - 0.3) + 0.0 * 0.3, e));
70 2 : REQUIRE_THAT(x.getFlowInEdge(1), WithinAbs(2.0 * (1.0 - 0.3) + 0.0 * 0.3, e));
71 2 : REQUIRE_THAT(x.getFlowInEdge(2), WithinAbs(0.0 * (1.0 - 0.3) + 3.0 * 0.3, e));
72 2 : REQUIRE_THAT(x.getFlowInEdge(3), WithinAbs(2.0 * (1.0 - 0.3) + 0.0 * 0.3, e));
73 2 : REQUIRE_THAT(x.getFlowInEdge(4), WithinAbs(2.0 * (1.0 - 0.3) + 3.0 * 0.3, e));
74 2 : REQUIRE_THAT(x.getFlowInEdge(5), WithinAbs(0.0 * (1.0 - 0.3) + 3.0 * 0.3, e));
75 2 : REQUIRE_THAT(x.getFlowInEdge(6), WithinAbs(0.0 * (1.0 - 0.3) + 3.0 * 0.3, e));
76 2 : REQUIRE_THAT(x.getFlowInEdge(7), WithinAbs(2.0 * (1.0 - 0.3) + 0.0 * 0.3, e));
77 3 : REQUIRE_THAT(x.getFlowInEdge(8), WithinAbs(0.0 * (1.0 - 0.3) + 0.0 * 0.3, e));
78 : }
79 4 : }
|