commit 76cefba1ddbc3bddf37a16ccea1ad0a74a6d74cc
Author: Priya <pdeo@Phlegethon.(none)>
Date:   Sat Mar 24 17:48:32 2012 -0400

    Merged scheduler implementations and modified order structrure class

diff --git a/scout/libscout/src/behaviors/Scheduler.cpp b/scout/libscout/src/behaviors/Scheduler.cpp
index 2337f60..171e148 100644
--- a/scout/libscout/src/behaviors/Scheduler.cpp
+++ b/scout/libscout/src/behaviors/Scheduler.cpp
@@ -29,7 +29,13 @@ Scheduler::~Scheduler()
    delete waitingRobots;
 }
 
-/** @Brief: Add robot to the waiting queue. */
+/** @Brief: Add robot to the waiting queue. 
+ *  A robot calls this function with itself
+ *  and gets pushed on a list of waiting robots.
+ *  When a task is availaible the scheduler, removes
+ *  the robot of the waiting queue, and gives it a
+ *  task.
+ */
 void Scheduler::get_task(WH_Robot r)
 {
 	waitingRobots.push(r);
@@ -39,10 +45,10 @@ void Scheduler::get_task(WH_Robot r)
 void Scheduler::create_orders()
 {
 	Order a(1,0,0,101,0,0,0);
-    Order b(2,0,0,11,0,0,0);
-    Order c(3,0,0,91,0,0,0);
-    Order d(4,0,0,21,0,0,0);
-    Order e(5,0,0,41,0,0,0);
+  Order b(2,0,0,11,0,0,0);
+  Order c(3,0,0,91,0,0,0);
+  Order d(4,0,0,21,0,0,0);
+  Order e(5,0,0,41,0,0,0);
 	
 	unassignedOrders.insert(a);
 	unassignedOrders.insert(b);
@@ -81,6 +87,19 @@ void Scheduler::waiting_dance()
 /** @Brief: The scheduling algorithm. Picks a task and pops from the PQWrapper. */
 Order Scheduler::get_next_item()
 {
+  Time time = ros::TIME_MAX; 
+
+  Order best;
+  for(int i=0; i<unassigned_orders.arraySize(); i++)
+  {
+    Order order = unassigned_orders.peek(i);
+
+    if(order.orderDeadline < time) //TODO: use another function
+    {
+      best = order;
+      time = order.orderDeadline;
+    }
+  }
 
 }
 
@@ -90,7 +109,9 @@ void Scheduler::run()
 {
 	while (ok())
 	{
-		while(waitingRobots.empty() || unassignedOrders.arraySize()==0) waiting_dance();
+		while(waitingRobots.empty() || unassignedOrders.arraySize()==0) 
+      waiting_dance();
+
 		waitingRobots.front().set_task(get_next_item());
 		waitingRobots.pop();
 	}
diff --git a/scout/libscout/src/behaviors/Scheduler.h b/scout/libscout/src/behaviors/Scheduler.h
index 8983489..0c9c44b 100644
--- a/scout/libscout/src/behaviors/Scheduler.h
+++ b/scout/libscout/src/behaviors/Scheduler.h
@@ -1,27 +1,30 @@
 #ifndef _SCHEDULER_
 #define _SCHEDULER_
 
-#include "helper_classes/PQWrapper.h"
-#include "helper_classes/Order.h"
+#include "../helper_classes/PQWrapper.h"
+#include "../helper_classes/Order.h"
 #include "WH_Robot.h"
+#include "../Behavior.h"
 
-class Scheduler {
-    std::vector<WH_Robot> robots;
+class Scheduler : Behavior {
+  std::vector<WH_Robot> robots;
 	PQWrapper unassignedOrders;
 	std::vector<Order> assignedOrders;
 	std::queue<WH_Robot> waitingRobots;
+
+	void create_orders();
+
+	void waiting_dance();
+
 public:
     Scheduler();
 	~Scheduler();
 	
 	void get_task(WH_Robot robot);
 	
-	void create_orders();
-	
 	void task_complete(Order o);
 	void task_failed(Order o);
 	
-	void waiting_dance();
 	
 	Order get_next_item();
 	
@@ -31,4 +34,4 @@ public:
 	
     
 };
-#endif
\ No newline at end of file
+#endif
diff --git a/scout/libscout/src/behaviors/scheduler.cpp b/scout/libscout/src/behaviors/scheduler.cpp
deleted file mode 100644
index 1b11268..0000000
--- a/scout/libscout/src/behaviors/scheduler.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "scheduler.cpp"
-
-/** @brief Initialize the scheduler */
-scheduler::scheduler(std::string scoutname) : Behavior(scoutname)
-{
-  waitingOrders = emptyPQ();
-}
-
-scheduler::~scheduler()
-{
-  //TODO:Free the priority queue here
-  return;
-}
-
-void scheduler::run()
-{
-  while(1)
-  {
-    //TODO: Everything in here
-    //listen for wireless messages, if you here one parse it
-    //if message is a addItem message, call addItem on the data
-    //if message is a getItem message, call getNextItem and send back the item
-  }
-}
-
-void scheduler::addItem(item job)
-{
-  Time job_time = getCompletionTime(item);
-  start_by_time = job.deadline - job_time;
-  waitingOrders.enQ(job, start_by_time);
-}
-
-item getNextItem()
-{
-  Time time = 999999;//Infinity
-  item best;
-  for(int i=0; i<10; i++)
-  {
-    pq_item order = waitingOrders.get(i);
-    //A checker to see if the order must go now?
-    if(order.job.deadline < time)
-    {
-      best = order.job;
-      time = order.job.deadline;
-    }
-  }
-
-  return best;
-
-}
diff --git a/scout/libscout/src/behaviors/scheduler.h b/scout/libscout/src/behaviors/scheduler.h
deleted file mode 100644
index 3c86dad..0000000
--- a/scout/libscout/src/behaviors/scheduler.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef _SCHEDULER_
-#define _SCHEDULER_
-
-#include <queue>
-#include "../Behavior.h"
-
-//location: where the robot has to go; 
-//job_type: what the robot is supposed to do when it gets there
-typedef struct{
-  int location;
-  int job_type;
-  int deadline;
-} item;
-
-//struct for the items in the pq. TODO: check its validity
-typedef struct {
-  item job;
-  Time start_time;
-} pq_item;
-
-
-class compare
-{
-  public:
-  bool operator() (pq_item a, pq_item b) const
-  {
-    return (a.start_time) >= (b.start_time);
-  }
-};
-
-
-
-class scheduler : Behavior
-{
-  public:
-    scheduler(std::scoutname);
-    ~scheduler();
-
-    void run();
-
-    
-  private:
-    void addItem(item);
-    item getNextItem();
-    Time getCompletionTime(item job);
-   
-    bool compare(pq_item x, pq_item y); 
-    //TODO:Check the validity of this line.
-    priority_queue<pq_item, vector<pq_item>, compare> waitingOrders;
-}
-
-#endif
diff --git a/scout/libscout/src/helper_classes/Order.cpp b/scout/libscout/src/helper_classes/Order.cpp
index 1b9256c..285e63c 100644
--- a/scout/libscout/src/helper_classes/Order.cpp
+++ b/scout/libscout/src/helper_classes/Order.cpp
@@ -2,40 +2,57 @@
 
 using namespace std;
 
-/** @Brief: Default order constructor */
-Order::Order()
+/** @Brief: Regular order constructor */
+Order::Order(int order_id, Address order_source, Address order_dest, Time order_deadline, Time order_start_time, Path order_path, Time order_est_time) 
+{ 
+    id = order_id;
+    source = order_source;
+    dest = order_dest;
+    start_time = order_start_time;
+    path = order_path;
+    est_time = order_est_time;
+}
+
+/** @Brief: Get order ID */
+int Order::getid() const 
 {
-    orderID = 0;
-    orderSource = 0;
-    orderDest = 0;
-    orderDeadline = 0;
-    orderStartTime = 0;
-    orderPath = 0;
-    orderEstTime = 0; 
+    return id;
+}  
+
+Address get_source() const
+{
+    return source;
 }
 
-/** @Brief: Regular order constructor */
-Order::Order(int ID, Address source, Address dest, Time deadline, Time start_time, Path path, Time est_time) { 
-    orderID = ID;
-    orderSource = source;
-    orderDest = dest;
-    orderDeadline = deadline;
-    orderStartTime = start_time;
-    orderPath = path;
-    orderEstTime = est_time;
+Address get_dest() const
+{
+    return dest;
 }
 
-/** @Brief: Get priority for the PQWrapper */
-double Order::getpriority() const { 
-    return orderDeadline - orderStartTime; 
+Time get_start_time() const
+{
+    return start_time;
 }
 
-/** @Brief: Get order ID */
-int Order::getid() const {
-    return orderID;
-}  
+Path get_path() const
+{
+    return path;
+}
 
-/** @Brief: Order comparison function for PQWrapper */
-bool CompareOrder::operator()(Order& o1, Order& o2) {
-    return o1.getpriority() > o2.getpriority();
+void set_path(Path order_path)
+{
+    path = order_path;
+    return;
+}
+/** @Brief: Order comparison function for PQWrapper 
+ *  NOTE: In order to have a min priority queue, using c++'s pq
+ *  implementation, the compare function must return true if
+ *  o1 is greater than o2.
+ */
+bool CompareOrder::operator()(Order& o1, Order& o2) 
+{
+  int pq_value1 = o1.get_start_time + MAX_WAIT_TIME - o1.get_est_time();
+  int pq_value2 = o2.get_start_time + MAX_WAIT_TIME - o2.get_est_time();
+  return pq_value1 > pq_value2;
 }
+
diff --git a/scout/libscout/src/helper_classes/Order.h b/scout/libscout/src/helper_classes/Order.h
index b12ff5d..eabc54e 100644
--- a/scout/libscout/src/helper_classes/Order.h
+++ b/scout/libscout/src/helper_classes/Order.h
@@ -1,25 +1,33 @@
 #ifndef _ORDER_
 #define _ORDER_
 
+#define MAX_WAIT_TIME 120 //2 minutes in seconds
+
 typedef unsigned int Address;
 typedef unsigned int Path;
 typedef double Time;
 
 class Order {
-    int orderID;
-    Address orderSource, orderDest;
-    Time orderDeadline, orderStartTime;
-    Path orderPath;
-    Time orderEstTime;
+    int id;
+    Address source, dest;
+    Time start_time;
+    Path path;
+    Time est_time;
 public:
-    Order();
-    Order(int ID, Address source, Address dest, Time deadline, Time start_time, Path path, Time est_time);
-    Time getpriority() const;
+    Order(int order_id, Address order_source, Address order_dest, Time order_deadline, Time order_start_time, Path order_path, Time order_est_time);
+
     int getid() const;
+    Address get_source() const;
+    Address get_dest() const;
+    Time get_start_time() const;
+    Path get_path() const;
+    void set_path(Path order_path);
+    
 };
 
 class CompareOrder {
-    public:
-        bool operator()(Order& o1, Order& o2);
+  public:
+    bool operator()(Order& o1, Order& o2);   
 };
-#endif
\ No newline at end of file
+
+#endif
