def __init__ (self): reader = InputReader() self.resourceCaps = reader.readCapacityFile() self.vmResourceRequirement = reader.readVMConfigFile() self.appsList = reader.readAppInfo() self.nVM = len(self.vmResourceRequirement) Scheduler.packedAppsForEachAvgSysLoad = {}
def __init__(self): reader = InputReader() self.resourceCaps = reader.readCapacityFile() self.vmResourceRequirement = reader.readVMConfigFile() self.appsList = reader.readAppInfo() self.nVM = len(self.vmResourceRequirement) Scheduler.packedAppsForEachAvgSysLoad = {}
def reInit(self, avgSystemLoad): self.currentRequestPool = [] self.waitingRequestPool = [] self.exitRequestPool = [] self.missedRequestPool = [] reader = InputReader() self.resourceCaps = reader.readCapacityFile()
def solveEquation(self): if len(self.file) == 0: return None try: inReader = InputReader(self.file) inReader.readEquationsFromFile() inVal = InputValidator( inReader.equations ) inVal.convertDataToFloat() self.solver = Solver(inVal) self.solver.solveEq() print('Rozwiazanie ukladu rownan:\n') print( self.solver.solution ) except FileNotFoundError: print("This file does'n exist") except ValueError: print("Incorrect insert data (value)")
def __init__( self, mInputReader , filterPath='../res/FeatureFilter' ): ''' Constructor - arguments passed from main @param mInputReader: InputReader object for setting raw data ''' # Feature dump and filter path self.outCSVPath = '../../tmp/featureDump.csv' self.filterCSVPath = filterPath # Get raw data from the passed InputReader mInputReader.readFile() self.rawData = mInputReader.getRawData() # Initialize feature set and training data from raw data self.features = self.rawData[0] self.trainingData = np.array( self.rawData[1:] ) # Construct the InputReader used for feature filtering self.filterReader = InputReader( self.filterCSVPath ) # Initialize number of samples removed self.nRmvSamples = 0
class InputReaderTest(unittest.TestCase): def setUp( self ): ''' Construct our InputReader object, pass it the test csv file ''' self.mInputReader = InputReader( testFile ) def test_read( self ): ''' Test the csv read functionality against known values ''' self.mInputReader.readFile() mRawData = self.mInputReader.getRawData() self.assertEqual( mRawData, [['InputReader', 'Test', 'CSV'], ['1', '44', '-4.3'], ['234', '-45', '0.45']] ) def test_pathSet( self ): ''' Test set file path and FileNotFoundError exception''' # Set a bogus file name self.mInputReader.setFilePath( '../../res/NonExist.csv' ) self.assertRaises( FileNotFoundError, self.mInputReader.readFile() )
nUser = len(bundles) self.init(nUser) self.calculateRelevanceFactor(resourceCaps) self.calculateRequiredResource(bundles, vmResourceRequirement, resourceCaps) self.calculateSigmaMetric(bids) self.sortUser(k, deadlines) orderedKUserIDs = self.U[:k] welfare, winnerLoser = self.allocate(resourceCaps, bids, k) return orderedKUserIDs, welfare, winnerLoser ''' To test the mechanism ''' if __name__ == '__main__': reader = InputReader() k = 2 bundles, runtimes, bids, deadlines = reader.readRequestFile() resourceCaps = reader.readCapacityFile() vmResourceRequirement = reader.readVMConfigFile() alloactor = KTimeSensitiveResourceAllocator() #alloactor.calculateRelevanceFactor(resourceCaps) #alloactor.calculateRequiredResource(bundles, vmResourceRequirement) #alloactor.calculateOurAnotherMetric(bids) alloactor.sortUserOnDeadline(k, deadlines) #alloactor.allocate(resourceCaps, bids)
return True #Transfors the priority queue into an array of strings def adaptSolution(node): path = [] finalCost = node.cost while node.parentNode: path.append("(" + str(node.movement[0]) + ", " + str(node.movement[1]) + "); ") node = node.parentNode return finalCost, path #Read the input file reader = InputReader() data = reader.read() #print data #Store the reading results in the global variables maxHeight = data[0] initialConfiguration = data[1] goalState = data[2] cost = 0 path = [] #Search if searchingByBFS(): cost, path = adaptSolution(success) #Print solution if len(path) > 0:
if tmpResCap[r] < 0: flag = False #print flag, break if flag: #print flag self.V = self.V + bids[userID][ 0] # might need to handle this differently for multiple bids self.x[userID] = poolId resourceCaps[poolId] = copy.deepcopy(tmpResCap) break #print 'total bid: ', self.V #print 'winner list:', self.x #print 'resourceCaps:', resourceCaps return self.V, self.x if __name__ == '__main__': reader = InputReader() #bundles, times, bids, deadlines = reader.readRequestFile() resourceCaps = reader.readCapacityFile() #vmResourceRequirement = reader.readVMConfigFile() alloactor = ResourceAllocator() alloactor.calculateRelevanceFactor(resourceCaps) #alloactor.calculateRequiredResource(bundles, vmResourceRequirement)
def path(node, count): current = node steps = [] if(node != None): print("Cost:",node.cost) #Total cost of the path while(current != None): if(current.parentNode != None): steps.append(current.movement) current = current.parentNode while(len(steps) > 0): count += 1 print(steps.pop()), #Nodes visited return count #Read the input file reader = InputReader() data = reader.readDFS() #print data #Store the reading results in the global variables #Creating the node for the initial configuration initialConfiguration = TreeNode(None, data[1], None, 0) #Pointing to the global variables goalState = data[2] maxHeight = data[0] initialState = initialConfiguration #Search auxDFS = searchingByDFS()
#DETerminant detMain = data[0][0]*data[1][1] - data[0][1]*data[1][0] detX = data[0][2]*data[1][1] - data[1][2]*data[0][1] detY = data[1][2]*data[0][0] - data[0][2]*data[1][0] if detMain == detX and detX == detY: self.solution = "Uklad oznaczony" if detMain == 0 and detX != detY: self.solution = "Uklad nieoznaczony" self.solution = [detX/detMain, detY/detMain] if __name__=='__main__': print('\n*****************') print('solver - selftest') inReader = InputReader('data.dat') inReader.readEquationsFromFile() inVal = InputValidator( inReader.equations ) inVal.convertDataToFloat() solver = Solver(inVal) solver.solveEq() print('Rozwiazanie rownania:\n') print( solver.solution )
# print 'tmpResCap[' + str(r) + ']', tmpResCap[r] if tmpResCap[r] < 0: flag = False # print flag, break if flag: # print flag self.V = self.V + bids[userID][0] # might need to handle this differently for multiple bids self.x[userID] = poolId resourceCaps[poolId] = copy.deepcopy(tmpResCap) break # print 'total bid: ', self.V # print 'winner list:', self.x # print 'resourceCaps:', resourceCaps return self.V, self.x if __name__ == "__main__": reader = InputReader() # bundles, times, bids, deadlines = reader.readRequestFile() resourceCaps = reader.readCapacityFile() # vmResourceRequirement = reader.readVMConfigFile() alloactor = ResourceAllocator() alloactor.calculateRelevanceFactor(resourceCaps) # alloactor.calculateRequiredResource(bundles, vmResourceRequirement)
def setUp( self ): ''' Construct our InputReader object, pass it the test csv file ''' self.mInputReader = InputReader( testFile )
class FeatureExtractor( metaclass=ABCMeta ): ''' Abstract base class for extracting and generating features from input resource file. Implementation classes must implement getFeatures() and getTrainingData() appropriately for the given input source. ''' def __init__( self, mInputReader , filterPath='../res/FeatureFilter' ): ''' Constructor - arguments passed from main @param mInputReader: InputReader object for setting raw data ''' # Feature dump and filter path self.outCSVPath = '../../tmp/featureDump.csv' self.filterCSVPath = filterPath # Get raw data from the passed InputReader mInputReader.readFile() self.rawData = mInputReader.getRawData() # Initialize feature set and training data from raw data self.features = self.rawData[0] self.trainingData = np.array( self.rawData[1:] ) # Construct the InputReader used for feature filtering self.filterReader = InputReader( self.filterCSVPath ) # Initialize number of samples removed self.nRmvSamples = 0 def setOutCSVPath( self , fPath ): '''@param fPath: relative location and name of feature dump CSV''' self.outCSVPath = fPath def setFilterPath( self , fPath ): '''@param fPath: relative location and name of feature filter CSV''' self.filterCSVPath = fPath def getFeatures( self ): return self.features def getTrainingData( self ): return self.trainingData def setTrainingData( self, data ): assert( isinstance( data, np.ndarray ) ) self.trainingData = data def getSampleCnt( self ): return len( self.trainingData ) def getRmvSampleCnt( self ): return self.nRmvSamples def listIdx( self, feature ): ''' Return the list index of a given feature @param feature: training feature @return index: index of passed feature ''' return self.features.index( feature ) def applyFeatureFilter( self ): ''' Reads the filter resource file and accordingly removes the feature from each sample. ''' # Read out the resource content self.filterReader.readFile() # Stash the results to a local list mFilterList = self.filterReader.getRawData()[0] # Use our list index method to find appropriate column in feature # list to remove for feature in mFilterList: try: idx = self.listIdx( feature ) del self.features[idx] self.trainingData = np.delete( self.trainingData, idx, 1 ) except ValueError: print( 'Unable to remove feature %s!' % feature ) def writeFeaturesToCSV( self ): ''' Dump the transformed data out to CSV for external eval Note: This shouldn't be called w/o extracting features from a derived class first. ''' mDumpFile = open( self.outCSVPath, 'w', newline='' ) mCSVWriter = csv.writer( mDumpFile, delimiter=',' ) # First write the features to the first row of the dump file mCSVWriter.writerow( self.features ) # Then, dump all training data writing by row/record mCSVWriter.writerows( self.trainingData ) # Release file i/o mDumpFile.close() @abstractmethod def extractFeatures( self ): ''' This method is to be implemented by subclasses''' pass def __del__( self ): '''No Destructor implementation''' pass
acumAux = 0.0 if not denominator: acumAux = 1.0 if denominator: relevants = getRelevants(denominator) combinations = combinateRelevants(relevants) if combinations: for combination in combinations: fullList = denominator+ combination acumAux += chain(fullList) else: fullList = denominator acumAux += chain(fullList) result = round(acum/acumAux,7) print (result) reader = InputReader() nodes, queries = reader.read() for query in queries: convertToJoinProb(query) #noChilds= getNodesWithoutChilds(["-Alarm", "+JohnCalls","-Earthquake", "-MaryCalls", "+Burglary"]) #noChilds= getNodesWithoutChilds(["-Earthquake", "-Alarm", "+Burglary"]) #noChilds= getNodesWithoutChilds(["-Earthquake", "+Burglary"])