test_adjacency_list.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 using namespace std;
00004 
00005 #include "../discrete_space_information/precomputed_adjacency_list/environment_precomputed_adjacency_list.h"
00006 
00007 
00008 // 2d Points
00009 struct Point2D
00010 {
00011   Point2D(int newX, int newY) : x(newX), y(newY) {}
00012 
00013   int heuristicDistanceTo (const Point2D& p) { int dx=p.x-x; int dy=p.y-y; int dist=((int)sqrt(dx*dx+dy*dy));  return dist; }
00014 
00015   int x;
00016   int y;
00017 };
00018 
00019 ostream& operator<< (ostream& stream, Point2D p)
00020 {
00021   stream << "(" << p.x << ", " << p.y << ")";
00022   return stream;
00023 }
00024 
00025 int operator< (const Point2D& p1, const Point2D& p2)
00026 {
00027   return (p1.x<p2.x) || ((p1.x==p2.x) && (p1.y<p2.y));
00028 }
00029 
00030 
00031 
00032 
00033 
00034 
00035 void testPlanner (AdjacencyListSBPLEnv<Point2D>& e)
00036 {
00037   int sol_cost;
00038   e.writeToStream();
00039   vector<Point2D> solution = e.findOptimalPath (&sol_cost);
00040   cout << "Returned plan is ";
00041   for (unsigned int i=0; i<solution.size(); i++) {
00042     cout << solution[i] << " ";
00043   }
00044   cout << endl;
00045 }  
00046 
00047 
00048 
00049 
00050 int main (int, char**)
00051 {
00052   AdjacencyListSBPLEnv<Point2D> e;
00053   Point2D p1(0,0);
00054   Point2D p2(2,1);
00055   Point2D p3(1,4);
00056   Point2D p4(5,5);
00057 
00058   e.addPoint(p1);
00059   e.addPoint(p4);
00060   e.addPoint(p3);
00061   e.addPoint(p2);
00062 
00063   e.setCost(p1,p2,4);
00064   e.setCost(p1,p3,6);
00065   e.setCost(p3,p4,5);
00066   e.setCost(p2,p4,15);
00067 
00068   e.setStartState(p1);
00069   e.setGoalState(p4);
00070 
00071   // Initialize the MDPConfig (what does this do exactly?)
00072   //MDPConfig c;
00073   //e.InitializeMDPCfg(&c);
00074 
00075 
00076   // Tests
00077   testPlanner (e);
00078   e.setCost(p2,p4,1);
00079   testPlanner (e);
00080   e.removeLastPoints();
00081   testPlanner (e);
00082   e.writeToStream();
00083   return 0;
00084 }
00085 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


sbpl
Author(s): Maxim Likhachev/maximl@seas.upenn.edu
autogenerated on Fri Jan 18 2013 13:41:53