8 import fields2cover
as f2c
10 def near(a, b, error = 1e-7):
11 assert abs(a - b) < error
15 swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
16 [f2c.Point(0.0, 1.0), f2c.Point(4.0, 1.0)])));
17 swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
18 [f2c.Point(4.0, 3.0), f2c.Point(0.0, 3.0)])));
19 swath3 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
20 [f2c.Point(0.0, 0.0), f2c.Point(1.0, 1.0)])));
24 route.addConnection();
26 route.addConnection();
29 swaths1 = f2c.Swaths();
30 [swaths1.push_back(i)
for i
in [swath1]]
31 swaths2 = f2c.Swaths();
32 [swaths2.push_back(i)
for i
in [swath2]]
33 swaths4 = f2c.Swaths();
34 [swaths4.push_back(i)
for i
in [swath1, swath2, swath1, swath2]]
36 r1 = createRoute(swaths1);
37 r2 = createRoute(swaths2);
38 r4 = createRoute(swaths4);
40 length = f2c.OBJ_DirectDistPathObj();
45 near(length.computeCost(p1, p2), 4.0);
47 ps1 = f2c.VectorPoint([p1, p2]);
48 ps2 = f2c.MultiPoint();
52 near(length.computeCost(ps1), 4.0);
53 near(length.computeCost(ps2), 4.0);
54 near(length.computeCost(p1, p2, 0.0), 4.0);
55 near(length.computeCost(p1, 0.0, p2), 4.0);
56 near(length.computeCost(p1, 0.0, p2, 0.0), 4.0);
57 near(length.computeCost(p1, swath2), 5.0);
58 near(length.computeCost(swath2, p1), 3.0);
59 near(length.computeCost(p1, 0.0, swath2), 5.0);
60 near(length.computeCost(swath2, p1, 0.0), 3.0);
62 near(length.computeCost(swath2, ps2), 3.0);
63 near(length.computeCost(swaths2, ps2), 3.0);
64 near(length.computeCost(ps2, swath2), 3.0);
65 near(length.computeCost(ps2, swaths2), 3.0);
67 near(length.computeCost(swath2), 4.0);
68 near(length.computeCost(swaths4), 22.0);
70 near(length.computeCost(f2c.MultiPoint(), swath2), 0.0);
71 near(length.computeCost(swath2, f2c.MultiPoint()), 0.0);
73 near(length.computeCost(r1), 4.0);
74 near(length.computeCostWithMinimizingSign(r1), length.computeCost(r1));
75 near(length.computeCost(r2), 4.0);
76 near(length.computeCostWithMinimizingSign(r2), length.computeCost(r2));
77 near(length.computeCost(r4), 22.0);
78 near(length.computeCostWithMinimizingSign(r4), length.computeCost(r4));
81 objective = f2c.OBJ_DirectDistPathObj();
83 assert not (objective.isMaximizing());
84 assert (objective.isMinimizing());