├── .gitignore ├── .make ├── README.html ├── README.md ├── beautify-settings.mk ├── beautify.mk ├── build.mk ├── mappings.imp ├── problem-template.mk ├── stack.mk ├── template.mk └── uncrustify.cfg ├── .ros-scripts ├── .rosinstall ├── build_boost_148.sh ├── build_vrep_plugin.sh ├── get_boost_148.sh ├── patch_boost_148.sh └── run.sh ├── CMakeLists.txt ├── Makefile ├── README.html ├── README.md ├── docs ├── .scripts │ ├── make-links.sh │ └── make-ref-links.sh ├── Doxyfile ├── Makefile ├── Making_A_New_Model.html ├── Making_A_New_Model.md ├── Overview.html ├── Overview.md ├── ROS_VREP_Guide.html ├── ROS_VREP_Guide.md ├── doxygen_links │ ├── Build_System.md │ ├── New_Model.md │ ├── Overview.md │ ├── Quick_Start.md │ └── Ros_Tag.md └── style.css ├── launch └── tag.launch ├── license ├── BSD.txt ├── GPL-2.0.txt ├── MIT.txt └── license.txt ├── msg └── VrepInfo.msg ├── package.xml ├── problems ├── Makefile ├── conttag │ ├── Makefile │ ├── default.cfg │ └── maps │ │ ├── map.txt │ │ └── map_tag.txt ├── homecare │ ├── Makefile │ ├── changes │ │ └── change.txt │ ├── default.cfg │ └── maps │ │ ├── pathMap.txt │ │ └── typeMap.txt ├── pushbox │ ├── Makefile │ ├── default.cfg │ └── maps │ │ └── map_free_paper.txt ├── rocksample │ ├── Makefile │ ├── changes │ │ ├── changes-11-11.txt │ │ ├── changes-7-8.txt │ │ ├── changes.txt │ │ └── changes2.txt │ ├── default-11-11.cfg │ ├── default.cfg │ └── maps │ │ ├── map-11-11.txt │ │ ├── map-7-1.txt │ │ ├── map-7-2.txt │ │ ├── map-7-3.txt │ │ ├── map-7-8-obstacles.txt │ │ └── map-7-8.txt └── tag │ ├── Makefile │ ├── changes │ ├── mid-wall.txt │ └── tag-changes.txt │ ├── default.cfg │ ├── maps │ └── map.txt │ └── vrep_scenes │ └── tag.ttt ├── src ├── LinkedHashSet.hpp ├── Makefile ├── RandomAccessSet.hpp ├── check_headers.sh ├── defs.hpp ├── global.cpp ├── global.hpp ├── options │ ├── Makefile │ ├── inih │ │ ├── LICENSE.txt │ │ ├── Makefile │ │ ├── README.txt │ │ ├── ini.c │ │ └── ini.h │ ├── option_parser.cpp │ ├── option_parser.hpp │ └── tclap │ │ ├── AUTHORS │ │ ├── Arg.h │ │ ├── ArgException.h │ │ ├── ArgTraits.h │ │ ├── COPYING │ │ ├── CmdLine.h │ │ ├── CmdLineInterface.h │ │ ├── CmdLineOutput.h │ │ ├── Constraint.h │ │ ├── DocBookOutput.h │ │ ├── HelpVisitor.h │ │ ├── IgnoreRestVisitor.h │ │ ├── MultiArg.h │ │ ├── MultiSwitchArg.h │ │ ├── OptionalUnlabeledTracker.h │ │ ├── StandardTraits.h │ │ ├── StdOutput.h │ │ ├── SwitchArg.h │ │ ├── UnlabeledMultiArg.h │ │ ├── UnlabeledValueArg.h │ │ ├── ValueArg.h │ │ ├── ValuesConstraint.h │ │ ├── VersionVisitor.h │ │ ├── Visitor.h │ │ ├── XorHandler.h │ │ └── ZshCompletionOutput.h ├── problems │ ├── Makefile │ ├── conttag │ │ ├── ContTagAction.hpp │ │ ├── ContTagModel.cpp │ │ ├── ContTagModel.hpp │ │ ├── ContTagObservation.hpp │ │ ├── ContTagOptions.hpp │ │ ├── ContTagPosition.hpp │ │ ├── ContTagState.hpp │ │ ├── ContTagTextSerializer.cpp │ │ ├── ContTagTextSerializer.hpp │ │ ├── Makefile │ │ ├── map2d.hpp │ │ ├── simulate.cpp │ │ └── solve.cpp │ ├── homecare │ │ ├── HomecareAction.cpp │ │ ├── HomecareAction.hpp │ │ ├── HomecareModel.cpp │ │ ├── HomecareModel.hpp │ │ ├── HomecareObservation.cpp │ │ ├── HomecareObservation.hpp │ │ ├── HomecareOptions.hpp │ │ ├── HomecareState.cpp │ │ ├── HomecareState.hpp │ │ ├── HomecareTextSerializer.cpp │ │ ├── HomecareTextSerializer.hpp │ │ ├── Makefile │ │ ├── simulate.cpp │ │ ├── solve.cpp │ │ └── stest.cpp │ ├── pushbox │ │ ├── Action2d.hpp │ │ ├── BearingObservation.hpp │ │ ├── Makefile │ │ ├── Map2d.hpp │ │ ├── Position2d.hpp │ │ ├── PushBoxModel.cpp │ │ ├── PushBoxModel.hpp │ │ ├── PushBoxOptions.hpp │ │ ├── PushBoxTextSerializer.cpp │ │ ├── PushBoxTextSerializer.hpp │ │ ├── StateRobotWithOpponent2d.hpp │ │ ├── TruncatedNormalDistribution.hpp │ │ ├── simulate.cpp │ │ └── solve.cpp │ ├── rocksample │ │ ├── LegalActionsPool.cpp │ │ ├── LegalActionsPool.hpp │ │ ├── Makefile │ │ ├── PreferredActionsPool.cpp │ │ ├── PreferredActionsPool.hpp │ │ ├── RockSampleAction.cpp │ │ ├── RockSampleAction.hpp │ │ ├── RockSampleMdpSolver.cpp │ │ ├── RockSampleMdpSolver.hpp │ │ ├── RockSampleModel.cpp │ │ ├── RockSampleModel.hpp │ │ ├── RockSampleObservation.cpp │ │ ├── RockSampleObservation.hpp │ │ ├── RockSampleOptions.hpp │ │ ├── RockSampleState.cpp │ │ ├── RockSampleState.hpp │ │ ├── RockSampleTextSerializer.cpp │ │ ├── RockSampleTextSerializer.hpp │ │ ├── position_history.cpp │ │ ├── position_history.hpp │ │ ├── simulate.cpp │ │ ├── smart_history.cpp │ │ ├── smart_history.hpp │ │ ├── solve.cpp │ │ └── stest.cpp │ ├── shared │ │ ├── GridPosition.hpp │ │ ├── Makefile │ │ ├── ModelWithProgramOptions.hpp │ │ ├── SharedOptions.hpp │ │ ├── geometry │ │ │ ├── Makefile │ │ │ ├── Point2D.cpp │ │ │ ├── Point2D.hpp │ │ │ ├── RTree.cpp │ │ │ ├── RTree.hpp │ │ │ ├── Rectangle2D.cpp │ │ │ ├── Rectangle2D.hpp │ │ │ ├── Vector2D.cpp │ │ │ ├── Vector2D.hpp │ │ │ ├── utilities.cpp │ │ │ └── utilities.hpp │ │ ├── parsers.cpp │ │ ├── parsers.hpp │ │ ├── policy_iteration.cpp │ │ ├── policy_iteration.hpp │ │ ├── ros │ │ │ ├── ScanToPcl.cpp │ │ │ ├── TapirNode.hpp │ │ │ ├── VrepHelper.cpp │ │ │ └── VrepHelper.hpp │ │ ├── simulate.hpp │ │ ├── solve.hpp │ │ └── stest.hpp │ └── tag │ │ ├── Makefile │ │ ├── TagAction.cpp │ │ ├── TagAction.hpp │ │ ├── TagMdpSolver.cpp │ │ ├── TagMdpSolver.hpp │ │ ├── TagModel.cpp │ │ ├── TagModel.hpp │ │ ├── TagObservation.cpp │ │ ├── TagObservation.hpp │ │ ├── TagOptions.hpp │ │ ├── TagState.cpp │ │ ├── TagState.hpp │ │ ├── TagTextSerializer.cpp │ │ ├── TagTextSerializer.hpp │ │ ├── ros │ │ ├── TagNode.cpp │ │ └── TagNode.hpp │ │ ├── simulate.cpp │ │ ├── solve.cpp │ │ └── stest.cpp └── solver │ ├── ActionNode.cpp │ ├── ActionNode.hpp │ ├── Agent.cpp │ ├── Agent.hpp │ ├── BeliefNode.cpp │ ├── BeliefNode.hpp │ ├── BeliefTree.cpp │ ├── BeliefTree.hpp │ ├── Histories.cpp │ ├── Histories.hpp │ ├── HistoryEntry.cpp │ ├── HistoryEntry.hpp │ ├── HistorySequence.cpp │ ├── HistorySequence.hpp │ ├── Makefile │ ├── Simulator.cpp │ ├── Simulator.hpp │ ├── Solver.cpp │ ├── Solver.hpp │ ├── StateInfo.cpp │ ├── StateInfo.hpp │ ├── StatePool.cpp │ ├── StatePool.hpp │ ├── abstract-problem │ ├── Action.hpp │ ├── DiscretizedPoint.cpp │ ├── DiscretizedPoint.hpp │ ├── HistoricalData.hpp │ ├── Makefile │ ├── Model.cpp │ ├── Model.hpp │ ├── ModelChange.hpp │ ├── Observation.hpp │ ├── Options.hpp │ ├── Point.hpp │ ├── State.hpp │ ├── TransitionParameters.hpp │ ├── Vector.cpp │ ├── Vector.hpp │ ├── VectorState.hpp │ └── heuristics │ │ ├── HeuristicFunction.hpp │ │ ├── Makefile │ │ ├── RolloutHeuristic.cpp │ │ └── RolloutHeuristic.hpp │ ├── belief-estimators │ ├── Makefile │ ├── estimators.cpp │ └── estimators.hpp │ ├── cached_values.hpp │ ├── changes │ ├── ChangeFlags.hpp │ ├── DefaultHistoryCorrector.cpp │ ├── DefaultHistoryCorrector.hpp │ ├── HistoryCorrector.hpp │ └── Makefile │ ├── indexing │ ├── FlaggingVisitor.cpp │ ├── FlaggingVisitor.hpp │ ├── Makefile │ ├── RTree.cpp │ ├── RTree.hpp │ ├── SpatialIndexVisitor.cpp │ ├── SpatialIndexVisitor.hpp │ └── StateIndex.hpp │ ├── mappings │ ├── Makefile │ ├── actions │ │ ├── ActionMapping.hpp │ │ ├── ActionMappingEntry.hpp │ │ ├── ActionPool.hpp │ │ ├── Makefile │ │ ├── continuous_actions.cpp │ │ ├── continuous_actions.hpp │ │ ├── discretized_actions.cpp │ │ ├── discretized_actions.hpp │ │ ├── enumerated_actions.cpp │ │ └── enumerated_actions.hpp │ └── observations │ │ ├── Makefile │ │ ├── ObservationMapping.hpp │ │ ├── ObservationMappingEntry.hpp │ │ ├── ObservationPool.hpp │ │ ├── approximate_observations.cpp │ │ ├── approximate_observations.hpp │ │ ├── discrete_observations.cpp │ │ ├── discrete_observations.hpp │ │ ├── enumerated_observations.cpp │ │ └── enumerated_observations.hpp │ ├── search │ ├── Makefile │ ├── MultipleStrategiesExp3.cpp │ ├── MultipleStrategiesExp3.hpp │ ├── SearchStatus.hpp │ ├── action-choosers │ │ ├── Makefile │ │ ├── choosers.cpp │ │ ├── choosers.hpp │ │ ├── gps_choosers.cpp │ │ └── gps_choosers.hpp │ ├── search_interface.cpp │ ├── search_interface.hpp │ └── steppers │ │ ├── Makefile │ │ ├── default_rollout.cpp │ │ ├── default_rollout.hpp │ │ ├── gps_search.cpp │ │ ├── gps_search.hpp │ │ ├── nn_rollout.cpp │ │ ├── nn_rollout.hpp │ │ ├── ucb_search.cpp │ │ └── ucb_search.hpp │ └── serialization │ ├── Makefile │ ├── Serializer.hpp │ ├── TextSerializer.cpp │ └── TextSerializer.hpp └── srv ├── simRosCopyPasteObjects.srv ├── simRosGetObjectHandle.srv ├── simRosGetObjectPose.srv ├── simRosLoadScene.srv ├── simRosSetObjectPosition.srv ├── simRosStartSimulation.srv └── simRosStopSimulation.srv /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse settings 2 | /.cproject 3 | /.project 4 | /.settings 5 | /EMPTY_HEADER.hpp 6 | 7 | # Local configuration settings 8 | /*local.make 9 | 10 | # Boost 1.48 built from source 11 | boost_1_48_0 12 | 13 | # Automatically generated documentation 14 | docs/html 15 | docs/generated 16 | 17 | # Binaries 18 | /builds 19 | /build 20 | simulate-ros 21 | simulate 22 | solve 23 | solve-mdp 24 | stest 25 | 26 | # Logging outputs 27 | core 28 | *.log 29 | *.pol 30 | *.pol2 31 | *.m 32 | *.prof 33 | 34 | # backup files 35 | *~ 36 | -------------------------------------------------------------------------------- /.make/beautify-settings.mk: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------- 2 | # Configuration of code cleaners. 3 | # ---------------------------------------------------------------------- 4 | BEAUTIFY_CFG := $(ROOT)/.make/uncrustify.cfg 5 | BEAUTIFY_CMD := uncrustify -c $(BEAUTIFY_CFG) 6 | BEAUTIFY_FLAGS := --no-backup 7 | 8 | IWYU_MAPPING_FILE := $(ROOT)/.make/mappings.imp 9 | IWYU_CMD := include-what-you-use 10 | IWYU_FLAGS := -Xiwyu --mapping_file=$(IWYU_MAPPING_FILE) -Xiwyu --verbose=3 11 | 12 | IWYU_FIX_CMD := fix-includes 13 | IWYU_FIX_FLAGS := --separate_c_cxx 14 | IWYU_FIX_FLAGS += --nosafe_headers --comments $(INCDIRS) 15 | IWYU_FIX_FLAGS += -o $(dir $@) 16 | 17 | # ---------------------------------------------------------------------- 18 | # Code cleaner recipes. 19 | # ---------------------------------------------------------------------- 20 | BEAUTIFY_RECIPE := $(BEAUTIFY_CMD) $(BEAUTIFY_FLAGS) $< 21 | IWYU_CXX_RECIPE := $(IWYU_CMD) $(IWYU_FLAGS) $(CPPFLAGS) $(CXXFLAGS_BASE) $< 2>&1 | tee $@ 22 | IWYU_CC_RECIPE := $(IWYU_CMD) $(IWYU_FLAGS) $(CPPFLAGS) $(CFLAGS) $< 2>&1 | tee $@ 23 | IWYU_FIX_RECIPE := $(IWYU_FIX_CMD) $(IWYU_FIX_FLAGS) < $< 2>&1 | tee $@ 24 | IWYU_FORCE_RECIPE := echo "\#include \"../EMPTY_HEADER.hpp\"" >> $< 25 | IWYU_DOFIX_RECIPE := cp -p $(dir $@)/$* $< 26 | 27 | # ---------------------------------------------------------------------- 28 | # Code cleaning targets. 29 | # ---------------------------------------------------------------------- 30 | .PHONY: beautify-all iwyu-all iwyu-fix-all iwyu-force-all iwyu-dofix-all iwyu-clean-all 31 | .PHONY: beautify iwyu iwyu-fix iwyu-force iwyu-dofix iwyu-clean 32 | 33 | beautify: beautify-all ; 34 | iwyu: iwyu-all ; 35 | iwyu-fix: iwyu-fix-all ; 36 | iwyu-force: iwyu-force-all ; 37 | iwyu-dofix: iwyu-dofix-all ; 38 | iwyu-clean: iwyu-clean-all ; 39 | 40 | iwyu-clean-all: 41 | @rm -rf iwyu-out 42 | clean: iwyu-clean-all 43 | -------------------------------------------------------------------------------- /.make/build.mk: -------------------------------------------------------------------------------- 1 | # Include a configuration for building just the object files 2 | build-$(MODULE_NAME): $$(OBJS_$(MODULE_NAME)) 3 | -------------------------------------------------------------------------------- /.make/stack.mk: -------------------------------------------------------------------------------- 1 | sp := $(sp).x 2 | dirstack_$(sp) := $(d) 3 | d := $(dir) 4 | 5 | # Default: name=directory; no children. 6 | MODULE_NAME := $(d) 7 | CHILD_DIRS := 8 | 9 | include $(d)/Makefile 10 | NAME_$(d) := $(MODULE_NAME) 11 | CHILD_DIRS_$(MODULE_NAME) := $(CHILD_DIRS) 12 | PATH_$(MODULE_NAME) := $(d) 13 | ALL_OBJS_$(MODULE_NAME) := $(OBJS_$(MODULE_NAME)) 14 | 15 | define child_template 16 | dir := $(d)/$(1) 17 | include .make/stack.mk 18 | endef 19 | $(foreach directory,$(CHILD_DIRS),$(eval $(call child_template,$(directory)))) 20 | 21 | define child_objs_template 22 | ALL_OBJS_$(NAME_$(d)) += $(ALL_OBJS_$(NAME_$(d)/$(1))) 23 | endef 24 | $(foreach directory,$(CHILD_DIRS_$(NAME_$(d))),$(eval $(call child_objs_template,$(directory)))) 25 | 26 | d := $(dirstack_$(sp)) 27 | sp := $(basename $(sp)) 28 | -------------------------------------------------------------------------------- /.make/uncrustify.cfg: -------------------------------------------------------------------------------- 1 | newlines = lf 2 | 3 | indent_columns = 4 4 | indent_with_tabs = 0 5 | 6 | indent_class = true 7 | indent_access_spec = 3 8 | 9 | #indent_continue = 8 10 | indent_align_assign = false 11 | indent_func_call_param = true 12 | indent_func_def_param = true 13 | indent_func_proto_param = true 14 | indent_func_class_param = true 15 | indent_func_ctor_var_param = true 16 | indent_template_param = true 17 | indent_func_param_double = true 18 | 19 | sp_before_ptr_star = force 20 | sp_after_ptr_star = remove 21 | sp_before_byref = force 22 | sp_after_byref = remove 23 | 24 | sp_angle_shift = remove 25 | sp_permit_cpp11_shift = true 26 | 27 | align_var_def_star_style = 1 28 | align_var_def_amp_style = 1 29 | align_typedef_star_style = 1 30 | align_typedef_amp_style = 1 31 | 32 | sp_func_def_paren = remove 33 | sp_cparen_oparen = remove 34 | sp_func_proto_paren = remove 35 | sp_func_call_paren = remove 36 | sp_after_tparen_close = remove 37 | nl_fdef_brace = remove 38 | 39 | sp_fparen_brace = force 40 | sp_after_comma = force 41 | 42 | code_width = 80 43 | pos_comma = trail 44 | pos_assign = trail 45 | pos_class_comma = trail 46 | pos_class_colon = trail 47 | 48 | pos_arith = lead 49 | pos_bool = lead 50 | pos_compare = lead 51 | pos_conditional = lead 52 | 53 | nl_remove_extra_newlines = 0 54 | -------------------------------------------------------------------------------- /.ros-scripts/.rosinstall: -------------------------------------------------------------------------------- 1 | - git: 2 | local-name: octomap_mapping 3 | uri: https://github.com/OctoMap/octomap_mapping.git 4 | version: indigo-devel 5 | - git: 6 | local-name: husky_description 7 | uri: https://github.com/husky/husky_description.git 8 | version: hydro-devel 9 | -------------------------------------------------------------------------------- /.ros-scripts/build_boost_148.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$TAPIR_BOOST_148" ] 3 | then 4 | echo "ERROR: No target directory specified for Boost" 5 | exit 1 6 | fi 7 | 8 | echo "Compile Boost 1.48?" 9 | select yn in "Yes" "No" 10 | do 11 | if [ "$yn" = "Yes" ] 12 | then 13 | cd tapir_boost_install/boost_1_48_0 14 | ./bootstrap.sh --prefix="$TAPIR_BOOST_148" 15 | echo "Building Boost." 16 | echo "This could take a long time..." 17 | sleep 1 18 | ./b2 install -j8 19 | cd ../.. 20 | rm -rf tapir_boost_install 21 | exit 0 22 | else 23 | exit 1 24 | fi 25 | done 26 | -------------------------------------------------------------------------------- /.ros-scripts/build_vrep_plugin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This script will automatically rebuild the V-REP ROS plugin, which causes 3 | # trouble on Ubuntu 14.04 4 | 5 | if [ -z "$VREP_DIR" ] 6 | then 7 | echo "Please set VREP_DIR in the root Makefile and run this script" 8 | echo "via the command 'make vrep_plugin' instead." 9 | exit 1 10 | fi 11 | 12 | if [ -z "$ROS_SCRIPT" ] 13 | then 14 | echo "Please set ROS_SCRIPT in the root Makefile and run this script" 15 | echo "via the command 'make vrep_plugin' instead." 16 | exit 2 17 | fi 18 | 19 | if [ ! -d "$VREP_DIR/programming/ros_packages" ] 20 | then 21 | echo "ERROR: V-REP code not found. Please set VREP_DIR correctly," 22 | echo "or download and extract V-REP in \"$VREP_DIR\"" 23 | exit 3 24 | fi 25 | 26 | . "$ROS_SCRIPT" 27 | 28 | ROS_VERSION=$(rosversion -d) 29 | PATCH_PLUGIN=false 30 | DISABLE_OTHER_INTERFACE=false 31 | if [ -z "$ROS_VERSION" ] 32 | then 33 | echo "ROS not found. Perhaps you have set the ROS_SCRIPT variable in" 34 | echo "the root Makefile incorrectly?" 35 | exit 4 36 | elif [ "$ROS_VERSION" = "hydro" ] 37 | then 38 | echo "ROS Hydro detected." 39 | elif [ "$ROS_VERSION" = "indigo" ] 40 | then 41 | echo "ROS Indigo detected." 42 | PATCH_PLUGIN=true 43 | else 44 | echo "ROS $ROS_VERSION detected." 45 | sudo apt-get install libopencv-dev 46 | # New V-REP interface doesn't seem to compile, use old plugin 47 | DISABLE_OTHER_INTERFACE=true 48 | fi 49 | 50 | JOY=$(env ROS_CACHE_TIMEOUT=0 rospack list-names | grep joy) 51 | if [ -z "$JOY" ] 52 | then 53 | echo "ROS joystick package not found!" 54 | sudo apt-get install ros-$ROS_VERSION-joy 55 | JOY=$(env ROS_CACHE_TIMEOUT=0 rospack list-names | grep joy) 56 | if [ -z "$JOY" ] 57 | then 58 | echo "Failed to install the ROS joystick package." 59 | echo "Please install it before re-running this script." 60 | exit 5 61 | fi 62 | fi 63 | 64 | echo "Copying V-REP code" 65 | 66 | mkdir -p vrep_plugin_build/src 67 | cd vrep_plugin_build 68 | cp -r $VREP_DIR/programming/ros_packages/* src 69 | 70 | if $DISABLE_OTHER_INTERFACE 71 | then 72 | rm -rf src/v_repExtRosInterface 73 | fi 74 | 75 | if $PATCH_PLUGIN 76 | then 77 | sed -i 's/hydro/indigo/g' src/vrep_plugin/CMakeLists.txt 78 | echo "V-REP code patched for ROS Indigo" 79 | fi 80 | 81 | echo "Building V-REP plugin..." 82 | sleep 0.5 83 | catkin_make 84 | 85 | echo "Moving plugin to V-REP directory" 86 | cp -i devel/lib/libv_repExtRos.so $VREP_DIR/ 87 | cd .. 88 | rm -rf vrep_plugin_build 89 | echo "Finished!" 90 | -------------------------------------------------------------------------------- /.ros-scripts/get_boost_148.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # If the temporary directory exists, we don't do anything. 3 | if [ -f tapir_boost_install/boost_1_48_0/bootstrap.sh ] 4 | then 5 | exit 0 6 | fi 7 | 8 | VERSION=$(lsb_release -a 2> /dev/null | grep Release | cut -d ':' -f 2) 9 | VERSION="${VERSION#"${VERSION%%[![:space:]]*}"}" # remove leading whitespace characters 10 | VERSION="${VERSION%"${VERSION##*[![:space:]]}"}" # remove trailing whitespace characters 11 | if [ "$VERSION" != "12.04" ] 12 | then 13 | echo "WARNING: If you have Ubuntu > 12.04 you shouldn't need to install Boost from source..." 14 | fi 15 | 16 | mkdir tapir_boost_install 17 | cd tapir_boost_install 18 | HAS_ARCHIVE=false 19 | if [ -f boost_1_48_0.tar.bz2 ] 20 | then 21 | if [ $(md5sum boost_1_48_0.tar.bz2 | cut -d " " -f 1) == "d1e9a7a7f532bb031a3c175d86688d95" ] 22 | then 23 | HAS_ARCHIVE=true 24 | else 25 | rm boost_1_48_0.tar.bz2 26 | fi 27 | fi 28 | if [ $HAS_ARCHIVE = "false" ] 29 | then 30 | wget "downloads.sourceforge.net/project/boost/boost/1.48.0/boost_1_48_0.tar.bz2" 31 | fi 32 | echo "Extracting Boost source code..." 33 | tar jxf boost_1_48_0.tar.bz2 34 | -------------------------------------------------------------------------------- /.ros-scripts/patch_boost_148.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Patching Boost Header..." 3 | perl -pi -e 's/defined\(_GLIBCXX__PTHREADS\)$/defined(_GLIBCXX__PTHREADS) \\\n || defined(_GLIBCXX_HAS_GTHREADS)/' tapir_boost_install/boost_1_48_0/boost/config/stdlib/libstdcpp3.hpp 4 | -------------------------------------------------------------------------------- /.ros-scripts/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This script automatically starts the TAPIR interface with ROS and V-REP 3 | if [ -z "$TAPIR_DIR" ] 4 | then 5 | echo "Set the environemnt variable TAPIR_DIR, or run this script" 6 | echo "via ./simulate-ros in the problem directory." 7 | exit 1 8 | fi 9 | 10 | if [ -z "$TAPIR_WS_DIR" ] 11 | then 12 | echo "Set the environemnt variable TAPIR_WS_DIR, or run this script" 13 | echo "via ./simulate-ros in the problem directory." 14 | exit 2 15 | fi 16 | 17 | if [ -z "$VREP_DIR" ] 18 | then 19 | echo "Set the environemnt variable VREP_DIR, or run this script" 20 | echo "via ./simulate-ros in the problem directory." 21 | exit 3 22 | fi 23 | 24 | if [ "$1" = "tracker" ] 25 | then 26 | VREP_SCENE="$TAPIR_DIR/problems/tracker/vrep-scenes/zones.ttt" 27 | LAUNCH=tracker_zones.launch 28 | else 29 | VREP_SCENE="$TAPIR_DIR/problems/tag/vrep-scenes/tag.ttt" 30 | LAUNCH=tag.launch 31 | 32 | fi 33 | 34 | # Check for catkin workspace setup.sh 35 | WS_SETUP_SCRIPT="$TAPIR_WS_DIR/devel/setup.sh" 36 | if [ -f "$WS_SETUP_SCRIPT" ] 37 | then 38 | . $WS_SETUP_SCRIPT 39 | echo "Successfully sourced ROS workspace environment variables" 40 | else 41 | echo "ERROR: The TAPIR workspace is not set up; please re-run \"make ros\"" 42 | echo "to set it up, or refer to README.md for further detail." 43 | exit 4 44 | fi 45 | 46 | # Check if V-REP is running 47 | MUST_START_VREP=false 48 | if ! pgrep vrep > /dev/null 49 | then 50 | if [ -e "$VREP_DIR/vrep.sh" ]; then 51 | MUST_START_VREP=true 52 | else 53 | echo "ERROR: vrep.sh not found in $VREP_DIR" 54 | echo "Please set VREP_DIR correctly in the root Makefile and re-run" 55 | echo "the command \"make ros-scripts\"" 56 | exit 5 57 | fi 58 | fi 59 | 60 | # Start the roscore 61 | x-terminal-emulator -e sh -c ". $WS_SETUP_SCRIPT; roscore; sh" 62 | 63 | if $MUST_START_VREP 64 | then 65 | sleep 1 66 | echo "Starting V-REP..." 67 | x-terminal-emulator -e sh -c ". $WS_SETUP_SCRIPT; cd $VREP_DIR; ./vrep.sh; sh" 68 | if [ "$1" = "tracker" ] 69 | then 70 | sleep 3 71 | fi 72 | fi 73 | 74 | # Now do a roslaunch! 75 | echo "Launching $LAUNCH" 76 | roslaunch tapir "$LAUNCH" 77 | -------------------------------------------------------------------------------- /docs/.scripts/make-links.sh: -------------------------------------------------------------------------------- 1 | grep -Po "(?<=\[)[^\]]*?[^\\\\](?=\]($|[^:\[\(]))" $1 | env LC_COLLATE=C sort | uniq | while read -r line 2 | do 3 | echo [$line]: $line 4 | done 5 | -------------------------------------------------------------------------------- /docs/.scripts/make-ref-links.sh: -------------------------------------------------------------------------------- 1 | echo [TOC] 2 | echo 3 | grep -Po "(?<=\[)[^\]]*?[^\\\\](?=\]($|[^:\[\(]))" $1 | env LC_COLLATE=C sort | uniq | while read -r line 4 | do 5 | echo [$line]: @ref $line 6 | done 7 | -------------------------------------------------------------------------------- /docs/doxygen_links/Build_System.md: -------------------------------------------------------------------------------- 1 | [build.mk]: @ref build.mk 2 | [problem-template.mk]: @ref problem-template.mk 3 | [stack.mk]: @ref stack.mk 4 | [template.mk]: @ref template.mk 5 | -------------------------------------------------------------------------------- /docs/doxygen_links/Overview.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | [../.make]: @ref LINK_DISABLED 4 | [../.make/README.md]: @ref docs/generated/Build_System.md 5 | [../.ros-scripts]: @ref LINK_DISABLED 6 | [../CMakeLists.txt]: @ref LINK_DISABLED 7 | [../Makefile]: @ref LINK_DISABLED 8 | [../README.md]: @ref docs/generated/Quick_Start.md 9 | [../docs]: @ref docs 10 | [../docs/Making_A_New_Model.md]: @ref docs/generated/New_Model.md 11 | [../docs/html]: @ref LINK_DISABLED 12 | [../docs/html/index.html]: @ref LINK_DISABLED 13 | [../launch]: @ref LINK_DISABLED 14 | [../msg]: @ref LINK_DISABLED 15 | [../problems]: @ref problems 16 | [../problems/rocksample]: @ref problems/rocksample 17 | [../problems/tag]: @ref problems/tag 18 | [../problems/tag/default.cfg]: @ref problems/tag/default.cfg 19 | [../src]: @ref src 20 | [../src/options]: @ref src/options 21 | [../src/options/inih]: @ref LINK_DISABLED 22 | [../src/options/tclap]: @ref LINK_DISABLED 23 | [../src/problems]: @ref src/problems 24 | [../src/problems/rocksample]: @ref src/problems/rocksample 25 | [../src/problems/shared]: @ref src/problems/shared 26 | [../src/problems/tag]: @ref src/problems/tag 27 | [../src/solver]: @ref src/solver 28 | [../srv]: @ref LINK_DISABLED 29 | [Options]: @ref Options 30 | [TagOptions]: @ref tag::TagOptions 31 | -------------------------------------------------------------------------------- /docs/doxygen_links/Quick_Start.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | [docs/ROS_VREP_Guide.md]: docs/generated/Ros_Tag.md 4 | [docs/Making_A_New_Model.md]: @ref docs/generated/New_Model.md 5 | [problems]: @ref problems 6 | [problems/rocksample/default.cfg]: @ref problems/rocksample/default.cfg 7 | [src/problems]: @ref src/problems 8 | [src/problems/Makefile]: @ref src/problems 9 | [src/problems/tag/Makefile]: @ref src/problems/tag 10 | [src/problems/tag/TagModel.hpp]: @ref src/problems/tag/TagModel.hpp 11 | [src/problems/tag/ros/TagVrep.cpp]: @ref src/problems/tag/ros/TagVrep.cpp 12 | [src/solver/Simulator.hpp]: @ref src/solver/Simulator.hpp 13 | -------------------------------------------------------------------------------- /docs/doxygen_links/Ros_Tag.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | [TapirNode]: @ref TapirNode 5 | [Simulator]: @ref solver::Simulator 6 | [TagNode]: @ref tag::TagNode 7 | [TagModel]: @ref tag::TagModel 8 | [../docs/Making_A_New_Model.md]: @ref docs/generated/New_Model.md 9 | [../README.md]: @ref docs/generated/Quick_Start.md 10 | -------------------------------------------------------------------------------- /docs/style.css: -------------------------------------------------------------------------------- 1 | h1, 2 | h2, 3 | h3, 4 | h4, 5 | h5, 6 | h6, 7 | p, 8 | blockquote { 9 | margin: 0; 10 | padding: 0; 11 | } 12 | body { 13 | font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif; 14 | font-size: 13px; 15 | line-height: 18px; 16 | color: #737373; 17 | margin: 10px 10px 10px 20px; 18 | } 19 | a { 20 | color: #0069d6; 21 | } 22 | a:hover { 23 | color: #0050a3; 24 | text-decoration: none; 25 | } 26 | a img { 27 | border: none; 28 | } 29 | p { 30 | margin-bottom: 9px; 31 | } 32 | h1, 33 | h2, 34 | h3, 35 | h4, 36 | h5, 37 | h6 { 38 | color: #404040; 39 | line-height: 36px; 40 | } 41 | h1 { 42 | margin-bottom: 18px; 43 | font-size: 30px; 44 | } 45 | h2 { 46 | font-size: 24px; 47 | } 48 | h3 { 49 | font-size: 18px; 50 | } 51 | h4 { 52 | font-size: 16px; 53 | } 54 | h5 { 55 | font-size: 14px; 56 | } 57 | h6 { 58 | font-size: 13px; 59 | } 60 | hr { 61 | margin: 0 0 19px; 62 | border: 0; 63 | border-bottom: 1px solid #aaa; 64 | } 65 | blockquote { 66 | padding: 13px 13px 21px 15px; 67 | margin-bottom: 18px; 68 | font-family:georgia,serif; 69 | font-style: italic; 70 | } 71 | blockquote:before { 72 | content:"\201C"; 73 | font-size:40px; 74 | margin-left:-10px; 75 | font-family:georgia,serif; 76 | color:#eee; 77 | } 78 | blockquote p { 79 | font-size: 14px; 80 | font-weight: 300; 81 | line-height: 18px; 82 | margin-bottom: 0; 83 | font-style: italic; 84 | } 85 | code, pre { 86 | padding: 0 3px 2px; 87 | font-family: Monaco, Andale Mono, Courier New, monospace; 88 | -webkit-border-radius: 3px; 89 | -moz-border-radius: 3px; 90 | border-radius: 3px; 91 | } 92 | code { 93 | background-color: #fee9cc; 94 | color: rgba(0, 0, 0, 0.75); 95 | padding: 1px 3px; 96 | font-size: 12px; 97 | } 98 | pre { 99 | display: block; 100 | padding: 14px; 101 | margin: 0 0 18px; 102 | line-height: 16px; 103 | font-size: 11px; 104 | border: 1px dashed #ccc; 105 | border: 1px dashed rgba(0, 0, 0, 0.15); 106 | -webkit-border-radius: 3px; 107 | -moz-border-radius: 3px; 108 | border-radius: 3px; 109 | white-space: pre; 110 | white-space: pre-wrap; 111 | word-wrap: break-word; 112 | } 113 | pre code { 114 | background-color: #fdfdfd; 115 | color:#737373; 116 | font-size: 11px; 117 | } 118 | @media screen and (min-width: 768px) { 119 | body { 120 | width: 748px; 121 | margin:10px auto; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /launch/tag.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /license/BSD.txt: -------------------------------------------------------------------------------- 1 | 2 | The "inih" library is distributed under the New BSD license: 3 | 4 | Copyright (c) 2009, Brush Technology 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 are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of Brush Technology nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY BRUSH TECHNOLOGY ''AS IS'' AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL BRUSH TECHNOLOGY BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /license/MIT.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2006-2011 by Mike Smoot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /license/license.txt: -------------------------------------------------------------------------------- 1 | License 2 | 3 | Copyright (c) 2014 by the University of Queensland. 4 | 5 | TAPIR is licensed under EITHER (your option): 6 | 1. GNU GPL V2. 7 | 2. TAPIR commercial license (please contact us at rdl.algorithm@itee.uq.edu.au for details). 8 | 9 | TAPIR makes use of inih (http://code.google.com/p/inih/) and tclap (http://www.google.com/#q=tclap) to parse program options. The code inih is released under the New BSD License, while the code tclap is released under the MIT License. 10 | -------------------------------------------------------------------------------- /msg/VrepInfo.msg: -------------------------------------------------------------------------------- 1 | std_msgs/Header headerInfo 2 | std_msgs/Int32 simulatorState 3 | std_msgs/Float32 simulationTime 4 | std_msgs/Float32 timeStep 5 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | tapir 4 | 0.0.0 5 | The tapir package 6 | 7 | 8 | 9 | 10 | joshua 11 | 12 | 13 | 14 | 15 | 16 | TODO 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | catkin 43 | roslib 44 | roscpp 45 | std_msgs 46 | geometry_msgs 47 | tf 48 | message_generation 49 | laser_geometry 50 | roslib 51 | roscpp 52 | std_msgs 53 | geometry_msgs 54 | tf 55 | message_runtime 56 | laser_geometry 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /problems/Makefile: -------------------------------------------------------------------------------- 1 | REDIRECT = 2 | .PHONY: $(MAKECMDGOALS) call-upwards 3 | $(MAKECMDGOALS): call-upwards ; 4 | call-upwards: 5 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 6 | -------------------------------------------------------------------------------- /problems/conttag/Makefile: -------------------------------------------------------------------------------- 1 | REDIRECT = conttag 2 | .PHONY: $(MAKECMDGOALS) call-upwards 3 | $(MAKECMDGOALS): call-upwards ; 4 | call-upwards: 5 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 6 | -------------------------------------------------------------------------------- /problems/conttag/default.cfg: -------------------------------------------------------------------------------- 1 | # seed = 1 2 | 3 | # General-purpose settings. 4 | color = false 5 | verbose = true 6 | 7 | [ABT] 8 | # Whether to keep track of states in an index data structure 9 | useStateIndex = false 10 | 11 | # The number of trajectories to simulate per time step (0 => wait for timeout) 12 | historiesPerStep = 0 13 | 14 | # The maximum time to spend on each step, in milliseconds (0 => no time limit) 15 | stepTimeout = 1000 16 | #solveTimeout = 1000 17 | 18 | # If this is set to "true", ABT will prune the tree after every step. 19 | pruneEveryStep = true 20 | 21 | # If this is set to "true", ABT will reset the tree instead of modifying it when 22 | # changes occur. 23 | resetOnChanges = false 24 | 25 | # The minimum number of particles for the current belief state in a simulation. 26 | # Extra particles will be resampled via a particle filter if the particle count 27 | # for the *current* belief state drops below this number during simulation. 28 | minParticleCount = 5000 29 | 30 | # The maximum depth to search in the tree, relative to the current belief. 31 | maximumDepth = 50 32 | # True if the above horizon is relative to the initial belief, and false 33 | # if it's relative to the current belief. 34 | isAbsoluteHorizon = false 35 | 36 | searchHeuristic = default() 37 | searchStrategy = gps(searchType=golden, dimensions=1, explorationCoefficient=100, newSearchPointCoefficient=4, minimumVisitsBeforeChildCreation=1, minimumChildCreationDistance=0.05) 38 | recommendationStrategy = gpsmax(searchType=golden, dimensions=1, recommendationMode=robust) 39 | 40 | estimator = mean() 41 | 42 | [problem] 43 | discountFactor = 0.95 44 | 45 | mapPath = maps/map_tag.txt 46 | moveCost = 1 47 | tagSuccessReward = 10 48 | tagFailPenalty = 10 49 | collisionPenalty = 0 50 | 51 | sizeX = 10 52 | sizeY = 10 53 | 54 | moveDistance = 1 55 | humanMoveDistance = 1 56 | sensorAngleInner = 0; 57 | sensorAngleOuter = 45; 58 | #sensorAngleOuter = 0; 59 | 60 | moveUncertainty = 0 61 | actionUncertainty = 0 62 | observationUncertainty = 0.0 63 | humanAngleUncertainty = 22.5 64 | 65 | fixedActionResolution = 0 66 | 67 | [changes] 68 | hasChanges = false 69 | changesPath = changes/mid-wall.txt 70 | areDynamic = true 71 | 72 | [simulation] 73 | loadInitialPolicy = true 74 | savePolicy = false 75 | nSteps = 90 76 | nRuns = 1 77 | 78 | [ros] 79 | # Path to the V-REP scene file 80 | # vrepScenePath = vrep_scenes/tag.ttt 81 | -------------------------------------------------------------------------------- /problems/conttag/maps/map.txt: -------------------------------------------------------------------------------- 1 | #####...s...###### 2 | #####.......###### 3 | #####.......###### 4 | .................. 5 | .................. 6 | .................. 7 | .................. -------------------------------------------------------------------------------- /problems/conttag/maps/map_tag.txt: -------------------------------------------------------------------------------- 1 | #####...## 2 | #####...## 3 | #####...## 4 | .......... 5 | .......... -------------------------------------------------------------------------------- /problems/homecare/Makefile: -------------------------------------------------------------------------------- 1 | REDIRECT = homecare 2 | .PHONY: $(MAKECMDGOALS) call-upwards 3 | $(MAKECMDGOALS): call-upwards ; 4 | call-upwards: 5 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 6 | -------------------------------------------------------------------------------- /problems/homecare/changes/change.txt: -------------------------------------------------------------------------------- 1 | t 5 : 1 2 | Add W: (25, 0) (25, 0) 3 | t 60 : 1 4 | Add W: (25, 49) (25, 49) 5 | t 90 : 1 6 | Add W: (0, 25) (0, 25) 7 | t 120 : 1 8 | Add W: (49, 25) (49, 25) 9 | 10 | -------------------------------------------------------------------------------- /problems/homecare/default.cfg: -------------------------------------------------------------------------------- 1 | # General-purpose settings. 2 | color = false 3 | verbose = true 4 | 5 | [ABT] 6 | # Whether to keep track of states in an index data structure 7 | useStateIndex = false 8 | 9 | # The number of trajectories to simulate per time step (0 => wait for timeout) 10 | historiesPerStep = 10000 11 | 12 | # The maximum time to spend on each step, in milliseconds (0 => no time limit) 13 | stepTimeout = 1000 14 | 15 | # If this is set to "true", ABT will prune the tree after every step. 16 | pruneEveryStep = true 17 | 18 | # If this is set to "true", ABT will reset the tree instead of modifying it whe 19 | # changes occur. 20 | resetOnChanges = false 21 | 22 | # The minimum number of particles for the current belief state in a simulation. 23 | # Extra particles will be resampled via a particle filter if the particle count 24 | # for the *current* belief state drops below this number during simulation. 25 | minParticleCount = 5000 26 | 27 | # The maximum depth to search in the tree. 28 | maximumDepth = 150 29 | # True if the above horizon is relative to the initial belief, and false 30 | # if it's relative to the current belief. 31 | isAbsoluteHorizon = false 32 | 33 | searchHeuristic = default() 34 | searchStrategy = ucb(20.0) 35 | estimator = mean() 36 | 37 | [problem] 38 | discountFactor = 0.95 39 | pathMapFilename = maps/pathMap.txt 40 | typeMapFilename = maps/typeMap.txt 41 | moveCost = 100 42 | helpReward = 5500 43 | targetWStayProbability = 0.9 44 | targetStayProbability = 0.5 45 | moveAccuracy = 0.8 46 | regionSensorAccuracy = 0.9 47 | callProbability = 0.1 48 | continueCallProbability = 1 49 | 50 | [changes] 51 | hasChanges = false 52 | changesPath = changes/change.txt 53 | areDynamic = true 54 | 55 | [simulation] 56 | loadInitialPolicy = true 57 | savePolicy = false 58 | nSteps = 150 59 | nRuns = 1 60 | -------------------------------------------------------------------------------- /problems/homecare/maps/pathMap.txt: -------------------------------------------------------------------------------- 1 | 50 50 2 | dlllllllllllllllnlllllllllllllllllllnlllllllllllll 3 | d000000000000u11d0000000000000000u11d000000000000u 4 | d000000000000u11d0000000000000000u11d000000000000u 5 | d000000000000u11d0000000000000000u11d000000000000u 6 | d000000000000u11d0000000000000000u11d000000000000u 7 | d000000000000u11d0000000000000000u11d000000000000u 8 | d000000000000u11d0000000000000000u11d000000000000u 9 | d000000000000u11d0000000000000000u11d000000000000u 10 | d000000000000u11d0000000000000000u11d000000000000u 11 | d000000000000u11d0000000000000000u11d000000000000u 12 | d000000000000u11d0000000000000000u11d000000000000u 13 | d000000000000ulll0000000000000000ulll000000000000u 14 | d000000000000000000000000000000000000000000000000u 15 | d000000000000000000000000000000000000000000000000u 16 | d000000000000000000000000000000000000000000000000u 17 | mrrrrrrrrrrrrrd00000000000000000000rrrrrrrrrrrrrru 18 | d1111111111111d00000000000000000000u1111111111111u 19 | d1111111111111d00000000000000000000u1111111111111u 20 | dllllllllllllll00000000000000000000ulllllllllllllo 21 | d000000000000000000000000000000000000000000000000u 22 | d000000000000000000000000000000000000000000000000u 23 | d000000000000000000000000000000000000000000000000u 24 | d000000000000000000000000000000000000000000000000u 25 | d000000000000000000000000000000000000000000000000u 26 | d000000000000000000000000000000000000000000000000u 27 | d000000000000000000000000000000000000000000000000u 28 | d000000000000000000000000000000000000000000000000u 29 | d000000000000000000000000000000000000000000000000u 30 | d000000000000000000000000000000000000000000000000u 31 | d000000000000000000000000000000000000000000000000u 32 | d000000000000000000000000000000000000000000000000u 33 | mrrrrrrrrrrrrrd00000000000000000000rrrrrrrrrrrrrru 34 | d1111111111111d00000000000000000000u1111111111111u 35 | d1111111111111d00000000000000000000u1111111111111u 36 | dllllllllllllll00000000000000000000ulllllllllllllo 37 | d000000000000000000000000000000000000000000000000u 38 | d000000000000000000000000000000000000000000000000u 39 | d000000000000000000000000000000000000000000000000u 40 | d000000000000rrrd0000000000000000rrrd000000000000u 41 | d000000000000u11d0000000000000000u11d000000000000u 42 | d000000000000u11d0000000000000000u11d000000000000u 43 | d000000000000u11d0000000000000000u11d000000000000u 44 | d000000000000u11d0000000000000000u11d000000000000u 45 | d000000000000u11d0000000000000000u11d000000000000u 46 | d000000000000u11d0000000000000000u11d000000000000u 47 | d000000000000u11d0000000000000000u11d000000000000u 48 | d000000000000u11d0000000000000000u11d000000000000u 49 | d000000000000u11d0000000000000000u11d000000000000u 50 | d000000000000u11d0000000000000000u11d000000000000u 51 | rrrrrrrrrrrrrprrrrrrrrrrrrrrrrrrrprrrrrrrrrrrrrrru -------------------------------------------------------------------------------- /problems/homecare/maps/typeMap.txt: -------------------------------------------------------------------------------- 1 | 50 50 2 | woooooooooooooooooooooooooooooooooooooooooooooooow 3 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 4 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 5 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 6 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 7 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 8 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 9 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 10 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 11 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 12 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 13 | oooooooooooooottoooooooooooooooooottoooooooooooooo 14 | oooooooooooooooooooooooooooooooooooooooooooooooooo 15 | oooooooooooooooooooooooooooooooooooooooooooooooooo 16 | oooooooooooooooooooooooooooooooooooooooooooooooooo 17 | oooooooooooooooooooooooooooooooooooooooooooooooooo 18 | o1111111111111toooooooooooooooooooot1111111111111o 19 | o1111111111111toooooooooooooooooooot1111111111111o 20 | oooooooooooooooooooooooooooooooooooooooooooooooooo 21 | oooooooooooooooooooooooooooooooooooooooooooooooooo 22 | oooooooooooooooooooooooooooooooooooooooooooooooooo 23 | oooooooooooooooooooooooooooooooooooooooooooooooooo 24 | oooooooooooooooooooooooooooooooooooooooooooooooooo 25 | ooooooooooooooooooooooosssoooooooooooooooooooooooo 26 | ooooooooooooooooooooooosssoooooooooooooooooooooooo 27 | ooooooooooooooooooooooosssoooooooooooooooooooooooo 28 | oooooooooooooooooooooooooooooooooooooooooooooooooo 29 | oooooooooooooooooooooooooooooooooooooooooooooooooo 30 | oooooooooooooooooooooooooooooooooooooooooooooooooo 31 | oooooooooooooooooooooooooooooooooooooooooooooooooo 32 | oooooooooooooooooooooooooooooooooooooooooooooooooo 33 | oooooooooooooooooooooooooooooooooooooooooooooooooo 34 | o1111111111111toooooooooooooooooooot1111111111111o 35 | o1111111111111toooooooooooooooooooot1111111111111o 36 | oooooooooooooooooooooooooooooooooooooooooooooooooo 37 | oooooooooooooooooooooooooooooooooooooooooooooooooo 38 | oooooooooooooooooooooooooooooooooooooooooooooooooo 39 | oooooooooooooooooooooooooooooooooooooooooooooooooo 40 | oooooooooooooottoooooooooooooooooottoooooooooooooo 41 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 42 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 43 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 44 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 45 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 46 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 47 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 48 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 49 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 50 | oooooooooooooo11oooooooooooooooooo11oooooooooooooo 51 | woooooooooooooooooooooooooooooooooooooooooooooooow -------------------------------------------------------------------------------- /problems/pushbox/Makefile: -------------------------------------------------------------------------------- 1 | REDIRECT = pushbox 2 | .PHONY: $(MAKECMDGOALS) call-upwards 3 | $(MAKECMDGOALS): call-upwards ; 4 | call-upwards: 5 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 6 | -------------------------------------------------------------------------------- /problems/pushbox/default.cfg: -------------------------------------------------------------------------------- 1 | # seed = 1 2 | 3 | # General-purpose settings. 4 | color = false 5 | verbose = true 6 | 7 | [ABT] 8 | # Whether to keep track of states in an index data structure 9 | useStateIndex = false 10 | 11 | # The number of trajectories to simulate per time step (0 => wait for timeout) 12 | historiesPerStep = 0 13 | 14 | # The maximum time to spend on each step, in milliseconds (0 => no time limit) 15 | stepTimeout = 3000 16 | #solveTimeout = 1000 17 | 18 | # If this is set to "true", ABT will prune the tree after every step. 19 | pruneEveryStep = true 20 | 21 | # If this is set to "true", ABT will reset the tree instead of modifying it when 22 | # changes occur. 23 | resetOnChanges = false 24 | 25 | # The minimum number of particles for the current belief state in a simulation. 26 | # Extra particles will be resampled via a particle filter if the particle count 27 | # for the *current* belief state drops below this number during simulation. 28 | minParticleCount = 5000 29 | 30 | #maxParticleCreationAttempts = 100000 31 | 32 | # The maximum depth to search in the tree, relative to the current belief. 33 | maximumDepth = 3 34 | # True if the above horizon is relative to the initial belief, and false 35 | # if it's relative to the current belief. 36 | isAbsoluteHorizon = false 37 | 38 | searchHeuristic = default() 39 | 40 | 41 | searchStrategy = gps(searchType=compass, dimensions=2, explorationCoefficient=100000, newSearchPointCoefficient=5, minimumVisitsBeforeChildCreation=1, minimumChildCreationDistance=0.2, initialCompassRadiusRatio=0.3333) 42 | recommendationStrategy = gpsmax(searchType=compass, dimensions=2, recommendationMode=robust) 43 | 44 | estimator = mean() 45 | 46 | [problem] 47 | discountFactor = 0.95 48 | 49 | mapPath = maps/map_free_paper.txt 50 | moveCost = 10 51 | goalReward = 1000 52 | collisionPenalty = 1000 53 | 54 | sizeX = 10 55 | sizeY = 10 56 | 57 | 58 | # startPositionX = 1 59 | # startPositionY = 3 60 | 61 | # goalPositionX = 8 62 | # goalPositionY = 6 63 | # goalRadius = 0.5 64 | 65 | moveUncertainty = 0.0 66 | actionUncertainty = 0.0 67 | boxPositionMoveUncertainty = 0.1 68 | boxSpeedUncertainty = 0.1 69 | initialBoxPositionUncertainty = 2 70 | 71 | # this is measured in degrees. So make it large to have an effect. 72 | #observationUncertainty = 20 73 | observationUncertainty = 0 74 | 75 | # the number of sectors the bearing measurement is split into. e.g. 4 means 90 degree resolution 76 | observationBuckets = 12 77 | 78 | fixedActionResolution = 0 79 | 80 | 81 | [changes] 82 | hasChanges = false 83 | changesPath = changes/mid-wall.txt 84 | areDynamic = true 85 | 86 | [simulation] 87 | loadInitialPolicy = true 88 | savePolicy = false 89 | nSteps = 50 90 | nRuns = 1 91 | 92 | [ros] 93 | # Path to the V-REP scene file 94 | # vrepScenePath = vrep_scenes/tag.ttt 95 | -------------------------------------------------------------------------------- /problems/pushbox/maps/map_free_paper.txt: -------------------------------------------------------------------------------- 1 | ############ 2 | #.......#### 3 | #....s..g### 4 | #..........# 5 | #..........# 6 | #..........# 7 | #....b.....# 8 | #..........# 9 | #..........# 10 | #..........# 11 | #..........# 12 | ############ -------------------------------------------------------------------------------- /problems/rocksample/Makefile: -------------------------------------------------------------------------------- 1 | REDIRECT = rocksample 2 | .PHONY: $(MAKECMDGOALS) call-upwards 3 | $(MAKECMDGOALS): call-upwards ; 4 | call-upwards: 5 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 6 | -------------------------------------------------------------------------------- /problems/rocksample/changes/changes-11-11.txt: -------------------------------------------------------------------------------- 1 | t 5 : 1 2 | Add Obstacles: (4, 2) (4, 6) 3 | t 8 : 2 4 | Add Obstacles: (2, 11) (5, 11) 5 | Add Obstacles: (5, 10) (5, 10) 6 | t 15 : 1 7 | Add Obstacles: (4, 1) (4, 3) 8 | t 18 : 1 9 | Remove Obstacles: (2, 11) (3, 11) 10 | t 23 : 2 11 | Add Obstacles: (8, 5) (8, 7) 12 | Add Obstacles: (9, 0) (9, 3) 13 | t 27 : 2 14 | Remove Obstacles: (5, 10) (5, 10) 15 | Remove Obstacles: (8, 5) (8, 7) 16 | -------------------------------------------------------------------------------- /problems/rocksample/changes/changes-7-8.txt: -------------------------------------------------------------------------------- 1 | t 3 : 1 2 | Add Obstacles: (0, 4) (0, 4) 3 | t 5 : 1 4 | Add Obstacles: (1, 1) (1, 3) 5 | t 9 : 1 6 | Add Obstacles: (4, 1) (4, 3) 7 | t 12 : 1 8 | Add Obstacles: (2, 6) (2, 6) 9 | t 18 : 2 10 | Remove Obstacles: (0, 4) (0, 4) 11 | Remove Obstacles: (2, 6) (2, 6) 12 | -------------------------------------------------------------------------------- /problems/rocksample/changes/changes.txt: -------------------------------------------------------------------------------- 1 | t 5 : 1 2 | Add Obstacles: (4, 1) (4, 4) 3 | t 25 : 2 4 | Remove Obstacles: (0, 4) (0, 4) 5 | Remove Obstacles: (2, 6) (2, 6) 6 | -------------------------------------------------------------------------------- /problems/rocksample/changes/changes2.txt: -------------------------------------------------------------------------------- 1 | t 5 : 1 2 | Add Obstacles: (4, 1) (4, 4) 3 | -------------------------------------------------------------------------------- /problems/rocksample/default-11-11.cfg: -------------------------------------------------------------------------------- 1 | # General-purpose settings. 2 | color = false 3 | verbose = true 4 | 5 | [ABT] 6 | # Whether to keep track of states in an index data structure 7 | useStateIndex = false 8 | 9 | # The number of trajectories to simulate per time step (0 => wait for timeout) 10 | historiesPerStep = 0 11 | 12 | # The maximum time to spend on each step, in milliseconds (0 => no time limit) 13 | stepTimeout = 1000 14 | 15 | # If this is set to "true", ABT will prune the tree after every step. 16 | pruneEveryStep = true 17 | 18 | # If this is set to "true", ABT will reset the tree instead of modifying it when 19 | # changes occur. 20 | resetOnChanges = false 21 | 22 | # The minimum number of particles for the current belief state in a simulation. 23 | # Extra particles will be resampled via a particle filter if the particle count 24 | # for the *current* belief state drops below this number during simulation. 25 | minParticleCount = 1000 26 | 27 | # The maximum depth to search in the tree, relative to the current belief. 28 | maximumDepth = 90 29 | # True if the above horizon is relative to the initial belief, and false 30 | # if it's relative to the current belief. 31 | isAbsoluteHorizon = false 32 | 33 | searchHeuristic = exactMdp() 34 | searchStrategy = ucb(5.0) 35 | estimator = mean() 36 | 37 | [problem] 38 | discountFactor = 0.95 39 | 40 | mapPath = maps/map-11-11.txt 41 | goodRockReward = 10 42 | badRockPenalty = 10 43 | exitReward = 10 44 | illegalMovePenalty = 100 45 | halfEfficiencyDistance = 20 46 | 47 | [changes] 48 | hasChanges = false 49 | changesPath = changes/changes-11-11.txt 50 | areDynamic = true 51 | 52 | [heuristics] 53 | # history-based heuristic type: 54 | # none/legal/preferred 55 | type = legal 56 | # Restricted search: searches only the given category 57 | # all / legal /preferred 58 | search = legal 59 | # Restricted rollout : randomly chooses from the given category 60 | # all / legal / preferred 61 | rollout = legal 62 | 63 | # Initialises preferred actions to have biased initial q-values. 64 | usePreferredInit = false 65 | preferredQValue = 0.0 66 | preferredVisitCount = 0 67 | 68 | [simulation] 69 | loadInitialPolicy = true 70 | savePolicy = false 71 | nSteps = 150 72 | nRuns = 1 73 | -------------------------------------------------------------------------------- /problems/rocksample/default.cfg: -------------------------------------------------------------------------------- 1 | # General-purpose settings. 2 | color = false 3 | verbose = true 4 | 5 | [ABT] 6 | # Whether to keep track of states in an index data structure 7 | useStateIndex = false 8 | 9 | # The number of trajectories to simulate per time step (0 => wait for timeout) 10 | historiesPerStep = 0 11 | 12 | # The maximum time to spend on each step, in milliseconds (0 => no time limit) 13 | stepTimeout = 1000 14 | 15 | # If this is set to "true", ABT will prune the tree after every step. 16 | pruneEveryStep = false 17 | 18 | # If this is set to "true", ABT will reset the tree instead of modifying it when 19 | # changes occur. 20 | resetOnChanges = false 21 | 22 | # The minimum number of particles for the current belief state in a simulation. 23 | # Extra particles will be resampled via a particle filter if the particle count 24 | # for the *current* belief state drops below this number during simulation. 25 | minParticleCount = 1000 26 | 27 | # The maximum depth to search in the tree, relative to the current belief. 28 | maximumDepth = 90 29 | # True if the above horizon is relative to the initial belief, and false 30 | # if it's relative to the current belief. 31 | isAbsoluteHorizon = false 32 | 33 | searchHeuristic = exactMdp() 34 | searchStrategy = ucb(5.0) 35 | estimator = mean() 36 | 37 | [problem] 38 | discountFactor = 0.95 39 | 40 | mapPath = maps/map-7-8.txt 41 | goodRockReward = 10 42 | badRockPenalty = 10 43 | exitReward = 10 44 | illegalMovePenalty = 100 45 | halfEfficiencyDistance = 20 46 | 47 | [changes] 48 | hasChanges = false 49 | changesPath = changes/changes-7-8.txt 50 | areDynamic = true 51 | 52 | [heuristics] 53 | # history-based heuristic type: 54 | # none/legal/preferred 55 | type = legal 56 | # Restricted search: searches only the given category 57 | # all / legal /preferred 58 | search = legal 59 | # Restricted rollout : randomly chooses from the given category 60 | # all / legal / preferred 61 | rollout = legal 62 | 63 | # Initialises preferred actions to have biased initial q-values. 64 | usePreferredInit = false 65 | preferredQValue = 0.0 66 | preferredVisitCount = 0 67 | 68 | [simulation] 69 | loadInitialPolicy = true 70 | savePolicy = false 71 | nSteps = 150 72 | nRuns = 1 73 | -------------------------------------------------------------------------------- /problems/rocksample/maps/map-11-11.txt: -------------------------------------------------------------------------------- 1 | 11 12 2 | ...........G 3 | .........o.G 4 | .o.o.o.....G 5 | o..........G 6 | ...........G 7 | S..........G 8 | ..o........G 9 | o..oo....o.G 10 | ...........G 11 | ......o....G 12 | ...........G 13 | -------------------------------------------------------------------------------- /problems/rocksample/maps/map-7-1.txt: -------------------------------------------------------------------------------- 1 | 7 8 2 | .......G 3 | .......G 4 | ...o...G 5 | S......G 6 | .......G 7 | .......G 8 | .......G 9 | -------------------------------------------------------------------------------- /problems/rocksample/maps/map-7-2.txt: -------------------------------------------------------------------------------- 1 | 7 8 2 | .o.....G 3 | .......G 4 | .......G 5 | S.....oG 6 | .......G 7 | .......G 8 | .......G 9 | -------------------------------------------------------------------------------- /problems/rocksample/maps/map-7-3.txt: -------------------------------------------------------------------------------- 1 | 7 8 2 | .o.....G 3 | .......G 4 | ...o...G 5 | S......G 6 | .......G 7 | .......G 8 | ..o....G 9 | -------------------------------------------------------------------------------- /problems/rocksample/maps/map-7-8-obstacles.txt: -------------------------------------------------------------------------------- 1 | 7 8 2 | .o..X..G 3 | XXX.Xo.G 4 | ..oo.XXG 5 | S....XoG 6 | .....X.G 7 | o..o.X.G 8 | ..o....G 9 | -------------------------------------------------------------------------------- /problems/rocksample/maps/map-7-8.txt: -------------------------------------------------------------------------------- 1 | 7 8 2 | .o.....G 3 | .....o.G 4 | ..oo...G 5 | S.....oG 6 | .......G 7 | o..o...G 8 | ..o....G 9 | -------------------------------------------------------------------------------- /problems/tag/Makefile: -------------------------------------------------------------------------------- 1 | REDIRECT = tag 2 | .PHONY: $(MAKECMDGOALS) call-upwards 3 | $(MAKECMDGOALS): call-upwards ; 4 | call-upwards: 5 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 6 | -------------------------------------------------------------------------------- /problems/tag/changes/mid-wall.txt: -------------------------------------------------------------------------------- 1 | t 5 : 1 2 | Add Obstacles: (3, 6) (4, 6) 3 | t 10 : 4 4 | Remove Obstacles: (0, 0) (2, 0) 5 | Remove Obstacles: (0, 0) (0, 4) 6 | Remove Obstacles: (0, 8) (0, 9) 7 | Remove Obstacles: (0, 9) (2, 9) 8 | -------------------------------------------------------------------------------- /problems/tag/changes/tag-changes.txt: -------------------------------------------------------------------------------- 1 | t 3 : 1 2 | Add Obstacles: (3, 6) (4, 6) 3 | t 5 : 1 4 | Remove Obstacles: (0, 0) (2, 0) 5 | t 8 : 1 6 | Remove Obstacles: (0, 0) (0, 4) 7 | t 10 : 2 8 | Remove Obstacles: (0, 8) (0, 9) 9 | Remove Obstacles: (0, 9) (2, 9) 10 | -------------------------------------------------------------------------------- /problems/tag/default.cfg: -------------------------------------------------------------------------------- 1 | # General-purpose settings. 2 | color = false 3 | verbose = true 4 | 5 | [ABT] 6 | # Whether to keep track of states in an index data structure 7 | useStateIndex = false 8 | 9 | # The number of trajectories to simulate per time step (0 => wait for timeout) 10 | historiesPerStep = 0 11 | 12 | # The maximum time to spend on each step, in milliseconds (0 => no time limit) 13 | stepTimeout = 1000 14 | 15 | # If this is set to "true", ABT will prune the tree after every step. 16 | pruneEveryStep = false 17 | 18 | # If this is set to "true", ABT will reset the tree instead of modifying it when 19 | # changes occur. 20 | resetOnChanges = false 21 | 22 | # The minimum number of particles for the current belief state in a simulation. 23 | # Extra particles will be resampled via a particle filter if the particle count 24 | # for the *current* belief state drops below this number during simulation. 25 | minParticleCount = 5000 26 | 27 | # The maximum depth to search in the tree, relative to the current belief. 28 | maximumDepth = 90 29 | # True if the above horizon is relative to the initial belief, and false 30 | # if it's relative to the current belief. 31 | isAbsoluteHorizon = true 32 | 33 | searchHeuristic = default() 34 | searchStrategy = ucb(10.0) 35 | estimator = mean() 36 | 37 | [problem] 38 | discountFactor = 0.95 39 | 40 | mapPath = maps/map.txt 41 | moveCost = 1 42 | tagReward = 10 43 | failedTagPenalty = 10 44 | opponentStayProbability = 0.2 45 | 46 | [changes] 47 | hasChanges = false 48 | changesPath = changes/mid-wall.txt 49 | areDynamic = true 50 | 51 | [simulation] 52 | loadInitialPolicy = true 53 | savePolicy = false 54 | nSteps = 90 55 | nRuns = 1 56 | 57 | [ros] 58 | # Path to the V-REP scene file 59 | vrepScenePath = vrep_scenes/tag.ttt 60 | -------------------------------------------------------------------------------- /problems/tag/maps/map.txt: -------------------------------------------------------------------------------- 1 | 5 10 2 | XXXXX...XX 3 | XXXXX...XX 4 | XXXXX...XX 5 | .......... 6 | .......... 7 | -------------------------------------------------------------------------------- /problems/tag/vrep_scenes/tag.ttt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdl-algorithm/tapir/b613c1c287853b2165ea1392a133496f338d8170/problems/tag/vrep_scenes/tag.ttt -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = global 2 | CHILD_DIRS := options solver problems 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/template.mk 7 | include .make/build.mk 8 | 9 | else 10 | REDIRECT=$(MODULE_NAME) 11 | .PHONY: $(MAKECMDGOALS) call-upwards 12 | $(MAKECMDGOALS): call-upwards ; 13 | call-upwards: 14 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 15 | endif 16 | -------------------------------------------------------------------------------- /src/check_headers.sh: -------------------------------------------------------------------------------- 1 | files=$(find -name "*pp" -print) 2 | need_doc= 3 | for f in $files 4 | do 5 | doc="$(grep -m 1 "^/\*\*" $f)" 6 | if [[ ${doc:0:10} != '/** @file ' ]] 7 | then 8 | need_doc+="$f " 9 | else 10 | name=${doc:10} 11 | if [[ $f == ${f%%$name} ]] 12 | then 13 | echo "WRONG NAME FOR $f: $name" 14 | fi 15 | fi 16 | done 17 | echo "MISSING DOC COMMENTS:" 18 | for f in $need_doc 19 | do 20 | echo $f 21 | done 22 | -------------------------------------------------------------------------------- /src/defs.hpp: -------------------------------------------------------------------------------- 1 | /** @file defs.hpp 2 | * 3 | * Some key definitions and macros for C++ programs. 4 | */ 5 | #ifndef DEFS_HPP_ 6 | #define DEFS_HPP_ 7 | 8 | /** A macro for quoting strings. */ 9 | #define QUOTE(str) #str 10 | /** A macro that quotes properly, by first expanding other macros, and then quoting that. */ 11 | #define EXPAND_AND_QUOTE(str) QUOTE(str) 12 | 13 | 14 | /** A macro used to delete all copy- and move-constructors and -assignment operators */ 15 | #define _NO_COPY_OR_MOVE(ClassName) \ 16 | ClassName(ClassName const &) = delete; \ 17 | ClassName(ClassName &&) = delete; \ 18 | ClassName &operator=(ClassName const &) = delete; \ 19 | ClassName &operator=(ClassName &&) = delete 20 | 21 | // If we're not using C++1y / C++14, we need to define our own std::make_unique 22 | #if __cplusplus <= 201103L 23 | /** We use an inclusion guard to make sure this definition is only included once. */ 24 | #ifndef __STD__MAKE__UNIQUE___ 25 | #define __STD__MAKE__UNIQUE___ 26 | namespace std { 27 | /** SFINAE struct for single objects. */ 28 | template struct _Unique_if { 29 | /** Return type - a single object wrapped in a unique_ptr. */ 30 | typedef unique_ptr _Single_object; 31 | }; 32 | 33 | /** SFINAE struct for arrays with unknown bounds. */ 34 | template struct _Unique_if { 35 | /** Return type - an array wrapped in a unique_ptr. */ 36 | typedef unique_ptr _Unknown_bound; 37 | }; 38 | 39 | /** SFINAE struct for arrays with known bounds. */ 40 | template struct _Unique_if { 41 | /** No return type, since make_unique is disallowed for arrays with known bounds. */ 42 | typedef void _Known_bound; 43 | }; 44 | 45 | /** The standard single-object make_unique. */ 46 | template 47 | typename _Unique_if::_Single_object 48 | make_unique(Args&&... args) { 49 | return unique_ptr(new T(std::forward(args)...)); 50 | } 51 | 52 | /** Construction of arrays with unknown bound. */ 53 | template 54 | typename _Unique_if::_Unknown_bound 55 | make_unique(size_t n) { 56 | typedef typename remove_extent::type U; 57 | return unique_ptr(new U[n]()); 58 | } 59 | 60 | /** Construction of arrays with a known bound is disallowed. */ 61 | template 62 | typename _Unique_if::_Known_bound 63 | make_unique(Args&&...) = delete; 64 | } 65 | #endif 66 | #endif 67 | 68 | #endif /* DEFS_HPP_ */ 69 | -------------------------------------------------------------------------------- /src/global.cpp: -------------------------------------------------------------------------------- 1 | /** @file global.cpp 2 | * 3 | * Implementation for show_message() - a great place for breakpoints! 4 | */ 5 | #include "global.hpp" 6 | 7 | #include 8 | #include 9 | 10 | #include "solver/abstract-problem/Point.hpp" 11 | 12 | namespace tapir { 13 | std::string get_current_directory() { 14 | char *buffer = getcwd(nullptr, 0); 15 | if (buffer == nullptr) { 16 | debug::show_message("ERROR: Failed to get current path."); 17 | std::exit(4); 18 | } 19 | std::string dir(buffer); 20 | free(buffer); 21 | return dir; 22 | } 23 | 24 | void change_directory(std::string &dir) { 25 | if (chdir(dir.c_str())) { 26 | std::ostringstream oss; 27 | oss << "ERROR: Failed to change path to " << dir; 28 | debug::show_message(oss.str()); 29 | std::exit(3); 30 | } 31 | } 32 | } /* namespace tapir */ 33 | 34 | 35 | namespace debug { 36 | void show_message(std::string message, bool print, bool bp_branch) { 37 | if (print) { 38 | std::cerr << message << std::endl; 39 | } 40 | if (bp_branch) { 41 | std::cerr << ""; 42 | } 43 | } 44 | 45 | /** Instantiation of the to_string template for easier printing of points in GDB. */ 46 | template std::string to_string(solver::Point &); 47 | } /* namespace debug */ 48 | -------------------------------------------------------------------------------- /src/options/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = options 2 | CHILD_DIRS := inih 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/template.mk 7 | include .make/build.mk 8 | 9 | else 10 | REDIRECT=$(MODULE_NAME) 11 | .PHONY: $(MAKECMDGOALS) call-upwards 12 | $(MAKECMDGOALS): call-upwards ; 13 | call-upwards: 14 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 15 | endif 16 | -------------------------------------------------------------------------------- /src/options/inih/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | The "inih" library is distributed under the New BSD license: 3 | 4 | Copyright (c) 2009, Brush Technology 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 are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of Brush Technology nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY BRUSH TECHNOLOGY ''AS IS'' AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL BRUSH TECHNOLOGY BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /src/options/inih/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = inih 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/options/inih/README.txt: -------------------------------------------------------------------------------- 1 | 2 | inih is a simple .INI file parser written in C, released under the New BSD 3 | license (see LICENSE.txt). Go to the project home page for more info: 4 | 5 | http://code.google.com/p/inih/ 6 | -------------------------------------------------------------------------------- /src/options/inih/ini.h: -------------------------------------------------------------------------------- 1 | /* inih -- simple .INI file parser 2 | 3 | inih is released under the New BSD license (see LICENSE.txt). Go to the project 4 | home page for more info: 5 | 6 | http://code.google.com/p/inih/ 7 | 8 | */ 9 | 10 | #ifndef __INI_H__ 11 | #define __INI_H__ 12 | 13 | /* Make this header file easier to include in C++ code */ 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include 19 | 20 | /* Parse given INI-style file. May have [section]s, name=value pairs 21 | (whitespace stripped), and comments starting with ';' (semicolon). Section 22 | is "" if name=value pair parsed before any section heading. name:value 23 | pairs are also supported as a concession to Python's ConfigParser. 24 | 25 | For each name=value pair parsed, call handler function with given user 26 | pointer as well as section, name, and value (data only valid for duration 27 | of handler call). Handler should return nonzero on success, zero on error. 28 | 29 | Returns 0 on success, line number of first error on parse error (doesn't 30 | stop on first error), -1 on file open error, or -2 on memory allocation 31 | error (only when INI_USE_STACK is zero). 32 | */ 33 | int ini_parse(const char* filename, 34 | int (*handler)(void* user, const char* section, 35 | const char* name, const char* value), 36 | void* user); 37 | 38 | /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't 39 | close the file when it's finished -- the caller must do that. */ 40 | int ini_parse_file(FILE* file, 41 | int (*handler)(void* user, const char* section, 42 | const char* name, const char* value), 43 | void* user); 44 | 45 | /* Nonzero to allow multi-line value parsing, in the style of Python's 46 | ConfigParser. If allowed, ini_parse() will call the handler with the same 47 | name for each subsequent line parsed. */ 48 | #ifndef INI_ALLOW_MULTILINE 49 | #define INI_ALLOW_MULTILINE 1 50 | #endif 51 | 52 | /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of 53 | the file. See http://code.google.com/p/inih/issues/detail?id=21 */ 54 | #ifndef INI_ALLOW_BOM 55 | #define INI_ALLOW_BOM 1 56 | #endif 57 | 58 | /* Nonzero to use stack, zero to use heap (malloc/free). */ 59 | #ifndef INI_USE_STACK 60 | #define INI_USE_STACK 1 61 | #endif 62 | 63 | /* Stop parsing on first error (default is to keep parsing). */ 64 | #ifndef INI_STOP_ON_FIRST_ERROR 65 | #define INI_STOP_ON_FIRST_ERROR 0 66 | #endif 67 | 68 | /* Maximum line length for any line in INI file. */ 69 | #ifndef INI_MAX_LINE 70 | #define INI_MAX_LINE 2000 71 | #endif 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* __INI_H__ */ 78 | -------------------------------------------------------------------------------- /src/options/tclap/AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | original author: Michael E. Smoot 3 | invaluable contributions: Daniel Aarno 4 | more contributions: Erik Zeek 5 | more contributions: Fabien Carmagnac (Tinbergen-AM) 6 | outstanding editing: Carol Smoot 7 | -------------------------------------------------------------------------------- /src/options/tclap/COPYING: -------------------------------------------------------------------------------- 1 | 2 | 3 | Copyright (c) 2003 Michael E. Smoot 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/options/tclap/CmdLineOutput.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: CmdLineOutput.h 6 | * 7 | * Copyright (c) 2004, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_CMDLINEOUTPUT_H 24 | #define TCLAP_CMDLINEOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace TCLAP { 34 | 35 | class CmdLineInterface; 36 | class ArgException; 37 | 38 | /** 39 | * The interface that any output object must implement. 40 | */ 41 | class CmdLineOutput 42 | { 43 | 44 | public: 45 | 46 | /** 47 | * Virtual destructor. 48 | */ 49 | virtual ~CmdLineOutput() {} 50 | 51 | /** 52 | * Generates some sort of output for the USAGE. 53 | * \param c - The CmdLine object the output is generated for. 54 | */ 55 | virtual void usage(CmdLineInterface& c)=0; 56 | 57 | /** 58 | * Generates some sort of output for the version. 59 | * \param c - The CmdLine object the output is generated for. 60 | */ 61 | virtual void version(CmdLineInterface& c)=0; 62 | 63 | /** 64 | * Generates some sort of output for a failure. 65 | * \param c - The CmdLine object the output is generated for. 66 | * \param e - The ArgException that caused the failure. 67 | */ 68 | virtual void failure( CmdLineInterface& c, 69 | ArgException& e )=0; 70 | 71 | }; 72 | 73 | } //namespace TCLAP 74 | #endif 75 | -------------------------------------------------------------------------------- /src/options/tclap/Constraint.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Constraint.h 5 | * 6 | * Copyright (c) 2005, Michael E. Smoot 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_CONSTRAINT_H 23 | #define TCLAP_CONSTRAINT_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * The interface that defines the interaction between the Arg and Constraint. 36 | */ 37 | template 38 | class Constraint 39 | { 40 | 41 | public: 42 | /** 43 | * Returns a description of the Constraint. 44 | */ 45 | virtual std::string description() const =0; 46 | 47 | /** 48 | * Returns the short ID for the Constraint. 49 | */ 50 | virtual std::string shortID() const =0; 51 | 52 | /** 53 | * The method used to verify that the value parsed from the command 54 | * line meets the constraint. 55 | * \param value - The value that will be checked. 56 | */ 57 | virtual bool check(const T& value) const =0; 58 | 59 | /** 60 | * Destructor. 61 | * Silences warnings about Constraint being a base class with virtual 62 | * functions but without a virtual destructor. 63 | */ 64 | virtual ~Constraint() { ; } 65 | }; 66 | 67 | } //namespace TCLAP 68 | #endif 69 | -------------------------------------------------------------------------------- /src/options/tclap/HelpVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: HelpVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_HELP_VISITOR_H 23 | #define TCLAP_HELP_VISITOR_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Visitor object that calls the usage method of the given CmdLineOutput 33 | * object for the specified CmdLine object. 34 | */ 35 | class HelpVisitor: public Visitor 36 | { 37 | private: 38 | /** 39 | * Prevent accidental copying. 40 | */ 41 | HelpVisitor(const HelpVisitor& rhs); 42 | HelpVisitor& operator=(const HelpVisitor& rhs); 43 | 44 | protected: 45 | 46 | /** 47 | * The CmdLine the output will be generated for. 48 | */ 49 | CmdLineInterface* _cmd; 50 | 51 | /** 52 | * The output object. 53 | */ 54 | CmdLineOutput** _out; 55 | 56 | public: 57 | 58 | /** 59 | * Constructor. 60 | * \param cmd - The CmdLine the output will be generated for. 61 | * \param out - The type of output. 62 | */ 63 | HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) 64 | : Visitor(), _cmd( cmd ), _out( out ) { } 65 | 66 | /** 67 | * Calls the usage method of the CmdLineOutput for the 68 | * specified CmdLine. 69 | */ 70 | void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } 71 | 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/options/tclap/IgnoreRestVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: IgnoreRestVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_IGNORE_REST_VISITOR_H 24 | #define TCLAP_IGNORE_REST_VISITOR_H 25 | 26 | #include 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Vistor that tells the CmdLine to begin ignoring arguments after 33 | * this one is parsed. 34 | */ 35 | class IgnoreRestVisitor: public Visitor 36 | { 37 | public: 38 | 39 | /** 40 | * Constructor. 41 | */ 42 | IgnoreRestVisitor() : Visitor() {} 43 | 44 | /** 45 | * Sets Arg::_ignoreRest. 46 | */ 47 | void visit() { Arg::beginIgnoring(); } 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/options/tclap/OptionalUnlabeledTracker.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: OptionalUnlabeledTracker.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H 25 | #define TCLAP_OPTIONAL_UNLABELED_TRACKER_H 26 | 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | class OptionalUnlabeledTracker 32 | { 33 | 34 | public: 35 | 36 | static void check( bool req, const std::string& argName ); 37 | 38 | static void gotOptional() { alreadyOptionalRef() = true; } 39 | 40 | static bool& alreadyOptional() { return alreadyOptionalRef(); } 41 | 42 | private: 43 | 44 | static bool& alreadyOptionalRef() { static bool ct = false; return ct; } 45 | }; 46 | 47 | 48 | inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) 49 | { 50 | if ( OptionalUnlabeledTracker::alreadyOptional() ) 51 | throw( SpecificationException( 52 | "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", 53 | argName ) ); 54 | 55 | if ( !req ) 56 | OptionalUnlabeledTracker::gotOptional(); 57 | } 58 | 59 | 60 | } // namespace TCLAP 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/options/tclap/VersionVisitor.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: VersionVisitor.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_VERSION_VISITOR_H 25 | #define TCLAP_VERSION_VISITOR_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace TCLAP { 32 | 33 | /** 34 | * A Vistor that will call the version method of the given CmdLineOutput 35 | * for the specified CmdLine object and then exit. 36 | */ 37 | class VersionVisitor: public Visitor 38 | { 39 | private: 40 | /** 41 | * Prevent accidental copying 42 | */ 43 | VersionVisitor(const VersionVisitor& rhs); 44 | VersionVisitor& operator=(const VersionVisitor& rhs); 45 | 46 | protected: 47 | 48 | /** 49 | * The CmdLine of interest. 50 | */ 51 | CmdLineInterface* _cmd; 52 | 53 | /** 54 | * The output object. 55 | */ 56 | CmdLineOutput** _out; 57 | 58 | public: 59 | 60 | /** 61 | * Constructor. 62 | * \param cmd - The CmdLine the output is generated for. 63 | * \param out - The type of output. 64 | */ 65 | VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) 66 | : Visitor(), _cmd( cmd ), _out( out ) { } 67 | 68 | /** 69 | * Calls the version method of the output object using the 70 | * specified CmdLine. 71 | */ 72 | void visit() { 73 | (*_out)->version(*_cmd); 74 | throw ExitException(0); 75 | } 76 | 77 | }; 78 | 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/options/tclap/Visitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Visitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_VISITOR_H 24 | #define TCLAP_VISITOR_H 25 | 26 | namespace TCLAP { 27 | 28 | /** 29 | * A base class that defines the interface for visitors. 30 | */ 31 | class Visitor 32 | { 33 | public: 34 | 35 | /** 36 | * Constructor. Does nothing. 37 | */ 38 | Visitor() { } 39 | 40 | /** 41 | * Destructor. Does nothing. 42 | */ 43 | virtual ~Visitor() { } 44 | 45 | /** 46 | * Does nothing. Should be overridden by child. 47 | */ 48 | virtual void visit() { } 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/problems/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = problems 2 | CHILD_DIRS := shared rocksample tag homecare pushbox conttag 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | problems: $(CHILD_DIRS) 7 | 8 | include .make/template.mk 9 | 10 | else 11 | REDIRECT=$(MODULE_NAME) 12 | .PHONY: $(MAKECMDGOALS) call-upwards 13 | $(MAKECMDGOALS): call-upwards ; 14 | call-upwards: 15 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 16 | endif 17 | -------------------------------------------------------------------------------- /src/problems/conttag/ContTagObservation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // for size_t 4 | 5 | #include // for ostream 6 | #include // for vector 7 | 8 | #include "global.hpp" // for RandomGenerator 9 | 10 | #include "solver/abstract-problem/DiscretizedPoint.hpp" 11 | #include "solver/abstract-problem/Observation.hpp" 12 | 13 | #include "ContTagPosition.hpp" 14 | 15 | namespace conttag { 16 | class ContTagModel; 17 | 18 | /** A class representing an observation in the Tag POMDP. 19 | * 20 | * This includes an observation of the robot's own position, and a boolean flag representing 21 | * whether or not the robot sees the opponent (and hence is on the same grid square). 22 | */ 23 | class ContTagObservation final: public solver::Point { 24 | typedef ContTagObservation This; 25 | public: 26 | ContTagObservation(const bool theSeen): seen(theSeen) {}; 27 | 28 | virtual ~ContTagObservation() = default; 29 | _NO_COPY_OR_MOVE(ContTagObservation); 30 | 31 | std::unique_ptr copy() const override { 32 | return std::make_unique(seen); 33 | } 34 | 35 | double distanceTo(solver::Observation const &otherObs) const override { 36 | This const &other = static_cast(otherObs); 37 | return (seen == other.seen) ? 0 : 1; 38 | } 39 | 40 | bool equals(solver::Observation const &otherObs) const override { 41 | This const &other = static_cast(otherObs); 42 | return seen == other.seen; 43 | } 44 | 45 | std::size_t hash() const override { 46 | return std::hash()(seen); 47 | } 48 | 49 | void print(std::ostream &os) const override { 50 | os << (seen ? "seen" : "not_seen"); 51 | } 52 | 53 | /** Returns the position the robot has observed itself in. */ 54 | bool isSeen() const { return seen; } 55 | 56 | private: 57 | /** The position the robot sees itself in. */ 58 | bool seen; 59 | }; 60 | } /* namespace contnav */ 61 | -------------------------------------------------------------------------------- /src/problems/conttag/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = conttag 2 | TARGET_NAMES := solve simulate 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/problem-template.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/problems/conttag/simulate.cpp: -------------------------------------------------------------------------------- 1 | /** @file conttag/simulate.cpp 2 | * 3 | * Defines the main method for the "simulate" executable for the Tag POMDP, which runs online 4 | * simulations to test the performance of the solver. 5 | */ 6 | #include "problems/shared/simulate.hpp" 7 | 8 | #include "ContTagModel.hpp" // for TagModel 9 | #include "ContTagOptions.hpp" // for TagOptions 10 | 11 | /** The main method for the "simulate" executable for Tag. */ 12 | int main(int argc, char const *argv[]) { 13 | return simulate(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/conttag/solve.cpp: -------------------------------------------------------------------------------- 1 | /** @file conttag/solve.cpp 2 | * 3 | * Defines the main method for the "solve" executable for the Tag POMDP, which generates an 4 | * initial policy. 5 | */ 6 | #include "problems/shared/solve.hpp" 7 | 8 | #include "ContTagModel.hpp" // for TagModel 9 | #include "ContTagOptions.hpp" // for TagOptions 10 | 11 | /** The main method for the "solve" executable for Tag. */ 12 | int main(int argc, char const *argv[]) { 13 | return solve(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/homecare/HomecareAction.cpp: -------------------------------------------------------------------------------- 1 | /** @file HomecareAction.cpp 2 | * 3 | * Contains the implementations for the methods of the HomecareAction class. 4 | */ 5 | #include "HomecareAction.hpp" 6 | 7 | #include // for size_t 8 | 9 | #include // for copy 10 | #include // for ostream_iterator 11 | #include // for operator<<, ostream 12 | #include // for vector, operator==, _Bit_const_iterator, _Bit_iterator_base, hash, vector<>::const_iterator 13 | 14 | #include "global.hpp" 15 | 16 | #include "problems/shared/GridPosition.hpp" // for GridPosition, operator==, operator<< 17 | #include "solver/abstract-problem/State.hpp" // for State 18 | 19 | namespace homecare { 20 | HomecareAction::HomecareAction(ActionType actionType): 21 | actionType_(actionType) { 22 | } 23 | 24 | HomecareAction::HomecareAction(long code) : 25 | actionType_(static_cast(code)) { 26 | } 27 | 28 | std::unique_ptr HomecareAction::copy() const { 29 | return std::make_unique(actionType_); 30 | } 31 | 32 | double HomecareAction::distanceTo(solver::Action const &/*otherAction*/) const { 33 | return 0; 34 | } 35 | 36 | void HomecareAction::print(std::ostream &os) const { 37 | switch (actionType_) { 38 | case ActionType::NORTH: 39 | os << "NORTH"; 40 | break; 41 | case ActionType::NORTH_EAST: 42 | os << "NORTH_EAST"; 43 | break; 44 | case ActionType::EAST: 45 | os << "EAST"; 46 | break; 47 | case ActionType::SOUTH_EAST: 48 | os << "SOUTH_EAST"; 49 | break; 50 | case ActionType::SOUTH: 51 | os << "SOUTH"; 52 | break; 53 | case ActionType::SOUTH_WEST: 54 | os << "SOUTH_WEST"; 55 | break; 56 | case ActionType::WEST: 57 | os << "WEST"; 58 | break; 59 | case ActionType::NORTH_WEST: 60 | os << "NORTH_WEST"; 61 | break; 62 | case ActionType::WAIT: 63 | os << "WAIT"; 64 | break; 65 | default: 66 | os << "ERROR-" << static_cast(actionType_); 67 | break; 68 | } 69 | } 70 | 71 | long HomecareAction::getBinNumber() const { 72 | return static_cast(actionType_); 73 | } 74 | ActionType HomecareAction::getActionType() const { 75 | return actionType_; 76 | } 77 | } /* namespace homecare */ 78 | -------------------------------------------------------------------------------- /src/problems/homecare/HomecareAction.hpp: -------------------------------------------------------------------------------- 1 | /** @file HomecareAction.hpp 2 | * 3 | * Defines the HomecareAction class, which represents an action for the Homecare problem, and also the 4 | * ActionType enumeration, which enumerates the different types of actions for Homecare. 5 | */ 6 | #ifndef HOMECARE_ACTION_HPP_ 7 | #define HOMECARE_ACTION_HPP_ 8 | 9 | #include // for size_t 10 | 11 | #include // for ostream 12 | #include // for vector 13 | 14 | #include "solver/abstract-problem/Action.hpp" 15 | #include "solver/abstract-problem/DiscretizedPoint.hpp" // for DiscretizedPoint 16 | 17 | namespace homecare { 18 | 19 | /** An enumeration of all the available actions in the Homecare PODMP. */ 20 | enum class ActionType : long { 21 | NORTH = 0, 22 | NORTH_EAST = 1, 23 | EAST = 2, 24 | SOUTH_EAST = 3, 25 | SOUTH = 4, 26 | SOUTH_WEST = 5, 27 | WEST = 6, 28 | NORTH_WEST = 7, 29 | WAIT = 8, 30 | }; 31 | 32 | /** A class representing an action in the Homecare POMDP. 33 | * 34 | * This class also implements solver::DiscretizedPoint so that the solver can use a simplistic 35 | * enumerated action mapping approach (EnumeratedActionPool) to store the available actions from 36 | * each belief node. 37 | */ 38 | class HomecareAction : public solver::DiscretizedPoint { 39 | friend class HomecareTextSerializer; 40 | public: 41 | /** Constructs a new action from the given ActionType. */ 42 | HomecareAction(ActionType actionType); 43 | /** Constructs a new action from the given integer code. */ 44 | HomecareAction(long code); 45 | 46 | virtual ~HomecareAction() = default; 47 | _NO_COPY_OR_MOVE(HomecareAction); 48 | 49 | std::unique_ptr copy() const override; 50 | double distanceTo(solver::Action const &otherAction) const override; 51 | void print(std::ostream &os) const override; 52 | 53 | long getBinNumber() const override; 54 | /** Returns the ActionType of this action. */ 55 | ActionType getActionType() const; 56 | private: 57 | /** The ActionType for this action in the Homecare POMDP. */ 58 | ActionType actionType_; 59 | }; 60 | } /* namespace homecare */ 61 | 62 | #endif /* HOMECARE_ACTION_HPP_ */ 63 | -------------------------------------------------------------------------------- /src/problems/homecare/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = homecare 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | TARGET_NAMES := solve simulate 6 | include .make/problem-template.mk 7 | 8 | else 9 | ROOT = ../../.. 10 | include $(ROOT)/.make/redirect.mk 11 | endif 12 | -------------------------------------------------------------------------------- /src/problems/homecare/simulate.cpp: -------------------------------------------------------------------------------- 1 | /** @file homecare/simulate.cpp 2 | * 3 | * Defines the main method for the "simulate" executable for the Homecare POMDP, which runs online 4 | * simulations to test the performance of the solver. 5 | */ 6 | #include "problems/shared/simulate.hpp" 7 | 8 | #include "HomecareModel.hpp" // for HomecareModel 9 | #include "HomecareOptions.hpp" // for HomecareOptions 10 | 11 | /** The main method for the "simulate" executable for Homecare. */ 12 | int main(int argc, char const *argv[]) { 13 | return simulate(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/homecare/solve.cpp: -------------------------------------------------------------------------------- 1 | /** @file homecare/solve.cpp 2 | * 3 | * Defines the main method for the "solve" executable for the Homecare POMDP, which generates an 4 | * initial policy. 5 | */ 6 | #include "problems/shared/solve.hpp" 7 | 8 | #include "HomecareModel.hpp" // for HomecareModel 9 | #include "HomecareOptions.hpp" // for HomecareOptions 10 | 11 | /** The main method for the "solve" executable for Homecare. */ 12 | int main(int argc, char const *argv[]) { 13 | return solve(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/homecare/stest.cpp: -------------------------------------------------------------------------------- 1 | /** @file homecare/stest.cpp 2 | * 3 | * Defines the main method for the "stest" executable for the Homecare POMDP, which tests the 4 | * serialization methods for Homecare by deserializing and re-serializing a policy file. 5 | */ 6 | #include "problems/shared/stest.hpp" 7 | 8 | #include "HomecareModel.hpp" // for HomecareModel 9 | #include "HomecareOptions.hpp" // for HomecareOptions 10 | 11 | /** The main method for the "stest" executable for Homecare. */ 12 | int main(int argc, char const *argv[]) { 13 | return stest(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/pushbox/BearingObservation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // for size_t 4 | 5 | #include // for ostream 6 | #include // for vector 7 | 8 | #include "global.hpp" // for RandomGenerator 9 | 10 | #include "solver/abstract-problem/DiscretizedPoint.hpp" 11 | #include "solver/abstract-problem/Observation.hpp" 12 | 13 | 14 | namespace pushbox { 15 | 16 | 17 | /** A class representing an observation of a bearing sensor 18 | * 19 | */ 20 | class BearingObservationDiscrete: public solver::Point { 21 | typedef BearingObservationDiscrete This; 22 | public: 23 | 24 | BearingObservationDiscrete(int theBearing, int numberOfBuckets, const bool wasPushed): bearing(theBearing), buckets(numberOfBuckets), pushed(wasPushed) {}; 25 | 26 | _NO_COPY_OR_MOVE(BearingObservationDiscrete); 27 | 28 | virtual std::unique_ptr copy() const { 29 | return std::make_unique(bearing, buckets, pushed); 30 | } 31 | 32 | double distanceTo(solver::Observation const &otherObs) const override { 33 | This const &other = static_cast(otherObs); 34 | return ((bearing-other.bearing) % buckets) + ( pushed == other.pushed ? 0 : buckets); 35 | } 36 | 37 | bool equals(solver::Observation const &otherObs) const override { 38 | This const &other = static_cast(otherObs); 39 | return (bearing == other.bearing) && (pushed == other.pushed); 40 | } 41 | 42 | std::size_t hash() const override { 43 | return std::hash()(bearing); 44 | } 45 | 46 | void print(std::ostream &os) const override { 47 | os << bearing << (pushed ? " pushed" : " normal"); 48 | } 49 | 50 | /** Returns the bearing. */ 51 | int getBearing() const { return bearing; } 52 | 53 | /** Returns the number of buckets. */ 54 | int getBuckets() const { return buckets; } 55 | 56 | /** returns the pushed status */ 57 | bool getPushed() const { return pushed; } 58 | 59 | private: 60 | /** The position the robot sees itself in. */ 61 | int bearing; 62 | int buckets; 63 | bool pushed; 64 | }; 65 | 66 | 67 | 68 | } /* namespace pushbox */ 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/problems/pushbox/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = pushbox 2 | TARGET_NAMES := solve simulate 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/problem-template.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/problems/pushbox/TruncatedNormalDistribution.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | 6 | namespace pushbox { 7 | 8 | class TruncatedNormalDistribution { 9 | public: 10 | TruncatedNormalDistribution(const double theMean = 0.0, const double stddev = 1.0 ): mean(theMean), lowerBound(mean-stddev), upperBound(mean+stddev), zeroStdDev(stddev==0), normalDistribution(mean, stddev) {} 11 | template 12 | double operator()(URNG& g) { 13 | if (zeroStdDev) return lowerBound; 14 | while (true) { 15 | double result = normalDistribution(g); 16 | if ( (result >= lowerBound) && (result <= upperBound) ) { 17 | return result; 18 | } 19 | } 20 | } 21 | bool hasZeroStdDev() const { return zeroStdDev; } 22 | double getMean() const { return mean; } 23 | private: 24 | double mean; 25 | double lowerBound; 26 | double upperBound; 27 | bool zeroStdDev; 28 | std::normal_distribution normalDistribution; 29 | }; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/problems/pushbox/simulate.cpp: -------------------------------------------------------------------------------- 1 | /** @file pushbox/simulate.cpp 2 | * 3 | * Defines the main method for the "simulate" executable for the Tag POMDP, which runs online 4 | * simulations to test the performance of the solver. 5 | */ 6 | #include "problems/shared/simulate.hpp" 7 | 8 | #include "PushBoxModel.hpp" 9 | 10 | /** The main method for the "simulate" executable for Tag. */ 11 | int main(int argc, char const *argv[]) { 12 | return simulate(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /src/problems/pushbox/solve.cpp: -------------------------------------------------------------------------------- 1 | /** @file pushbox/solve.cpp 2 | * 3 | * Defines the main method for the "solve" executable for the Tag POMDP, which generates an 4 | * initial policy. 5 | */ 6 | #include "problems/shared/solve.hpp" 7 | 8 | #include "PushBoxModel.hpp" 9 | 10 | /** The main method for the "solve" executable for Tag. */ 11 | int main(int argc, char const *argv[]) { 12 | return solve(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /src/problems/rocksample/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = rocksample 2 | TARGET_NAMES := solve simulate 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/problem-template.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/problems/rocksample/PreferredActionsPool.cpp: -------------------------------------------------------------------------------- 1 | /** @file PreferredActionsPool.cpp 2 | * 3 | * Contains the implementation of the mapping classes for dealing with preferred actions in the 4 | * RockSample problem, a la POMCP's "smart" tree knowledge. 5 | */ 6 | #include "PreferredActionsPool.hpp" 7 | 8 | #include "RockSampleAction.hpp" 9 | #include "RockSampleModel.hpp" 10 | #include "smart_history.hpp" 11 | 12 | namespace rocksample { 13 | PreferredActionsPool::PreferredActionsPool(RockSampleModel *model) : 14 | EnumeratedActionPool(model, model->getAllActionsInOrder()), 15 | model_(model) { 16 | } 17 | 18 | std::vector PreferredActionsPool::createBinSequence(solver::BeliefNode *node) { 19 | solver::HistoricalData const *data = node->getHistoricalData(); 20 | RockSampleModel::RSActionCategory category = model_->getSearchActionCategory(); 21 | if (category == RockSampleModel::RSActionCategory::LEGAL) { 22 | std::vector bins = static_cast(data)->generateLegalActions(); 23 | std::shuffle(bins.begin(), bins.end(), *model_->getRandomGenerator()); 24 | return std::move(bins); 25 | } else if (category == RockSampleModel::RSActionCategory::PREFERRED) { 26 | std::vector bins = static_cast(data)->generatePreferredActions(); 27 | std::shuffle(bins.begin(), bins.end(), *model_->getRandomGenerator()); 28 | return std::move(bins); 29 | } else { 30 | return EnumeratedActionPool::createBinSequence(node); 31 | } 32 | } 33 | 34 | std::unique_ptr PreferredActionsPool::createActionMapping( 35 | solver::BeliefNode *node) { 36 | std::unique_ptr discMap = ( 37 | std::make_unique(node, this, createBinSequence(node))); 38 | 39 | PositionAndRockData const &data = 40 | static_cast(*node->getHistoricalData()); 41 | 42 | if (model_->usingPreferredInit()) { 43 | for (RockSampleAction const &action : data.generatePreferredActions()) { 44 | long visitCount = model_->getPreferredVisitCount(); 45 | discMap->getEntry(action)->update(visitCount, visitCount * model_->getPreferredQValue()); 46 | } 47 | } 48 | 49 | return std::move(discMap); 50 | } 51 | } /* namespace rocksample */ 52 | -------------------------------------------------------------------------------- /src/problems/rocksample/PreferredActionsPool.hpp: -------------------------------------------------------------------------------- 1 | /** @file PreferredActionsPool.hpp 2 | * 3 | * Contains an ActionPool implementation for preferred actions in RockSample. 4 | * 5 | * This is done by using the "smart" historical data stored within a PositionAndRockData instance 6 | * in order to determine which actions are preferred. This implementation follows the "smart" 7 | * data for RockSample used in POMCP, and allows for the same functionality. 8 | * 9 | * NOTE: Preferred actions are not currently updated in response to model changes! 10 | */ 11 | #ifndef ROCKSAMPLE_PREFERREDACTIONSPOOL_HPP_ 12 | #define ROCKSAMPLE_PREFERREDACTIONSPOOL_HPP_ 13 | 14 | #include 15 | #include 16 | 17 | #include "solver/mappings/actions/enumerated_actions.hpp" 18 | 19 | namespace solver { 20 | class ActionMapping; 21 | class BeliefNode; 22 | class HistoricalData; 23 | } 24 | 25 | namespace rocksample { 26 | class RockSampleModel; 27 | 28 | /** An implementation of ActionPool for preferred actions in RockSample. 29 | * 30 | * The basic functionality comes from EnumeratedActionPool; this class also customizes the 31 | * createBinSequence() method to control which actions are considered legal and what order they 32 | * are chosen in. 33 | * The createActionMapping() method is also modified - if preferred initialization is used, the 34 | * Q-values and visit counts for preferred actions can be initialized to non-zero values, 35 | * a la the "SMART rollout knowledge" in POMCP. 36 | */ 37 | class PreferredActionsPool: public solver::EnumeratedActionPool { 38 | public: 39 | /** Initializes a new PreferredActionsPool instance associated with the given model. */ 40 | PreferredActionsPool(RockSampleModel *model); 41 | virtual ~PreferredActionsPool() = default; 42 | _NO_COPY_OR_MOVE(PreferredActionsPool); 43 | 44 | virtual std::vector createBinSequence(solver::BeliefNode *node) override; 45 | 46 | virtual std::unique_ptr createActionMapping(solver::BeliefNode *node) 47 | override; 48 | 49 | private: 50 | /** The RockSampleModel instance this pool is assoicated with. */ 51 | RockSampleModel *model_; 52 | }; 53 | } /* namespace rocksample */ 54 | 55 | #endif /* ROCKSAMPLE_PREFERREDACTIONSPOOL_HPP_ */ 56 | -------------------------------------------------------------------------------- /src/problems/rocksample/RockSampleAction.cpp: -------------------------------------------------------------------------------- 1 | /** @file RockSampleAction.cpp 2 | * 3 | * Contains the implementations for the methods of the RockSampleAction class. 4 | */ 5 | #include "RockSampleAction.hpp" 6 | 7 | #include // for size_t 8 | #include 9 | 10 | #include // for copy 11 | #include // for ostream_iterator 12 | #include // for operator<<, ostream 13 | #include // for vector, operator==, _Bit_const_iterator, _Bit_iterator_base, hash, vector<>::const_iterator 14 | 15 | #include "global.hpp" 16 | #include "problems/shared/GridPosition.hpp" // for GridPosition, operator==, operator<< 17 | #include "solver/abstract-problem/State.hpp" // for State 18 | 19 | namespace rocksample { 20 | RockSampleAction::RockSampleAction(ActionType actionType, uint8_t rockNo) : 21 | actionType_(actionType), 22 | rockNo_(rockNo) { 23 | } 24 | 25 | RockSampleAction::RockSampleAction(long code) : 26 | actionType_(code <= 5 ? static_cast(code) : ActionType::CHECK), 27 | rockNo_(actionType_ == ActionType::CHECK ? code-5 : 0) { 28 | } 29 | 30 | std::unique_ptr RockSampleAction::copy() const { 31 | return std::make_unique(actionType_,rockNo_); 32 | } 33 | 34 | double RockSampleAction::distanceTo(solver::Action const &/*otherAction*/) const { 35 | return 0; 36 | } 37 | 38 | void RockSampleAction::print(std::ostream &os) const { 39 | os << actionType_; 40 | if (actionType_ == ActionType::CHECK) { 41 | os << static_cast(rockNo_); 42 | } 43 | } 44 | 45 | long RockSampleAction::getBinNumber() const { 46 | long code = static_cast(actionType_); 47 | if (actionType_ == ActionType::CHECK) { 48 | code += rockNo_; 49 | } 50 | return code; 51 | } 52 | 53 | ActionType RockSampleAction::getActionType() const { 54 | return actionType_; 55 | } 56 | 57 | long RockSampleAction::getRockNo() const { 58 | return rockNo_; 59 | } 60 | } /* namespace rocksample */ 61 | -------------------------------------------------------------------------------- /src/problems/rocksample/RockSampleObservation.cpp: -------------------------------------------------------------------------------- 1 | /** @file RockSampleObservation.cpp 2 | * 3 | * Contains the implementations for the methods of RockSampleObservation. 4 | */ 5 | #include "RockSampleObservation.hpp" 6 | 7 | #include // for size_t 8 | 9 | #include // for copy 10 | #include // for ostream_iterator 11 | #include // for operator<<, ostream 12 | #include // for vector, operator==, _Bit_const_iterator, _Bit_iterator_base, hash, vector<>::const_iterator 13 | 14 | #include "global.hpp" 15 | #include "problems/shared/GridPosition.hpp" // for GridPosition, operator==, operator<< 16 | #include "solver/abstract-problem/Observation.hpp" // for Observation 17 | 18 | namespace rocksample { 19 | 20 | RockSampleObservation::RockSampleObservation() : 21 | isEmpty_(true), 22 | isGood_(false) { 23 | } 24 | 25 | RockSampleObservation::RockSampleObservation(bool _isGood) : 26 | isEmpty_(false), 27 | isGood_(_isGood) { 28 | } 29 | 30 | RockSampleObservation::RockSampleObservation(bool _isEmpty, bool _isGood) : 31 | isEmpty_(_isEmpty), 32 | isGood_(_isGood) { 33 | } 34 | 35 | RockSampleObservation::RockSampleObservation(long code) : 36 | isEmpty_(code == 0), 37 | isGood_(code == 1) { 38 | } 39 | 40 | std::unique_ptr RockSampleObservation::copy() const { 41 | return std::make_unique(isEmpty_,isGood_); 42 | } 43 | 44 | double RockSampleObservation::distanceTo(solver::Observation const &otherObs) const { 45 | RockSampleObservation const &other = 46 | static_cast(otherObs); 47 | return isGood_ == other.isGood_ ? 0 : 1; 48 | } 49 | 50 | bool RockSampleObservation::equals(solver::Observation const &otherObs) const { 51 | RockSampleObservation const &other = 52 | static_cast(otherObs); 53 | return isGood_ == other.isGood_; 54 | } 55 | 56 | std::size_t RockSampleObservation::hash() const { 57 | return isGood_ ? 1 : 0; 58 | } 59 | 60 | void RockSampleObservation::print(std::ostream &os) const { 61 | if (isEmpty_) { 62 | os << "NONE"; 63 | } else if (isGood_) { 64 | os << "GOOD"; 65 | } else { 66 | os << "BAD"; 67 | } 68 | } 69 | 70 | long RockSampleObservation::getBinNumber() const { 71 | return isEmpty_ ? 0 : (isGood_ ? 1 : 2); 72 | } 73 | 74 | bool RockSampleObservation::isEmpty() const { 75 | return isEmpty_; 76 | } 77 | 78 | bool RockSampleObservation::isGood() const { 79 | return isGood_; 80 | } 81 | } 82 | /* namespace rocksample */ 83 | -------------------------------------------------------------------------------- /src/problems/rocksample/RockSampleObservation.hpp: -------------------------------------------------------------------------------- 1 | /** @file RockSampleObservation.hpp 2 | * 3 | * Defines the RockSampleObservation class, which represents an observation in the RockSample POMDP. 4 | */ 5 | #ifndef ROCKSAMPLE_OBSERVATION_HPP_ 6 | #define ROCKSAMPLE_OBSERVATION_HPP_ 7 | 8 | #include // for size_t 9 | 10 | #include // for ostream 11 | #include // for vector 12 | 13 | #include "solver/abstract-problem/DiscretizedPoint.hpp" 14 | #include "solver/abstract-problem/Observation.hpp" 15 | 16 | #include "global.hpp" // for RandomGenerator 17 | 18 | namespace rocksample { 19 | /** A class representing an observation in the RockSample POMDP. 20 | * 21 | * This is represented by two boolean flags; one for whether or not any observation was made, 22 | * and one for whether the rock was seen as good or bad if an observation was, in fact, made. 23 | * 24 | * This class also implements solver::DiscretizedPoint so that the solver can use a simplistic 25 | * enumerated observation mapping approach (EnumeratedObservationPool) to store the possible 26 | * observations from each ActionNode. 27 | */ 28 | class RockSampleObservation : public solver::DiscretizedPoint { 29 | friend class RockSampleTextSerializer; 30 | 31 | public: 32 | /** Constructs a new, empty observation. */ 33 | RockSampleObservation(); 34 | /** Constructs a non-empty observation, which is good iff _isGood is true. */ 35 | RockSampleObservation(bool _isGood); 36 | /** Constructs a new observation with the given values for whether it is empty, and whether it 37 | * is good. 38 | */ 39 | RockSampleObservation(bool _isEmpty, bool _isGood); 40 | /** Constructs a new observation from the given integer code. */ 41 | RockSampleObservation(long code); 42 | 43 | virtual ~RockSampleObservation() = default; 44 | _NO_COPY_OR_MOVE(RockSampleObservation); 45 | 46 | std::unique_ptr copy() const override; 47 | double distanceTo(solver::Observation const &otherObs) const override; 48 | bool equals(solver::Observation const &otherObs) const override; 49 | std::size_t hash() const override; 50 | void print(std::ostream &os) const override; 51 | 52 | long getBinNumber() const override; 53 | 54 | /** Returns true iff this observation is empty. */ 55 | bool isEmpty() const; 56 | /** Returns true iff this observation is good. */ 57 | bool isGood() const; 58 | 59 | private: 60 | /** True iff this observation is empty. */ 61 | bool isEmpty_; 62 | /** True iff this observation is good. */ 63 | bool isGood_; 64 | }; 65 | } /* namespace rocksample */ 66 | 67 | #endif /* ROCKSAMPLE_OBSERVATION_HPP_ */ 68 | -------------------------------------------------------------------------------- /src/problems/rocksample/position_history.hpp: -------------------------------------------------------------------------------- 1 | /** @file position_history.hpp 2 | * 3 | * Defines a class to keep track of the position of the robot in RockSample. 4 | * 5 | * This is useful, since the position is fully observable but is not included in observations. 6 | */ 7 | #ifndef ROCKSAMPLE_POSITION_HISTORY_HPP_ 8 | #define ROCKSAMPLE_POSITION_HISTORY_HPP_ 9 | 10 | #include 11 | #include 12 | 13 | #include "solver/abstract-problem/HistoricalData.hpp" 14 | 15 | #include "solver/serialization/TextSerializer.hpp" 16 | 17 | #include "problems/shared/GridPosition.hpp" 18 | 19 | namespace rocksample { 20 | class RockSampleAction; 21 | class RockSampleModel; 22 | 23 | /** A class to store the robot position associated with a given belief node. 24 | * 25 | * Since the robot position in RockSample is fully observable, all particles in any belief will 26 | * in fact have the same position, which is stored here. 27 | */ 28 | class PositionData : public solver::HistoricalData { 29 | friend class PositionDataTextSerializer; 30 | public: 31 | /** Creates a new PositionData instance for the given model, and located in the given grid 32 | * square. 33 | */ 34 | PositionData(RockSampleModel *model, GridPosition position); 35 | virtual ~PositionData() = default; 36 | _NO_COPY_OR_MOVE(PositionData); 37 | 38 | std::unique_ptr copy() const; 39 | 40 | std::unique_ptr createChild( 41 | solver::Action const &action, 42 | solver::Observation const &observation) const override; 43 | 44 | /** Generates the legal actions that are available from this position. */ 45 | std::vector generateLegalActions() const; 46 | 47 | /** Returns the grid position for this PositionData instance. */ 48 | GridPosition getPosition() const; 49 | 50 | void print(std::ostream &os) const override; 51 | 52 | private: 53 | /** The RockSampleModel instance this PositionData instance is associated with. */ 54 | RockSampleModel *model_; 55 | /** The grid position of this PositionData. */ 56 | GridPosition position_; 57 | }; 58 | 59 | /** An implementation of the serialization methods for the PositionData class. */ 60 | class PositionDataTextSerializer : virtual public solver::TextSerializer { 61 | public: 62 | void saveHistoricalData(solver::HistoricalData const *data, std::ostream &os) override; 63 | std::unique_ptr loadHistoricalData(std::istream &is) override; 64 | }; 65 | } /* namespace rocksample */ 66 | 67 | #endif /* ROCKSAMPLE_POSITION_HISTORY_HPP_ */ 68 | -------------------------------------------------------------------------------- /src/problems/rocksample/simulate.cpp: -------------------------------------------------------------------------------- 1 | /** @file rocksample/simulate.cpp 2 | * 3 | * Defines the main method for the "simulate" executable for the RockSample POMDP, which runs 4 | * online simulations to test the performance of the solver. 5 | */ 6 | #include "problems/shared/simulate.hpp" 7 | 8 | #include "RockSampleModel.hpp" // for RockSampleModel 9 | #include "RockSampleOptions.hpp" // for RockSampleOptions 10 | 11 | /** The main method for the "simulate" executable for RockSample. */ 12 | int main(int argc, char const *argv[]) { 13 | return simulate(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/rocksample/solve.cpp: -------------------------------------------------------------------------------- 1 | /** @file rocksample/solve.cpp 2 | * 3 | * Defines the main method for the "solve" executable for the RockSample POMDP, which generates an 4 | * initial policy. 5 | */ 6 | #include "problems/shared/solve.hpp" 7 | 8 | #include "RockSampleModel.hpp" // for RockSampleModel 9 | #include "RockSampleOptions.hpp" // for RockSampleOptions 10 | 11 | /** The main method for the "solve" executable for RockSample. */ 12 | int main(int argc, char const *argv[]) { 13 | return solve(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/rocksample/stest.cpp: -------------------------------------------------------------------------------- 1 | /** @file rocksample/stest.cpp 2 | * 3 | * Defines the main method for the "stest" executable for the RockSample POMDP, which tests the 4 | * serialization methods for RockSample by deserializing and re-serializing a policy file. 5 | */ 6 | #include "problems/shared/stest.hpp" 7 | 8 | #include "RockSampleModel.hpp" // for RockSampleModel 9 | #include "RockSampleOptions.hpp" // for RockSampleOptions 10 | 11 | /** The main method for the "stest" executable for RockSample. */ 12 | int main(int argc, char const *argv[]) { 13 | return stest(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/shared/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = shared 2 | CHILD_DIRS := geometry 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/template.mk 7 | include .make/build.mk 8 | 9 | else 10 | REDIRECT=$(MODULE_NAME) 11 | .PHONY: $(MAKECMDGOALS) call-upwards 12 | $(MAKECMDGOALS): call-upwards ; 13 | call-upwards: 14 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 15 | endif 16 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = geometry 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/Point2D.cpp: -------------------------------------------------------------------------------- 1 | /** @file Point2D.cpp 2 | * 3 | * Contains implementations for the methods of the Point2D class. 4 | */ 5 | #include "problems/shared/geometry/Point2D.hpp" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "global.hpp" 13 | 14 | #include "solver/abstract-problem/Point.hpp" 15 | #include "solver/abstract-problem/Vector.hpp" 16 | 17 | #include "problems/shared/geometry/Vector2D.hpp" 18 | 19 | namespace geometry { 20 | Point2D::Point2D() : 21 | Point2D(0.0, 0.0) { 22 | } 23 | 24 | Point2D::Point2D(double x, double y) : 25 | x_(x), 26 | y_(y) { 27 | } 28 | 29 | Point2D::~Point2D() { 30 | } 31 | 32 | std::unique_ptr Point2D::copy() const { 33 | return std::make_unique(*this); 34 | } 35 | 36 | double Point2D::distanceTo(const Point& otherPoint) const { 37 | Point2D const &other = static_cast(otherPoint); 38 | return std::sqrt(std::pow(x_ - other.x_, 2) + std::pow(y_ - other.y_, 2)); 39 | } 40 | 41 | bool Point2D::equals(const Point& otherPoint) const { 42 | Point2D const &other = static_cast(otherPoint); 43 | return (x_ == other.x_ && y_ == other.y_); 44 | } 45 | 46 | std::size_t Point2D::hash() const { 47 | std::size_t hashValue = 0; 48 | tapir::hash_combine(hashValue, x_); 49 | tapir::hash_combine(hashValue, y_); 50 | return hashValue; 51 | } 52 | 53 | void Point2D::print(std::ostream& os) const { 54 | os << "(" << x_ << ", " << y_ << ")"; 55 | } 56 | 57 | void Point2D::loadFrom(std::istream &is) { 58 | std::string tmpStr; 59 | std::getline(is, tmpStr, '('); 60 | std::getline(is, tmpStr, ','); 61 | std::istringstream(tmpStr) >> x_; 62 | std::getline(is, tmpStr, ')'); 63 | std::istringstream(tmpStr) >> y_; 64 | } 65 | 66 | std::vector Point2D::asVector() const { 67 | return std::vector {x_, y_}; 68 | } 69 | 70 | double Point2D::getX() const { 71 | return x_; 72 | } 73 | 74 | double Point2D::getY() const { 75 | return y_; 76 | } 77 | } /* namespace geometry */ 78 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/Point2D.hpp: -------------------------------------------------------------------------------- 1 | /** @file Point2D.hpp 2 | * 3 | * Defines the Point2D class, which represents a point in 2-D Euclidean space. 4 | */ 5 | #ifndef GEOMETRY_POINT2D_HPP_ 6 | #define GEOMETRY_POINT2D_HPP_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "solver/abstract-problem/Point.hpp" 13 | #include "solver/abstract-problem/Vector.hpp" 14 | 15 | namespace geometry { 16 | class Vector2D; 17 | 18 | /** A class modeling a point in 2-D space. */ 19 | class Point2D: public solver::Vector { 20 | public: 21 | /** Creates a new Point2D at (0, 0). */ 22 | Point2D(); 23 | /** Creates a new Point2D with coordinates (x, y). */ 24 | Point2D(double x, double y); 25 | 26 | virtual ~Point2D(); 27 | 28 | virtual std::unique_ptr copy() const override; 29 | virtual double distanceTo(solver::Point const &otherPoint) const override; 30 | virtual bool equals(solver::Point const &otherPoint) const override; 31 | virtual std::size_t hash() const override; 32 | 33 | virtual void print(std::ostream &os) const override; 34 | /** Loads the contents of this point from the given input stream. */ 35 | virtual void loadFrom(std::istream &is); 36 | 37 | virtual std::vector asVector() const override; 38 | 39 | /** Returns the x coordinate of this point. */ 40 | double getX() const; 41 | /** Returns the y coordinate of this point. */ 42 | double getY() const; 43 | 44 | private: 45 | /** The x coordinate of this point. */ 46 | double x_; 47 | /** The y coordinate of this point. */ 48 | double y_; 49 | 50 | /** Adds a vector to this point. The definition is given in Vector2D.hpp. */ 51 | friend Point2D &operator+=(Point2D &p, Vector2D const &v); 52 | }; 53 | 54 | /** We define operator>> to allow easier serialization of Point2D; operator<< is already defined 55 | * by the base Point class. 56 | */ 57 | inline std::istream &operator>>(std::istream &is, Point2D &point) { 58 | point.loadFrom(is); 59 | return is; 60 | } 61 | } /* namespace geometry */ 62 | 63 | #endif /* GEOMETRY_POINT2D_HPP_ */ 64 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/RTree.cpp: -------------------------------------------------------------------------------- 1 | /** @file geometry/RTree.cpp 2 | * 3 | * Contains the implementation for the geometry::RTree class. 4 | */ 5 | #include "problems/shared/geometry/RTree.hpp" 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "global.hpp" 14 | 15 | namespace geometry { 16 | RTree::RTree(unsigned int nSDim) : 17 | nSDim_(nSDim), 18 | properties_(nullptr), 19 | storageManager_(nullptr), 20 | tree_(nullptr) { 21 | reset(); 22 | } 23 | 24 | void RTree::reset() { 25 | properties_ = std::make_unique(); 26 | Tools::Variant var; 27 | 28 | var.m_varType = Tools::VT_ULONG; 29 | var.m_val.ulVal = nSDim_; 30 | properties_->setProperty("Dimension", var); 31 | 32 | var.m_varType = Tools::VT_ULONG; 33 | var.m_val.ulVal = 100; 34 | properties_->setProperty("IndexCapacity", var); 35 | 36 | var.m_varType = Tools::VT_ULONG; 37 | var.m_val.ulVal = 100; 38 | properties_->setProperty("LeafCapacity", var); 39 | 40 | var.m_varType = Tools::VT_DOUBLE; 41 | var.m_val.dblVal = 0.7; 42 | properties_->setProperty("FillFactor", var); 43 | 44 | var.m_varType = Tools::VT_LONG; 45 | var.m_val.lVal = SpatialIndex::RTree::RV_RSTAR; 46 | properties_->setProperty("TreeVariant", var); 47 | 48 | tree_.reset(nullptr); 49 | storageManager_.reset( 50 | SpatialIndex::StorageManager::returnMemoryStorageManager(*properties_)); 51 | tree_.reset(SpatialIndex::RTree::returnRTree(*storageManager_, *properties_)); 52 | } 53 | 54 | SpatialIndex::ISpatialIndex *RTree::getTree() { 55 | return tree_.get(); 56 | } 57 | 58 | } /* namespace geometry */ 59 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/RTree.hpp: -------------------------------------------------------------------------------- 1 | /** @file geometry/RTree.hpp 2 | * 3 | * Defines the geometry::RTree class, which wraps the R*-tree implementation in 4 | * libspatialindex. 5 | */ 6 | #ifndef GEOMETRY_RTREE_HPP_ 7 | #define GEOMETRY_RTREE_HPP_ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "global.hpp" 15 | 16 | namespace geometry { 17 | 18 | /** A wrapper class for the R*-tree implementation in libspatialindex; the main function of this 19 | * class is to set up the properties and storage manager for the R*-tree. 20 | */ 21 | class RTree { 22 | public: 23 | /** Constructs a new RTree with the given number of spatial dimensions. */ 24 | RTree(unsigned int nSDim); 25 | virtual ~RTree() = default; 26 | _NO_COPY_OR_MOVE(RTree); 27 | 28 | /** Resets the RTree to be completely empty. */ 29 | virtual void reset(); 30 | 31 | /** Returns the ISpatialIndex contained within the tree. */ 32 | SpatialIndex::ISpatialIndex *getTree(); 33 | 34 | private: 35 | /** The number of spatial dimensions for the tree. */ 36 | unsigned int nSDim_; 37 | /** The set of properties for the tree. */ 38 | std::unique_ptr properties_; 39 | /** The storage manager for the tree. */ 40 | std::unique_ptr storageManager_; 41 | /** The actual R*-tree instance itself. */ 42 | std::unique_ptr tree_; 43 | }; 44 | } /* namespace geometry */ 45 | 46 | #endif /* GEOMETRY_RTREE_HPP_ */ 47 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/utilities.cpp: -------------------------------------------------------------------------------- 1 | /** @file utilities.cpp 2 | * 3 | * Contains implementations of utility functions for geometric calculations. 4 | */ 5 | #include "utilities.hpp" 6 | 7 | #include 8 | 9 | namespace geometry { 10 | double normalizeTurn(double turn) { 11 | double numRotations; 12 | turn = std::modf(turn, &numRotations); 13 | if (turn <= -0.5) { 14 | turn += 1; 15 | } else if (turn > 0.5) { 16 | turn -= 1; 17 | } 18 | return turn; 19 | } 20 | } /* namespace geometry */ 21 | -------------------------------------------------------------------------------- /src/problems/shared/geometry/utilities.hpp: -------------------------------------------------------------------------------- 1 | /** @file utilities.hpp 2 | * 3 | * Defines some utility functions for use with geometric calculations. 4 | */ 5 | #ifndef GEOMETRY_UTILITIES_HPP_ 6 | #define GEOMETRY_UTILITIES_HPP_ 7 | 8 | /** A namespace holding utility classes and functions related to 2-D geometry. */ 9 | namespace geometry { 10 | /** Normalizes the given turn amount to a quantity between -0.5 (exclusive) and 0.5 (inclusive). */ 11 | double normalizeTurn(double turn); 12 | } /* namespace geometry */ 13 | 14 | #endif /* GEOMETRY_UTILITIES_HPP_ */ 15 | -------------------------------------------------------------------------------- /src/problems/shared/ros/ScanToPcl.cpp: -------------------------------------------------------------------------------- 1 | /** @file ScanToPcl.cpp 2 | * 3 | * A simple ROS node that subscribes to the laser scan data published by V-REP, and then 4 | * re-publishes it as a PointCould2 message which can then be used by the Octomap server. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /** An event listener to respond to laser scan data from V-REP. */ 12 | void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg); 13 | 14 | /** This utility instance does the work of converting the laser data to a point cloud. */ 15 | laser_geometry::LaserProjection projector; 16 | /** A Publisher for publishing the point cloud. */ 17 | ros::Publisher pclPub; 18 | 19 | /** The main method for this laser data conversion node, which converts V-REP laser data messages 20 | * to PointCloud2 messages. 21 | */ 22 | int main(int argc, char **argv) { 23 | ros::init(argc, argv, "scan_to_pcl_node"); 24 | ros::NodeHandle node; 25 | pclPub = node.advertise("cloud_in", 1); 26 | ros::Subscriber scanSub = node.subscribe("/vrep/front_scan", 1, scanCallback); 27 | ros::spin(); 28 | } 29 | 30 | void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg) { 31 | sensor_msgs::PointCloud2 cloud; 32 | projector.projectLaser(*msg, cloud); 33 | pclPub.publish(cloud); 34 | } 35 | -------------------------------------------------------------------------------- /src/problems/tag/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = tag 2 | TARGET_NAMES := solve simulate 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/problem-template.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/problems/tag/TagAction.cpp: -------------------------------------------------------------------------------- 1 | /** @file TagAction.cpp 2 | * 3 | * Contains the implementations for the methods of the TagAction class. 4 | */ 5 | #include "TagAction.hpp" 6 | 7 | #include // for size_t 8 | 9 | #include // for copy 10 | #include // for ostream_iterator 11 | #include // for operator<<, ostream 12 | #include // for vector, operator==, _Bit_const_iterator, _Bit_iterator_base, hash, vector<>::const_iterator 13 | 14 | #include "global.hpp" 15 | 16 | #include "problems/shared/GridPosition.hpp" // for GridPosition, operator==, operator<< 17 | #include "solver/abstract-problem/State.hpp" // for State 18 | 19 | namespace tag { 20 | TagAction::TagAction(ActionType actionType): 21 | actionType_(actionType) { 22 | } 23 | 24 | TagAction::TagAction(long code) : 25 | actionType_(static_cast(code)) { 26 | } 27 | 28 | std::unique_ptr TagAction::copy() const { 29 | return std::make_unique(actionType_); 30 | } 31 | 32 | double TagAction::distanceTo(solver::Action const &/*otherAction*/) const { 33 | return 0; 34 | } 35 | 36 | void TagAction::print(std::ostream &os) const { 37 | switch (actionType_) { 38 | case ActionType::NORTH: 39 | os << "NORTH"; 40 | break; 41 | case ActionType::EAST: 42 | os << "EAST"; 43 | break; 44 | case ActionType::SOUTH: 45 | os << "SOUTH"; 46 | break; 47 | case ActionType::WEST: 48 | os << "WEST"; 49 | break; 50 | case ActionType::TAG: 51 | os << "TAG"; 52 | break; 53 | default: 54 | os << "ERROR-" << static_cast(actionType_); 55 | break; 56 | } 57 | } 58 | 59 | long TagAction::getBinNumber() const { 60 | return static_cast(actionType_); 61 | } 62 | ActionType TagAction::getActionType() const { 63 | return actionType_; 64 | } 65 | } /* namespace tag */ 66 | -------------------------------------------------------------------------------- /src/problems/tag/TagAction.hpp: -------------------------------------------------------------------------------- 1 | /** @file TagAction.hpp 2 | * 3 | * Defines the TagAction class, which represents an action for the Tag problem, and also the 4 | * ActionType enumeration, which enumerates the different types of actions for Tag. 5 | */ 6 | #ifndef TAG_ACTION_HPP_ 7 | #define TAG_ACTION_HPP_ 8 | 9 | #include // for size_t 10 | 11 | #include // for ostream 12 | #include // for vector 13 | 14 | #include "solver/abstract-problem/Action.hpp" 15 | #include "solver/abstract-problem/DiscretizedPoint.hpp" // for DiscretizedPoint 16 | 17 | namespace tag { 18 | 19 | /** An enumeration of all the available actions in the Tag PODMP. */ 20 | enum class ActionType : long { 21 | /** The action to move north. */ 22 | NORTH = 0, 23 | /** The action to move east. */ 24 | EAST = 1, 25 | /** The action to move south. */ 26 | SOUTH = 2, 27 | /** The action to move west. */ 28 | WEST = 3, 29 | /** The action to attempt to tag the opponent. */ 30 | TAG = 4, 31 | }; 32 | 33 | /** A class representing an action in the Tag POMDP. 34 | * 35 | * This class also implements solver::DiscretizedPoint so that the solver can use a simplistic 36 | * enumerated action mapping approach (EnumeratedActionPool) to store the available actions from 37 | * each belief node. 38 | */ 39 | class TagAction : public solver::DiscretizedPoint { 40 | friend class TagTextSerializer; 41 | public: 42 | /** Constructs a new action from the given ActionType. */ 43 | TagAction(ActionType actionType); 44 | /** Constructs a new action from the given integer code. */ 45 | TagAction(long code); 46 | 47 | virtual ~TagAction() = default; 48 | _NO_COPY_OR_MOVE(TagAction); 49 | 50 | std::unique_ptr copy() const override; 51 | double distanceTo(solver::Action const &otherAction) const override; 52 | void print(std::ostream &os) const override; 53 | 54 | long getBinNumber() const override; 55 | /** Returns the ActionType of this action. */ 56 | ActionType getActionType() const; 57 | 58 | private: 59 | /** The ActionType for this action in the Tag POMDP. */ 60 | ActionType actionType_; 61 | }; 62 | } /* namespace tag */ 63 | 64 | #endif /* TAG_ACTION_HPP_ */ 65 | -------------------------------------------------------------------------------- /src/problems/tag/TagMdpSolver.hpp: -------------------------------------------------------------------------------- 1 | /** @file TagMdpSolver.hpp 2 | * 3 | * Defines the TagMdpSolver class, which solves the fully observable version of Tag in order to 4 | * serve as a heuristic function for the POMDP. 5 | * 6 | * This file also contains the definition for TagMdpParser, which allows this heuristic to be 7 | * selected via the string "exactMdp()" in the configuration file. 8 | */ 9 | #ifndef TAG_MDPSOLVER_HPP_ 10 | #define TAG_MDPSOLVER_HPP_ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "global.hpp" 17 | 18 | #include "problems/shared/parsers.hpp" 19 | 20 | #include "solver/abstract-problem/heuristics/HeuristicFunction.hpp" 21 | 22 | #include "TagState.hpp" 23 | 24 | namespace tag { 25 | class TagModel; 26 | 27 | /** A class that solves the fully observable version of Tag and stores the calculated value for 28 | * each state. 29 | */ 30 | class TagMdpSolver { 31 | public: 32 | /** Creates a new TagMdpSolver which will be tied to the given TagModel instance. */ 33 | TagMdpSolver(TagModel *model); 34 | virtual ~TagMdpSolver() = default; 35 | _NO_COPY_OR_MOVE(TagMdpSolver); 36 | 37 | /** Solves the MDP, using the current state of the */ 38 | void solve(); 39 | 40 | /** Returns the calculated MDP value for the given state. */ 41 | double getValue(TagState const &state) const; 42 | 43 | private: 44 | /** The model instance this MDP solver is associated with. */ 45 | TagModel *model_; 46 | /** A map to hold the calculated value for each non-terminal state. */ 47 | std::unordered_map valueMap_; 48 | }; 49 | 50 | /** A class to parse the command-line heuristic setting for the case "exactMdp()". */ 51 | class TagMdpParser : public shared::Parser { 52 | public: 53 | /** Creates a new MDP parser associated with the given TagModel instance. */ 54 | TagMdpParser(TagModel *model); 55 | virtual ~TagMdpParser() = default; 56 | _NO_COPY_OR_MOVE(TagMdpParser); 57 | 58 | /** Creates a solver::HeuristicFunction associated with the stored TagModel instance. 59 | * 60 | * This heuristic can then be used by the ABT algorithm. 61 | */ 62 | virtual solver::HeuristicFunction parse(solver::Solver *solver, std::vector args); 63 | 64 | private: 65 | /** The TagModel instance this heuristic parser is associated with. */ 66 | TagModel *model_; 67 | }; 68 | } /* namespace tag */ 69 | 70 | #endif /* TAG_MDPSOLVER_HPP_ */ 71 | -------------------------------------------------------------------------------- /src/problems/tag/TagObservation.cpp: -------------------------------------------------------------------------------- 1 | /** @file TagObservation.cpp 2 | * 3 | * Contains the implementations for the methods of TagObservation. 4 | */ 5 | #include "TagObservation.hpp" 6 | 7 | #include // for size_t 8 | 9 | #include // for copy 10 | #include // for ostream_iterator 11 | #include // for operator<<, ostream 12 | #include // for vector, operator==, _Bit_const_iterator, _Bit_iterator_base, hash, vector<>::const_iterator 13 | 14 | #include "global.hpp" 15 | 16 | #include "problems/shared/GridPosition.hpp" // for GridPosition, operator==, operator<< 17 | #include "solver/abstract-problem/Observation.hpp" // for Observation 18 | 19 | #include "TagModel.hpp" 20 | 21 | namespace tag { 22 | TagObservation::TagObservation(GridPosition position, 23 | bool _seesOpponent) : 24 | position_(position), 25 | seesOpponent_(_seesOpponent) { 26 | } 27 | std::unique_ptr 28 | TagObservation::copy() const { 29 | return std::make_unique(position_, seesOpponent_); 30 | } 31 | 32 | double TagObservation::distanceTo( 33 | solver::Observation const &otherObs) const { 34 | TagObservation const &other = 35 | static_cast(otherObs); 36 | return seesOpponent_ == other.seesOpponent_ ? 0 : 1; 37 | } 38 | 39 | bool TagObservation::equals( 40 | solver::Observation const &otherObs) const { 41 | TagObservation const &other = 42 | static_cast(otherObs); 43 | return position_ == other.position_ && seesOpponent_ == other.seesOpponent_; 44 | } 45 | 46 | std::size_t TagObservation::hash() const { 47 | std::size_t hashValue = 0; 48 | tapir::hash_combine(hashValue, position_.i); 49 | tapir::hash_combine(hashValue, position_.j); 50 | tapir::hash_combine(hashValue, seesOpponent_); 51 | return hashValue; 52 | } 53 | 54 | void TagObservation::print(std::ostream &os) const { 55 | os << position_ << " "; 56 | if (seesOpponent_) { 57 | os << "SEEN"; 58 | } else { 59 | os << "UNSEEN"; 60 | } 61 | } 62 | 63 | GridPosition TagObservation::getPosition() const { 64 | return position_; 65 | } 66 | 67 | bool TagObservation::seesOpponent() const { 68 | return seesOpponent_; 69 | } 70 | } 71 | /* namespace tag */ 72 | -------------------------------------------------------------------------------- /src/problems/tag/TagObservation.hpp: -------------------------------------------------------------------------------- 1 | /** @file TagObservation.hpp 2 | * 3 | * Defines the TagObservation class, which represents an observation in the Tag POMDP. 4 | */ 5 | #ifndef TAG_OBSERVATION_HPP_ 6 | #define TAG_OBSERVATION_HPP_ 7 | 8 | #include // for size_t 9 | 10 | #include // for ostream 11 | #include // for vector 12 | 13 | #include "global.hpp" // for RandomGenerator 14 | 15 | #include "problems/shared/GridPosition.hpp" 16 | #include "solver/abstract-problem/DiscretizedPoint.hpp" 17 | #include "solver/abstract-problem/Observation.hpp" 18 | 19 | namespace tag { 20 | class TagModel; 21 | 22 | /** A class representing an observation in the Tag POMDP. 23 | * 24 | * This includes an observation of the robot's own position, and a boolean flag representing 25 | * whether or not the robot sees the opponent (and hence is on the same grid square). 26 | */ 27 | class TagObservation : public solver::Point { 28 | friend class TagTextSerializer; 29 | public: 30 | /** Constructs a new TagObservation for the given robot position; seesOpponent should be true 31 | * iff the robot sees the opponent due to being on the same square. 32 | */ 33 | TagObservation(GridPosition myPosition, bool seesOpponent = false); 34 | 35 | virtual ~TagObservation() = default; 36 | _NO_COPY_OR_MOVE(TagObservation); 37 | 38 | std::unique_ptr copy() const override; 39 | double distanceTo(solver::Observation const &otherObs) const override; 40 | bool equals(solver::Observation const &otherObs) const override; 41 | std::size_t hash() const override; 42 | void print(std::ostream &os) const override; 43 | 44 | /** Returns the position the robot has observed itself in. */ 45 | GridPosition getPosition() const; 46 | /** Returns true iff the robot sees the opponent in the same square it is in. */ 47 | bool seesOpponent() const; 48 | 49 | private: 50 | /** The position the robot sees itself in. */ 51 | GridPosition position_; 52 | /** True iff the robot sees the opponent in the same square it is in. */ 53 | bool seesOpponent_; 54 | }; 55 | } /* namespace tag */ 56 | #endif /* TAG_OBSERVATION_HPP_ */ 57 | -------------------------------------------------------------------------------- /src/problems/tag/TagOptions.hpp: -------------------------------------------------------------------------------- 1 | /** @file TagOptions.hpp 2 | * 3 | * Defines the TagOptions class, which specifies the configuration settings available for the 4 | * Tag problem. 5 | */ 6 | #ifndef TAGOPTIONS_HPP_ 7 | #define TAGOPTIONS_HPP_ 8 | 9 | #include // for string 10 | 11 | #include "problems/shared/SharedOptions.hpp" 12 | 13 | namespace tag { 14 | /** A class defining the configuration settings for the Tag problem. */ 15 | struct TagOptions : public shared::SharedOptions { 16 | TagOptions() = default; 17 | virtual ~TagOptions() = default; 18 | 19 | /* -------- Settings specific to the Tag POMDP -------- */ 20 | /** Path to the map file (relative to SharedOptions::baseConfigPath) */ 21 | std::string mapPath = ""; 22 | /** Cost per move. */ 23 | double moveCost = 0.0; 24 | /** Reward for tagging. */ 25 | double tagReward = 0.0; 26 | /** Penalty for a failed tag attempt. */ 27 | double failedTagPenalty = 0.0; 28 | /** Probability the opponent will stay in place. */ 29 | double opponentStayProbability = 0.0; 30 | /** Path to vrep scene tag.ttt */ 31 | std::string vrepScenePath = ""; 32 | 33 | /** Constructs an OptionParser instance that will parse configuration settings for the Tag 34 | * problem into an instance of TagOptions. 35 | */ 36 | static std::unique_ptr makeParser(bool simulating) { 37 | std::unique_ptr parser = SharedOptions::makeParser(simulating, 38 | EXPAND_AND_QUOTE(ROOT_PATH) "/problems/tag"); 39 | addTagOptions(parser.get()); 40 | return std::move(parser); 41 | } 42 | 43 | /** Adds the core configuration settings for the Tag problem to the given parser. */ 44 | static void addTagOptions(options::OptionParser *parser) { 45 | parser->addOption("problem", "mapPath", &TagOptions::mapPath); 46 | parser->addValueArg("problem", "mapPath", &TagOptions::mapPath, 47 | "", "map", "the path to the map file (relative to the base config path)", "path"); 48 | 49 | parser->addOption("problem", "moveCost", &TagOptions::moveCost); 50 | parser->addOption("problem", "tagReward", &TagOptions::tagReward); 51 | parser->addOption("problem", "failedTagPenalty", &TagOptions::failedTagPenalty); 52 | parser->addOption("problem", "opponentStayProbability", 53 | &TagOptions::opponentStayProbability); 54 | parser->addOptionWithDefault("ros", "vrepScenePath", 55 | &TagOptions::vrepScenePath, ""); 56 | } 57 | }; 58 | } /* namespace tag */ 59 | 60 | #endif /* TAGOPTIONS_HPP_ */ 61 | -------------------------------------------------------------------------------- /src/problems/tag/simulate.cpp: -------------------------------------------------------------------------------- 1 | /** @file problems/tag/simulate.cpp 2 | * 3 | * Defines the main method for the "simulate" executable for the Tag POMDP, which runs online 4 | * simulations to test the performance of the solver. 5 | */ 6 | #include "problems/shared/simulate.hpp" 7 | 8 | #include "TagModel.hpp" // for TagModel 9 | #include "TagOptions.hpp" // for TagOptions 10 | 11 | /** The main method for the "simulate" executable for Tag. */ 12 | int main(int argc, char const *argv[]) { 13 | return simulate(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/tag/solve.cpp: -------------------------------------------------------------------------------- 1 | /** @file problems/tag/solve.cpp 2 | * 3 | * Defines the main method for the "solve" executable for the Tag POMDP, which generates an 4 | * initial policy. 5 | */ 6 | #include "problems/shared/solve.hpp" 7 | 8 | #include "TagModel.hpp" // for TagModel 9 | #include "TagOptions.hpp" // for TagOptions 10 | 11 | /** The main method for the "solve" executable for Tag. */ 12 | int main(int argc, char const *argv[]) { 13 | return solve(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/problems/tag/stest.cpp: -------------------------------------------------------------------------------- 1 | /** @file tag/stest.cpp 2 | * 3 | * Defines the main method for the "stest" executable for the Tag POMDP, which tests the 4 | * serialization methods for Tag by deserializing and re-serializing a policy file. 5 | */ 6 | #include "problems/shared/stest.hpp" 7 | 8 | #include "TagModel.hpp" // for TagModel 9 | #include "TagOptions.hpp" // for TagOptions 10 | 11 | /** The main method for the "stest" executable for Tag. */ 12 | int main(int argc, char const *argv[]) { 13 | return stest(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /src/solver/ActionNode.cpp: -------------------------------------------------------------------------------- 1 | /** @file ActionNode.cpp 2 | * 3 | * Contains the implementation of ActionNode. 4 | */ 5 | #include "solver/ActionNode.hpp" 6 | 7 | #include // for unique_ptr 8 | #include // for make_pair, move, pair 9 | #include // for vector 10 | 11 | #include "global.hpp" // for make_unique 12 | 13 | #include "solver/BeliefNode.hpp" 14 | #include "solver/Solver.hpp" 15 | 16 | #include "solver/belief-estimators/estimators.hpp" 17 | 18 | #include "solver/abstract-problem/Action.hpp" // for Action 19 | #include "solver/abstract-problem/Observation.hpp" // for Observation 20 | 21 | #include "solver/mappings/actions/ActionPool.hpp" // for ActionPool 22 | #include "solver/mappings/observations/ObservationMapping.hpp" // for ObservationMapping 23 | 24 | namespace solver { 25 | ActionNode::ActionNode() : 26 | parentEntry_(nullptr), 27 | observationMap_(nullptr) { 28 | } 29 | 30 | ActionNode::ActionNode(ActionMappingEntry *parentEntry) : 31 | parentEntry_(parentEntry), 32 | observationMap_(nullptr) { 33 | } 34 | 35 | // Default destructor 36 | ActionNode::~ActionNode() { 37 | } 38 | 39 | /* -------------------- Tree-related getters ---------------------- */ 40 | ObservationMapping *ActionNode::getMapping() const { 41 | return observationMap_.get(); 42 | } 43 | ActionMappingEntry *ActionNode::getParentEntry() const { 44 | return parentEntry_; 45 | } 46 | BeliefNode *ActionNode::getParentBelief() const { 47 | return parentEntry_->getMapping()->getOwner(); 48 | } 49 | BeliefNode *ActionNode::getChild(Observation const &obs) const { 50 | return observationMap_->getBelief(obs); 51 | } 52 | 53 | 54 | /* ============================ PRIVATE ============================ */ 55 | 56 | 57 | /* -------------------- Tree-related setters ---------------------- */ 58 | void ActionNode::setMapping(std::unique_ptr mapping) { 59 | observationMap_ = std::move(mapping); 60 | } 61 | 62 | /* -------------------- Tree-related methods ---------------------- */ 63 | std::pair ActionNode::createOrGetChild(Solver */*solver*/, 64 | Observation const &obs) { 65 | BeliefNode *childNode = getChild(obs); 66 | bool added = false; 67 | if (childNode == nullptr) { 68 | childNode = observationMap_->createBelief(obs); 69 | added = true; 70 | } 71 | return std::make_pair(childNode, added); 72 | } 73 | } /* namespace solver */ 74 | -------------------------------------------------------------------------------- /src/solver/Agent.cpp: -------------------------------------------------------------------------------- 1 | /** @file Agent.cpp 2 | * 3 | * Contains the implementation of the Agent class. 4 | */ 5 | #include "solver/Agent.hpp" 6 | 7 | #include "solver/BeliefNode.hpp" 8 | #include "solver/BeliefTree.hpp" 9 | #include "solver/Solver.hpp" 10 | 11 | namespace solver { 12 | 13 | Agent::Agent(Solver *solver) : 14 | solver_(solver), 15 | currentBelief_(solver_->getPolicy()->getRoot()) { 16 | } 17 | 18 | Solver *Agent::getSolver() const { 19 | return solver_; 20 | } 21 | std::unique_ptr Agent::getPreferredAction() const { 22 | return currentBelief_->getRecommendedAction(); 23 | } 24 | BeliefNode *Agent::getCurrentBelief() const { 25 | return currentBelief_; 26 | } 27 | 28 | void Agent::setCurrentBelief(BeliefNode *belief) { 29 | currentBelief_ = belief; 30 | } 31 | void Agent::updateBelief(Action const &action, Observation const &observation) { 32 | currentBelief_ = currentBelief_->createOrGetChild(action, observation); 33 | } 34 | } /* namespace solver */ 35 | -------------------------------------------------------------------------------- /src/solver/Agent.hpp: -------------------------------------------------------------------------------- 1 | /** @file Agent.hpp 2 | * 3 | * Contains the Agent class, which represents an actual agent embedded in an environment. 4 | * 5 | * This is a general class that should allow ABT to interface with external sensors; it is 6 | * also used by the Simulator class to test performance of the algorithm. 7 | */ 8 | #ifndef SOLVER_AGENT_HPP_ 9 | #define SOLVER_AGENT_HPP_ 10 | 11 | #include 12 | 13 | #include "global.hpp" 14 | 15 | #include "solver/abstract-problem/Action.hpp" 16 | #include "solver/abstract-problem/Observation.hpp" 17 | 18 | namespace solver { 19 | class BeliefNode; 20 | class Solver; 21 | 22 | /** Represents an agent embedded within an environment. 23 | * 24 | * The agent is tied to a solver, which in turn has an associated model of the environment and 25 | * uses the ABT algorithm to find a good policy for the agent to take. 26 | * 27 | * The agent represents its current state by associating it with a node in the solver's belief tree. 28 | * 29 | * Note that multiple agents can use the same solver, as the belief tree representation 30 | * is not tied to the state of a specific agent. 31 | */ 32 | class Agent { 33 | public: 34 | /** Constructs a new agent associated with the given solver. The initial belief will start 35 | * at the root node of the solver. */ 36 | Agent(Solver *solver); 37 | ~Agent() = default; 38 | _NO_COPY_OR_MOVE(Agent); 39 | 40 | /** Returns the solver being used by this agent. */ 41 | Solver *getSolver() const; 42 | /** Returns the agent's current choice of action. */ 43 | std::unique_ptr getPreferredAction() const; 44 | /** Returns the current belief of the agent (as a BeliefNode within the solver's belief tree). */ 45 | BeliefNode *getCurrentBelief() const; 46 | 47 | /** Sets the current belief of this agent to the given BeliefNode. */ 48 | void setCurrentBelief(BeliefNode *belief); 49 | /** Updates the belief of this agent based on an action and observation. */ 50 | void updateBelief(Action const &action, Observation const &observation); 51 | 52 | private: 53 | /** The solver used by this agent. */ 54 | Solver *solver_; 55 | /** The belief node in the tree that represents this agent's current belief. */ 56 | BeliefNode *currentBelief_; 57 | }; 58 | 59 | } /* namespace solver */ 60 | 61 | #endif /* SOLVER_AGENT_HPP_ */ 62 | 63 | -------------------------------------------------------------------------------- /src/solver/Histories.cpp: -------------------------------------------------------------------------------- 1 | /** @file Histories.cpp 2 | * 3 | * Contains the implementation of the Histories class 4 | */ 5 | #include "solver/Histories.hpp" 6 | 7 | #include // for move 8 | 9 | #include "global.hpp" // for make_unique 10 | 11 | #include "solver/HistoryEntry.hpp" // for HistoryEntry 12 | #include "solver/HistorySequence.hpp" // for HistorySequence 13 | 14 | namespace solver { 15 | Histories::Histories() : 16 | sequencesById_() { 17 | } 18 | 19 | /* ------------------- Retrieving sequences ------------------- */ 20 | long Histories::getNumberOfSequences() const { 21 | return sequencesById_.size(); 22 | } 23 | HistorySequence *Histories::getSequence(long seqId) const { 24 | return sequencesById_[seqId].get(); 25 | } 26 | 27 | 28 | /* ============================ PRIVATE ============================ */ 29 | 30 | 31 | /* ---------------- Adding / removing sequences ---------------- */ 32 | void Histories::reset() { 33 | sequencesById_.clear(); 34 | } 35 | HistorySequence *Histories::createSequence() { 36 | std::unique_ptr histSeq( 37 | std::make_unique(sequencesById_.size())); 38 | HistorySequence *rawPtr = histSeq.get(); 39 | sequencesById_.push_back(std::move(histSeq)); 40 | return rawPtr; 41 | } 42 | void Histories::deleteSequence(HistorySequence *sequence) { 43 | // Retrieve the current ID of the sequence, which should be its position in the vector. 44 | long seqId = sequence->id_; 45 | 46 | if (sequencesById_[seqId].get() != sequence) { 47 | debug::show_message("ERROR: sequence ID does not match its index!"); 48 | } 49 | 50 | // Deregister and clear the sequence. 51 | sequence->erase(); 52 | if (seqId < static_cast(sequencesById_.size()) - 1) { 53 | sequencesById_[seqId] = std::move(sequencesById_[sequencesById_.size()-1]); 54 | sequencesById_[seqId]->id_ = seqId; 55 | } 56 | sequencesById_.pop_back(); 57 | } 58 | } /* namespace solver */ 59 | -------------------------------------------------------------------------------- /src/solver/Histories.hpp: -------------------------------------------------------------------------------- 1 | /** @file Histories.hpp 2 | * 3 | * Contains the Histories class, which represents a collection of history sequences. 4 | * 5 | * This class owns the associated sequences, which are stored in a vector of unique_ptr 6 | */ 7 | #ifndef SOLVER_HISTORIES_HPP_ 8 | #define SOLVER_HISTORIES_HPP_ 9 | 10 | #include // for map 11 | #include // for unique_ptr 12 | 13 | #include "global.hpp" 14 | 15 | namespace solver { 16 | class HistoryEntry; 17 | class HistorySequence; 18 | 19 | /** Owns a collection of history sequences. 20 | * 21 | * The createSequence() method is the usual way to make a new history sequence, as it will 22 | * be owned by this Histories object. 23 | * 24 | * Individual sequences can also be removed outright using the deleteSequence() method. Note that 25 | * this is done by moving the sequence from the last position in the vector into the newly 26 | * deleted spot. 27 | * 28 | * Since the ID of a history sequence corresponds to its index in the vector, this means that 29 | * the ID of a history sequence is not guaranteed to remain constant. If you need to keep a 30 | * permanent reference to a sequence as long as it exists, just use a raw pointer to it. 31 | */ 32 | class Histories { 33 | public: 34 | friend class Solver; 35 | friend class TextSerializer; 36 | 37 | /** Constructs an empty bundle of histories. */ 38 | Histories(); 39 | 40 | // Default destructor; copying and moving disallowed! 41 | ~Histories() = default; 42 | _NO_COPY_OR_MOVE(Histories); 43 | 44 | /* ------------------- Retrieving sequences ------------------- */ 45 | /** Returns the number of history sequences. */ 46 | long getNumberOfSequences() const; 47 | /** Retrieves the history sequence with the given ID. */ 48 | HistorySequence *getSequence(long seqId) const; 49 | 50 | 51 | private: 52 | /* ---------------- Adding / removing sequences ---------------- */ 53 | /** Resets the histories to be empty. */ 54 | void reset(); 55 | /** Adds a new history sequence. */ 56 | HistorySequence *createSequence(); 57 | /** Deletes the given history sequence. */ 58 | void deleteSequence(HistorySequence *sequence); 59 | 60 | private: 61 | /** A vector to hold all of the sequences in this collection. */ 62 | std::vector> sequencesById_; 63 | }; 64 | } /* namespace solver */ 65 | 66 | #endif /* SOLVER_HISTORIES_HPP_ */ 67 | -------------------------------------------------------------------------------- /src/solver/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = solver 2 | CHILD_DIRS := indexing mappings serialization abstract-problem changes 3 | CHILD_DIRS += search belief-estimators 4 | 5 | ifdef HAS_ROOT_MAKEFILE 6 | 7 | include .make/template.mk 8 | 9 | # Elements that make up the library - deferred expansion! 10 | MEMBERS_solver = $(ALL_OBJS_solver) $(OBJS_global) 11 | 12 | # The output file for the library. 13 | ifeq ($(CFG),shared) 14 | LIB_solver := $(BUILDDIR)/libtapir.so 15 | else 16 | LIB_solver := $(BUILDDIR)/libtapir.a 17 | endif 18 | OUTPUTS_TO_CLEAN_solver += $(LIB_solver) 19 | 20 | # Configuration for building the library 21 | build-solver: $(LIB_solver) 22 | 23 | # Now we define the command to build this library 24 | ifeq ($(CFG),shared) 25 | $(LIB_solver): $$(MEMBERS_solver) 26 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared $(MEMBERS_solver) -o $@ 27 | else 28 | $(LIB_solver): $$(MEMBERS_solver) 29 | $(AR) rcs $@ $(MEMBERS_solver) 30 | endif 31 | 32 | # Rebuild the archive if this Makefile changes. 33 | $(LIB_solver): $(d)/Makefile 34 | 35 | else 36 | REDIRECT=$(MODULE_NAME) 37 | .PHONY: $(MAKECMDGOALS) call-upwards 38 | $(MAKECMDGOALS): call-upwards ; 39 | call-upwards: 40 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 41 | endif 42 | -------------------------------------------------------------------------------- /src/solver/StateInfo.cpp: -------------------------------------------------------------------------------- 1 | /** @file StateInfo.cpp 2 | * 3 | * Contains the implementation of the StateInfo class. 4 | */ 5 | #include "solver/StateInfo.hpp" 6 | 7 | #include // for find 8 | #include // for unique_ptr 9 | #include // for set 10 | #include // for move 11 | #include // for vector, vector<>::iterator 12 | 13 | #include "solver/abstract-problem/State.hpp" // for State 14 | #include "solver/changes/ChangeFlags.hpp" // for ChangeFlags, ChangeFlags::UNCHANGED 15 | 16 | namespace solver { 17 | class BeliefNode; 18 | class HistoryEntry; 19 | 20 | StateInfo::StateInfo(std::unique_ptr state) : 21 | state_(std::move(state)), 22 | id_(-1), 23 | usedInHistoryEntries_(), 24 | changeFlags_(ChangeFlags::UNCHANGED) { 25 | } 26 | 27 | // Constructor for serialization. 28 | StateInfo::StateInfo() : 29 | StateInfo(nullptr) { 30 | } 31 | 32 | StateInfo::StateInfo(State const &state) : 33 | StateInfo(state.copy()) { 34 | } 35 | 36 | // Do nothing! 37 | StateInfo::~StateInfo() { 38 | } 39 | 40 | 41 | /* ---------------------- Simple getters ---------------------- */ 42 | long StateInfo::getId() const { 43 | return id_; 44 | } 45 | State const *StateInfo::getState() const { 46 | return state_.get(); 47 | } 48 | 49 | 50 | /* ============================ PRIVATE ============================ */ 51 | 52 | 53 | /* ----------------- History entry registration ----------------- */ 54 | void StateInfo::addHistoryEntry(HistoryEntry *entry) { 55 | usedInHistoryEntries_.insert(entry); 56 | } 57 | void StateInfo::removeHistoryEntry(HistoryEntry *entry) { 58 | usedInHistoryEntries_.erase(entry); 59 | } 60 | 61 | /* ---------------------- Model change handling ---------------------- */ 62 | void StateInfo::resetChangeFlags() { 63 | changeFlags_ = ChangeFlags::UNCHANGED; 64 | } 65 | 66 | void StateInfo::setChangeFlags(ChangeFlags flags) { 67 | changeFlags_ |= flags; 68 | } 69 | 70 | } /* namespace solver */ 71 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/Action.hpp: -------------------------------------------------------------------------------- 1 | /** @file Action.hpp 2 | * 3 | * Defines the Action interface; currently this is the same as Point, so this is just a straight 4 | * typedef. 5 | */ 6 | #ifndef SOLVER_ACTION_HPP_ 7 | #define SOLVER_ACTION_HPP_ 8 | 9 | #include "solver/abstract-problem/Point.hpp" 10 | 11 | namespace solver { 12 | /** Currently Action has no requirements over and above Point, so this is just a typedef. */ 13 | typedef Point Action; 14 | } /* namespace solver */ 15 | 16 | #endif /* SOLVER_ACTION_HPP_ */ 17 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/DiscretizedPoint.cpp: -------------------------------------------------------------------------------- 1 | /** @file DiscretizedPoint.cpp 2 | * 3 | * Contains the implementation of the DiscretizedPoint class. 4 | */ 5 | #include "solver/abstract-problem/DiscretizedPoint.hpp" 6 | 7 | #include "solver/abstract-problem/Point.hpp" 8 | 9 | namespace solver { 10 | bool DiscretizedPoint::equals(Point const &otherPoint) const { 11 | DiscretizedPoint const &other = 12 | static_cast(otherPoint); 13 | return getBinNumber() == other.getBinNumber(); 14 | } 15 | 16 | std::size_t DiscretizedPoint::hash() const { 17 | return getBinNumber(); 18 | } 19 | 20 | void DiscretizedPoint::print(std::ostream &os) const { 21 | os << getBinNumber(); 22 | } 23 | } /* namespace solver */ 24 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/DiscretizedPoint.hpp: -------------------------------------------------------------------------------- 1 | /** @file DiscretizedPoint.hpp 2 | * 3 | * Defines a point within a discretized space. In addition to the default point methods, this class 4 | * requires each point to be able to return its associated bin number. 5 | */ 6 | #ifndef SOLVER_DISCRETIZED_POINT_HPP_ 7 | #define SOLVER_DISCRETIZED_POINT_HPP_ 8 | 9 | #include // for size_t 10 | 11 | #include 12 | #include 13 | #include // for unique_ptr 14 | #include // for ostream 15 | 16 | #include "global.hpp" 17 | 18 | #include "solver/abstract-problem/Point.hpp" 19 | 20 | namespace solver { 21 | /** Represents a point within a discretized space. 22 | * 23 | * This can be used to easily implement a simple, discrete state space by simply associating a 24 | * unique ID with each individual state. 25 | * 26 | * However, there need not be only one point in each bin; a bin can have as many or as few points 27 | * as you prefer. 28 | * 29 | * For convenience, the standard implementations for the equals(), hash() and print() are 30 | * implemented simply by using the ID. If you want something more sophisticated, override them. 31 | */ 32 | class DiscretizedPoint : public Point { 33 | public: 34 | DiscretizedPoint() = default; 35 | virtual ~DiscretizedPoint() = default; 36 | 37 | /** Returns the bin number associated with this point. */ 38 | virtual long getBinNumber() const = 0; 39 | 40 | // Simple implementations usinng just the bin number. 41 | virtual bool equals(Point const &otherPoint) const override; 42 | virtual std::size_t hash() const override; 43 | virtual void print(std::ostream &os) const override; 44 | }; 45 | } /* namespace solver */ 46 | 47 | #endif /* SOLVER_DISCRETIZED_POINT_HPP_ */ 48 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/HistoricalData.hpp: -------------------------------------------------------------------------------- 1 | /** @file HistoricalData.hpp 2 | * 3 | * Defines an abstract base class for storing history-based heuristic information within a belief 4 | * node. 5 | */ 6 | #ifndef SOLVER_HISTORICALDATA_HPP_ 7 | #define SOLVER_HISTORICALDATA_HPP_ 8 | 9 | #include 10 | 11 | #include "solver/abstract-problem/Action.hpp" 12 | #include "solver/abstract-problem/Observation.hpp" 13 | 14 | namespace solver { 15 | /** An abstract base class for history-based heuristic info; each HistoricalData will be owned 16 | * by a single belief node. 17 | * 18 | * In order to function a HistoricalData must be able to generate a new, derived HistoricalData 19 | * instance for a child belief node, based on the action and observation taken to get there. 20 | */ 21 | class HistoricalData { 22 | public: 23 | HistoricalData() = default; 24 | virtual ~HistoricalData() = default; 25 | 26 | /** Creates a copy of this HistoricalData instance. */ 27 | virtual std::unique_ptr copy() const = 0; 28 | 29 | /** Generates a new child HistoricalData for a new belief node, based on the action taken 30 | * and observation received in going to that child node. 31 | */ 32 | virtual std::unique_ptr createChild(Action const &action, 33 | Observation const &observation) const = 0; 34 | 35 | /** Prints out the contents of this HistoricalData [optional] */ 36 | virtual void print(std::ostream &/*os*/) const {}; 37 | }; 38 | 39 | /** Uses the virtual print method to output HistoricalData to a stream. */ 40 | inline std::ostream &operator<<(std::ostream &os, HistoricalData const &data) { 41 | data.print(os); 42 | return os; 43 | } 44 | } /* namespace solver */ 45 | 46 | #endif /* SOLVER_HISTORICALDATA_HPP_ */ 47 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = abstract-problem 2 | CHILD_DIRS := heuristics 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/template.mk 7 | include .make/build.mk 8 | 9 | else 10 | REDIRECT=$(MODULE_NAME) 11 | .PHONY: $(MAKECMDGOALS) call-upwards 12 | $(MAKECMDGOALS): call-upwards ; 13 | call-upwards: 14 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 15 | endif 16 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/ModelChange.hpp: -------------------------------------------------------------------------------- 1 | /** @file ModelChange.hpp 2 | * 3 | * Defines an interface for storing changes to a model; this also defines a class 4 | * for a sequence of model changes, which is represented by a map from change times to 5 | * the associated changes at those times. 6 | */ 7 | #ifndef SOLVER_MODELCHANGE_HPP_ 8 | #define SOLVER_MODELCHANGE_HPP_ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "global.hpp" 15 | 16 | namespace solver { 17 | /** An interface for model changes. There are no mandatory methods, because it is up to each 18 | * individual implementation of Model to determine how it will interact with model changes. 19 | */ 20 | class ModelChange { 21 | public: 22 | ModelChange() = default; 23 | virtual ~ModelChange() = default; 24 | _NO_COPY_OR_MOVE (ModelChange); 25 | }; 26 | 27 | /** Defines a change sequence as a map of times to vectors of model changes. */ 28 | typedef std::map>> ChangeSequence; 29 | } /* namespace solver */ 30 | 31 | #endif /* SOLVER_MODELCHANGES_HPP_ */ 32 | 33 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/Observation.hpp: -------------------------------------------------------------------------------- 1 | /** @file Observation.hpp 2 | * 3 | * Defines the Observation interface; currently this is the same as Point, so this is just a 4 | * straight typedef. 5 | */ 6 | #ifndef SOLVER_OBSERVATION_HPP_ 7 | #define SOLVER_OBSERVATION_HPP_ 8 | 9 | #include "solver/abstract-problem/Point.hpp" 10 | 11 | namespace solver { 12 | /** Currently Observation has no requirements over and above Point, 13 | * so this is just a typedef. 14 | */ 15 | typedef Point Observation; 16 | } /* namespace solver */ 17 | 18 | #endif /* SOLVER_OBSERVATION_HPP_ */ 19 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/State.hpp: -------------------------------------------------------------------------------- 1 | /** @file State.hpp 2 | * 3 | * Defines the State interface; currently this is the same as Point, so this is just a straight 4 | * typedef. 5 | */ 6 | #ifndef SOLVER_STATE_HPP_ 7 | #define SOLVER_STATE_HPP_ 8 | 9 | #include "solver/abstract-problem/Point.hpp" 10 | 11 | namespace solver { 12 | /** Currently State has no requirements over and above Point, so this is just a typedef. */ 13 | typedef Point State; 14 | } /* namespace solver */ 15 | 16 | #endif /* SOLVER_STATE_HPP_ */ 17 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/TransitionParameters.hpp: -------------------------------------------------------------------------------- 1 | /** @file TransitionParameters.hpp 2 | * 3 | * An abstract base class for transition parameters, which allow intermediate generation of 4 | * steps in a sequence. If used, the idea is that the transition parameters can work as follows: 5 | * (s, a) => T => (o, r, s'). 6 | * 7 | * This is useful when model changes need to be applied, as the transition parameters can store 8 | * values such as sampled random numbers or intermediate calculations, allowing the transitions 9 | * to be recalculated more efficiently. Also, not having to re-randomize means that unnecessary 10 | * divergence of histories due to resampling can be avoided. 11 | */ 12 | #ifndef SOLVER_TRANSITIONPARAMETERS_HPP_ 13 | #define SOLVER_TRANSITIONPARAMETERS_HPP_ 14 | 15 | namespace solver { 16 | 17 | /** An abstract base to store transitional values for a generative model. 18 | * 19 | * This allows for intermediate values between a state-action pair to the subsequent next state, 20 | * observation and reward to be kept. 21 | * 22 | * The base class has no mandatory methods, because it is up to the Model to decide what to store; 23 | * the model can also choose not to use them at all by using null pointers. 24 | */ 25 | class TransitionParameters { 26 | public: 27 | TransitionParameters() = default; 28 | virtual ~TransitionParameters() = default; 29 | 30 | /** Prints the parameters in a human-readable way [optional]. */ 31 | virtual void print(std::ostream &/*os*/) const {}; 32 | }; 33 | 34 | /** Uses the virtual print method to output HistoricalData to a stream. */ 35 | inline std::ostream &operator<<(std::ostream &os, 36 | TransitionParameters const &tp) { 37 | tp.print(os); 38 | return os; 39 | } 40 | 41 | } /* namespace solver */ 42 | 43 | #endif /* SOLVER_TRANSITIONPARAMETERS_HPP_ */ 44 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/Vector.cpp: -------------------------------------------------------------------------------- 1 | /** @file Vector.cpp 2 | * 3 | * Provides default implementations for some basic methods of the vector class in terms of the 4 | * asVector() method. 5 | */ 6 | #include "solver/abstract-problem/Vector.hpp" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "global.hpp" 14 | 15 | namespace solver { 16 | 17 | double Vector::distanceTo(Point const &otherPoint) const { 18 | std::vector v1 = this->asVector(); 19 | std::vector v2 = static_cast( 20 | &otherPoint)->asVector(); 21 | std::vector::iterator i1 = v1.begin(); 22 | std::vector::iterator i2 = v2.begin(); 23 | double distanceSquared = 0; 24 | for (; i1 < v1.end(); i1++, i2++) { 25 | distanceSquared += std::pow(*i1 - *i2, 2); 26 | } 27 | return std::sqrt(distanceSquared); 28 | } 29 | 30 | bool Vector::equals(Point const &otherPoint) const { 31 | std::vector v1 = this->asVector(); 32 | std::vector v2 = static_cast( 33 | &otherPoint)->asVector(); 34 | std::vector::iterator i1 = v1.begin(); 35 | std::vector::iterator i2 = v2.begin(); 36 | 37 | for (; i1 < v1.end(); i1++, i2++) { 38 | if (*i1 != *i2) { 39 | return false; 40 | } 41 | } 42 | return true; 43 | } 44 | 45 | std::size_t Vector::hash() const { 46 | std::vector v1 = this->asVector(); 47 | 48 | std::size_t hashValue = 0; 49 | for (std::vector::iterator i1 = v1.begin(); i1 < v1.end(); i1++) { 50 | tapir::hash_combine(hashValue, *i1); 51 | } 52 | return hashValue; 53 | 54 | } 55 | 56 | void Vector::print(std::ostream &os) const { 57 | std::vector values = asVector(); 58 | os << "("; 59 | for (std::vector::const_iterator it = values.begin(); 60 | it < values.end(); it++) { 61 | os << *it; 62 | if (it + 1 != values.end()) { 63 | os << ","; 64 | } 65 | } 66 | os << ")"; 67 | } 68 | 69 | } /* namespace solver */ 70 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/Vector.hpp: -------------------------------------------------------------------------------- 1 | /** @file Vector.hpp 2 | * 3 | * An abstract extension of the Point class for points that can be easily be represented as 4 | * real vectors. 5 | * 6 | * This is primarily used to provide an interface for storing states (via VectorState, which is 7 | * currently just typedef of Vector) within an RTree. This allows for efficient lookup via 8 | * range-based queries. 9 | */ 10 | #ifndef SOLVER_VECTOR_HPP_ 11 | #define SOLVER_VECTOR_HPP_ 12 | 13 | #include // for size_t 14 | 15 | #include // for unique_ptr 16 | #include // for ostream 17 | #include 18 | 19 | #include "global.hpp" 20 | 21 | #include "solver/abstract-problem/Point.hpp" 22 | 23 | namespace solver { 24 | /** An abstract class for states that can easily be represented as real vectors. 25 | * 26 | * This is done via a virtual asVector() method; this is required in order to be able to store 27 | * states within the RTree. 28 | */ 29 | class Vector: public solver::Point { 30 | public: 31 | Vector() = default; 32 | virtual ~Vector() = default; 33 | 34 | /** Returns this vector in the form of an std::vector. 35 | * 36 | * This allows for vector-like functionality; we don't implement it directly as we are being 37 | * storage-agnostic here. 38 | */ 39 | virtual std::vector asVector() const = 0; 40 | 41 | // copy() remains unimplemented because we have no data! 42 | 43 | // The default implementation for distance uses a Euclidean metric. 44 | virtual double distanceTo(Point const &otherPoint) const override; 45 | 46 | // We will give default implementations for these methods using asVector(). 47 | virtual bool equals(Point const &otherPoint) const override; 48 | virtual std::size_t hash() const override; 49 | virtual void print(std::ostream &os) const override; 50 | }; 51 | 52 | } /* namespace solver */ 53 | 54 | #endif /* SOLVER_VECTOR_HPP_ */ 55 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/VectorState.hpp: -------------------------------------------------------------------------------- 1 | /** @file VectorState.hpp 2 | * 3 | * Defines the VectorState interface; currently this is the same as Vector, so this is just a 4 | * straight typedef. 5 | */ 6 | #ifndef SOLVER_VECTORSTATE_HPP_ 7 | #define SOLVER_VECTORSTATE_HPP_ 8 | 9 | #include "solver/abstract-problem/Vector.hpp" 10 | 11 | namespace solver { 12 | /** The VectorState class currently has the same interface as Vector, because there are no 13 | * special methods required by State. 14 | */ 15 | typedef Vector VectorState; 16 | } 17 | 18 | #endif /* SOLVER_VECTORSTATE_HPP_ */ 19 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/heuristics/HeuristicFunction.hpp: -------------------------------------------------------------------------------- 1 | /** @file HeuristicFunction.hpp 2 | * 3 | * Contains a typedef for the "HeuristicFunction" type, which is represented via a function that 4 | * takes pointers to a history entry, state, and/or historical data, and returns a double value. 5 | */ 6 | #ifndef SOLVER_HEURISTICFUNCTION_HPP_ 7 | #define SOLVER_HEURISTICFUNCTION_HPP_ 8 | 9 | #include 10 | 11 | #include "global.hpp" 12 | 13 | #include "solver/abstract-problem/State.hpp" 14 | 15 | namespace solver { 16 | class HistoricalData; 17 | class HistoryEntry; 18 | 19 | /** A typedef for the HeuristicFunction type. 20 | * 21 | * In order to allow for different types of heuristics, this heuristic takes three different 22 | * arguments via pointers. It is not necessary to use any or all of these arguments - you can 23 | * base a heuristic on whichever one you wish to. 24 | * 25 | * - Access to the history entry allows for heuristics based on the actual belief node, as 26 | * the history entry keeps a pointer to the associated belief. 27 | * - Access to the state allows for "perfect information" heuristics, e.g. using the MDP value 28 | * as a heuristic. 29 | * - Access to historical data allows simpler incorporation of history-based information into the 30 | * heuristic value. 31 | */ 32 | typedef std::function HeuristicFunction; 34 | 35 | } /* namespace solver */ 36 | 37 | #endif /* SOLVER_HEURISTICFUNCTION_HPP_ */ 38 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/heuristics/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = heuristics 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/heuristics/RolloutHeuristic.cpp: -------------------------------------------------------------------------------- 1 | /** @file RolloutHeuristic.cpp 2 | * 3 | * Contains the implementation of the RolloutHeuristic class. 4 | */ 5 | #include "solver/abstract-problem/heuristics/RolloutHeuristic.hpp" 6 | 7 | #include 8 | 9 | #include "solver/HistoryEntry.hpp" 10 | 11 | #include "solver/abstract-problem/HistoricalData.hpp" 12 | #include "solver/abstract-problem/Model.hpp" 13 | 14 | #include "solver/search/SearchStatus.hpp" 15 | 16 | namespace solver { 17 | RolloutHeuristic::RolloutHeuristic(Model *model, std::unique_ptr factory, 18 | HeuristicFunction heuristic) : 19 | model_(model), 20 | factory_(std::move(factory)), 21 | heuristic_(heuristic) { 22 | } 23 | 24 | double RolloutHeuristic::getHeuristicValue(HistoryEntry const *entry, 25 | State const *state, HistoricalData const *data) { 26 | SearchStatus status = SearchStatus::UNINITIALIZED; 27 | std::unique_ptr generator = factory_->createGenerator(status, 28 | entry, state, data); 29 | double value = 0.0; 30 | double netDiscount = 1.0; 31 | double discountFactor = model_->getOptions()->discountFactor; 32 | 33 | Model::StepResult result = generator->getStep(entry, state, data); 34 | std::unique_ptr currentState = state->copy(); 35 | std::unique_ptr currentData = nullptr; 36 | while (result.action != nullptr) { 37 | value += netDiscount * result.reward; 38 | netDiscount *= discountFactor; 39 | 40 | currentState = result.nextState->copy(); 41 | if (data != nullptr) { 42 | currentData = data->createChild(*result.action, *result.observation); 43 | data = currentData.get(); 44 | } 45 | result = generator->getStep(nullptr, result.nextState.get(), data); 46 | } 47 | value += netDiscount * heuristic_(nullptr, currentState.get(), data); 48 | return value; 49 | } 50 | 51 | HeuristicFunction RolloutHeuristic::asFunction() { 52 | using namespace std::placeholders; 53 | return std::bind(&RolloutHeuristic::getHeuristicValue, this, _1, _2, _3); 54 | } 55 | } /* namespace solver */ 56 | -------------------------------------------------------------------------------- /src/solver/abstract-problem/heuristics/RolloutHeuristic.hpp: -------------------------------------------------------------------------------- 1 | /** @file RolloutHeuristic.hpp 2 | * 3 | * Defines a simple heuristic that uses a rollout-based approach to estimate the value at the end 4 | * of a history sequence. 5 | */ 6 | #ifndef SOLVER_ROLLOUTHEURISTIC_HPP_ 7 | #define SOLVER_ROLLOUTHEURISTIC_HPP_ 8 | 9 | #include 10 | 11 | #include "global.hpp" 12 | 13 | #include "solver/abstract-problem/heuristics/HeuristicFunction.hpp" 14 | #include "solver/search/search_interface.hpp" 15 | 16 | namespace solver { 17 | class HistoryEntry; 18 | 19 | /** A simple heuristic that uses a rollout to estimate the value of a history. 20 | * 21 | * Unlike rollouts within the ABT algorithm, the steps rollouts will not be stored as history 22 | * entries, and new belief nodes will not be created for them. This avoids a lot of overhead and 23 | * allows for rollouts that behave like standard MCTS rollouts. 24 | * 25 | * A step generator is used to generate the steps for the heuristic, and a second, different 26 | * heuristic (other than this one) is applied to the final state if it is non-terminal. 27 | * 28 | * It is important to note that using this kind of rollout-based heuristic makes it more difficult 29 | * to determine which heuristic values need to be recalculated when changes occur. 30 | */ 31 | class RolloutHeuristic { 32 | public: 33 | /** Constructs a new rollout-based heuristic for the given model, and using the given 34 | * factory to generate new */ 35 | RolloutHeuristic(Model *model, std::unique_ptr factory, 36 | HeuristicFunction heuristic); 37 | ~RolloutHeuristic() = default; 38 | _NO_COPY_OR_MOVE(RolloutHeuristic); 39 | 40 | /** Uses a rollout to generate a heuristic value for the given entry, state and data. */ 41 | double getHeuristicValue(HistoryEntry const *entry, 42 | State const *state, HistoricalData const *data); 43 | 44 | /** Returns this heuristic as an actual HeuristicFunction. */ 45 | HeuristicFunction asFunction(); 46 | private: 47 | Model *model_; 48 | std::unique_ptr factory_; 49 | HeuristicFunction heuristic_; 50 | }; 51 | } /* namespace solver */ 52 | 53 | #endif /* SOLVER_ROLLOUTHEURISTIC_HPP_ */ 54 | -------------------------------------------------------------------------------- /src/solver/belief-estimators/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = belief-q-estimators 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/belief-estimators/estimators.hpp: -------------------------------------------------------------------------------- 1 | /** @file estimators.hpp 2 | * 3 | * Defines an interface for how backpropagation will be handled; this is done by providing a custom 4 | * way to estimate the value of a belief based on the q-values of its actions. 5 | * 6 | * This file also provides a few basic implementations of this interface via three core functions; 7 | * these allow for an estimate of the value of the node via one of: 8 | * average - the visit-weighted average of its action children 9 | * max - the maximum value of its action children 10 | * robust - the value of the action child with the greatest number of visits 11 | */ 12 | #ifndef SOLVER_ESTIMATORS_HPP_ 13 | #define SOLVER_ESTIMATORS_HPP_ 14 | 15 | #include // for unique_ptr 16 | 17 | #include "global.hpp" 18 | 19 | namespace solver { 20 | class BeliefNode; 21 | class Solver; 22 | 23 | /** An abstract base class to control how the values of belief nodes will be estimated. 24 | * 25 | * Every time a new belief node is created, the estimation strategy will be queried to set up 26 | * the estimator 27 | */ 28 | class EstimationStrategy { 29 | public: 30 | EstimationStrategy() = default; 31 | virtual ~EstimationStrategy() = default; 32 | /** Sets the value estimator for the given belief node. */ 33 | virtual void setValueEstimator(Solver *solver, BeliefNode *node) = 0; 34 | }; 35 | 36 | /** A simple implementation of EstimationStrategy using a functional programming interface. */ 37 | class EstimationFunction : public EstimationStrategy { 38 | public: 39 | /** Constructs a new estimator based on a function that takes a BeliefNode and returns a 40 | * double. 41 | */ 42 | EstimationFunction(std::function function); 43 | 44 | // Implementation of the key virtual setter method. 45 | virtual void setValueEstimator(Solver *solver, BeliefNode *node); 46 | 47 | private: 48 | /** The function used by this estimation strategy .*/ 49 | std::function function_; 50 | }; 51 | 52 | // 53 | namespace estimators { 54 | /** Returns the average of the q-values of the actions that can be taken from this node, weighted 55 | * by the number of visits for each action. */ 56 | double average(BeliefNode const *node); 57 | /** Returns the maximum q-value among the actions that can be taken from this node. */ 58 | double max(BeliefNode const *node); 59 | /** Returns the q-value of the action taken most frequently from this node. */ 60 | double robust(BeliefNode const *node); 61 | } /* namespace estimators */ 62 | } /* namespace solver */ 63 | 64 | #endif /* SOLVER_ESTIMATORS_HPP_ */ 65 | -------------------------------------------------------------------------------- /src/solver/cached_values.hpp: -------------------------------------------------------------------------------- 1 | /** @file cached_values.hpp 2 | * 3 | * Contains the classes used to store cached values for a belief node. 4 | */ 5 | #ifndef SOLVER_CACHED_VALUES_HPP_ 6 | #define SOLVER_CACHED_VALUES_HPP_ 7 | 8 | #include "global.hpp" 9 | 10 | #include "solver/BeliefNode.hpp" 11 | 12 | namespace solver { 13 | /** An interface class so that cached values can easily be stored in a vector. */ 14 | class BaseCachedValue { 15 | public: 16 | BaseCachedValue() = default; 17 | virtual ~BaseCachedValue() = default; 18 | }; 19 | 20 | /** Represents a cached value associated with a specific belief node. 21 | * 22 | * This is done by wrapping a function that takes a pointer to a belief node and returns a value 23 | * of the value type together with a pointer to the specific belief node this cache is associated 24 | * with. 25 | * 26 | * This allows the value to be stored, and also recalculated on demand. 27 | */ 28 | template class CachedValue : public BaseCachedValue { 29 | public: 30 | /** Constructs a new CachedValue for the given node, which will use the given function in order 31 | * to recalculate the cahced value whenever it is needed. 32 | */ 33 | CachedValue(BeliefNode const *node, std::function f) : 34 | node_(node), 35 | function_(f), 36 | cache_() { 37 | } 38 | _NO_COPY_OR_MOVE(CachedValue); 39 | 40 | /** Updates the cache inside this cached value by using the stored function on the associated 41 | * belief node. 42 | */ 43 | virtual void updateCache() { 44 | cache_ = function_(node_); 45 | } 46 | 47 | /** Returns the currently cached value. */ 48 | virtual T getCache() { 49 | return cache_; 50 | } 51 | private: 52 | /** The associated belief node. */ 53 | BeliefNode const *node_; 54 | /** The function. */ 55 | std::function function_; 56 | /** The cached value. */ 57 | T cache_; 58 | }; 59 | 60 | /** A template specialization for caches of type unique_ptr. 61 | * 62 | * Since a unique_ptr can only be moved we need to make a new Point via the method Point::copy() 63 | */ 64 | template<> inline std::unique_ptr 65 | CachedValue>::getCache() { 66 | return cache_->copy(); 67 | } 68 | } /* namespace solver */ 69 | 70 | #endif /* SOLVER_CACHED_VALUES_HPP_ */ 71 | -------------------------------------------------------------------------------- /src/solver/changes/DefaultHistoryCorrector.hpp: -------------------------------------------------------------------------------- 1 | /** @file DefaultHistoryCorrector.hpp 2 | * 3 | * Provides a default, general-purpose implementation of a HistoryCorrector that will be able to 4 | * deal with any POMDP model. 5 | */ 6 | #ifndef SOLVER_DEFAULTHISTORYCORRECTOR_HPP_ 7 | #define SOLVER_DEFAULTHISTORYCORRECTOR_HPP_ 8 | 9 | #include "solver/changes/HistoryCorrector.hpp" 10 | 11 | #include "solver/abstract-problem/heuristics/HeuristicFunction.hpp" 12 | 13 | namespace solver { 14 | class HistorySequence; 15 | 16 | /** A default HistoryCorrector implementation which should work quite well regardless of the 17 | * specific problem. 18 | */ 19 | class DefaultHistoryCorrector: public solver::HistoryCorrector { 20 | public: 21 | /** Constructs a new DefaultHistoryCorrector, which will be associated with the given Solver. 22 | * 23 | * The given heuristic will be used to estimate the value at the end of any sequence that 24 | * ends with a non-terminal state. 25 | */ 26 | DefaultHistoryCorrector(Solver *solver, HeuristicFunction heuristic); 27 | virtual ~DefaultHistoryCorrector() = default; 28 | _NO_COPY_OR_MOVE(DefaultHistoryCorrector); 29 | 30 | /** Revises the given history sequence; returns false if the sequence previously took an 31 | * illegal action and hence requires continuation via the default search algorithm. 32 | */ 33 | virtual bool reviseSequence(HistorySequence *sequence) override; 34 | private: 35 | HeuristicFunction heuristic_; 36 | }; 37 | 38 | } /* namespace solver */ 39 | 40 | #endif /* SOLVER_DEFAULTHISTORYCORRECTOR_HPP_ */ 41 | -------------------------------------------------------------------------------- /src/solver/changes/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = changes 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/indexing/FlaggingVisitor.cpp: -------------------------------------------------------------------------------- 1 | /** @file FlaggingVisitor.cpp 2 | * 3 | * Contains the implementation of the FlaggingVisitor class. 4 | */ 5 | #include "solver/indexing/FlaggingVisitor.hpp" 6 | 7 | #include "solver/changes/ChangeFlags.hpp" 8 | #include "solver/StatePool.hpp" 9 | 10 | namespace solver { 11 | 12 | FlaggingVisitor::FlaggingVisitor(StatePool *pool, 13 | ChangeFlags flagsToSet) : 14 | SpatialIndexVisitor(pool), 15 | flagsToSet_(flagsToSet) { 16 | } 17 | 18 | void FlaggingVisitor::visit(StateInfo* info) { 19 | getStatePool()->setChangeFlags(info, flagsToSet_); 20 | } 21 | 22 | } /* namespace solver */ 23 | -------------------------------------------------------------------------------- /src/solver/indexing/FlaggingVisitor.hpp: -------------------------------------------------------------------------------- 1 | /** @file FlaggingVisitor.hpp 2 | * 3 | * Defines the FlaggingVisitor class, which is useful for flagging affected states that are looked 4 | * up via an RTree-based StateIndex. 5 | */ 6 | #ifndef SOLVER_FLAGGINGVISITOR_HPP_ 7 | #define SOLVER_FLAGGINGVISITOR_HPP_ 8 | 9 | #include "solver/changes/ChangeFlags.hpp" 10 | 11 | #include "SpatialIndexVisitor.hpp" 12 | 13 | #include "global.hpp" 14 | 15 | namespace solver { 16 | class StateInfo; 17 | class StatePool; 18 | 19 | /** An implementation of SpatialIndexVisitor that flags any StateInfo it encounters with the given 20 | * flags. 21 | * 22 | * This is useful for purposes such as marking a range of states as deleted. 23 | */ 24 | class FlaggingVisitor: public solver::SpatialIndexVisitor { 25 | public: 26 | /** Constructs a new FlaggingVisitor which is associated with the given StatePool, and will 27 | * set the given flags in each StateInfo it encounters. 28 | */ 29 | FlaggingVisitor(StatePool *pool, ChangeFlags flagsToSet); 30 | virtual ~FlaggingVisitor() = default; 31 | _NO_COPY_OR_MOVE(FlaggingVisitor); 32 | 33 | /** The visitor method - flags the StateInfo with the flags. */ 34 | virtual void visit(StateInfo *info) override; 35 | /** The flags that will be set by this visitor. */ 36 | ChangeFlags flagsToSet_; 37 | }; 38 | 39 | } /* namespace solver */ 40 | 41 | #endif /* SOLVER_FLAGGINGVISITOR_HPP_ */ 42 | -------------------------------------------------------------------------------- /src/solver/indexing/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = indexing 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/indexing/RTree.hpp: -------------------------------------------------------------------------------- 1 | /** @file indexing/RTree.hpp 2 | * 3 | * Contains the RTree class, which is an implementation of the StateIndex interface that functions 4 | * as a thin wrapper for the RTree class of libspatialindex. 5 | */ 6 | #ifndef SOLVER_RTREE_HPP_ 7 | #define SOLVER_RTREE_HPP_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "global.hpp" 17 | 18 | #include "solver/indexing/StateIndex.hpp" 19 | 20 | namespace solver { 21 | class SpatialIndexVisitor; 22 | class StateInfo; 23 | class StatePool; 24 | 25 | /** A thin wrapper class that used the RTree class of libspatialindex to allow for range-based 26 | * state queries. 27 | * 28 | * The only constructor parameter is nSDim, the number of dimensions for a state vector. 29 | * 30 | * The core query method is boxQuery(), which takes a visitor and two state vectors (which must 31 | * clearly each have nSDim as their # of elements), and passes each StateInfo encountered during 32 | * the query onto the visitor. 33 | */ 34 | class RTree : public StateIndex { 35 | public: 36 | /** Constructs a new RTree with the given number of state dimensions. */ 37 | RTree(unsigned int nSDim); 38 | virtual ~RTree() = default; 39 | _NO_COPY_OR_MOVE(RTree); 40 | 41 | /** Resets this RTree, making it empty. */ 42 | virtual void reset() override; 43 | 44 | /** Adds the given StateInfo to this RTree. 45 | * NOTE: the same StateInfo / same ID must not have been added since the last reset. 46 | */ 47 | virtual void addStateInfo(StateInfo *stateInfo) override; 48 | 49 | /** Removes the given StateInfo from this RTree. 50 | * NOTE: Undefined behaviour results if this StateInfo hasn't been added since after the last 51 | * reset. 52 | */ 53 | virtual void removeStateInfo(StateInfo *stateInfo) override; 54 | 55 | /** Performs a range query on the RTree. All StateInfo that are encountered in the range of 56 | * the query will be passed on to the given visitor. 57 | */ 58 | virtual void boxQuery(SpatialIndexVisitor &visitor, 59 | std::vector lowCorner, 60 | std::vector highCorner); 61 | 62 | private: 63 | /** The number of state dimensions for this RTree. */ 64 | unsigned int nSDim_; 65 | /** The properties of the RTree. */ 66 | std::unique_ptr properties_; 67 | /** A storage manager for the RTree. */ 68 | std::unique_ptr storageManager_; 69 | /** The RTree itself. */ 70 | std::unique_ptr tree_; 71 | }; 72 | } /* namespace solver */ 73 | 74 | #endif /* SOLVER_RTREE_HPP_ */ 75 | -------------------------------------------------------------------------------- /src/solver/indexing/SpatialIndexVisitor.cpp: -------------------------------------------------------------------------------- 1 | /** @file SpatialIndexVisitor.cpp 2 | * 3 | * Contains the implementation of SpatialIndexVisitor. 4 | */ 5 | #include "solver/indexing/SpatialIndexVisitor.hpp" 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "solver/StatePool.hpp" 12 | 13 | namespace solver { 14 | 15 | SpatialIndexVisitor::SpatialIndexVisitor(StatePool *statePool) : 16 | statePool_(statePool) { 17 | } 18 | 19 | SpatialIndexVisitor::~SpatialIndexVisitor() { 20 | } 21 | 22 | void SpatialIndexVisitor::visitNode(const SpatialIndex::INode &/*node*/) { 23 | } 24 | 25 | /** This is the key visit method we need to use. Since we use the ID of the StateInfo as the ID 26 | * of the data in the SpatialIndex, we can look up the StateInfo by ID and pass it to the 27 | * visit() method. 28 | */ 29 | void SpatialIndexVisitor::visitData(const SpatialIndex::IData &data) { 30 | visit(statePool_->getInfoById(data.getIdentifier())); 31 | } 32 | 33 | void SpatialIndexVisitor::visitData(std::vector &/*v*/) { 34 | } 35 | 36 | StatePool *SpatialIndexVisitor::getStatePool() const { 37 | return statePool_; 38 | } 39 | 40 | } /* namespace solver */ 41 | -------------------------------------------------------------------------------- /src/solver/indexing/SpatialIndexVisitor.hpp: -------------------------------------------------------------------------------- 1 | /** @file SpatialIndexVisitor.hpp 2 | * 3 | * Defines the SpatialIndexVisitor class, which provides a visitor pattern-based approach to 4 | * deal with the results of querying states within an RTree. 5 | */ 6 | #ifndef SOLVER_SPATIALINDEXVISITOR_HPP_ 7 | #define SOLVER_SPATIALINDEXVISITOR_HPP_ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include "global.hpp" 14 | 15 | namespace solver { 16 | class StateInfo; 17 | class StatePool; 18 | 19 | /** An abstract class which implements the IVisitor interface from libspatialindex in order 20 | * to provide a visitor pattern approach to querying states within an RTree. 21 | * 22 | * The mandatory virtual method is the method visit(), which allows the visitor pattern to 23 | * handle each state visited during the query. 24 | */ 25 | class SpatialIndexVisitor: public SpatialIndex::IVisitor { 26 | public: 27 | /** Constructs a new SpatialIndexVisitor, which will query the given StatePool in order to 28 | * access the StateInfo instances associated with the entries in the spatial index. 29 | */ 30 | SpatialIndexVisitor(StatePool *statePool); 31 | virtual ~SpatialIndexVisitor(); 32 | _NO_COPY_OR_MOVE(SpatialIndexVisitor); 33 | 34 | /** The method used when visiting an individual node - we don't use this one. */ 35 | virtual void visitNode(const SpatialIndex::INode &node) override; 36 | /** This is the key method of IVisitor we need to override in order to implement the 37 | * functionality we need. 38 | */ 39 | virtual void visitData(const SpatialIndex::IData &data) override; 40 | 41 | /** The method used when visiting a vector of data - we don't use this one as we visit one 42 | * data entry at a time. 43 | */ 44 | virtual void visitData(std::vector &v) override; 45 | 46 | /** A method following the visitor design patter, allowing each StateInfo to be processed. */ 47 | virtual void visit(StateInfo *info) = 0; 48 | 49 | /** Returns the StatePool associated with this SpatialIndexVisitor. */ 50 | StatePool *getStatePool() const; 51 | 52 | private: 53 | /** The StatePool used by this visitor. */ 54 | StatePool *statePool_; 55 | }; 56 | 57 | } /* namespace solver */ 58 | 59 | #endif /* SOLVER_SPATIALINDEXVISITOR_HPP_ */ 60 | -------------------------------------------------------------------------------- /src/solver/indexing/StateIndex.hpp: -------------------------------------------------------------------------------- 1 | /** @file StateIndex.hpp 2 | * 3 | * Defines an interface allowing states to be indexed in a custom manner. 4 | * 5 | * Currently the only provided implementation of this interface is the RTree, which is a wrapper 6 | * for the RTree class within libspatialindex. 7 | * 8 | * The RTree-based approach should be sufficient for most purposes, but you can easily make your 9 | * own implementation of this interface if need be. 10 | */ 11 | #ifndef SOLVER_STATEINDEX_HPP_ 12 | #define SOLVER_STATEINDEX_HPP_ 13 | 14 | #include 15 | 16 | #include "global.hpp" 17 | 18 | namespace solver { 19 | class StateInfo; 20 | 21 | /** An interface class for storing states and looking them up in custom ways. 22 | * 23 | * Note that only a way of adding and removing states is mandatory; there are no required query 24 | * methods. This is because there could be many different kinds of query, depending on the 25 | * approach taken for indexing. 26 | * 27 | * You will need to define your own query methods if you implement this interface - your new 28 | * Model class can then interface with those query methods as needed. 29 | */ 30 | class StateIndex { 31 | public: 32 | StateIndex() = default; 33 | virtual ~StateIndex() = default; 34 | _NO_COPY_OR_MOVE(StateIndex); 35 | 36 | /** Resets the state index, making it empty. */ 37 | virtual void reset() = 0; 38 | 39 | /** Adds the given state info to the index. */ 40 | virtual void addStateInfo(StateInfo *stateInfo) = 0; 41 | 42 | /** Removes the given state info from the index. */ 43 | virtual void removeStateInfo(StateInfo *stateInfo) = 0; 44 | }; 45 | } /* namespace solver */ 46 | 47 | #endif /* SOLVER_STATEINDEX_HPP_ */ 48 | -------------------------------------------------------------------------------- /src/solver/mappings/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = mappings 2 | CHILD_DIRS = actions observations 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/template.mk 7 | OBJS_mappings = $(OBJS_action_mappings) $(OBJS_observation_mappings) 8 | include .make/build.mk 9 | 10 | else 11 | REDIRECT=$(MODULE_NAME) 12 | .PHONY: $(MAKECMDGOALS) call-upwards 13 | $(MAKECMDGOALS): call-upwards ; 14 | call-upwards: 15 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 16 | endif 17 | -------------------------------------------------------------------------------- /src/solver/mappings/actions/ActionPool.hpp: -------------------------------------------------------------------------------- 1 | /** @file ActionPool.hpp 2 | * 3 | * Defines the ActionPool interface, which allows customization of how the mapping for each 4 | * individual belief node is set up. 5 | * 6 | * Using a single class in this way allows certain aspects of the mappings to be stored globally, 7 | * e.g. to keep statistics that are shared across all of the mappings rather than stored on 8 | * a per-mapping basis. 9 | */ 10 | #ifndef SOLVER_ACTIONPOOL_HPP_ 11 | #define SOLVER_ACTIONPOOL_HPP_ 12 | 13 | #include // for unique_ptr 14 | 15 | #include "global.hpp" 16 | 17 | #include "solver/abstract-problem/Action.hpp" // for Action 18 | #include "solver/BeliefNode.hpp" 19 | 20 | namespace solver { 21 | class ActionMapping; 22 | class ActionNode; 23 | class BeliefNode; 24 | class HistoricalData; 25 | class ObservationPool; 26 | class Solver; 27 | 28 | /** An interface class which is a factory for creating action mappings. 29 | * 30 | * Using a central factory instance allows each individual mapping to interface with this single 31 | * instance; this allows shared statistics to be kept. 32 | */ 33 | class ActionPool { 34 | public: 35 | ActionPool() = default; 36 | virtual ~ActionPool() = default; 37 | /** Creates an action mapping for the given belief node. */ 38 | virtual std::unique_ptr createActionMapping(BeliefNode *node) = 0; 39 | }; 40 | } /* namespace solver */ 41 | 42 | #endif /* SOLVER_ACTIONPOOL_HPP_ */ 43 | -------------------------------------------------------------------------------- /src/solver/mappings/actions/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = action_mappings 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/mappings/actions/enumerated_actions.cpp: -------------------------------------------------------------------------------- 1 | /** @file enumerated_actions.cpp 2 | * 3 | * Contains an implementation for the action mapping interfaces in terms of an enumerated 4 | * set of actions, which is done via a simple implementation of the abstract class 5 | * DiscretizedActionPool. 6 | */ 7 | #include "solver/mappings/actions/enumerated_actions.hpp" 8 | 9 | namespace solver { 10 | /* ------------------- EnumeratedActionPool ------------------- */ 11 | EnumeratedActionPool::EnumeratedActionPool(Model *model, 12 | std::vector> allActions) : 13 | randGen_(model->getRandomGenerator()), 14 | allActions_(std::move(allActions)) { 15 | } 16 | long EnumeratedActionPool::getNumberOfBins() { 17 | return allActions_.size(); 18 | } 19 | std::unique_ptr EnumeratedActionPool::sampleAnAction( 20 | long binNumber) { 21 | return allActions_[binNumber]->copy(); 22 | } 23 | 24 | std::vector EnumeratedActionPool::createBinSequence(BeliefNode */*node*/) { 25 | std::vector bins; 26 | for (int i = 0; i < getNumberOfBins(); i++) { 27 | bins.push_back(i); 28 | } 29 | std::shuffle(bins.begin(), bins.end(), *randGen_); 30 | return std::move(bins); 31 | } 32 | } /* namespace solver */ 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/solver/mappings/observations/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = observation_mappings 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/mappings/observations/ObservationMappingEntry.hpp: -------------------------------------------------------------------------------- 1 | /** @file ObservationMappingEntry.hpp 2 | * 3 | * Defines the ObservationMappingEntry interface, which defines the core methods for an edge in 4 | * the tree between an ActionNode and a subsequent BeliefNode. 5 | * 6 | * In particular, this involves storing the visit count for this specific edge in the tree. 7 | */ 8 | #ifndef SOLVER_OBSERVATIONMAPPINGENTRY_HPP_ 9 | #define SOLVER_OBSERVATIONMAPPINGENTRY_HPP_ 10 | 11 | #include // for unique_ptr 12 | 13 | #include "global.hpp" 14 | 15 | #include "solver/abstract-problem/Observation.hpp" // for Observation 16 | 17 | namespace solver { 18 | class ActionNode; 19 | class BeliefNode; 20 | class ObservationMapping; 21 | 22 | /** An interface that represents an edge in the belief tree between an action node and a 23 | * subsequent belief node; this interface is provided so that observations can be grouped together 24 | * in custom ways. 25 | * 26 | * Conceptually, this corresponds to a (belief, action, observation) triplet (b, a, o), or, 27 | * equivalently, it can be seen as the parent edge of the resulting belief (b'). 28 | * 29 | * Apart from grouping observations together, the primary purpose of this entry is to store 30 | * a visit count - i.e. the number of times this edge has been visited during searching. 31 | */ 32 | class ObservationMappingEntry { 33 | public: 34 | ObservationMappingEntry() = default; 35 | virtual ~ObservationMappingEntry() = default; 36 | 37 | /** Returns the mapping this entry belongs to. */ 38 | virtual ObservationMapping *getMapping() const = 0; 39 | /** Returns the observation for this entry. */ 40 | virtual std::unique_ptr getObservation() const = 0; 41 | /** Returns the belief node for this entry. */ 42 | virtual BeliefNode *getBeliefNode() const = 0; 43 | /** Returns the visit count for this entry. */ 44 | virtual long getVisitCount() const = 0; 45 | 46 | /** Updates the visit count for this observation. */ 47 | virtual void updateVisitCount(long deltaNVisits) = 0; 48 | }; 49 | } /* namespace solver */ 50 | 51 | #endif /* SOLVER_OBSERVATIONMAPPINGENTRY_HPP_ */ 52 | -------------------------------------------------------------------------------- /src/solver/mappings/observations/ObservationPool.hpp: -------------------------------------------------------------------------------- 1 | /** @file ObservationPool.hpp 2 | * 3 | * Defines the ObservationPool interface, which allows customization of how the mapping for each 4 | * individual action node is set up. 5 | * 6 | * Using a single class in this way allows certain aspects of the mappings to be stored globally, 7 | * e.g. to keep statistics that are shared across all of the mappings rather than stored on 8 | * a per-mapping basis. 9 | */ 10 | #ifndef SOLVER_OBSERVATIONPOOL_HPP_ 11 | #define SOLVER_OBSERVATIONPOOL_HPP_ 12 | 13 | #include "global.hpp" 14 | 15 | namespace solver { 16 | class ActionPool; 17 | class ObservationMapping; 18 | class Solver; 19 | 20 | /** An interface class which is a factory for creating observation mappings. 21 | * 22 | * Using a central factory instance allows each individual mapping to interface with this single 23 | * instance; this allows shared statistics to be kept. 24 | */ 25 | class ObservationPool { 26 | public: 27 | ObservationPool() = default; 28 | virtual ~ObservationPool() = default; 29 | /** Creates an observation mapping for the given action node. */ 30 | virtual std::unique_ptr createObservationMapping(ActionNode *owner) = 0; 31 | }; 32 | 33 | } /* namespace solver */ 34 | 35 | #endif /* SOLVER_OBSERVATIONPOOL_HPP_ */ 36 | -------------------------------------------------------------------------------- /src/solver/search/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = search 2 | CHILD_DIRS := steppers action-choosers 3 | 4 | ifdef HAS_ROOT_MAKEFILE 5 | 6 | include .make/template.mk 7 | include .make/build.mk 8 | 9 | else 10 | REDIRECT=$(MODULE_NAME) 11 | .PHONY: $(MAKECMDGOALS) call-upwards 12 | $(MAKECMDGOALS): call-upwards ; 13 | call-upwards: 14 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 15 | endif 16 | -------------------------------------------------------------------------------- /src/solver/search/SearchStatus.hpp: -------------------------------------------------------------------------------- 1 | /** @file SearchStatus.hpp 2 | * 3 | * Defines a basic enumeration of the different states the search for an individual history 4 | * could be in. 5 | */ 6 | #ifndef SOLVER_SEARCHSTATUS_HPP_ 7 | #define SOLVER_SEARCHSTATUS_HPP_ 8 | 9 | namespace solver { 10 | 11 | /** An enumeration of possible states for searching an individual history. */ 12 | enum class SearchStatus : long { 13 | UNINITIALIZED, // Not yet set up - could indicate a failure to meet preliminary conditions. 14 | INITIAL, // Ready to go. 15 | OUT_OF_STEPS, // The step generator is out of steps - 16 | FINISHED, // The history is finished now (i.e. a terminal state, or a non-terminal state 17 | // for which the heuristic value has already been calculated). 18 | ERROR // An error occurred in the search (e.g. UCB had no legal actions to choose from) 19 | }; 20 | } /* namespace solver */ 21 | 22 | #endif /* SOLVER_SEARCHSTATUS_HPP_ */ 23 | -------------------------------------------------------------------------------- /src/solver/search/action-choosers/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = action-choosers 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/search/action-choosers/choosers.hpp: -------------------------------------------------------------------------------- 1 | /** @file choosers.hpp 2 | * 3 | * Defines some useful basic functions for selecting an action from a belief node. 4 | */ 5 | #ifndef SOLVER_CHOOSERS_HPP_ 6 | #define SOLVER_CHOOSERS_HPP_ 7 | 8 | #include // for unique_ptr 9 | 10 | #include "global.hpp" 11 | 12 | #include "solver/abstract-problem/Action.hpp" 13 | 14 | namespace solver { 15 | class BeliefNode; 16 | class Solver; 17 | 18 | namespace choosers { 19 | /** Returns the action with the maximum estimate Q-value. */ 20 | std::unique_ptr max_action(BeliefNode const *node); 21 | /** Returns the action with the highest visit count (ties are broken by max. value) */ 22 | std::unique_ptr robust_action(BeliefNode const *node); 23 | /** Returns the action with the highest UCB value, using the given exploration coefficient. */ 24 | std::unique_ptr ucb_action(BeliefNode const *node, double explorationCoefficient); 25 | } /* namespace choosers */ 26 | } /* namespace solver */ 27 | 28 | #endif /* SOLVER_CHOOSERS_HPP_ */ 29 | -------------------------------------------------------------------------------- /src/solver/search/steppers/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = steppers 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /src/solver/search/steppers/default_rollout.cpp: -------------------------------------------------------------------------------- 1 | /** @file default_rollout.cpp 2 | * 3 | * Contains the implementation for a basic rollout strategy, which queries the model for a 4 | * history-based rollout action at every time step. 5 | */ 6 | #include "solver/search/steppers/default_rollout.hpp" 7 | 8 | #include "solver/BeliefNode.hpp" 9 | #include "solver/HistoryEntry.hpp" 10 | #include "solver/HistorySequence.hpp" 11 | #include "solver/Solver.hpp" 12 | 13 | #include "solver/abstract-problem/Model.hpp" 14 | 15 | #include "solver/mappings/actions/ActionPool.hpp" 16 | #include "solver/mappings/actions/ActionMapping.hpp" 17 | 18 | namespace solver { 19 | /* ------------------------- DefaultRolloutGenerator ------------------------- */ 20 | DefaultRolloutGenerator::DefaultRolloutGenerator(SearchStatus &status, 21 | Solver *solver, long maxNSteps) : 22 | StepGenerator(status), 23 | model_(solver->getModel()), 24 | maxNSteps_(maxNSteps), 25 | currentNSteps_(0) { 26 | status_ = SearchStatus::INITIAL; 27 | } 28 | 29 | Model::StepResult DefaultRolloutGenerator::getStep(HistoryEntry const *entry, State const *state, 30 | HistoricalData const *data) { 31 | // If we've hit the step limit, we don't generate any more steps. 32 | if (currentNSteps_ >= maxNSteps_) { 33 | status_ = SearchStatus::OUT_OF_STEPS; 34 | return Model::StepResult { }; 35 | } 36 | 37 | // Otherwise, we generate a new step and return it. 38 | currentNSteps_++; 39 | std::unique_ptr action = model_->getRolloutAction(entry, state, data); 40 | return model_->generateStep(*state, *action); 41 | } 42 | 43 | /* ------------------------- DefaultRolloutFactory ------------------------- */ 44 | DefaultRolloutFactory::DefaultRolloutFactory(Solver *solver, long maxNSteps) : 45 | solver_(solver), 46 | maxNSteps_(maxNSteps) { 47 | } 48 | 49 | std::unique_ptr DefaultRolloutFactory::createGenerator(SearchStatus &status, 50 | HistoryEntry const */*entry*/, State const */*state*/, HistoricalData const */*data*/) { 51 | return std::make_unique(status, solver_, maxNSteps_); 52 | } 53 | 54 | } /* namespace solver */ 55 | -------------------------------------------------------------------------------- /src/solver/search/steppers/default_rollout.hpp: -------------------------------------------------------------------------------- 1 | /** @file default_rollout.hpp 2 | * 3 | * Defines a simple rollout strategy that queries the model for a history-based rollout action. 4 | * This is done via the StepGenerator and StepGeneratory factory classes in search_interface.hpp. 5 | */ 6 | #ifndef SOLVER_DEFAULTROLLOUTSTRATEGY_HPP_ 7 | #define SOLVER_DEFAULTROLLOUTSTRATEGY_HPP_ 8 | 9 | #include "solver/search/SearchStatus.hpp" 10 | #include "solver/search/search_interface.hpp" 11 | 12 | namespace solver { 13 | class HistoricalData; 14 | class HistorySequence; 15 | class Solver; 16 | 17 | /** A StepGenerator implementation that simply queries the model for a rollout action at each 18 | * time step. 19 | */ 20 | class DefaultRolloutGenerator: public StepGenerator { 21 | public: 22 | /** Makes a new DefaultRolloutGenerator, which will be associated with the given solver, and 23 | * will only take the specified maximum # of steps in depth. 24 | */ 25 | DefaultRolloutGenerator(SearchStatus &status, Solver *solver, long maxNSteps); 26 | virtual ~DefaultRolloutGenerator() = default; 27 | _NO_COPY_OR_MOVE(DefaultRolloutGenerator); 28 | 29 | virtual Model::StepResult getStep(HistoryEntry const *entry, 30 | State const *state, HistoricalData const *data) override; 31 | 32 | private: 33 | /** The associated model, which will be queried to generate steps. */ 34 | Model *model_; 35 | /** The maximum # of steps to take. */ 36 | long maxNSteps_; 37 | /** The number of steps taken so far. */ 38 | long currentNSteps_; 39 | }; 40 | 41 | 42 | /** A factory class to create instances of DefaultRolloutGenerator. */ 43 | class DefaultRolloutFactory: public StepGeneratorFactory { 44 | public: 45 | /** Creates a new rollout factory with the given solver, and the given max # of steps. */ 46 | DefaultRolloutFactory(Solver *solver, long maxNSteps); 47 | virtual ~DefaultRolloutFactory() = default; 48 | _NO_COPY_OR_MOVE(DefaultRolloutFactory); 49 | 50 | virtual std::unique_ptr createGenerator(SearchStatus &status, 51 | HistoryEntry const *entry, State const *state, HistoricalData const *data) override; 52 | 53 | private: 54 | /** The associated solver. */ 55 | Solver *solver_; 56 | /** The maximum number of steps to take in a rollout. */ 57 | long maxNSteps_; 58 | }; 59 | 60 | } /* namespace solver */ 61 | 62 | #endif /* SOLVER_DEFAULTROLLOUTSTRATEGY_HPP_ */ 63 | -------------------------------------------------------------------------------- /src/solver/search/steppers/gps_search.cpp: -------------------------------------------------------------------------------- 1 | /** @file gps_search.cpp 2 | * 3 | * Contains the basic implementation code for a SearchStrategy using GPS 4 | * search. 5 | */ 6 | #include "solver/search/steppers/gps_search.hpp" 7 | 8 | #include "solver/ActionNode.hpp" 9 | #include "solver/BeliefNode.hpp" 10 | #include "solver/HistoryEntry.hpp" 11 | #include "solver/HistorySequence.hpp" 12 | #include "solver/Solver.hpp" 13 | 14 | #include "solver/search/action-choosers/choosers.hpp" 15 | 16 | #include "solver/mappings/actions/ActionMapping.hpp" 17 | 18 | namespace solver { 19 | GpsStepGenerator::GpsStepGenerator(SearchStatus &status, Solver *solver, choosers::GpsChooserOptions theOptions) : 20 | StepGenerator(status), 21 | model(solver->getModel()), 22 | options(theOptions), 23 | choseUnvisitedAction(false) { 24 | status_ = SearchStatus::INITIAL; 25 | } 26 | 27 | Model::StepResult GpsStepGenerator::getStep(HistoryEntry const *entry, State const *state, HistoricalData const */*data*/) { 28 | 29 | // If we previously chose a new action that hadn't been tried before, the search is over. 30 | if (choseUnvisitedAction) { 31 | // We've reached the new leaf node - this search is over. 32 | status_ = SearchStatus::OUT_OF_STEPS; 33 | return Model::StepResult { }; 34 | } 35 | 36 | // Retrieve the mapping. 37 | BeliefNode *currentNode = entry->getAssociatedBeliefNode(); 38 | //ActionMapping *mapping = currentNode->getMapping(); 39 | 40 | choosers::GpsChooserResponse chooserResponse = choosers::gps_ucb_action(currentNode, *model, options); 41 | 42 | if (!chooserResponse.actionIsVisited) { 43 | choseUnvisitedAction = true; 44 | } 45 | 46 | // NO action -> error! 47 | if (chooserResponse.action == nullptr) { 48 | debug::show_message("ERROR: node has no actions!?"); 49 | status_ = SearchStatus::ERROR; 50 | return Model::StepResult { }; 51 | } 52 | 53 | // Use the model to generate the step. 54 | return model->generateStep(*state, *(chooserResponse.action) ); 55 | 56 | } 57 | 58 | GpsStepGeneratorFactory::GpsStepGeneratorFactory(Solver *theSolver, choosers::GpsChooserOptions theOptions) : 59 | solver(theSolver), 60 | options(theOptions) { 61 | } 62 | 63 | std::unique_ptr GpsStepGeneratorFactory::createGenerator(SearchStatus &status, HistoryEntry const */*entry*/, State const */*state*/, HistoricalData const */*data*/) { 64 | return std::make_unique(status, solver, options); 65 | } 66 | } /* namespace solver */ 67 | -------------------------------------------------------------------------------- /src/solver/search/steppers/gps_search.hpp: -------------------------------------------------------------------------------- 1 | /** @file gps_search.hpp 2 | * 3 | * Contains the necessary classes for a GPS search strategy; this is done via an 4 | * implementation of StepGenerator and StepGeneratorFactory; 5 | * the latter can then be wrapped inside a BasicSearchStrategy. 6 | */ 7 | #ifndef SOLVER_GPS_SEARCH_HPP_ 8 | #define SOLVER_GPS_SEARCH_HPP_ 9 | 10 | #include "solver/search/SearchStatus.hpp" 11 | #include "solver/search/search_interface.hpp" 12 | 13 | #include "solver/search/action-choosers/gps_choosers.hpp" 14 | 15 | namespace solver { 16 | /** A generator for steps that uses GPS to select actions. 17 | * 18 | * The action will be selected using GPS as long as the last action has been tried before; once 19 | * an action that has never been tried before is encountered, the search will terminate. 20 | */ 21 | class GpsStepGenerator : public StepGenerator { 22 | public: 23 | /** Creates a new GpsStepGenerator associated with the given solver, using the given 24 | * options for GPS. 25 | */ 26 | GpsStepGenerator(SearchStatus &status, Solver *solver, choosers::GpsChooserOptions options); 27 | ~GpsStepGenerator() = default; 28 | _NO_COPY_OR_MOVE(GpsStepGenerator); 29 | 30 | virtual Model::StepResult getStep(HistoryEntry const *entry, State const *state, HistoricalData const *data) override; 31 | 32 | private: 33 | /** The model to use to generate next steps. */ 34 | Model *model; 35 | /** Settings for the GPS search. */ 36 | choosers::GpsChooserOptions options; 37 | 38 | /** True iff the last action selected hadn't been tried before. */ 39 | bool choseUnvisitedAction; 40 | }; 41 | 42 | 43 | 44 | /** A factory class for generating instances of GpsStepGenerator. */ 45 | class GpsStepGeneratorFactory: public StepGeneratorFactory { 46 | public: 47 | /** Creates a new factory associated with the given solver, and with the given options. */ 48 | GpsStepGeneratorFactory(Solver *solver, choosers::GpsChooserOptions options); 49 | virtual ~GpsStepGeneratorFactory() = default; 50 | _NO_COPY_OR_MOVE(GpsStepGeneratorFactory); 51 | 52 | virtual std::unique_ptr createGenerator(SearchStatus &status, HistoryEntry const *entry, State const *state, HistoricalData const *data) override; 53 | private: 54 | /** The associated solver. */ 55 | Solver *solver; 56 | /** GPS search options */ 57 | choosers::GpsChooserOptions options; 58 | }; 59 | 60 | } /* namespace solver */ 61 | 62 | #endif /* SOLVER_GPS_SEARCH_HPP_ */ 63 | -------------------------------------------------------------------------------- /src/solver/search/steppers/ucb_search.hpp: -------------------------------------------------------------------------------- 1 | /** @file ucb_search.hpp 2 | * 3 | * Contains the necessary classes for a UCB-based search strategy; this is done via an 4 | * implementation of StepGenerator and StepGeneratorFactory; the latter can then be wrapped 5 | * inside a BasicSearchStrategy. 6 | */ 7 | #ifndef SOLVER_UCB_SEARCH_HPP_ 8 | #define SOLVER_UCB_SEARCH_HPP_ 9 | 10 | #include "solver/search/SearchStatus.hpp" 11 | #include "solver/search/search_interface.hpp" 12 | 13 | namespace solver { 14 | /** A generator for steps that uses UCB to select actions. 15 | * 16 | * The action will be selected using UCB as long as the last action has been tried before; once 17 | * an action that has never been tried before is encountered, the search will terminate. 18 | */ 19 | class UcbStepGenerator : public StepGenerator { 20 | public: 21 | /** Creates a new UcbStepGenerator associated with the given solver, and using the given 22 | * value for the UCB exploration coefficient. 23 | */ 24 | UcbStepGenerator(SearchStatus &status, Solver *solver, double explorationCoefficient); 25 | ~UcbStepGenerator() = default; 26 | _NO_COPY_OR_MOVE(UcbStepGenerator); 27 | 28 | virtual Model::StepResult getStep(HistoryEntry const *entry, 29 | State const *state, HistoricalData const *data) override; 30 | 31 | private: 32 | /** The model to use to generate next steps. */ 33 | Model *model_; 34 | /** The exploration coefficient for UCB. */ 35 | double explorationCoefficient_; 36 | 37 | /** True iff the last action selected hadn't been tried before. */ 38 | bool choseUnvisitedAction_; 39 | }; 40 | 41 | /** A factory class for generating instances of UcbStepGenerator. */ 42 | class UcbStepGeneratorFactory: public StepGeneratorFactory { 43 | public: 44 | /** Creates a new factory associated with the given solver, and with the given UCB exploration 45 | * coefficient. 46 | */ 47 | UcbStepGeneratorFactory(Solver *solver, double explorationCoefficient); 48 | virtual ~UcbStepGeneratorFactory() = default; 49 | _NO_COPY_OR_MOVE(UcbStepGeneratorFactory); 50 | 51 | virtual std::unique_ptr createGenerator(SearchStatus &status, 52 | HistoryEntry const *entry, State const *state, HistoricalData const *data) override; 53 | private: 54 | /** The associated solver. */ 55 | Solver *solver_; 56 | /** The exploration coefficient for UCB. */ 57 | double explorationCoefficient_; 58 | }; 59 | 60 | } /* namespace solver */ 61 | 62 | #endif /* SOLVER_UCB_SEARCH_HPP_ */ 63 | -------------------------------------------------------------------------------- /src/solver/serialization/Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = serialization 2 | 3 | ifdef HAS_ROOT_MAKEFILE 4 | 5 | include .make/template.mk 6 | include .make/build.mk 7 | 8 | else 9 | REDIRECT=$(MODULE_NAME) 10 | .PHONY: $(MAKECMDGOALS) call-upwards 11 | $(MAKECMDGOALS): call-upwards ; 12 | call-upwards: 13 | @$(MAKE) --no-print-directory -C .. $(MAKECMDGOALS) REDIRECT=$(REDIRECT) 14 | endif 15 | -------------------------------------------------------------------------------- /srv/simRosCopyPasteObjects.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simxInt simxCopyPasteObjects(const simxInt* objectHandles,simxInt objectCount,simxInt** newObjectHandles,simxInt* newObjectCount) 3 | # 4 | 5 | int32[] objectHandles 6 | --- 7 | int32 result 8 | int32[] newObjectHandles 9 | -------------------------------------------------------------------------------- /srv/simRosGetObjectHandle.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simInt simGetObjectHandle(const simChar* objectName) 3 | # 4 | 5 | string objectName 6 | --- 7 | int32 handle 8 | -------------------------------------------------------------------------------- /srv/simRosGetObjectPose.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simInt simGetObjectPosition(simInt objectHandle,simInt relativeToObjectHandle,simFloat* position) 3 | # simInt simGetObjectQuaternion(simInt objectHandle,simInt relativeToObjectHandle,simFloat* quat) 4 | 5 | int32 handle 6 | int32 relativeToObjectHandle 7 | --- 8 | int32 result 9 | geometry_msgs/PoseStamped pose 10 | -------------------------------------------------------------------------------- /srv/simRosLoadScene.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simxInt simxLoadScene(const simxChar* scenePathAndName,simxChar options,simxInt operationMode) 3 | # 4 | 5 | string fileName 6 | --- 7 | int32 result 8 | -------------------------------------------------------------------------------- /srv/simRosSetObjectPosition.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simInt simSetObjectPosition(simInt objectHandle,simInt relativeToObjectHandle,simFloat* position) 3 | # 4 | 5 | int32 handle 6 | int32 relativeToObjectHandle 7 | geometry_msgs/Point position 8 | --- 9 | int32 result 10 | -------------------------------------------------------------------------------- /srv/simRosStartSimulation.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simInt simStartSimulation() 3 | # 4 | 5 | --- 6 | int32 result 7 | -------------------------------------------------------------------------------- /srv/simRosStopSimulation.srv: -------------------------------------------------------------------------------- 1 | # 2 | # simInt simStopSimulation() 3 | # 4 | 5 | --- 6 | int32 result 7 | --------------------------------------------------------------------------------