def test_get_booking_distance_bins(self):
     number = 10
     bounding_box = (13.34014892578125, 52.52791908000258, 13.506317138671875, 52.562995039558004)
     instance = Simulator(bounding_box);
     response = Simulator.get_booking_distance_bins(instance, number);
     actualSum=sum(response.values())
     self.assertEqual(actualSum,number)
Example #2
0
def main():
    """ Main program function. """
    resources_path = Path(os.path.dirname(os.path.abspath(__file__))).parent / 'resource'
    print(resources_path)
    all_players = load_players(resources_path / 'players.json')
    simulator = Simulator(resources_path)
    simulator.run(all_players)
Example #3
0
    def test_simultor_2_steps(self):
        simulator = Simulator()

        simulator.run(2)

        self.assertEqual(len(simulator.grid.cells), 2)

        for cell in simulator.grid.cells:
            self.assertEqual(simulator.grid.cells[cell].color, Color.BLACK)
Example #4
0
    def test_simultor_1_step(self):
        simulator = Simulator()

        simulator.run(1)

        self.assertEqual(len(simulator.grid.cells), 1)

        element = list(simulator.grid.cells.keys())[0]

        self.assertEqual(element, Simulator.ORIGIN)
        self.assertEqual(simulator.grid.cells[element].color, Color.BLACK)

        self.assertEqual(simulator.robot.move_orientation, WindRose.EAST)
Example #5
0
def main():

    woman = 500
    man = 500
    years = 20
    if len(argv) == 4:
        woman = int(argv[1])
        man = int(argv[2])
        years = int(argv[3])
    s = Simulator()
    s.build(woman, man, 12 * years)
    collector = s.sim()

    if argv.count('graph'):
        from app import app
        app.data = collector
        app.run(host='0.0.0.0', port=8000, debug=False)
Example #6
0
    def build(self):
        Config.set('graphics', 'width', '380')
        Config.set('graphics', 'height', '500')

        self.root = T2Root()
        self.simulator = Simulator(0, 0, 0, 0, 0)
        self.root.app = self
        return self.root
Example #7
0
def test_event_computation():
    import argparse
    # args = {
    #     'use_reserve': False,
    #     'num_stations': 20
    # }
    parser = argparse.ArgumentParser(description='Process simulation args')
    parser.add_argument('--use_reserve', default=False, type=bool)
    parser.add_argument('--num_stations', default=20, type=int)
    args = parser.parse_args()

    simulator = Simulator(args)
    current_init = CallInit(0, 0, 1, 0, 0.5, 1)
    speed, position, duration, direction = current_init.get_params()
    next_event_type, _, _, _, _, _ = simulator.compute_next_event(
        speed, position, duration, direction,
        simulator.stations_array[current_init.station_id], current_init)

    assert next_event_type == "Termination"
Example #8
0
    def put(self, steps):
        simulator = Simulator()

        simulator.run(steps)

        folder = 'simulations'
        filename = 'simulation-%d-%s' % (steps, uuid.uuid4())
        simulator.export_grid(os.path.join(folder, filename))

        return filename
 def runner():
     simulator = Simulator()
     simulator.evolve(dt=0.1)
def benchmark_memory():
    simulator = Simulator(particle_count=100000)
    simulator.evolve(dt=0.0001)
#! /usr/bin/env python2.7

import src.simulator
import sys

from src.simulator import Simulator
port = 0
if (len(sys.argv) == 3):
   if (sys.argv[1] == "-p"):
      port = int(sys.argv[2])
      print(port)
sim = Simulator(port)
sim.run()
def main(args):
    check_path = Path(f'./results/warmups/res_{args.num_reserve}_blocked.npy')
    # capture stats
    blocked_arr = []
    dropped_arr = []
    num_inits = num_handover = num_terminate = 0
    if not check_path.exists():
        # set the base seed
        np.random.seed(args.seed)
        simulator = Simulator(args)  # init simulator

        # for step in tqdm(range(args.steps), leave=False):
        for step in tqdm(range(args.steps)):
            event = simulator.FEL.dequeue()
            simulator.clock = event.time  # advance clock to event
            # clock_times.append(simulator.clock)

            if isinstance(event, CallInit):
                simulator.handle_call_init(event)
                num_inits += 1
            elif isinstance(event, CallHandover):
                num_handover += 1
                if args.num_reserve == 0:
                    simulator.handle_call_handover_no_res(event)
                else:
                    simulator.handle_call_handover_res(event)
            elif isinstance(event, CallTerminate):
                num_terminate += 1
                simulator.handle_call_termination(event)
            else:
                raise TypeError("Wrong event type in FEL")

            blocked_arr.append(
                (simulator.blocked_calls / simulator.total_calls) * 100)
            dropped_arr.append(
                (simulator.dropped_calls / simulator.total_calls) * 100)

        np.save(f'./results/warmups/res_{args.num_reserve}_blocked.npy',
                blocked_arr)
        np.save(f'./results/warmups/res_{args.num_reserve}_dropped.npy',
                dropped_arr)

    else:
        blocked_arr = np.load(
            f'./results/warmups/res_{args.num_reserve}_blocked.npy')
        dropped_arr = np.load(
            f'./results/warmups/res_{args.num_reserve}_dropped.npy')

    fig, ax = plt.subplots()

    ############################ UNUSED ########################
    # plt.plot(clock_times, blocked_percents, label='blocked')
    # plt.plot(clock_times, dropped_percents, label="dropped")
    # plt.xlabel('clock times')
    ############################################################

    ax.plot(blocked_arr, label='blocked')
    ax.plot(dropped_arr, label="dropped")
    ax.vlines(x=args.plot_at,
              ymin=-0.1,
              ymax=args.ymax,
              color='r',
              linestyle='dashed')
    ax.set_xlabel('Number of Events')
    ax.set_ylabel('Percentages')
    plt.legend()
    ax.set_title('Percentages of Dropped and Blocked Calls')

    fig.savefig(f'./images/warmups/res_{args.num_reserve}.png')
