Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 1099e73f16f15ba3cf656e619f52a447 > files > 208

ompl-devel-0.9.5-1.fc14.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8"/>
<title>OMPL: src/ompl/geometric/planners/prm/src/PRM.cpp Source File</title>
<meta name="author" content="Ioan A. Șucan, Mark Moll, Lydia E. Kavraki">
<link rel="stylesheet" href="../css/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="../css/print.css" type="text/css" media="print">
<!--[if lt IE 7]>
<script type="text/javascript" src="../js/jquery/jquery.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.dropdown.js"></script>
<![endif]-->
<script type="text/javaScript" src="search/search.js"></script>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-9156598-2']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search API');
--></script>
<div class="navigation" id="top">
  <div class="tabs" id="ompltitle">
    <ul class="tablist">
      <li>The Open Motion Planning Library</li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search API" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>

  <ul id="nav" class="dropdown">
    <li class="first"><a href="index.html">Home</a></li>
    <li><a href="download.html">Download</a></li>
    <li><a href="documentation.html">Documentation</a></li>
    <li><span class="dir">Code API</span>
      <ul>
        <li><a href="api_overview.html">API Overview</a></li>
        <li><a href="namespaces.html">Namespaces</a></li>
        <li><a href="annotated.html">Classes</a></li>
        <li><a href="files.html">Files</a></li>
        <li><a href="dirs.html">Directories</a></li>
      </ul>
    </li>
    <li><span class="dir">Community</span>
      <ul>
        <li><a href="developers.html">Developers</a></li>
        <li><a href="thirdparty.html">Contributions</a></li>
        <li><a href="education.html">Education</a></li>
        <li><a href="gallery.html">Gallery</a></li>
      </ul>
    </li>
    <li><span class="dir">About</span>
      <ul>
        <li><a href="license.html">License</a></li>
        <li><a href="citations.html">Citations</a></li>
        <li><a href="acknowledgements.html">Acknowledgments</a></li>
        <li><a href="contact.html">Contact Us</a></li>
      </ul>
    </li>
  </ul>
</div>

<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
  onmouseover="return searchBox.OnSearchSelectShow()"
  onmouseout="return searchBox.OnSearchSelectHide()"
  onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
  <iframe src="" frameborder="0"name="MSearchResults" id="MSearchResults"></iframe>
</div>

<div class="container">
  <div class="span-22 push-2 first last">
  <div>
<!-- Generated by Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_f5421e52a658cd938113ed6044324834.html">src</a>      </li>
      <li class="navelem"><a class="el" href="dir_ae92c2ff78847f0cb49b545f9089bbbc.html">ompl</a>      </li>
      <li class="navelem"><a class="el" href="dir_09c87af92e12dad9ad42621ff12ca21c.html">geometric</a>      </li>
      <li class="navelem"><a class="el" href="dir_ea5fd944e8f903b1c975832ff4982cc4.html">planners</a>      </li>
      <li class="navelem"><a class="el" href="dir_0bc9285a285c1ab505d89a54e821cc99.html">prm</a>      </li>
      <li class="navelem"><a class="el" href="dir_abd15b36824fdbca1af43ff409e42bfd.html">src</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">PRM.cpp</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*********************************************************************</span>
