GCC Code Coverage Report


Directory: ./
File: src/path-optimization/random-shortcut.cc
Date: 2025-03-07 11:10:46
Exec Total Coverage
Lines: 0 22 0.0%
Branches: 0 26 0.0%

Line Branch Exec Source
1 // Copyright (c) 2018, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28
29 #include <hpp/core/path-vector.hh>
30 #include <hpp/core/path.hh>
31 #include <hpp/manipulation/constraint-set.hh>
32 #include <hpp/manipulation/graph/edge.hh>
33 #include <hpp/manipulation/path-optimization/random-shortcut.hh>
34
35 namespace hpp {
36 namespace manipulation {
37 namespace pathOptimization {
38 using core::PathPtr_t;
39 using core::PathVector;
40 using core::PathVectorPtr_t;
41
42 bool isShort(const PathVectorPtr_t& path, const value_type& t) {
43 value_type localT;
44 std::size_t i = path->rankAtParam(t, localT);
45 PathPtr_t p = path->pathAtRank(i);
46 PathVectorPtr_t pv = HPP_DYNAMIC_PTR_CAST(PathVector, p);
47 if (pv) return isShort(pv, localT);
48 ConstraintSetPtr_t c =
49 HPP_DYNAMIC_PTR_CAST(ConstraintSet, path->constraints());
50 if (c) return c->edge()->isShort();
51 return false;
52 }
53
54 bool RandomShortcut::shootTimes(const PathVectorPtr_t& currentOpt,
55 const value_type& t0, value_type& t1,
56 value_type& t2, const value_type& t3) {
57 bool ok = false;
58 for (int i = 0; i < 5; ++i) {
59 value_type u2 = (t3 - t0) * rand() / RAND_MAX;
60 value_type u1 = (t3 - t0) * rand() / RAND_MAX;
61 if (isShort(currentOpt, u1) || isShort(currentOpt, u2)) continue;
62 if (u1 < u2) {
63 t1 = t0 + u1;
64 t2 = t0 + u2;
65 } else {
66 t1 = t0 + u2;
67 t2 = t0 + u1;
68 }
69 ok = true;
70 break;
71 }
72 return ok;
73 }
74 } // namespace pathOptimization
75 } // namespace manipulation
76 } // namespace hpp
77