Example #1
0
def simulate( arrayOfVehicleArrivals ):
    
    # reset global variables such as time, done/failed lots
    common.updateGlobals( arrayOfVehicleArrivals )
    global currentTime
    global llfSimpleIndex

    # initialize a CSV document for storing all data
    csvGen.generateCSV( "llfSimple" )

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate( arrayOfVehicleArrivals ):
        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()

            # check if it actually needs to be charged
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV( vehicle, "Charge Not Needed" )
                common.cantChargeLot.append( vehicle )
                continue

            # there is an open chargePort, add vehicle to it
            if port is not None:

                # add to chargePort
                chargePorts.chargePorts[ port ] = vehicle

                # make listener
                chargePorts.chargePortListeners[ port ].insert( 0 , chargeEvent.ChargeEvent( vehicle , common.currentTime ) )

            # no open chargePort, append to llfQueue
            else:

                llfSimpleQueue.append( vehicle )

                # update the llfIndex if this vehicle is better
                if llfSimpleIndex == -1 or vehicle.laxity < llfSimpleQueue[ llfSimpleIndex ].laxity:
                    llfSimpleIndex = len( llfSimpleQueue ) - 1

        updateVehiclesLLFSimple()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while chargePorts.chargePortsEmpty() == False or len( llfSimpleQueue ) != 0:
        updateVehiclesLLFSimple()
        common.currentTime += 1

    # print "LLF Simple: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  llfQueue size:  " , len( llfSimpleQueue ) , \
    #     "  chargePort " , chargePorts.toString()
        
    # write a CSV of all the data in chargePortListeners
    csvGen.exportChargePortsToCSV( "llfSimple" )

    output = [common.calcProfit(), len(common.doneChargingLot), len(common.failedLot), len(common.declinedLot), common.numberOfVehiclesInSimulation, common.currentTime]
    return output
Example #2
0
def simulate( arrayOfVehicleArrivals ):
    
    # reset global variables such as time, done/failed lots
    common.updateGlobals( arrayOfVehicleArrivals )
    global currentTime
    global earliestDLIndex

    # initialize a CSV document for storing all data
    csvGen.generateCSV( "edf" )

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate( arrayOfVehicleArrivals ):
        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()

            # check if it actually needs to be charged
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV( vehicle, "Charge Not Needed" )
                common.cantChargeLot.append( vehicle )
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort
                chargePorts.chargePorts[ port ] = vehicle

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[ port ].insert( 0 , chargeEvent.ChargeEvent( vehicle, common.currentTime ) )

            # no ports available so put in queue
            else:
                edfQueue.append( vehicle )
                if earliestDLIndex == -1 or vehicle.depTime < edfQueue[ earliestDLIndex ].depTime:
                    earliestDLIndex = len( edfQueue ) - 1
        
        updateVehiclesEDF()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while chargePorts.chargePortsEmpty() == False or not len( edfQueue ) == 0:
        updateVehiclesEDF()
        common.currentTime += 1

    # print "EDF: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  edfQueue size:  " , len( edfQueue ) , \
    #     "  chargePort " , chargePorts.toString()

    # write a CSV with all the chargePort logs
    csvGen.exportChargePortsToCSV( "edf" )
    
    output = [common.calcProfit(), len(common.doneChargingLot), len(common.failedLot), len(common.declinedLot), common.numberOfVehiclesInSimulation, common.currentTime]
    return output
