示例#1
0
def penaltyFunction(lamb, mu, numServers, simTime, numReps, maxMIPS, aggressivness):
    mySim = Simulator(lam, mu, numServers, simTime, numRepsSim, maxMIPS, aggressivness)
    mySim.runSimulation()
    totalPenalty = 0

    maxTemps                = mySim.getMaxTemps()
    responseTimes           = mySim.getAvgResponseTime()
    avgjobsinsys            = mySim.getAvgJobsInSimulation()
    avgUtilizations         = mySim.getAvgServerUtils()
    powerConsumedByServers  = mySim.getPowerConsumptions()

    for rep in powerConsumedByServers:
        repIndex = powerConsumedByServers.index(rep)

        print '*****************************************************'
        print 'Log dump for rep', repIndex+1
        print 'Avg avg utils: ', sum(avgUtilizations[repIndex]) / len(avgUtilizations[repIndex])
        print 'Avg power consumed', sum(powerConsumedByServers[repIndex]) / len(powerConsumedByServers[repIndex])
        print 'Avg Response Time', sum(responseTimes[repIndex]) / len(responseTimes[repIndex])
        for i in range(0, len(rep)):
            print 'Server', i, '\tUtil:', avgUtilizations[repIndex][i], '\tMax temp:', maxTemps[repIndex][i],  '\t\tConsumed:', powerConsumedByServers[repIndex][i], '\tRT:', responseTimes[repIndex][i]

        maxTempForRep      = max(maxTemps[repIndex])
        maxPowerConsForRep = max(powerConsumedByServers[repIndex])
        maxUtilForRep      = max(avgUtilizations[repIndex])
        maxRTForRep        = max(responseTimes[repIndex])

        # Huge penalties for infeasible solutions
        if maxTempForRep > maxTemperature:
            totalPenalty += maxTempForRep
        if maxUtilForRep > maxUtilization:
            totalPenalty += maxUtilForRep
        if maxRTForRep > maxResponseTime:
            totalPenalty += maxRTForRep

        # Calculate norms against the maximums for each list
        # No actual use for this, penalties wouldn't make sense since the normalized scores can only be compared relative to the max...
        # normMaxTemps        = [float(i)/maxTempForRep for i in maxTemps[repIndex]].sort(reverse=True)
        # normPowerConsumed   = [float(i)/maxPowerConsForRep for i in powerConsumedByServers[repIndex]].sort(reverse=True)
        # normAvgUtils        = [float(i)/maxUtilForRep for i in avgUtilizations[repIndex]].sort(reverse=True)
        # normResponseTimes   = [float(i)/maxRTForRep for i in responseTimes[repIndex]].sort(reverse=True)

        avgMaxTempForRep    = sum(maxTemps[repIndex]) / len(maxTemps[repIndex])
        avgPowerConsForRep  = sum(powerConsumedByServers[repIndex]) / len(powerConsumedByServers[repIndex])
        avgUtilForRep       = sum(avgUtilizations[repIndex]) / len(avgUtilizations[repIndex])
        avgRTForRep         = sum(responseTimes[repIndex]) / len(responseTimes[repIndex])

        for item in rep:
            itemIndex = rep.index(item)
            if maxTemps[repIndex][itemIndex] > avgMaxTempForRep:
                totalPenalty += maxTemps[repIndex][itemIndex] - avgMaxTempForRep
            if powerConsumedByServers[repIndex][itemIndex] > avgPowerConsForRep:
                totalPenalty += powerConsumedByServers[repIndex][itemIndex] - avgPowerConsForRep
            if avgUtilizations[repIndex][itemIndex] > avgUtilForRep:
                totalPenalty += avgUtilizations[repIndex][itemIndex] - avgUtilForRep
            if responseTimes[repIndex][itemIndex] > avgRTForRep:
                totalPenalty += responseTimes[repIndex][itemIndex] - avgRTForRep
        # ENDFOR
    return totalPenalty
maxMIPS = 2500000
aggressivness = 0.10

util = lamb / (float)(mu * c)

# 	def __init__(lamb, mu, c, simTime, reps):
mySim = Simulator(lamb, mu, c, st, reps, maxMIPS, c * aggressivness)

mySim.runSimulation()

throughput = mySim.getThroughput()
avgjobsinsys = mySim.getAvgJobsInSimulation()
powerConsumedByServers = mySim.getPowerConsumptions()
avgUtilizations = mySim.getAvgServerUtils()
maxTemps = mySim.getMaxTemps()
rrs = mySim.getAvgResponseTime()

roundedAvg = [round(elem, accuracy) for elem in avgjobsinsys]
roundedThroughput = [round(elem, accuracy) for elem in throughput]

print '*****************************************************'
print 'Params: (', lamb, ', ', mu, ', ', c, ', ', st, ', ', reps, ', ', maxMIPS, ')'

print 'Utilization: ', round(util, accuracy)

print 'Throughput: ', roundedThroughput

print 'Avg # Jobs in System: ', roundedAvg

print 'Throughput Average: ', round(
    (sum(roundedThroughput) / len(roundedThroughput)), accuracy)