![]() |
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/strategy/dsastrategy/Random.hpp> 00029 #include <WNS/scheduler/strategy/dsastrategy/DSAStrategy.hpp> 00030 #include <WNS/scheduler/strategy/dsastrategy/DSAStrategyInterface.hpp> 00031 #include <WNS/scheduler/SchedulerTypes.hpp> 00032 #include <vector> 00033 #include <iostream> 00034 #include <algorithm> 00035 #include <stdlib.h> 00036 #include <time.h> 00037 00038 using namespace wns::scheduler; 00039 using namespace wns::scheduler::strategy; 00040 using namespace wns::scheduler::strategy::dsastrategy; 00041 00042 STATIC_FACTORY_REGISTER_WITH_CREATOR(Random, 00043 DSAStrategyInterface, 00044 "Random", 00045 wns::PyConfigViewCreator); 00046 00047 Random::Random(const wns::pyconfig::View& config) 00048 : DSAStrategy(config), 00049 randomDist(NULL) 00050 { 00051 randomDist = new wns::distribution::StandardUniform(); 00052 } 00053 00054 Random::~Random() 00055 { 00056 delete randomDist; 00057 } 00058 00059 // call this before each timeSlot/frame 00060 void 00061 Random::initialize(SchedulerStatePtr schedulerState, 00062 SchedulingMapPtr schedulingMap) 00063 { 00064 DSAStrategy::initialize(schedulerState,schedulingMap); // must always initialize base class too 00065 } 00066 00067 DSAResult 00068 Random::getSubChannelWithDSA(RequestForResource& request, 00069 SchedulerStatePtr schedulerState, 00070 SchedulingMapPtr schedulingMap) 00071 { 00072 DSAResult dsaResult; 00073 00074 int maxSubChannel = schedulerState->currentState->strategyInput->getFChannels(); 00075 int numberOfTimeSlots = schedulerState->currentState->strategyInput->getNumberOfTimeSlots(); 00076 int maxSpatialLayers = schedulerState->currentState->strategyInput->getMaxSpatialLayers(); 00077 00078 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(" << request.toString()<<")"); 00079 00080 int numberOfEssays = 0; 00081 00082 DSAResult resource; 00083 std::vector<DSAResult> freeResources; 00084 for(int i = 0; i < maxSubChannel; i++) 00085 { 00086 for(int j = 0; j < numberOfTimeSlots; j++) 00087 { 00088 for(int k = 0; k < maxSpatialLayers; k++) 00089 { 00090 if (channelIsUsable(i, j, k, request, schedulerState, schedulingMap)) 00091 { 00092 resource.subChannel = i; 00093 resource.timeSlot = j; 00094 resource.spatialLayer = k; 00095 freeResources.push_back(resource); 00096 } 00097 } 00098 } 00099 } 00100 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(" << request.toString() << ") found " 00101 << freeResources.size() << " potential resources"); 00102 00103 if (freeResources.size() == 0) 00104 { 00105 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): no free subchannel"); 00106 return dsaResult; 00107 } 00108 else 00109 { 00110 int rnd = int((*randomDist)() * freeResources.size()); 00111 resource = freeResources[rnd]; 00112 00113 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): Drawn random resource: " << rnd 00114 << " subChannel=" << resource.subChannel << "." << resource.timeSlot << "." 00115 << resource.spatialLayer); 00116 return resource; 00117 } 00118 } // getSubChannelWithDSA
1.5.5