$search
00001 /* 00002 * Copyright (c) 2008, Maxim Likhachev 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the University of Pennsylvania nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 #ifndef __UTILS_H_ 00030 #define __UTILS_H_ 00031 00032 #ifndef WIN32 00033 #define __max(x,y) (x>y?x:y) 00034 #define __min(x,y) (x>y?y:x) 00035 #endif 00036 00037 00038 #define NORMALIZEDISCTHETA(THETA, THETADIRS) (((THETA>=0)?((THETA)%(THETADIRS)):(((THETA)%(THETADIRS)+THETADIRS)%THETADIRS))) 00039 00040 #define CONTXY2DISC(X, CELLSIZE) (((X)>=0)?((int)((X)/(CELLSIZE))):((int)((X)/(CELLSIZE))-1)) 00041 #define DISCXY2CONT(X, CELLSIZE) ((X)*(CELLSIZE) + (CELLSIZE)/2.0) 00042 00043 00044 #define PI_CONST 3.141592653589793238462643383279502884 00045 00046 #define UNKNOWN_COST 1000000 00047 00048 typedef struct { 00049 int X1, Y1; 00050 int X2, Y2; 00051 int Increment; 00052 int UsingYIndex; 00053 int DeltaX, DeltaY; 00054 int DTerm; 00055 int IncrE, IncrNE; 00056 int XIndex, YIndex; 00057 int Flipped; 00058 } bresenham_param_t; 00059 00060 00061 typedef struct { 00062 int x; 00063 int y; 00064 } sbpl_2Dcell_t; 00065 00066 00067 typedef struct { 00068 double x; 00069 double y; 00070 } sbpl_2Dpt_t; 00071 00072 typedef struct BINARYHIDDENVARIABLE 00073 { 00074 int h_ID; //ID of the variable 00075 unsigned char Prob; 00076 00077 }sbpl_BinaryHiddenVar_t; 00078 00079 typedef struct BELIEFSTATEWITHBINARYHVALS 00080 { 00081 int s_ID; //ID of S part of state-space 00082 vector<sbpl_BinaryHiddenVar_t> updatedhvaluesV; //vector of updated h-values, the rest are the same as at the start state 00083 00084 00085 }sbpl_BeliefStatewithBinaryh_t; 00086 00087 typedef struct POLICYBELIEFSTATEWITHBINARYHVALS 00088 { 00089 00090 sbpl_BeliefStatewithBinaryh_t BeliefState; //current belief state 00091 00092 int nextpolicyactionID; //ID of the next policy action if exists (otherwise -1) 00093 vector<int> outcomestateIndexV; //indices of the outcome states of the policy action. If outcome state is not in the policy, then it is -1 00094 00095 }sbpl_PolicyStatewithBinaryh_t; 00096 00097 00098 00099 00100 //function prototypes 00101 #if MEM_CHECK == 1 00102 void DisableMemCheck(); 00103 void EnableMemCheck(); 00104 #endif 00105 void CheckMDP(CMDP* mdp); 00106 void PrintMatrix(int** matrix, int rows, int cols, FILE* fOut); 00107 void EvaluatePolicy(CMDP* PolicyMDP, int StartStateID, int GoalStateID, 00108 double* PolValue, bool *bFullPolicy, double *Pcgoal, 00109 int* nMerges, bool *bCycles); 00110 int ComputeNumofStochasticActions(CMDP* pMDP); 00111 00115 void get_bresenham_parameters(int p1x, int p1y, int p2x, int p2y, bresenham_param_t *params); 00119 void get_current_point(bresenham_param_t *params, int *x, int *y); 00123 int get_next_point(bresenham_param_t *params); 00124 00128 double DiscTheta2Cont(int nTheta, int NUMOFANGLEVALS); 00132 int ContTheta2Disc(double fTheta, int NUMOFANGLEVALS); 00133 00138 double normalizeAngle(double angle); 00139 00142 double computeMinUnsignedAngleDiff(double angle1, double angle2); 00143 00146 bool IsInsideFootprint(sbpl_2Dpt_t pt, vector<sbpl_2Dpt_t>* bounding_polygon); 00147 00150 void computeDistancestoNonfreeAreas(unsigned char** Grid2D, int width_x, int height_y, unsigned char obsthresh, float** disttoObs_incells, 00151 float** disttoNonfree_incells); 00152 00153 00154 #if 0 00155 void CheckSearchMDP(CMDP* mdp, int ExcludeSuccStateID = -1); 00156 void CheckSearchPredSucc(CMDPSTATE* state, int ExcludeSuccStateID = -1); 00157 #endif 00158 00159 #endif