def main(args):
    # set the base seed
    np.random.seed(args.seed)
    final_blocked_arr = []
    final_dropped_arr = []
    seeds = list(np.random.randint(1, 20381, size=args.reps))
    print(f'Seeds: {seeds}')

    for rep in tqdm(range(args.reps)):
        np.random.seed(seeds[rep]) # scipy uses numpy seeds
        # print('Simulator initialised')
        args.seed = seeds[rep] # so simulator sets correct internal seed
        simulator = Simulator(args) # init simulator

        # capture stats
        blocked_arr = []
        dropped_arr = []
        num_inits = num_handover = num_terminate = 0
        warmed_up = False

        # for step in tqdm(range(args.steps), leave=False):
        for step in range(args.steps):
            # if step % 10000 == 0:
            #     print(f'Currently in step {step}')
            if step > args.warmup and not warmed_up:
                # print('Simulator reset')
                simulator.reset()
                warmed_up = True

            event = simulator.FEL.dequeue()
            simulator.clock = event.time # advance clock to event
            # clock_times.append(simulator.clock)

            if isinstance(event, CallInit):
                simulator.handle_call_init(event)
                num_inits += 1
            elif isinstance(event, CallHandover):
                num_handover += 1
                if args.num_reserve == 0:
                    simulator.handle_call_handover_no_res(event)
                else:
                    simulator.handle_call_handover_res(event)
            elif isinstance(event, CallTerminate):
                num_terminate += 1
                simulator.handle_call_termination(event)
            else:
                raise TypeError("Wrong event type in FEL")

            if warmed_up: # only start collecting when warmed up
                # print("total calls", simulator.total_calls)
                #! BUG FOUND, not the fault of the pool!!!
                # I had just reset and then entered this section where I attempt to divide by 0
                assert simulator.total_calls != 0
                percent_blocked = (simulator.blocked_calls / simulator.total_calls) * 100
                percent_dropped = (simulator.dropped_calls / simulator.total_calls) * 100
                blocked_arr.append(percent_blocked)
                dropped_arr.append(percent_dropped)

        final_blocked_arr.append(np.mean(blocked_arr))
        final_dropped_arr.append(np.mean(dropped_arr))        

    np.save(f'./results/reps_{args.reps}_blocked.npy', final_blocked_arr)
    np.save(f'./results/reps_{args.reps}_dropped.npy', final_dropped_arr)
#!/usr/bin/env python3

from src.game import Game
from src.player import MartingalePlayer, SevenRedsPlayer, Player1326, PlayerFibonacci
from src.simulator import Simulator
from src.table import Table
from src.wheel import Wheel

from test.non_random import NonRandom

chosen_player = PlayerFibonacci


wheel = Wheel()
table = Table(1000)
game = Game(wheel, table)
player = chosen_player(table)
simulator = Simulator(game, player)

# possible_outcomes = []
# for bin in wheel.bin_iterator():
#     for outcome in bin:
#         possible_outcomes.append(outcome)
# self.player.set_possible_outcomes(possible_outcomes)

