User Manual, Developers Guide and API Documentation

FarFirst.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 <WNS/scheduler/strategy/dsastrategy/FarFirst.hpp>
00029 #include <WNS/scheduler/SchedulerTypes.hpp>
00030 #include <WNS/Positionable.hpp>
00031 
00032 using namespace wns::scheduler;
00033 using namespace wns::scheduler::strategy;
00034 using namespace wns::scheduler::strategy::dsastrategy;
00035 
00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(FarFirst,
00037                                      DSAStrategyInterface,
00038                                      "FarFirst",
00039                                      wns::PyConfigViewCreator);
00040 
00041 FarFirst::FarFirst(const wns::pyconfig::View& config)
00042     : DSAStrategy(config)
00043 {
00044 
00045 }
00046 
00047 FarFirst::~FarFirst()
00048 {
00049 
00050 }
00051 
00052 // call this before each timeSlot/frame
00053 void
00054 FarFirst::initialize(SchedulerStatePtr schedulerState,
00055                          SchedulingMapPtr schedulingMap)
00056 {
00057     DSAStrategy::initialize(schedulerState,schedulingMap); // must always initialize base class too
00058 
00059     int maxSubChannel = schedulerState->currentState->strategyInput->getFChannels();
00060     int numberOfTimeSlots = schedulerState->currentState->strategyInput->getNumberOfTimeSlots();
00061     int maxSpatialLayers = schedulerState->currentState->strategyInput->getMaxSpatialLayers();
00062 
00063     int prio = schedulerState->currentState->getCurrentPriority();
00064     wns::scheduler::ConnectionSet conns = colleagues.registry->getConnectionsForPriority(prio);
00065 
00066     std::set<wns::scheduler::UserID> userIDs;
00067     wns::scheduler::ConnectionSet::iterator it;
00068 
00069     // store users in userIDs from type std::set
00070     for(it = conns.begin(); it != conns.end(); it++)
00071         userIDs.insert(colleagues.registry->getUserForCID(*it));
00072 
00073     unsigned int numberOfUsers = userIDs.size();
00074     unsigned int numberOfResources = maxSubChannel * numberOfTimeSlots * maxSpatialLayers;
00075 
00076     MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA: Distributing " 
00077         << numberOfUsers << " users on " << numberOfResources << " resources.");
00078 
00079     if(numberOfUsers == 0)
00080         return;
00081 
00082     // store resources in sortedResources_ from type std::set
00083     for(int i = 0; i < maxSubChannel; i++)
00084     {
00085         for(int j = 0; j < numberOfTimeSlots; j++)
00086         {
00087             for(int k = 0; k < maxSpatialLayers; k++)
00088             {
00089                 DSAResult res;
00090                 res.subChannel = i;
00091                 res.timeSlot = j;
00092                 res.spatialLayer = k;
00093                 sortedResources_.insert(res);
00094             }
00095         } 
00096     }
00097 
00098     int usersMore = numberOfResources % numberOfUsers;
00099     int usersLess = numberOfUsers - usersMore;
00100     int resourcesMore = int(numberOfResources / numberOfUsers) + 1;
00101     int resourcesLess = int(numberOfResources / numberOfUsers);
00102 
00103     MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA: " 
00104         << usersLess << " users get " << resourcesLess << " resources, "
00105         << usersMore << " users get " << resourcesMore << " resources");
00106 
00107     assure(resourcesLess > 0, "Not enough resources for all users");
00108     assure(usersMore * resourcesMore + usersLess * resourcesLess == numberOfResources,
00109         "Mismatched resource distribution");
00110 
00111     // BS Position
00112     wns::PositionableInterface* bsPos = schedulerState->myUserID.getNode()->getService<wns::PositionableInterface*>("mobility");
00113 
00114     //map<Distanz zu BS, UserID>
00115     std::map<double, wns::scheduler::UserID, std::greater<double> > userIdMap;
00116     std::set<wns::scheduler::UserID>::iterator userIdIt;
00117     for(userIdIt = userIDs.begin(); userIdIt != userIDs.end(); userIdIt++)
00118     {
00119         // SSs Positions
00120         wns::PositionableInterface* ssPos = (*userIdIt).getNode()->getService<wns::PositionableInterface*>("mobility");
00121         userIdMap[ssPos->getDistance(bsPos)] = *userIdIt;
00122     }
00123 
00124     std::map<double, wns::scheduler::UserID, std::greater<double> >::iterator userIdMapIt;
00125     userIdMapIt = userIdMap.begin();
00126 
00127     // Resources for first UserID
00128     resStart_[userIdMapIt->first] = sortedResources_.begin();
00129     resAmount_[userIdMapIt->first] = resourcesLess;
00130 
00131     MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA: User "
00132         << userIdMapIt->second.getNodeID() << " with distance " << userIdMapIt->first << " starts at "
00133         << sortedResources_.begin()->subChannel << "."
00134         << sortedResources_.begin()->timeSlot << "."
00135         << sortedResources_.begin()->spatialLayer
00136         << " and gets " << resourcesLess << " resources");
00137 
00138     userIdMapIt++;
00139 
00140     // Resources for other UserIDs
00141     int plus = 0;
00142     int user = 0;
00143     int counter = 0;
00144 
00145     std::set<DSAResult, FreqFirst>::iterator itr;
00146     for(itr = sortedResources_.begin(); itr != sortedResources_.end(); itr++)
00147     {
00148         if(counter == resourcesLess + plus)
00149         {
00150             resStart_[userIdMapIt->first] = itr;
00151             resAmount_[userIdMapIt->first] = resourcesLess + plus;
00152 
00153             MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA: User " 
00154                 << userIdMapIt->second.getNodeID() << " with distance " << userIdMapIt->first << " starts at "
00155                 << itr->subChannel << "."
00156                 << itr->timeSlot << "."
00157                 << itr->spatialLayer
00158                 << " and gets " << resourcesLess + plus << " resources");
00159 
00160             counter = 0;
00161             userIdMapIt++;
00162             user++;
00163         }
00164         if(plus == 0 && user == usersLess - 1)
00165         {
00166             plus++;
00167             counter++;
00168         }
00169     counter++;
00170     }
00172     std::map<double, std::set<DSAResult>::iterator>::iterator resStartIt;
00173     for(resStartIt = resStart_.begin(); resStartIt != resStart_.end(); resStartIt++)
00174     {
00175         MESSAGE_SINGLE(NORMAL, logger, "FarFirst::initialize:  "
00176             << "Distanz zu BS : " << resStartIt->first
00177             << "  Ressourcen-Start: " 
00178             << resStartIt->second->subChannel << "."
00179             << resStartIt->second->timeSlot << "."
00180             << resStartIt->second->spatialLayer);
00181     }
00182 
00183 
00184     std::map<double, int>::iterator resAmountIt;
00185     for(resAmountIt = resAmount_.begin(); resAmountIt != resAmount_.end(); resAmountIt++)
00186     {
00187         MESSAGE_SINGLE(NORMAL, logger, "FarFirst::initialize:  "
00188             << "Distanz zu BS : " << resAmountIt->first
00189             << "  Ressourcen-Groesse: " << resAmountIt->second);
00190     }
00191 
00193 } //initialize
00194 
00195 DSAResult
00196 FarFirst::getSubChannelWithDSA(RequestForResource& request,
00197                                    SchedulerStatePtr schedulerState,
00198                                    SchedulingMapPtr schedulingMap)
00199 {
00200     MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(" << request.toString()<<")");
00201 
00202     wns::PositionableInterface* bsPos = schedulerState->myUserID.getNode()->getService<wns::PositionableInterface*>("mobility");
00203     wns::PositionableInterface* ssPos = request.user.getNode()->getService<wns::PositionableInterface*>("mobility");
00204     double distance = ssPos->getDistance(bsPos);
00205 
00206     assure(resStart_.find(distance) != resStart_.end(), "No resources for user " + request.user.getNodeID());
00207     assure(resAmount_.find(distance) != resAmount_.end(), "Unknown resource amount for user " + request.user.getNodeID());
00208 
00209     int max = resAmount_[distance];
00210     std::set<DSAResult>::iterator dsaResultSetIt;
00211     int i = 0;
00212 
00213     bool found = false;
00214     for(dsaResultSetIt = resStart_[distance]; i < max && !found; dsaResultSetIt++)
00215     {
00216         i++;
00217         found = channelIsUsable(dsaResultSetIt->subChannel, 
00218                                 dsaResultSetIt->timeSlot,
00219                                 dsaResultSetIt->spatialLayer,
00220                                 request, 
00221                                 schedulerState, 
00222                                 schedulingMap);
00223     }
00224 
00225     if(!found)
00226     {
00227         MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): no free subchannel");
00228         DSAResult dsaResult;
00229         return dsaResult;
00230     }
00231     else
00232     {
00233         dsaResultSetIt--;
00234 
00235         MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): Granting resource: "
00236             << dsaResultSetIt->subChannel << "." << dsaResultSetIt->timeSlot << "." 
00237             << dsaResultSetIt->spatialLayer << " to " << request.toString());
00238         return *dsaResultSetIt;
00239     }
00240 } // getSubChannelWithDSA
00241 

Generated on Thu May 24 03:31:50 2012 for openWNS by  doxygen 1.5.5