Example #3
0
def simulate( arrayOfVehicleArrivals ):
    
    # reset global variables such as time, done/failed lots
    common.updateGlobals( arrayOfVehicleArrivals )
    global currentTime

    # initialize a CSV document for storing all data
    csvGen.generateCSV( "fcfs" )

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate( arrayOfVehicleArrivals ):
        for vehicle in numVehiclesPerMin:       
            port = chargePorts.openChargePort()

            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV( vehicle, "Charge Not Needed" )
                common.cantChargeLot.append( vehicle )
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort
                chargePorts.chargePorts[ port ] = vehicle
            
                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[ port ].insert( 0 , chargeEvent.ChargeEvent( vehicle, common.currentTime ) )
                
            # no ports are available so put the vehicle in the queue
            else:
                queue.put( vehicle )

        updateVehiclesFCFS()
        common.currentTime += 1

    # print "status:  " , openChargePort() , "  " , queue.empty()
    
    # run the clock until all vehicles have ran through the simulation
    while chargePorts.chargePortsEmpty() == False or not queue.empty():
        updateVehiclesFCFS()
        common.currentTime += 1

    # print "FCFS: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  fcfsQueue size:  " , queue.qsize() , \
    #     "  chargePort " , chargePorts.toString()

    # write a CSV for all the chargePort logs
    csvGen.exportChargePortsToCSV( "fcfs" )
    
    output = [common.calcProfit(), len(common.doneChargingLot), len(common.failedLot), len(common.declinedLot), common.numberOfVehiclesInSimulation, common.currentTime]
    return output
Example #4
0
def simulate( arrayOfVehicleArrivals ):

    #global schedules

    # reset global variables such as time, done/failed lots
    common.updateGlobals( arrayOfVehicleArrivals )
    global currentTime
    # global earliestDLIndex

    # initialize a CSV document for storing all data
    csvGen.generateCSV( "edfPro" )

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate( arrayOfVehicleArrivals ):
        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()

            # check if it actually needs to be charged
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV( vehicle, "Charge Not Needed" )
                common.cantChargeLot.append( vehicle )
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort and schedule
                chargePorts.chargePorts[ port ] = vehicle
                schedules[ port ].insert( 0 , vehicle )

                if len( schedules[ port ] ) > 1:
                    print "empty chargePort, but shit was scheduled to be there"
                    break

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[ port ].insert( 0 , chargeEvent.ChargeEvent( vehicle, common.currentTime ) )

            # no ports available so try to put it in a queue, but have to find one that will work
            else:

                bestSchedule = -1
                scheduleFlex = float( "inf" );
                
                # iterate through every schedule
                for index, schedule in enumerate( schedules ):

                    # insert a vehicle in the schedule and get its admission feasibility
                    insertLocation =  insertIntoSchedule( vehicle , index )
                    insertLocation = int( insertLocation )
                    admissionTest  =  genAdmissionFeasiblity( index )
                   
                    # will it work?
                    tempFlex = admissionFeasibility( index , admissionTest )

                    # check if it can work for this sched
                    if tempFlex == False:

                        # if it can't work, delete from schedule and move on
                        del schedules[ index ][ insertLocation ]
                        continue

                    # now check if it's the best one
                    if tempFlex < scheduleFlex:
                        scheduleFlex = tempFlex
                        bestSchedule = index

                    # regardless, delete from schedule for now
                    del schedules[ index ][ insertLocation ]

                # now will we do an official insert? or decline
                if bestSchedule >= 0 and scheduleFlex > 0:
                    insertIntoSchedule( vehicle , bestSchedule )

                # decline
                else:
                    csvGen.exportVehicleToCSV( vehicle, "DECLINED" )
                    common.declinedLot.append( vehicle )

        updateVehiclesEDFPro()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while chargePorts.chargePortsEmpty() == False or not schedulesEmpty():
        updateVehiclesEDFPro()
        common.currentTime += 1

    # print "EDFPro: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  declined lot: ", len( common.declinedLot ), \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  schedules:  " , schedulesEmpty() , \
    #     "  chargePort " , chargePorts.toString()

    # write a CSV with all the chargePort logs
    csvGen.exportChargePortsToCSV( "edfPro" )
    
    output = [common.calcProfit(), len(common.doneChargingLot), len(common.failedLot), len(common.declinedLot), common.numberOfVehiclesInSimulation, common.currentTime]
    return output