<a name="l00002"></a>00002 <span class="comment">* Software License Agreement (BSD License)</span>
<a name="l00003"></a>00003 <span class="comment">*</span>
<a name="l00004"></a>00004 <span class="comment">*  Copyright (c) 2011, Rice University</span>
<a name="l00005"></a>00005 <span class="comment">*  All rights reserved.</span>
<a name="l00006"></a>00006 <span class="comment">*</span>
<a name="l00007"></a>00007 <span class="comment">*  Redistribution and use in source and binary forms, with or without</span>
<a name="l00008"></a>00008 <span class="comment">*  modification, are permitted provided that the following conditions</span>
<a name="l00009"></a>00009 <span class="comment">*  are met:</span>
<a name="l00010"></a>00010 <span class="comment">*</span>
<a name="l00011"></a>00011 <span class="comment">*   * Redistributions of source code must retain the above copyright</span>
<a name="l00012"></a>00012 <span class="comment">*     notice, this list of conditions and the following disclaimer.</span>
<a name="l00013"></a>00013 <span class="comment">*   * Redistributions in binary form must reproduce the above</span>
<a name="l00014"></a>00014 <span class="comment">*     copyright notice, this list of conditions and the following</span>
<a name="l00015"></a>00015 <span class="comment">*     disclaimer in the documentation and/or other materials provided</span>
<a name="l00016"></a>00016 <span class="comment">*     with the distribution.</span>
<a name="l00017"></a>00017 <span class="comment">*   * Neither the name of the Rice University nor the names of its</span>
<a name="l00018"></a>00018 <span class="comment">*     contributors may be used to endorse or promote products derived</span>
<a name="l00019"></a>00019 <span class="comment">*     from this software without specific prior written permission.</span>
<a name="l00020"></a>00020 <span class="comment">*</span>
<a name="l00021"></a>00021 <span class="comment">*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<a name="l00022"></a>00022 <span class="comment">*  &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<a name="l00023"></a>00023 <span class="comment">*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS</span>
<a name="l00024"></a>00024 <span class="comment">*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE</span>
<a name="l00025"></a>00025 <span class="comment">*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,</span>
<a name="l00026"></a>00026 <span class="comment">*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span>
<a name="l00027"></a>00027 <span class="comment">*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<a name="l00028"></a>00028 <span class="comment">*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</span>
<a name="l00029"></a>00029 <span class="comment">*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
<a name="l00030"></a>00030 <span class="comment">*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN</span>
<a name="l00031"></a>00031 <span class="comment">*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span>
<a name="l00032"></a>00032 <span class="comment">*  POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00033"></a>00033 <span class="comment">*********************************************************************/</span>
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="comment">/* Author: Ioan Sucan, James D. Marble */</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;ompl/geometric/planners/prm/PRM.h&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;ompl/geometric/planners/prm/ConnectionStrategy.h&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;ompl/base/GoalSampleableRegion.h&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;ompl/datastructures/NearestNeighborsGNAT.h&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;ompl/datastructures/PDF.h&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;boost/lambda/bind.hpp&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;boost/graph/astar_search.hpp&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;boost/graph/incremental_components.hpp&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;boost/property_map/vector_property_map.hpp&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &lt;boost/foreach.hpp&gt;</span>
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="preprocessor">#define foreach BOOST_FOREACH</span>
<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define foreach_reverse BOOST_REVERSE_FOREACH</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="keyword">namespace </span>ompl
<a name="l00052"></a>00052 {
<a name="l00053"></a><a class="code" href="namespaceompl_1_1magic.html">00053</a>     <span class="keyword">namespace </span>magic
<a name="l00054"></a>00054     {
<a name="l00055"></a>00055 
<a name="l00059"></a><a class="code" href="namespaceompl_1_1magic.html#ae716f011fd25c37894b1853abfbba05b">00059</a>         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespaceompl_1_1magic.html#ae716f011fd25c37894b1853abfbba05b" title="Maximum number of sampling attempts to find a valid state, without checking whether the allowed time ...">FIND_VALID_STATE_ATTEMPTS_WITHOUT_TIME_CHECK</a> = 2;
<a name="l00060"></a>00060 
<a name="l00063"></a><a class="code" href="namespaceompl_1_1magic.html#acf09430426a57052295791746f014f12">00063</a>         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespaceompl_1_1magic.html#acf09430426a57052295791746f014f12" title="The number of steps to take for a random bounce motion generated as part of the expansion step of PRM...">MAX_RANDOM_BOUNCE_STEPS</a>   = 5;
<a name="l00064"></a>00064 
<a name="l00067"></a><a class="code" href="namespaceompl_1_1magic.html#a44f09b05d50332500c8b681d441f91d2">00067</a>         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespaceompl_1_1magic.html#a44f09b05d50332500c8b681d441f91d2" title="The number of nearest neighbors to consider by default in the construction of the PRM roadmap...">DEFAULT_NEAREST_NEIGHBORS</a> = 10;
<a name="l00068"></a>00068     }
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 
<a name="l00071"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a5db629bb4a2bf02fb76a4cabbc5e0dcb">00071</a> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a5db629bb4a2bf02fb76a4cabbc5e0dcb" title="Constructor.">ompl::geometric::PRM::PRM</a>(<span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1SpaceInformationPtr.html" title="A boost shared pointer wrapper for ompl::base::SpaceInformation.">base::SpaceInformationPtr</a> &amp;si, <span class="keywordtype">bool</span> starStrategy) :
<a name="l00072"></a>00072     base::Planner(si, <span class="stringliteral">&quot;PRM&quot;</span>),
<a name="l00073"></a>00073     starStrategy_(starStrategy),
<a name="l00074"></a>00074     stateProperty_(boost::get(<a class="code" href="structompl_1_1geometric_1_1PRM_1_1vertex__state__t.html">vertex_state_t</a>(), g_)),
<a name="l00075"></a>00075     totalConnectionAttemptsProperty_(boost::get(<a class="code" href="structompl_1_1geometric_1_1PRM_1_1vertex__total__connection__attempts__t.html">vertex_total_connection_attempts_t</a>(), g_)),
<a name="l00076"></a>00076     successfulConnectionAttemptsProperty_(boost::get(<a class="code" href="structompl_1_1geometric_1_1PRM_1_1vertex__successful__connection__attempts__t.html">vertex_successful_connection_attempts_t</a>(), g_)),
<a name="l00077"></a>00077     weightProperty_(boost::get(boost::edge_weight, g_)),
<a name="l00078"></a>00078     edgeIDProperty_(boost::get(boost::edge_index, g_)),
<a name="l00079"></a>00079     disjointSets_(boost::get(boost::vertex_rank, g_),
<a name="l00080"></a>00080                   boost::get(boost::vertex_predecessor, g_)),
<a name="l00081"></a>00081     maxEdgeID_(0),
<a name="l00082"></a>00082     userSetConnectionStrategy_(false)
<a name="l00083"></a>00083 {
<a name="l00084"></a>00084     <a class="code" href="classompl_1_1base_1_1Planner.html#a4311ea7a0470f0e0f76cb1656d63e365" title="The specifications of the planner (its capabilities)">specs_</a>.recognizedGoal = <a class="code" href="namespaceompl_1_1base.html#a1620a159019faf720c550eeca5723f55a6fb685fa51055688c4e130094225b7f9" title="This bit is set if casting to sampleable goal regions (ompl::base::GoalSampleableRegion) is possible...">base::GOAL_SAMPLEABLE_REGION</a>;
<a name="l00085"></a>00085     <a class="code" href="classompl_1_1base_1_1Planner.html#a4311ea7a0470f0e0f76cb1656d63e365" title="The specifications of the planner (its capabilities)">specs_</a>.approximateSolutions = <span class="keyword">true</span>;
<a name="l00086"></a>00086     <a class="code" href="classompl_1_1base_1_1Planner.html#a4311ea7a0470f0e0f76cb1656d63e365" title="The specifications of the planner (its capabilities)">specs_</a>.optimizingPaths = <span class="keyword">true</span>;
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a52ccbc48b63859db436ad03d95091fa9">00089</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a52ccbc48b63859db436ad03d95091fa9" title="Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...">ompl::geometric::PRM::setup</a>(<span class="keywordtype">void</span>)
<a name="l00090"></a>00090 {
<a name="l00091"></a>00091     Planner::setup();
<a name="l00092"></a>00092     <span class="keywordflow">if</span> (!nn_)
<a name="l00093"></a>00093         nn_.reset(<span class="keyword">new</span> <a class="code" href="classompl_1_1NearestNeighborsGNAT.html" title="Geometric Near-neighbor Access Tree (GNAT), a data structure for nearest neighbor search...">NearestNeighborsGNAT&lt;Vertex&gt;</a>());
<a name="l00094"></a>00094     nn_-&gt;setDistanceFunction(boost::bind(&amp;<a class="code" href="classompl_1_1geometric_1_1PRM.html#a983bce5dd72ba208357b5518f4515125" title="Compute distance between two milestones (this is simply distance between the states of the milestones...">PRM::distanceFunction</a>, <span class="keyword">this</span>, _1, _2));
<a name="l00095"></a>00095     <span class="keywordflow">if</span> (!connectionStrategy_)
<a name="l00096"></a>00096     {
<a name="l00097"></a>00097         <span class="keywordflow">if</span> (starStrategy_)
<a name="l00098"></a>00098             connectionStrategy_ = <a class="code" href="classompl_1_1geometric_1_1KStarStrategy.html" title="Make the minimal number of connections required to ensure asymptotic optimality.">KStarStrategy&lt;Vertex&gt;</a>(boost::bind(&amp;<a class="code" href="classompl_1_1geometric_1_1PRM.html#add6627598d515cbc5c77ac7f669f2721" title="Compute distance between two milestones (this is simply distance between the states of the milestones...">PRM::milestoneCount</a>, <span class="keyword">this</span>), nn_, si_-&gt;getStateDimension());
<a name="l00099"></a>00099         <span class="keywordflow">else</span>
<a name="l00100"></a>00100             connectionStrategy_ = <a class="code" href="classompl_1_1geometric_1_1KStrategy.html">KStrategy&lt;Vertex&gt;</a>(<a class="code" href="namespaceompl_1_1magic.html#a44f09b05d50332500c8b681d441f91d2" title="The number of nearest neighbors to consider by default in the construction of the PRM roadmap...">magic::DEFAULT_NEAREST_NEIGHBORS</a>, nn_);
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102     <span class="keywordflow">if</span> (!connectionFilter_)
<a name="l00103"></a>00103         connectionFilter_ = boost::lambda::constant(<span class="keyword">true</span>);
<a name="l00104"></a>00104 }
<a name="l00105"></a>00105 
<a name="l00106"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#ab8832a466b3178de436acbb000712f2b">00106</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#ab8832a466b3178de436acbb000712f2b" title="Convenience function that sets the connection strategy to the default one with k nearest neighbors...">ompl::geometric::PRM::setMaxNearestNeighbors</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k)
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108     <span class="keywordflow">if</span> (!setup_)
<a name="l00109"></a>00109         setup();
<a name="l00110"></a>00110     connectionStrategy_ = <a class="code" href="classompl_1_1geometric_1_1KStrategy.html">KStrategy&lt;Vertex&gt;</a>(k, nn_);
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112 
<a name="l00113"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#aefef4c0c54de26622152347fa0078961">00113</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#aefef4c0c54de26622152347fa0078961" title="Set the problem definition for the planner. The problem needs to be set before calling solve()...">ompl::geometric::PRM::setProblemDefinition</a>(<span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1ProblemDefinitionPtr.html" title="A boost shared pointer wrapper for ompl::base::ProblemDefinition.">base::ProblemDefinitionPtr</a> &amp;pdef)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115     Planner::setProblemDefinition(pdef);
<a name="l00116"></a>00116     startM_.clear();
<a name="l00117"></a>00117     goalM_.clear();
<a name="l00118"></a>00118 }
<a name="l00119"></a>00119 
<a name="l00120"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a54c8858fdff3da173a0650e66f962f94">00120</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a54c8858fdff3da173a0650e66f962f94" title="Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...">ompl::geometric::PRM::clear</a>(<span class="keywordtype">void</span>)
<a name="l00121"></a>00121 {
<a name="l00122"></a>00122     Planner::clear();
<a name="l00123"></a>00123     sampler_.reset();
<a name="l00124"></a>00124     simpleSampler_.reset();
<a name="l00125"></a>00125     freeMemory();
<a name="l00126"></a>00126     <span class="keywordflow">if</span> (nn_)
<a name="l00127"></a>00127         nn_-&gt;clear();
<a name="l00128"></a>00128     startM_.clear();
<a name="l00129"></a>00129     goalM_.clear();
<a name="l00130"></a>00130     maxEdgeID_ = 0;
<a name="l00131"></a>00131 }
<a name="l00132"></a>00132 
<a name="l00133"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a6134f963a94d1ecf831dbac17b04be42">00133</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a6134f963a94d1ecf831dbac17b04be42" title="Free all the memory allocated by the planner.">ompl::geometric::PRM::freeMemory</a>(<span class="keywordtype">void</span>)
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135     <span class="keywordflow">foreach</span> (Vertex v, boost::vertices(g_))
<a name="l00136"></a>00136         si_-&gt;freeState(stateProperty_[v]);
<a name="l00137"></a>00137     g_.clear();
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00140"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a718ea717e0928e0d4555683021508e46">00140</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a718ea717e0928e0d4555683021508e46" title="Attempt to connect disjoint components in the roadmap using random bounding motions (the PRM expansio...">ompl::geometric::PRM::expandRoadmap</a>(<span class="keywordtype">double</span> expandTime)
<a name="l00141"></a>00141 {
<a name="l00142"></a>00142     <span class="keywordflow">if</span> (!simpleSampler_)
<a name="l00143"></a>00143         simpleSampler_ = si_-&gt;allocStateSampler();
<a name="l00144"></a>00144 
<a name="l00145"></a>00145     std::vector&lt;Vertex&gt; empty;
<a name="l00146"></a>00146     std::vector&lt;base::State*&gt; states(<a class="code" href="namespaceompl_1_1magic.html#acf09430426a57052295791746f014f12" title="The number of steps to take for a random bounce motion generated as part of the expansion step of PRM...">magic::MAX_RANDOM_BOUNCE_STEPS</a>);
<a name="l00147"></a>00147     si_-&gt;allocStates(states);
<a name="l00148"></a>00148     expandRoadmap(empty, empty, base::timedPlannerTerminationCondition(expandTime), states);
<a name="l00149"></a>00149     si_-&gt;freeStates(states);
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a3b09a1ba7f16a58264933323fea83065">00152</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a718ea717e0928e0d4555683021508e46" title="Attempt to connect disjoint components in the roadmap using random bounding motions (the PRM expansio...">ompl::geometric::PRM::expandRoadmap</a>(<span class="keyword">const</span> std::vector&lt;Vertex&gt; &amp;starts,
<a name="l00153"></a>00153                                          <span class="keyword">const</span> std::vector&lt;Vertex&gt; &amp;goals,
<a name="l00154"></a>00154                                          <span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1PlannerTerminationCondition.html" title="Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...">base::PlannerTerminationCondition</a> &amp;ptc,
<a name="l00155"></a>00155                                          std::vector&lt;base::State*&gt; &amp;workStates)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157     <span class="comment">// construct a probability distribution over the vertices in the roadmap</span>
<a name="l00158"></a>00158     <span class="comment">// as indicated in</span>
<a name="l00159"></a>00159     <span class="comment">//  &quot;Probabilistic Roadmaps for Path Planning in High-Dimensional Configuration Spaces&quot;</span>
<a name="l00160"></a>00160     <span class="comment">//        Lydia E. Kavraki, Petr Svestka, Jean-Claude Latombe, and Mark H. Overmars</span>
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     <a class="code" href="classompl_1_1PDF.html" title="A container that supports probabilistic sampling over weighted data.">PDF&lt;Vertex&gt;</a> pdf;
<a name="l00163"></a>00163     <span class="keywordflow">foreach</span> (Vertex v, boost::vertices(g_))
<a name="l00164"></a>00164     {
<a name="l00165"></a>00165         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t = totalConnectionAttemptsProperty_[v];
<a name="l00166"></a>00166         pdf.<a class="code" href="classompl_1_1PDF.html#af4083c1c6e1b2e2579cc8e893446cfac" title="Adds a piece of data with a given weight to the PDF. Returns a corresponding Element, which can be used to subsequently update or remove the data from the PDF.">add</a>(v, (<span class="keywordtype">double</span>)(t - successfulConnectionAttemptsProperty_[v]) / (<span class="keywordtype">double</span>)t);
<a name="l00167"></a>00167     }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169     <span class="keywordflow">if</span> (pdf.<a class="code" href="classompl_1_1PDF.html#a78a61ac1ec20e6690ffa33370c95a94d" title="Returns whether the PDF contains no data.">empty</a>())
<a name="l00170"></a>00170         <span class="keywordflow">return</span>;
<a name="l00171"></a>00171 
<a name="l00172"></a>00172     <span class="keywordflow">while</span> (ptc() == <span class="keyword">false</span>)
<a name="l00173"></a>00173     {
<a name="l00174"></a>00174         Vertex v = pdf.<a class="code" href="classompl_1_1PDF.html#a3f8ee992fa9240d15f10c5782166e6c3" title="Returns a piece of data from the PDF according to the input sampling value, which must be between 0 a...">sample</a>(rng_.uniform01());
<a name="l00175"></a>00175         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> s = si_-&gt;randomBounceMotion(simpleSampler_, stateProperty_[v], workStates.size(), workStates, <span class="keyword">false</span>);
<a name="l00176"></a>00176         <span class="keywordflow">if</span> (s &gt; 0)
<a name="l00177"></a>00177         {
<a name="l00178"></a>00178             s--;
<a name="l00179"></a>00179             Vertex last = addMilestone(si_-&gt;cloneState(workStates[s]));
<a name="l00180"></a>00180 
<a name="l00181"></a>00181             <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0 ; i &lt; s ; ++i)
<a name="l00182"></a>00182             {
<a name="l00183"></a>00183                 <span class="comment">// add the vertex along the bouncing motion</span>
<a name="l00184"></a>00184                 Vertex m = boost::add_vertex(g_);
<a name="l00185"></a>00185                 stateProperty_[m] = si_-&gt;cloneState(workStates[i]);
<a name="l00186"></a>00186                 totalConnectionAttemptsProperty_[m] = 1;
<a name="l00187"></a>00187                 successfulConnectionAttemptsProperty_[m] = 0;
<a name="l00188"></a>00188                 disjointSets_.make_set(m);
<a name="l00189"></a>00189 
<a name="l00190"></a>00190                 <span class="comment">// add the edge to the parent vertex</span>
<a name="l00191"></a>00191                 <span class="keyword">const</span> <span class="keywordtype">double</span> weight = distanceFunction(v, m);
<a name="l00192"></a>00192                 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span> = maxEdgeID_++;
<a name="l00193"></a>00193                 <span class="keyword">const</span> Graph::edge_property_type properties(weight, <span class="keywordtype">id</span>);
<a name="l00194"></a>00194                 boost::add_edge(v, m, properties, g_);
<a name="l00195"></a>00195                 uniteComponents(v, m);
<a name="l00196"></a>00196 
<a name="l00197"></a>00197                 <span class="comment">// add the vertext to the nearest neighbors data structure</span>
<a name="l00198"></a>00198                 nn_-&gt;add(m);
<a name="l00199"></a>00199                 v = m;
<a name="l00200"></a>00200             }
<a name="l00201"></a>00201 
<a name="l00202"></a>00202             <span class="comment">// if there are intermediary states or the milestone has not been connected to the initially sampled vertex,</span>
<a name="l00203"></a>00203             <span class="comment">// we add an edge</span>
<a name="l00204"></a>00204             <span class="keywordflow">if</span> (s &gt; 0 || !boost::same_component(v, last, disjointSets_))
<a name="l00205"></a>00205             {
<a name="l00206"></a>00206                 <span class="comment">// add the edge to the parent vertex</span>
<a name="l00207"></a>00207                 <span class="keyword">const</span> <span class="keywordtype">double</span> weight = distanceFunction(v, last);
<a name="l00208"></a>00208                 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span> = maxEdgeID_++;
<a name="l00209"></a>00209                 <span class="keyword">const</span> Graph::edge_property_type properties(weight, <span class="keywordtype">id</span>);
<a name="l00210"></a>00210                 boost::add_edge(v, last, properties, g_);
<a name="l00211"></a>00211                 uniteComponents(v, last);
<a name="l00212"></a>00212             }
<a name="l00213"></a>00213             <span class="keywordflow">if</span> (haveSolution(starts, goals))
<a name="l00214"></a>00214                 <span class="keywordflow">break</span>;
<a name="l00215"></a>00215         }
<a name="l00216"></a>00216     }
<a name="l00217"></a>00217 }
<a name="l00218"></a>00218 
<a name="l00219"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a9f15e6dafe26d97547526317b457c201">00219</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a9f15e6dafe26d97547526317b457c201" title="If the user desires, the roadmap can be improved for a specified amount of time. The solve() method w...">ompl::geometric::PRM::growRoadmap</a>(<span class="keywordtype">double</span> growTime)
<a name="l00220"></a>00220 {
<a name="l00221"></a>00221     <span class="keywordflow">if</span> (!isSetup())
<a name="l00222"></a>00222         setup();
<a name="l00223"></a>00223     <span class="keywordflow">if</span> (!sampler_)
<a name="l00224"></a>00224         sampler_ = si_-&gt;allocValidStateSampler();
<a name="l00225"></a>00225 
<a name="l00226"></a>00226     <a class="code" href="namespaceompl_1_1time.html#a9f28e947d7e95cfa5f0790ccdb7f0953" title="Representation of a point in time.">time::point</a> endTime = <a class="code" href="namespaceompl_1_1time.html#a1413ad6c9709d0699343679b291b9c1d" title="Get the current time point.">time::now</a>() + <a class="code" href="namespaceompl_1_1time.html#acac374ab4374adb207edb38cedb7fbb1" title="Return the time duration representing a given number of seconds.">time::seconds</a>(growTime);
<a name="l00227"></a>00227     <a class="code" href="classompl_1_1base_1_1State.html" title="Definition of an abstract state.">base::State</a> *workState = si_-&gt;allocState();
<a name="l00228"></a>00228     <span class="keywordflow">while</span> (<a class="code" href="namespaceompl_1_1time.html#a1413ad6c9709d0699343679b291b9c1d" title="Get the current time point.">time::now</a>() &lt; endTime)
<a name="l00229"></a>00229     {
<a name="l00230"></a>00230         <span class="comment">// search for a valid state</span>
<a name="l00231"></a>00231         <span class="keywordtype">bool</span> found = <span class="keyword">false</span>;
<a name="l00232"></a>00232         <span class="keywordflow">while</span> (!found &amp;&amp; <a class="code" href="namespaceompl_1_1time.html#a1413ad6c9709d0699343679b291b9c1d" title="Get the current time point.">time::now</a>() &lt; endTime)
<a name="l00233"></a>00233         {
<a name="l00234"></a>00234             <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> attempts = 0;
<a name="l00235"></a>00235             <span class="keywordflow">do</span>
<a name="l00236"></a>00236             {
<a name="l00237"></a>00237                 found = sampler_-&gt;sample(workState);
<a name="l00238"></a>00238                 attempts++;
<a name="l00239"></a>00239             } <span class="keywordflow">while</span> (attempts &lt; <a class="code" href="namespaceompl_1_1magic.html#ae716f011fd25c37894b1853abfbba05b" title="Maximum number of sampling attempts to find a valid state, without checking whether the allowed time ...">magic::FIND_VALID_STATE_ATTEMPTS_WITHOUT_TIME_CHECK</a> &amp;&amp; !found);
<a name="l00240"></a>00240         }
<a name="l00241"></a>00241         <span class="comment">// add it as a milestone</span>
<a name="l00242"></a>00242         <span class="keywordflow">if</span> (found)
<a name="l00243"></a>00243             addMilestone(si_-&gt;cloneState(workState));
<a name="l00244"></a>00244     }
<a name="l00245"></a>00245     si_-&gt;freeState(workState);
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247 
<a name="l00248"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a2815e95d4785eeb45175f1cb4d5778a9">00248</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a9f15e6dafe26d97547526317b457c201" title="If the user desires, the roadmap can be improved for a specified amount of time. The solve() method w...">ompl::geometric::PRM::growRoadmap</a>(<span class="keyword">const</span> std::vector&lt;Vertex&gt; &amp;start,
<a name="l00249"></a>00249                                        <span class="keyword">const</span> std::vector&lt;Vertex&gt; &amp;goal,
<a name="l00250"></a>00250                                        <span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1PlannerTerminationCondition.html" title="Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...">base::PlannerTerminationCondition</a> &amp;ptc,
<a name="l00251"></a>00251                                        <a class="code" href="classompl_1_1base_1_1State.html" title="Definition of an abstract state.">base::State</a> *workState)
<a name="l00252"></a>00252 {
<a name="l00253"></a>00253     <span class="keywordflow">while</span> (ptc() == <span class="keyword">false</span>)
<a name="l00254"></a>00254     {
<a name="l00255"></a>00255         <span class="comment">// search for a valid state</span>
<a name="l00256"></a>00256         <span class="keywordtype">bool</span> found = <span class="keyword">false</span>;
<a name="l00257"></a>00257         <span class="keywordflow">while</span> (!found &amp;&amp; ptc() == <span class="keyword">false</span>)
<a name="l00258"></a>00258         {
<a name="l00259"></a>00259             <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> attempts = 0;
<a name="l00260"></a>00260             <span class="keywordflow">do</span>
<a name="l00261"></a>00261             {
<a name="l00262"></a>00262                 found = sampler_-&gt;sample(workState);
<a name="l00263"></a>00263                 attempts++;
<a name="l00264"></a>00264             } <span class="keywordflow">while</span> (attempts &lt; <a class="code" href="namespaceompl_1_1magic.html#ae716f011fd25c37894b1853abfbba05b" title="Maximum number of sampling attempts to find a valid state, without checking whether the allowed time ...">magic::FIND_VALID_STATE_ATTEMPTS_WITHOUT_TIME_CHECK</a> &amp;&amp; !found);
<a name="l00265"></a>00265         }
<a name="l00266"></a>00266         <span class="comment">// add it as a milestone</span>
<a name="l00267"></a>00267         <span class="keywordflow">if</span> (found)
<a name="l00268"></a>00268         {
<a name="l00269"></a>00269             addMilestone(si_-&gt;cloneState(workState));
<a name="l00270"></a>00270             <span class="keywordflow">if</span> (haveSolution(start, goal))
<a name="l00271"></a>00271                 <span class="keywordflow">break</span>;
<a name="l00272"></a>00272         }
<a name="l00273"></a>00273     }
<a name="l00274"></a>00274 }
<a name="l00275"></a>00275 
<a name="l00276"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#acdfe06f2ca9b6e13149a0ce0aa228e59">00276</a> <span class="keywordtype">bool</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#acdfe06f2ca9b6e13149a0ce0aa228e59" title="Check if there exists a solution, i.e., there exists a pair of milestones such that the first is in s...">ompl::geometric::PRM::haveSolution</a>(<span class="keyword">const</span> std::vector&lt;Vertex&gt; &amp;starts, <span class="keyword">const</span> std::vector&lt;Vertex&gt; &amp;goals, std::pair&lt;Vertex, Vertex&gt; *endpoints)
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278     <a class="code" href="classompl_1_1base_1_1Goal.html" title="Abstract definition of goals. Will contain solutions, if found.">base::Goal</a> *g = pdef_-&gt;getGoal().get();
<a name="l00279"></a>00279     <span class="keywordflow">foreach</span> (Vertex start, starts)
<a name="l00280"></a>00280         <span class="keywordflow">foreach</span> (Vertex goal, goals)
<a name="l00281"></a>00281         {
<a name="l00282"></a>00282 
<a name="l00283"></a>00283             <span class="keywordflow">if</span> (boost::same_component(start, goal, disjointSets_) &amp;&amp;
<a name="l00284"></a>00284                 g-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#a5d5285908b7e09d61577279f35e47175" title="Since there can be multiple starting states (and multiple goal states) it is possible certain pairs a...">isStartGoalPairValid</a>(stateProperty_[goal], stateProperty_[start]))
<a name="l00285"></a>00285             {
<a name="l00286"></a>00286                 <span class="keywordtype">bool</span> sol = <span class="keyword">true</span>;
<a name="l00287"></a>00287 
<a name="l00288"></a>00288                 <span class="comment">// if there is a maximum path length we wish to accept, we need to check the solution length</span>
<a name="l00289"></a>00289                 <span class="keywordflow">if</span> (g-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#a033696b98580c4be0694a878ef1e7bbb" title="Get the maximum length allowed for a solution path.">getMaximumPathLength</a>() &lt; std::numeric_limits&lt;double&gt;::infinity())
<a name="l00290"></a>00290                 {
<a name="l00291"></a>00291                     <a class="code" href="classompl_1_1base_1_1PathPtr.html" title="A boost shared pointer wrapper for ompl::base::Path.">base::PathPtr</a> p = constructSolution(start, goal);
<a name="l00292"></a>00292                     <span class="keywordtype">double</span> pl = p-&gt;length();
<a name="l00293"></a>00293                     <span class="keywordflow">if</span> (pl &gt; g-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#a033696b98580c4be0694a878ef1e7bbb" title="Get the maximum length allowed for a solution path.">getMaximumPathLength</a>())
<a name="l00294"></a>00294                     {
<a name="l00295"></a>00295                         sol = <span class="keyword">false</span>;
<a name="l00296"></a>00296                         <span class="comment">// record approximate solution</span>
<a name="l00297"></a>00297                         <span class="keywordflow">if</span> (approxlen_ &lt; 0.0 || approxlen_ &gt; pl)
<a name="l00298"></a>00298                         {
<a name="l00299"></a>00299                             approxsol_ = p;
<a name="l00300"></a>00300                             approxlen_ = pl;
<a name="l00301"></a>00301                         }
<a name="l00302"></a>00302                     }
<a name="l00303"></a>00303                 }
<a name="l00304"></a>00304 
<a name="l00305"></a>00305                 <span class="keywordflow">if</span> (sol)
<a name="l00306"></a>00306                 {
<a name="l00307"></a>00307                     <span class="keywordflow">if</span> (endpoints)
<a name="l00308"></a>00308                     {
<a name="l00309"></a>00309                         endpoints-&gt;first = start;
<a name="l00310"></a>00310                         endpoints-&gt;second = goal;
<a name="l00311"></a>00311                     }
<a name="l00312"></a>00312                     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00313"></a>00313                 }
<a name="l00314"></a>00314             }
<a name="l00315"></a>00315         }
<a name="l00316"></a>00316     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00317"></a>00317 }
<a name="l00318"></a>00318 
<a name="l00319"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#af622f66347e33f4bb6a2fe7f5df97b5f">00319</a> <span class="keywordtype">bool</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#af622f66347e33f4bb6a2fe7f5df97b5f" title="Function that can solve the motion planning problem. This function can be called multiple times on th...">ompl::geometric::PRM::solve</a>(<span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1PlannerTerminationCondition.html" title="Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...">base::PlannerTerminationCondition</a> &amp;ptc)
<a name="l00320"></a>00320 {
<a name="l00321"></a>00321     checkValidity();
<a name="l00322"></a>00322     <a class="code" href="classompl_1_1base_1_1GoalSampleableRegion.html" title="Abstract definition of a goal region that can be sampled.">base::GoalSampleableRegion</a> *goal = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classompl_1_1base_1_1GoalSampleableRegion.html" title="Abstract definition of a goal region that can be sampled.">base::GoalSampleableRegion</a>*<span class="keyword">&gt;</span>(pdef_-&gt;getGoal().get());
<a name="l00323"></a>00323 
<a name="l00324"></a>00324     <span class="keywordflow">if</span> (!goal)
<a name="l00325"></a>00325     {
<a name="l00326"></a>00326         msg_.error(<span class="stringliteral">&quot;Goal undefined or unknown type of goal&quot;</span>);
<a name="l00327"></a>00327         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00328"></a>00328     }
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nrStartStates = boost::num_vertices(g_);
<a name="l00331"></a>00331 
<a name="l00332"></a>00332     <span class="comment">// add the valid start states as milestones</span>
<a name="l00333"></a>00333     <span class="keywordflow">while</span> (<span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1State.html" title="Definition of an abstract state.">base::State</a> *st = pis_.nextStart())
<a name="l00334"></a>00334         startM_.push_back(addMilestone(si_-&gt;cloneState(st)));
<a name="l00335"></a>00335 
<a name="l00336"></a>00336     <span class="keywordflow">if</span> (startM_.size() == 0)
<a name="l00337"></a>00337     {
<a name="l00338"></a>00338         msg_.error(<span class="stringliteral">&quot;There are no valid initial states!&quot;</span>);
<a name="l00339"></a>00339         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00340"></a>00340     }
<a name="l00341"></a>00341 
<a name="l00342"></a>00342     <span class="keywordflow">if</span> (!goal-&gt;<a class="code" href="classompl_1_1base_1_1GoalSampleableRegion.html#a60329b89ea7217a7550197e5866c28c7" title="Return true of maxSampleCount() &gt; 0, since in this case samples can certainly be produced.">canSample</a>())
<a name="l00343"></a>00343     {
<a name="l00344"></a>00344         msg_.error(<span class="stringliteral">&quot;Insufficient states in sampleable goal region&quot;</span>);
<a name="l00345"></a>00345         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00346"></a>00346     }
<a name="l00347"></a>00347 
<a name="l00348"></a>00348     <span class="keywordflow">if</span> (!sampler_)
<a name="l00349"></a>00349         sampler_ = si_-&gt;allocValidStateSampler();
<a name="l00350"></a>00350     <span class="keywordflow">if</span> (!simpleSampler_)
<a name="l00351"></a>00351         simpleSampler_ = si_-&gt;allocStateSampler();
<a name="l00352"></a>00352 
<a name="l00353"></a>00353     approxsol_.reset();
<a name="l00354"></a>00354     approxlen_ = -1.0;
<a name="l00355"></a>00355 
<a name="l00356"></a>00356     msg_.inform(<span class="stringliteral">&quot;Starting with %u states&quot;</span>, nrStartStates);
<a name="l00357"></a>00357 
<a name="l00358"></a>00358     std::vector&lt;base::State*&gt; xstates(<a class="code" href="namespaceompl_1_1magic.html#acf09430426a57052295791746f014f12" title="The number of steps to take for a random bounce motion generated as part of the expansion step of PRM...">magic::MAX_RANDOM_BOUNCE_STEPS</a>);
<a name="l00359"></a>00359     si_-&gt;allocStates(xstates);
<a name="l00360"></a>00360     std::pair&lt;Vertex, Vertex&gt; solEndpoints;
<a name="l00361"></a>00361     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> steps = 0;
<a name="l00362"></a>00362 
<a name="l00363"></a>00363     <span class="keywordflow">while</span> (ptc() == <span class="keyword">false</span>)
<a name="l00364"></a>00364     {
<a name="l00365"></a>00365         <span class="comment">// find at least one valid goal state</span>
<a name="l00366"></a>00366         <span class="keywordflow">if</span> (goal-&gt;<a class="code" href="classompl_1_1base_1_1GoalSampleableRegion.html#a155c0de80eb09a969d6f3dce2093fdc5" title="Return the maximum number of samples that can be asked for before repeating.">maxSampleCount</a>() &gt; goalM_.size() || goalM_.empty())
<a name="l00367"></a>00367         {
<a name="l00368"></a>00368             <span class="keyword">const</span> <a class="code" href="classompl_1_1base_1_1State.html" title="Definition of an abstract state.">base::State</a> *st = goalM_.empty() ? pis_.nextGoal(ptc) : pis_.nextGoal();
<a name="l00369"></a>00369             <span class="keywordflow">if</span> (st)
<a name="l00370"></a>00370                 goalM_.push_back(addMilestone(si_-&gt;cloneState(st)));
<a name="l00371"></a>00371             <span class="keywordflow">if</span> (goalM_.empty())
<a name="l00372"></a>00372             {
<a name="l00373"></a>00373                 msg_.error(<span class="stringliteral">&quot;Unable to find any valid goal states&quot;</span>);
<a name="l00374"></a>00374                 <span class="keywordflow">break</span>;
<a name="l00375"></a>00375             }
<a name="l00376"></a>00376         }
<a name="l00377"></a>00377 
<a name="l00378"></a>00378         <span class="comment">// if there already is a solution, construct it</span>
<a name="l00379"></a>00379         <span class="keywordflow">if</span> (haveSolution(startM_, goalM_, &amp;solEndpoints))
<a name="l00380"></a>00380         {
<a name="l00381"></a>00381             goal-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#ade528c0fefb9094abc1a2d1518a5f860" title="Update the solution path. If a previous solution path exists, it is deleted.">setSolutionPath</a>(constructSolution(solEndpoints.first, solEndpoints.second));
<a name="l00382"></a>00382             <span class="keywordflow">break</span>;
<a name="l00383"></a>00383         }
<a name="l00384"></a>00384         <span class="comment">// othewise, spend some time building a roadmap</span>
<a name="l00385"></a>00385         <span class="keywordflow">else</span>
<a name="l00386"></a>00386         {
<a name="l00387"></a>00387             <span class="comment">// maintain a 2:1 ration for growing:expansion of roadmap</span>
<a name="l00388"></a>00388             <span class="comment">// call growRoadmap() 4 times for 0.1 seconds, for every call of expandRoadmap() for 0.2 seconds</span>
<a name="l00389"></a>00389             <span class="keywordflow">if</span> (steps &lt; 4)
<a name="l00390"></a>00390             {
<a name="l00391"></a>00391                 growRoadmap(startM_, goalM_, <a class="code" href="classompl_1_1base_1_1PlannerOrTerminationCondition.html" title="Combine two termination conditions into one. If either termination condition returns true...">base::PlannerOrTerminationCondition</a>(ptc, base::timedPlannerTerminationCondition(0.1)), xstates[0]);
<a name="l00392"></a>00392                 steps++;
<a name="l00393"></a>00393             }
<a name="l00394"></a>00394             <span class="keywordflow">else</span>
<a name="l00395"></a>00395             {
<a name="l00396"></a>00396                 expandRoadmap(startM_, goalM_, <a class="code" href="classompl_1_1base_1_1PlannerOrTerminationCondition.html" title="Combine two termination conditions into one. If either termination condition returns true...">base::PlannerOrTerminationCondition</a>(ptc, base::timedPlannerTerminationCondition(0.2)), xstates);
<a name="l00397"></a>00397                 steps = 0;
<a name="l00398"></a>00398             }
<a name="l00399"></a>00399 
<a name="l00400"></a>00400             <span class="comment">// if a solution has been found, construct it</span>
<a name="l00401"></a>00401             <span class="keywordflow">if</span> (haveSolution(startM_, goalM_, &amp;solEndpoints))
<a name="l00402"></a>00402             {
<a name="l00403"></a>00403                 goal-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#ade528c0fefb9094abc1a2d1518a5f860" title="Update the solution path. If a previous solution path exists, it is deleted.">setSolutionPath</a>(constructSolution(solEndpoints.first, solEndpoints.second));
<a name="l00404"></a>00404                 <span class="keywordflow">break</span>;
<a name="l00405"></a>00405             }
<a name="l00406"></a>00406         }
<a name="l00407"></a>00407     }
<a name="l00408"></a>00408     si_-&gt;freeStates(xstates);
<a name="l00409"></a>00409 
<a name="l00410"></a>00410     msg_.inform(<span class="stringliteral">&quot;Created %u states&quot;</span>, boost::num_vertices(g_) - nrStartStates);
<a name="l00411"></a>00411 
<a name="l00412"></a>00412     <span class="keywordflow">if</span> (!goal-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#ab15b334d24d37e52d21b76ef18eb9058" title="Return the found solution path.">getSolutionPath</a>() &amp;&amp; approxsol_)
<a name="l00413"></a>00413     {
<a name="l00414"></a>00414         goal-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#ade528c0fefb9094abc1a2d1518a5f860" title="Update the solution path. If a previous solution path exists, it is deleted.">setSolutionPath</a>(approxsol_, <span class="keyword">true</span>);
<a name="l00415"></a>00415         <span class="comment">// the solution is exact, but not as short as we&#39;d like it to be</span>
<a name="l00416"></a>00416         goal-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#afbfc02ebac97049ebdd28d040ce44c37" title="Set the difference between the found solution path and the desired solution path.">setDifference</a>(0.0);
<a name="l00417"></a>00417     }
<a name="l00418"></a>00418 
<a name="l00419"></a>00419     <span class="keywordflow">return</span> goal-&gt;<a class="code" href="classompl_1_1base_1_1Goal.html#a9a6e44d33f848108d0beeb1cf7a6c1ad" title="Returns true if a solution path has been found (could be approximate)">isAchieved</a>();
<a name="l00420"></a>00420 }
<a name="l00421"></a>00421 
<a name="l00422"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#aa393c5591243c7d166fc0f73b46627f2">00422</a> ompl::geometric::PRM::Vertex <a class="code" href="classompl_1_1geometric_1_1PRM.html#aa393c5591243c7d166fc0f73b46627f2" title="Construct a milestone for a given state (state) and store it in the nearest neighbors data structure...">ompl::geometric::PRM::addMilestone</a>(<a class="code" href="classompl_1_1base_1_1State.html" title="Definition of an abstract state.">base::State</a> *state)
<a name="l00423"></a>00423 {
<a name="l00424"></a>00424     Vertex m = boost::add_vertex(g_);
<a name="l00425"></a>00425     stateProperty_[m] = state;
<a name="l00426"></a>00426     totalConnectionAttemptsProperty_[m] = 1;
<a name="l00427"></a>00427     successfulConnectionAttemptsProperty_[m] = 0;
<a name="l00428"></a>00428 
<a name="l00429"></a>00429     <span class="comment">// Initialize to its own (dis)connected component.</span>
<a name="l00430"></a>00430     disjointSets_.make_set(m);
<a name="l00431"></a>00431 
<a name="l00432"></a>00432     <span class="comment">// Which milestones will we attempt to connect to?</span>
<a name="l00433"></a>00433     <span class="keywordflow">if</span> (!connectionStrategy_)
<a name="l00434"></a>00434         <span class="keywordflow">throw</span> <a class="code" href="classompl_1_1Exception.html" title="The exception type for ompl.">Exception</a>(name_, <span class="stringliteral">&quot;No connection strategy!&quot;</span>);
<a name="l00435"></a>00435 
<a name="l00436"></a>00436     <span class="keyword">const</span> std::vector&lt;Vertex&gt;&amp; neighbors = connectionStrategy_(m);
<a name="l00437"></a>00437 
<a name="l00438"></a>00438     <span class="keywordflow">foreach</span> (Vertex n, neighbors)
<a name="l00439"></a>00439         <span class="keywordflow">if</span> ((boost::same_component(m, n, disjointSets_) || connectionFilter_(m, n)))
<a name="l00440"></a>00440         {
<a name="l00441"></a>00441             totalConnectionAttemptsProperty_[m]++;
<a name="l00442"></a>00442             totalConnectionAttemptsProperty_[n]++;
<a name="l00443"></a>00443             <span class="keywordflow">if</span> (si_-&gt;checkMotion(stateProperty_[m], stateProperty_[n]))
<a name="l00444"></a>00444             {
<a name="l00445"></a>00445                 successfulConnectionAttemptsProperty_[m]++;
<a name="l00446"></a>00446                 successfulConnectionAttemptsProperty_[n]++;
<a name="l00447"></a>00447                 <span class="keyword">const</span> <span class="keywordtype">double</span> weight = distanceFunction(m, n);
<a name="l00448"></a>00448                 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span> = maxEdgeID_++;
<a name="l00449"></a>00449                 <span class="keyword">const</span> Graph::edge_property_type properties(weight, <span class="keywordtype">id</span>);
<a name="l00450"></a>00450                 boost::add_edge(m, n, properties, g_);
<a name="l00451"></a>00451                 uniteComponents(n, m);
<a name="l00452"></a>00452             }
<a name="l00453"></a>00453         }
<a name="l00454"></a>00454 
<a name="l00455"></a>00455     nn_-&gt;add(m);
<a name="l00456"></a>00456     <span class="keywordflow">return</span> m;
<a name="l00457"></a>00457 }
<a name="l00458"></a>00458 
<a name="l00459"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a8b699f5d6c9ffd15094ef3854f1eb7b4">00459</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a8b699f5d6c9ffd15094ef3854f1eb7b4" title="Make two milestones (m1 and m2) be part of the same connected component. The component with fewer ele...">ompl::geometric::PRM::uniteComponents</a>(Vertex m1, Vertex m2)
<a name="l00460"></a>00460 {
<a name="l00461"></a>00461     disjointSets_.union_set(m1, m2);
<a name="l00462"></a>00462 }
<a name="l00463"></a>00463 
<a name="l00464"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a3f13f8a7e5ba67332f4734b037870c33">00464</a> <a class="code" href="classompl_1_1base_1_1PathPtr.html" title="A boost shared pointer wrapper for ompl::base::Path.">ompl::base::PathPtr</a> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a3f13f8a7e5ba67332f4734b037870c33" title="Given two milestones from the same connected component, construct a path connecting them and set it a...">ompl::geometric::PRM::constructSolution</a>(<span class="keyword">const</span> Vertex start, <span class="keyword">const</span> Vertex goal)
<a name="l00465"></a>00465 {
<a name="l00466"></a>00466     <a class="code" href="classompl_1_1geometric_1_1PathGeometric.html" title="Definition of a geometric path.">PathGeometric</a> *p = <span class="keyword">new</span> <a class="code" href="classompl_1_1geometric_1_1PathGeometric.html" title="Definition of a geometric path.">PathGeometric</a>(si_);
<a name="l00467"></a>00467 
<a name="l00468"></a>00468     boost::vector_property_map&lt;Vertex&gt; prev(boost::num_vertices(g_));
<a name="l00469"></a>00469 
<a name="l00470"></a>00470     boost::astar_search(g_, start,
<a name="l00471"></a>00471             boost::bind(&amp;<a class="code" href="classompl_1_1geometric_1_1PRM.html#a983bce5dd72ba208357b5518f4515125" title="Compute distance between two milestones (this is simply distance between the states of the milestones...">PRM::distanceFunction</a>, <span class="keyword">this</span>, _1, goal),
<a name="l00472"></a>00472             boost::predecessor_map(prev));
<a name="l00473"></a>00473 
<a name="l00474"></a>00474     <span class="keywordflow">if</span> (prev[goal] == goal)
<a name="l00475"></a>00475         <span class="keywordflow">throw</span> <a class="code" href="classompl_1_1Exception.html" title="The exception type for ompl.">Exception</a>(name_, <span class="stringliteral">&quot;Could not find solution path&quot;</span>);
<a name="l00476"></a>00476     <span class="keywordflow">else</span>
<a name="l00477"></a>00477         <span class="keywordflow">for</span> (Vertex pos = goal; prev[pos] != pos; pos = prev[pos])
<a name="l00478"></a>00478             p-&gt;<a class="code" href="classompl_1_1geometric_1_1PathGeometric.html#a3a729dab22338b733888bc2f9c9769a4" title="The list of states that make up the path.">states</a>.push_back(si_-&gt;cloneState(stateProperty_[pos]));
<a name="l00479"></a>00479     p-&gt;<a class="code" href="classompl_1_1geometric_1_1PathGeometric.html#a3a729dab22338b733888bc2f9c9769a4" title="The list of states that make up the path.">states</a>.push_back(si_-&gt;cloneState(stateProperty_[start]));
<a name="l00480"></a>00480     p-&gt;<a class="code" href="classompl_1_1geometric_1_1PathGeometric.html#ae4b56284e4b049df559fcb1320f69fa5" title="Reverse the path.">reverse</a>();
<a name="l00481"></a>00481 
<a name="l00482"></a>00482     <span class="keywordflow">return</span> <a class="code" href="classompl_1_1base_1_1PathPtr.html" title="A boost shared pointer wrapper for ompl::base::Path.">base::PathPtr</a>(p);
<a name="l00483"></a>00483 }
<a name="l00484"></a>00484 
<a name="l00485"></a><a class="code" href="classompl_1_1geometric_1_1PRM.html#a294b21109833dbbc80f5eb322e9c4fbc">00485</a> <span class="keywordtype">void</span> <a class="code" href="classompl_1_1geometric_1_1PRM.html#a294b21109833dbbc80f5eb322e9c4fbc" title="Get information about the current run of the motion planner. Repeated calls to this function will upd...">ompl::geometric::PRM::getPlannerData</a>(<a class="code" href="classompl_1_1base_1_1PlannerData.html" title="Datatype holding data a planner can expose for debug purposes.">base::PlannerData</a> &amp;data)<span class="keyword"> const</span>
<a name="l00486"></a>00486 <span class="keyword"></span>{
<a name="l00487"></a>00487     Planner::getPlannerData(data);
<a name="l00488"></a>00488 
<a name="l00489"></a>00489     <span class="keywordflow">foreach</span>(<span class="keyword">const</span> Edge e, boost::edges(g_))
<a name="l00490"></a>00490     {
<a name="l00491"></a>00491         <span class="keyword">const</span> Vertex v1 = boost::source(e, g_);
<a name="l00492"></a>00492         <span class="keyword">const</span> Vertex v2 = boost::target(e, g_);
<a name="l00493"></a>00493         data.<a class="code" href="classompl_1_1base_1_1PlannerData.html#aa11d568e75a53a0fecddbecbc05ca429" title="Record an edge between two states. This function is called by planners to fill states, stateIndex and edges. If the same state/edge is seen multiple times, it is added only once.">recordEdge</a>(stateProperty_[v1], stateProperty_[v2]);
<a name="l00494"></a>00494     }
<a name="l00495"></a>00495 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div>

<div class="footer span-22 push-2 last">
  <a href="http://www.kavrakilab.org">Physical and Biological Computing Group</a> &bull;
  <a href="http://www.cs.rice.edu">Department of Computer Science</a> &bull;
  <a href="http://www.rice.edu">Rice University</a><br>
  <div class="gray">Generated on Sun Oct 9 2011 23:04:30 by&#160;<a href="http://www.doxygen.org/index.html">doxygen</a> 1.7.4</div>
</div>
</div>
</body>
</html>