User Manual, Developers Guide and API Documentation

DoAHeuristicLinearCost.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2009
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 #include <WNS/scheduler/grouper/DoAHeuristicLinearCost.hpp>
00028 
00029 #include <WNS/pyconfig/View.hpp>
00030 #include <WNS/StaticFactory.hpp>
00031 
00032 #include <list>
00033 #include <math.h>
00034 #include <algorithm>
00035 
00036 using namespace wns::scheduler;
00037 using namespace wns::scheduler::grouper;
00038 
00039 STATIC_FACTORY_REGISTER_WITH_CREATOR(DoAHeuristicLinearCost, GroupingProviderInterface, "DoAHeuristicLinearCost", wns::PyConfigViewCreator);
00040 
00041 
00042 DoAHeuristicLinearCost::DoAHeuristicLinearCost(const wns::pyconfig::View& config)
00043     : DoATreeBasedGrouper(config),
00044       minAngle(config.get<float>("minAngleDegree")*M_PI/180.0),
00045       weight(config.get<float>("weight"))
00046 {
00047 }
00048 
00049 
00050 float
00051 DoAHeuristicLinearCost::groupingCostForAUser(UserSet group, UserID newUser) {
00052     float cost = 0.0;
00053     float threshold = minAngle;
00054 //  float threshold = 20.0 / 180.0 * M_PI;
00055     float penalty = 1000.0;
00056     float min = M_PI;
00057 
00058     float newUserDoA = getNormalizedDoA(newUser);
00059 
00060 //  if (Debug)
00061 //      std::cout << "New user at " << rad2deg(newUserDoA) << " degrees\n";
00062 
00063     for (UserSet::const_iterator iter = group.begin();
00064          iter != group.end(); ++iter) {
00065         float userDoA = getNormalizedDoA(*iter);
00066 
00067 //      if (Debug)
00068 //          std::cout << "Group user at " << rad2deg(userDoA) << " degrees\n";
00069 
00070         float diff = userDoA - newUserDoA;
00071         // normalize angles to [0.0, M_PI]
00072         if (diff < 0.0)
00073             diff = diff + 2*M_PI;
00074         if (diff > M_PI)
00075             diff = 2*M_PI - diff;
00076 
00077         if (fabs(diff) < min)
00078             min = fabs(diff);
00079     }
00080 
00081 //  if (Debug)
00082 //      std::cout << "Minimum " << rad2deg(min) << " degrees\n";
00083 
00084     // calculate cost to add user
00085     if (min < threshold)
00086         cost = penalty;
00087     else
00088         cost = weight*(threshold/min);
00089 
00090 //  if (Debug)
00091 //      std::cout << "Resulting in cost of " << cost << " \n\n";
00092 
00093     return cost;
00094 }
00095 
00096 
00097 
00098 
00099 
00100 

Generated on Wed May 23 03:31:47 2012 for openWNS by  doxygen 1.5.5