Example #5
0
def simulate(arrayOfVehicleArrivals):

    #global schedules

    # reset global variables such as time, done/failed lots
    common.updateGlobals(arrayOfVehicleArrivals)
    global currentTime
    # global earliestDLIndex

    # initialize a CSV document for storing all data
    csvGen.generateCSV("llfSimpleACPro")

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate(arrayOfVehicleArrivals):
        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()

            # check if it actually needs to be charged
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV(vehicle, "Charge Not Needed")
                common.cantChargeLot.append(vehicle)
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort and schedule
                chargePorts.chargePorts[port] = vehicle
                schedules[port].insert(0, vehicle)

                # make it break if something isn't right
                if len(schedules[port]) > 1:
                    print "empty chargePort, but shit was scheduled to be there"
                    break

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[port].insert(
                    0, chargeEvent.ChargeEvent(vehicle, common.currentTime))

            # no ports available so try to put it in a queue, but have to find one that will work
            else:

                bestSchedule = -1
                scheduleFlex = float("inf")

                # iterate through every schedule
                for index, schedule in enumerate(schedules):

                    # insert a vehicle in the schedule and get its admission feasibility
                    insertLocation = insertIntoSchedule(vehicle, index)
                    insertLocation = int(insertLocation)
                    admissionTest = genAdmissionFeasiblity(index)

                    # will it work?
                    tempFlex = admissionFeasibility(index, admissionTest)

                    # check if it can work for this sched
                    if tempFlex == False:

                        # if it can't work, delete from schedule and move on
                        del schedules[index][insertLocation]
                        continue

                    # now check if it's the best one
                    if tempFlex < scheduleFlex:
                        scheduleFlex = tempFlex
                        bestSchedule = index

                    # regardless, delete from schedule for now
                    del schedules[index][insertLocation]

                # now will we do an official insert? or decline
                if bestSchedule >= 0 and scheduleFlex > 0:
                    insertIntoSchedule(vehicle, bestSchedule)

                # decline
                else:
                    csvGen.exportVehicleToCSV(vehicle, "DECLINED")
                    common.declinedLot.append(vehicle)

        updateVehiclesLLFPro()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while chargePorts.chargePortsEmpty() == False or not schedulesEmpty():
        updateVehiclesLLFPro()
        common.currentTime += 1

    # print "LLFSimple AC Pro: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  declined lot: ", len( common.declinedLot ), \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  schedules:  " , schedulesEmpty() , \
    #     "  chargePort " , chargePorts.toString()

    # write a CSV with all the chargePort logs
    csvGen.exportChargePortsToCSV("llfSimpleACPro")

    output = [
        common.calcProfit(),
        len(common.doneChargingLot),
        len(common.failedLot),
        len(common.declinedLot), common.numberOfVehiclesInSimulation,
        common.currentTime
    ]
    return output
Example #6
0
def simulate(arrayOfVehicleArrivals):

    # reset global variables such as time, done/failed lots
    common.updateGlobals(arrayOfVehicleArrivals)
    global currentTime
    global earliestDLIndex

    # initialize a CSV document for storing all data
    csvGen.generateCSV("edf")

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate(arrayOfVehicleArrivals):
        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()

            # check if it actually needs to be charged
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV(vehicle, "Charge Not Needed")
                common.cantChargeLot.append(vehicle)
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort
                chargePorts.chargePorts[port] = vehicle

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[port].insert(
                    0, chargeEvent.ChargeEvent(vehicle, common.currentTime))

            # no ports available so put in queue
            else:
                edfQueue.append(vehicle)
                if earliestDLIndex == -1 or vehicle.depTime < edfQueue[
                        earliestDLIndex].depTime:
                    earliestDLIndex = len(edfQueue) - 1

        updateVehiclesEDF()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while chargePorts.chargePortsEmpty() == False or not len(edfQueue) == 0:
        updateVehiclesEDF()
        common.currentTime += 1

    # print "EDF: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  edfQueue size:  " , len( edfQueue ) , \
    #     "  chargePort " , chargePorts.toString()

    # write a CSV with all the chargePort logs
    csvGen.exportChargePortsToCSV("edf")

    output = [
        common.calcProfit(),
        len(common.doneChargingLot),
        len(common.failedLot),
        len(common.declinedLot), common.numberOfVehiclesInSimulation,
        common.currentTime
    ]
    return output
