def solve(self, resultsSearches, resultsCost):
     location_x = np.random.randint(self.rowSize)
     location_y = np.random.randint(self.columnSize)
     while not self.targetFound:
         self.numberOfSteps += 1
         landscapeProbab = self.probOfLandScapes[
             self.matrix[location_x][location_y] - 1]  #negative probab
         if location_x == self.target_x and location_y == self.target_y and np.random.uniform(
         ) > landscapeProbab:
             print("Target found at ", location_x, location_y)
             print("Number of Steps: ", self.numberOfSteps)
             print("landscape : ", self.landScapeType)
             self.targetFound = True
             resultsSearches[self.landScapeType] += self.numberOfSteps
             Utility.resetProbabilityDistribution(
                 self.probabilityDistribution, self.rowSize,
                 self.columnSize)
             return Analyser(self.matrix, self.rowSize, self.columnSize,
                             self.ruleType, self.isStationary,
                             self.numberOfSteps, self.distanceTravelled,
                             self.trials, self.landScapeType)
         else:
             #Bayessian updating after the target is not found
             Utility.updateProbabilities(
                 self.probabilityDistribution, landscapeProbab,
                 self.rowSize, self.columnSize, location_x, location_y,
                 self.grid, self.rowWindowSize, self.colWindowSize,
                 self.textMatrix)
             self.transitions = []
             Utility.makeTransitions(self.rowSize, self.columnSize,
                                     location_x, location_y, self.matrix,
                                     self.transitions)
             Utility.updateMovementProbability(self.rowSize,
                                               self.columnSize,
                                               self.transitions,
                                               self.probabilityDistribution,
                                               self.matrix,
                                               self.temporaryProbability)
             print("*&&&&&&&&&&&&&&&&&& transition print begins")
             print(self.probabilityDistribution)
             print(self.transitions)
             print("*&&&&&&&&&&&&&&&&&& transition print ends")
             if self.ruleType == 'Rule 1':
                 location_x, location_y, d = Utility.getProbabContainTarget(
                     self.probabilityDistribution, self.rowSize,
                     self.columnSize, location_x, location_y)
                 resultsCost[self.landScapeType] += d
             elif self.ruleType == 'Rule 2':
                 location_x, location_y, d = Utility.getProbabFindingTarget(
                     self.probabilityDistribution, self.probOfLandScapes,
                     self.matrix, self.rowSize, self.columnSize, location_x,
                     location_y)
                 resultsCost[self.landScapeType] += d
Exemple #2
0
    def __init__(self, graphLogReader):
        self.graphLogReader = graphLogReader
        if not self.graphLogReader.hasSnapshotEntry():
            raise RuntimeError('Log must start with a complete graph snapshot')

        self.graph = self.graphLogReader.getSnapshotEntry().graph
        self.rules = getRuleset()

        self.graphLogger = gl.GraphLogger(
            self.graph,
            gl.GraphLogWriter(
                get_graph_logger('GraphLogger', 'graphReproduced.log')))
        self.graphLogger.setGraphGetter(lambda: self.graph)

        self.analyzer = Analyser.Analyser()
        self.analyzer.initAnalysis(self.graph, config={'stepSize': 10})
Exemple #3
0
"""This module contains entry point"""

from Parser import *
from Analyser import *
import sys

if __name__ == '__main__':
    while True:
        try:
            parser = Parser("")
            for line in sys.stdin:
                if line == '\n':
                    continue
                parser.reinit(line)
                parser.parse()
                analyser = Analyser(parser.parsed_args)
                analyser.command = line
                analyser.run()
        except ExitException:
            break
        except Exception:
            print("Command could not be recognized. Please, try again.")

Exemple #4
0
 def __init__(self, ruleset=None, config=default_config):
     if ruleset is None:
         ruleset = getRuleset()
     self.rules = {rulename:{'rule':rule,'weight':config[rulename+'_weight']} for rulename, rule in ruleset.items()}
     self.analyzer = Analyser.Analyser()
     self.writeLog = config['logging_enabled']
