StateSpace.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_BASE_STATE_SPACE_
38 #define OMPL_BASE_STATE_SPACE_
39 
40 #include "ompl/base/State.h"
41 #include "ompl/base/StateSpaceTypes.h"
42 #include "ompl/base/StateSampler.h"
43 #include "ompl/base/ProjectionEvaluator.h"
44 #include "ompl/base/GenericParam.h"
45 #include "ompl/util/Console.h"
46 #include "ompl/util/ClassForward.h"
47 #include <boost/concept_check.hpp>
48 #include <iostream>
49 #include <vector>
50 #include <string>
51 #include <map>
52 
53 namespace ompl
54 {
55  namespace base
56  {
57 
59 
60  OMPL_CLASS_FORWARD(StateSpace);
62 
72  class StateSpace
73  {
74  public:
75  // non-copyable
76  StateSpace(const StateSpace&) = delete;
77  StateSpace& operator=(const StateSpace&) = delete;
78 
80  typedef State StateType;
81 
83  StateSpace();
84 
85  virtual ~StateSpace();
86 
88  template<class T>
89  T* as()
90  {
92  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, StateSpace*>));
93 
94  return static_cast<T*>(this);
95  }
96 
98  template<class T>
99  const T* as() const
100  {
102  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, StateSpace*>));
103 
104  return static_cast<const T*>(this);
105  }
106 
109  {
115  std::vector<std::size_t> chain;
116 
119  };
120 
123  {
126 
128  std::size_t index;
129  };
130 
134  {
135 
138 
141 
144 
147 
150 
153 
156 
159  };
160 
165  virtual bool isCompound() const;
166 
173  virtual bool isDiscrete() const;
174 
176  virtual bool isHybrid() const;
177 
180  virtual bool isMetricSpace() const
181  {
182  return true;
183  }
184 
186  virtual bool hasSymmetricDistance() const;
187 
189  virtual bool hasSymmetricInterpolate() const;
190 
192  const std::string& getName() const;
193 
195  void setName(const std::string &name);
196 
200  int getType() const
201  {
202  return type_;
203  }
204 
206  bool includes(const StateSpacePtr &other) const;
207 
209  bool includes(const StateSpace *other) const;
210 
213  bool covers(const StateSpacePtr &other) const;
214 
217  bool covers(const StateSpace *other) const;
218 
221  {
222  return params_;
223  }
224 
226  const ParamSet& params() const
227  {
228  return params_;
229  }
230 
236  virtual double getLongestValidSegmentFraction() const;
237 
248  virtual void setLongestValidSegmentFraction(double segmentFraction);
249 
251  virtual unsigned int validSegmentCount(const State *state1, const State *state2) const;
252 
259  void setValidSegmentCountFactor(unsigned int factor);
260 
262  unsigned int getValidSegmentCountFactor() const;
263 
265  double getLongestValidSegmentLength() const;
266 
269  void computeSignature(std::vector<int> &signature) const;
270 
277  virtual unsigned int getDimension() const = 0;
278 
285  virtual double getMaximumExtent() const = 0;
286 
288  virtual double getMeasure() const = 0;
289 
292  virtual void enforceBounds(State *state) const = 0;
293 
296  virtual bool satisfiesBounds(const State *state) const = 0;
297 
300  virtual void copyState(State *destination, const State *source) const = 0;
301 
303  State* cloneState(const State* source) const;
304 
307  virtual double distance(const State *state1, const State *state2) const = 0;
308 
310  virtual unsigned int getSerializationLength() const;
311 
313  virtual void serialize(void *serialization, const State *state) const;
314 
316  virtual void deserialize(State *state, const void *serialization) const;
317 
319  virtual bool equalStates(const State *state1, const State *state2) const = 0;
320 
324  virtual void interpolate(const State *from, const State *to, const double t, State *state) const = 0;
325 
327  virtual StateSamplerPtr allocDefaultStateSampler() const = 0;
328 
332  virtual StateSamplerPtr allocStateSampler() const;
333 
336 
339 
341  virtual State* allocState() const = 0;
342 
344  virtual void freeState(State *state) const = 0;
345 
363  virtual double* getValueAddressAtIndex(State *state, const unsigned int index) const;
364 
366  const double* getValueAddressAtIndex(const State *state, const unsigned int index) const;
367 
370  const std::vector<ValueLocation>& getValueLocations() const;
371 
374  const std::map<std::string, ValueLocation>& getValueLocationsByName() const;
375 
377  double* getValueAddressAtLocation(State *state, const ValueLocation &loc) const;
378 
380  const double* getValueAddressAtLocation(const State *state, const ValueLocation &loc) const;
381 
383  double* getValueAddressAtName(State *state, const std::string &name) const;
384 
386  const double* getValueAddressAtName(const State *state, const std::string &name) const;
387 
389  void copyToReals(std::vector<double> &reals, const State *source) const;
390 
392  void copyFromReals(State *destination, const std::vector<double> &reals) const;
393 
400  void registerProjection(const std::string &name, const ProjectionEvaluatorPtr &projection);
401 
403  void registerDefaultProjection(const ProjectionEvaluatorPtr &projection);
404 
407  virtual void registerProjections();
408 
410  ProjectionEvaluatorPtr getProjection(const std::string &name) const;
411 
414 
416  bool hasProjection(const std::string &name) const;
417 
419  bool hasDefaultProjection() const;
420 
422  const std::map<std::string, ProjectionEvaluatorPtr>& getRegisteredProjections() const;
423 
430  virtual void printState(const State *state, std::ostream &out) const;
431 
433  virtual void printSettings(std::ostream &out) const;
434 
436  virtual void printProjections(std::ostream &out) const;
437 
440  virtual void sanityChecks(double zero, double eps, unsigned int flags) const;
441 
444  virtual void sanityChecks() const;
445 
447  void diagram(std::ostream &out) const;
448 
450  void list(std::ostream &out) const;
451 
453  static void Diagram(std::ostream &out);
454 
456  static void List(std::ostream &out);
457 
465 
467  virtual StateSamplerPtr allocSubspaceStateSampler(const StateSpace *subspace) const;
468 
470  State* getSubstateAtLocation(State *state, const SubstateLocation &loc) const;
471 
473  const State* getSubstateAtLocation(const State *state, const SubstateLocation &loc) const;
474 
476  const std::map<std::string, SubstateLocation>& getSubstateLocationsByName() const;
477 
480  void getCommonSubspaces(const StateSpacePtr &other, std::vector<std::string> &subspaces) const;
481 
484  void getCommonSubspaces(const StateSpace *other, std::vector<std::string> &subspaces) const;
485 
488  virtual void computeLocations();
489 
500  virtual void setup();
501 
502  protected:
503 
505  static const std::string DEFAULT_PROJECTION_NAME;
506 
508  int type_;
509 
512 
514  double maxExtent_;
515 
518 
521 
524 
526  std::map<std::string, ProjectionEvaluatorPtr> projections_;
527 
530 
533  std::vector<ValueLocation> valueLocationsInOrder_;
534 
537  std::map<std::string, ValueLocation> valueLocationsByName_;
538 
540  std::map<std::string, SubstateLocation> substateLocationsByName_;
541 
542  private:
543 
545  std::string name_;
546  };
547 
550  {
551  public:
552 
555 
558 
560  CompoundStateSpace(const std::vector<StateSpacePtr> &components, const std::vector<double> &weights);
561 
562  virtual ~CompoundStateSpace()
563  {
564  }
565 
567  template<class T>
568  T* as(const unsigned int index) const
569  {
571  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, StateSpace*>));
572 
573  return static_cast<T*>(getSubspace(index).get());
574  }
575 
577  template<class T>
578  T* as(const std::string &name) const
579  {
581  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, StateSpace*>));
582 
583  return static_cast<T*>(getSubspace(name).get());
584  }
585 
586  virtual bool isCompound() const;
587 
588  virtual bool isHybrid() const;
589 
595  void addSubspace(const StateSpacePtr &component, double weight);
596 
598  unsigned int getSubspaceCount() const;
599 
601  const StateSpacePtr& getSubspace(const unsigned int index) const;
602 
604  const StateSpacePtr& getSubspace(const std::string& name) const;
605 
607  unsigned int getSubspaceIndex(const std::string& name) const;
608 
610  bool hasSubspace(const std::string &name) const;
611 
613  double getSubspaceWeight(const unsigned int index) const;
614 
616  double getSubspaceWeight(const std::string &name) const;
617 
619  void setSubspaceWeight(const unsigned int index, double weight);
620 
622  void setSubspaceWeight(const std::string &name, double weight);
623 
625  const std::vector<StateSpacePtr>& getSubspaces() const;
626 
628  const std::vector<double>& getSubspaceWeights() const;
629 
633  bool isLocked() const;
634 
640  void lock();
646  virtual StateSamplerPtr allocSubspaceStateSampler(const StateSpace *subspace) const;
647 
653  virtual unsigned int getDimension() const;
654 
655  virtual double getMaximumExtent() const;
656 
657  virtual double getMeasure() const;
658 
659  virtual void enforceBounds(State *state) const;
660 
661  virtual bool satisfiesBounds(const State *state) const;
662 
663  virtual void copyState(State *destination, const State *source) const;
664 
665  virtual unsigned int getSerializationLength() const;
666 
667  virtual void serialize(void *serialization, const State *state) const;
668 
669  virtual void deserialize(State *state, const void *serialization) const;
670 
671  virtual double distance(const State *state1, const State *state2) const;
672 
678  virtual void setLongestValidSegmentFraction(double segmentFraction);
679 
682  virtual unsigned int validSegmentCount(const State *state1, const State *state2) const;
683 
684  virtual bool equalStates(const State *state1, const State *state2) const;
685 
686  virtual void interpolate(const State *from, const State *to, const double t, State *state) const;
687 
689 
690  virtual State* allocState() const;
691 
692  virtual void freeState(State *state) const;
693 
694  virtual double* getValueAddressAtIndex(State *state, const unsigned int index) const;
695 
698  virtual void printState(const State *state, std::ostream &out) const;
699 
700  virtual void printSettings(std::ostream &out) const;
701 
702  virtual void computeLocations();
703 
704  virtual void setup();
705 
706  protected:
707 
709  void allocStateComponents(CompoundState *state) const;
710 
712  std::vector<StateSpacePtr> components_;
713 
715  unsigned int componentCount_;
716 
718  std::vector<double> weights_;
719 
721  double weightSum_;
722 
724  bool locked_;
725 
726  };
727 
741 
749 
752  StateSpacePtr operator-(const StateSpacePtr &a, const std::string &name);
753 
766  {
769 
772 
775  };
776 
784  AdvancedStateCopyOperation copyStateData(const StateSpacePtr &destS, State *dest,
785  const StateSpacePtr &sourceS, const State *source);
786 
794  AdvancedStateCopyOperation copyStateData(const StateSpace *destS, State *dest,
795  const StateSpace *sourceS, const State *source);
796 
802  AdvancedStateCopyOperation copyStateData(const StateSpacePtr &destS, State *dest,
803  const StateSpacePtr &sourceS, const State *source,
804  const std::vector<std::string> &subspaces);
805 
811  AdvancedStateCopyOperation copyStateData(const StateSpace *destS, State *dest,
812  const StateSpace *sourceS, const State *source,
813  const std::vector<std::string> &subspaces);
816  }
817 }
818 
819 #endif
State * getSubstateAtLocation(State *state, const SubstateLocation &loc) const
Get the substate of state that is pointed to by loc.
Definition: StateSpace.cpp:287
void setName(const std::string &name)
Set the name of the state space.
Definition: StateSpace.cpp:201
virtual void setup()
Perform final setup steps. This function is automatically called by the SpaceInformation. If any default projections are to be registered, this call will set them and call their setup() functions. It is safe to call this function multiple times. At a subsequent call, projections that have been previously user configured are not re-instantiated, but their setup() method is still called.
virtual StateSamplerPtr allocStateSampler() const
Allocate an instance of the state sampler for this space. This sampler will be allocated with the sam...
Definition: StateSpace.cpp:790
virtual void deserialize(State *state, const void *serialization) const
Read the binary representation of a state from serialization and write it to state.
int type_
A type assigned for this state space.
Definition: StateSpace.h:508
ParamSet params_
The set of parameters for this space.
Definition: StateSpace.h:529
bool hasDefaultProjection() const
Check if a default projection is available.
Definition: StateSpace.cpp:704
virtual unsigned int validSegmentCount(const State *state1, const State *state2) const
Count how many segments of the "longest valid length" fit on the motion from state1 to state2...
Definition: StateSpace.cpp:839
virtual bool hasSymmetricInterpolate() const
Check if the interpolation function on this state space is symmetric, i.e. interpolate(from, to, t, state) = interpolate(to, from, 1-t, state). Default implementation returns true.
Definition: StateSpace.cpp:775
Definition of a compound state.
Definition: State.h:95
virtual void copyState(State *destination, const State *source) const
Copy a state to another. The memory of source and destination should NOT overlap. ...
virtual double * getValueAddressAtIndex(State *state, const unsigned int index) const
Many states contain a number of double values. This function provides a means to get the memory addre...
Definition: StateSpace.cpp:303
virtual bool isHybrid() const
Check if this is a hybrid state space (i.e., both discrete and continuous components exist) ...
Definition: StateSpace.cpp:765
static const std::string DEFAULT_PROJECTION_NAME
The name used for the default projection.
Definition: StateSpace.h:505
std::size_t index
The index of the value to be accessed, within the substate location above.
Definition: StateSpace.h:128
virtual double getLongestValidSegmentFraction() const
When performing discrete validation of motions, the length of the longest segment that does not requi...
Definition: StateSpace.cpp:829
unsigned int getSubspaceIndex(const std::string &name) const
Get the index of a specific subspace from the compound state space.
Definition: StateSpace.cpp:914
virtual bool isCompound() const
Check if the state space is compound.
Definition: StateSpace.cpp:872
virtual unsigned int getSerializationLength() const
Get the number of chars in the serialization of a state in this space.
virtual StateSamplerPtr allocDefaultStateSampler() const
Allocate an instance of the default uniform state sampler for this space.
State * cloneState(const State *source) const
Clone a state.
Definition: StateSpace.cpp:225
bool includes(const StateSpacePtr &other) const
Return true if other is a space included (perhaps equal, perhaps a subspace) in this one...
Definition: StateSpace.cpp:471
static void Diagram(std::ostream &out)
Print a Graphviz digraph that represents the containment diagram for all the instantiated state space...
Definition: StateSpace.cpp:573
virtual void printProjections(std::ostream &out) const
Print the list of registered projections. This function is also called by printSettings() ...
Definition: StateSpace.cpp:390
A shared pointer wrapper for ompl::base::StateSpace.
const std::vector< ValueLocation > & getValueLocations() const
Get the locations of values of type double contained in a state from this space. The order of the val...
Definition: StateSpace.cpp:314
double getSubspaceWeight(const unsigned int index) const
Get the weight of a subspace from the compound state space (used in distance computation) ...
Definition: StateSpace.cpp:927
A shared pointer wrapper for ompl::base::StateSampler.
void lock()
Lock this state space. This means no further spaces can be added as components. This function can be ...
virtual unsigned int getDimension() const =0
Get the dimension of the space (not the dimension of the surrounding ambient space) ...
Check whether the StateSpace::distance() is bounded by StateSpace::getExtent()
Definition: StateSpace.h:149
bool isLocked() const
Return true if the state space is locked. A value of true means that no further spaces can be added a...
std::vector< std::size_t > chain
In a complex state space there may be multiple compound state spaces that make up an even larger comp...
Definition: StateSpace.h:115
Check whether sampled states are always within bounds.
Definition: StateSpace.h:152
Representation of the address of a value in a state. This structure stores the indexing information n...
Definition: StateSpace.h:122
No data was copied.
Definition: StateSpace.h:768
StateSpace()
Constructor. Assigns a unique name to the space.
Definition: StateSpace.cpp:86
AdvancedStateCopyOperation copyStateData(const StateSpacePtr &destS, State *dest, const StateSpacePtr &sourceS, const State *source)
Copy data from source (state from space sourceS) to dest (state from space destS) on a component by c...
T * as(const unsigned int index) const
Cast a component of this instance to a desired type.
Definition: StateSpace.h:568
CompoundState StateType
Define the type of state allocated by this state space.
Definition: StateSpace.h:554
virtual double getMeasure() const
Get a measure of the space (this can be thought of as a generalization of volume) ...
Definition: StateSpace.cpp:994
virtual bool isMetricSpace() const
Return true if the distance function associated with the space is a metric.
Definition: StateSpace.h:180
virtual StateSamplerPtr allocSubspaceStateSampler(const StateSpace *subspace) const
Allocate a sampler that actually samples only components that are part of subspace.
void diagram(std::ostream &out) const
Print a Graphviz digraph that represents the containment diagram for the state space.
Definition: StateSpace.cpp:546
void registerProjection(const std::string &name, const ProjectionEvaluatorPtr &projection)
Register a projection for this state space under a specified name.
Definition: StateSpace.cpp:747
virtual void computeLocations()
Compute the location information for various components of the state space. Either this function or s...
Definition: StateSpace.cpp:213
void copyFromReals(State *destination, const std::vector< double > &reals) const
Copy the values from reals to the state destination using getValueAddressAtLocation() ...
Definition: StateSpace.cpp:331
void computeSignature(std::vector< int > &signature) const
Compute an array of ints that uniquely identifies the structure of the state space. The first element of the signature is the number of integers that follow.
Definition: StateSpace.cpp:218
virtual void printSettings(std::ostream &out) const
Print the settings for this state space to a stream.
Definition: StateSpace.cpp:384
virtual void registerProjections()
Register the projections for this state space. Usually, this is at least the default projection...
Definition: StateSpace.cpp:232
virtual void setLongestValidSegmentFraction(double segmentFraction)
When performing discrete validation of motions, the length of the longest segment that does not requi...
ParamSet & params()
Get the parameters for this space.
Definition: StateSpace.h:220
void registerDefaultProjection(const ProjectionEvaluatorPtr &projection)
Register the default projection for this state space.
Definition: StateSpace.cpp:742
unsigned int longestValidSegmentCountFactor_
The factor to multiply the value returned by validSegmentCount(). Rarely used but useful for things l...
Definition: StateSpace.h:523
void allocStateComponents(CompoundState *state) const
Allocate the state components. Called by allocState(). Usually called by derived state spaces...
StateSamplerAllocator ssa_
An optional state sampler allocator.
Definition: StateSpace.h:511
virtual double * getValueAddressAtIndex(State *state, const unsigned int index) const
Many states contain a number of double values. This function provides a means to get the memory addre...
unsigned int componentCount_
The number of components.
Definition: StateSpace.h:715
std::function< StateSamplerPtr(const StateSpace *)> StateSamplerAllocator
Definition of a function that can allocate a state sampler.
Definition: StateSampler.h:200
Maintain a set of parameters.
Definition: GenericParam.h:233
const StateSpacePtr & getSubspace(const unsigned int index) const
Get a specific subspace from the compound state space.
Definition: StateSpace.cpp:898
State StateType
Define the type of state allocated by this space.
Definition: StateSpace.h:80
T * as()
Cast this instance to a desired type.
Definition: StateSpace.h:89
All data was copied.
Definition: StateSpace.h:774
virtual void setLongestValidSegmentFraction(double segmentFraction)
When performing discrete validation of motions, the length of the longest segment that does not requi...
Definition: StateSpace.cpp:817
Check whether the distances between non-equal states is strictly positive (StateSpace::distance()) ...
Definition: StateSpace.h:137
virtual State * allocState() const
Allocate a state that can store a point in the described space.
const std::vector< StateSpacePtr > & getSubspaces() const
Get the list of components.
Definition: StateSpace.cpp:967
virtual void computeLocations()
Compute the location information for various components of the state space. Either this function or s...
virtual void interpolate(const State *from, const State *to, const double t, State *state) const
Computes the state that lies at time t in [0, 1] on the segment that connects from state to to state...
A space to allow the composition of state spaces.
Definition: StateSpace.h:549
Representation of the address of a substate in a state. This structure stores the indexing informatio...
Definition: StateSpace.h:108
std::vector< double > weights_
The weight assigned to each component of the state space when computing the compound distance...
Definition: StateSpace.h:718
virtual double getMaximumExtent() const
Get the maximum value a call to distance() can return (or an upper bound). For unbounded state spaces...
Definition: StateSpace.cpp:985
const std::map< std::string, SubstateLocation > & getSubstateLocationsByName() const
Get the list of known substate locations (keys of the map corrspond to names of subspaces) ...
Definition: StateSpace.cpp:282
void setSubspaceWeight(const unsigned int index, double weight)
Set the weight of a subspace in the compound state space (used in distance computation) ...
Definition: StateSpace.cpp:943
virtual void printState(const State *state, std::ostream &out) const
Print a state to a stream.
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
StateSpacePtr operator-(const StateSpacePtr &a, const StateSpacePtr &b)
Construct a compound state space that contains subspaces only from a. If a is compound, b (or the components from b, if b is compound) are removed and the remaining components are returned as a compound state space. If the compound space would end up containing solely one component, that component is returned instead.
Representation of a space in which planning can be performed. Topology specific sampling, interpolation and distance are defined.
Definition: StateSpace.h:72
virtual void setup()
Perform final setup steps. This function is automatically called by the SpaceInformation. If any default projections are to be registered, this call will set them and call their setup() functions. It is safe to call this function multiple times. At a subsequent call, projections that have been previously user configured are not re-instantiated, but their setup() method is still called.
Definition: StateSpace.cpp:236
virtual StateSamplerPtr allocDefaultStateSampler() const =0
Allocate an instance of the default uniform state sampler for this space.
unsigned int getValidSegmentCountFactor() const
Get the value used to multiply the return value of validSegmentCount().
Definition: StateSpace.cpp:824
virtual void printSettings(std::ostream &out) const
Print the settings for this state space to a stream.
virtual void freeState(State *state) const
Free the memory of the allocated state.
Definition of an abstract state.
Definition: State.h:50
virtual bool equalStates(const State *state1, const State *state2) const
Checks whether two states are equal.
Check whether the triangle inequality holds when using StateSpace::interpolate() and StateSpace::dist...
Definition: StateSpace.h:146
virtual bool satisfiesBounds(const State *state) const =0
Check if a state is inside the bounding box. For unbounded spaces this function can always return tru...
void setValidSegmentCountFactor(unsigned int factor)
Set factor to be the value to multiply the return value of validSegmentCount(). By default...
Definition: StateSpace.cpp:810
virtual bool isDiscrete() const
Check if the set of states is discrete.
Definition: StateSpace.cpp:760
OptimizationObjectivePtr operator+(const OptimizationObjectivePtr &a, const OptimizationObjectivePtr &b)
Given two optimization objectives, returns a MultiOptimizationObjective that combines the two objecti...
virtual double distance(const State *state1, const State *state2) const
Computes distance between two states. This function satisfies the properties of a metric if isMetricS...
StateSamplerPtr allocSubspaceStateSampler(const StateSpacePtr &subspace) const
Allocate a sampler that actually samples only components that are part of subspace.
Definition: StateSpace.cpp:798
int getType() const
Get the type of the state space. The type can be used to verify whether two space instances are of th...
Definition: StateSpace.h:200
const ParamSet & params() const
Get the parameters for this space.
Definition: StateSpace.h:226
void setStateSamplerAllocator(const StateSamplerAllocator &ssa)
Set the sampler allocator to use.
Definition: StateSpace.cpp:780
bool covers(const StateSpacePtr &other) const
Return true if other is a space that is either included (perhaps equal, perhaps a subspace) in this o...
Definition: StateSpace.cpp:466
Some data was copied.
Definition: StateSpace.h:771
virtual double getMeasure() const =0
Get a measure of the space (this can be thought of as a generalization of volume) ...
virtual bool hasSymmetricDistance() const
Check if the distance function on this state space is symmetric, i.e. distance(s1,s2) = distance(s2,s1). Default implementation returns true.
Definition: StateSpace.cpp:770
void addSubspace(const StateSpacePtr &component, double weight)
Adds a new state space as part of the compound state space. For computing distances within the compou...
Definition: StateSpace.cpp:860
std::vector< ValueLocation > valueLocationsInOrder_
The value locations for all varliables of type double contained in a state; The locations point to va...
Definition: StateSpace.h:533
double maxExtent_
The extent of this space at the time setup() was called.
Definition: StateSpace.h:514
SanityChecks
Flags to use in a bit mask for state space sanity checks. Some basic checks do not have flags associa...
Definition: StateSpace.h:133
std::map< std::string, ProjectionEvaluatorPtr > projections_
List of available projections.
Definition: StateSpace.h:526
const T * as() const
Cast this instance to a desired type.
Definition: StateSpace.h:99
virtual void enforceBounds(State *state) const =0
Bring the state within the bounds of the state space. For unbounded spaces this function can be a no-...
const std::vector< double > & getSubspaceWeights() const
Get the list of component weights.
Definition: StateSpace.cpp:972
virtual bool isHybrid() const
Check if this is a hybrid state space (i.e., both discrete and continuous components exist) ...
Definition: StateSpace.cpp:877
bool hasSubspace(const std::string &name) const
Check if a specific subspace is contained in this state space.
Definition: StateSpace.cpp:906
void getCommonSubspaces(const StateSpacePtr &other, std::vector< std::string > &subspaces) const
Get the set of subspaces that this space and other have in common. The computed list of subspaces doe...
Definition: StateSpace.cpp:486
double weightSum_
The sum of all the weights in weights_.
Definition: StateSpace.h:721
virtual void deserialize(State *state, const void *serialization) const
Read the binary representation of a state from serialization and write it to state.
Definition: StateSpace.cpp:375
SubstateLocation stateLocation
Location of the substate that contains the pointed to value.
Definition: StateSpace.h:125
virtual unsigned int validSegmentCount(const State *state1, const State *state2) const
Count how many segments of the "longest valid length" fit on the motion from state1 to state2...
Check whether the distance function is symmetric (StateSpace::distance())
Definition: StateSpace.h:140
double longestValidSegmentFraction_
The fraction of the longest valid segment.
Definition: StateSpace.h:517
virtual bool equalStates(const State *state1, const State *state2) const =0
Checks whether two states are equal.
virtual double distance(const State *state1, const State *state2) const =0
Computes distance between two states. This function satisfies the properties of a metric if isMetricS...
const std::map< std::string, ProjectionEvaluatorPtr > & getRegisteredProjections() const
Get all the registered projections.
Definition: StateSpace.cpp:737
bool locked_
Flag indicating whether adding further components is allowed or not.
Definition: StateSpace.h:724
bool hasProjection(const std::string &name) const
Check if a projection with a specified name is available.
Definition: StateSpace.cpp:709
static void List(std::ostream &out)
Print the list of available state space instances.
Definition: StateSpace.cpp:520
virtual void serialize(void *serialization, const State *state) const
Write the binary representation of state to serialization.
Definition: StateSpace.cpp:371
std::map< std::string, SubstateLocation > substateLocationsByName_
All the known substat locations, by name.
Definition: StateSpace.h:540
virtual bool isCompound() const
Check if the state space is compound.
Definition: StateSpace.cpp:755
unsigned int getSubspaceCount() const
Get the number of state spaces that make up the compound state space.
Definition: StateSpace.cpp:893
Check whether the StateSpace::serialize() and StateSpace::deserialize() work as expected.
Definition: StateSpace.h:158
Check whether calling StateSpace::interpolate() works as expected.
Definition: StateSpace.h:143
Check that enforceBounds() does not modify the contents of states that are within bounds...
Definition: StateSpace.h:155
double longestValidSegment_
The longest valid segment at the time setup() was called.
Definition: StateSpace.h:520
double getLongestValidSegmentLength() const
Get the longest valid segment at the time setup() was called.
Definition: StateSpace.cpp:834
const std::string & getName() const
Get the name of the state space.
Definition: StateSpace.cpp:196
CompoundStateSpace()
Construct an empty compound state space.
Definition: StateSpace.cpp:844
virtual void interpolate(const State *from, const State *to, const double t, State *state) const =0
Computes the state that lies at time t in [0, 1] on the segment that connects from state to to state...
ProjectionEvaluatorPtr getDefaultProjection() const
Get the default projection.
Definition: StateSpace.cpp:714
virtual void freeState(State *state) const =0
Free the memory of the allocated state.
virtual void enforceBounds(State *state) const
Bring the state within the bounds of the state space. For unbounded spaces this function can be a no-...
double * getValueAddressAtLocation(State *state, const ValueLocation &loc) const
Get a pointer to the double value in state that loc points to.
Definition: StateSpace.cpp:338
const std::map< std::string, ValueLocation > & getValueLocationsByName() const
Get the named locations of values of type double contained in a state from this space. The setup() function must have been previously called.
Definition: StateSpace.cpp:319
double * getValueAddressAtName(State *state, const std::string &name) const
Get a pointer to the double value in state that name points to.
Definition: StateSpace.cpp:354
virtual void copyState(State *destination, const State *source) const =0
Copy a state to another. The memory of source and destination should NOT overlap. ...
const StateSpace * space
The space that is reached if the chain above is followed on the state space.
Definition: StateSpace.h:118
AdvancedStateCopyOperation
The possible outputs for an advanced copy operation.
Definition: StateSpace.h:765
virtual void serialize(void *serialization, const State *state) const
Write the binary representation of state to serialization.
void copyToReals(std::vector< double > &reals, const State *source) const
Copy all the real values from a state source to the array reals using getValueAddressAtLocation() ...
Definition: StateSpace.cpp:324
virtual State * allocState() const =0
Allocate a state that can store a point in the described space.
ProjectionEvaluatorPtr getProjection(const std::string &name) const
Get the projection registered under a specific name.
Definition: StateSpace.cpp:725
virtual void printState(const State *state, std::ostream &out) const
Print a state to a stream.
Definition: StateSpace.cpp:379
void clearStateSamplerAllocator()
Clear the state sampler allocator (reset to default)
Definition: StateSpace.cpp:785
virtual unsigned int getDimension() const
Get the dimension of the space (not the dimension of the surrounding ambient space) ...
Definition: StateSpace.cpp:977
virtual void sanityChecks() const
Convenience function that allows derived state spaces to choose which checks should pass (see SanityC...
Definition: StateSpace.cpp:596
std::map< std::string, ValueLocation > valueLocationsByName_
All the known value locations, by name. The names of state spaces access the first element of a state...
Definition: StateSpace.h:537
std::vector< StateSpacePtr > components_
The state spaces that make up the compound state space.
Definition: StateSpace.h:712
virtual unsigned int getSerializationLength() const
Get the number of chars in the serialization of a state in this space.
Definition: StateSpace.cpp:366
T * as(const std::string &name) const
Cast a component of this instance to a desired type.
Definition: StateSpace.h:578
OptimizationObjectivePtr operator*(double w, const OptimizationObjectivePtr &a)
Given a weighing factor and an optimization objective, returns a MultiOptimizationObjective containin...
virtual bool satisfiesBounds(const State *state) const
Check if a state is inside the bounding box. For unbounded spaces this function can always return tru...
void list(std::ostream &out) const
Print the list of all contained state space instances.
Definition: StateSpace.cpp:528
virtual double getMaximumExtent() const =0
Get the maximum value a call to distance() can return (or an upper bound). For unbounded state spaces...