Example #7
0
def simulate(arrayOfVehicleArrivals):

    # reset global variables such as time, done/failed lots
    common.updateGlobals(arrayOfVehicleArrivals)
    global currentTime
    global llfSimpleIndex

    # initialize a CSV document for storing all data
    csvGen.generateCSV("llfSimple")

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate(arrayOfVehicleArrivals):
        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()

            # check if it actually needs to be charged
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV(vehicle, "Charge Not Needed")
                common.cantChargeLot.append(vehicle)
                continue

            # there is an open chargePort, add vehicle to it
            if port is not None:

                # add to chargePort
                chargePorts.chargePorts[port] = vehicle

                # make listener
                chargePorts.chargePortListeners[port].insert(
                    0, chargeEvent.ChargeEvent(vehicle, common.currentTime))

            # no open chargePort, append to llfQueue
            else:

                llfSimpleQueue.append(vehicle)

                # update the llfIndex if this vehicle is better
                if llfSimpleIndex == -1 or vehicle.laxity < llfSimpleQueue[
                        llfSimpleIndex].laxity:
                    llfSimpleIndex = len(llfSimpleQueue) - 1

        updateVehiclesLLFSimple()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while chargePorts.chargePortsEmpty() == False or len(llfSimpleQueue) != 0:
        updateVehiclesLLFSimple()
        common.currentTime += 1

    # print "LLF Simple: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  llfQueue size:  " , len( llfSimpleQueue ) , \
    #     "  chargePort " , chargePorts.toString()

    # write a CSV of all the data in chargePortListeners
    csvGen.exportChargePortsToCSV("llfSimple")

    output = [
        common.calcProfit(),
        len(common.doneChargingLot),
        len(common.failedLot),
        len(common.declinedLot), common.numberOfVehiclesInSimulation,
        common.currentTime
    ]
    return output
Example #8
0
def simulate( arrayOfVehicleArrivals ):

    # reset global variables such as time, done/failed lots
    common.updateGlobals( arrayOfVehicleArrivals )
    global currentTime

    # initialize a CSV document for storing all data
    csvGen.generateCSV( "fcfsAC" )

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate( arrayOfVehicleArrivals ):
        for vehicle in numVehiclesPerMin:       
            port = chargePorts.openChargePort()

            # in case something wrong with distribution, pull vehicle out of system
            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV( vehicle, "Charge Not Needed" )
                common.cantChargeLot.append( vehicle )
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort
                chargePorts.chargePorts[ port ] = vehicle
                schedules[ port ].append(vehicle)

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[ port ].insert( 0 , chargeEvent.ChargeEvent( vehicle, common.currentTime ) )

            # no ports are available so put the vehicle in the queue
            else:
                # queue.put( vehicle )

                bestPortInfo     =  findEarliestEndingSchedule()
                bestPortIndex    =  bestPortInfo[ 0 ]      #index
                bestPortEndTime  =  bestPortInfo[ 1 ]      #end time

                # vehicle declined because not enough time to charge
                if vehicle.depTime - bestPortEndTime < vehicle.timeToCharge:
                    csvGen.exportVehicleToCSV( vehicle, "DECLINED" )
                    common.declinedLot.append( vehicle )

                # vehicle appended to best schedule
                else:
                    schedules[ bestPortIndex ].append( vehicle )

        updateVehiclesFCFSAC()
        common.currentTime += 1

    # print "status:  " , openChargePort() , "  " , queue.empty()

    # run the clock until all vehicles have ran through the simulation
    while chargePorts.chargePortsEmpty() == False or not schedulesEmpty():
        updateVehiclesFCFSAC()
        common.currentTime += 1

    # print "FCFSAC: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #   "  elapsed time: " , common.currentTime , \
    #   "  done charging lot: " , len( common.doneChargingLot ) , \
    #   "  failed charging lot: " , len( common.failedLot ) , \
    #   "  cant charge lot: " , len( common.cantChargeLot ) , \
    #   "  declined lot: "  , len( common.declinedLot ) , \
    #   "  fcfsACQueue schedules:  " , schedules , \
    #   "  chargePort " , chargePorts.toString()

    # write a CSV for all the chargePort logs
    csvGen.exportChargePortsToCSV( "fcfsAC" )

    output = [common.calcProfit(), len(common.doneChargingLot), len(common.failedLot), len(common.declinedLot), common.numberOfVehiclesInSimulation, common.currentTime]
    return output
