def simulation_optimization_runV2(failureRates,
                                  serviceRates,
                                  holdingCosts,
                                  penalty,
                                  skillServerAssignment,
                                  replications=replicationsDefault,
                                  stopNrRequests=stopNrRequestsDefault,
                                  numberWarmingUpRequests=0,
                                  maxQ=maxQueue):

    totalCostList = []
    for i in xrange(replications):
        numberInSystemDistributionAverage, _, _, _ = \
            simulation_batch_run(failureRates = failureRates,
                                serviceRates = serviceRates,
                                skillServerAssignment = skillServerAssignment,
                                histogramBucketsInput = [],
                                expectedTotalNumberRequests = stopNrRequests,
                                numberWarmingUpRequests = numberWarmingUpRequests,
                                replications=1,
                                maxQueue=maxQ,
                                startSeed=100+i*30)

        if numberInSystemDistributionAverage is not None:
            totalCost, _, _ = OptimizeStockLevelsAndCostsSimBased(
                holdingCosts, penalty, numberInSystemDistributionAverage)
            totalCostList.append(totalCost)

    return totalCostList
def simulation_optimization_run(failureRates,
                                serviceRates,
                                holdingCosts,
                                penalty,
                                skillServerAssignment,
                                stopNrRequests=stopNrRequestsDefault,
                                replications=replicationsDefault,
                                numberWarmingUpRequests=0,
                                runTheSimulation=True,
                                useDatabase=True,
                                maxQ=maxQueue):

    numberInSystemDistributionAverage = None
    utilizationRatesAverage = None
    skillServerAssignmentStatisitcsAverage = None

    m_skills = skillServerAssignment.shape[1]
    n_servers = skillServerAssignment.shape[0]

    databaseUpdated = False
    if useDatabase:
        numberInSystemDistributionAverage = getRecordFromDB(
            n_servers, m_skills, failureRates, serviceRates,
            skillServerAssignment)

    if numberInSystemDistributionAverage is None and runTheSimulation:

        # run the simulaiton
        # print "run simulation:", skillServerAssignment, failureRates, serviceRates
        if checkSkillAssignment(skillServerAssignment, failureRates,
                                serviceRates):
            # print skillServerAssignment.tolist(), failureRates, serviceRates,
            numberInSystemDistributionAverage, _, utilizationRatesAverage, skillServerAssignmentStatisitcsAverage\
                    = simulation_batch_run( failureRates = failureRates,
                                            serviceRates = serviceRates,
                                            skillServerAssignment = skillServerAssignment,
                                            histogramBucketsInput = [],
                                            # stopTimeInput=stopTime,
                                            expectedTotalNumberRequests = stopNrRequests,
                                            numberWarmingUpRequests = numberWarmingUpRequests,
                                            replications=replications,
                                            maxQueue=maxQ,
                                            nCores=nCores)

            if useDatabase:
                databaseUpdated = writeToDB(
                    n_servers, m_skills, failureRates, serviceRates,
                    skillServerAssignment, numberInSystemDistributionAverage,
                    utilizationRatesAverage,
                    skillServerAssignmentStatisitcsAverage)

    totalCost = float('inf')
    S = np.zeros(m_skills, dtype=int)
    EBO = np.zeros(m_skills)
    if numberInSystemDistributionAverage is not None:
        # print [np.nanmean([numberInSystemDistributionAverage[j][i-1]/numberInSystemDistributionAverage[j][i]*failureRates[j] for i in range(3,15)]) for j in range(m_skills)]
        totalCost, S, EBO = OptimizeStockLevelsAndCostsSimBased(
            holdingCosts, penalty, numberInSystemDistributionAverage)

    return totalCost, S, EBO, databaseUpdated, utilizationRatesAverage, skillServerAssignmentStatisitcsAverage
예제 #3
0
        print n, sku_num, failureRates, serviceRates,


        assignmentID = 0
        for skillServerAssignment in generateSkillsMultiServer(n, sku_num):
            if checkSkillAssignment(skillServerAssignment, failureRates, serviceRates):
                assignmentID +=1
                case["assignments"][assignmentID] = dict()
                case["assignments"][assignmentID]["skill_assignment"] = np.transpose(skillServerAssignment).tolist()

                numberInSystemDistributionAverage, waitingTimeHistogramAverage, utilizationRatesAverage, skillServerAssignmentStatisitcsAverage  \
                    = simulation_batch_run(failureRates, serviceRates, skillServerAssignment,
                                              histogramBucketsInput = waitingTimeBuckets,
                                              # stopTimeInput = stopTimeInput*np.sum(failureRates),
                                              expectedTotalNumberRequests = stopNrRequests,
                                              numberWarmingUpRequests = 1000,
                                              replications=replications,
                                              maxQueue=maxQueue,
                                              nCores=cores)

                case["assignments"][assignmentID]["queue_length_distributions"] = dict()
                case["assignments"][assignmentID]["waiting_time_distributions"] = dict()
                for sk in range(sku_num):
                    case["assignments"][assignmentID]["queue_length_distributions"][sk] \
                        = {k: v for k, v in zip(range(maxQueue), numberInSystemDistributionAverage[sk]) if v != 0} #remove zero values
                    case["assignments"][assignmentID]["waiting_time_distributions"][sk] \
                        = {k: v for k, v in zip(waitingTimeBuckets, waitingTimeHistogramAverage[sk]) if v != 0} #remove zero values
                case["assignments"][assignmentID]["utilization_rates"] = utilizationRatesAverage.tolist()
                case["assignments"][assignmentID]["skill_server_distribution"] = skillServerAssignmentStatisitcsAverage.tolist()

        print assignmentID