![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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/grouper/GreedyGrouper.hpp> 00029 #include <algorithm> 00030 00031 using namespace wns::scheduler; 00032 using namespace wns::scheduler::grouper; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR(GreedyGrouper, GroupingProviderInterface, "GreedyGrouper", wns::PyConfigViewCreator); 00035 00036 GreedyGrouper::GreedyGrouper(const wns::pyconfig::View& config) 00037 : AllPossibleGroupsGrouper(config) 00038 { 00039 } 00040 00041 00042 bool 00043 GreedyGrouper::BeamCmp::operator() (const Beams& b1, const Beams& b2) const { 00044 return b1.throughPut > b2.throughPut; 00045 } 00046 00047 00048 AllPossibleGroupsGrouper::Partition 00049 GreedyGrouper::makeGrouping(int /* maxBeams */, unsigned int noOfStations ) 00050 { 00051 // calculate this before sorting the array, as it depends on the original 00052 // order 00053 float throughputTrivialGrouping = getTPperGroupTrivialGrouping(noOfStations); 00054 00055 // sort the beams 00056 // choose the best beam 00057 // choose the next beam that doesn't conflict 00058 // sort beam beginning with highest throughput 00059 sort(allPossibleGroups.begin(), allPossibleGroups.end(), BeamCmp()); 00060 00061 // init greedyGrouping 00062 Partition groupingGreedy; 00063 groupingGreedy.servedStations = std::bitset<MAX_STATIONS>(0); 00064 groupingGreedy.groups.clear(); 00065 groupingGreedy.totalThroughput = 0.0; 00066 00067 // try to consecutively add next biggest beam 00068 00069 for (unsigned int i = 0; i < allPossibleGroups.size(); ++i) { 00070 // do a bitwise AND of the two bitsets to check whether the set of 00071 // already covered stations in groupingGreedy and the stations in the 00072 // group to be considered (allPossibleGroups[i]) conflict 00073 if ((allPossibleGroups[i].servedStations & groupingGreedy.servedStations).count() == 0) 00074 { // can add this group 00075 groupingGreedy.servedStations = (allPossibleGroups[i].servedStations | groupingGreedy.servedStations); 00076 00077 // add group to new grouping 00078 groupingGreedy.groups.push_back(i); 00079 groupingGreedy.totalThroughput += allPossibleGroups[i].throughPut; 00080 } 00081 if (groupingGreedy.servedStations.count() == noOfStations) 00082 break; // all covered, we are done 00083 } 00084 00085 assure(groupingGreedy.servedStations.count() == noOfStations, "Greedy did not find grouping covering everything -> impossible"); 00086 00087 float throughputBestGrouping = (float) (groupingGreedy.totalThroughput) / (float)(groupingGreedy.groups.size()); 00088 00089 groupingGainProbeBus->put(throughputBestGrouping / throughputTrivialGrouping); 00090 00091 MESSAGE_BEGIN(VERBOSE, logger, m, colleagues.registry->getNameForUser(colleagues.registry->getMyUserID())); 00092 m << " GreedyGrouper calculated new grouping with a gain of " 00093 << throughputBestGrouping / throughputTrivialGrouping; 00094 MESSAGE_END(); 00095 00096 return groupingGreedy; 00097 } 00098 00099 00100 00101
1.5.5