Example #9
0
def simulate(arrayOfVehicleArrivals):

    # reset global variables such as time, done/failed lots
    common.updateGlobals(arrayOfVehicleArrivals)

    global currentTime
    global numOverlapInserts
    global minutesCharged
    global allVehicles

    minutesCharged = [0] * common.numberOfVehiclesInSimulation
    allVehicles = []

    # initialize a CSV document for storing all data
    csvGen.generateCSV("dsac")

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate(arrayOfVehicleArrivals):

        for vehicle in numVehiclesPerMin:
            port = chargePorts.openChargePort()
            allVehicles.append(vehicle)

            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV(vehicle, "Charge Not Needed")
                common.cantChargeLot.append(vehicle)
                print "CHARGE NOT NEEDED: ", vehicle.id
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort and respective schedule
                chargePorts.chargePorts[port] = vehicle
                schedules[port].append(vehicle)

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[port].insert(
                    0, chargeEvent.ChargeEvent(vehicle, common.currentTime))

                continue
            # no ports are available so put the vehicle in the queue
            else:

                # any appendables?
                appendable = findAppendableChargePort(vehicle)

                # add to schedule
                if appendable != -1:
                    # there is at least one car in the schedule
                    if len(schedules[appendable]) > 0:
                        tempVehicle = schedules[appendable][len(
                            schedules[appendable]) - 1]  #last item
                        newStartTime = tempVehicle.startTime + tempVehicle.timeToCharge

                    # schedule is appendable because it is empty
                    else:
                        carInChargePort = chargePorts.chargePorts[appendable]
                        newStartTime = carInChargePort.startTime + carInChargePort.timeToCharge

                    vehicle.updateStartTime(newStartTime)
                    schedules[appendable].append(vehicle)

                # an ugly conflict
                else:
                    vehicle.updateStartTime(vehicle.depTime -
                                            vehicle.timeToCharge)

                    leastProfitConflictResults = leastProfitConflict(vehicle)
                    leastProfitConflictPort = leastProfitConflictResults[0]
                    leastProfitConflictSchedule = leastProfitConflictResults[1]

                    # vehicle appended with conflict
                    if leastProfitConflictPort > 0:
                        schedules[
                            leastProfitConflictPort] = leastProfitConflictSchedule
                        numOverlapInserts += 1
                        if leastProfitConflictSchedule[0] == vehicle:
                            chargePorts.chargePorts[
                                leastProfitConflictPort] = vehicle

                    else:
                        # CSV to decline car
                        csvGen.exportVehicleToCSV(vehicle, "DECLINED")
                        common.declinedLot.append(vehicle)

        updateVehicles()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while not chargePorts.chargePortsEmpty() or not schedulesEmpty():        \

        updateVehicles()
        common.currentTime += 1

    # print "DSAC: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  declind lot: ", len( common.declinedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  schedules:  " , schedulesToString() , \
    #     "  chargePorts " , chargePorts.toString()

    # write a CSV for all the chargePort logs
    csvGen.exportChargePortsToCSV("dsac")

    failed = uniqueVehicles(common.failedLot)
    done = uniqueVehicles(
        common.doneChargingLot
    ) - failed  # if a car gets split and is in done and failed, that is considered failed
    declined = uniqueVehicles(common.declinedLot)

    output = [
        totalProfit(),
        len(done),
        len(failed),
        len(declined), common.numberOfVehiclesInSimulation, common.currentTime
    ]
    return output