Exemple #5
0
    def setup_ui(self, main_window):
        """
        Setup UI components
        """
        self.__streamer_client = StreamerClient.StreamerClient(self.__host)
        self.__communicator_client = CommunicatorClient.CommunicatorClient(self.__host)
        self.__data_provider_client = DataProviderClient.DataProviderClient(self.__host)
        self.__analyser = Analyser.Analyser()

        main_window.setObjectName(FROM_UTF8("main_window"))
        main_window.resize(660, 700)
        main_window.keyPressEvent = self.key_press_event
        main_window.closeEvent = self.close_event
        self.centralwidget = QtGui.QWidget(main_window)
        self.centralwidget.setObjectName(FROM_UTF8("centralwidget"))
        self.grid_layout = QtGui.QGridLayout(self.centralwidget)
        self.grid_layout.setObjectName(FROM_UTF8("grid_layout"))
        self.distance_buttons_layout = QtGui.QVBoxLayout()
        self.distance_buttons_layout.setObjectName(FROM_UTF8("distance_buttons_layout"))
        self.acc_activate_button = QtGui.QPushButton(self.centralwidget)
        self.acc_activate_button.setObjectName(FROM_UTF8("acc_activate_button"))
        self.distance_buttons_layout.addWidget(self.acc_activate_button)
        self.decisions_activate_button = QtGui.QPushButton(self.centralwidget)
        self.decisions_activate_button.setObjectName(FROM_UTF8("decisions_activate_button"))
        self.distance_buttons_layout.addWidget(self.decisions_activate_button)
        self.increase_distance_button = QtGui.QPushButton(self.centralwidget)
        self.increase_distance_button.setObjectName(FROM_UTF8("increase_distance_button"))
        self.distance_buttons_layout.addWidget(self.increase_distance_button)
        self.decrease_distance_button = QtGui.QPushButton(self.centralwidget)
        self.decrease_distance_button.setObjectName(FROM_UTF8("decrease_distance_button"))
        self.distance_buttons_layout.addWidget(self.decrease_distance_button)
        self.grid_layout.addLayout(self.distance_buttons_layout, 1, 0, 3, 1)
        self.streamer_image_layout = QtGui.QVBoxLayout()
        self.streamer_image_layout.setObjectName(FROM_UTF8("streamer_image_layout"))
        self.streamer_image_view = QtGui.QLabel(self.centralwidget)
        self.streamer_image_view = OwnImageWidget(self.streamer_image_view)
        self.streamer_image_view.setMinimumSize(QtCore.QSize(640, 480))
        self.streamer_image_view.setObjectName(FROM_UTF8("streamer_image_view"))
        self.streamer_image_layout.addWidget(self.streamer_image_view)
        self.grid_layout.addLayout(self.streamer_image_layout, 0, 0, 1, 6)
        self.speed_buttons_layout = QtGui.QVBoxLayout()
        self.speed_buttons_layout.setObjectName(FROM_UTF8("speed_buttons_layout"))
        self.speed_up_button = QtGui.QPushButton(self.centralwidget)
        self.speed_up_button.setObjectName(FROM_UTF8("speed_up_button"))
        self.speed_buttons_layout.addWidget(self.speed_up_button)
        self.speed_down_button = QtGui.QPushButton(self.centralwidget)
        self.speed_down_button.setObjectName(FROM_UTF8("speed_down_button"))
        self.speed_buttons_layout.addWidget(self.speed_down_button)
        self.brake_button = QtGui.QPushButton(self.centralwidget)
        self.brake_button.setObjectName(FROM_UTF8("brake_button"))
        self.speed_buttons_layout.addWidget(self.brake_button)
        self.grid_layout.addLayout(self.speed_buttons_layout, 1, 5, 3, 1)
        self.states_layout = QtGui.QFormLayout()
        self.states_layout.setObjectName(FROM_UTF8("states_layout"))
        self.speed_label = QtGui.QLabel(self.centralwidget)
        self.speed_label.setObjectName(FROM_UTF8("speed_label"))
        self.states_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.speed_label)
        self.speed_text = QtGui.QLineEdit(self.centralwidget)
        self.speed_text.setReadOnly(True)
        self.speed_text.setObjectName(FROM_UTF8("speed_text"))
        self.states_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.speed_text)
        self.preferred_speed_label = QtGui.QLabel(self.centralwidget)
        self.preferred_speed_label.setObjectName(FROM_UTF8("preferred_speed_label"))
        self.states_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.preferred_speed_label)
        self.preferred_speed_text = QtGui.QLineEdit(self.centralwidget)
        self.preferred_speed_text.setReadOnly(True)
        self.preferred_speed_text.setObjectName(FROM_UTF8("preferred_speed_text"))
        self.states_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.preferred_speed_text)
        self.cruise_distance_label = QtGui.QLabel(self.centralwidget)
        self.cruise_distance_label.setObjectName(FROM_UTF8("cruise_distance_label"))
        self.states_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.cruise_distance_label)
        self.cruise_distance_text = QtGui.QLineEdit(self.centralwidget)
        self.cruise_distance_text.setReadOnly(True)
        self.cruise_distance_text.setObjectName(FROM_UTF8("cruise_distance_text"))
        self.states_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.cruise_distance_text)
        self.detection_label = QtGui.QLabel(self.centralwidget)
        self.detection_label.setObjectName(FROM_UTF8("detection_label"))
        self.states_layout.setWidget(3, QtGui.QFormLayout.LabelRole, self.detection_label)
        self.detection_text = QtGui.QLineEdit(self.centralwidget)
        self.detection_text.setReadOnly(True)
        self.detection_text.setObjectName(FROM_UTF8("detection_text"))
        self.states_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.detection_text)
        self.command_label = QtGui.QLabel(self.centralwidget)
        self.command_label.setObjectName(FROM_UTF8("command_label"))
        self.states_layout.setWidget(4, QtGui.QFormLayout.LabelRole, self.command_label)
        self.command_text = QtGui.QLineEdit(self.centralwidget)
        self.command_text.setReadOnly(True)
        self.command_text.setObjectName(FROM_UTF8("command_text"))
        self.states_layout.setWidget(4, QtGui.QFormLayout.FieldRole, self.command_text)
        self.grid_layout.addLayout(self.states_layout, 1, 1, 3, 4)
        main_window.setCentralWidget(self.centralwidget)
        self.statusbar = QtGui.QStatusBar(main_window)
        self.statusbar.setObjectName(FROM_UTF8("statusbar"))
        main_window.setStatusBar(self.statusbar)

        # receive frames thread
        self.__streamer_client_thread = \
            threading.Thread(target=StreamerClient.StreamerClient.receive_stream, \
            args=(self.__streamer_client, FRAME_QUEUE))
        self.__streamer_client_thread.setDaemon(True)
        self.__streamer_client_thread.start()

        # send commands to car thread
        self.__communicator_client_thread = \
            threading.Thread(target=CommunicatorClient.CommunicatorClient.send_commands, \
            args=(self.__communicator_client, COMMANDS_QUEUE))
        self.__communicator_client_thread.setDaemon(True)
        self.__communicator_client_thread.start()

        # receive data about the car thread
        self.__data_provider_client_thread = \
            threading.Thread(target=DataProviderClient.DataProviderClient.receive_car_data, \
            args=(self.__data_provider_client, CAR_DATA_QUEUE))
        self.__data_provider_client_thread.setDaemon(True)
        self.__data_provider_client_thread.start()

        # analyse every frame and take decisions thread
        self.__analyser_thread = \
            threading.Thread(target=Analyser.Analyser.analyse, \
            args=(self.__analyser, FRAME_QUEUE, ANALYSED_FRAME_QUEUE, AUTONOMOUS_STATES_QUEUE, \
            COMMANDS_QUEUE, CAR_STATES_QUEUE,))
        self.__analyser_thread.setDaemon(True)
        self.__analyser_thread.start()
        self.__analyser_thread.is_analysing = self.__acc_activated

        # update frames thread
        self.update_frame_timer = QtCore.QTimer(self.streamer_image_layout)
        self.update_frame_timer.timeout.connect(self.__update_frame)
        self.update_frame_timer.start(10)

        # update car data thread
        self.update_car_data_timer = QtCore.QTimer(self.states_layout)
        self.update_car_data_timer.timeout.connect(self.__update_car_data)
        self.update_car_data_timer.start(200)

        # supervise the user settings and sync entire app thread
        self.superviser_timer = QtCore.QTimer(self.centralwidget)
        self.superviser_timer.timeout.connect(self.__superviser_thread)
        self.superviser_timer.start(100)

        self.window_width = self.streamer_image_view.frameSize().width()
        self.window_height = self.streamer_image_view.frameSize().height()

        self.speed_up_button.clicked.connect(self.__speed_up_button_clicked)
        self.speed_down_button.clicked.connect(self.__speed_down_button_clicked)
        self.brake_button.clicked.connect(self.__brake_button_clicked)
        self.increase_distance_button.clicked.connect(self.__increase_distance_btn_clicked)
        self.decrease_distance_button.clicked.connect(self.__decrease_distance_btn_clicked)
        self.acc_activate_button.clicked.connect(self.__acc_activate_button_clicked)
        self.decisions_activate_button.clicked.connect(self.__decisions_button_clicked)

        self.retranslate_ui(main_window)
        QtCore.QMetaObject.connectSlotsByName(main_window)
Exemple #6
0
def get_how_many():
    return int(input('How many results do you want? '))


# This is the function to show the menu.
# Yes, it is big and weird, deal with it.
if __name__ == '__main__':

    exit = False
    while not exit:
        show_main_menu()
        option = int(input('> '))

        if option == 1:
            an = Analyser()

            main_menu = False
            while not main_menu:
                show_sports_menu()
                sport_idx = int(input('> '))
                if sport_idx == -1:
                    main_menu = True
                else:
                    process_sport_choice(sport_idx)
        elif option == 2:
            where_we_are_now = os.getcwd()
            os.chdir(f'..{const.slash}accesslink-API{const.slash}')
            utils.clear()
            os.system('python accesslink_example.py')
            os.chdir(where_we_are_now)