simulator.gather()
print(simulator.durations)
print(simulator.maxima)
Example #15
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1274, 896)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout_9 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout_9.setObjectName("gridLayout_9")
        self.tab_view = QtWidgets.QTabWidget(self.centralwidget)
        self.tab_view.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.tab_view.setTabPosition(QtWidgets.QTabWidget.North)
        self.tab_view.setTabShape(QtWidgets.QTabWidget.Triangular)
        self.tab_view.setElideMode(QtCore.Qt.ElideLeft)
        self.tab_view.setDocumentMode(False)
        self.tab_view.setTabsClosable(False)
        self.tab_view.setMovable(False)
        self.tab_view.setTabBarAutoHide(False)
        self.tab_view.setObjectName("tab_view")
        self.tab_1 = QtWidgets.QWidget()
        self.tab_1.setObjectName("tab_1")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.tab_1)
        self.gridLayout_3.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.formLayout = QtWidgets.QFormLayout()
        self.formLayout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        self.formLayout.setObjectName("formLayout")
        self.numberOfInboundTrucksLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfInboundTrucksLabel.setObjectName("numberOfInboundTrucksLabel")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.numberOfInboundTrucksLabel)
        self.numberOfInboundTrucksSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfInboundTrucksSpinBox.setObjectName("numberOfInboundTrucksSpinBox")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.numberOfInboundTrucksSpinBox)
        self.numberOfOutboundTrucksLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfOutboundTrucksLabel.setObjectName("numberOfOutboundTrucksLabel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.numberOfOutboundTrucksLabel)
        self.numberOfOutboundTrucksSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfOutboundTrucksSpinBox.setObjectName("numberOfOutboundTrucksSpinBox")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.numberOfOutboundTrucksSpinBox)
        self.numberOfCompoundTrucksLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfCompoundTrucksLabel.setObjectName("numberOfCompoundTrucksLabel")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.numberOfCompoundTrucksLabel)
        self.numberOfCompoundTrucksSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfCompoundTrucksSpinBox.setObjectName("numberOfCompoundTrucksSpinBox")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.numberOfCompoundTrucksSpinBox)
        self.numberOfReceivingDoorsLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfReceivingDoorsLabel.setObjectName("numberOfReceivingDoorsLabel")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.numberOfReceivingDoorsLabel)
        self.numberOfReceivingDoorsSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfReceivingDoorsSpinBox.setObjectName("numberOfReceivingDoorsSpinBox")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.numberOfReceivingDoorsSpinBox)
        self.numberOfShippingDoorsLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfShippingDoorsLabel.setObjectName("numberOfShippingDoorsLabel")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.numberOfShippingDoorsLabel)
        self.numberOfShippingDoorsSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfShippingDoorsSpinBox.setObjectName("numberOfShippingDoorsSpinBox")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.numberOfShippingDoorsSpinBox)
        self.numberOfGoodsLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfGoodsLabel.setObjectName("numberOfGoodsLabel")
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.numberOfGoodsLabel)
        self.numberOfGoodsSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfGoodsSpinBox.setObjectName("numberOfGoodsSpinBox")
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.numberOfGoodsSpinBox)
        self.loadingTumeLabel = QtWidgets.QLabel(self.tab_1)
        self.loadingTumeLabel.setObjectName("loadingTumeLabel")
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.loadingTumeLabel)
        self.loadingTumeLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.loadingTumeLineEdit.setObjectName("loadingTumeLineEdit")
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.loadingTumeLineEdit)
        self.truckChangeoverTimeLabel = QtWidgets.QLabel(self.tab_1)
        self.truckChangeoverTimeLabel.setObjectName("truckChangeoverTimeLabel")
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.truckChangeoverTimeLabel)
        self.truckChangeoverTimeLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.truckChangeoverTimeLineEdit.setObjectName("truckChangeoverTimeLineEdit")
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.truckChangeoverTimeLineEdit)
        self.effectOfTheArrivalTimesOnMakespanLabel = QtWidgets.QLabel(self.tab_1)
        self.effectOfTheArrivalTimesOnMakespanLabel.setObjectName("effectOfTheArrivalTimesOnMakespanLabel")
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.effectOfTheArrivalTimesOnMakespanLabel)
        self.effectOfTheArrivalTimesOnMakespanLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.effectOfTheArrivalTimesOnMakespanLineEdit.setObjectName("effectOfTheArrivalTimesOnMakespanLineEdit")
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.effectOfTheArrivalTimesOnMakespanLineEdit)
        self.truckTransferTimeLabel = QtWidgets.QLabel(self.tab_1)
        self.truckTransferTimeLabel.setObjectName("truckTransferTimeLabel")
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.truckTransferTimeLabel)
        self.truckTransferTimeLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.truckTransferTimeLineEdit.setObjectName("truckTransferTimeLineEdit")
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.FieldRole, self.truckTransferTimeLineEdit)
        self.inboundArrivalTimeLabel = QtWidgets.QLabel(self.tab_1)
        self.inboundArrivalTimeLabel.setObjectName("inboundArrivalTimeLabel")
        self.formLayout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.inboundArrivalTimeLabel)
        self.inboundArrivalTimeLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.inboundArrivalTimeLineEdit.setObjectName("inboundArrivalTimeLineEdit")
        self.formLayout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.inboundArrivalTimeLineEdit)
        self.outboundArrivalTimeLabel = QtWidgets.QLabel(self.tab_1)
        self.outboundArrivalTimeLabel.setObjectName("outboundArrivalTimeLabel")
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.outboundArrivalTimeLabel)
        self.outboundArrivalTimeLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.outboundArrivalTimeLineEdit.setObjectName("outboundArrivalTimeLineEdit")
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.outboundArrivalTimeLineEdit)
        self.goodTransferTimeLabel = QtWidgets.QLabel(self.tab_1)
        self.goodTransferTimeLabel.setObjectName("goodTransferTimeLabel")
        self.formLayout.setWidget(13, QtWidgets.QFormLayout.LabelRole, self.goodTransferTimeLabel)
        self.goodTransferTimeLineEdit = QtWidgets.QLineEdit(self.tab_1)
        self.goodTransferTimeLineEdit.setObjectName("goodTransferTimeLineEdit")
        self.formLayout.setWidget(13, QtWidgets.QFormLayout.FieldRole, self.goodTransferTimeLineEdit)
        self.numberOfDataSetsLabel = QtWidgets.QLabel(self.tab_1)
        self.numberOfDataSetsLabel.setObjectName("numberOfDataSetsLabel")
        self.formLayout.setWidget(14, QtWidgets.QFormLayout.LabelRole, self.numberOfDataSetsLabel)
        self.numberOfDataSetsSpinBox = QtWidgets.QSpinBox(self.tab_1)
        self.numberOfDataSetsSpinBox.setMinimum(0)
        self.numberOfDataSetsSpinBox.setProperty("value", 0)
        self.numberOfDataSetsSpinBox.setObjectName("numberOfDataSetsSpinBox")
        self.formLayout.setWidget(14, QtWidgets.QFormLayout.FieldRole, self.numberOfDataSetsSpinBox)
        self.label_20 = QtWidgets.QLabel(self.tab_1)
        self.label_20.setObjectName("label_20")
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.label_20)
        self.unloading_time_edit = QtWidgets.QLineEdit(self.tab_1)
        self.unloading_time_edit.setObjectName("unloading_time_edit")
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.unloading_time_edit)
        self.verticalLayout.addLayout(self.formLayout)
        self.datasettable = ClipboardTableView(self.tab_1)
        self.datasettable.setAccessibleDescription("")
        self.datasettable.setLineWidth(1)
        self.datasettable.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked)
        self.datasettable.setTabKeyNavigation(False)
        self.datasettable.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.datasettable.setSortingEnabled(True)
        self.datasettable.setObjectName("datasettable")
        self.datasettable.horizontalHeader().setCascadingSectionResizes(True)
        self.datasettable.horizontalHeader().setDefaultSectionSize(70)
        self.verticalLayout.addWidget(self.datasettable)
        self.gridLayout_3.addLayout(self.verticalLayout, 0, 0, 1, 1)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.inbound_good_table = ClipboardTableView(self.tab_1)
        self.inbound_good_table.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked)
        self.inbound_good_table.setObjectName("inbound_good_table")
        self.verticalLayout_2.addWidget(self.inbound_good_table)
        self.compound_coming_good_table = ClipboardTableView(self.tab_1)
        self.compound_coming_good_table.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked)
        self.compound_coming_good_table.setObjectName("compound_coming_good_table")
        self.verticalLayout_2.addWidget(self.compound_coming_good_table)
        self.outbound_good_table = ClipboardTableView(self.tab_1)
        self.outbound_good_table.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked)
        self.outbound_good_table.setObjectName("outbound_good_table")
        self.verticalLayout_2.addWidget(self.outbound_good_table)
        self.compound_going_good_table = ClipboardTableView(self.tab_1)
        self.compound_going_good_table.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked)
        self.compound_going_good_table.setObjectName("compound_going_good_table")
        self.verticalLayout_2.addWidget(self.compound_going_good_table)
        self.gridLayout_3.addLayout(self.verticalLayout_2, 0, 1, 1, 1)
        self.gridLayout_3.setColumnStretch(0, 1)
        self.gridLayout_3.setColumnStretch(1, 5)
        self.tab_view.addTab(self.tab_1, "")
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.tab)
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout()
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.label_2 = QtWidgets.QLabel(self.tab)
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
        self.label_2.setObjectName("label_2")
        self.verticalLayout_4.addWidget(self.label_2)
        self.leaving_lower_table = ClipboardTableView(self.tab)
        self.leaving_lower_table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.leaving_lower_table.setObjectName("leaving_lower_table")
        self.verticalLayout_4.addWidget(self.leaving_lower_table)
        self.gridLayout_2.addLayout(self.verticalLayout_4, 2, 1, 1, 1)
        self.print_gams = QtWidgets.QPushButton(self.tab)
        self.print_gams.setObjectName("print_gams")
        self.gridLayout_2.addWidget(self.print_gams, 0, 1, 1, 1)
        self.verticalLayout_5 = QtWidgets.QVBoxLayout()
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        self.label_3 = QtWidgets.QLabel(self.tab)
        self.label_3.setAlignment(QtCore.Qt.AlignCenter)
        self.label_3.setObjectName("label_3")
        self.verticalLayout_5.addWidget(self.label_3)
        self.leaving_upper_table = ClipboardTableView(self.tab)
        self.leaving_upper_table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.leaving_upper_table.setObjectName("leaving_upper_table")
        self.verticalLayout_5.addWidget(self.leaving_upper_table)
        self.gridLayout_2.addLayout(self.verticalLayout_5, 2, 2, 1, 1)
        self.print_text = QtWidgets.QPushButton(self.tab)
        self.print_text.setObjectName("print_text")
        self.gridLayout_2.addWidget(self.print_text, 0, 2, 1, 1)
        self.generate_times_button = QtWidgets.QPushButton(self.tab)
        self.generate_times_button.setObjectName("generate_times_button")
        self.gridLayout_2.addWidget(self.generate_times_button, 0, 0, 1, 1)
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.label = QtWidgets.QLabel(self.tab)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout_3.addWidget(self.label)
        self.arrival_time_table = ClipboardTableView(self.tab)
        self.arrival_time_table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.arrival_time_table.setObjectName("arrival_time_table")
        self.verticalLayout_3.addWidget(self.arrival_time_table)
        self.gridLayout_2.addLayout(self.verticalLayout_3, 2, 0, 1, 1)
        self.generate_new_boundaries_button = QtWidgets.QPushButton(self.tab)
        self.generate_new_boundaries_button.setObjectName("generate_new_boundaries_button")
        self.gridLayout_2.addWidget(self.generate_new_boundaries_button, 1, 0, 1, 1)
        self.tab_view.addTab(self.tab, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.gridLayout_7 = QtWidgets.QGridLayout(self.tab_2)
        self.gridLayout_7.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_7.setObjectName("gridLayout_7")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.solverLabel = QtWidgets.QLabel(self.tab_2)
        self.solverLabel.setObjectName("solverLabel")
        self.horizontalLayout_4.addWidget(self.solverLabel)
        self.solverComboBox = QtWidgets.QComboBox(self.tab_2)
        self.solverComboBox.setObjectName("solverComboBox")
        self.solverComboBox.addItem("")
        self.solverComboBox.addItem("")
        self.horizontalLayout_4.addWidget(self.solverComboBox)
        self.numberOfIterationsLabel = QtWidgets.QLabel(self.tab_2)
        self.numberOfIterationsLabel.setObjectName("numberOfIterationsLabel")
        self.horizontalLayout_4.addWidget(self.numberOfIterationsLabel)
        self.numberOfIterationsLineEdit = QtWidgets.QLineEdit(self.tab_2)
        self.numberOfIterationsLineEdit.setObjectName("numberOfIterationsLineEdit")
        self.horizontalLayout_4.addWidget(self.numberOfIterationsLineEdit)
        self.label_19 = QtWidgets.QLabel(self.tab_2)
        self.label_19.setObjectName("label_19")
        self.horizontalLayout_4.addWidget(self.label_19)
        self.solution_time_label = QtWidgets.QLineEdit(self.tab_2)
        self.solution_time_label.setObjectName("solution_time_label")
        self.horizontalLayout_4.addWidget(self.solution_time_label)
        self.stackedWidget = QtWidgets.QStackedWidget(self.tab_2)
        self.stackedWidget.setObjectName("stackedWidget")
        self.page = QtWidgets.QWidget()
        self.page.setObjectName("page")
        self.gridLayout_4 = QtWidgets.QGridLayout(self.page)
        self.gridLayout_4.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label_7 = QtWidgets.QLabel(self.page)
        self.label_7.setObjectName("label_7")
        self.horizontalLayout.addWidget(self.label_7)
        self.tempereature_line_edit = QtWidgets.QLineEdit(self.page)
        self.tempereature_line_edit.setObjectName("tempereature_line_edit")
        self.horizontalLayout.addWidget(self.tempereature_line_edit)
        self.label_9 = QtWidgets.QLabel(self.page)
        self.label_9.setObjectName("label_9")
        self.horizontalLayout.addWidget(self.label_9)
        self.decav_factor_line_edit = QtWidgets.QLineEdit(self.page)
        self.decav_factor_line_edit.setObjectName("decav_factor_line_edit")
        self.horizontalLayout.addWidget(self.decav_factor_line_edit)
        self.gridLayout_4.addLayout(self.horizontalLayout, 0, 0, 1, 1)
        self.stackedWidget.addWidget(self.page)
        self.page_2 = QtWidgets.QWidget()
        self.page_2.setObjectName("page_2")
        self.gridLayout_8 = QtWidgets.QGridLayout(self.page_2)
        self.gridLayout_8.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_8.setObjectName("gridLayout_8")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.label_10 = QtWidgets.QLabel(self.page_2)
        self.label_10.setObjectName("label_10")
        self.horizontalLayout_3.addWidget(self.label_10)
        self.number_of_tabu_neighbours_line_edit = QtWidgets.QLineEdit(self.page_2)
        self.number_of_tabu_neighbours_line_edit.setObjectName("number_of_tabu_neighbours_line_edit")
        self.horizontalLayout_3.addWidget(self.number_of_tabu_neighbours_line_edit)
        self.label_11 = QtWidgets.QLabel(self.page_2)
        self.label_11.setObjectName("label_11")
        self.horizontalLayout_3.addWidget(self.label_11)
        self.number_of_tabu_line_edit = QtWidgets.QLineEdit(self.page_2)
        self.number_of_tabu_line_edit.setObjectName("number_of_tabu_line_edit")
        self.horizontalLayout_3.addWidget(self.number_of_tabu_line_edit)
        self.gridLayout_8.addLayout(self.horizontalLayout_3, 0, 0, 1, 1)
        self.stackedWidget.addWidget(self.page_2)
        self.horizontalLayout_4.addWidget(self.stackedWidget)
        self.label_21 = QtWidgets.QLabel(self.tab_2)
        self.label_21.setObjectName("label_21")
        self.horizontalLayout_4.addWidget(self.label_21)
        self.function_combo_box = QtWidgets.QComboBox(self.tab_2)
        self.function_combo_box.setObjectName("function_combo_box")
        self.function_combo_box.addItem("")
        self.function_combo_box.addItem("")
        self.function_combo_box.addItem("")
        self.function_combo_box.addItem("")
        self.function_combo_box.addItem("")
        self.function_combo_box.addItem("")
        self.function_combo_box.setItemText(5, "")
        self.horizontalLayout_4.addWidget(self.function_combo_box)
        self.time_limit_edit = QtWidgets.QLineEdit(self.tab_2)
        self.time_limit_edit.setObjectName("time_limit_edit")
        self.horizontalLayout_4.addWidget(self.time_limit_edit)
        self.solve_data_set_button = QtWidgets.QPushButton(self.tab_2)
        self.solve_data_set_button.setObjectName("solve_data_set_button")
        self.horizontalLayout_4.addWidget(self.solve_data_set_button)
        self.data_set_spin_box = QtWidgets.QSpinBox(self.tab_2)
        self.data_set_spin_box.setMinimum(1)
        self.data_set_spin_box.setProperty("value", 1)
        self.data_set_spin_box.setObjectName("data_set_spin_box")
        self.horizontalLayout_4.addWidget(self.data_set_spin_box)
        self.stop_data_set_solve_button = QtWidgets.QPushButton(self.tab_2)
        self.stop_data_set_solve_button.setObjectName("stop_data_set_solve_button")
        self.horizontalLayout_4.addWidget(self.stop_data_set_solve_button)
        self.gridLayout_7.addLayout(self.horizontalLayout_4, 0, 0, 1, 3)
        self.verticalLayout_6 = QtWidgets.QVBoxLayout()
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        self.label_4 = QtWidgets.QLabel(self.tab_2)
        self.label_4.setAlignment(QtCore.Qt.AlignCenter)
        self.label_4.setObjectName("label_4")
        self.verticalLayout_6.addWidget(self.label_4)
        self.coming_sequence_table = ClipboardTableView(self.tab_2)
        self.coming_sequence_table.setObjectName("coming_sequence_table")
        self.verticalLayout_6.addWidget(self.coming_sequence_table)
        self.gridLayout_7.addLayout(self.verticalLayout_6, 1, 0, 1, 1)
        self.verticalLayout_7 = QtWidgets.QVBoxLayout()
        self.verticalLayout_7.setObjectName("verticalLayout_7")
        self.label_5 = QtWidgets.QLabel(self.tab_2)
        self.label_5.setAlignment(QtCore.Qt.AlignCenter)
        self.label_5.setObjectName("label_5")
        self.verticalLayout_7.addWidget(self.label_5)
        self.going_sequence_table = ClipboardTableView(self.tab_2)
        self.going_sequence_table.setObjectName("going_sequence_table")
        self.verticalLayout_7.addWidget(self.going_sequence_table)
        self.gridLayout_7.addLayout(self.verticalLayout_7, 1, 1, 1, 1)
        self.verticalLayout_8 = QtWidgets.QVBoxLayout()
        self.verticalLayout_8.setObjectName("verticalLayout_8")
        self.label_6 = QtWidgets.QLabel(self.tab_2)
        self.label_6.setAlignment(QtCore.Qt.AlignCenter)
        self.label_6.setObjectName("label_6")
        self.verticalLayout_8.addWidget(self.label_6)
        self.sequence_error_table = ClipboardTableView(self.tab_2)
        self.sequence_error_table.setObjectName("sequence_error_table")
        self.verticalLayout_8.addWidget(self.sequence_error_table)
        self.gridLayout_7.addLayout(self.verticalLayout_8, 1, 2, 1, 1)
        self.gridLayout_7.setRowStretch(1, 3)
        self.tab_view.addTab(self.tab_2, "")
        self.tab_4 = QtWidgets.QWidget()
        self.tab_4.setObjectName("tab_4")
        self.gridLayout_5 = QtWidgets.QGridLayout(self.tab_4)
        self.gridLayout_5.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_5.setObjectName("gridLayout_5")
        self.frame = QtWidgets.QFrame(self.tab_4)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.gridLayout_6 = QtWidgets.QGridLayout(self.frame)
        self.gridLayout_6.setObjectName("gridLayout_6")
        self.sequence_grid = QtWidgets.QGridLayout()
        self.sequence_grid.setObjectName("sequence_grid")
        self.gridLayout_6.addLayout(self.sequence_grid, 0, 0, 1, 1)
        self.gridLayout_5.addWidget(self.frame, 1, 0, 1, 1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.solve_one_sequence_button = QtWidgets.QPushButton(self.tab_4)
        self.solve_one_sequence_button.setObjectName("solve_one_sequence_button")
        self.horizontalLayout_2.addWidget(self.solve_one_sequence_button)
        self.label_8 = QtWidgets.QLabel(self.tab_4)
        self.label_8.setObjectName("label_8")
        self.horizontalLayout_2.addWidget(self.label_8)
        self.time = QtWidgets.QLCDNumber(self.tab_4)
        font = QtGui.QFont()
        font.setBold(True)
        font.setItalic(False)
        font.setWeight(75)
        self.time.setFont(font)
        self.time.setObjectName("time")
        self.horizontalLayout_2.addWidget(self.time)
        self.label_12 = QtWidgets.QLabel(self.tab_4)
        self.label_12.setObjectName("label_12")
        self.horizontalLayout_2.addWidget(self.label_12)
        self.time_constant = QtWidgets.QLineEdit(self.tab_4)
        self.time_constant.setObjectName("time_constant")
        self.horizontalLayout_2.addWidget(self.time_constant)
        self.pause_button = QtWidgets.QPushButton(self.tab_4)
        self.pause_button.setObjectName("pause_button")
        self.horizontalLayout_2.addWidget(self.pause_button)
        self.resume_button = QtWidgets.QPushButton(self.tab_4)
        self.resume_button.setObjectName("resume_button")
        self.horizontalLayout_2.addWidget(self.resume_button)
        self.stop_button = QtWidgets.QPushButton(self.tab_4)
        self.stop_button.setObjectName("stop_button")
        self.horizontalLayout_2.addWidget(self.stop_button)
        self.gridLayout_5.addLayout(self.horizontalLayout_2, 0, 0, 1, 1)
        self.graphicsView = Simulator(self.tab_4)
        self.graphicsView.setObjectName("graphicsView")
        self.gridLayout_5.addWidget(self.graphicsView, 2, 0, 1, 1)
        self.gridLayout_5.setRowStretch(2, 3)
        self.tab_view.addTab(self.tab_4, "")
        self.tab_3 = QtWidgets.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.gridLayout = QtWidgets.QGridLayout(self.tab_3)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.result_names_combo_box = QtWidgets.QComboBox(self.tab_3)
        self.result_names_combo_box.setMinimumSize(QtCore.QSize(300, 0))
        self.result_names_combo_box.setObjectName("result_names_combo_box")
        self.horizontalLayout_5.addWidget(self.result_names_combo_box)
        self.label_13 = QtWidgets.QLabel(self.tab_3)
        self.label_13.setObjectName("label_13")
        self.horizontalLayout_5.addWidget(self.label_13)
        self.result_iteration_number_line_edit = QtWidgets.QLineEdit(self.tab_3)
        self.result_iteration_number_line_edit.setObjectName("result_iteration_number_line_edit")
        self.horizontalLayout_5.addWidget(self.result_iteration_number_line_edit)
        self.show_results_button = QtWidgets.QPushButton(self.tab_3)
        self.show_results_button.setObjectName("show_results_button")
        self.horizontalLayout_5.addWidget(self.show_results_button)
        self.multiSolveButton = QtWidgets.QPushButton(self.tab_3)
        self.multiSolveButton.setObjectName("multiSolveButton")
        self.horizontalLayout_5.addWidget(self.multiSolveButton)
        self.multiSolveCombo = QtWidgets.QComboBox(self.tab_3)
        self.multiSolveCombo.setObjectName("multiSolveCombo")
        self.multiSolveCombo.addItem("")
        self.multiSolveCombo.addItem("")
        self.multiSolveCombo.addItem("")
        self.multiSolveCombo.addItem("")
        self.multiSolveCombo.addItem("")
        self.horizontalLayout_5.addWidget(self.multiSolveCombo)
        self.horizontalLayout_5.setStretch(0, 2)
        self.gridLayout.addLayout(self.horizontalLayout_5, 0, 0, 1, 1)
        self.verticalLayout_15 = QtWidgets.QVBoxLayout()
        self.verticalLayout_15.setObjectName("verticalLayout_15")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.verticalLayout_12 = QtWidgets.QVBoxLayout()
        self.verticalLayout_12.setObjectName("verticalLayout_12")
        self.verticalLayout_13 = QtWidgets.QVBoxLayout()
        self.verticalLayout_13.setObjectName("verticalLayout_13")
        self.label_17 = QtWidgets.QLabel(self.tab_3)
        self.label_17.setObjectName("label_17")
        self.verticalLayout_13.addWidget(self.label_17)
        self.sequence_table = ClipboardTableView(self.tab_3)
        self.sequence_table.setMinimumSize(QtCore.QSize(350, 0))
        self.sequence_table.setObjectName("sequence_table")
        self.verticalLayout_13.addWidget(self.sequence_table)
        self.verticalLayout_12.addLayout(self.verticalLayout_13)
        self.verticalLayout_11 = QtWidgets.QVBoxLayout()
        self.verticalLayout_11.setObjectName("verticalLayout_11")
        self.label_16 = QtWidgets.QLabel(self.tab_3)
        self.label_16.setAlignment(QtCore.Qt.AlignCenter)
        self.label_16.setObjectName("label_16")
        self.verticalLayout_11.addWidget(self.label_16)
        self.inbound_time_table = ClipboardTableView(self.tab_3)
        self.inbound_time_table.setMinimumSize(QtCore.QSize(350, 0))
        self.inbound_time_table.setObjectName("inbound_time_table")
        self.verticalLayout_11.addWidget(self.inbound_time_table)
        self.verticalLayout_12.addLayout(self.verticalLayout_11)
        self.horizontalLayout_6.addLayout(self.verticalLayout_12)
        self.verticalLayout_14 = QtWidgets.QVBoxLayout()
        self.verticalLayout_14.setObjectName("verticalLayout_14")
        self.label_18 = QtWidgets.QLabel(self.tab_3)
        self.label_18.setObjectName("label_18")
        self.verticalLayout_14.addWidget(self.label_18)
        self.good_in_out_table = ClipboardTableView(self.tab_3)
        self.good_in_out_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
        self.good_in_out_table.setObjectName("good_in_out_table")
        self.good_in_out_table.horizontalHeader().setHighlightSections(False)
        self.verticalLayout_14.addWidget(self.good_in_out_table)
        self.horizontalLayout_6.addLayout(self.verticalLayout_14)
        self.horizontalLayout_6.setStretch(0, 1)
        self.horizontalLayout_6.setStretch(1, 1)
        self.verticalLayout_15.addLayout(self.horizontalLayout_6)
        self.verticalLayout_9 = QtWidgets.QVBoxLayout()
        self.verticalLayout_9.setObjectName("verticalLayout_9")
        self.label_14 = QtWidgets.QLabel(self.tab_3)
        self.label_14.setAlignment(QtCore.Qt.AlignCenter)
        self.label_14.setObjectName("label_14")
        self.verticalLayout_9.addWidget(self.label_14)
        self.outbound_time_table = ClipboardTableView(self.tab_3)
        self.outbound_time_table.setMinimumSize(QtCore.QSize(0, 150))
        self.outbound_time_table.setObjectName("outbound_time_table")
        self.verticalLayout_9.addWidget(self.outbound_time_table)
        self.verticalLayout_15.addLayout(self.verticalLayout_9)
        self.verticalLayout_10 = QtWidgets.QVBoxLayout()
        self.verticalLayout_10.setObjectName("verticalLayout_10")
        self.label_15 = QtWidgets.QLabel(self.tab_3)
        self.label_15.setAlignment(QtCore.Qt.AlignCenter)
        self.label_15.setObjectName("label_15")
        self.verticalLayout_10.addWidget(self.label_15)
        self.compound_time_table = ClipboardTableView(self.tab_3)
        self.compound_time_table.setMinimumSize(QtCore.QSize(0, 150))
        self.compound_time_table.setObjectName("compound_time_table")
        self.verticalLayout_10.addWidget(self.compound_time_table)
        self.verticalLayout_15.addLayout(self.verticalLayout_10)
        self.gridLayout.addLayout(self.verticalLayout_15, 1, 0, 1, 1)
        self.tab_view.addTab(self.tab_3, "")
        self.gridLayout_9.addWidget(self.tab_view, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1274, 30))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionNew_Data = QtWidgets.QAction(MainWindow)
        self.actionNew_Data.setObjectName("actionNew_Data")
        self.actionLoad_Data = QtWidgets.QAction(MainWindow)
        self.actionLoad_Data.setObjectName("actionLoad_Data")
        self.actionSave_Data = QtWidgets.QAction(MainWindow)
        self.actionSave_Data.setObjectName("actionSave_Data")
        self.actionQuit = QtWidgets.QAction(MainWindow)
        self.actionQuit.setObjectName("actionQuit")
        self.menuFile.addAction(self.actionNew_Data)
        self.menuFile.addAction(self.actionLoad_Data)
        self.menuFile.addAction(self.actionSave_Data)
        self.menuFile.addAction(self.actionQuit)
        self.menubar.addAction(self.menuFile.menuAction())

        self.retranslateUi(MainWindow)
        self.tab_view.setCurrentIndex(2)
        self.stackedWidget.setCurrentIndex(0)
        self.solverComboBox.currentIndexChanged['int'].connect(self.stackedWidget.setCurrentIndex)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Example #16
0
def run_avian(inter_name, sig_method, sc, start_time_stamp, tester):
    """
    .. note:: The following assumptions are important to notice:
        - Trajectories must end at the stop bar, i.e. the distance to stop bar converges to zero, even if they are temporarily assigned.
        - The desired speed of vehicles shall not exceed the speed limit or they will be advised speeding
        - Use default values for pieces of information that are impossible to obtain, i.e. accel/decel rates and destination of conventional vehicles.

    :param inter_name: The intersection name (should match the name given to identify an intersection in ``config.py``)
    :type inter_name: str
    :param sig_method: signalization method ``pretimed, GA, ...``
    :type sig_method: str
    :param sc: scenario number (should match ``/data/<intersection name>/<intersection name>_<scenario number>.csv``)
    :type sc: int
    :param start_time_stamp: The local time stamp to name the output CSV files
    :param tester: The tester object
    :type tester: test.unit_tests.SimTest

    :Author:
        Mahmoud Pourmehrab <*****@*****.**>
    :Date:
        April-2018
    :Organization:
        University of Florida
    """
    intersection = Intersection(inter_name)
    lanes = Lanes(intersection)
    traffic = Traffic(intersection, sc, start_time_stamp)
    first_detection_time = traffic.get_first_detection_time()

    if sig_method == "MCF":
        signal = MCF_SPaT(first_detection_time, intersection, sc, start_time_stamp)
    elif sig_method == "GA":
        signal = GA_SPaT(first_detection_time, intersection, sc, start_time_stamp)

    trajectory_planner = TrajectoryPlanner(intersection)
    simulator = Simulator(first_detection_time)

    if intersection._general_params.get("log_csv"):
        t_start = perf_counter()  # to measure the total run time (IS NOT THE SIMULATION TIME)

    while True:  # stops when all rows of CSV are processed (a break statement controls this)
        simulation_time = simulator.clock  # gets current simulation clock
        intersection._general_params.get("print_commandline") and print(
            "\n################################# CLOCK: {:>5.1f} SEC #################################".format(
                simulation_time))

        # update the assigned trajectories
        traffic.serve_update_at_stop_bar(lanes, simulation_time, intersection)
        # tester is not None and intersection._general_params.get("do_traj_computation") and tester.check_order_in_lanes(lanes)
        # add/update the vehicles
        traffic.get_traffic_info(lanes, simulation_time, intersection)
        # update earliest departure schedule
        lanes.refresh_earliest_departure_times(lanes, intersection)
        # update the SPaT
        signal.update_SPaT(intersection, simulation_time, sc)

        # update the space mean speed
        volumes = traffic.get_volumes(lanes, intersection)
        critical_volume_ratio = 3_600 * volumes.max() / intersection._general_params.get(
            "min_CAV_headway")  # todo could depend on min_CNV_headway too

        # perform signal optimization
        signal.solve(lanes, intersection, critical_volume_ratio, trajectory_planner, tester)

        num_lanes = intersection._general_params.get("num_lanes")
        tester is not None and tester.test_departure_of_trj(lanes, intersection, [0] * num_lanes,
                                                            lanes.last_vehicle_indx)

        # move it forward
        if traffic.last_veh_arrived() and lanes.all_served(num_lanes):
            if intersection._general_params.get("log_csv"):
                elapsed_time = perf_counter() - t_start  # THIS IS NOT SIMULATION TIME! IT'S JUST FOR TIMING THE ALGORITHM
                simulator.record_sim_stats(sc, inter_name, start_time_stamp, elapsed_time)
                traffic.save_veh_level_csv(inter_name, start_time_stamp)
                traffic.close_trj_csv()
                signal.close_sig_csv()
                intersection._general_params.get("print_commandline") and print(
                    "\n### ELAPSED TIME: {:>5d} ms ###".format(int(1000 * elapsed_time)))
            return

        else:
            simulator.next_sim_step()
class SimulatorDriver(models.Model):

    #def __str__(self):
    #    return self.summary

    def __init__(self, file_name):
        self.simulator = Simulator()
        self.simulator.process_input(file_name)
        self.simulator.setup()

    def get_data(self):
        return self.simulator.get_mdata_for_gui()

    def next_move(self):
        self.simulator.make_simulation_turn()

    def fast_forward(self):
        self.simulator.fast_forward()

    def stop(self):
        self.simulator.stop_simulation()
 def __init__(self, file_name):
     self.simulator = Simulator()
     self.simulator.process_input(file_name)
     self.simulator.setup()
Example #19
0
    os.chdir("reports")
    dir_name = strftime("%Y%m%d_%H%M%S")

    if os.path.exists(dir_name):
        id = 0
        tmp_dir_name = dir_name + "." + id
        while os.path.exists(tmp_dir_name):
            id = id + 1
            tmp_dir_name = dir_name + "." + id
        dir_name = tmp_dir_name

    os.makedirs(dir_name)
    os.chdir(dir_name)

    return dir_name


if __name__ == "__main__":
    args = parse_arguments()
    if (2 * args.minimum_bitwidth) > args.maximum_fanout:
        print("The maximum fanout needs to be smaller than twice the "
              "minimum bitwidth plus one.")
        quit()

    print("Starting ...")
    working_dir = setup_working_dir()
    print("Working directory: " + working_dir)
    sim = Simulator(args.minimum_bitwidth, args.maximum_fanout, working_dir)
    sim.run_designs()
    print("Thank you!")
def run(args, shared_blocked, shared_dropped, run_seed):
    np.random.seed(run_seed)  # scipy uses numpy seeds
    args.seed = run_seed
    simulator = Simulator(args)  # init simulator

    # capture stats
    # step-wise statistics no longer required
    # blocked_arr = []
    # dropped_arr = []
    num_inits = num_handover = num_terminate = 0
    warmed_up = False

    for step in range(args.steps):
        if step > args.warmup and not warmed_up:
            simulator.reset()
            warmed_up = True
            # print('Simulator reset')
            # print(f'Total Calls: {simulator.total_calls}')
            # print(f'Blocked Calls: {simulator.blocked_calls}')
            # print(f'Dropped Calls: {simulator.dropped_calls}')
            # print('Leaving simulator reset')

        event = simulator.FEL.dequeue()
        simulator.clock = event.time  # advance clock to event

        if isinstance(event, CallInit):
            simulator.handle_call_init(event)
            num_inits += 1
        elif isinstance(event, CallHandover):
            num_handover += 1
            if args.num_reserve == 0:
                simulator.handle_call_handover_no_res(event)
            else:
                simulator.handle_call_handover_res(event)
        elif isinstance(event, CallTerminate):
            num_terminate += 1
            simulator.handle_call_termination(event)
        else:
            raise TypeError("Wrong event type in FEL")

        # if warmed_up: # only start collecting when warmed up
        #     assert simulator.total_calls != 0
        #     percent_blocked = (simulator.blocked_calls / simulator.total_calls) * 100
        #     percent_dropped = (simulator.dropped_calls / simulator.total_calls) * 100
        #     blocked_arr.append(percent_blocked)
        #     dropped_arr.append(percent_dropped)

    # compute final run statistics
    # for debugging
    # print(f'Total Calls: {simulator.total_calls}')
    # print(f'Blocked Calls: {simulator.blocked_calls}')
    # print(f'Dropped Calls: {simulator.dropped_calls}')

    run_blocked = (simulator.blocked_calls / simulator.total_calls) * 100
    run_dropped = (simulator.dropped_calls / simulator.total_calls) * 100

    # store results in shared list
    shared_blocked.append(run_blocked)
    shared_dropped.append(run_dropped)
def test_visualize() -> None:
    particles = [Particle(0.3, 0.5), Particle(0.0, -0.5), Particle(-0.1, -0.4)]
    simulator = Simulator(particles)
    visualize(simulator)
Example #22
0
if __name__ == '__main__':
    ranking = Ranking()

    setup_teams = ['Slovakia', 'Brasil', 'Argentina', 'Germany', 'France',
                   'Spain', 'England', 'Italy']

    print('Registering teams into ranking...')
    for t in setup_teams:
        ranking.register_team(Team(t, 0))

    print('Building groups...')
    groups = ranking.build_groups()
    for group in groups:
        group.generate_matches()

    print('Building simulator...')
    sim = Simulator(groups)

    print('Simulating qualification...')
    while not sim.simulate_qualification_one_day():
        pass

    print('Building championship...')
    sim.build_championship()

    print('Simulating championship spider rounds...')
    while not sim.simulate_championship_round():
        pass

    print('Done... The winner is {0}'.format(sim.get_championship_winner()))