Example #10
0
def simulate( arrayOfVehicleArrivals ):

    # reset global variables such as time, done/failed lots
    common.updateGlobals( arrayOfVehicleArrivals )

    global currentTime
    global numOverlapInserts
    global minutesCharged 
    global allVehicles

    minutesCharged = [0] * common.numberOfVehiclesInSimulation
    allVehicles = []

    # initialize a CSV document for storing all data
    csvGen.generateCSV( "dsac" )

    # iterate through each vehicle in each minute
    for minute, numVehiclesPerMin in enumerate( arrayOfVehicleArrivals ):

        for vehicle in numVehiclesPerMin: 
            port = chargePorts.openChargePort()
            allVehicles.append(vehicle)

            if vehicle.currentCharge > vehicle.chargeNeeded:
                csvGen.exportVehicleToCSV( vehicle, "Charge Not Needed" )
                common.cantChargeLot.append( vehicle )
                print "CHARGE NOT NEEDED: ",vehicle.id
                continue

            # a port is open so start charging the vehicle
            if port is not None:

                # add to chargePort and respective schedule
                chargePorts.chargePorts[ port ] = vehicle
                schedules[ port ].append( vehicle )

                # initialize a listener object for its charging activity
                chargePorts.chargePortListeners[ port ].insert( 0 , chargeEvent.ChargeEvent( vehicle, common.currentTime ) )
    
                continue
            # no ports are available so put the vehicle in the queue
            else:

                # any appendables?
                appendable = findAppendableChargePort( vehicle )

                # add to schedule
                if appendable != -1:
                    # there is at least one car in the schedule
                    if len(schedules[ appendable ]) > 0:
                        tempVehicle = schedules[ appendable ][ len( schedules[ appendable ] ) - 1  ] #last item
                        newStartTime = tempVehicle.startTime + tempVehicle.timeToCharge

                    # schedule is appendable because it is empty 
                    else:
                        carInChargePort = chargePorts.chargePorts[ appendable ]
                        newStartTime = carInChargePort.startTime + carInChargePort.timeToCharge

                    vehicle.updateStartTime( newStartTime )
                    schedules[ appendable ].append( vehicle )

                # an ugly conflict
                else:
                    vehicle.updateStartTime( vehicle.depTime - vehicle.timeToCharge )
                    
                    leastProfitConflictResults = leastProfitConflict( vehicle )
                    leastProfitConflictPort = leastProfitConflictResults[0]
                    leastProfitConflictSchedule = leastProfitConflictResults[1]

                    # vehicle appended with conflict
                    if leastProfitConflictPort > 0:
                        schedules[ leastProfitConflictPort ] = leastProfitConflictSchedule
                        numOverlapInserts += 1
                        if leastProfitConflictSchedule[0] == vehicle:
                            chargePorts.chargePorts[leastProfitConflictPort] = vehicle

                    else:
                        # CSV to decline car
                        csvGen.exportVehicleToCSV( vehicle, "DECLINED" )
                        common.declinedLot.append( vehicle )


        updateVehicles()
        common.currentTime += 1

    # vehicles done arriving, now continue with the simulation
    while not chargePorts.chargePortsEmpty() or not schedulesEmpty():\

        updateVehicles()
        common.currentTime += 1

    # print "DSAC: total number of cars: ", common.numberOfVehiclesInSimulation , \
    #     "  elapsed time: " , common.currentTime , \
    #     "  done charging lot: " , len( common.doneChargingLot ) , \
    #     "  failed charging lot: " , len( common.failedLot ) , \
    #     "  declind lot: ", len( common.declinedLot ) , \
    #     "  cant charge lot: " , len( common.cantChargeLot ) , \
    #     "  schedules:  " , schedulesToString() , \
    #     "  chargePorts " , chargePorts.toString()

    # write a CSV for all the chargePort logs
    csvGen.exportChargePortsToCSV( "dsac" )

    failed = uniqueVehicles(common.failedLot)
    done = uniqueVehicles(common.doneChargingLot) - failed # if a car gets split and is in done and failed, that is considered failed
    declined = uniqueVehicles(common.declinedLot)

    output = [totalProfit(), len(done), len(failed), len(declined), common.numberOfVehiclesInSimulation, common.currentTime]
    return output