User Manual, Developers Guide and API Documentation

DoAHeuristicPreferredAngle.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 
00028 #include "DoAHeuristicPreferredAngle.hpp"
00029 
00030 #include <WNS/pyconfig/View.hpp>
00031 #include <WNS/StaticFactory.hpp>
00032 
00033 #include <list>
00034 #include <math.h>
00035 #include <algorithm>
00036 
00037 using namespace wns::scheduler;
00038 using namespace wns::scheduler::grouper;
00039 
00040 
00041 STATIC_FACTORY_REGISTER_WITH_CREATOR(DoAHeuristicPreferredAngle, GroupingProviderInterface, "DoAHeuristicPreferredAngle", wns::PyConfigViewCreator);
00042 
00043 
00044 DoAHeuristicPreferredAngle::DoAHeuristicPreferredAngle(const wns::pyconfig::View& config)
00045     : DoATreeBasedGrouper(config),
00046       minAngle(config.get<float>("minAngleDegree")*M_PI/180.0),
00047       weight(config.get<float>("weight"))
00048 {
00049 }
00050 
00051 
00052 float
00053 DoAHeuristicPreferredAngle::groupingCostForAUser(UserSet group, UserID newUser) {
00054     float cost = 0.0;
00055     float threshold = minAngle;
00056 //  float threshold = 20.0 / 180.0 * M_PI;
00057     float penalty = 1000.0;
00058     float min = M_PI;
00059 
00060     float newUserDoA = getNormalizedDoA(newUser);
00061 
00062 //  if (Debug)
00063 //      std::cout << "New user at " << rad2deg(newUserDoA) << " degrees\n";
00064 
00065     for (UserSet::const_iterator iter = group.begin();
00066          iter != group.end(); ++iter) {
00067         float userDoA = getNormalizedDoA(*iter);
00068 
00069 //      if (Debug)
00070 //          std::cout << "Group user at " << rad2deg(userDoA) << " degrees\n";
00071 
00072         float diff = userDoA - newUserDoA;
00073         // normalize angles to [0.0, M_PI]
00074         if (diff < 0.0)
00075             diff = diff + 2*M_PI;
00076         if (diff > M_PI)
00077             diff = 2*M_PI - diff;
00078 
00079         if (fabs(diff) < min)
00080             min = fabs(diff);
00081     }
00082 
00083 //  if (Debug)
00084 //      std::cout << "Minimum " << rad2deg(min) << " degrees\n";
00085 
00086     // calculate cost to add user
00087     if (min < threshold)
00088         cost = penalty;
00089     else
00090     {
00091         // 0..threshold verboten
00092         // threshold .. 2.5X threshold erwuenscht mit minimalen kosten bei 2x
00093         // threshold. von 2.5x threshold bis 180 konstanter langsam wachsender
00094         // wert auf 1+mincost
00095 
00096         float minCost = threshold / M_PI;
00097         if (min < 2.5*threshold)
00098             cost = weight*(fabs(min-2*threshold)/threshold+minCost);
00099         else
00100             // fange bei 2.5*th mit 0.5+minCost an, dann steiger dich auf
00101             // 1+minCost bei M_PI
00102             cost = weight*((min-2.5*threshold)*(0.5/(M_PI-2.5*threshold)) +0.5+minCost );
00103 
00104     }
00105 
00106 //  if (Debug)
00107 //      std::cout << "Resulting in cost of " << cost << " \n\n";
00108 
00109     return cost;
00110 }
00111 
00112 
00113 
00114 
00115 
00116 

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